Search in sources :

Example 1 with ResourceState

use of com.cloud.legacymodel.resource.ResourceState 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() == HostType.Routing) {
        final CapacityState capacityState = nextState == ResourceState.Enabled ? CapacityState.Enabled : CapacityState.Disabled;
        final short[] capacityTypes = { Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY };
        this._capacityDao.updateCapacityState(null, null, null, host.getId(), capacityState.toString(), capacityTypes);
    }
    return this._hostDao.updateResourceState(currentState, event, nextState, host);
}
Also used : CapacityState(com.cloud.model.enumeration.CapacityState) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) ResourceState(com.cloud.legacymodel.resource.ResourceState)

Example 2 with ResourceState

use of com.cloud.legacymodel.resource.ResourceState in project cosmic by MissionCriticalCloud.

the class AgentManagerImpl method agentStatusTransitTo.

@Override
public boolean agentStatusTransitTo(final HostVO host, final Event e, final long msId) {
    try {
        this._agentStatusLock.lock();
        if (status_logger.isDebugEnabled()) {
            final ResourceState state = host.getResourceState();
            final StringBuilder msg = new StringBuilder("Transition:");
            msg.append("[Resource state = ").append(state);
            msg.append(", Agent event = ").append(e.toString());
            msg.append(", Host id = ").append(host.getId()).append(", name = " + host.getName()).append("]");
            status_logger.debug(msg.toString());
        }
        host.setManagementServerId(msId);
        try {
            return new StateMachine2Transitions(this._statusStateMachine).transitTo(host, e, host.getId(), this._hostDao);
        } catch (final NoTransitionException e1) {
            status_logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() + ", mangement server id is " + msId);
            throw new CloudRuntimeException("Cannot transit agent status with event " + e + " for host " + host.getId() + ", mangement server id is " + msId + "," + e1.getMessage());
        }
    } finally {
        this._agentStatusLock.unlock();
    }
}
Also used : StateMachine2Transitions(com.cloud.utils.fsm.StateMachine2Transitions) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) ResourceState(com.cloud.legacymodel.resource.ResourceState)

Aggregations

NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)2 ResourceState (com.cloud.legacymodel.resource.ResourceState)2 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 CapacityState (com.cloud.model.enumeration.CapacityState)1 StateMachine2Transitions (com.cloud.utils.fsm.StateMachine2Transitions)1