Search in sources :

Example 41 with ServiceConfiguration

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

the class SqlViewExporterSpiTest method testServices.

/**
 */
@Test
public void testServices() throws Exception {
    ServiceConfiguration srvcCfg = new ServiceConfiguration();
    srvcCfg.setName("service");
    srvcCfg.setMaxPerNodeCount(1);
    srvcCfg.setService(new DummyService());
    ignite0.services().deploy(srvcCfg);
    List<List<?>> srvs = execute(ignite0, "SELECT " + "  NAME, " + "  SERVICE_ID, " + "  SERVICE_CLASS, " + "  TOTAL_COUNT, " + "  MAX_PER_NODE_COUNT, " + "  CACHE_NAME, " + "  AFFINITY_KEY, " + "  NODE_FILTER, " + "  STATICALLY_CONFIGURED, " + "  ORIGIN_NODE_ID " + "FROM SYS.SERVICES");
    assertEquals(ignite0.context().service().serviceDescriptors().size(), srvs.size());
    List<?> sysView = srvs.iterator().next();
    assertEquals(srvcCfg.getName(), sysView.get(0));
    assertEquals(DummyService.class.getName(), sysView.get(2));
    assertEquals(srvcCfg.getMaxPerNodeCount(), sysView.get(4));
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) DummyService(org.apache.ignite.internal.processors.service.DummyService) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) AbstractExporterSpiTest(org.apache.ignite.internal.metric.AbstractExporterSpiTest) Test(org.junit.Test)

Example 42 with ServiceConfiguration

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

the class KillCommandsTests method doTestCancelService.

/**
 * Test cancel of the service.
 *
 * @param startCli Client node to start service.
 * @param killCli Client node to kill service.
 * @param srv Server node.
 * @param svcCanceler Service cancel closure.
 */
public static void doTestCancelService(IgniteEx startCli, IgniteEx killCli, IgniteEx srv, Consumer<String> svcCanceler) throws Exception {
    ServiceConfiguration scfg = new ServiceConfiguration();
    scfg.setName(SVC_NAME);
    scfg.setMaxPerNodeCount(1);
    scfg.setNodeFilter(srv.cluster().predicate());
    scfg.setService(new TestServiceImpl());
    startCli.services().deploy(scfg);
    SystemView<ServiceView> svcView = srv.context().systemView().view(SVCS_VIEW);
    SystemView<ServiceView> killCliSvcView = killCli.context().systemView().view(SVCS_VIEW);
    boolean res = waitForCondition(() -> svcView.size() == 1 && killCliSvcView.size() == 1, TIMEOUT);
    assertTrue(res);
    TestService svc = startCli.services().serviceProxy(SVC_NAME, TestService.class, true);
    assertNotNull(svc);
    svcCanceler.accept(SVC_NAME);
    res = waitForCondition(() -> svcView.size() == 0, TIMEOUT);
    assertTrue(res);
}
Also used : ServiceView(org.apache.ignite.spi.systemview.view.ServiceView) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration)

Example 43 with ServiceConfiguration

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

the class GridServiceContinuousQueryRedeployTest method deployService.

/**
 * @param ignite Ignite.
 */
private void deployService(final Ignite ignite) {
    ServiceConfiguration svcCfg = new ServiceConfiguration();
    svcCfg.setService(new ManagementService());
    svcCfg.setName(SERVICE_NAME);
    svcCfg.setTotalCount(1);
    svcCfg.setMaxPerNodeCount(1);
    svcCfg.setNodeFilter((IgnitePredicate<ClusterNode>) node -> !node.isClient());
    ignite.services().deploy(svcCfg);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) Callable(java.util.concurrent.Callable) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteCache(org.apache.ignite.IgniteCache) ArrayList(java.util.ArrayList) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) List(java.util.List) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ClusterNode(org.apache.ignite.cluster.ClusterNode) ServiceContext(org.apache.ignite.services.ServiceContext) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Service(org.apache.ignite.services.Service) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Collections(java.util.Collections) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration)

Example 44 with ServiceConfiguration

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

the class GridServiceDeploymentCompoundFutureSelfTest method testWaitForCompletionOnFailingFuture.

/**
 * @throws Exception If failed.
 */
@Test
public void testWaitForCompletionOnFailingFuture() throws Exception {
    GridServiceDeploymentCompoundFuture<IgniteUuid> 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<IgniteUuid> failingFut = new GridServiceDeploymentFuture<>(failingCfg, IgniteUuid.randomUuid());
        failingFuts.add(failingFut);
        compFut.add(failingFut);
    }
    List<GridFutureAdapter<Object>> futs = new ArrayList<>(completingFutsNum);
    for (int i = 0; i < completingFutsNum; i++) {
        GridServiceDeploymentFuture<IgniteUuid> fut = new GridServiceDeploymentFuture<>(config(String.valueOf(i)), IgniteUuid.randomUuid());
        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) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 45 with ServiceConfiguration

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

the class IgniteServiceReassignmentTest method testNodeRestart2.

/**
 * @throws Exception If failed.
 */
@Test
public void testNodeRestart2() throws Exception {
    startGrids(3);
    ServiceConfiguration svcCfg = new ServiceConfiguration();
    svcCfg.setName("DummyService");
    svcCfg.setTotalCount(10);
    svcCfg.setMaxPerNodeCount(1);
    svcCfg.setService(new DummyService());
    ignite(0).services().deploy(svcCfg);
    for (int i = 0; i < 3; i++) assertEquals(42, serviceProxy(ignite(i)).foo());
    for (int i = 0; i < 3; i++) startGrid(i + 3);
    for (int i = 0; i < 3; i++) stopGrid(i);
    for (int i = 0; i < 3; i++) assertEquals(42, serviceProxy(ignite(i + 3)).foo());
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

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