Search in sources :

Example 6 with AllocationState

use of com.cloud.model.enumeration.AllocationState 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 Hypervisor.HypervisorType hypervisorType = Hypervisor.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;
        }
    }
    Managed.ManagedState newManagedState = null;
    final Managed.ManagedState oldManagedState = cluster.getManagedState();
    if (managedstate != null && !managedstate.isEmpty()) {
        try {
            newManagedState = Managed.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) {
        _clusterDao.update(cluster.getId(), cluster);
    }
    if (newManagedState != null && !newManagedState.equals(oldManagedState)) {
        if (newManagedState.equals(Managed.ManagedState.Unmanaged)) {
            boolean success = false;
            try {
                cluster.setManagedState(Managed.ManagedState.PrepareUnmanaged);
                _clusterDao.update(cluster.getId(), cluster);
                List<HostVO> hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
                for (final HostVO host : hosts) {
                    if (host.getType().equals(Host.Type.Routing) && !host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.Up) && !host.getStatus().equals(Status.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(Status.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(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
                    for (final HostVO host : hosts) {
                        if (!host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.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 ? Managed.ManagedState.Unmanaged : Managed.ManagedState.PrepareUnmanagedError);
                _clusterDao.update(cluster.getId(), cluster);
            }
        } else if (newManagedState.equals(Managed.ManagedState.Managed)) {
            cluster.setManagedState(Managed.ManagedState.Managed);
            _clusterDao.update(cluster.getId(), cluster);
        }
    }
    return cluster;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Hypervisor(com.cloud.hypervisor.Hypervisor) PodCluster(com.cloud.dc.PodCluster) Cluster(com.cloud.org.Cluster) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) 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) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) AllocationState(com.cloud.model.enumeration.AllocationState) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Managed(com.cloud.org.Managed) DB(com.cloud.utils.db.DB)

Example 7 with AllocationState

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

the class StorageManagerImpl method createCapacityEntry.

@Override
public void createCapacityEntry(final StoragePoolVO storagePool, final short capacityType, final long allocated) {
    final SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
    capacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, storagePool.getId());
    capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, storagePool.getDataCenterId());
    capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
    final List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
    final long totalOverProvCapacity;
    if (storagePool.getPoolType() == StoragePoolType.NetworkFilesystem) {
        // All this is for the inaccuracy of floats for big number multiplication.
        final BigDecimal overProvFactor = getStorageOverProvisioningFactor(storagePool.getId());
        totalOverProvCapacity = overProvFactor.multiply(new BigDecimal(storagePool.getCapacityBytes())).longValue();
        s_logger.debug("Found storage pool " + storagePool.getName() + " of type " + storagePool.getPoolType().toString() + " with overprovisioning factor " + overProvFactor.toString());
        s_logger.debug("Total over provisioned capacity calculated is " + overProvFactor + " * " + storagePool.getCapacityBytes());
    } else {
        s_logger.debug("Found storage pool " + storagePool.getName() + " of type " + storagePool.getPoolType().toString());
        totalOverProvCapacity = storagePool.getCapacityBytes();
    }
    s_logger.debug("Total over provisioned capacity of the pool " + storagePool.getName() + " id: " + storagePool.getId() + " is " + totalOverProvCapacity);
    CapacityState capacityState = CapacityState.Enabled;
    if (storagePool.getScope() == ScopeType.ZONE) {
        final DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId());
        final AllocationState allocationState = dc.getAllocationState();
        capacityState = allocationState == AllocationState.Disabled ? CapacityState.Disabled : CapacityState.Enabled;
    } else {
        if (storagePool.getClusterId() != null) {
            final ClusterVO cluster = ApiDBUtils.findClusterById(storagePool.getClusterId());
            if (cluster != null) {
                final AllocationState allocationState = _configMgr.findClusterAllocationState(cluster);
                capacityState = allocationState == AllocationState.Disabled ? CapacityState.Disabled : CapacityState.Enabled;
            }
        }
    }
    if (capacities.size() == 0) {
        final CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(), storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType);
        capacity.setCapacityState(capacityState);
        _capacityDao.persist(capacity);
    } else {
        final CapacityVO capacity = capacities.get(0);
        if (capacity.getTotalCapacity() != totalOverProvCapacity || allocated != capacity.getUsedCapacity() || capacity.getCapacityState() != capacityState) {
            capacity.setTotalCapacity(totalOverProvCapacity);
            capacity.setUsedCapacity(allocated);
            capacity.setCapacityState(capacityState);
            _capacityDao.update(capacity.getId(), capacity);
        }
    }
    s_logger.debug("Successfully set Capacity - " + totalOverProvCapacity + " for capacity type - " + capacityType + " , DataCenterId - " + storagePool.getDataCenterId() + ", HostOrPoolId - " + storagePool.getId() + ", PodId " + storagePool.getPodId());
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) CapacityState(com.cloud.capacity.CapacityState) AllocationState(com.cloud.model.enumeration.AllocationState) CapacityVO(com.cloud.capacity.CapacityVO) BigDecimal(java.math.BigDecimal)

Aggregations

AllocationState (com.cloud.model.enumeration.AllocationState)7 DB (com.cloud.utils.db.DB)6 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 TransactionStatus (com.cloud.utils.db.TransactionStatus)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ClusterVO (com.cloud.dc.ClusterVO)3 HostPodVO (com.cloud.dc.HostPodVO)3 ConfigurationException (javax.naming.ConfigurationException)3 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)2 PodCluster (com.cloud.dc.PodCluster)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 DiscoveryException (com.cloud.exception.DiscoveryException)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 ResourceInUseException (com.cloud.exception.ResourceInUseException)2 HostVO (com.cloud.host.HostVO)2 Hypervisor (com.cloud.hypervisor.Hypervisor)2 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)2 Cluster (com.cloud.org.Cluster)2 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)2