Search in sources :

Example 41 with JetException

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;
}
Also used : XADataSource(javax.sql.XADataSource) SQLException(java.sql.SQLException) JetException(com.hazelcast.jet.JetException) XADataSource(javax.sql.XADataSource) DataSource(javax.sql.DataSource) CommonDataSource(javax.sql.CommonDataSource) XAConnection(javax.sql.XAConnection)

Example 42 with JetException

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);
    }
}
Also used : ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) Address(com.hazelcast.cluster.Address) ILogger(com.hazelcast.logging.ILogger) JetException(com.hazelcast.jet.JetException) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend)

Example 43 with JetException

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);
    }
}
Also used : 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) Response(org.elasticsearch.client.Response) JsonArray(com.hazelcast.internal.json.JsonArray) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 44 with JetException

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);
    }
}
Also used : Response(org.elasticsearch.client.Response) JsonArray(com.hazelcast.internal.json.JsonArray) InputStreamReader(java.io.InputStreamReader) Request(org.elasticsearch.client.Request) JsonObject(com.hazelcast.internal.json.JsonObject) IOException(java.io.IOException) JetException(com.hazelcast.jet.JetException)

Example 45 with JetException

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;
}
Also used : Address(com.hazelcast.cluster.Address) Collections.emptyMap(java.util.Collections.emptyMap) Member(com.hazelcast.cluster.Member) Collections.emptyList(java.util.Collections.emptyList) Collections.nCopies(java.util.Collections.nCopies) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Collection(java.util.Collection) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Processors(com.hazelcast.jet.core.processor.Processors) Set(java.util.Set) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) JetException(com.hazelcast.jet.JetException) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Collectors.toSet(java.util.stream.Collectors.toSet) Address(com.hazelcast.cluster.Address) HashMap(java.util.HashMap) JetException(com.hazelcast.jet.JetException) Collections.emptyList(java.util.Collections.emptyList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

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