Search in sources :

Example 1 with ManagedState

use of com.cloud.model.enumeration.ManagedState in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method updateCluster.

@Override
@DB
public Cluster updateCluster(final Cluster clusterToUpdate, final String clusterType, final String hypervisor, final String allocationState, final String managedstate) {
    final ClusterVO cluster = (ClusterVO) clusterToUpdate;
    // Verify cluster information and update the cluster if needed
    boolean doUpdate = false;
    if (hypervisor != null && !hypervisor.isEmpty()) {
        final HypervisorType hypervisorType = HypervisorType.getType(hypervisor);
        if (hypervisorType == null) {
            s_logger.error("Unable to resolve " + hypervisor + " to a valid supported hypervisor type");
            throw new InvalidParameterValueException("Unable to resolve " + hypervisor + " to a supported type");
        } else {
            cluster.setHypervisorType(hypervisor);
            doUpdate = true;
        }
    }
    final Cluster.ClusterType newClusterType;
    if (clusterType != null && !clusterType.isEmpty()) {
        try {
            newClusterType = Cluster.ClusterType.valueOf(clusterType);
        } catch (final IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve " + clusterType + " to a supported type");
        }
        if (newClusterType == null) {
            s_logger.error("Unable to resolve " + clusterType + " to a valid supported cluster type");
            throw new InvalidParameterValueException("Unable to resolve " + clusterType + " to a supported type");
        } else {
            cluster.setClusterType(newClusterType);
            doUpdate = true;
        }
    }
    final AllocationState newAllocationState;
    if (allocationState != null && !allocationState.isEmpty()) {
        try {
            newAllocationState = AllocationState.valueOf(allocationState);
        } catch (final IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationState + "' to a supported state");
        }
        if (newAllocationState == null) {
            s_logger.error("Unable to resolve " + allocationState + " to a valid supported allocation State");
            throw new InvalidParameterValueException("Unable to resolve " + allocationState + " to a supported state");
        } else {
            cluster.setAllocationState(newAllocationState);
            doUpdate = true;
        }
    }
    ManagedState newManagedState = null;
    final ManagedState oldManagedState = cluster.getManagedState();
    if (managedstate != null && !managedstate.isEmpty()) {
        try {
            newManagedState = ManagedState.valueOf(managedstate);
        } catch (final IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve Managed State '" + managedstate + "' to a supported state");
        }
        if (newManagedState == null) {
            s_logger.error("Unable to resolve Managed State '" + managedstate + "' to a supported state");
            throw new InvalidParameterValueException("Unable to resolve Managed State '" + managedstate + "' to a supported state");
        } else {
            doUpdate = true;
        }
    }
    if (doUpdate) {
        this._clusterDao.update(cluster.getId(), cluster);
    }
    if (newManagedState != null && !newManagedState.equals(oldManagedState)) {
        if (newManagedState.equals(ManagedState.Unmanaged)) {
            boolean success = false;
            try {
                cluster.setManagedState(ManagedState.PrepareUnmanaged);
                this._clusterDao.update(cluster.getId(), cluster);
                List<HostVO> hosts = listAllUpAndEnabledHosts(HostType.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
                for (final HostVO host : hosts) {
                    if (host.getType().equals(HostType.Routing) && !host.getStatus().equals(HostStatus.Down) && !host.getStatus().equals(HostStatus.Disconnected) && !host.getStatus().equals(HostStatus.Up) && !host.getStatus().equals(HostStatus.Alert)) {
                        final String msg = "host " + host.getPrivateIpAddress() + " should not be in " + host.getStatus().toString() + " status";
                        throw new CloudRuntimeException("PrepareUnmanaged Failed due to " + msg);
                    }
                }
                for (final HostVO host : hosts) {
                    if (host.getStatus().equals(HostStatus.Up)) {
                        umanageHost(host.getId());
                    }
                }
                final int retry = 40;
                boolean lsuccess;
                for (int i = 0; i < retry; i++) {
                    lsuccess = true;
                    try {
                        Thread.sleep(5 * 1000);
                    } catch (final Exception e) {
                    }
                    hosts = listAllUpAndEnabledHosts(HostType.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
                    for (final HostVO host : hosts) {
                        if (!host.getStatus().equals(HostStatus.Down) && !host.getStatus().equals(HostStatus.Disconnected) && !host.getStatus().equals(HostStatus.Alert)) {
                            lsuccess = false;
                            break;
                        }
                    }
                    if (lsuccess == true) {
                        success = true;
                        break;
                    }
                }
                if (success == false) {
                    throw new CloudRuntimeException("PrepareUnmanaged Failed due to some hosts are still in UP status after 5 Minutes, please try later ");
                }
            } finally {
                cluster.setManagedState(success ? ManagedState.Unmanaged : ManagedState.PrepareUnmanagedError);
                this._clusterDao.update(cluster.getId(), cluster);
            }
        } else if (newManagedState.equals(ManagedState.Managed)) {
            cluster.setManagedState(ManagedState.Managed);
            this._clusterDao.update(cluster.getId(), cluster);
        }
    }
    return cluster;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) PodCluster(com.cloud.dc.PodCluster) Cluster(com.cloud.legacymodel.dc.Cluster) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) 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) HypervisorType(com.cloud.model.enumeration.HypervisorType) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) AllocationState(com.cloud.model.enumeration.AllocationState) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ManagedState(com.cloud.model.enumeration.ManagedState) DB(com.cloud.utils.db.DB)

Aggregations

ClusterVO (com.cloud.dc.ClusterVO)1 PodCluster (com.cloud.dc.PodCluster)1 HostVO (com.cloud.host.HostVO)1 Cluster (com.cloud.legacymodel.dc.Cluster)1 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 DiscoveryException (com.cloud.legacymodel.exceptions.DiscoveryException)1 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)1 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)1 ResourceInUseException (com.cloud.legacymodel.exceptions.ResourceInUseException)1 UnableDeleteHostException (com.cloud.legacymodel.exceptions.UnableDeleteHostException)1 AllocationState (com.cloud.model.enumeration.AllocationState)1 HypervisorType (com.cloud.model.enumeration.HypervisorType)1 ManagedState (com.cloud.model.enumeration.ManagedState)1 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)1 DB (com.cloud.utils.db.DB)1 SshException (com.cloud.utils.ssh.SshException)1 URISyntaxException (java.net.URISyntaxException)1 ConfigurationException (javax.naming.ConfigurationException)1