services.cancel(reader.readString()); readAndListenFuture(reader, services.cancelAsync(reader.readString())); readAndListenFuture(reader, services.cancelAllAsync());
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws IgniteCheckedException { ServiceResource ann = (ServiceResource)mtd.getAnnotation(); Class svcItf = ann.proxyInterface(); Object svc; if (svcItf == Void.class) svc = ignite.services().service(ann.serviceName()); else svc = ignite.services().serviceProxy(ann.serviceName(), svcItf, ann.proxySticky()); Class<?>[] types = mtd.getMethod().getParameterTypes(); if (types.length != 1) throw new IgniteCheckedException("Setter does not have single parameter of required type [type=" + svc.getClass().getName() + ", setter=" + mtd + ']'); if (svc != null) GridResourceUtils.inject(mtd.getMethod(), target, svc); } }
@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); } }));
/** {@inheritDoc} */ @Override public PlatformTarget processInStreamOutObject(int type, BinaryRawReaderEx reader) throws IgniteCheckedException { switch (type) { case OP_SERVICE_PROXY: { String name = reader.readString(); boolean sticky = reader.readBoolean(); ServiceDescriptor d = findDescriptor(name); if (d == null) throw new IgniteException("Failed to find deployed service: " + name); Object proxy = PlatformService.class.isAssignableFrom(d.serviceClass()) ? services.serviceProxy(name, PlatformService.class, sticky) : new GridServiceProxy<>(services.clusterGroup(), name, Service.class, sticky, 0, platformCtx.kernalContext()); return new ServiceProxyHolder(proxy, d.serviceClass(), platformContext()); } } return super.processInStreamOutObject(type, reader); }
/** * @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(); }
/** * Unwraps error message from InvocationTargetException. * * @throws Exception If failed. */ @SuppressWarnings("ThrowableNotThrown") @Test public void testException() throws Exception { String name = "errorService"; Ignite ignite = grid(0); ignite.services(ignite.cluster().forRemotes()).deployNodeSingleton(name, new ErrorServiceImpl()); final ErrorService svc = ignite.services().serviceProxy(name, ErrorService.class, false); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { svc.go(); return null; } }, ErrorServiceException.class, "Test exception"); }
TestService proxy = services.serviceProxy(SERVICE_NAME, TestService.class, sticky); assertEquals(expected, proxy.getValue()); assertEquals("Expected 1 deployed service", 1, services.serviceDescriptors().size()); services.cancelAll(); else services.cancel(SERVICE_NAME);
/** * @throws Exception If failed. */ @Test public void testDeployMultiple2Old() throws Exception { Ignite g = randomGrid(); String name = "serviceMultiple2Old"; int cnt = nodeCount() * 2 + 1; CountDownLatch latch = new CountDownLatch(cnt); DummyService.exeLatch(name, latch); IgniteServices svcs = g.services().withAsync(); svcs.deployMultiple(name, new DummyService(), cnt, 3); IgniteFuture<?> fut = svcs.future(); info("Deployed service: " + name); fut.get(); info("Finished waiting for service future: " + name); latch.await(); assertEquals(name, cnt, DummyService.started(name)); assertEquals(name, 0, DummyService.cancelled(name)); checkCount(name, g.services().serviceDescriptors(), cnt); }
/** * @throws Exception If failed. */ @Test public void testServiceDeployment1() throws Exception { startGrid(0).services().deploy(serviceConfig(true)); startGrid(1).services().deploy(serviceConfig(false)); client = true; startGrid(2).services().deploy(serviceConfig(true)); startGrid(3).services().deploy(serviceConfig(false)); for (int i = 0; i < 4; i++) ignite(i).services().serviceDescriptors(); ignite(0).services().cancel("TestDeploymentService1"); ignite(1).services().cancel("TestDeploymentService2"); }
/** * Stops Apache Ignite services that represent distributed inference infrastructure. */ private void stopService() { ignite.services().cancel(String.format(INFERENCE_SERVICE_NAME_PATTERN, suffix)); }
/** * @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()); } }
/** * @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); }
@Override public boolean apply() { MapService<Integer, String> svc = grid(idx) .services() .serviceProxy(name, MapService.class, false); ref.set(svc); return svc instanceof Service; } }, 2000);
/** * @throws Exception If failed. */ @Test public void testDefaultService() throws Exception { UUID clientNodeId = grid(CLIENT_IDX).cluster().localNode().id(); for (int i = 0 ; i < NODES_CNT; i++) { log.info("Iteration: " + i); final Ignite ignite = grid(i); ignite.services().deployNodeSingleton(SINGLETON_NAME, new TestService()); final ClusterGroup grp = ignite.cluster(); assertEquals(NODES_CNT, grp.nodes().size()); GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return ignite.services(grp).serviceDescriptors().size() == 1; } }, 5000); Collection<ServiceDescriptor> srvDscs = ignite.services(grp).serviceDescriptors(); assertEquals(1, srvDscs.size()); Map<UUID, Integer> nodesMap = F.first(srvDscs).topologySnapshot(); assertEquals(NODES_CNT - 1, nodesMap.size()); for (Map.Entry<UUID, Integer> nodeInfo : nodesMap.entrySet()) { assertFalse(clientNodeId.equals(nodeInfo.getKey())); assertEquals(1, nodeInfo.getValue().intValue()); } ignite.services().cancelAll(); } }
/** * @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)); }
grid(0).services().deployMultiple(SERVICE_NAME, new CounterServiceImpl(), total, maxPerNode); grid(F.first(startedGrids)).services().cancel(SERVICE_NAME);
/** * @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); }
srvcCfg.setService(new DummyService()); IgniteServices svcs = g.services().withAsync(); svcs.deploy(srvcCfg); IgniteFuture<?> fut = svcs.future(); assertEquals(name, 0, DummyService.cancelled(name)); checkCount(name, g.services().serviceDescriptors(), nodeCount());
@Override public void run(IgniteServices services, String svcName, TestService svc) throws Exception { services.deployClusterSingleton(svcName, (Service)svc); waitForServiceDeploymentIfNeeded(services, svcName); } }));
IgniteFuture<?> fut = svcs.deployNodeSingletonAsync(name, new DummyService()); assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));