Search in sources :

Example 1 with EndPointStates

use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine.EndPointStates in project ozone by apache.

the class RunningDatanodeState method initEndPointTask.

/**
 * Initialize end point tasks corresponding to each end point,
 * each end point state.
 */
private void initEndPointTask() {
    endpointTasks = new HashMap<>();
    for (EndpointStateMachine endpoint : connectionManager.getValues()) {
        EnumMap<EndPointStates, Callable<EndPointStates>> endpointTaskForState = new EnumMap<>(EndPointStates.class);
        for (EndPointStates state : EndPointStates.values()) {
            Callable<EndPointStates> endPointTask = null;
            switch(state) {
                case GETVERSION:
                    endPointTask = new VersionEndpointTask(endpoint, conf, context.getParent().getContainer());
                    break;
                case REGISTER:
                    endPointTask = RegisterEndpointTask.newBuilder().setConfig(conf).setEndpointStateMachine(endpoint).setContext(context).setDatanodeDetails(context.getParent().getDatanodeDetails()).setOzoneContainer(context.getParent().getContainer()).build();
                    break;
                case HEARTBEAT:
                    endPointTask = HeartbeatEndpointTask.newBuilder().setConfig(conf).setEndpointStateMachine(endpoint).setDatanodeDetails(context.getParent().getDatanodeDetails()).setContext(context).build();
                    break;
                default:
                    break;
            }
            if (endPointTask != null) {
                endpointTaskForState.put(state, endPointTask);
            }
        }
        endpointTasks.put(endpoint, endpointTaskForState);
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) VersionEndpointTask(org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask) EndPointStates(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine.EndPointStates) EnumMap(java.util.EnumMap) Callable(java.util.concurrent.Callable)

Example 2 with EndPointStates

use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine.EndPointStates in project ozone by apache.

the class RunningDatanodeState method execute.

/**
 * Executes one or more tasks that is needed by this state.
 *
 * @param executor -  ExecutorService
 */
@Override
public void execute(ExecutorService executor) {
    ecs = new ExecutorCompletionService<>(executor);
    for (EndpointStateMachine endpoint : connectionManager.getValues()) {
        Callable<EndPointStates> endpointTask = getEndPointTask(endpoint);
        if (endpointTask != null) {
            // Just do a timely wait. A slow EndpointStateMachine won't occupy
            // the thread in executor from DatanodeStateMachine for a long time,
            // so that it won't affect the communication between datanode and
            // other EndpointStateMachine.
            ecs.submit(() -> endpoint.getExecutorService().submit(endpointTask).get(context.getHeartbeatFrequency(), TimeUnit.MILLISECONDS));
        } else {
            // This can happen if a task is taking more time than the timeOut
            // specified for the task in await, and when it is completed the task
            // has set the state to shut down, we may see the state as shutdown
            // here. So, we need to shut down DatanodeStateMachine.
            LOG.error("State is Shutdown in RunningDatanodeState");
            context.setState(DatanodeStateMachine.DatanodeStates.SHUTDOWN);
        }
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) EndPointStates(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine.EndPointStates)

Aggregations

EndpointStateMachine (org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine)2 EndPointStates (org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine.EndPointStates)2 EnumMap (java.util.EnumMap)1 Callable (java.util.concurrent.Callable)1 VersionEndpointTask (org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask)1