Skip to content

Commit

Permalink
IGNITE-14823 Service abbrevation (#11195)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov authored Jan 29, 2024
1 parent eca48ef commit 628e424
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,26 @@ private static class Audit implements ServiceCallInterceptor {

/** {@inheritDoc} */
@Override public Object invoke(String mtd, Object[] args, ServiceContext ctx, Callable<Object> next) throws Exception {
String serviceName = ctx.name();
String srvcName = ctx.name();
ServiceCallContext callCtx = ctx.currentCallContext();
String user = callCtx == null ? null : callCtx.attribute("user");

recordEvent(user, serviceName, mtd, "start");
recordEvent(user, srvcName, mtd, "start");

try {
// Execute service method.
Object res = next.call();

// Record finish event after execution of the service method.
recordEvent(user, serviceName, mtd, "result " + res);
recordEvent(user, srvcName, mtd, "result " + res);

return res;
}
catch (Exception e) {
log.error("Intercepted error", e);

// Record error.
recordEvent(user, serviceName, mtd, "error: " + e.getMessage());
recordEvent(user, srvcName, mtd, "error: " + e.getMessage());

// Re-throw exception to initiator.
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,17 +685,17 @@ private List<GridQueryFieldMetadata> fieldsMeta(QueryPlan plan, boolean isParams

/** */
private void onStart(GridKernalContext ctx, Service... services) {
for (Service service : services) {
if (service instanceof LifecycleAware)
((LifecycleAware)service).onStart(ctx);
for (Service srvc : services) {
if (srvc instanceof LifecycleAware)
((LifecycleAware)srvc).onStart(ctx);
}
}

/** */
private void onStop(Service... services) {
for (Service service : services) {
if (service instanceof LifecycleAware)
((LifecycleAware)service).onStop();
for (Service srvc : services) {
if (srvc instanceof LifecycleAware)
((LifecycleAware)srvc).onStop();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,20 @@ public void testCancelTx() {
/** @throws Exception If failed. */
@Test
public void testCancelService() throws Exception {
String serviceName = "MY_SERVICE";
String srvcName = "MY_SERVICE";

ServiceConfiguration scfg = new ServiceConfiguration();
scfg.setName(serviceName);
scfg.setName(srvcName);
scfg.setMaxPerNodeCount(1);
scfg.setNodeFilter(grid(0).cluster().predicate());
scfg.setService(new TestServiceImpl());

client.services().deploy(scfg);

TestService svc = client.services().serviceProxy(serviceName, TestService.class, true);
TestService svc = client.services().serviceProxy(srvcName, TestService.class, true);
assertNotNull(svc);

sql(client, "KILL SERVICE '" + serviceName + "'");
sql(client, "KILL SERVICE '" + srvcName + "'");

boolean res = waitForCondition(() -> grid(0).context().systemView().view(SVCS_VIEW).size() == 0, TIMEOUT);
assertTrue(res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,11 @@ public void killScan() throws Exception {
*/
@Test
public void killService() throws Exception {
IgniteSqlKill killService;
IgniteSqlKill killSrvc;

killService = parse("kill service 'my-service'");
assertTrue(killService instanceof IgniteSqlKillService);
assertEquals("my-service", stringValue(((IgniteSqlKillService)killService).serviceName()));
killSrvc = parse("kill service 'my-service'");
assertTrue(killSrvc instanceof IgniteSqlKillService);
assertEquals("my-service", stringValue(((IgniteSqlKillService)killSrvc).serviceName()));

assertParserThrows("kill service 'my-service' 'test'", SqlParseException.class);
assertParserThrows("kill service 10000", SqlParseException.class);
Expand Down
2 changes: 1 addition & 1 deletion modules/checkstyle/src/main/resources/abbrevations.csv
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ resource,rsrc
response,res
#returnValue,retVal
sender,snd
#service,srvc
service,srvc
#session,ses
#sequence,seq
#socket,sock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public void registerMBeansAfterNodeStarted() throws IgniteCheckedException {
registerMBean("Compute", computeMXBean.getClass().getSimpleName(), computeMXBean, ComputeMXBean.class);

// Service management
ServiceMXBean serviceMXBean = new ServiceMXBeanImpl(ctx);
registerMBean("Service", serviceMXBean.getClass().getSimpleName(), serviceMXBean, ServiceMXBean.class);
ServiceMXBean srvcMXBean = new ServiceMXBeanImpl(ctx);
registerMBean("Service", srvcMXBean.getClass().getSimpleName(), srvcMXBean, ServiceMXBean.class);

// Data storage
DataStorageMXBean dataStorageMXBean = new DataStorageMXBeanImpl(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1550,9 +1550,9 @@ void updateServicesTopologies(@NotNull final Map<IgniteUuid, Map<UUID, Integer>>
* @return @return Service's id if exists, otherwise {@code null};
*/
@Nullable private IgniteUuid lookupDeployedServiceId(String name) {
ServiceInfo serviceInfo = deployedServicesByName.get(name);
if (serviceInfo != null) {
return serviceInfo.serviceId();
ServiceInfo srvcInfo = deployedServicesByName.get(name);
if (srvcInfo != null) {
return srvcInfo.serviceId();
}

return null;
Expand Down Expand Up @@ -1713,11 +1713,11 @@ public ServiceDeploymentManager deployment() {
}

for (ServiceConfiguration srvcCfg : prepCfgs.cfgs) {
ServiceInfo serviceInfo = new ServiceInfo(ctx.localNodeId(), IgniteUuid.randomUuid(), srvcCfg, true);
ServiceInfo srvcInfo = new ServiceInfo(ctx.localNodeId(), IgniteUuid.randomUuid(), srvcCfg, true);

serviceInfo.context(ctx);
srvcInfo.context(ctx);

staticServicesInfo.add(serviceInfo);
staticServicesInfo.add(srvcInfo);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,16 +590,16 @@ public void testServerCriticalError() throws Exception {
public void testServiceMethodInvocationAfterFailover() throws Exception {
PersonExternalizable person = new PersonExternalizable("Person 1");

ServiceConfiguration testServiceCfg = new ServiceConfiguration();
testServiceCfg.setName(SERVICE_NAME);
testServiceCfg.setService(new TestService());
testServiceCfg.setTotalCount(1);
ServiceConfiguration testSrvcCfg = new ServiceConfiguration();
testSrvcCfg.setName(SERVICE_NAME);
testSrvcCfg.setService(new TestService());
testSrvcCfg.setTotalCount(1);

Ignite ignite = null;
IgniteClient client = null;
try {
// Initialize cluster and client
ignite = startGrid(getConfiguration().setServiceConfiguration(testServiceCfg));
ignite = startGrid(getConfiguration().setServiceConfiguration(testSrvcCfg));
client = startClient(ignite);
TestServiceInterface svc = client.services().serviceProxy(SERVICE_NAME, TestServiceInterface.class);

Expand All @@ -621,7 +621,7 @@ public void testServiceMethodInvocationAfterFailover() throws Exception {
GridTestUtils.assertThrowsWithCause(() -> svc.testMethod(person), ClientConnectionException.class);

// Restore the cluster and redeploy the service.
ignite = startGrid(getConfiguration().setServiceConfiguration(testServiceCfg));
ignite = startGrid(getConfiguration().setServiceConfiguration(testSrvcCfg));

// Invoke the service method with Externalizable parameter once again.
// This should restore the client connection and trigger registration of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public void testSemaphoreClosing() throws Exception {
@Test
public void testAcquireAndExecute() throws Exception {
IgniteSemaphore semaphore = ignite(0).semaphore("testAcquireAndExecute", 1, true, true);
ExecutorService executorService = Executors.newSingleThreadExecutor();
ExecutorService executorSrvc = Executors.newSingleThreadExecutor();

IgniteCallable<Integer> callable = new IgniteCallable<Integer>() {
@Override public Integer call() {
Expand All @@ -334,7 +334,7 @@ public void testAcquireAndExecute() throws Exception {
}
};

executorService.submit(runnable);
executorSrvc.submit(runnable);

Thread.sleep(1000);
igniteFut.get(7000, MILLISECONDS);
Expand All @@ -343,7 +343,7 @@ public void testAcquireAndExecute() throws Exception {

assertTrue(semaphore.availablePermits() == 1);

executorService.shutdown();
executorSrvc.shutdown();
}

/**
Expand All @@ -354,7 +354,7 @@ public void testAcquireAndExecute() throws Exception {
@Test
public void testAcquireAndExecuteIfFailure() {
IgniteSemaphore semaphore = ignite(0).semaphore("testAcquireAndExecuteIfFailure", 1, true, true);
ExecutorService executorService = Executors.newSingleThreadExecutor();
ExecutorService executorSrvc = Executors.newSingleThreadExecutor();

IgniteCallable<Integer> callable = new IgniteCallable<Integer>() {
@Override public Integer call() {
Expand Down Expand Up @@ -382,7 +382,7 @@ public void testAcquireAndExecuteIfFailure() {
}
};

executorService.submit(runnable);
executorSrvc.submit(runnable);

((IgniteFutureImpl)igniteFut).internalFuture().get();

Expand All @@ -392,7 +392,7 @@ public void testAcquireAndExecuteIfFailure() {
}
}, RuntimeException.class, "Foobar");

executorService.shutdown();
executorSrvc.shutdown();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,49 +186,49 @@ public void testDeployAsyncAllowed() {
public void testDeployAllAllowed() {
grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);

Collection<String> serviceNames = new HashSet<>();
Collection<String> srvcNames = new HashSet<>();

for (int i = 0; i < 2; i++)
serviceNames.add(SERVICE_NAME + "_" + i);
srvcNames.add(SERVICE_NAME + "_" + i);

Set<ServiceConfiguration> configs = serviceNames.stream()
Set<ServiceConfiguration> configs = srvcNames.stream()
.map(GridServiceDeployClusterReadOnlyModeTest::serviceConfiguration)
.collect(toSet());

deployMultipleServices(s -> s.deployAll(configs), configs.size());

for (String serviceName : serviceNames)
checkServiceDeployed(serviceName, true);
for (String srvcName : srvcNames)
checkServiceDeployed(srvcName, true);

grid(0).services().cancelAll(serviceNames);
grid(0).services().cancelAll(srvcNames);

for (String serviceName : serviceNames)
checkServiceCanceled(serviceName, true);
for (String srvcName : srvcNames)
checkServiceCanceled(srvcName, true);
}

/** */
@Test
public void testDeployAllAsyncAllowed() {
grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);

Collection<String> serviceNames = new HashSet<>();
Collection<String> srvcNames = new HashSet<>();

for (int i = 0; i < 2; i++)
serviceNames.add(SERVICE_NAME + "_" + i);
srvcNames.add(SERVICE_NAME + "_" + i);

Set<ServiceConfiguration> configs = serviceNames.stream()
Set<ServiceConfiguration> configs = srvcNames.stream()
.map(GridServiceDeployClusterReadOnlyModeTest::serviceConfiguration)
.collect(toSet());

deployMultipleServices(s -> s.deployAllAsync(configs), configs.size());

for (String serviceName : serviceNames)
checkServiceDeployed(serviceName, true);
for (String srvcName : srvcNames)
checkServiceDeployed(srvcName, true);

grid(0).services().cancelAll(serviceNames);
grid(0).services().cancelAll(srvcNames);

for (String serviceName : serviceNames)
checkServiceCanceled(serviceName, true);
for (String srvcName : srvcNames)
checkServiceCanceled(srvcName, true);
}

/** */
Expand Down Expand Up @@ -256,50 +256,50 @@ public void testCancelAsyncAllowed() {
/** */
@Test
public void testCancelAllAllowed() {
Collection<String> serviceNames = new HashSet<>();
Collection<String> srvcNames = new HashSet<>();

for (int i = 0; i < 2; i++)
serviceNames.add(SERVICE_NAME + "_" + i);
srvcNames.add(SERVICE_NAME + "_" + i);

Set<ServiceConfiguration> configs = serviceNames.stream()
Set<ServiceConfiguration> configs = srvcNames.stream()
.map(GridServiceDeployClusterReadOnlyModeTest::serviceConfiguration)
.collect(toSet());

deployMultipleServices(s -> s.deployAll(configs), configs.size());

for (String serviceName : serviceNames)
checkServiceDeployed(serviceName, true);
for (String srvcName : srvcNames)
checkServiceDeployed(srvcName, true);

grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);

grid(0).services().cancelAll(serviceNames);
grid(0).services().cancelAll(srvcNames);

for (String name : serviceNames)
for (String name : srvcNames)
checkServiceCanceled(name, true);
}

/** */
@Test
public void testCancelAllAsyncAllowed() {
Collection<String> serviceNames = new HashSet<>();
Collection<String> srvcNames = new HashSet<>();

for (int i = 0; i < 2; i++)
serviceNames.add(SERVICE_NAME + "_" + i);
srvcNames.add(SERVICE_NAME + "_" + i);

Set<ServiceConfiguration> configs = serviceNames.stream()
Set<ServiceConfiguration> configs = srvcNames.stream()
.map(GridServiceDeployClusterReadOnlyModeTest::serviceConfiguration)
.collect(toSet());

deployMultipleServices(s -> s.deployAll(configs), configs.size());

for (String serviceName : serviceNames)
checkServiceDeployed(serviceName, true);
for (String srvcName : srvcNames)
checkServiceDeployed(srvcName, true);

grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);

grid(0).services().cancelAllAsync(serviceNames).get();
grid(0).services().cancelAllAsync(srvcNames).get();

for (String name : serviceNames)
for (String name : srvcNames)
checkServiceCanceled(name, true);
}

Expand Down
Loading

0 comments on commit 628e424

Please sign in to comment.