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();
}
}
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);
}
}
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));
}
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);
}
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));
}
Aggregations