Package com.cloudbees.sdk.commands.bg

Source Code of com.cloudbees.sdk.commands.bg.ApplicationBlueGreenCreate

package com.cloudbees.sdk.commands.bg;

import com.cloudbees.api.ApplicationCreateResponse;
import com.cloudbees.api.ApplicationInfo;
import com.cloudbees.sdk.cli.BeesCommand;
import com.cloudbees.sdk.cli.CLICommand;
import com.cloudbees.sdk.utils.Helper;
import org.kohsuke.args4j.Option;

import java.util.*;

@BeesCommand(group="Application", description = "Create an application for the Blue-Green process")
@CLICommand("app:bg:create")
public class ApplicationBlueGreenCreate extends ApplicationBlueGreenBase {

    @Option(name = "-bg", usage = "blue-green parameter", required = true, aliases = "--blueGreen")
    private String bg;

    @Option(name = "-al", usage = "application aliases", aliases = "--alias")
    private String aliases;

    @Option(name = "-t", usage = "application type", aliases = "--type")
    private String type;

    public ApplicationBlueGreenCreate() {
    }

    @Override
    public int main() throws Exception {
        ApplicationClient client = getBeesClient(ApplicationClient.class, getAppId());

        Map<String, String> parameters = new HashMap<String, String>();
        Map<String, String> appParameters = new HashMap<String, String>();
        Map<String, String> appVariables = new HashMap<String, String>();

        appVariables.put("blue-green", bg);

        if (aliases != null) {
            appParameters.put("aliases", aliases);
        }

        if (type != null) {
            parameters.put("app_type", type);
        }

        ApplicationCreateResponse res = client.applicationCreate(getAppId(), parameters, appParameters, appVariables);
        ApplicationInfo applicationInfo = res.getApplicationInfo();
        System.out.println( "Application     : " + applicationInfo.getId());
        System.out.println( "Title           : " + applicationInfo.getTitle());
        System.out.println( "Created         : " + applicationInfo.getCreated());
        System.out.println( "Status          : " + applicationInfo.getStatus());
        System.out.println( "URL             : " + applicationInfo.getUrls()[0]);
        Map<String, String> settings = applicationInfo.getSettings();
        if (settings != null) {
            List<String> list = new ArrayList<String>(settings.size());
            for (Map.Entry<String, String> entry: settings.entrySet()) {
                list.add(Helper.getPaddedString(entry.getKey(), 16) + ": " + entry.getValue());
            }
            Collections.sort(list);
            for (String item : list)
                System.out.println(item);
        }

        return 0;
    }

}
TOP

Related Classes of com.cloudbees.sdk.commands.bg.ApplicationBlueGreenCreate

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.