use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class KieServerImpl method disposeContainer.
public ServiceResponse<Void> disposeContainer(String containerId) {
List<Message> messages = new CopyOnWriteArrayList<Message>();
try {
KieContainerInstanceImpl kci = context.unregisterContainer(containerId);
if (kci != null) {
synchronized (kci) {
eventSupport.fireBeforeContainerStopped(this, kci);
// just in case
kci.setStatus(KieContainerStatus.DISPOSING);
if (kci.getKieContainer() != null) {
org.kie.api.builder.ReleaseId releaseId = kci.getKieContainer().getReleaseId();
List<KieServerExtension> disposedExtensions = new ArrayList<KieServerExtension>();
try {
// first attempt to dispose container on all extensions
logger.debug("Container {} (for release id {}) shutdown: In Progress", containerId, kci.getResource().getReleaseId());
// process server extensions
List<KieServerExtension> extensions = context.getServerExtensions();
for (KieServerExtension extension : extensions) {
extension.disposeContainer(containerId, kci, new HashMap<String, Object>());
logger.debug("Container {} (for release id {}) {} shutdown: DONE", containerId, kci.getResource().getReleaseId(), extension);
disposedExtensions.add(extension);
}
} catch (Exception e) {
logger.warn("Dispose of container {} failed, putting it back to started state by recreating container on {}", containerId, disposedExtensions);
// since the dispose fail rollback must take place to put it back to running state
KieModuleMetaData metadata = buildKieModuleMetadata(kci.getKieContainer().getReleaseId());
Map<String, Object> parameters = getContainerParameters(metadata, messages);
for (KieServerExtension extension : disposedExtensions) {
extension.createContainer(containerId, kci, parameters);
logger.debug("Container {} (for release id {}) {} restart: DONE", containerId, kci.getResource().getReleaseId(), extension);
}
kci.setStatus(KieContainerStatus.STARTED);
context.registerContainer(containerId, kci);
logger.info("Container {} (for release id {}) STARTED after failed dispose", containerId, kci.getResource().getReleaseId());
messages.add(new Message(Severity.WARN, "Error disposing container '" + containerId + "' due to " + e.getMessage() + ", container is running"));
return new ServiceResponse<Void>(ResponseType.FAILURE, "Container " + containerId + " failed to dispose, exception was raised: " + e.getClass().getName() + ": " + e.getMessage());
}
if (kci.getScanner() != null && kci.getScanner().getStatus() != Status.SHUTDOWN) {
kci.stopScanner();
}
InternalKieContainer kieContainer = kci.getKieContainer();
// helps reduce concurrent access issues
kci.setKieContainer(null);
// this may fail, but we already removed the container from the registry
kieContainer.dispose();
ks.getRepository().removeKieModule(releaseId);
logger.info("Container {} (for release id {}) successfully stopped", containerId, kci.getResource().getReleaseId());
// store the current state of the server
storeServerState(currentState -> {
List<KieContainerResource> containers = new ArrayList<>();
currentState.getContainers().forEach(containerResource -> {
if (!containerId.equals(containerResource.getContainerId())) {
containers.add(containerResource);
}
});
currentState.setContainers(new HashSet<KieContainerResource>(containers));
});
messages.add(new Message(Severity.INFO, "Container " + containerId + " successfully stopped."));
eventSupport.fireAfterContainerStopped(this, kci);
notifyStatusToControllers();
return new ServiceResponse<Void>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully disposed.");
} else {
messages.add(new Message(Severity.INFO, "Container " + containerId + " was not instantiated."));
return new ServiceResponse<Void>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " was not instantiated.");
}
}
} else {
messages.add(new Message(Severity.INFO, "Container " + containerId + " was not instantiated."));
return new ServiceResponse<Void>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " was not instantiated.");
}
} catch (Exception e) {
messages.add(new Message(Severity.ERROR, "Error disposing container '" + containerId + "' due to " + e.getMessage()));
logger.error("Error disposing Container '" + containerId + "'", e);
return new ServiceResponse<Void>(ServiceResponse.ResponseType.FAILURE, "Error disposing container " + containerId + ": " + e.getClass().getName() + ": " + e.getMessage());
} finally {
this.containerMessages.put(containerId, messages);
}
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeKieServerExtension method init.
@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
this.registry = registry;
// JAXB and JSON required.
registry.getExtraClasses().add(LocalDateTimeValue.class);
KieServerExtension jbpmExtension = registry.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
if (jbpmExtension == null) {
throw new KieServicesException(MISSING_REQUIRED_JBPM_EXTENSION_ERROR);
}
configureServices(kieServer, registry);
services.add(taskAssigningRuntimeServiceBase);
try {
registerQueries();
} catch (Exception e) {
throw new KieServicesException(String.format(QUERIES_INITIALIZATION_ERROR, e.getMessage()), e);
}
initialized = true;
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeKieServerExtension method configureServices.
private void configureServices(KieServerImpl kieServer, KieServerRegistry registry) {
KieServerExtension jbpmExtension = registry.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
List<Object> jbpmServices = jbpmExtension.getServices();
UserTaskService userTaskService = null;
for (Object object : jbpmServices) {
// in case given service is null (meaning was not configured) continue with next one
if (object != null) {
if (UserTaskService.class.isAssignableFrom(object.getClass())) {
userTaskService = (UserTaskService) object;
} else if (QueryService.class.isAssignableFrom(object.getClass())) {
queryService = (QueryService) object;
}
}
}
taskAssigningRuntimeServiceBase = new TaskAssigningRuntimeServiceBase(kieServer, registry, userTaskService, queryService);
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class TaskAssigningPlanningKieServerExtension method init.
/**
* Invoked by the KieServer initialization procedure for performing current extension initialization.
*/
@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
LOGGER.debug("Initializing " + EXTENSION_NAME + " extension.");
this.kieServer = kieServer;
this.registry = registry;
KieServerExtension jbpmExtension = registry.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
if (jbpmExtension != null) {
String msg = String.format(UNDESIRED_EXTENSIONS_RUNNING_ERROR, JbpmKieServerExtension.EXTENSION_NAME);
LOGGER.warn(msg);
kieServer.addServerMessage(new Message(Severity.WARN, addExtensionMessagePrefix(msg)));
}
initRuntimeClient();
try {
validateAndSetSolverConfiguration();
} catch (TaskAssigningValidationException e) {
throw new KieServicesException(String.format(SOLVER_CONFIGURATION_ERROR, e.getMessage()), e);
}
try {
validateAndSetUserSystemServiceConfiguration();
} catch (TaskAssigningValidationException e) {
throw new KieServicesException(String.format(USER_SYSTEM_CONFIGURATION_ERROR, e.getMessage()), e);
}
this.executorService = Executors.newScheduledThreadPool(4);
try {
this.taskAssigningService = createTaskAssigningService(readAndValidateTaskAssigningServiceConfig());
this.services.add(taskAssigningService);
} catch (TaskAssigningValidationException e) {
throw new KieServicesException(String.format(String.format(TASK_ASSIGNING_SERVICE_CONFIGURATION_ERROR, e.getMessage()), e));
}
this.initialized = true;
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class JBPMClusterKieServerExtension method init.
@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
this.registry = registry;
KieServerExtension jbpmExtension = registry.getServerExtension("jBPM");
if (jbpmExtension == null) {
initialized = false;
logger.warn("jBPM extension not found, jBPM Cluster cannot work without jBPM extension, disabling itself");
return;
}
configureServices();
// this implements fail over for jobs
ExecutorServiceImpl service = (ExecutorServiceImpl) jbpmExecutorService;
ClusteredJobFailOverListener clusteredJobFailOverListener = new ClusteredJobFailOverListener(clusterService, service);
service.addAsyncJobListener(clusteredJobFailOverListener);
clusterService.addClusterListener(clusteredJobFailOverListener);
initialized = true;
}
Aggregations