Search in sources :

Example 1 with SolverInstanceList

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();
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) Marshaller(org.kie.server.api.marshalling.Marshaller) ResponseHandler(org.kie.server.client.jms.ResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) SolverInstanceList(org.kie.server.api.model.instance.SolverInstanceList) OptaplannerKieServerBaseIntegrationTest(org.kie.server.integrationtests.optaplanner.OptaplannerKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 2 with SolverInstanceList

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");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) RequestInfoInstanceList(org.kie.server.api.model.instance.RequestInfoInstanceList) KieServerInfo(org.kie.server.api.model.KieServerInfo) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) SolverInstanceList(org.kie.server.api.model.instance.SolverInstanceList) TaskSummaryList(org.kie.server.api.model.instance.TaskSummaryList) ServiceResponse(org.kie.server.api.model.ServiceResponse) DocumentInstance(org.kie.server.api.model.instance.DocumentInstance)

Example 3 with SolverInstanceList

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();
}
Also used : ServiceResponse(org.kie.server.api.model.ServiceResponse) GetSolversCommand(org.kie.server.api.commands.optaplanner.GetSolversCommand) ArrayList(java.util.ArrayList) CommandScript(org.kie.server.api.commands.CommandScript) SolverInstanceList(org.kie.server.api.model.instance.SolverInstanceList)

Example 4 with SolverInstanceList

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);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) SolverInstanceList(org.kie.server.api.model.instance.SolverInstanceList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

SolverInstanceList (org.kie.server.api.model.instance.SolverInstanceList)4 ServiceResponse (org.kie.server.api.model.ServiceResponse)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Variant (javax.ws.rs.core.Variant)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 Test (org.junit.Test)1 CommandScript (org.kie.server.api.commands.CommandScript)1 GetSolversCommand (org.kie.server.api.commands.optaplanner.GetSolversCommand)1 Marshaller (org.kie.server.api.marshalling.Marshaller)1 KieServerInfo (org.kie.server.api.model.KieServerInfo)1 ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)1 ProcessDefinitionList (org.kie.server.api.model.definition.ProcessDefinitionList)1 DocumentInstance (org.kie.server.api.model.instance.DocumentInstance)1 NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)1 RequestInfoInstanceList (org.kie.server.api.model.instance.RequestInfoInstanceList)1 SolverInstance (org.kie.server.api.model.instance.SolverInstance)1