Search in sources :

Example 16 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class ExecutionPlan method createRemoteOutboundCollectors.

private OutboundCollector[] createRemoteOutboundCollectors(EdgeDef edge, String jobPrefix, int processorIndex, int totalPartitionCount, int[][] partitionsPerProcessor, InternalSerializationService jobSerializationService) {
    // the distributed-to-one edge must be partitioned and the target member must be present
    if (!edge.getDistributedTo().equals(DISTRIBUTE_TO_ALL)) {
        if (edge.routingPolicy() != RoutingPolicy.PARTITIONED) {
            throw new JetException("An edge distributing to a specific member must be partitioned: " + edge);
        }
        if (!ptionArrgmt.getRemotePartitionAssignment().containsKey(edge.getDistributedTo()) && !edge.getDistributedTo().equals(nodeEngine.getThisAddress())) {
            throw new JetException("The target member of an edge is not present in the cluster or is a lite member: " + edge);
        }
    }
    Map<Address, ConcurrentConveyor<Object>> senderConveyorMap = memberToSenderConveyorMap(edgeSenderConveyorMap, edge, jobPrefix, jobSerializationService);
    createIfAbsentReceiverTasklet(edge, jobPrefix, partitionsPerProcessor, totalPartitionCount, jobSerializationService);
    // assign remote partitions to outbound data collectors
    Address distributeTo = edge.getDistributedTo();
    Map<Address, int[]> memberToPartitions = distributeTo.equals(DISTRIBUTE_TO_ALL) ? ptionArrgmt.getRemotePartitionAssignment() : ptionArrgmt.remotePartitionAssignmentToOne(distributeTo);
    OutboundCollector[] remoteCollectors = new OutboundCollector[memberToPartitions.size()];
    int index = 0;
    for (Map.Entry<Address, int[]> entry : memberToPartitions.entrySet()) {
        Address memberAddress = entry.getKey();
        int[] memberPartitions = entry.getValue();
        ConcurrentConveyor<Object> conveyor = senderConveyorMap.get(memberAddress);
        remoteCollectors[index++] = new ConveyorCollectorWithPartition(conveyor, processorIndex, memberPartitions);
    }
    return remoteCollectors;
}
Also used : ConcurrentConveyor(com.hazelcast.internal.util.concurrent.ConcurrentConveyor) Address(com.hazelcast.cluster.Address) OutboundCollector(com.hazelcast.jet.impl.execution.OutboundCollector) JetException(com.hazelcast.jet.JetException) ConveyorCollectorWithPartition(com.hazelcast.jet.impl.execution.ConveyorCollectorWithPartition) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 17 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class AsyncOperation method doSendResponse.

private void doSendResponse(Object value) {
    try {
        final JetServiceBackend service = getJetServiceBackend();
        service.getLiveOperationRegistry().deregister(this);
    } finally {
        try {
            sendResponse(value);
        } catch (Exception e) {
            Throwable ex = peel(e);
            if (value instanceof Throwable && ex instanceof HazelcastSerializationException) {
                // Sometimes exceptions are not serializable, for example on
                // https://github.com/hazelcast/hazelcast-jet/issues/1995.
                // When sending exception as a response and the serialization fails,
                // the response will not be sent and the operation will hang.
                // To prevent this from happening, replace the exception with
                // another exception that can be serialized.
                sendResponse(new JetException(stackTraceToString(ex)));
            } else {
                throw e;
            }
        }
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) JetException(com.hazelcast.jet.JetException) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ExceptionUtil.isTopologyException(com.hazelcast.jet.impl.util.ExceptionUtil.isTopologyException) JetException(com.hazelcast.jet.JetException)

Example 18 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class Hz3Util method createMapAdapter.

static Hz3MapAdapter createMapAdapter(String clientXml) {
    try {
        Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass("com.hazelcast.connector.map.impl.MapAdapterImpl");
        Constructor<?> constructor = clazz.getDeclaredConstructor(String.class);
        return (Hz3MapAdapter) constructor.newInstance(clientXml);
    } catch (InvocationTargetException e) {
        throw new JetException("Could not create instance of MapAdapterImpl", e.getCause());
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) {
        throw new HazelcastException(e);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Hz3MapAdapter(com.hazelcast.connector.map.Hz3MapAdapter) JetException(com.hazelcast.jet.JetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 19 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class CsvInputFormat method createRecordReader.

@Override
public RecordReader<NullWritable, Object> createRecordReader(InputSplit split, TaskAttemptContext context) {
    return new RecordReader<NullWritable, Object>() {

        private Object current;

        private MappingIterator<Object> iterator;

        private Function<Object, Object> projection = identity();

        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        public void initialize(InputSplit split, TaskAttemptContext context) throws IOException {
            FileSplit fileSplit = (FileSplit) split;
            Configuration conf = context.getConfiguration();
            Configuration configuration = context.getConfiguration();
            String className = configuration.get(CSV_INPUT_FORMAT_BEAN_CLASS);
            Class<?> formatClazz = className == null ? null : ReflectionUtils.loadClass(className);
            Path file = fileSplit.getPath();
            FileSystem fs = file.getFileSystem(conf);
            FSDataInputStream in = fs.open(file);
            if (formatClazz == String[].class) {
                ObjectReader reader = new CsvMapper().enable(Feature.WRAP_AS_ARRAY).readerFor(String[].class).with(CsvSchema.emptySchema().withSkipFirstDataRow(false));
                iterator = reader.readValues((InputStream) in);
                if (!iterator.hasNext()) {
                    throw new JetException("Header row missing in " + split);
                }
                String[] header = (String[]) iterator.next();
                List<String> fieldNames = new ArrayList<>();
                String field;
                for (int i = 0; (field = configuration.get(CSV_INPUT_FORMAT_FIELD_LIST_PREFIX + i)) != null; i++) {
                    fieldNames.add(field);
                }
                projection = (Function) createFieldProjection(header, fieldNames);
            } else {
                iterator = new CsvMapper().readerFor(formatClazz).withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).with(CsvSchema.emptySchema().withHeader()).readValues((InputStream) in);
            }
        }

        @Override
        public boolean nextKeyValue() {
            if (!iterator.hasNext()) {
                return false;
            }
            current = projection.apply(iterator.next());
            return true;
        }

        @Override
        public NullWritable getCurrentKey() {
            return NullWritable.get();
        }

        @Override
        public Object getCurrentValue() {
            return current;
        }

        @Override
        public float getProgress() {
            return 0;
        }

        @Override
        public void close() throws IOException {
            iterator.close();
        }
    };
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) InputStream(java.io.InputStream) RecordReader(org.apache.hadoop.mapreduce.RecordReader) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) ArrayList(java.util.ArrayList) TaskAttemptContext(org.apache.hadoop.mapreduce.TaskAttemptContext) JetException(com.hazelcast.jet.JetException) FileSplit(org.apache.hadoop.mapreduce.lib.input.FileSplit) Function(java.util.function.Function) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) InputSplit(org.apache.hadoop.mapreduce.InputSplit)

Example 20 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class ElasticCatClient method nodes.

/**
 * Returns list of nodes currently in ES cluster
 */
public List<Node> nodes() {
    try {
        Request r = new Request("GET", "/_cat/nodes");
        r.addParameter("format", "json");
        r.addParameter("full_id", "true");
        r.addParameter("h", "id,ip,name,http_address,master");
        Response res = withRetry(() -> client.performRequest(r), retries);
        try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
            JsonArray array = Json.parse(reader).asArray();
            List<Node> nodes = new ArrayList<>(array.size());
            for (JsonValue value : array) {
                Optional<Node> shard = convertToNode(value);
                shard.ifPresent(nodes::add);
            }
            LOG.fine("Nodes: " + nodes);
            return nodes;
        }
    } catch (IOException e) {
        throw new JetException("Could not get ES cluster nodes", e);
    }
}
Also used : Response(org.elasticsearch.client.Response) JsonArray(com.hazelcast.internal.json.JsonArray) InputStreamReader(java.io.InputStreamReader) Request(org.elasticsearch.client.Request) ArrayList(java.util.ArrayList) JsonValue(com.hazelcast.internal.json.JsonValue) IOException(java.io.IOException) JetException(com.hazelcast.jet.JetException)

Aggregations

JetException (com.hazelcast.jet.JetException)52 IOException (java.io.IOException)8 Nonnull (javax.annotation.Nonnull)8 ILogger (com.hazelcast.logging.ILogger)7 List (java.util.List)7 Map (java.util.Map)6 Util.idToString (com.hazelcast.jet.Util.idToString)5 JobConfig (com.hazelcast.jet.config.JobConfig)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 BroadcastKey (com.hazelcast.jet.core.BroadcastKey)4 JobStatus (com.hazelcast.jet.core.JobStatus)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 FunctionEx (com.hazelcast.function.FunctionEx)3 Job (com.hazelcast.jet.Job)3 DAG (com.hazelcast.jet.core.DAG)3 Watermark (com.hazelcast.jet.core.Watermark)3 Tuple2 (com.hazelcast.jet.datamodel.Tuple2)3 Pipeline (com.hazelcast.jet.pipeline.Pipeline)3