use of org.kie.server.api.model.instance.SolverInstanceList in project droolsjbpm-integration by kiegroup.
the class OptaPlannerJmsResponseHandlerIntegrationTest method testSolverWithAsyncResponseHandler.
@Test
public void testSolverWithAsyncResponseHandler() throws Exception {
Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<>(extraClasses.values()), configuration.getMarshallingFormat(), client.getClassLoader());
ResponseCallback responseCallback = new BlockingResponseCallback(marshaller);
ResponseHandler asyncResponseHandler = new AsyncResponseHandler(responseCallback);
solverClient.setResponseHandler(asyncResponseHandler);
SolverInstance response = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
assertThat(response).isNull();
SolverInstance solver = responseCallback.get(SolverInstance.class);
assertThat(solver).isNotNull();
assertThat(solver.getContainerId()).isEqualTo(CONTAINER_1_ID);
assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
List<SolverInstance> solverInstanceList = solverClient.getSolvers(CONTAINER_1_ID);
assertThat(solverInstanceList).isNull();
SolverInstanceList solverList = responseCallback.get(SolverInstanceList.class);
assertThat(solverList).isNotNull();
assertThat(solverList.getContainers()).isNotNull().isNotEmpty().hasSize(1);
solver = solverList.getContainers().get(0);
assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.NOT_SOLVING);
solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(5, 15));
// Make sure the service call result is consumed
responseCallback.get(Void.class);
response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
assertThat(response).isNull();
solver = responseCallback.get(SolverInstance.class);
assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.SOLVING);
solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
// Make sure the service call result is consumed
responseCallback.get(Void.class);
response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
assertThat(response).isNull();
solver = responseCallback.get(SolverInstance.class);
assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
assertThat(solver.getStatus()).isIn(SolverInstance.SolverStatus.TERMINATING_EARLY, SolverInstance.SolverStatus.NOT_SOLVING);
solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
// Make sure the service call result is consumed
responseCallback.get(Void.class);
solverClient.getSolvers(CONTAINER_1_ID);
assertThat(response).isNull();
solverList = responseCallback.get(SolverInstanceList.class);
assertThat(solverList).isNotNull();
assertThat(solverList.getContainers()).isNullOrEmpty();
}
use of org.kie.server.api.model.instance.SolverInstanceList in project droolsjbpm-integration by kiegroup.
the class KieClientServicesIntegrationTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
KieServerInfo info = new KieServerInfo("mock", "1.2.3");
List<String> capabilities = Arrays.asList(KieServerConstants.CAPABILITY_BPM, KieServerConstants.CAPABILITY_BPM_UI, KieServerConstants.CAPABILITY_BRM, KieServerConstants.CAPABILITY_BRP, KieServerConstants.CAPABILITY_CASE, KieServerConstants.CAPABILITY_DMN);
info.setCapabilities(capabilities);
ServiceResponse<KieServerInfo> response = new ServiceResponse<KieServerInfo>(ResponseType.SUCCESS, "Kie Server info");
response.setResult(info);
stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(response, KieServerInfo.class, ServiceResponse.class))));
// case mock response
ProcessDefinitionList caseResponse = new ProcessDefinitionList();
caseResponse.setProcesses(new ProcessDefinition[] { new ProcessDefinition() });
stubFor(get(urlMatching("/queries/cases/processes.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(caseResponse, ProcessDefinitionList.class, ProcessDefinition.class))));
// document mock response
DocumentInstance documentResponse = new DocumentInstance();
documentResponse.setIdentifier("1234");
stubFor(get(urlMatching("/documents/1234")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(documentResponse, DocumentInstance.class))));
// job service mock response
RequestInfoInstanceList jobResponse = new RequestInfoInstanceList();
stubFor(get(urlMatching("/jobs.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(jobResponse, RequestInfoInstanceList.class))));
// query service mock response
NodeInstanceList queryResponse = new NodeInstanceList();
stubFor(get(urlMatching("/queries/processes/instances/100/nodes/instances.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(queryResponse, NodeInstanceList.class))));
// solver service mock response
SolverInstanceList solverResponse = new SolverInstanceList();
stubFor(get(urlMatching("/containers/my-container/solvers")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(solverResponse, SolverInstanceList.class))));
// ui service mock response
stubFor(get(urlMatching("/containers/my-container/forms/processes/my-process.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody("my form")));
// user task mock response
TaskSummaryList userTaskResponse = new TaskSummaryList();
stubFor(get(urlMatching("/queries/tasks/instances.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(userTaskResponse, TaskSummaryList.class))));
return new RouteBuilder() {
@Override
public void configure() {
from("direct:start").to("kie:" + getAuthenticadUrl("admin", "admin")).to("mock:result");
}
};
}
use of org.kie.server.api.model.instance.SolverInstanceList in project droolsjbpm-integration by kiegroup.
the class SolverServicesClientImpl method getSolvers.
@Override
public List<SolverInstance> getSolvers(String containerId) {
checkMandatoryParameter("ContainerID", containerId);
final SolverInstanceList solverInstanceList;
if (config.isRest()) {
String uri = getURI(containerId);
solverInstanceList = makeHttpGetRequestAndCreateCustomResponse(uri, SolverInstanceList.class);
} else {
CommandScript script = new CommandScript(Collections.singletonList(new GetSolversCommand(containerId)));
ServiceResponse<SolverInstanceList> response = (ServiceResponse<SolverInstanceList>) executeJmsCommand(script, GetSolversCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
solverInstanceList = response.getResult();
}
if (solverInstanceList != null && solverInstanceList.getContainers() != null) {
return new ArrayList<>(solverInstanceList.getContainers());
}
return Collections.emptyList();
}
use of org.kie.server.api.model.instance.SolverInstanceList in project droolsjbpm-integration by kiegroup.
the class SolverResource method getSolvers.
@ApiOperation(value = "Retrieves solvers from given container", response = SolverInstanceList.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Container does not exist or failure in creating solver") })
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSolvers(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id where the solvers reside", required = true) @PathParam(CONTAINER_ID) String containerId) {
Variant v = getVariant(headers);
Header conversationIdHeader = buildConversationIdHeader(containerId, solverService.getKieServerRegistry(), headers);
try {
ServiceResponse<SolverInstanceList> result = solverService.getSolvers(containerId);
if (result.getType() == ServiceResponse.ResponseType.SUCCESS) {
return createCorrectVariant(marshallerHelper, containerId, result.getResult(), headers, Response.Status.OK, conversationIdHeader);
}
return createCorrectVariant(marshallerHelper, containerId, result.getMsg(), headers, Response.Status.NOT_FOUND, conversationIdHeader);
} catch (Exception e) {
logger.error("Unexpected error retrieving solvers. Message: '{}'", e.getMessage(), e);
return internalServerError(MessageFormat.format(Messages.UNEXPECTED_ERROR, e.getMessage()), v, conversationIdHeader);
}
}
Aggregations