Search in sources :

Example 1 with ServiceDeploymentException

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;
}
Also used : ArrayList(java.util.ArrayList) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException)

Example 2 with ServiceDeploymentException

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();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ArrayList(java.util.ArrayList) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Ignite(org.apache.ignite.Ignite)

Example 3 with ServiceDeploymentException

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());
    }
}
Also used : ArrayList(java.util.ArrayList) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteException(org.apache.ignite.IgniteException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)

Example 4 with ServiceDeploymentException

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;
}
Also used : ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Transaction(org.apache.ignite.transactions.Transaction) IgniteException(org.apache.ignite.IgniteException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

ServiceDeploymentException (org.apache.ignite.services.ServiceDeploymentException)4 ArrayList (java.util.ArrayList)3 ServiceConfiguration (org.apache.ignite.services.ServiceConfiguration)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Ignite (org.apache.ignite.Ignite)1 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)1 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)1 Transaction (org.apache.ignite.transactions.Transaction)1