use of org.apache.ignite.services.ServiceDeploymentException in project ignite by apache.
the class GridServiceDeploymentCompoundFuture method processFailure.
/**
* {@inheritDoc}
*/
@Override
protected boolean processFailure(Throwable err, IgniteInternalFuture<Object> fut) {
assert fut instanceof GridServiceDeploymentFuture : fut;
GridServiceDeploymentFuture depFut = (GridServiceDeploymentFuture) fut;
synchronized (this) {
if (this.err == null) {
this.err = new ServiceDeploymentException("Failed to deploy some services.", new ArrayList<ServiceConfiguration>());
}
this.err.getFailedConfigurations().add(depFut.configuration());
this.err.addSuppressed(err);
}
return true;
}
use of org.apache.ignite.services.ServiceDeploymentException in project ignite by apache.
the class GridServiceProcessorBatchDeploySelfTest method _testDeployAllTopologyChangeFail.
/**
* TODO: enable when IGNITE-6259 is fixed.
*
* @throws Exception If failed.
*/
public void _testDeployAllTopologyChangeFail() throws Exception {
final Ignite client = grid(CLIENT_NODE_NAME);
final AtomicBoolean finished = new AtomicBoolean();
IgniteInternalFuture<Object> topChangeFut = runTopChanger(finished);
try {
int numServices = 500;
int batchSize = 5;
CountDownLatch latch = new CountDownLatch(numServices);
IgnitePredicate<ClusterNode> depPred = client.cluster().forServers().forPredicate(new IgnitePredicate<ClusterNode>() {
@Override
public boolean apply(ClusterNode node) {
String gridName = node.attribute(IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME);
assert gridName != null;
return gridName.startsWith(getTestIgniteInstanceName());
}
}).predicate();
List<ServiceConfiguration> cfgs = getConfigs(depPred, numServices);
List<ServiceConfiguration> failingCfgs = new ArrayList<>();
subscribeExeLatch(cfgs, latch);
int from = 0;
while (from < numServices) {
int to = Math.min(numServices, from + batchSize);
List<ServiceConfiguration> cfgsBatch = cfgs.subList(from, to);
ServiceConfiguration failingCfg = cfgsBatch.get(0);
failingCfg.setName(null);
failingCfgs.add(failingCfg);
try {
client.services().deployAllAsync(cfgsBatch).get(5000);
fail("Should never reach here.");
} catch (ServiceDeploymentException e) {
assertEquals(1, e.getFailedConfigurations().size());
ServiceConfiguration actFailedCfg = copyService(e.getFailedConfigurations().iterator().next());
assertEquals(failingCfg, actFailedCfg);
latch.countDown();
}
from = to;
}
assertTrue(latch.await(30, TimeUnit.SECONDS));
cfgs.removeAll(failingCfgs);
assertDeployedServices(client, cfgs);
} finally {
finished.set(true);
}
topChangeFut.get();
}
use of org.apache.ignite.services.ServiceDeploymentException in project ignite by apache.
the class GridServiceDeploymentCompoundFutureSelfTest method testWaitForCompletionOnFailingFuture.
/**
* @throws Exception If failed.
*/
public void testWaitForCompletionOnFailingFuture() throws Exception {
GridServiceDeploymentCompoundFuture compFut = new GridServiceDeploymentCompoundFuture();
int failingFutsNum = 2;
int completingFutsNum = 5;
Collection<GridServiceDeploymentFuture> failingFuts = new ArrayList<>(completingFutsNum);
for (int i = 0; i < failingFutsNum; i++) {
ServiceConfiguration failingCfg = config("Failed-" + i);
GridServiceDeploymentFuture failingFut = new GridServiceDeploymentFuture(failingCfg);
failingFuts.add(failingFut);
compFut.add(failingFut);
}
List<GridFutureAdapter<Object>> futs = new ArrayList<>(completingFutsNum);
for (int i = 0; i < completingFutsNum; i++) {
GridServiceDeploymentFuture fut = new GridServiceDeploymentFuture(config(String.valueOf(i)));
futs.add(fut);
compFut.add(fut);
}
compFut.markInitialized();
List<Exception> causes = new ArrayList<>();
for (GridServiceDeploymentFuture fut : failingFuts) {
Exception cause = new Exception("Test error");
causes.add(cause);
fut.onDone(cause);
}
try {
compFut.get(100);
fail("Should never reach here.");
} catch (IgniteFutureTimeoutCheckedException e) {
log.info("Expected exception: " + e.getMessage());
}
for (GridFutureAdapter<Object> fut : futs) fut.onDone();
try {
compFut.get();
fail("Should never reach here.");
} catch (IgniteCheckedException ce) {
log.info("Expected exception: " + ce.getMessage());
IgniteException e = U.convertException(ce);
assertTrue(e instanceof ServiceDeploymentException);
Throwable[] supErrs = e.getSuppressed();
assertEquals(failingFutsNum, supErrs.length);
for (int i = 0; i < failingFutsNum; i++) assertEquals(causes.get(i), supErrs[i].getCause());
}
}
use of org.apache.ignite.services.ServiceDeploymentException in project ignite by apache.
the class GridServiceProcessor method deployAll.
/**
* @param cfgs Service configurations.
* @param dfltNodeFilter Default NodeFilter.
* @return Future for deployment.
*/
private IgniteInternalFuture<?> deployAll(Collection<ServiceConfiguration> cfgs, @Nullable IgnitePredicate<ClusterNode> dfltNodeFilter) {
assert cfgs != null;
PreparedConfigurations srvCfg = prepareServiceConfigurations(cfgs, dfltNodeFilter);
List<ServiceConfiguration> cfgsCp = srvCfg.cfgs;
List<GridServiceDeploymentFuture> failedFuts = srvCfg.failedFuts;
Collections.sort(cfgsCp, new Comparator<ServiceConfiguration>() {
@Override
public int compare(ServiceConfiguration cfg1, ServiceConfiguration cfg2) {
return cfg1.getName().compareTo(cfg2.getName());
}
});
GridServiceDeploymentCompoundFuture res;
while (true) {
res = new GridServiceDeploymentCompoundFuture();
if (ctx.deploy().enabled())
ctx.cache().context().deploy().ignoreOwnership(true);
try {
if (cfgsCp.size() == 1)
writeServiceToCache(res, cfgsCp.get(0));
else if (cfgsCp.size() > 1) {
try (Transaction tx = serviceCache().txStart(PESSIMISTIC, READ_COMMITTED)) {
for (ServiceConfiguration cfg : cfgsCp) {
try {
writeServiceToCache(res, cfg);
} catch (IgniteCheckedException e) {
if (X.hasCause(e, ClusterTopologyCheckedException.class))
// Retry.
throw e;
else
U.error(log, e.getMessage());
}
}
tx.commit();
}
}
break;
} catch (IgniteException | IgniteCheckedException e) {
for (String name : res.servicesToRollback()) depFuts.remove(name).onDone(e);
if (X.hasCause(e, ClusterTopologyCheckedException.class)) {
if (log.isDebugEnabled())
log.debug("Topology changed while deploying services (will retry): " + e.getMessage());
} else {
res.onDone(new IgniteCheckedException(new ServiceDeploymentException("Failed to deploy provided services.", e, cfgs)));
return res;
}
} finally {
if (ctx.deploy().enabled())
ctx.cache().context().deploy().ignoreOwnership(false);
}
}
if (ctx.clientDisconnected()) {
IgniteClientDisconnectedCheckedException err = new IgniteClientDisconnectedCheckedException(ctx.cluster().clientReconnectFuture(), "Failed to deploy services, client node disconnected: " + cfgs);
for (String name : res.servicesToRollback()) {
GridServiceDeploymentFuture fut = depFuts.remove(name);
if (fut != null)
fut.onDone(err);
}
return new GridFinishedFuture<>(err);
}
if (failedFuts != null) {
for (GridServiceDeploymentFuture fut : failedFuts) res.add(fut, false);
}
res.markInitialized();
return res;
}
Aggregations