use of org.apache.ignite.services.ServiceConfiguration in project ignite by apache.
the class GridServiceProcessor method deployAll.
/**
* @param cfgs Service configurations.
* @param dfltNodeFilter Default NodeFilter.
* @return Future for deployment.
*/
private IgniteInternalFuture<?> deployAll(Collection<ServiceConfiguration> cfgs, @Nullable IgnitePredicate<ClusterNode> dfltNodeFilter) {
assert cfgs != null;
PreparedConfigurations srvCfg = prepareServiceConfigurations(cfgs, dfltNodeFilter);
List<ServiceConfiguration> cfgsCp = srvCfg.cfgs;
List<GridServiceDeploymentFuture> failedFuts = srvCfg.failedFuts;
Collections.sort(cfgsCp, new Comparator<ServiceConfiguration>() {
@Override
public int compare(ServiceConfiguration cfg1, ServiceConfiguration cfg2) {
return cfg1.getName().compareTo(cfg2.getName());
}
});
GridServiceDeploymentCompoundFuture res;
while (true) {
res = new GridServiceDeploymentCompoundFuture();
if (ctx.deploy().enabled())
ctx.cache().context().deploy().ignoreOwnership(true);
try {
if (cfgsCp.size() == 1)
writeServiceToCache(res, cfgsCp.get(0));
else if (cfgsCp.size() > 1) {
try (Transaction tx = serviceCache().txStart(PESSIMISTIC, READ_COMMITTED)) {
for (ServiceConfiguration cfg : cfgsCp) {
try {
writeServiceToCache(res, cfg);
} catch (IgniteCheckedException e) {
if (X.hasCause(e, ClusterTopologyCheckedException.class))
// Retry.
throw e;
else
U.error(log, e.getMessage());
}
}
tx.commit();
}
}
break;
} catch (IgniteException | IgniteCheckedException e) {
for (String name : res.servicesToRollback()) depFuts.remove(name).onDone(e);
if (X.hasCause(e, ClusterTopologyCheckedException.class)) {
if (log.isDebugEnabled())
log.debug("Topology changed while deploying services (will retry): " + e.getMessage());
} else {
res.onDone(new IgniteCheckedException(new ServiceDeploymentException("Failed to deploy provided services.", e, cfgs)));
return res;
}
} finally {
if (ctx.deploy().enabled())
ctx.cache().context().deploy().ignoreOwnership(false);
}
}
if (ctx.clientDisconnected()) {
IgniteClientDisconnectedCheckedException err = new IgniteClientDisconnectedCheckedException(ctx.cluster().clientReconnectFuture(), "Failed to deploy services, client node disconnected: " + cfgs);
for (String name : res.servicesToRollback()) {
GridServiceDeploymentFuture fut = depFuts.remove(name);
if (fut != null)
fut.onDone(err);
}
return new GridFinishedFuture<>(err);
}
if (failedFuts != null) {
for (GridServiceDeploymentFuture fut : failedFuts) res.add(fut, false);
}
res.markInitialized();
return res;
}
use of org.apache.ignite.services.ServiceConfiguration in project ignite by apache.
the class GridServiceProcessor method deployMultiple.
/**
* @param name Service name.
* @param svc Service.
* @param totalCnt Total count.
* @param maxPerNodeCnt Max per-node count.
* @return Future.
*/
public IgniteInternalFuture<?> deployMultiple(ClusterGroup prj, String name, Service svc, int totalCnt, int maxPerNodeCnt) {
ServiceConfiguration cfg = new ServiceConfiguration();
cfg.setName(name);
cfg.setService(svc);
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 GridServiceProcessor method reassign.
/**
* Reassigns service to nodes.
*
* @param dep Service deployment.
* @param topVer Topology version.
* @throws IgniteCheckedException If failed.
*/
private void reassign(GridServiceDeployment dep, AffinityTopologyVersion topVer) throws IgniteCheckedException {
IgniteInternalCache<Object, Object> cache = serviceCache();
ServiceConfiguration cfg = dep.configuration();
Object nodeFilter = cfg.getNodeFilter();
if (nodeFilter != null)
ctx.resource().injectGeneric(nodeFilter);
int totalCnt = cfg.getTotalCount();
int maxPerNodeCnt = cfg.getMaxPerNodeCount();
String cacheName = cfg.getCacheName();
Object affKey = cfg.getAffinityKey();
while (true) {
GridServiceAssignments assigns = new GridServiceAssignments(cfg, dep.nodeId(), topVer.topologyVersion());
Collection<ClusterNode> nodes;
// Call node filter outside of transaction.
if (affKey == null) {
nodes = ctx.discovery().nodes(topVer);
if (assigns.nodeFilter() != null) {
Collection<ClusterNode> nodes0 = new ArrayList<>();
for (ClusterNode node : nodes) {
if (assigns.nodeFilter().apply(node))
nodes0.add(node);
}
nodes = nodes0;
}
} else
nodes = null;
try (GridNearTxLocal tx = cache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
GridServiceAssignmentsKey key = new GridServiceAssignmentsKey(cfg.getName());
GridServiceAssignments oldAssigns = (GridServiceAssignments) cache.get(key);
Map<UUID, Integer> cnts = new HashMap<>();
if (affKey != null) {
ClusterNode n = ctx.affinity().mapKeyToNode(cacheName, affKey, topVer);
if (n != null) {
int cnt = maxPerNodeCnt == 0 ? totalCnt == 0 ? 1 : totalCnt : maxPerNodeCnt;
cnts.put(n.id(), cnt);
}
} else {
if (!nodes.isEmpty()) {
int size = nodes.size();
int perNodeCnt = totalCnt != 0 ? totalCnt / size : maxPerNodeCnt;
int remainder = totalCnt != 0 ? totalCnt % size : 0;
if (perNodeCnt >= maxPerNodeCnt && maxPerNodeCnt != 0) {
perNodeCnt = maxPerNodeCnt;
remainder = 0;
}
for (ClusterNode n : nodes) cnts.put(n.id(), perNodeCnt);
assert perNodeCnt >= 0;
assert remainder >= 0;
if (remainder > 0) {
int cnt = perNodeCnt + 1;
if (oldAssigns != null) {
Collection<UUID> used = new HashSet<>();
// Avoid redundant moving of services.
for (Map.Entry<UUID, Integer> e : oldAssigns.assigns().entrySet()) {
// Do not assign services to left nodes.
if (ctx.discovery().node(e.getKey()) == null)
continue;
// If old count and new count match, then reuse the assignment.
if (e.getValue() == cnt) {
cnts.put(e.getKey(), cnt);
used.add(e.getKey());
if (--remainder == 0)
break;
}
}
if (remainder > 0) {
List<Map.Entry<UUID, Integer>> entries = new ArrayList<>(cnts.entrySet());
// Randomize.
Collections.shuffle(entries);
for (Map.Entry<UUID, Integer> e : entries) {
// Assign only the ones that have not been reused from previous assignments.
if (!used.contains(e.getKey())) {
if (e.getValue() < maxPerNodeCnt || maxPerNodeCnt == 0) {
e.setValue(e.getValue() + 1);
if (--remainder == 0)
break;
}
}
}
}
} else {
List<Map.Entry<UUID, Integer>> entries = new ArrayList<>(cnts.entrySet());
// Randomize.
Collections.shuffle(entries);
for (Map.Entry<UUID, Integer> e : entries) {
e.setValue(e.getValue() + 1);
if (--remainder == 0)
break;
}
}
}
}
}
assigns.assigns(cnts);
cache.put(key, assigns);
tx.commit();
break;
} catch (ClusterTopologyCheckedException e) {
if (log.isDebugEnabled())
log.debug("Topology changed while reassigning (will retry): " + e.getMessage());
U.sleep(10);
}
}
}
use of org.apache.ignite.services.ServiceConfiguration in project ignite by apache.
the class PlatformServices method dotnetDeploy.
/**
* Deploys dotnet service.
*
* @param reader Binary reader.
* @param services Services.
*/
private void dotnetDeploy(BinaryRawReaderEx reader, IgniteServices services) {
ServiceConfiguration cfg = dotnetConfiguration(reader);
services.deploy(cfg);
}
use of org.apache.ignite.services.ServiceConfiguration in project ignite by apache.
the class PlatformServices method dotnetConfiguration.
/**
* Read the dotnet service configuration.
*
* @param reader Binary reader,
* @return Service configuration.
*/
@NotNull
private ServiceConfiguration dotnetConfiguration(BinaryRawReaderEx reader) {
ServiceConfiguration cfg = new ServiceConfiguration();
cfg.setName(reader.readString());
cfg.setService(new PlatformDotNetServiceImpl(reader.readObjectDetached(), platformCtx, srvKeepBinary));
cfg.setTotalCount(reader.readInt());
cfg.setMaxPerNodeCount(reader.readInt());
cfg.setCacheName(reader.readString());
cfg.setAffinityKey(reader.readObjectDetached());
Object filter = reader.readObjectDetached();
if (filter != null)
cfg.setNodeFilter(platformCtx.createClusterNodeFilter(filter));
return cfg;
}
Aggregations