Search in sources :

Example 1 with CapacityState

use of com.cloud.capacity.CapacityState in project cosmic by MissionCriticalCloud.

the class AlertManagerImpl method createOrUpdateIpCapacity.

public void createOrUpdateIpCapacity(final Long dcId, final Long podId, final short capacityType, final AllocationState capacityState) {
    SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
    List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
    capacitySC = _capacityDao.createSearchCriteria();
    capacitySC.addAnd("podId", SearchCriteria.Op.EQ, podId);
    capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, dcId);
    capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
    final int totalIPs;
    final int allocatedIPs;
    capacities = _capacityDao.search(capacitySC, null);
    if (capacityType == Capacity.CAPACITY_TYPE_PRIVATE_IP) {
        totalIPs = _privateIPAddressDao.countIPs(podId, dcId, false);
        allocatedIPs = _privateIPAddressDao.countIPs(podId, dcId, true);
    } else if (capacityType == Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP) {
        totalIPs = _publicIPAddressDao.countIPsForNetwork(dcId, false, VlanType.VirtualNetwork);
        allocatedIPs = _publicIPAddressDao.countIPsForNetwork(dcId, true, VlanType.VirtualNetwork);
    } else {
        totalIPs = _publicIPAddressDao.countIPsForNetwork(dcId, false, VlanType.DirectAttached);
        allocatedIPs = _publicIPAddressDao.countIPsForNetwork(dcId, true, VlanType.DirectAttached);
    }
    final CapacityState ipCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
    if (capacities.size() == 0) {
        final CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedIPs, totalIPs, capacityType);
        newPublicIPCapacity.setCapacityState(ipCapacityState);
        _capacityDao.persist(newPublicIPCapacity);
    } else if (!(capacities.get(0).getUsedCapacity() == allocatedIPs && capacities.get(0).getTotalCapacity() == totalIPs && capacities.get(0).getCapacityState() == ipCapacityState)) {
        final CapacityVO capacity = capacities.get(0);
        capacity.setUsedCapacity(allocatedIPs);
        capacity.setTotalCapacity(totalIPs);
        capacity.setCapacityState(ipCapacityState);
        _capacityDao.update(capacity.getId(), capacity);
    }
}
Also used : CapacityState(com.cloud.capacity.CapacityState) CapacityVO(com.cloud.capacity.CapacityVO)

Example 2 with CapacityState

use of com.cloud.capacity.CapacityState in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method resourceStateTransitTo.

@Override
public boolean resourceStateTransitTo(final Host host, final ResourceState.Event event, final long msId) throws NoTransitionException {
    final ResourceState currentState = host.getResourceState();
    final ResourceState nextState = currentState.getNextState(event);
    if (nextState == null) {
        throw new NoTransitionException("No next resource state found for current state = " + currentState + " event = " + event);
    }
    // TO DO - Make it more granular and have better conversion into capacity type
    if (host.getType() == Type.Routing) {
        final CapacityState capacityState = nextState == ResourceState.Enabled ? CapacityState.Enabled : CapacityState.Disabled;
        final short[] capacityTypes = { Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY };
        _capacityDao.updateCapacityState(null, null, null, host.getId(), capacityState.toString(), capacityTypes);
    }
    return _hostDao.updateResourceState(currentState, event, nextState, host);
}
Also used : CapacityState(com.cloud.capacity.CapacityState) NoTransitionException(com.cloud.utils.fsm.NoTransitionException)

Example 3 with CapacityState

use of com.cloud.capacity.CapacityState in project cloudstack by apache.

the class ResourceManagerImpl method resourceStateTransitTo.

@Override
public boolean resourceStateTransitTo(final Host host, final ResourceState.Event event, final long msId) throws NoTransitionException {
    final ResourceState currentState = host.getResourceState();
    final ResourceState nextState = currentState.getNextState(event);
    if (nextState == null) {
        throw new NoTransitionException("No next resource state found for current state = " + currentState + " event = " + event);
    }
    // TO DO - Make it more granular and have better conversion into capacity type
    if (host.getType() == Type.Routing) {
        final CapacityState capacityState = nextState == ResourceState.Enabled ? CapacityState.Enabled : CapacityState.Disabled;
        final short[] capacityTypes = { Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY, Capacity.CAPACITY_TYPE_CPU_CORE };
        _capacityDao.updateCapacityState(null, null, null, host.getId(), capacityState.toString(), capacityTypes);
        final StoragePoolVO storagePool = _storageMgr.findLocalStorageOnHost(host.getId());
        if (storagePool != null) {
            final short[] capacityTypesLocalStorage = { Capacity.CAPACITY_TYPE_LOCAL_STORAGE };
            _capacityDao.updateCapacityState(null, null, null, storagePool.getId(), capacityState.toString(), capacityTypesLocalStorage);
        }
    }
    return _hostDao.updateResourceState(currentState, event, nextState, host);
}
Also used : CapacityState(com.cloud.capacity.CapacityState) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 4 with CapacityState

use of com.cloud.capacity.CapacityState in project cloudstack by apache.

the class AlertManagerImpl method createOrUpdateVlanCapacity.

private void createOrUpdateVlanCapacity(long dcId, AllocationState capacityState) {
    SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
    List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
    capacitySC = _capacityDao.createSearchCriteria();
    capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, dcId);
    capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, Capacity.CAPACITY_TYPE_VLAN);
    capacities = _capacityDao.search(capacitySC, null);
    int totalVlans = _dcDao.countZoneVlans(dcId, false);
    int allocatedVlans = _dcDao.countZoneVlans(dcId, true);
    CapacityState vlanCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
    if (capacities.size() == 0) {
        CapacityVO newVlanCapacity = new CapacityVO(null, dcId, null, null, allocatedVlans, totalVlans, Capacity.CAPACITY_TYPE_VLAN);
        newVlanCapacity.setCapacityState(vlanCapacityState);
        _capacityDao.persist(newVlanCapacity);
    } else if (!(capacities.get(0).getUsedCapacity() == allocatedVlans && capacities.get(0).getTotalCapacity() == totalVlans && capacities.get(0).getCapacityState() == vlanCapacityState)) {
        CapacityVO capacity = capacities.get(0);
        capacity.setUsedCapacity(allocatedVlans);
        capacity.setTotalCapacity(totalVlans);
        capacity.setCapacityState(vlanCapacityState);
        _capacityDao.update(capacity.getId(), capacity);
    }
}
Also used : CapacityState(com.cloud.capacity.CapacityState) CapacityVO(com.cloud.capacity.CapacityVO)

Example 5 with CapacityState

use of com.cloud.capacity.CapacityState in project cloudstack by apache.

the class AlertManagerImpl method createOrUpdateIpCapacity.

public void createOrUpdateIpCapacity(Long dcId, Long podId, short capacityType, AllocationState capacityState) {
    SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
    List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
    capacitySC = _capacityDao.createSearchCriteria();
    capacitySC.addAnd("podId", SearchCriteria.Op.EQ, podId);
    capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, dcId);
    capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
    int totalIPs;
    int allocatedIPs;
    capacities = _capacityDao.search(capacitySC, null);
    if (capacityType == Capacity.CAPACITY_TYPE_PRIVATE_IP) {
        totalIPs = _privateIPAddressDao.countIPs(podId, dcId, false);
        allocatedIPs = _privateIPAddressDao.countIPs(podId, dcId, true);
    } else if (capacityType == Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP) {
        totalIPs = _publicIPAddressDao.countIPsForNetwork(dcId, false, VlanType.VirtualNetwork);
        allocatedIPs = _publicIPAddressDao.countIPsForNetwork(dcId, true, VlanType.VirtualNetwork);
    } else {
        totalIPs = _publicIPAddressDao.countIPsForNetwork(dcId, false, VlanType.DirectAttached);
        allocatedIPs = _publicIPAddressDao.countIPsForNetwork(dcId, true, VlanType.DirectAttached);
    }
    CapacityState ipCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
    if (capacities.size() == 0) {
        CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedIPs, totalIPs, capacityType);
        newPublicIPCapacity.setCapacityState(ipCapacityState);
        _capacityDao.persist(newPublicIPCapacity);
    } else if (!(capacities.get(0).getUsedCapacity() == allocatedIPs && capacities.get(0).getTotalCapacity() == totalIPs && capacities.get(0).getCapacityState() == ipCapacityState)) {
        CapacityVO capacity = capacities.get(0);
        capacity.setUsedCapacity(allocatedIPs);
        capacity.setTotalCapacity(totalIPs);
        capacity.setCapacityState(ipCapacityState);
        _capacityDao.update(capacity.getId(), capacity);
    }
}
Also used : CapacityState(com.cloud.capacity.CapacityState) CapacityVO(com.cloud.capacity.CapacityVO)

Aggregations

CapacityState (com.cloud.capacity.CapacityState)8 CapacityVO (com.cloud.capacity.CapacityVO)6 ClusterVO (com.cloud.dc.ClusterVO)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)2 BigDecimal (java.math.BigDecimal)2 HostVO (com.cloud.host.HostVO)1 AllocationState (com.cloud.model.enumeration.AllocationState)1 AllocationState (com.cloud.org.Grouping.AllocationState)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1