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