if (command instanceof CreateSolverCommand) { CreateSolverCommand createSolverCommand = (CreateSolverCommand) command; String containerId = context.getContainerId(createSolverCommand.getContainerId(), ContainerLocatorProvider.get().getLocator()); SolverInstance instance = new SolverInstance(); instance.setContainerId(containerId); instance.setSolverId(createSolverCommand.getSolverId()); instance.setSolverConfigFile(createSolverCommand.getSolverConfigFile()); response = solverService.createSolver(containerId, createSolverCommand.getSolverId(), instance); } else if (command instanceof GetSolversCommand) { GetSolversCommand getSolversCommand = (GetSolversCommand) command; String containerId = context.getContainerId(getSolversCommand.getContainerId(), ContainerLocatorProvider.get().getLocator()); response = solverService.getSolvers(containerId); } else if (command instanceof GetSolverCommand) { GetSolverCommand getSolverCommand = (GetSolverCommand) command; String containerId = context.getContainerId(getSolverCommand.getContainerId(), ContainerLocatorProvider.get().getLocator()); response = solverService.getSolver(containerId, getSolverCommand.getSolverId()); } else if (command instanceof GetSolverWithBestSolutionCommand) { GetSolverWithBestSolutionCommand getSolverWithBestSolutionCommand = (GetSolverWithBestSolutionCommand) command; String containerId = context.getContainerId(getSolverWithBestSolutionCommand.getContainerId(), ContainerLocatorProvider.get().getLocator()); response = solverService.getSolverWithBestSolution(containerId, getSolverWithBestSolutionCommand.getSolverId());
@Override public void terminateSolverEarly(String containerId, String solverId) { checkMandatoryParameter("ContainerID", containerId); checkMandatoryParameter("SolverId", solverId); if (config.isRest()) { String uri = getURI(containerId, solverId) + "/" + RestURI.SOLVER_STATE_TERMINATING; makeHttpPostRequestAndCreateCustomResponse(uri, "", ServiceResponse.class); } else { CommandScript script = new CommandScript(Collections.singletonList(new TerminateSolverEarlyCommand(containerId, solverId))); ServiceResponse<Void> response = (ServiceResponse<Void>) executeJmsCommand(script, TerminateSolverEarlyCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0); throwExceptionOnFailure(response); } }
@Override public void disposeSolver(String containerId, String solverId) { checkMandatoryParameter("ContainerID", containerId); checkMandatoryParameter("SolverId", solverId); if (config.isRest()) { String uri = getURI(containerId, solverId); makeHttpDeleteRequestAndCreateCustomResponse(uri, ServiceResponse.class); } else { CommandScript script = new CommandScript(Collections.singletonList(new DisposeSolverCommand(containerId, solverId))); ServiceResponse<Void> response = (ServiceResponse<Void>) executeJmsCommand(script, DisposeSolverCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0); throwExceptionOnFailure(response); } }
@Override public void addProblemFactChanges(String containerId, String solverId, List<ProblemFactChange> problemFactChanges) { checkMandatoryParameter("containerId", containerId); checkMandatoryParameter("solverId", solverId); checkMandatoryParameter("problemFactChange", problemFactChanges); if (config.isRest()) { String uri = getURI(containerId, solverId) + "/" + RestURI.SOLVER_PROBLEM_FACT_CHANGES; makeHttpPostRequestAndCreateCustomResponse(uri, problemFactChanges, ServiceResponse.class, getHeaders(problemFactChanges)); } else { CommandScript script = new CommandScript(Collections.singletonList(new AddProblemFactChangesCommand(containerId, solverId, problemFactChanges))); ServiceResponse<Void> response = (ServiceResponse<Void>) executeJmsCommand(script, AddProblemFactChangeCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0); throwExceptionOnFailure(response); } }
@Override public void solvePlanningProblem(String containerId, String solverId, Object planningProblem) { checkMandatoryParameter("ContainerID", containerId); checkMandatoryParameter("SolverId", solverId); checkMandatoryParameter("planningSolution", planningProblem); if (config.isRest()) { String uri = getURI(containerId, solverId) + "/" + RestURI.SOLVER_STATE_RUNNING; makeHttpPostRequestAndCreateCustomResponse(uri, planningProblem, ServiceResponse.class, getHeaders(planningProblem)); } else { CommandScript script = new CommandScript(Collections.singletonList(new SolvePlanningProblemCommand(containerId, solverId, serialize(planningProblem)))); ServiceResponse<Void> response = (ServiceResponse<Void>) executeJmsCommand(script, SolvePlanningProblemCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0); throwExceptionOnFailure(response); } }
@Override public void addProblemFactChange(String containerId, String solverId, ProblemFactChange problemFactChange) { checkMandatoryParameter("containerId", containerId); checkMandatoryParameter("solverId", solverId); checkMandatoryParameter("problemFactChange", problemFactChange); if (config.isRest()) { String uri = getURI(containerId, solverId) + "/" + RestURI.SOLVER_PROBLEM_FACT_CHANGES; makeHttpPostRequestAndCreateCustomResponse(uri, problemFactChange, ServiceResponse.class, getHeaders(problemFactChange)); } else { CommandScript script = new CommandScript(Collections.singletonList(new AddProblemFactChangeCommand(containerId, solverId, problemFactChange))); ServiceResponse<Void> response = (ServiceResponse<Void>) executeJmsCommand(script, AddProblemFactChangeCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0); throwExceptionOnFailure(response); } }
@Override public SolverInstance getSolverWithBestSolution(String containerId, String solverId) { checkMandatoryParameter("ContainerID", containerId); checkMandatoryParameter("SolverId", solverId); if (config.isRest()) { String uri = getURI(containerId, solverId) + "/" + RestURI.SOLVER_BEST_SOLUTION; return makeHttpGetRequestAndCreateCustomResponse(uri, SolverInstance.class); } else { CommandScript script = new CommandScript(Collections.singletonList(new GetSolverWithBestSolutionCommand(containerId, solverId))); ServiceResponse<SolverInstance> response = (ServiceResponse<SolverInstance>) executeJmsCommand(script, GetSolverWithBestSolutionCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public SolverInstance getSolver(String containerId, String solverId) { checkMandatoryParameter("ContainerID", containerId); checkMandatoryParameter("SolverId", solverId); if (config.isRest()) { String uri = getURI(containerId, solverId); return makeHttpGetRequestAndCreateCustomResponse(uri, SolverInstance.class); } else { CommandScript script = new CommandScript(Collections.singletonList(new GetSolverCommand(containerId, solverId))); ServiceResponse<SolverInstance> response = (ServiceResponse<SolverInstance>) executeJmsCommand(script, GetSolverCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@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(); }
Object.class); } else { CommandScript script = new CommandScript(Collections.singletonList(new IsEveryProblemFactChangeProcessedCommand(containerId, solverId))); ServiceResponse<Object> response = (ServiceResponse<Object>) executeJmsCommand(script,
Collections.emptyMap()); } else { CommandScript script = new CommandScript(Collections.singletonList(new CreateSolverCommand(containerId, solverId, configFile)));