Search in sources :

Example 11 with Cluster

use of com.cloud.legacymodel.dc.Cluster in project cosmic by MissionCriticalCloud.

the class VmWorkMigrate method getDeployDestination.

public DeployDestination getDeployDestination() {
    final Zone zone = zoneId != null ? s_zoneRepository.findById(zoneId).orElse(null) : null;
    final Pod pod = podId != null ? s_entityMgr.findById(Pod.class, podId) : null;
    final Cluster cluster = clusterId != null ? s_entityMgr.findById(Cluster.class, clusterId) : null;
    final Host host = hostId != null ? s_entityMgr.findById(Host.class, hostId) : null;
    Map<Volume, StoragePool> vols = null;
    if (storage != null) {
        vols = new HashMap<>(storage.size());
        for (final Map.Entry<String, String> entry : storage.entrySet()) {
            vols.put(s_entityMgr.findByUuid(Volume.class, entry.getKey()), s_entityMgr.findByUuid(StoragePool.class, entry.getValue()));
        }
    }
    final DeployDestination dest = new DeployDestination(zone, pod, cluster, host, vols);
    return dest;
}
Also used : StoragePool(com.cloud.legacymodel.storage.StoragePool) Pod(com.cloud.legacymodel.dc.Pod) Volume(com.cloud.legacymodel.storage.Volume) Zone(com.cloud.db.model.Zone) DeployDestination(com.cloud.deploy.DeployDestination) Cluster(com.cloud.legacymodel.dc.Cluster) Host(com.cloud.legacymodel.dc.Host) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with Cluster

use of com.cloud.legacymodel.dc.Cluster in project cosmic by MissionCriticalCloud.

the class AddClusterCmd method execute.

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

Example 13 with Cluster

use of com.cloud.legacymodel.dc.Cluster in project cosmic by MissionCriticalCloud.

the class ListClustersCmd method execute.

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

Example 14 with Cluster

use of com.cloud.legacymodel.dc.Cluster in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method findStoragePool.

@Override
public StoragePool findStoragePool(final DiskProfile dskCh, final DataCenter dc, final Pod pod, final Long clusterId, final Long hostId, final VirtualMachine vm, final Set<StoragePool> avoid) {
    Long podId = null;
    if (pod != null) {
        podId = pod.getId();
    } else if (clusterId != null) {
        final Cluster cluster = this._entityMgr.findById(Cluster.class, clusterId);
        if (cluster != null) {
            podId = cluster.getPodId();
        }
    }
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    for (final StoragePoolAllocator allocator : this._storagePoolAllocators) {
        final ExcludeList avoidList = new ExcludeList();
        for (final StoragePool pool : avoid) {
            avoidList.addPool(pool.getId());
        }
        final DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), podId, clusterId, hostId, null, null);
        final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, 1);
        if (poolList != null && !poolList.isEmpty()) {
            return (StoragePool) this.dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
        }
    }
    return null;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.legacymodel.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) Cluster(com.cloud.legacymodel.dc.Cluster) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) StoragePoolAllocator(com.cloud.engine.subsystem.api.storage.StoragePoolAllocator)

Example 15 with Cluster

use of com.cloud.legacymodel.dc.Cluster in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method discoverCluster.

@DB
@Override
public List<? extends Cluster> discoverCluster(final AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException {
    final ResourceChecker resourceChecker = ResourceChecker.builder().dataCenterDao(this._dcDao).accountManager(this._accountMgr).hostPodDao(this._podDao).build();
    final long dcId = cmd.getZoneId();
    final long podId = cmd.getPodId();
    final String clusterName = cmd.getClusterName();
    String url = cmd.getUrl();
    final String username = cmd.getUsername();
    final String password = cmd.getPassword();
    if (url != null) {
        url = URLDecoder.decode(url);
    }
    final URI uri;
    final DataCenterVO zone = resourceChecker.checkIfDataCenterExists(dcId);
    final Account account = CallContext.current().getCallingAccount();
    resourceChecker.checkIfDataCenterIsUsable(zone, account);
    final HostPodVO pod = this._podDao.findById(podId);
    if (pod == null) {
        throw new InvalidParameterValueException("Can't find pod with specified podId " + podId);
    }
    // Check if the pod exists in the system
    if (this._podDao.findById(podId) == null) {
        throw new InvalidParameterValueException("Can't find pod by id " + podId);
    }
    // check if pod belongs to the zone
    if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified id doesn't belong to the zone " + dcId);
        ex.addProxyObject(pod.getUuid(), "podId");
        ex.addProxyObject(zone.getUuid(), "dcId");
        throw ex;
    }
    // Verify cluster information and create a new cluster if needed
    if (clusterName == null || clusterName.isEmpty()) {
        throw new InvalidParameterValueException("Please specify cluster name");
    }
    if (cmd.getHypervisor() == null || cmd.getHypervisor().isEmpty()) {
        throw new InvalidParameterValueException("Please specify a hypervisor");
    }
    final HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor());
    if (hypervisorType == null) {
        s_logger.error("Unable to resolve " + cmd.getHypervisor() + " to a valid supported hypervisor type");
        throw new InvalidParameterValueException("Unable to resolve " + cmd.getHypervisor() + " to a supported ");
    }
    Cluster.ClusterType clusterType = null;
    if (cmd.getClusterType() != null && !cmd.getClusterType().isEmpty()) {
        clusterType = Cluster.ClusterType.valueOf(cmd.getClusterType());
    }
    if (clusterType == null) {
        clusterType = Cluster.ClusterType.CloudManaged;
    }
    AllocationState allocationState = null;
    if (cmd.getAllocationState() != null && !cmd.getAllocationState().isEmpty()) {
        try {
            allocationState = AllocationState.valueOf(cmd.getAllocationState());
        } catch (final IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve Allocation State '" + cmd.getAllocationState() + "' to a supported state");
        }
    }
    if (allocationState == null) {
        allocationState = AllocationState.Enabled;
    }
    final Discoverer discoverer = getMatchingDiscover(hypervisorType);
    if (discoverer == null) {
        throw new InvalidParameterValueException("Could not find corresponding resource manager for " + cmd.getHypervisor());
    }
    final List<ClusterVO> result = new ArrayList<>();
    ClusterVO cluster = new ClusterVO(dcId, podId, clusterName);
    cluster.setHypervisorType(hypervisorType.toString());
    cluster.setClusterType(clusterType);
    cluster.setAllocationState(allocationState);
    try {
        cluster = this._clusterDao.persist(cluster);
    } catch (final Exception e) {
        // no longer tolerate exception during the cluster creation phase
        final CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod and data center with specified ids", e);
        // Get the pod VO object's table name.
        ex.addProxyObject(pod.getUuid(), "podId");
        ex.addProxyObject(zone.getUuid(), "dcId");
        throw ex;
    }
    result.add(cluster);
    if (clusterType == Cluster.ClusterType.CloudManaged) {
        final Map<String, String> details = new HashMap<>();
        details.put("cpuOvercommitRatio", CapacityManager.CpuOverprovisioningFactor.value().toString());
        details.put("memoryOvercommitRatio", CapacityManager.MemOverprovisioningFactor.value().toString());
        this._clusterDetailsDao.persist(cluster.getId(), details);
        return result;
    }
    // save cluster details for later cluster/host cross-checking
    final Map<String, String> details = new HashMap<>();
    details.put("url", url);
    details.put("username", username);
    details.put("password", password);
    details.put("cpuOvercommitRatio", CapacityManager.CpuOverprovisioningFactor.value().toString());
    details.put("memoryOvercommitRatio", CapacityManager.MemOverprovisioningFactor.value().toString());
    this._clusterDetailsDao.persist(cluster.getId(), details);
    boolean success = false;
    try {
        try {
            uri = new URI(UriUtils.encodeURIComponent(url));
            if (uri.getScheme() == null) {
                throw new InvalidParameterValueException("uri.scheme is null " + url + ", add http:// as a prefix");
            } else if (uri.getScheme().equalsIgnoreCase("http")) {
                if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) {
                    throw new InvalidParameterValueException("Your host and/or path is wrong.  Make sure it's of the format http://hostname/path");
                }
            }
        } catch (final URISyntaxException e) {
            throw new InvalidParameterValueException(url + " is not a valid uri");
        }
        final List<HostVO> hosts = new ArrayList<>();
        final Map<? extends ServerResource, Map<String, String>> resources;
        resources = discoverer.find(dcId, podId, cluster.getId(), uri, username, password, null);
        if (resources != null) {
            for (final Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
                final ServerResource resource = entry.getKey();
                final HostVO host = (HostVO) createHostAndAgent(resource, entry.getValue(), true, null, false);
                if (host != null) {
                    hosts.add(host);
                }
                discoverer.postDiscovery(hosts, this._nodeId);
            }
            s_logger.info("External cluster has been successfully discovered by " + discoverer.getName());
            success = true;
            return result;
        }
        s_logger.warn("Unable to find the server resources at " + url);
        throw new DiscoveryException("Unable to add the external cluster");
    } finally {
        if (!success) {
            this._clusterDetailsDao.deleteDetails(cluster.getId());
            this._clusterDao.remove(cluster.getId());
        }
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServerResource(com.cloud.common.resource.ServerResource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HostPodVO(com.cloud.dc.HostPodVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DiscoveryException(com.cloud.legacymodel.exceptions.DiscoveryException) DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) PodCluster(com.cloud.dc.PodCluster) Cluster(com.cloud.legacymodel.dc.Cluster) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) ResourceInUseException(com.cloud.legacymodel.exceptions.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) SshException(com.cloud.utils.ssh.SshException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.legacymodel.exceptions.UnableDeleteHostException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DiscoveryException(com.cloud.legacymodel.exceptions.DiscoveryException) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) HypervisorType(com.cloud.model.enumeration.HypervisorType) AllocationState(com.cloud.model.enumeration.AllocationState) Map(java.util.Map) HashMap(java.util.HashMap) DB(com.cloud.utils.db.DB)

Aggregations

Cluster (com.cloud.legacymodel.dc.Cluster)16 HostVO (com.cloud.host.HostVO)7 Zone (com.cloud.db.model.Zone)6 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)6 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)5 ArrayList (java.util.ArrayList)5 DeployDestination (com.cloud.deploy.DeployDestination)4 Pod (com.cloud.legacymodel.dc.Pod)4 StoragePool (com.cloud.legacymodel.storage.StoragePool)4 ClusterResponse (com.cloud.api.response.ClusterResponse)3 HostPodVO (com.cloud.dc.HostPodVO)3 Host (com.cloud.legacymodel.dc.Host)3 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)3 DiscoveryException (com.cloud.legacymodel.exceptions.DiscoveryException)3 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)3 ResourceInUseException (com.cloud.legacymodel.exceptions.ResourceInUseException)3 Volume (com.cloud.legacymodel.storage.Volume)3 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3