Package com.cloudbees.sdk.pool

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

/*
* 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.BeesClient;
import com.cloudbees.api.ServerInfo;
import com.cloudbees.api.ServerPoolInfo;
import com.cloudbees.api.ServerPoolListResponse;
import com.cloudbees.sdk.cli.BeesCommand;
import com.cloudbees.sdk.cli.CLICommand;

/**
* @author Fabian Donze
*/
@BeesCommand(group = "Server", description = "List the available pools")
@CLICommand("app:pool:list")
public class ServerPoolList extends ServerPoolBase {
    private Boolean allPools;
    private Boolean allServers;

    public ServerPoolList() {
        super();
        setArgumentExpected(0);
    }

    public void setAllPools(Boolean allPools) {
        this.allPools = allPools;
    }

    protected boolean allPools() {
        return allPools == null ? false : allPools;
    }

    public void setAllServers(Boolean allServers) {
        this.allServers = allServers;
    }

    protected boolean allServers() {
        return allServers == null ? false : allServers;
    }

    @Override
    protected boolean preParseCommandLine() {
        if (super.preParseCommandLine()) {
            addOption( null, "allPools", false, "list all pools even deleted one" );
            addOption( null, "allServers", false, "list all servers even deleted one" );
        }
        return true;
    }

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

        ServerPoolListResponse res = client.serverPoolList(getAccount());
        if (isTextOutput()) {
            for (ServerPoolInfo poolInfo: res.getPools()) {
                if (allPools() || (poolInfo.getState() != null && poolInfo.getState().equalsIgnoreCase("active"))) {
                    printPoolInfo(poolInfo, allServers());
                    System.out.println();
                }
            }

        } else  printOutput(res, ServerInfo.class, ServerPoolInfo.class, ServerPoolListResponse.class);

        return true;
    }
}
TOP

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

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.