Search in sources :

Example 1 with IdentityProxy

use of com.cloud.utils.IdentityProxy 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)

Aggregations

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