use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.
the class WriteJdbcP method connectAndPrepareStatement.
private boolean connectAndPrepareStatement() {
try {
if (snapshotUtility.usesTransactionLifecycle()) {
if (!(dataSource instanceof XADataSource)) {
throw new JetException("When using exactly-once, the dataSource must implement " + XADataSource.class.getName());
}
xaConnection = ((XADataSource) dataSource).getXAConnection();
connection = xaConnection.getConnection();
// we never ignore errors in ex-once mode
assert idleCount == 0 : "idleCount=" + idleCount;
setXaResource(xaConnection.getXAResource());
} else if (dataSource instanceof DataSource) {
connection = ((DataSource) dataSource).getConnection();
} else if (dataSource instanceof XADataSource) {
logger.warning("Using " + XADataSource.class.getName() + " when no XA transactions are needed");
XAConnection xaConnection = ((XADataSource) dataSource).getXAConnection();
connection = xaConnection.getConnection();
} else {
throw new JetException("The dataSource implements neither " + DataSource.class.getName() + " nor " + XADataSource.class.getName());
}
connection.setAutoCommit(false);
supportsBatch = connection.getMetaData().supportsBatchUpdates();
statement = connection.prepareStatement(updateQuery);
} catch (SQLException e) {
if (snapshotUtility.usesTransactionLifecycle()) {
throw ExceptionUtil.rethrow(e);
}
logger.warning("Exception when connecting and preparing the statement", e);
idleCount++;
return false;
}
return true;
}
use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.
the class InitExecutionOperation method doRun.
@Override
protected CompletableFuture<?> doRun() {
ILogger logger = getLogger();
if (!getNodeEngine().getLocalMember().getVersion().asVersion().equals(coordinatorVersion)) {
// the same address.
throw new JetException("Mismatch between coordinator and participant version");
}
JetServiceBackend service = getJetServiceBackend();
Address caller = getCallerAddress();
LoggingUtil.logFine(logger, "Initializing execution plan for %s from %s", jobIdAndExecutionId(jobId(), executionId), caller);
ExecutionPlan plan = deserializePlan(serializedPlan);
if (isLightJob) {
return service.getJobExecutionService().runLightJob(jobId(), executionId, caller, coordinatorMemberListVersion, participants, plan);
} else {
service.getJobExecutionService().initExecution(jobId(), executionId, caller, coordinatorMemberListVersion, participants, plan);
return CompletableFuture.completedFuture(null);
}
}
use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.
the class ElasticCatClient method shards.
/**
* Returns list of shards for given indexes
*
* Only STARTED shards are returned.
*
* @param indices indexes to return shards for (wildcard format accepted)
*/
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public List<Shard> shards(String... indices) {
Map<String, String> idToAddress = nodes().stream().collect(toMap(Node::getId, Node::getHttpAddress));
try {
Request r = new Request("GET", "/_cat/shards/" + String.join(",", indices));
r.addParameter("format", "json");
r.addParameter("h", "id,index,shard,prirep,docs,state,ip,node");
Response res = withRetry(() -> client.performRequest(r), retries);
try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
JsonArray array = Json.parse(reader).asArray();
List<Shard> shards = new ArrayList<>(array.size());
for (JsonValue value : array) {
Optional<Shard> shard = convertToShard(value, idToAddress);
shard.ifPresent(shards::add);
}
LOG.log(FINE, "Shards " + shards);
return shards;
}
} catch (IOException e) {
throw new JetException("Could not get ES shards", e);
}
}
use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.
the class ElasticCatClient method master.
/**
* Returns current master of the ES cluster
*/
public Master master() {
try {
Request r = new Request("GET", "/_cat/master");
r.addParameter("format", "json");
Response res = withRetry(() -> client.performRequest(r), retries);
try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
JsonArray array = Json.parse(reader).asArray();
JsonObject object = array.get(0).asObject();
return new Master(object.get("host").asString(), object.get("id").asString(), object.get("ip").asString(), object.get("node").asString());
}
} catch (IOException e) {
throw new JetException("Could not get ES cluster master", e);
}
}
use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.
the class ElasticSourcePMetaSupplier method assignShards.
static Map<Address, List<Shard>> assignShards(Collection<Shard> shards, Collection<Address> addresses) {
Map<String, List<Shard>> nodeCandidates = shards.stream().collect(groupingBy(Shard::getIp));
Map<Address, List<Shard>> nodeAssigned = new HashMap<>();
if (!addresses.stream().map(Address::getHost).collect(toSet()).containsAll(nodeCandidates.keySet())) {
throw new JetException("Shard locations are not equal to Hazelcast members locations, " + "shards=" + nodeCandidates.keySet() + ", Hazelcast members=" + addresses);
}
int uniqueShards = (int) shards.stream().map(Shard::indexShard).distinct().count();
Set<String> assignedShards = new HashSet<>();
int candidatesSize = nodeCandidates.size();
// Same as Math.ceil for float div
int iterations = (uniqueShards + candidatesSize - 1) / candidatesSize;
for (int i = 0; i < iterations; i++) {
for (Address address : addresses) {
String host = address.getHost();
List<Shard> thisNodeCandidates = nodeCandidates.getOrDefault(host, emptyList());
if (thisNodeCandidates.isEmpty()) {
continue;
}
Shard shard = thisNodeCandidates.remove(0);
List<Shard> nodeShards = nodeAssigned.computeIfAbsent(address, (key) -> new ArrayList<>());
nodeShards.add(shard);
nodeCandidates.values().forEach(candidates -> candidates.removeIf(next -> next.indexShard().equals(shard.indexShard())));
assignedShards.add(shard.indexShard());
}
}
if (assignedShards.size() != uniqueShards) {
throw new JetException("Not all shards have been assigned");
}
return nodeAssigned;
}
Aggregations