Skip to content

Commit

Permalink
chore(distro): clean up wildfly subsystem code (#4111)
Browse files Browse the repository at this point in the history
* Java deprecations : class.newInstance -> class.getDeclaredConstructor().newInstance()
* WildFly
  * (DeploymentPhaseContext) getServiceTarget() ->
getRequirementServiceTarget()
  * (OperationContext) getServiceTarget() -> getCapabilityServiceTarget()
  * use default constructor for AbstractAddStepHandler
* jboss-modules
  * (Module) getIdentifier() -> getName()
  * ModuleIdentifier -> String
* jboss-threads
  * remove ExecutionTimedOutException usage
* JBoss MSC - reduce usage of deprecations in classes addService + requires + provides
  * ProcessApplicationModuleService
  * MscExecutorService
  * MscRuntimeContainerDelegate
  * MscBpmPlatformPlugins
  * MscRuntimeContainerJobExecutor
  * use #addService(serviceName) to register the services with their names
  * remove addAliases usage
* improve code: 
  * replace #length() == 0 with #isEmpty()
  * remove redundant code
  * remove unused suppress
  * improve naming
  * add override annotation, adjust imports and whitespaces
  * clean up TODO and adjust formatting
  * fix typo in module identifier constants
  * remove empty undeploy method
  * remove redundant comments
  * adjust formatting
  * replace lambda with method reference
  * fix typos
  * remove redundant deprecation annotation of THREAD_POOL_NAME
  * add final modifier

related to #3589
  • Loading branch information
yanavasileva authored Mar 12, 2024
1 parent 096d542 commit 6118083
Show file tree
Hide file tree
Showing 35 changed files with 577 additions and 476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.camunda.bpm.container.impl.jboss.deployment.processor;

import java.util.function.Consumer;

import org.camunda.bpm.container.impl.jboss.deployment.marker.ProcessApplicationAttachments;
import org.camunda.bpm.container.impl.jboss.service.ProcessApplicationModuleService;
import org.camunda.bpm.container.impl.jboss.service.ServiceNames;
Expand All @@ -33,7 +35,6 @@
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;

/**
* <p>This Processor creates implicit module dependencies for process applications</p>
Expand All @@ -49,17 +50,18 @@ public class ModuleDependencyProcessor implements DeploymentUnitProcessor {

public static final int PRIORITY = 0x2300;

public static ModuleIdentifier MODULE_IDENTIFYER_PROCESS_ENGINE = ModuleIdentifier.create("org.camunda.bpm.camunda-engine");
public static ModuleIdentifier MODULE_IDENTIFYER_XML_MODEL = ModuleIdentifier.create("org.camunda.bpm.model.camunda-xml-model");
public static ModuleIdentifier MODULE_IDENTIFYER_BPMN_MODEL = ModuleIdentifier.create("org.camunda.bpm.model.camunda-bpmn-model");
public static ModuleIdentifier MODULE_IDENTIFYER_CMMN_MODEL = ModuleIdentifier.create("org.camunda.bpm.model.camunda-cmmn-model");
public static ModuleIdentifier MODULE_IDENTIFYER_DMN_MODEL = ModuleIdentifier.create("org.camunda.bpm.model.camunda-dmn-model");
public static ModuleIdentifier MODULE_IDENTIFYER_SPIN = ModuleIdentifier.create("org.camunda.spin.camunda-spin-core");
public static ModuleIdentifier MODULE_IDENTIFYER_CONNECT = ModuleIdentifier.create("org.camunda.connect.camunda-connect-core");
public static ModuleIdentifier MODULE_IDENTIFYER_ENGINE_DMN = ModuleIdentifier.create("org.camunda.bpm.dmn.camunda-engine-dmn");
public static ModuleIdentifier MODULE_IDENTIFYER_GRAAL_JS = ModuleIdentifier.create("org.graalvm.js.js-scriptengine");
public static ModuleIdentifier MODULE_IDENTIFYER_JUEL = ModuleIdentifier.create("org.camunda.bpm.juel.camunda-juel");

public static String MODULE_IDENTIFIER_PROCESS_ENGINE = "org.camunda.bpm.camunda-engine";
public static String MODULE_IDENTIFIER_XML_MODEL = "org.camunda.bpm.model.camunda-xml-model";
public static String MODULE_IDENTIFIER_BPMN_MODEL = "org.camunda.bpm.model.camunda-bpmn-model";
public static String MODULE_IDENTIFIER_CMMN_MODEL = "org.camunda.bpm.model.camunda-cmmn-model";
public static String MODULE_IDENTIFIER_DMN_MODEL = "org.camunda.bpm.model.camunda-dmn-model";
public static String MODULE_IDENTIFIER_SPIN = "org.camunda.spin.camunda-spin-core";
public static String MODULE_IDENTIFIER_CONNECT = "org.camunda.connect.camunda-connect-core";
public static String MODULE_IDENTIFIER_ENGINE_DMN = "org.camunda.bpm.dmn.camunda-engine-dmn";
public static String MODULE_IDENTIFIER_GRAAL_JS = "org.graalvm.js.js-scriptengine";
public static String MODULE_IDENTIFIER_JUEL = "org.camunda.bpm.juel.camunda-juel";

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
Expand Down Expand Up @@ -105,40 +107,37 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
ModuleIdentifier identifyer = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER);
String moduleName = identifyer.toString();

ProcessApplicationModuleService processApplicationModuleService = new ProcessApplicationModuleService();
ServiceName serviceName = ServiceNames.forProcessApplicationModuleService(moduleName);

final ServiceBuilder<ServiceTarget> serviceBuilder = phaseContext.getServiceTarget()
.addService(serviceName, processApplicationModuleService)
.setInitialMode(Mode.ACTIVE);
ServiceBuilder<?> serviceBuilder = phaseContext.getRequirementServiceTarget().addService(serviceName);
Consumer<ProcessApplicationModuleService> provider = serviceBuilder.provides(serviceName);
serviceBuilder.requires(phaseContext.getPhaseServiceName());
serviceBuilder.setInitialMode(Mode.ACTIVE);
ProcessApplicationModuleService processApplicationModuleService = new ProcessApplicationModuleService(provider);
serviceBuilder.setInstance(processApplicationModuleService);
serviceBuilder.install();

}

private void addSystemDependencies(ModuleLoader moduleLoader, final ModuleSpecification moduleSpecification) {
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_PROCESS_ENGINE);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_XML_MODEL);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_BPMN_MODEL);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_CMMN_MODEL);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_DMN_MODEL);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_SPIN);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_CONNECT);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_ENGINE_DMN);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_GRAAL_JS, true);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFYER_JUEL, true);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFIER_PROCESS_ENGINE);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFIER_XML_MODEL);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFIER_BPMN_MODEL);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFIER_CMMN_MODEL);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFIER_DMN_MODEL);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFIER_SPIN);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFIER_CONNECT);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFIER_ENGINE_DMN);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFIER_GRAAL_JS, true);
addSystemDependency(moduleLoader, moduleSpecification, MODULE_IDENTIFIER_JUEL, true);
}

private void addSystemDependency(ModuleLoader moduleLoader, final ModuleSpecification moduleSpecification, ModuleIdentifier dependency) {
addSystemDependency(moduleLoader, moduleSpecification, dependency, false);
private void addSystemDependency(ModuleLoader moduleLoader, final ModuleSpecification moduleSpecification, String identifier) {
addSystemDependency(moduleLoader, moduleSpecification, identifier, false);
}

private void addSystemDependency(ModuleLoader moduleLoader, final ModuleSpecification moduleSpecification, ModuleIdentifier dependency, boolean importServices) {
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, dependency, false, false, importServices, false));
}

public void undeploy(DeploymentUnit context) {

private void addSystemDependency(ModuleLoader moduleLoader, final ModuleSpecification moduleSpecification, String identifier, boolean importServices) {
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, identifier, false, false, importServices, false));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.camunda.bpm.application.ProcessApplicationInterface;
import org.camunda.bpm.application.impl.metadata.spi.ProcessArchiveXml;
import org.camunda.bpm.application.impl.metadata.spi.ProcessesXml;
Expand Down Expand Up @@ -96,19 +100,26 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro

List<ServiceName> deploymentServiceNames = new ArrayList<>();

ProcessApplicationStopService paStopService = new ProcessApplicationStopService();
ServiceBuilder<ProcessApplicationStopService> stopServiceBuilder = phaseContext.getServiceTarget().addService(paStopServiceName, paStopService)
.addDependency(ServiceNames.forBpmPlatformPlugins(), BpmPlatformPlugins.class, paStopService.getPlatformPluginsInjector())
.setInitialMode(Mode.ACTIVE);

ServiceBuilder<?> stopServiceBuilder = phaseContext.getRequirementServiceTarget().addService(paStopServiceName);
Consumer<ProcessApplicationStopService> paStopProvider = stopServiceBuilder.provides(paStopServiceName);
stopServiceBuilder.requires(phaseContext.getPhaseServiceName());
Supplier<BpmPlatformPlugins> platformPluginsSupplier = stopServiceBuilder.requires(ServiceNames.forBpmPlatformPlugins());

if(paViewServiceName != null) {
stopServiceBuilder.addDependency(paViewServiceName, ComponentView.class, paStopService.getPaComponentViewInjector());
Supplier<ComponentView> paComponentViewSupplierStopService = null;
Supplier<ProcessApplicationInterface> noViewApplicationSupplierStopService = null;
if (paViewServiceName != null) {
paComponentViewSupplierStopService = stopServiceBuilder.requires(paViewServiceName);
} else {
stopServiceBuilder.addDependency(noViewStartService, ProcessApplicationInterface.class, paStopService.getNoViewProcessApplication());
noViewApplicationSupplierStopService = stopServiceBuilder.requires(noViewStartService);
}

ProcessApplicationStopService paStopService = new ProcessApplicationStopService(
paComponentViewSupplierStopService,
noViewApplicationSupplierStopService,
platformPluginsSupplier,
paStopProvider);
stopServiceBuilder.setInitialMode(Mode.ACTIVE);
stopServiceBuilder.setInstance(paStopService);
stopServiceBuilder.install();

// deploy all process archives
Expand All @@ -122,31 +133,45 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
Map<String, byte[]> deploymentResources = getDeploymentResources(processArchive, deploymentUnit, processesXmlWrapper.getProcessesXmlFile());

// add the deployment service for each process archive we deploy.
ProcessApplicationDeploymentService deploymentService = new ProcessApplicationDeploymentService(deploymentResources, processArchive, module);
String processArachiveName = processArchive.getName();
if(processArachiveName == null) {
String processArchiveName = processArchive.getName();
if(processArchiveName == null) {
// use random name for deployment service if name is null (we cannot ask the process application yet since the component might not be up.
processArachiveName = UUID.randomUUID().toString();
processArchiveName = UUID.randomUUID().toString();
}
ServiceName deploymentServiceName = ServiceNames.forProcessApplicationDeploymentService(deploymentUnit.getName(), processArachiveName);
ServiceBuilder<ProcessApplicationDeploymentService> serviceBuilder = phaseContext.getServiceTarget().addService(deploymentServiceName, deploymentService)
.addDependency(processEngineServiceName, ProcessEngine.class, deploymentService.getProcessEngineInjector())
.setInitialMode(Mode.ACTIVE);
ServiceName deploymentServiceName = ServiceNames.forProcessApplicationDeploymentService(deploymentUnit.getName(), processArchiveName);
ServiceBuilder<?> deploymentServiceBuilder = phaseContext.getRequirementServiceTarget().addService(deploymentServiceName);

Consumer<ProcessApplicationDeploymentService> paDeploymentProvider = deploymentServiceBuilder.provides(deploymentServiceName);
deploymentServiceBuilder.requires(phaseContext.getPhaseServiceName());
deploymentServiceBuilder.requires(paStopServiceName);
Supplier<ProcessEngine> processEngineServiceSupplier = deploymentServiceBuilder.requires(processEngineServiceName);

serviceBuilder.requires(phaseContext.getPhaseServiceName());
serviceBuilder.requires(paStopServiceName);
deploymentServiceBuilder.setInitialMode(Mode.ACTIVE);

Supplier<ComponentView> paComponentViewSupplier = null;
Supplier<ProcessApplicationInterface> noViewProcessApplicationSupplier = null;
if(paViewServiceName != null) {
// add a dependency on the component start service to make sure we are started after the pa-component (Singleton EJB) has started
serviceBuilder.requires(paComponent.getStartServiceName());
serviceBuilder.addDependency(paViewServiceName, ComponentView.class, deploymentService.getPaComponentViewInjector());
deploymentServiceBuilder.requires(paComponent.getStartServiceName());
paComponentViewSupplier = deploymentServiceBuilder.requires(paViewServiceName);
} else {
serviceBuilder.addDependency(noViewStartService, ProcessApplicationInterface.class, deploymentService.getNoViewProcessApplication());
noViewProcessApplicationSupplier = deploymentServiceBuilder.requires(noViewStartService);
}

JBossCompatibilityExtension.addServerExecutorDependency(serviceBuilder, deploymentService.getExecutorInjector());
Supplier<ExecutorService> executorSupplier = JBossCompatibilityExtension.addServerExecutorDependency(deploymentServiceBuilder);

serviceBuilder.install();
ProcessApplicationDeploymentService deploymentService = new ProcessApplicationDeploymentService(
deploymentResources,
processArchive,
module,
executorSupplier,
processEngineServiceSupplier,
noViewProcessApplicationSupplier,
paComponentViewSupplier,
paDeploymentProvider);
deploymentServiceBuilder.setInstance(deploymentService);

deploymentServiceBuilder.install();

deploymentServiceNames.add(deploymentServiceName);

Expand All @@ -157,29 +182,40 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
AnnotationInstance preUndeploy = ProcessApplicationAttachments.getPreUndeployDescription(deploymentUnit);

// register the managed process application start service
ProcessApplicationStartService paStartService = new ProcessApplicationStartService(deploymentServiceNames, postDeploy, preUndeploy, module);
ServiceBuilder<ProcessApplicationStartService> serviceBuilder = phaseContext.getServiceTarget().addService(paStartServiceName, paStartService)
.addDependency(ServiceNames.forBpmPlatformPlugins(), BpmPlatformPlugins.class, paStartService.getPlatformPluginsInjector())
.setInitialMode(Mode.ACTIVE);
ServiceBuilder<?> processApplicationStartServiceBuilder = phaseContext.getRequirementServiceTarget().addService(paStartServiceName);
Consumer<ProcessApplicationStartService> paStartProvider =processApplicationStartServiceBuilder.provides(paStartServiceName);

processApplicationStartServiceBuilder.requires(phaseContext.getPhaseServiceName());
Supplier<BpmPlatformPlugins> platformPluginsSupplierStartService = processApplicationStartServiceBuilder.requires(ServiceNames.forBpmPlatformPlugins());
deploymentServiceNames.forEach(processApplicationStartServiceBuilder::requires);

serviceBuilder.requires(phaseContext.getPhaseServiceName());
deploymentServiceNames.forEach(serviceName -> serviceBuilder.requires(serviceName));
processApplicationStartServiceBuilder.setInitialMode(Mode.ACTIVE);

Supplier<ProcessEngine> defaultProcessEngineSupplier = null;
if (phaseContext.getServiceRegistry().getService(ServiceNames.forDefaultProcessEngine()) != null) {
serviceBuilder.addDependency(ServiceNames.forDefaultProcessEngine(), ProcessEngine.class, paStartService.getDefaultProcessEngineInjector());
defaultProcessEngineSupplier = processApplicationStartServiceBuilder.requires(ServiceNames.forDefaultProcessEngine());
}
if(paViewServiceName != null) {
serviceBuilder.addDependency(paViewServiceName, ComponentView.class, paStartService.getPaComponentViewInjector());
Supplier<ComponentView> paComponentViewSupplier = null;
Supplier<ProcessApplicationInterface> noViewProcessApplication = null;
if (paViewServiceName != null) {
paComponentViewSupplier = processApplicationStartServiceBuilder.requires(paViewServiceName);
} else {
serviceBuilder.addDependency(noViewStartService, ProcessApplicationInterface.class, paStartService.getNoViewProcessApplication());
noViewProcessApplication = processApplicationStartServiceBuilder.requires(noViewStartService);
}

serviceBuilder.install();
}

@Override
public void undeploy(DeploymentUnit deploymentUnit) {

ProcessApplicationStartService paStartService = new ProcessApplicationStartService(
deploymentServiceNames,
postDeploy,
preUndeploy,
module,
paComponentViewSupplier,
noViewProcessApplication,
defaultProcessEngineSupplier,
platformPluginsSupplierStartService,
paStartProvider);

processApplicationStartServiceBuilder.setInstance(paStartService);
processApplicationStartServiceBuilder.install();
}

protected ServiceName getProcessApplicationViewServiceName(ComponentDescription paComponent) {
Expand All @@ -193,13 +229,12 @@ protected ServiceName getProcessApplicationViewServiceName(ComponentDescription
}

protected ComponentDescription getProcessApplicationComponent(DeploymentUnit deploymentUnit) {
ComponentDescription paComponentDescription = ProcessApplicationAttachments.getProcessApplicationComponent(deploymentUnit);
return paComponentDescription;
return ProcessApplicationAttachments.getProcessApplicationComponent(deploymentUnit);
}

protected ServiceName getProcessEngineServiceName(ProcessArchiveXml processArchive) {
ServiceName serviceName = null;
if(processArchive.getProcessEngineName() == null || processArchive.getProcessEngineName().length() == 0) {
if(processArchive.getProcessEngineName() == null || processArchive.getProcessEngineName().isEmpty()) {
serviceName = ServiceNames.forDefaultProcessEngine();
} else {
serviceName = ServiceNames.forManagedProcessEngine(processArchive.getProcessEngineName());
Expand All @@ -213,7 +248,7 @@ protected Map<String, byte[]> getDeploymentResources(ProcessArchiveXml processAr

Map<String, byte[]> resources = new HashMap<>();

// first, add all resources listed in the processe.xml
// first, add all resources listed in the processes.xml
List<String> process = processArchive.getProcessResourceNames();
ModuleClassLoader classLoader = module.getClassLoader();

Expand Down Expand Up @@ -250,4 +285,4 @@ protected URL vfsFileAsUrl(VirtualFile processesXmlFile) {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,4 @@ protected ClassInfo getClassInfo(AnnotationInstance annotation) {
}
}

@Override
public void undeploy(DeploymentUnit context) {

}

}
Loading

0 comments on commit 6118083

Please sign in to comment.