@Override public void run(IgniteServices services, String svcName, TestService svc) throws Exception { services.deployClusterSingleton(svcName, (Service)svc); waitForServiceDeploymentIfNeeded(services, svcName); } }));
/** * Creates and starts a new TensorFlow cluster for the specified cache. * * @param clusterId Cluster identifier. * @param jobArchive Job archive. * @return TensorFlow cluster gateway that allows to subscribe on cluster changes. */ public TensorFlowClusterGateway createCluster(UUID clusterId, TensorFlowJobArchive jobArchive) { String svcName = String.format(SERVICE_NAME_TEMPLATE, clusterId); String topicName = String.format(SERVICE_TOPIC_NAME_TEMPLATE, clusterId); TensorFlowClusterGateway gateway = createTensorFlowClusterGateway(topicName); ignite.services().deployClusterSingleton( svcName, new TensorFlowClusterMaintainer(clusterId, jobArchive, topicName) ); log.info("Cluster maintainer deployed as a service [clusterId=" + clusterId + "]"); return gateway; }
@Override public Object call() throws Exception { try { services.deployClusterSingleton("testReconnectInDeploying", new TestServiceImpl()); } catch (IgniteClientDisconnectedException e) { checkAndWait(e); return true; } return false; } });
@Override public Object call() throws Exception { try { services.deployClusterSingleton("testReconnectInDeploying", new TestServiceImpl()); } catch (IgniteClientDisconnectedException e) { checkAndWait(e); return true; } return false; } });
/** * @param client Client node. * @param svcName Service name. * @throws Exception If failed. */ private void checkDeploy(Ignite client, String svcName) throws Exception { assertTrue(client.configuration().isClientMode()); CountDownLatch latch = new CountDownLatch(1); DummyService.exeLatch(svcName, latch); client.services().deployClusterSingleton(svcName, new DummyService()); assertTrue(latch.await(5000, TimeUnit.MILLISECONDS)); } }
/** */ @Test public void testExceptionPropagation() throws Exception { try (IgniteEx srv = startGrid("server")) { try (Ignite client = startGrid("client", getConfiguration("client").setClientMode(true))) { final String srvcName = "my-service"; try { client.services().deployClusterSingleton(srvcName, new ServiceImpl()); fail("Deployment exception has been expected."); } catch (ServiceDeploymentException ex) { String errMsg = ex.getSuppressed()[0].getMessage(); // Check that message contains cause node id assertTrue(errMsg.contains(srv.cluster().localNode().id().toString())); // Check that message contains service name assertTrue(errMsg.contains(srvcName)); Throwable cause = ex.getSuppressed()[0].getCause(); // Check that error's cause contains users message assertTrue(cause.getMessage().contains("ServiceImpl init exception")); } } } }
/** * @throws Exception If failed. */ @Test public void testCancelSingleton() throws Exception { Ignite g = randomGrid(); String name = "serviceCancel"; CountDownLatch latch = new CountDownLatch(1); DummyService.exeLatch(name, latch); g.services().deployClusterSingleton(name, new DummyService()); info("Deployed service: " + name); latch.await(); assertEquals(name, 1, DummyService.started(name)); assertEquals(name, 0, DummyService.cancelled(name)); latch = new CountDownLatch(1); DummyService.cancelLatch(name, latch); g.services().cancel(name); info("Cancelled service: " + name); latch.await(); assertEquals(name, 1, DummyService.started(name)); assertEquals(name, 1, DummyService.cancelled(name)); }
/** * @throws Exception If failed. */ @Test public void testClientReconnectLongServiceInit() throws Exception { startGrid("server"); Ignite client = startGrid("client"); client.services().deployClusterSingleton("my-service", new MyLongInitServiceImpl()); MyService proxy = client.services().serviceProxy("my-service", MyService.class, false); assertEquals(9001, proxy.hello()); final CountDownLatch latch = new CountDownLatch(1); client.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event event) { latch.countDown(); return true; } }, EventType.EVT_CLIENT_NODE_RECONNECTED); stopGrid("server"); startGrid("server"); assertTrue(latch.await(10, TimeUnit.SECONDS)); client.services().deployClusterSingleton("my-service", new MyLongInitServiceImpl()); assertEquals(9001, proxy.hello()); }
/** * @throws Exception If failed. */ @Test public void testClientReconnect() throws Exception { startGrid("server"); Ignite client = startGrid("client"); client.services().deployClusterSingleton("my-service", new MyServiceImpl()); MyService proxy = client.services().serviceProxy("my-service", MyService.class, false); assertEquals(42, proxy.hello()); final CountDownLatch latch = new CountDownLatch(1); client.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event event) { latch.countDown(); return true; } }, EventType.EVT_CLIENT_NODE_RECONNECTED); stopGrid("server"); startGrid("server"); assertTrue(latch.await(10, TimeUnit.SECONDS)); client.services().deployClusterSingleton("my-service", new MyServiceImpl()); assertEquals(42, proxy.hello()); }
@Override public void run(IgniteServices services, String svcName, TestService svc) throws Exception { services.deployClusterSingleton(svcName, (Service)svc); ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(svcName); cfg.setService((Service)svc); cfg.setTotalCount(1); cfg.setMaxPerNodeCount(1); cfg.setNodeFilter(services.clusterGroup().predicate()); services.deploy(cfg); waitForServiceDeploymentIfNeeded(services, svcName); } }));
/** * @throws Exception If failed. */ @Test public void testExecution() throws Exception { startGrid(0); // Server. Ignition.setClientMode(true); Ignite ignite = startGrid(); // Client. ignite.services().deployClusterSingleton("my-service", new MyServiceImpl()); MyService svc = ignite.services().serviceProxy("my-service", MyService.class, false); svc.hello(); }
/** * @throws Exception If failed. */ @Test public void testCancelSingletonAsync() throws Exception { Ignite g = randomGrid(); String name = "serviceCancelAsync"; CountDownLatch latch = new CountDownLatch(1); DummyService.exeLatch(name, latch); g.services().deployClusterSingleton(name, new DummyService()); info("Deployed service: " + name); latch.await(); assertEquals(name, 1, DummyService.started(name)); assertEquals(name, 0, DummyService.cancelled(name)); latch = new CountDownLatch(1); DummyService.cancelLatch(name, latch); g.services().cancelAsync(name).get(); info("Cancelled service: " + name); latch.await(); assertEquals(name, 1, DummyService.started(name)); assertEquals(name, 1, DummyService.cancelled(name)); }
/** * @throws Exception If failed. */ @Test public void testClusterSingletonProxy() throws Exception { String name = "testClusterSingletonProxy"; Ignite ignite = randomGrid(); ignite.services().deployClusterSingleton(name, new CounterServiceImpl()); CounterService svc = ignite.services().serviceProxy(name, CounterService.class, true); for (int i = 0; i < 10; i++) svc.increment(); assertEquals(10, svc.get()); }
/** * @throws Exception If failed. */ @Test public void testSameConfigurationOld() throws Exception { String name = "dupServiceOld"; IgniteServices svcs1 = randomGrid().services().withAsync(); IgniteServices svcs2 = randomGrid().services().withAsync(); svcs1.deployClusterSingleton(name, new DummyService()); IgniteFuture<?> fut1 = svcs1.future(); svcs2.deployClusterSingleton(name, new DummyService()); IgniteFuture<?> fut2 = svcs2.future(); info("Deployed service: " + name); fut1.get(); info("Finished waiting for service future1: " + name); // This must succeed without exception because configuration is the same. fut2.get(); info("Finished waiting for service future2: " + name); }
/** * @throws Exception If failed. */ @Test public void testReconnect() throws Exception { Ignite client = grid(serverCount()); assertTrue(client.cluster().localNode().isClient()); IgniteServices services = client.services(); services.deployClusterSingleton("testReconnect", new TestServiceImpl()); TestService srvc = services.serviceProxy("testReconnect", TestService.class, false); assertNotNull(srvc); long topVer = grid(0).cluster().topologyVersion(); assertEquals((Object)topVer, srvc.test()); Ignite srv = ignite(0); reconnectClientNode(client, srv, null); CountDownLatch latch = new CountDownLatch(1); DummyService.exeLatch("testReconnect2", latch); services.deployClusterSingleton("testReconnect2", new DummyService()); assertTrue(latch.await(5000, TimeUnit.MILLISECONDS)); assertEquals((Object)(topVer + 2), srvc.test()); }
Ignite server = startGrid("server"); server.services().deployClusterSingleton("my-service", MyServiceFactory.create());
/** * @throws Exception If failed. */ @Test public void testDeploySingletonOld() throws Exception { Ignite g = randomGrid(); String name = "serviceSingletonOld"; CountDownLatch latch = new CountDownLatch(1); DummyService.exeLatch(name, latch); IgniteServices svcs = g.services().withAsync(); svcs.deployClusterSingleton(name, new DummyService()); IgniteFuture<?> fut = svcs.future(); info("Deployed service: " + name); fut.get(); info("Finished waiting for service future: " + name); latch.await(); assertEquals(name, 1, DummyService.started(name)); assertEquals(name, 0, DummyService.cancelled(name)); checkCount(name, g.services().serviceDescriptors(), 1); }
/** * @throws Exception If failed. */ @Test public void testPackagePrivateService() throws Exception { try { Ignite server = startGrid("server"); server.services().deployClusterSingleton("my-service", MyServiceFactory.create()); Ignition.setClientMode(true); Ignite client = startGrid("client"); MyService svc = client.services().serviceProxy("my-service", MyService.class, true); assertEquals(42, svc.hello()); } finally { stopAllGrids(); } } }
/** * @throws Exception If failed. */ @Test public void testServiceRemove() throws Exception { Ignite client = grid(serverCount()); assertTrue(client.cluster().localNode().isClient()); Ignite srv = ignite(0); IgniteServices clnServices = client.services(); final IgniteServices srvServices = srv.services(); srvServices.deployClusterSingleton("testServiceRemove", new TestServiceImpl()); final TestService srvc = clnServices.serviceProxy("testServiceRemove", TestService.class, false); assertNotNull(srvc); assertNotNull(srvc.test()); reconnectClientNode(client, srv, new Runnable() { @Override public void run() { srvServices.cancel("testServiceRemove"); } }); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return srvc.test(); } }, IgniteException.class, null); clnServices.deployClusterSingleton("testServiceRemove", new TestServiceImpl()); TestService newSrvc = clnServices.serviceProxy("testServiceRemove", TestService.class, false); assertNotNull(newSrvc); assertNotNull(newSrvc.test()); }
/** * @throws Exception If failed. */ @Test public void testDifferentConfigurationOld() throws Exception { String name = "dupServiceOld"; IgniteServices svcs1 = randomGrid().services().withAsync(); IgniteServices svcs2 = randomGrid().services().withAsync(); svcs1.deployClusterSingleton(name, new DummyService()); IgniteFuture<?> fut1 = svcs1.future(); svcs2.deployNodeSingleton(name, new DummyService()); IgniteFuture<?> fut2 = svcs2.future(); info("Deployed service: " + name); fut1.get(); info("Finished waiting for service future: " + name); try { fut2.get(); fail("Failed to receive mismatching configuration exception."); } catch (IgniteException e) { info("Received mismatching configuration exception: " + e.getMessage()); } }