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