Search in sources :

Example 36 with ServiceConfiguration

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

the class IgniteServiceProcessor method deployAll.

/**
 * @param cfgs Service configurations.
 * @param dfltNodeFilter Default NodeFilter.
 * @return Future for deployment.
 */
private IgniteInternalFuture<?> deployAll(@NotNull Collection<ServiceConfiguration> cfgs, @Nullable IgnitePredicate<ClusterNode> dfltNodeFilter) {
    opsLock.readLock().lock();
    try {
        if (disconnected) {
            return new GridFinishedFuture<>(new IgniteClientDisconnectedCheckedException(ctx.cluster().clientReconnectFuture(), "Failed to deploy services, " + "client node disconnected: " + cfgs));
        }
        if (ctx.isStopping()) {
            return new GridFinishedFuture<>(new IgniteCheckedException("Failed to deploy services, " + "node is stopping: " + cfgs));
        }
        if (cfgs.isEmpty())
            return new GridFinishedFuture<>();
        PreparedConfigurations<IgniteUuid> srvcCfg = prepareServiceConfigurations(cfgs, dfltNodeFilter);
        List<ServiceConfiguration> cfgsCp = srvcCfg.cfgs;
        List<GridServiceDeploymentFuture<IgniteUuid>> failedFuts = srvcCfg.failedFuts;
        GridServiceDeploymentCompoundFuture<IgniteUuid> res = new GridServiceDeploymentCompoundFuture<>();
        if (!cfgsCp.isEmpty()) {
            try {
                Collection<ServiceChangeAbstractRequest> reqs = new ArrayList<>();
                for (ServiceConfiguration cfg : cfgsCp) {
                    IgniteUuid srvcId = IgniteUuid.randomUuid();
                    GridServiceDeploymentFuture<IgniteUuid> fut = new GridServiceDeploymentFuture<>(cfg, srvcId);
                    res.add(fut, true);
                    reqs.add(new ServiceDeploymentRequest(srvcId, cfg));
                    depFuts.put(srvcId, fut);
                }
                ServiceChangeBatchRequest msg = new ServiceChangeBatchRequest(reqs);
                ctx.discovery().sendCustomEvent(msg);
                if (log.isDebugEnabled())
                    log.debug("Services have been sent to deploy, req=" + msg);
            } catch (IgniteException | IgniteCheckedException e) {
                for (IgniteUuid id : res.servicesToRollback()) depFuts.remove(id).onDone(e);
                res.onDone(new IgniteCheckedException(new ServiceDeploymentException("Failed to deploy provided services.", e, cfgs)));
                return res;
            }
        }
        if (failedFuts != null) {
            for (GridServiceDeploymentFuture<IgniteUuid> fut : failedFuts) res.add(fut, false);
        }
        res.markInitialized();
        return res;
    } finally {
        opsLock.readLock().unlock();
    }
}
Also used : ArrayList(java.util.ArrayList) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)

Example 37 with ServiceConfiguration

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

the class IgniteServiceProcessor method processServicesChangeRequest.

/**
 * @param snd Sender.
 * @param msg Message.
 */
private void processServicesChangeRequest(ClusterNode snd, ServiceChangeBatchRequest msg) {
    DiscoveryDataClusterState state = ctx.state().clusterState();
    if (!state.active() || state.transition()) {
        for (ServiceChangeAbstractRequest req : msg.requests()) {
            GridFutureAdapter<?> fut = null;
            if (req instanceof ServiceDeploymentRequest)
                fut = depFuts.remove(req.serviceId());
            else if (req instanceof ServiceUndeploymentRequest)
                fut = undepFuts.remove(req.serviceId());
            if (fut != null) {
                fut.onDone(new IgniteCheckedException("Operation has been canceled, cluster state " + "change is in progress."));
            }
        }
        return;
    }
    Map<IgniteUuid, ServiceInfo> toDeploy = new HashMap<>();
    Map<IgniteUuid, ServiceInfo> toUndeploy = new HashMap<>();
    for (ServiceChangeAbstractRequest req : msg.requests()) {
        IgniteUuid reqSrvcId = req.serviceId();
        ServiceInfo oldDesc = registeredServices.get(reqSrvcId);
        if (req instanceof ServiceDeploymentRequest) {
            Exception err = null;
            if (oldDesc != null) {
                // In case of a collision of IgniteUuid.randomUuid() (almost impossible case)
                err = new IgniteCheckedException("Failed to deploy service. Service with generated id already" + "exists : [" + "srvcId" + reqSrvcId + ", srvcTop=" + oldDesc.topologySnapshot() + ']');
            } else {
                ServiceConfiguration cfg = ((ServiceDeploymentRequest) req).configuration();
                if (ctx.security().enabled())
                    err = checkPermissions(((ServiceDeploymentRequest) req).configuration().getName(), SERVICE_DEPLOY);
                if (err == null) {
                    oldDesc = lookupInRegisteredServices(cfg.getName());
                    if (oldDesc == null) {
                        if (cfg.getCacheName() != null && ctx.cache().cacheDescriptor(cfg.getCacheName()) == null) {
                            err = new IgniteCheckedException("Failed to deploy service, " + "affinity cache is not found, cfg=" + cfg);
                        } else {
                            ServiceInfo desc = new ServiceInfo(snd.id(), reqSrvcId, cfg);
                            registerService(desc);
                            toDeploy.put(reqSrvcId, desc);
                        }
                    } else {
                        if (!oldDesc.configuration().equalsIgnoreNodeFilter(cfg)) {
                            err = new IgniteCheckedException("Failed to deploy service " + "(service already exists with different configuration) : " + "[deployed=" + oldDesc.configuration() + ", new=" + cfg + ']');
                        } else {
                            GridServiceDeploymentFuture<IgniteUuid> fut = depFuts.remove(reqSrvcId);
                            if (fut != null) {
                                fut.onDone();
                                if (log.isDebugEnabled()) {
                                    log.debug("Service sent to deploy is already deployed : " + "[srvcId=" + oldDesc.serviceId() + ", cfg=" + oldDesc.configuration());
                                }
                            }
                        }
                    }
                }
            }
            if (err != null) {
                completeInitiatingFuture(true, reqSrvcId, err);
                U.warn(log, err.getMessage(), err);
            }
        } else if (req instanceof ServiceUndeploymentRequest) {
            ServiceInfo rmv = registeredServices.remove(reqSrvcId);
            assert oldDesc == rmv : "Concurrent map modification.";
            toUndeploy.put(reqSrvcId, rmv);
        }
    }
    if (!toDeploy.isEmpty() || !toUndeploy.isEmpty()) {
        ServiceDeploymentActions depActions = new ServiceDeploymentActions();
        if (!toDeploy.isEmpty())
            depActions.servicesToDeploy(toDeploy);
        if (!toUndeploy.isEmpty())
            depActions.servicesToUndeploy(toUndeploy);
        msg.servicesDeploymentActions(depActions);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) 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) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Example 38 with ServiceConfiguration

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

the class IgniteServiceProcessor method deployMultiple.

/**
 * @param name Service name.
 * @param srvc Service.
 * @param totalCnt Total count.
 * @param maxPerNodeCnt Max per-node count.
 * @return Future.
 */
public IgniteInternalFuture<?> deployMultiple(ClusterGroup prj, String name, Service srvc, int totalCnt, int maxPerNodeCnt) {
    ServiceConfiguration cfg = new ServiceConfiguration();
    cfg.setName(name);
    cfg.setService(srvc);
    cfg.setTotalCount(totalCnt);
    cfg.setMaxPerNodeCount(maxPerNodeCnt);
    return deployAll(prj, Collections.singleton(cfg));
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration)

Example 39 with ServiceConfiguration

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

the class IgniteServiceProcessor method deployKeyAffinitySingleton.

/**
 * @param name Service name.
 * @param srvc Service.
 * @param cacheName Cache name.
 * @param affKey Affinity key.
 * @return Future.
 */
public IgniteInternalFuture<?> deployKeyAffinitySingleton(String name, Service srvc, String cacheName, Object affKey) {
    A.notNull(affKey, "affKey");
    ServiceConfiguration cfg = new ServiceConfiguration();
    cfg.setName(name);
    cfg.setService(srvc);
    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 40 with ServiceConfiguration

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

the class SystemViewCommandTest method testServices.

/**
 */
@Test
public void testServices() {
    ServiceConfiguration srvcCfg = new ServiceConfiguration();
    srvcCfg.setName("service");
    srvcCfg.setMaxPerNodeCount(1);
    srvcCfg.setService(new DummyService());
    ignite0.services().deploy(srvcCfg);
    List<List<String>> srvsView = systemView(ignite0, SVCS_VIEW);
    assertEquals(1, srvsView.size());
    List<String> sysView = srvsView.get(0);
    // name
    assertEquals(srvcCfg.getName(), sysView.get(1));
    // serviceClass
    assertEquals(DummyService.class.getName(), sysView.get(2));
    // maxPerNodeCount
    assertEquals(Integer.toString(srvcCfg.getMaxPerNodeCount()), sysView.get(6));
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) DummyService(org.apache.ignite.internal.processors.service.DummyService) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) CommandList(org.apache.ignite.internal.commandline.CommandList) List(java.util.List) 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