Search in sources :

Example 1 with TopologyChangedException

use of com.hazelcast.mapreduce.TopologyChangedException in project hazelcast by hazelcast.

the class KeysAssignmentOperation method run.

@Override
public void run() throws Exception {
    MapReduceService mapReduceService = getService();
    JobSupervisor supervisor = mapReduceService.getJobSupervisor(getName(), getJobId());
    if (supervisor == null) {
        this.result = new KeysAssignmentResult(NO_SUPERVISOR, null);
        return;
    }
    Map<Object, Address> assignment = new HashMap<Object, Address>();
    // Precheck if still all members are available
    if (!supervisor.checkAssignedMembersAvailable()) {
        TopologyChangedStrategy tcs = supervisor.getConfiguration().getTopologyChangedStrategy();
        if (tcs == CANCEL_RUNNING_OPERATION) {
            Exception exception = new TopologyChangedException();
            supervisor.cancelAndNotify(exception);
            this.result = new KeysAssignmentResult(CHECK_STATE_FAILED, assignment);
            return;
        // TODO Not yet fully supported
        /* } else if (tcs == DISCARD_AND_RESTART) {
             *   supervisor.cancelNotifyAndRestart();
             */
        } else {
            Exception exception = new TopologyChangedException("Unknown or unsupported TopologyChangedStrategy");
            supervisor.cancelAndNotify(exception);
            this.result = new KeysAssignmentResult(CHECK_STATE_FAILED, assignment);
            return;
        }
    }
    try {
        for (Object key : keys) {
            Address address = supervisor.assignKeyReducerAddress(key);
            assignment.put(key, address);
        }
        this.result = new KeysAssignmentResult(SUCCESSFUL, assignment);
    } catch (NoDataMemberInClusterException e) {
        supervisor.cancelAndNotify(e);
        this.result = new KeysAssignmentResult(CHECK_STATE_FAILED, assignment);
    }
}
Also used : TopologyChangedStrategy(com.hazelcast.mapreduce.TopologyChangedStrategy) Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) MapReduceService(com.hazelcast.mapreduce.impl.MapReduceService) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) TopologyChangedException(com.hazelcast.mapreduce.TopologyChangedException) JobSupervisor(com.hazelcast.mapreduce.impl.task.JobSupervisor) IOException(java.io.IOException) TopologyChangedException(com.hazelcast.mapreduce.TopologyChangedException) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException)

Aggregations

TopologyChangedException (com.hazelcast.mapreduce.TopologyChangedException)1 TopologyChangedStrategy (com.hazelcast.mapreduce.TopologyChangedStrategy)1 MapReduceService (com.hazelcast.mapreduce.impl.MapReduceService)1 JobSupervisor (com.hazelcast.mapreduce.impl.task.JobSupervisor)1 Address (com.hazelcast.nio.Address)1 NoDataMemberInClusterException (com.hazelcast.partition.NoDataMemberInClusterException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1