Search in sources :

Example 11 with GridClientException

use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.

the class HadoopClientProtocol method getNewJobID.

/**
 * {@inheritDoc}
 */
@Override
public JobID getNewJobID() throws IOException, InterruptedException {
    try {
        conf.setLong(HadoopCommonUtils.REQ_NEW_JOBID_TS_PROPERTY, U.currentTimeMillis());
        HadoopJobId jobID = execute(HadoopProtocolNextTaskIdTask.class);
        conf.setLong(HadoopCommonUtils.RESPONSE_NEW_JOBID_TS_PROPERTY, U.currentTimeMillis());
        return new JobID(jobID.globalId().toString(), jobID.localId());
    } catch (GridClientException e) {
        throw new IOException("Failed to get new job ID.", e);
    }
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) IOException(java.io.IOException) HadoopJobId(org.apache.ignite.internal.processors.hadoop.HadoopJobId) JobID(org.apache.hadoop.mapreduce.JobID)

Example 12 with GridClientException

use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.

the class HadoopClientProtocol method getJobStatus.

/**
 * {@inheritDoc}
 */
@Override
public JobStatus getJobStatus(JobID jobId) throws IOException, InterruptedException {
    try {
        Long delay = conf.getLong(HadoopJobProperty.JOB_STATUS_POLL_DELAY.propertyName(), -1);
        HadoopJobStatus status;
        if (delay >= 0)
            status = execute(HadoopProtocolJobStatusTask.class, jobId.getJtIdentifier(), jobId.getId(), delay);
        else
            status = execute(HadoopProtocolJobStatusTask.class, jobId.getJtIdentifier(), jobId.getId());
        if (status == null)
            throw new IOException("Job tracker doesn't have any information about the job: " + jobId);
        return processStatus(status);
    } catch (GridClientException e) {
        throw new IOException("Failed to get job status: " + jobId, e);
    }
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) HadoopJobStatus(org.apache.ignite.internal.processors.hadoop.HadoopJobStatus) IOException(java.io.IOException)

Example 13 with GridClientException

use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.

the class ClientAbstractSelfTest method testShutdown.

/**
 * @throws Exception If failed.
 */
public void testShutdown() throws Exception {
    GridClient c = client();
    GridClientCompute compute = c.compute();
    String taskName = getTaskName();
    Object taskArg = getTaskArgument();
    Collection<GridClientFuture<Object>> futs = new ArrayList<>();
    // Validate connection works.
    compute.execute(taskName, taskArg);
    info(">>> First task executed successfully, running batch.");
    for (int i = 0; i < 10; i++) futs.add(compute.executeAsync(taskName, taskArg));
    // Stop client.
    GridClientFactory.stop(c.id(), true);
    info(">>> Completed stop request.");
    int failed = 0;
    for (GridClientFuture<Object> fut : futs) {
        try {
            assertEquals(17, fut.get());
        } catch (GridClientException e) {
            failed++;
            log.warning("Task execution failed.", e);
        }
    }
    assertEquals(0, failed);
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientFuture(org.apache.ignite.internal.client.GridClientFuture) ArrayList(java.util.ArrayList) GridClient(org.apache.ignite.internal.client.GridClient)

Example 14 with GridClientException

use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.

the class GridClientRoundRobinBalancer method balancedNode.

/**
 * {@inheritDoc}
 */
@Override
public GridClientNode balancedNode(Collection<? extends GridClientNode> nodes) throws GridClientException {
    assert !nodes.isEmpty();
    if (isPreferDirectNodes()) {
        Collection<GridClientNode> direct = selectDirectNodes(nodes);
        int directSize = direct.size();
        // replace original set of nodes with directly available.
        if (directSize > 0 && directSize < nodes.size())
            nodes = direct;
    }
    Map<UUID, GridClientNode> lookup = U.newHashMap(nodes.size());
    for (GridClientNode node : nodes) lookup.put(node.nodeId(), node);
    lock.lock();
    try {
        GridClientNode balanced = null;
        for (Iterator<UUID> iter = nodeQueue.iterator(); iter.hasNext(); ) {
            UUID nodeId = iter.next();
            balanced = lookup.get(nodeId);
            if (balanced != null) {
                iter.remove();
                break;
            }
        }
        if (balanced != null) {
            nodeQueue.addLast(balanced.nodeId());
            return balanced;
        }
        throw new GridClientException("Passed nodes doesn't present in topology " + "[nodes=" + nodes + ", top=" + nodeQueue);
    } finally {
        lock.unlock();
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) UUID(java.util.UUID)

Example 15 with GridClientException

use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.

the class GridClientAbstractProjection method withReconnectHandling.

/**
 * This method executes request to a communication layer and handles connection error, if it occurs. Server
 * is picked up according to the projection affinity and key given. Connection will be made with the node
 * on which key is cached. In case of communication exception client instance is notified and new instance
 * of client is created. If none of servers can be reached, an exception is thrown.
 *
 * @param c Closure to be executed.
 * @param cacheName Cache name for which mapped node will be calculated.
 * @param affKey Affinity key.
 * @param <R> Type of result in future.
 * @return Operation future.
 */
protected <R> GridClientFuture<R> withReconnectHandling(ClientProjectionClosure<R> c, String cacheName, @Nullable Object affKey) {
    GridClientDataAffinity affinity = client.affinity(cacheName);
    // If pinned (fixed-nodes) or no affinity provided use balancer.
    if (nodes != null || affinity == null || affKey == null)
        return withReconnectHandling(c);
    try {
        Collection<? extends GridClientNode> prjNodes = projectionNodes();
        if (prjNodes.isEmpty())
            throw new GridServerUnreachableException("Failed to get affinity node (no nodes in topology were " + "accepted by the filter): " + filter);
        GridClientNode node = affinity.node(affKey, prjNodes);
        for (int i = 0; i < RETRY_CNT; i++) {
            GridClientConnection conn = null;
            try {
                conn = client.connectionManager().connection(node);
                return c.apply(conn, node.nodeId());
            } catch (GridConnectionIdleClosedException e) {
                client.connectionManager().terminateConnection(conn, node, e);
            } catch (GridClientConnectionResetException e) {
                client.connectionManager().terminateConnection(conn, node, e);
                if (!checkNodeAlive(node.nodeId()))
                    throw new GridServerUnreachableException("Failed to communicate with mapped grid node for " + "given affinity key (node left the grid) [nodeId=" + node.nodeId() + ", affKey=" + affKey + ']', e);
            } catch (RuntimeException | Error e) {
                if (conn != null)
                    client.connectionManager().terminateConnection(conn, node, e);
                throw e;
            }
            U.sleep(RETRY_DELAY);
        }
        throw new GridServerUnreachableException("Failed to communicate with mapped grid node for given affinity " + "key (did node leave the grid?) [nodeId=" + node.nodeId() + ", affKey=" + affKey + ']');
    } catch (GridClientException e) {
        return new GridClientFutureAdapter<>(e);
    } catch (IgniteInterruptedCheckedException | InterruptedException e) {
        Thread.currentThread().interrupt();
        return new GridClientFutureAdapter<>(new GridClientException("Interrupted when (re)trying to perform " + "request.", e));
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) GridConnectionIdleClosedException(org.apache.ignite.internal.client.impl.connection.GridConnectionIdleClosedException) GridClientConnectionResetException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException) GridClientDataAffinity(org.apache.ignite.internal.client.GridClientDataAffinity) GridClientConnection(org.apache.ignite.internal.client.impl.connection.GridClientConnection) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Aggregations

GridClientException (org.apache.ignite.internal.client.GridClientException)25 GridClientNode (org.apache.ignite.internal.client.GridClientNode)6 GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 SQLException (java.sql.SQLException)3 List (java.util.List)3 UUID (java.util.UUID)3 GridClient (org.apache.ignite.internal.client.GridClient)3 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)3 GridClientConnection (org.apache.ignite.internal.client.impl.connection.GridClientConnection)3 GridClientConnectionResetException (org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException)3 InetSocketAddress (java.net.InetSocketAddress)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)2 GridClientDataAffinity (org.apache.ignite.internal.client.GridClientDataAffinity)2 GridClientFuture (org.apache.ignite.internal.client.GridClientFuture)2 GridClientConnectionManager (org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager)2 GridConnectionIdleClosedException (org.apache.ignite.internal.client.impl.connection.GridConnectionIdleClosedException)2