Search in sources :

Example 6 with Service

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

the class GridServiceProcessorMultiNodeSelfTest method testDeployOnEachProjectionNodeUpdateTopology.

/**
 * @throws Exception If failed.
 */
public void testDeployOnEachProjectionNodeUpdateTopology() throws Exception {
    // Prestart client node.
    Ignite client = startGrid("client", getConfiguration("client").setClientMode(true));
    try {
        final String name = "serviceOnEachProjectionNodeUpdateTopology";
        Ignite g = randomGrid();
        int prestartedSrvcs = 1;
        CountDownLatch latch = new CountDownLatch(prestartedSrvcs);
        DummyService.exeLatch(name, latch);
        IgniteServices svcs = g.services(g.cluster().forClients());
        IgniteFuture<?> fut = svcs.deployNodeSingletonAsync(name, new DummyService());
        info("Deployed service: " + name);
        fut.get();
        info("Finished waiting for service future: " + name);
        latch.await();
        // Ensure service is deployed
        assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));
        assertEquals(name, prestartedSrvcs, DummyService.started(name));
        assertEquals(name, 0, DummyService.cancelled(name));
        int servers = 2;
        int clients = 2;
        latch = new CountDownLatch(clients);
        DummyService.exeLatch(name, latch);
        startExtraNodes(servers, clients);
        try {
            latch.await();
            waitForDeployment(name, clients);
            // Since we start extra nodes, there may be extra start and cancel events,
            // so we check only the difference between start and cancel and
            // not start and cancel events individually.
            assertEquals(name, clients + prestartedSrvcs, DummyService.started(name) - DummyService.cancelled(name));
            checkCount(name, g.services().serviceDescriptors(), clients + prestartedSrvcs);
        } finally {
            stopExtraNodes(servers + clients);
        }
    } finally {
        stopGrid("client");
    }
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) Service(org.apache.ignite.services.Service) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 7 with Service

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

the class GridServiceProcessorMultiNodeSelfTest method testDeployOnEachNodeUpdateTopology.

/**
 * @throws Exception If failed.
 */
public void testDeployOnEachNodeUpdateTopology() throws Exception {
    // Prestart client node.
    Ignite client = startGrid("client", getConfiguration("client").setClientMode(true));
    try {
        final String name = "serviceOnEachNodeUpdateTopology";
        Ignite g = randomGrid();
        final int prestartedNodes = nodeCount() + 1;
        CountDownLatch latch = new CountDownLatch(prestartedNodes);
        DummyService.exeLatch(name, latch);
        ServiceConfiguration srvcCfg = new ServiceConfiguration();
        srvcCfg.setNodeFilter(new CacheConfiguration.IgniteAllNodesPredicate());
        srvcCfg.setName(name);
        srvcCfg.setMaxPerNodeCount(1);
        srvcCfg.setService(new DummyService());
        IgniteServices svcs = g.services();
        IgniteFuture<?> fut = svcs.deployAsync(srvcCfg);
        info("Deployed service: " + name);
        fut.get();
        info("Finished waiting for service future: " + name);
        latch.await();
        // Ensure service is deployed
        assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));
        assertEquals(name, prestartedNodes, DummyService.started(name));
        assertEquals(name, 0, DummyService.cancelled(name));
        int servers = 2;
        int clients = 2;
        int extraNodes = servers + clients;
        latch = new CountDownLatch(extraNodes);
        DummyService.exeLatch(name, latch);
        startExtraNodes(servers, clients);
        try {
            latch.await();
            waitForDeployment(name, prestartedNodes + extraNodes);
            // Since we start extra nodes, there may be extra start and cancel events,
            // so we check only the difference between start and cancel and
            // not start and cancel events individually.
            assertEquals(name, prestartedNodes + extraNodes, DummyService.started(name) - DummyService.cancelled(name));
            checkCount(name, g.services().serviceDescriptors(), prestartedNodes + extraNodes);
        } finally {
            stopExtraNodes(extraNodes);
        }
    } finally {
        stopGrid("client");
    }
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteServices(org.apache.ignite.IgniteServices) Service(org.apache.ignite.services.Service) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 8 with Service

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

the class GridServiceProcessorProxySelfTest method testLocalProxyInvocation.

/**
 * @throws Exception If failed.
 */
public void testLocalProxyInvocation() throws Exception {
    final String name = "testLocalProxyInvocation";
    final Ignite ignite = grid(0);
    ignite.services().deployNodeSingleton(name, new MapServiceImpl<String, Integer>());
    for (int i = 0; i < nodeCount(); i++) {
        final int idx = i;
        final AtomicReference<MapService<Integer, String>> ref = new AtomicReference<>();
        // wait because after deployNodeSingleton we don't have guarantees what service was deploy.
        boolean wait = GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                MapService<Integer, String> svc = grid(idx).services().serviceProxy(name, MapService.class, false);
                ref.set(svc);
                return svc instanceof Service;
            }
        }, 2000);
        // Make sure service is a local instance.
        assertTrue("Invalid service instance [srv=" + ref.get() + ", node=" + i + ']', wait);
        ref.get().put(i, Integer.toString(i));
    }
    MapService<Integer, String> map = ignite.services().serviceProxy(name, MapService.class, false);
    for (int i = 0; i < nodeCount(); i++) assertEquals(1, map.size());
}
Also used : Service(org.apache.ignite.services.Service) AtomicReference(java.util.concurrent.atomic.AtomicReference) PA(org.apache.ignite.internal.util.typedef.PA) Ignite(org.apache.ignite.Ignite)

Example 9 with Service

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

the class GridServiceProcessorProxySelfTest method testRemoteNotStickProxyInvocation.

/**
 * @throws Exception If failed.
 */
public void testRemoteNotStickProxyInvocation() throws Exception {
    final String name = "testRemoteNotStickProxyInvocation";
    final Ignite ignite = grid(0);
    ignite.services().deployNodeSingleton(name, new MapServiceImpl<String, Integer>());
    // Get remote proxy.
    MapService<Integer, String> svc = ignite.services(ignite.cluster().forRemotes()).serviceProxy(name, MapService.class, false);
    // Make sure service is a local instance.
    assertFalse(svc instanceof Service);
    for (int i = 0; i < nodeCount(); i++) svc.put(i, Integer.toString(i));
    int size = 0;
    for (ClusterNode n : ignite.cluster().forRemotes().nodes()) {
        MapService<Integer, String> map = ignite.services(ignite.cluster().forNode(n)).serviceProxy(name, MapService.class, false);
        // Make sure service is a local instance.
        assertFalse(map instanceof Service);
        size += map.size();
    }
    assertEquals(nodeCount(), size);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Service(org.apache.ignite.services.Service) Ignite(org.apache.ignite.Ignite)

Example 10 with Service

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

the class GridServiceProcessorProxySelfTest method testSingletonProxyInvocation.

/**
 * @throws Exception If failed.
 */
public void testSingletonProxyInvocation() throws Exception {
    final String name = "testProxyInvocationFromSeveralNodes";
    final Ignite ignite = grid(0);
    ignite.services(ignite.cluster().forLocal()).deployClusterSingleton(name, new MapServiceImpl<String, Integer>());
    for (int i = 1; i < nodeCount(); i++) {
        MapService<Integer, String> svc = grid(i).services().serviceProxy(name, MapService.class, false);
        // Make sure service is a proxy.
        assertFalse(svc instanceof Service);
        svc.put(i, Integer.toString(i));
    }
    assertEquals(nodeCount() - 1, ignite.services().serviceProxy(name, MapService.class, false).size());
}
Also used : Service(org.apache.ignite.services.Service) Ignite(org.apache.ignite.Ignite)

Aggregations

Service (org.apache.ignite.services.Service)16 Ignite (org.apache.ignite.Ignite)7 ExecutorService (java.util.concurrent.ExecutorService)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 IgniteException (org.apache.ignite.IgniteException)3 IgniteServices (org.apache.ignite.IgniteServices)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 ServiceConfiguration (org.apache.ignite.services.ServiceConfiguration)3 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)1 GridSpinBusyLock (org.apache.ignite.internal.util.GridSpinBusyLock)1 PA (org.apache.ignite.internal.util.typedef.PA)1