Search in sources :

Example 1 with ClusterResponse

use of com.cloud.api.response.ClusterResponse in project CloudStack-archive by CloudStack-extras.

the class AddClusterCmd method execute.

@Override
public void execute() {
    try {
        List<? extends Cluster> result = _resourceService.discoverCluster(this);
        ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
        List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
        if (result != null) {
            for (Cluster cluster : result) {
                ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
                clusterResponses.add(clusterResponse);
            }
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add cluster");
        }
        response.setResponses(clusterResponses);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (ResourceInUseException ex) {
        s_logger.warn("Exception: ", ex);
        ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
        for (IdentityProxy proxyObj : ex.getIdProxyList()) {
            e.addProxyObject(proxyObj.getTableName(), proxyObj.getValue(), proxyObj.getidFieldName());
        }
        throw e;
    }
}
Also used : IdentityProxy(com.cloud.utils.IdentityProxy) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) ResourceInUseException(com.cloud.exception.ResourceInUseException) ArrayList(java.util.ArrayList) ClusterResponse(com.cloud.api.response.ClusterResponse) Cluster(com.cloud.org.Cluster) DiscoveryException(com.cloud.exception.DiscoveryException)

Example 2 with ClusterResponse

use of com.cloud.api.response.ClusterResponse in project CloudStack-archive by CloudStack-extras.

the class ListClustersCmd method execute.

@Override
public void execute() {
    List<? extends Cluster> result = _mgr.searchForClusters(this);
    ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
    List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
    for (Cluster cluster : result) {
        ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, showCapacities);
        clusterResponse.setObjectName("cluster");
        clusterResponses.add(clusterResponse);
    }
    response.setResponses(clusterResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) ClusterResponse(com.cloud.api.response.ClusterResponse) Cluster(com.cloud.org.Cluster)

Example 3 with ClusterResponse

use of com.cloud.api.response.ClusterResponse in project CloudStack-archive by CloudStack-extras.

the class UpdateClusterCmd method execute.

@Override
public void execute() {
    Cluster cluster = _resourceService.getCluster(getId());
    if (cluster == null) {
        throw new InvalidParameterValueException("Unable to find the cluster by id=" + getId());
    }
    Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate());
    if (result != null) {
        ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
        clusterResponse.setResponseName(getCommandName());
        this.setResponseObject(clusterResponse);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update cluster");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Cluster(com.cloud.org.Cluster) ClusterResponse(com.cloud.api.response.ClusterResponse)

Aggregations

ClusterResponse (com.cloud.api.response.ClusterResponse)3 Cluster (com.cloud.org.Cluster)3 ServerApiException (com.cloud.api.ServerApiException)2 ListResponse (com.cloud.api.response.ListResponse)2 ArrayList (java.util.ArrayList)2 DiscoveryException (com.cloud.exception.DiscoveryException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ResourceInUseException (com.cloud.exception.ResourceInUseException)1 IdentityProxy (com.cloud.utils.IdentityProxy)1