Search in sources :

Example 11 with Cluster

use of com.cloud.org.Cluster 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 12 with Cluster

use of com.cloud.org.Cluster 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 13 with Cluster

use of com.cloud.org.Cluster 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)

Example 14 with Cluster

use of com.cloud.org.Cluster in project cloudstack by apache.

the class VolumeServiceImpl method getHost.

private HostVO getHost(Long zoneId, HypervisorType hypervisorType, boolean computeClusterMustSupportResign) {
    if (zoneId == null) {
        throw new CloudRuntimeException("Zone ID cannot be null.");
    }
    List<? extends Cluster> clusters = mgr.searchForClusters(zoneId, new Long(0), Long.MAX_VALUE, hypervisorType.toString());
    if (clusters == null) {
        clusters = new ArrayList<>();
    }
    Collections.shuffle(clusters, new Random(System.nanoTime()));
    clusters: for (Cluster cluster : clusters) {
        if (cluster.getAllocationState() == AllocationState.Enabled) {
            List<HostVO> hosts = _hostDao.findByClusterId(cluster.getId());
            if (hosts != null) {
                Collections.shuffle(hosts, new Random(System.nanoTime()));
                for (HostVO host : hosts) {
                    if (host.getResourceState() == ResourceState.Enabled) {
                        if (computeClusterMustSupportResign) {
                            if (clusterDao.getSupportsResigning(cluster.getId())) {
                                return host;
                            } else {
                                // no other host in the cluster in question should be able to satisfy our requirements here, so move on to the next cluster
                                continue clusters;
                            }
                        } else {
                            return host;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : Random(java.util.Random) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Cluster(com.cloud.org.Cluster) List(java.util.List) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO)

Example 15 with Cluster

use of com.cloud.org.Cluster in project cloudstack by apache.

the class DisableOutOfBandManagementForClusterCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public final void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    final Cluster cluster = _resourceService.getCluster(getClusterId());
    if (cluster == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find cluster by ID: " + getClusterId());
    }
    OutOfBandManagementResponse response = outOfBandManagementService.disableOutOfBandManagement(cluster);
    CallContext.current().setEventDetails("Cluster Id:" + cluster.getId() + " out-of-band management enabled: false");
    CallContext.current().putContextParameter(Cluster.class, cluster.getUuid());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Cluster(com.cloud.org.Cluster)

Aggregations

Cluster (com.cloud.org.Cluster)26 ArrayList (java.util.ArrayList)13 HostVO (com.cloud.host.HostVO)8 ServerApiException (org.apache.cloudstack.api.ServerApiException)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 DataCenter (com.cloud.dc.DataCenter)5 Pod (com.cloud.dc.Pod)5 DeployDestination (com.cloud.deploy.DeployDestination)5 DataCenterVO (com.cloud.dc.DataCenterVO)4 DiscoveryException (com.cloud.exception.DiscoveryException)4 ResourceInUseException (com.cloud.exception.ResourceInUseException)4 Host (com.cloud.host.Host)4 StoragePool (com.cloud.storage.StoragePool)4 ClusterResponse (org.apache.cloudstack.api.response.ClusterResponse)4 ClusterResponse (com.cloud.api.response.ClusterResponse)3 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)3 ClusterVO (com.cloud.dc.ClusterVO)3 List (java.util.List)3 ServerApiException (com.cloud.api.ServerApiException)2