use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class OptaplannerIntegrationTest method testExecuteSolverHelper.
private void testExecuteSolverHelper(String solverID) throws Exception {
SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, solverID, SOLVER_1_CONFIG);
assertNotNull(solverInstance);
assertEquals(SolverInstance.SolverStatus.NOT_SOLVING, solverInstance.getStatus());
// the following status starts the solver
Object planningProblem = loadPlanningProblem(5, 15);
solverClient.solvePlanningProblem(CONTAINER_1_ID, solverID, planningProblem);
solverInstance = solverClient.getSolver(CONTAINER_1_ID, solverID);
// solver should finish in 5 seconds, but we wait up to 15s before timing out
final long SOLVER_STATUS_CHECK_PERIOD = 1000L;
while (solverInstance.getStatus() == SolverInstance.SolverStatus.SOLVING) {
solverInstance = solverClient.getSolver(CONTAINER_1_ID, solverID);
assertNotNull(solverInstance);
Thread.sleep(SOLVER_STATUS_CHECK_PERIOD);
}
assertEquals(SolverInstance.SolverStatus.NOT_SOLVING, solverInstance.getStatus());
solverClient.disposeSolver(CONTAINER_1_ID, solverID);
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class OptaplannerIntegrationTest method testExecuteRealtimePlanningSolverSingleItemSubmit.
private void testExecuteRealtimePlanningSolverSingleItemSubmit(boolean daemon) throws Exception {
SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, daemon ? SOLVER_1_REALTIME_DAEMON_CONFIG : SOLVER_1_REALTIME_CONFIG);
assertNotNull(solverInstance);
assertEquals(SolverInstance.SolverStatus.NOT_SOLVING, solverInstance.getStatus());
final int computerCount = 5;
final int numberOfComputersToAdd = 5;
final Object planningProblem = loadPlanningProblem(computerCount, 15);
solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, planningProblem);
SolverInstance solver = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
assertEquals(SolverInstance.SolverStatus.SOLVING, solver.getStatus());
Thread.sleep(3000);
List computerList = null;
for (int i = 0; i < numberOfComputersToAdd; i++) {
ProblemFactChange<?> problemFactChange = loadAddProblemFactChange(computerCount + i);
solverClient.addProblemFactChange(CONTAINER_1_ID, SOLVER_1_ID, problemFactChange);
do {
final Object bestSolution = verifySolverAndGetBestSolution();
computerList = getCloudBalanceComputerList(bestSolution);
} while (computerCount + i + 1 != computerList.size());
}
assertTrue(solverClient.isEveryProblemFactChangeProcessed(CONTAINER_1_ID, SOLVER_1_ID));
Thread.sleep(3000);
assertNotNull(computerList);
for (int i = 0; i < numberOfComputersToAdd; i++) {
ProblemFactChange<?> problemFactChange = loadDeleteProblemFactChange(computerList.get(i));
solverClient.addProblemFactChange(CONTAINER_1_ID, SOLVER_1_ID, problemFactChange);
do {
final Object bestSolution = verifySolverAndGetBestSolution();
computerList = getCloudBalanceComputerList(bestSolution);
} while (computerCount + numberOfComputersToAdd - i - 1 != computerList.size());
}
assertTrue(solverClient.isEveryProblemFactChangeProcessed(CONTAINER_1_ID, SOLVER_1_ID));
solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class SolverServicesClientImpl method getSolver.
@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();
}
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class SolverServicesClientImpl method getSolverWithBestSolution.
@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();
}
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class SolverServicesClientImpl method createSolver.
@Override
public SolverInstance createSolver(String containerId, String solverId, String configFile) {
checkMandatoryParameter("ContainerId", containerId);
checkMandatoryParameter("SolverId", solverId);
checkMandatoryParameter("ConfigFile", configFile);
if (config.isRest()) {
String uri = getURI(containerId, solverId);
SolverInstance instance = new SolverInstance();
instance.setSolverConfigFile(configFile);
instance.setContainerId(containerId);
instance.setSolverId(solverId);
return makeHttpPutRequestAndCreateCustomResponse(uri, instance, SolverInstance.class, Collections.emptyMap());
} else {
CommandScript script = new CommandScript(Collections.singletonList(new CreateSolverCommand(containerId, solverId, configFile)));
ServiceResponse<SolverInstance> response = (ServiceResponse<SolverInstance>) executeJmsCommand(script, CreateSolverCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
return response.getResult();
}
}
Aggregations