Search in sources :

Example 81 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class ClusterDaoImpl method remove.

@Override
public boolean remove(final Long id) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    final ClusterVO cluster = createForUpdate();
    cluster.setName(null);
    cluster.setGuid(null);
    update(id, cluster);
    final boolean result = super.remove(id);
    txn.commit();
    return result;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ClusterVO(com.cloud.dc.ClusterVO)

Example 82 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class DiscovererBase method buildConfigParams.

protected HashMap<String, Object> buildConfigParams(final HostVO host) {
    final HashMap<String, Object> params = new HashMap<>(host.getDetails().size() + 5);
    params.putAll(host.getDetails());
    params.put("guid", host.getGuid());
    params.put("zone", Long.toString(host.getDataCenterId()));
    if (host.getPodId() != null) {
        params.put("pod", Long.toString(host.getPodId()));
    }
    if (host.getClusterId() != null) {
        params.put("cluster", Long.toString(host.getClusterId()));
        String guid = null;
        final ClusterVO cluster = _clusterDao.findById(host.getClusterId());
        if (cluster.getGuid() == null) {
            guid = host.getDetail("pool");
        } else {
            guid = cluster.getGuid();
        }
        if (guid != null && !guid.isEmpty()) {
            params.put("pool", guid);
        }
    }
    params.put("ipaddress", host.getPrivateIpAddress());
    params.put("secondary.storage.vm", "false");
    params.put("max.template.iso.size", _configDao.getValue(Config.MaxTemplateAndIsoSize.toString()));
    params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString()));
    params.put(Config.XenServerMaxNics.toString().toLowerCase(), _configDao.getValue(Config.XenServerMaxNics.toString()));
    params.put(Config.XenServerHeartBeatInterval.toString().toLowerCase(), _configDao.getValue(Config.XenServerHeartBeatInterval.toString()));
    params.put(Config.XenServerHeartBeatTimeout.toString().toLowerCase(), _configDao.getValue(Config.XenServerHeartBeatTimeout.toString()));
    params.put("router.aggregation.command.each.timeout", _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString()));
    return params;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) HashMap(java.util.HashMap)

Example 83 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method listByDataCenter.

@Override
public List<PodCluster> listByDataCenter(final long dcId) {
    final List<HostPodVO> pods = _podDao.listByDataCenterId(dcId);
    final ArrayList<PodCluster> pcs = new ArrayList<>();
    for (final HostPodVO pod : pods) {
        final List<ClusterVO> clusters = _clusterDao.listByPodId(pod.getId());
        if (clusters.size() == 0) {
            pcs.add(new PodCluster(pod, null));
        } else {
            for (final ClusterVO cluster : clusters) {
                pcs.add(new PodCluster(pod, cluster));
            }
        }
    }
    return pcs;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) PodCluster(com.cloud.dc.PodCluster)

Example 84 with ClusterVO

use of com.cloud.dc.ClusterVO 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(_dcDao).accountManager(_accountMgr).hostPodDao(_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 = _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 (_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 Hypervisor.HypervisorType hypervisorType = Hypervisor.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 = _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());
        _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());
    _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, _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) {
            _clusterDetailsDao.deleteDetails(cluster.getId());
            _clusterDao.remove(cluster.getId());
        }
    }
}
Also used : Account(com.cloud.user.Account) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HostPodVO(com.cloud.dc.HostPodVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DiscoveryException(com.cloud.exception.DiscoveryException) DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) Hypervisor(com.cloud.hypervisor.Hypervisor) PodCluster(com.cloud.dc.PodCluster) Cluster(com.cloud.org.Cluster) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) SshException(com.cloud.utils.ssh.SshException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) AllocationState(com.cloud.model.enumeration.AllocationState) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Map(java.util.Map) HashMap(java.util.HashMap) DB(com.cloud.utils.db.DB)

Example 85 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method discoverHosts.

@Override
public List<? extends Host> discoverHosts(final AddHostCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
    Long dcId = cmd.getZoneId();
    final Long podId = cmd.getPodId();
    final Long clusterId = cmd.getClusterId();
    String clusterName = cmd.getClusterName();
    final String url = cmd.getUrl();
    final String username = cmd.getUsername();
    final String password = cmd.getPassword();
    final List<String> hostTags = cmd.getHostTags();
    dcId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), dcId);
    // this is for standalone option
    if (clusterName == null && clusterId == null) {
        clusterName = "Standalone-" + url;
    }
    if (clusterId != null) {
        final ClusterVO cluster = _clusterDao.findById(clusterId);
        if (cluster == null) {
            final InvalidParameterValueException ex = new InvalidParameterValueException("can not find cluster for specified clusterId");
            ex.addProxyObject(clusterId.toString(), "clusterId");
            throw ex;
        } else {
            if (cluster.getGuid() == null) {
                final List<HostVO> hosts = listAllHostsInCluster(clusterId);
                if (!hosts.isEmpty()) {
                    final CloudRuntimeException ex = new CloudRuntimeException("Guid is not updated for cluster with specified cluster id; need to wait for hosts in this cluster to come up");
                    ex.addProxyObject(cluster.getUuid(), "clusterId");
                    throw ex;
                }
            }
        }
    }
    return discoverHostsFull(dcId, podId, clusterId, clusterName, url, username, password, cmd.getHypervisor(), hostTags, cmd.getFullUrlParams(), false);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Aggregations

ClusterVO (com.cloud.dc.ClusterVO)151 HostVO (com.cloud.host.HostVO)72 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)66 ArrayList (java.util.ArrayList)55 HostPodVO (com.cloud.dc.HostPodVO)46 DataCenterVO (com.cloud.dc.DataCenterVO)38 ConfigurationException (javax.naming.ConfigurationException)37 HashMap (java.util.HashMap)28 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)24 Map (java.util.Map)24 DiscoveryException (com.cloud.exception.DiscoveryException)21 DB (com.cloud.utils.db.DB)21 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)20 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 Account (com.cloud.user.Account)17 List (java.util.List)17 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)17 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)16 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)15 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)14