use of org.apache.ignite.internal.IgniteClientDisconnectedCheckedException in project ignite by apache.
the class GridServiceProcessor method deploy.
/**
* @param cfg Service configuration.
* @return Future for deployment.
*/
public IgniteInternalFuture<?> deploy(ServiceConfiguration cfg) {
A.notNull(cfg, "cfg");
ServicesCompatibilityState state = markCompatibilityStateAsUsed();
validate(cfg);
ctx.security().authorize(cfg.getName(), SecurityPermission.SERVICE_DEPLOY, null);
if (!state.srvcCompatibility) {
Marshaller marsh = ctx.config().getMarshaller();
LazyServiceConfiguration cfg0;
try {
byte[] srvcBytes = U.marshal(marsh, cfg.getService());
cfg0 = new LazyServiceConfiguration(cfg, srvcBytes);
} catch (IgniteCheckedException e) {
U.error(log, "Failed to marshal service with configured marshaller [srvc=" + cfg.getService() + ", marsh=" + marsh + "]", e);
return new GridFinishedFuture<>(e);
}
cfg = cfg0;
}
GridServiceDeploymentFuture fut = new GridServiceDeploymentFuture(cfg);
GridServiceDeploymentFuture old = depFuts.putIfAbsent(cfg.getName(), fut);
if (old != null) {
if (!old.configuration().equalsIgnoreNodeFilter(cfg)) {
fut.onDone(new IgniteCheckedException("Failed to deploy service (service already exists with " + "different configuration) [deployed=" + old.configuration() + ", new=" + cfg + ']'));
return fut;
}
return old;
}
if (ctx.clientDisconnected()) {
fut.onDone(new IgniteClientDisconnectedCheckedException(ctx.cluster().clientReconnectFuture(), "Failed to deploy service, client node disconnected."));
depFuts.remove(cfg.getName(), fut);
}
while (true) {
try {
GridServiceDeploymentKey key = new GridServiceDeploymentKey(cfg.getName());
if (ctx.deploy().enabled())
ctx.cache().context().deploy().ignoreOwnership(true);
try {
GridServiceDeployment dep = (GridServiceDeployment) cache.getAndPutIfAbsent(key, new GridServiceDeployment(ctx.localNodeId(), cfg));
if (dep != null) {
if (!dep.configuration().equalsIgnoreNodeFilter(cfg)) {
// Remove future from local map.
depFuts.remove(cfg.getName(), fut);
fut.onDone(new IgniteCheckedException("Failed to deploy service (service already exists with " + "different configuration) [deployed=" + dep.configuration() + ", new=" + cfg + ']'));
} else {
Iterator<Cache.Entry<Object, Object>> it = serviceEntries(ServiceAssignmentsPredicate.INSTANCE);
while (it.hasNext()) {
Cache.Entry<Object, Object> e = it.next();
GridServiceAssignments assigns = (GridServiceAssignments) e.getValue();
if (assigns.name().equals(cfg.getName())) {
// Remove future from local map.
depFuts.remove(cfg.getName(), fut);
fut.onDone();
break;
}
}
if (!dep.configuration().equalsIgnoreNodeFilter(cfg))
U.warn(log, "Service already deployed with different configuration (will ignore) " + "[deployed=" + dep.configuration() + ", new=" + cfg + ']');
}
}
} finally {
if (ctx.deploy().enabled())
ctx.cache().context().deploy().ignoreOwnership(false);
}
return fut;
} catch (ClusterTopologyCheckedException e) {
if (log.isDebugEnabled())
log.debug("Topology changed while deploying service (will retry): " + e.getMessage());
} catch (IgniteCheckedException e) {
if (e.hasCause(ClusterTopologyCheckedException.class)) {
if (log.isDebugEnabled())
log.debug("Topology changed while deploying service (will retry): " + e.getMessage());
continue;
}
U.error(log, "Failed to deploy service: " + cfg.getName(), e);
return new GridFinishedFuture<>(e);
}
}
}
use of org.apache.ignite.internal.IgniteClientDisconnectedCheckedException in project ignite by apache.
the class DataStreamerImpl method doFlush.
/**
* Performs flush.
*
* @throws IgniteCheckedException If failed.
*/
private void doFlush() throws IgniteCheckedException {
lastFlushTime = U.currentTimeMillis();
List<IgniteInternalFuture> activeFuts0 = null;
int doneCnt = 0;
for (IgniteInternalFuture<?> f : activeFuts) {
if (!f.isDone()) {
if (activeFuts0 == null)
activeFuts0 = new ArrayList<>((int) (activeFuts.size() * 1.2));
activeFuts0.add(f);
} else {
f.get();
doneCnt++;
}
}
if (activeFuts0 == null || activeFuts0.isEmpty())
return;
while (true) {
Queue<IgniteInternalFuture<?>> q = null;
for (Buffer buf : bufMappings.values()) {
IgniteInternalFuture<?> flushFut = buf.flush();
if (flushFut != null) {
if (q == null)
q = new ArrayDeque<>(bufMappings.size() * 2);
q.add(flushFut);
}
}
if (q != null) {
assert !q.isEmpty();
boolean err = false;
long startTimeMillis = U.currentTimeMillis();
for (IgniteInternalFuture fut = q.poll(); fut != null; fut = q.poll()) {
try {
if (timeout == DFLT_UNLIMIT_TIMEOUT)
fut.get();
else {
long timeRemain = timeout - U.currentTimeMillis() + startTimeMillis;
if (timeRemain <= 0)
throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.");
fut.get(timeRemain);
}
} catch (IgniteClientDisconnectedCheckedException e) {
if (log.isDebugEnabled())
log.debug("Failed to flush buffer: " + e);
throw CU.convertToCacheException(e);
} catch (IgniteFutureTimeoutCheckedException e) {
if (log.isDebugEnabled())
log.debug("Failed to flush buffer: " + e);
throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.", e);
} catch (IgniteCheckedException e) {
if (log.isDebugEnabled())
log.debug("Failed to flush buffer: " + e);
err = true;
}
}
if (err)
// Remaps needed - flush buffers.
continue;
}
doneCnt = 0;
for (int i = 0; i < activeFuts0.size(); i++) {
IgniteInternalFuture f = activeFuts0.get(i);
if (f == null)
doneCnt++;
else if (f.isDone()) {
f.get();
doneCnt++;
activeFuts0.set(i, null);
} else
break;
}
if (doneCnt == activeFuts0.size())
return;
}
}
use of org.apache.ignite.internal.IgniteClientDisconnectedCheckedException in project ignite by apache.
the class IgniteUtils method exceptionConverters.
/**
* Gets map with converters to convert internal checked exceptions to public API unchecked exceptions.
*
* @return Exception converters.
*/
private static Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> exceptionConverters() {
Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> m = new HashMap<>();
m.put(IgniteInterruptedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteInterruptedException(e.getMessage(), (InterruptedException) e.getCause());
}
});
m.put(IgniteFutureCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureCancelledException(e.getMessage(), e);
}
});
m.put(IgniteFutureTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureTimeoutException(e.getMessage(), e);
}
});
m.put(ClusterGroupEmptyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ClusterGroupEmptyException(e.getMessage(), e);
}
});
m.put(ClusterTopologyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
ClusterTopologyException topEx = new ClusterTopologyException(e.getMessage(), e);
ClusterTopologyCheckedException checked = (ClusterTopologyCheckedException) e;
if (checked.retryReadyFuture() != null)
topEx.retryReadyFuture(new IgniteFutureImpl<>(checked.retryReadyFuture()));
return topEx;
}
});
m.put(IgniteDeploymentCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteDeploymentException(e.getMessage(), e);
}
});
m.put(ComputeTaskTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskTimeoutException(e.getMessage(), e);
}
});
m.put(ComputeTaskCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskCancelledException(e.getMessage(), e);
}
});
m.put(IgniteTxRollbackCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionRollbackException(e.getMessage(), e);
}
});
m.put(IgniteTxHeuristicCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionHeuristicException(e.getMessage(), e);
}
});
m.put(IgniteTxTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
if (e.getCause() instanceof TransactionDeadlockException)
return new TransactionTimeoutException(e.getMessage(), e.getCause());
return new TransactionTimeoutException(e.getMessage(), e);
}
});
m.put(IgniteTxOptimisticCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionOptimisticException(e.getMessage(), e);
}
});
m.put(IgniteClientDisconnectedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteClientDisconnectedException(((IgniteClientDisconnectedCheckedException) e).reconnectFuture(), e.getMessage(), e);
}
});
return m;
}
use of org.apache.ignite.internal.IgniteClientDisconnectedCheckedException in project ignite by apache.
the class ClientImpl method pingNode.
/** {@inheritDoc} */
@Override
public boolean pingNode(@NotNull final UUID nodeId) {
if (nodeId.equals(getLocalNodeId()))
return true;
TcpDiscoveryNode node = rmtNodes.get(nodeId);
if (node == null || !node.visible())
return false;
GridFutureAdapter<Boolean> fut = pingFuts.get(nodeId);
if (fut == null) {
fut = new GridFutureAdapter<>();
GridFutureAdapter<Boolean> oldFut = pingFuts.putIfAbsent(nodeId, fut);
if (oldFut != null)
fut = oldFut;
else {
State state = this.state;
if (spi.getSpiContext().isStopping() || state == STOPPED || state == SEGMENTED) {
if (pingFuts.remove(nodeId, fut))
fut.onDone(false);
return false;
} else if (state == DISCONNECTED) {
if (pingFuts.remove(nodeId, fut))
fut.onDone(new IgniteClientDisconnectedCheckedException(null, "Failed to ping node, client node disconnected."));
} else {
final GridFutureAdapter<Boolean> finalFut = fut;
timer.schedule(new TimerTask() {
@Override
public void run() {
if (pingFuts.remove(nodeId, finalFut)) {
if (ClientImpl.this.state == DISCONNECTED)
finalFut.onDone(new IgniteClientDisconnectedCheckedException(null, "Failed to ping node, client node disconnected."));
else
finalFut.onDone(false);
}
}
}, spi.netTimeout);
sockWriter.sendMessage(new TcpDiscoveryClientPingRequest(getLocalNodeId(), nodeId));
}
}
}
try {
return fut.get();
} catch (IgniteInterruptedCheckedException ignored) {
return false;
} catch (IgniteCheckedException e) {
throw new IgniteSpiException(e);
}
}
Aggregations