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;
}
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;
}
}
}
}
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);
}
}
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();
}
};
}
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);
}
}
Aggregations