Package com.cloudbees.sdk.pool

Source Code of com.cloudbees.sdk.pool.ServerPoolUpdate

/*
* Copyright 2010-2014, CloudBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cloudbees.sdk.pool;

import com.cloudbees.api.ServerInfo;
import com.cloudbees.api.ServerPoolInfo;
import com.cloudbees.sdk.cli.BeesCommand;
import com.cloudbees.sdk.cli.CLICommand;

import java.util.Map;

/**
* @author Fabian Donze
*/
@BeesCommand(group = "Server", description = "Update a server pool")
@CLICommand("app:pool:update")
public class ServerPoolUpdate extends ServerPoolBase {
    Boolean defaultOption;
    private String name;

    public ServerPoolUpdate() {
        super();
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getDefaultOption() {
        if (defaultOption == null) {
            Map<String, String> settings = getSettings();
            String str = settings.get("default");
            if (str != null) defaultOption = Boolean.valueOf(str);
        }
        return defaultOption;
    }

    public void setDefaultOption(Boolean defaultOption) {
        this.defaultOption = defaultOption;
    }

    public String getName() {
        if (name == null) {
            Map<String, String> settings = getSettings();
            name = settings.get("name");
        }
        return name;
    }

    @Override
    protected String getUsageMessage() {
        return "POOL_NAME";
    }

    @Override
    protected boolean preParseCommandLine() {
        if (super.preParseCommandLine()) {
            addOption( "n", "name", true, "The pool name/title" );
            addOption( null, "default", false, "To set the pool as the default deployment pool" );
        }
        return true;
    }

    @Override
    protected boolean execute() throws Exception {
        PoolClient client = getBeesClient(PoolClient.class);

        Map<String, String> settings = getSettings();
        if (getDefaultOption() != null) {
            settings.put("default", getDefaultOption().toString());
        }
        if (getName() != null) {
            settings.put("name", getName());
        }

        ServerPoolInfo poolInfo = client.serverPoolUpdate(getParameterID(), settings);
        if (isTextOutput()) {
            printPoolInfo(poolInfo, false);
        } else  printOutput(poolInfo, ServerInfo.class, ServerPoolInfo.class);

        return true;
    }
}
TOP

Related Classes of com.cloudbees.sdk.pool.ServerPoolUpdate

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.