Search in sources :

Example 26 with ServiceConfiguration

use of org.apache.ignite.services.ServiceConfiguration in project ignite by apache.

the class ServiceReassignmentFunctionSelfTest method testCustomConfiguration.

/**
 * @throws Exception In case of an error.
 */
@Test
public void testCustomConfiguration() throws Exception {
    ServiceConfiguration cfg = new ServiceConfiguration();
    cfg.setName(TEST_SERVICE_NAME);
    cfg.setMaxPerNodeCount(3);
    cfg.setTotalCount(10);
    runTestReassignFunction(IgniteUuid.randomUuid(), cfg, null);
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Test(org.junit.Test)

Example 27 with ServiceConfiguration

use of org.apache.ignite.services.ServiceConfiguration in project ignite by apache.

the class IgniteServiceReassignmentTest method serviceConfiguration.

/**
 * @return Service configuration.
 */
private ServiceConfiguration serviceConfiguration() {
    ServiceConfiguration svc = new ServiceConfiguration();
    svc.setName("DummyService");
    svc.setTotalCount(1);
    svc.setService(new DummyService());
    return svc;
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration)

Example 28 with ServiceConfiguration

use of org.apache.ignite.services.ServiceConfiguration in project ignite by apache.

the class GridServiceProcessor method onKernalStart.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public void onKernalStart(boolean activeOnStart) throws IgniteCheckedException {
    if (ctx.isDaemon() || !ctx.state().active())
        return;
    cache = ctx.cache().utilityCache();
    if (!ctx.clientNode())
        ctx.event().addDiscoveryEventListener(topLsnr, EVTS);
    try {
        if (ctx.deploy().enabled())
            ctx.cache().context().deploy().ignoreOwnership(true);
        if (!ctx.clientNode()) {
            assert cache.context().affinityNode();
            cache.context().continuousQueries().executeInternalQuery(new ServiceEntriesListener(), null, true, true, false);
        } else {
            assert !ctx.isDaemon();
            ctx.closure().runLocalSafe(new Runnable() {

                @Override
                public void run() {
                    try {
                        Iterable<CacheEntryEvent<?, ?>> entries = cache.context().continuousQueries().existingEntries(false, null);
                        onSystemCacheUpdated(entries);
                    } catch (IgniteCheckedException e) {
                        U.error(log, "Failed to load service entries: " + e, e);
                    }
                }
            });
        }
    } finally {
        if (ctx.deploy().enabled())
            ctx.cache().context().deploy().ignoreOwnership(false);
    }
    ServiceConfiguration[] cfgs = ctx.config().getServiceConfiguration();
    if (cfgs != null) {
        Collection<IgniteInternalFuture<?>> futs = new ArrayList<>();
        for (ServiceConfiguration c : cfgs) {
            // Deploy only on server nodes by default.
            if (c.getNodeFilter() == null)
                c.setNodeFilter(ctx.cluster().get().forServers().predicate());
            futs.add(deploy(c));
        }
        // Await for services to deploy.
        for (IgniteInternalFuture<?> f : futs) f.get();
    }
    if (log.isDebugEnabled())
        log.debug("Started service processor.");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 29 with ServiceConfiguration

use of org.apache.ignite.services.ServiceConfiguration in project ignite by apache.

the class GridServiceProcessorBatchDeploySelfTest method _testDeployAllTopologyChange.

/**
 * TODO: enable when IGNITE-6259 is fixed.
 *
 * @throws Exception If failed.
 */
public void _testDeployAllTopologyChange() throws Exception {
    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);
        subscribeExeLatch(cfgs, latch);
        int from = 0;
        while (from < numServices) {
            int to = Math.min(numServices, from + batchSize);
            client.services().deployAllAsync(cfgs.subList(from, to)).get(5000);
            from = to;
        }
        assertTrue(latch.await(30, TimeUnit.SECONDS));
        assertDeployedServices(client, cfgs);
    } finally {
        finished.set(true);
    }
    topChangeFut.get();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 30 with ServiceConfiguration

use of org.apache.ignite.services.ServiceConfiguration in project ignite by apache.

the class GridServiceProcessorBatchDeploySelfTest method _testCancelAllTopologyChange.

/**
 * TODO: enable when IGNITE-6259 is fixed.
 *
 * @throws Exception If failed.
 */
public void _testCancelAllTopologyChange() throws Exception {
    Ignite client = grid(CLIENT_NODE_NAME);
    int numServices = 500;
    List<ServiceConfiguration> cfgs = getConfigs(client.cluster().forServers().predicate(), numServices);
    CountDownLatch latch = new CountDownLatch(numServices);
    subscribeExeLatch(cfgs, latch);
    client.services().deployAll(cfgs);
    latch.await(30, TimeUnit.SECONDS);
    final AtomicBoolean finished = new AtomicBoolean();
    IgniteInternalFuture<Object> topChangeFut = runTopChanger(finished);
    List<String> names = new ArrayList<>();
    for (ServiceConfiguration cfg : cfgs) names.add(cfg.getName());
    try {
        int batchSize = 5;
        int from = 0;
        while (from < numServices) {
            int to = Math.min(numServices, from + batchSize);
            log.info("Trying to cancel services [" + from + ".." + to + ")");
            client.services().cancelAllAsync(names.subList(from, to)).get(5000);
            from = to;
        }
        assertDeployedServices(client, Collections.<ServiceConfiguration>emptyList());
    } finally {
        finished.set(true);
    }
    topChangeFut.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ServiceConfiguration (org.apache.ignite.services.ServiceConfiguration)71 Test (org.junit.Test)29 Ignite (org.apache.ignite.Ignite)20 ArrayList (java.util.ArrayList)18 CountDownLatch (java.util.concurrent.CountDownLatch)18 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)9 IgniteUuid (org.apache.ignite.lang.IgniteUuid)8 ServiceDeploymentException (org.apache.ignite.services.ServiceDeploymentException)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 UUID (java.util.UUID)6 IgniteException (org.apache.ignite.IgniteException)6 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 HashMap (java.util.HashMap)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 Service (org.apache.ignite.services.Service)4 HashSet (java.util.HashSet)3 List (java.util.List)3