Search in sources :

Example 1 with ServiceConfiguration

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

the class GridServiceProcessor method prepareServiceConfigurations.

/**
 * @param cfgs Service configurations.
 * @param dfltNodeFilter Default NodeFilter.
 * @return Configurations to deploy.
 */
private PreparedConfigurations prepareServiceConfigurations(Collection<ServiceConfiguration> cfgs, IgnitePredicate<ClusterNode> dfltNodeFilter) {
    List<ServiceConfiguration> cfgsCp = new ArrayList<>(cfgs.size());
    Marshaller marsh = ctx.config().getMarshaller();
    List<GridServiceDeploymentFuture> failedFuts = null;
    for (ServiceConfiguration cfg : cfgs) {
        Exception err = null;
        // or only on server nodes if no projection .
        if (cfg.getNodeFilter() == null && dfltNodeFilter != null)
            cfg.setNodeFilter(dfltNodeFilter);
        try {
            validate(cfg);
        } catch (Exception e) {
            U.error(log, "Failed to validate service configuration [name=" + cfg.getName() + ", srvc=" + cfg.getService() + ']', e);
            err = e;
        }
        if (err == null) {
            try {
                ctx.security().authorize(cfg.getName(), SecurityPermission.SERVICE_DEPLOY, null);
            } catch (Exception e) {
                U.error(log, "Failed to authorize service creation [name=" + cfg.getName() + ", srvc=" + cfg.getService() + ']', e);
                err = e;
            }
        }
        if (err == null) {
            try {
                byte[] srvcBytes = U.marshal(marsh, cfg.getService());
                cfgsCp.add(new LazyServiceConfiguration(cfg, srvcBytes));
            } catch (Exception e) {
                U.error(log, "Failed to marshal service with configured marshaller [name=" + cfg.getName() + ", srvc=" + cfg.getService() + ", marsh=" + marsh + "]", e);
                err = e;
            }
        }
        if (err != null) {
            if (failedFuts == null)
                failedFuts = new ArrayList<>();
            GridServiceDeploymentFuture fut = new GridServiceDeploymentFuture(cfg);
            fut.onDone(err);
            failedFuts.add(fut);
        }
    }
    return new PreparedConfigurations(cfgsCp, failedFuts);
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) ArrayList(java.util.ArrayList) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) SecurityException(org.apache.ignite.plugin.security.SecurityException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 2 with ServiceConfiguration

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

the class GridServiceProcessor method deployKeyAffinitySingleton.

/**
 * @param name Service name.
 * @param svc Service.
 * @param cacheName Cache name.
 * @param affKey Affinity key.
 * @return Future.
 */
public IgniteInternalFuture<?> deployKeyAffinitySingleton(String name, Service svc, String cacheName, Object affKey) {
    A.notNull(affKey, "affKey");
    ServiceConfiguration cfg = new ServiceConfiguration();
    cfg.setName(name);
    cfg.setService(svc);
    cfg.setCacheName(cacheName);
    cfg.setAffinityKey(affKey);
    cfg.setTotalCount(1);
    cfg.setMaxPerNodeCount(1);
    // Ignore projection here.
    return deployAll(Collections.singleton(cfg), null);
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration)

Example 3 with ServiceConfiguration

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

the class GridServiceProcessorBatchDeploySelfTest method _testDeployAllTopologyChangeFail.

/**
 * TODO: enable when IGNITE-6259 is fixed.
 *
 * @throws Exception If failed.
 */
public void _testDeployAllTopologyChangeFail() throws Exception {
    final 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);
        List<ServiceConfiguration> failingCfgs = new ArrayList<>();
        subscribeExeLatch(cfgs, latch);
        int from = 0;
        while (from < numServices) {
            int to = Math.min(numServices, from + batchSize);
            List<ServiceConfiguration> cfgsBatch = cfgs.subList(from, to);
            ServiceConfiguration failingCfg = cfgsBatch.get(0);
            failingCfg.setName(null);
            failingCfgs.add(failingCfg);
            try {
                client.services().deployAllAsync(cfgsBatch).get(5000);
                fail("Should never reach here.");
            } catch (ServiceDeploymentException e) {
                assertEquals(1, e.getFailedConfigurations().size());
                ServiceConfiguration actFailedCfg = copyService(e.getFailedConfigurations().iterator().next());
                assertEquals(failingCfg, actFailedCfg);
                latch.countDown();
            }
            from = to;
        }
        assertTrue(latch.await(30, TimeUnit.SECONDS));
        cfgs.removeAll(failingCfgs);
        assertDeployedServices(client, cfgs);
    } finally {
        finished.set(true);
    }
    topChangeFut.get();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ArrayList(java.util.ArrayList) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Ignite(org.apache.ignite.Ignite)

Example 4 with ServiceConfiguration

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

the class JmxExporterSpiTest method testServices.

/**
 */
@Test
public void testServices() throws Exception {
    ServiceConfiguration srvcCfg = new ServiceConfiguration();
    srvcCfg.setName("service");
    srvcCfg.setMaxPerNodeCount(1);
    srvcCfg.setService(new DummyService());
    ignite.services().deploy(srvcCfg);
    TabularDataSupport srvs = systemView(SVCS_VIEW);
    assertEquals(ignite.context().service().serviceDescriptors().size(), srvs.size());
    CompositeData sysView = srvs.get(new Object[] { 0 });
    assertEquals(srvcCfg.getName(), sysView.get("name"));
    assertEquals(srvcCfg.getMaxPerNodeCount(), sysView.get("maxPerNodeCount"));
    assertEquals(DummyService.class.getName(), sysView.get("serviceClass"));
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) DummyService(org.apache.ignite.internal.processors.service.DummyService) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) Test(org.junit.Test)

Example 5 with ServiceConfiguration

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

the class IgniteServiceProcessor method prepareServiceConfigurations.

/**
 * @param cfgs Service configurations.
 * @param dfltNodeFilter Default NodeFilter.
 * @return Configurations to deploy.
 */
private PreparedConfigurations<IgniteUuid> prepareServiceConfigurations(Collection<ServiceConfiguration> cfgs, IgnitePredicate<ClusterNode> dfltNodeFilter) {
    List<ServiceConfiguration> cfgsCp = new ArrayList<>(cfgs.size());
    List<GridServiceDeploymentFuture<IgniteUuid>> failedFuts = null;
    for (ServiceConfiguration cfg : cfgs) {
        Exception err = null;
        // or only on server nodes if no projection.
        if (cfg.getNodeFilter() == null && dfltNodeFilter != null)
            cfg.setNodeFilter(dfltNodeFilter);
        try {
            validate(cfg);
        } catch (Exception e) {
            U.error(log, "Failed to validate service configuration [name=" + cfg.getName() + ", srvc=" + cfg.getService() + ']', e);
            err = e;
        }
        if (err == null) {
            try {
                byte[] srvcBytes = U.marshal(marsh, cfg.getService());
                cfgsCp.add(new LazyServiceConfiguration(cfg, srvcBytes));
            } catch (Exception e) {
                U.error(log, "Failed to marshal service with configured marshaller " + "[name=" + cfg.getName() + ", srvc=" + cfg.getService() + ", marsh=" + marsh + "]", e);
                err = e;
            }
        }
        if (err != null) {
            if (failedFuts == null)
                failedFuts = new ArrayList<>();
            GridServiceDeploymentFuture<IgniteUuid> fut = new GridServiceDeploymentFuture<>(cfg, null);
            fut.onDone(err);
            failedFuts.add(fut);
        }
    }
    return new PreparedConfigurations<>(cfgsCp, failedFuts);
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ArrayList(java.util.ArrayList) SecurityException(org.apache.ignite.plugin.security.SecurityException) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

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