Search in sources :

Example 1 with TopologyChangedStrategy

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

the class AbstractMapReduceTask method getTopologyChangedStrategyOrConfigTopologyChangedStrategy.

private TopologyChangedStrategy getTopologyChangedStrategyOrConfigTopologyChangedStrategy(JobTrackerConfig config) {
    String topologyChangedStrategyStr = getTopologyChangedStrategy();
    TopologyChangedStrategy topologyChangedStrategy;
    if (topologyChangedStrategyStr == null) {
        topologyChangedStrategy = config.getTopologyChangedStrategy();
    } else {
        topologyChangedStrategy = TopologyChangedStrategy.valueOf(topologyChangedStrategyStr.toUpperCase(LOCALE_INTERNAL));
    }
    return topologyChangedStrategy;
}
Also used : TopologyChangedStrategy(com.hazelcast.mapreduce.TopologyChangedStrategy)

Example 2 with TopologyChangedStrategy

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

the class AbstractMapReduceTask method startSupervisionTask.

private void startSupervisionTask(JobTracker jobTracker) {
    final MapReduceService mapReduceService = getService(MapReduceService.SERVICE_NAME);
    final JobTrackerConfig config = ((AbstractJobTracker) jobTracker).getJobTrackerConfig();
    final boolean communicateStats = config.isCommunicateStats();
    final int chunkSize = getChunkSizeOrConfigChunkSize(config);
    final TopologyChangedStrategy topologyChangedStrategy = getTopologyChangedStrategyOrConfigTopologyChangedStrategy(config);
    final String name = getDistributedObjectName();
    final String jobId = getJobId();
    final KeyValueSource keyValueSource = getKeyValueSource();
    final Mapper mapper = getMapper();
    final CombinerFactory combinerFactory = getCombinerFactory();
    final ReducerFactory reducerFactory = getReducerFactory();
    final Collection keys = getKeys();
    final Collection<Object> keyObjects = getKeyObjects(keys);
    final KeyPredicate predicate = getPredicate();
    final ClusterService clusterService = nodeEngine.getClusterService();
    for (Member member : clusterService.getMembers(KeyValueJobOperation.MEMBER_SELECTOR)) {
        Operation operation = new KeyValueJobOperation(name, jobId, chunkSize, keyValueSource, mapper, combinerFactory, reducerFactory, communicateStats, topologyChangedStrategy);
        executeOperation(operation, member.getAddress(), mapReduceService, nodeEngine);
    }
    // After we prepared all the remote systems we can now start the processing
    for (Member member : clusterService.getMembers(DATA_MEMBER_SELECTOR)) {
        Operation operation = new StartProcessingJobOperation(name, jobId, keyObjects, predicate);
        executeOperation(operation, member.getAddress(), mapReduceService, nodeEngine);
    }
}
Also used : JobTrackerConfig(com.hazelcast.config.JobTrackerConfig) KeyValueJobOperation(com.hazelcast.mapreduce.impl.operation.KeyValueJobOperation) ReducerFactory(com.hazelcast.mapreduce.ReducerFactory) AbstractJobTracker(com.hazelcast.mapreduce.impl.AbstractJobTracker) StartProcessingJobOperation(com.hazelcast.mapreduce.impl.operation.StartProcessingJobOperation) Operation(com.hazelcast.spi.Operation) MapReduceUtil.executeOperation(com.hazelcast.mapreduce.impl.MapReduceUtil.executeOperation) KeyValueJobOperation(com.hazelcast.mapreduce.impl.operation.KeyValueJobOperation) KeyPredicate(com.hazelcast.mapreduce.KeyPredicate) KeyValueSource(com.hazelcast.mapreduce.KeyValueSource) CombinerFactory(com.hazelcast.mapreduce.CombinerFactory) Mapper(com.hazelcast.mapreduce.Mapper) TopologyChangedStrategy(com.hazelcast.mapreduce.TopologyChangedStrategy) ClusterService(com.hazelcast.internal.cluster.ClusterService) MapReduceService(com.hazelcast.mapreduce.impl.MapReduceService) Collection(java.util.Collection) StartProcessingJobOperation(com.hazelcast.mapreduce.impl.operation.StartProcessingJobOperation) Member(com.hazelcast.core.Member)

Example 3 with TopologyChangedStrategy

use of com.hazelcast.mapreduce.TopologyChangedStrategy 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)

Example 4 with TopologyChangedStrategy

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

the class XmlConfigBuilder method handleJobTracker.

private void handleJobTracker(Node node) {
    Node attName = node.getAttributes().getNamedItem("name");
    String name = getTextContent(attName);
    JobTrackerConfig jConfig = new JobTrackerConfig();
    jConfig.setName(name);
    for (Node n : childElements(node)) {
        String nodeName = cleanNodeName(n);
        String value = getTextContent(n).trim();
        if ("max-thread-size".equals(nodeName)) {
            jConfig.setMaxThreadSize(getIntegerValue("max-thread-size", value));
        } else if ("queue-size".equals(nodeName)) {
            jConfig.setQueueSize(getIntegerValue("queue-size", value));
        } else if ("retry-count".equals(nodeName)) {
            jConfig.setRetryCount(getIntegerValue("retry-count", value));
        } else if ("chunk-size".equals(nodeName)) {
            jConfig.setChunkSize(getIntegerValue("chunk-size", value));
        } else if ("communicate-stats".equals(nodeName)) {
            jConfig.setCommunicateStats(value == null || value.length() == 0 ? JobTrackerConfig.DEFAULT_COMMUNICATE_STATS : parseBoolean(value));
        } else if ("topology-changed-stategy".equals(nodeName)) {
            TopologyChangedStrategy topologyChangedStrategy = JobTrackerConfig.DEFAULT_TOPOLOGY_CHANGED_STRATEGY;
            for (TopologyChangedStrategy temp : TopologyChangedStrategy.values()) {
                if (temp.name().equals(value)) {
                    topologyChangedStrategy = temp;
                }
            }
            jConfig.setTopologyChangedStrategy(topologyChangedStrategy);
        }
    }
    config.addJobTrackerConfig(jConfig);
}
Also used : TopologyChangedStrategy(com.hazelcast.mapreduce.TopologyChangedStrategy) Node(org.w3c.dom.Node)

Aggregations

TopologyChangedStrategy (com.hazelcast.mapreduce.TopologyChangedStrategy)4 MapReduceService (com.hazelcast.mapreduce.impl.MapReduceService)2 JobTrackerConfig (com.hazelcast.config.JobTrackerConfig)1 Member (com.hazelcast.core.Member)1 ClusterService (com.hazelcast.internal.cluster.ClusterService)1 CombinerFactory (com.hazelcast.mapreduce.CombinerFactory)1 KeyPredicate (com.hazelcast.mapreduce.KeyPredicate)1 KeyValueSource (com.hazelcast.mapreduce.KeyValueSource)1 Mapper (com.hazelcast.mapreduce.Mapper)1 ReducerFactory (com.hazelcast.mapreduce.ReducerFactory)1 TopologyChangedException (com.hazelcast.mapreduce.TopologyChangedException)1 AbstractJobTracker (com.hazelcast.mapreduce.impl.AbstractJobTracker)1 MapReduceUtil.executeOperation (com.hazelcast.mapreduce.impl.MapReduceUtil.executeOperation)1 KeyValueJobOperation (com.hazelcast.mapreduce.impl.operation.KeyValueJobOperation)1 StartProcessingJobOperation (com.hazelcast.mapreduce.impl.operation.StartProcessingJobOperation)1 JobSupervisor (com.hazelcast.mapreduce.impl.task.JobSupervisor)1 Address (com.hazelcast.nio.Address)1 NoDataMemberInClusterException (com.hazelcast.partition.NoDataMemberInClusterException)1 Operation (com.hazelcast.spi.Operation)1 IOException (java.io.IOException)1