use of org.kie.server.api.model.ServiceResponse 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.api.model.ServiceResponse in project droolsjbpm-integration by kiegroup.
the class QueryServicesClientImpl method findProcessInstancesByStatus.
@Override
public List<ProcessInstance> findProcessInstancesByStatus(List<Integer> status, Integer page, Integer pageSize, String sort, boolean sortOrder) {
ProcessInstanceList result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
String statusQueryString = getAdditionalParams("?sort=" + sort + "&sortOrder=" + sortOrder, "status", status);
String queryString = getPagingQueryString(statusQueryString, page, pageSize);
result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCES_GET_URI, valuesMap) + queryString, ProcessInstanceList.class);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstances", new Object[] { safeList(status), "", "", page, pageSize, sort, sortOrder })));
ServiceResponse<ProcessInstanceList> response = (ServiceResponse<ProcessInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
result = response.getResult();
}
if (result != null && result.getProcessInstances() != null) {
return Arrays.asList(result.getProcessInstances());
}
return Collections.emptyList();
}
use of org.kie.server.api.model.ServiceResponse in project droolsjbpm-integration by kiegroup.
the class QueryServicesClientImpl method findProcessInstancesByContainerId.
@Override
public List<ProcessInstance> findProcessInstancesByContainerId(String containerId, List<Integer> status, Integer page, Integer pageSize, String sort, boolean sortOrder) {
ProcessInstanceList result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(CONTAINER_ID, containerId);
String statusQueryString = getAdditionalParams("?sort=" + sort + "&sortOrder=" + sortOrder, "status", status);
String queryString = getPagingQueryString(statusQueryString, page, pageSize);
result = makeHttpGetRequestAndCreateCustomResponseWithHandleNotFound(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCES_BY_CONTAINER_ID_GET_URI, valuesMap) + queryString, ProcessInstanceList.class);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstancesByDeploymentId", new Object[] { containerId, safeList(status), page, pageSize, sort, sortOrder })));
ServiceResponse<ProcessInstanceList> response = (ServiceResponse<ProcessInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
result = response.getResult();
}
if (result != null && result.getProcessInstances() != null) {
return Arrays.asList(result.getProcessInstances());
}
return Collections.emptyList();
}
use of org.kie.server.api.model.ServiceResponse in project droolsjbpm-integration by kiegroup.
the class QueryServicesClientImpl method findProcessInstancesByProcessIdAndInitiator.
@Override
public List<ProcessInstance> findProcessInstancesByProcessIdAndInitiator(String processId, String initiator, List<Integer> status, Integer page, Integer pageSize, String sort, boolean sortOrder) {
ProcessInstanceList result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(PROCESS_ID, processId);
String statusQueryString = getAdditionalParams("?initiator=" + initiator + "&sort=" + sort + "&sortOrder=" + sortOrder, "status", status);
String queryString = getPagingQueryString(statusQueryString, page, pageSize);
result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCES_BY_PROCESS_ID_GET_URI, valuesMap) + queryString, ProcessInstanceList.class);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstancesByProcessId", new Object[] { processId, safeList(status), initiator, page, pageSize, sort, sortOrder })));
ServiceResponse<ProcessInstanceList> response = (ServiceResponse<ProcessInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
result = response.getResult();
}
if (result != null && result.getProcessInstances() != null) {
return Arrays.asList(result.getProcessInstances());
}
return Collections.emptyList();
}
use of org.kie.server.api.model.ServiceResponse in project droolsjbpm-integration by kiegroup.
the class QueryServicesClientImpl method findProcessesByContainerId.
@Override
public List<ProcessDefinition> findProcessesByContainerId(String containerId, Integer page, Integer pageSize, String sort, boolean sortOrder) {
ProcessDefinitionList result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(CONTAINER_ID, containerId);
String queryString = getPagingQueryString("?sort=" + sort + "&sortOrder=" + sortOrder, page, pageSize);
result = makeHttpGetRequestAndCreateCustomResponseWithHandleNotFound(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_DEFINITIONS_BY_CONTAINER_ID_GET_URI, valuesMap) + queryString, ProcessDefinitionList.class);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessesByDeploymentId", new Object[] { containerId, page, pageSize, sort, sortOrder })));
ServiceResponse<ProcessDefinitionList> response = (ServiceResponse<ProcessDefinitionList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
result = response.getResult();
}
if (result != null && result.getProcesses() != null) {
return Arrays.asList(result.getProcesses());
}
return Collections.emptyList();
}
Aggregations