@Test public void createSolverWithInstanceNullFailure() { ServiceResponse<SolverInstance> response = serviceBase.createSolver(CONTAINER_ID, SOLVER_ID, null); assertFailure(response, String.format(CREATE_SOLVER_FOR_CONTAINER_ERROR, CONTAINER_ID)); }
public ServiceResponse<SolverInstance> createSolver(String containerId, String solverId, SolverInstance instance) { if (instance == null || instance.getSolverConfigFile() == null) { logger.error("Error creating solver. Configuration file name is null: " + instance); return new ServiceResponse<>( ServiceResponse.ResponseType.FAILURE, "Failed to create solver for container " + containerId + ". Solver configuration file is null: " + instance); } instance.setContainerId(containerId); instance.setSolverId(solverId); try { KieContainerInstanceImpl ci = context.getContainer(containerId); if (ci == null) { logger.error("Error creating solver. Container does not exist: " + containerId); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Failed to create solver. Container does not exist: " + containerId); } synchronized (ci) { if (solvers.containsKey(instance.getSolverInstanceKey())) { logger.error("Error creating solver. Solver '" + solverId + "' already exists for container '" + containerId + "'."); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Failed to create solver. Solver '" + solverId + "' already exists for container '" + containerId + "'."); } SolverInstanceContext sic = new SolverInstanceContext(instance); if (instance.getStatus() == null) { instance.setStatus(SolverInstance.SolverStatus.NOT_SOLVING); } try { Solver<Object> solver = buildSolver(ci.getKieContainer(), instance.getSolverConfigFile()); sic.setSolver(solver); registerListener(solver, solverId); updateSolverInstance(sic); solvers.put(instance.getSolverInstanceKey(), sic); logger.info("Solver '" + solverId + "' successfully created in container '" + containerId + "'"); return new ServiceResponse<>(ServiceResponse.ResponseType.SUCCESS, "Solver '" + solverId + "' successfully created in container '" + containerId + "'", instance); } catch (Exception e) { logger.error("Error creating solver factory for solver " + instance, e); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Error creating solver factory for solver: " + e.getMessage(), instance); } } } catch (Exception e) { logger.error("Error creating solver '" + solverId + "' in container '" + containerId + "'", e); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Error creating solver '" + solverId + "' in container '" + containerId + "': " + e.getMessage(), instance); } }
SolverServiceBase { public ServiceResponse<SolverInstance> createSolver(String containerId, String solverId, SolverInstance instance) { if (instance == null || instance.getSolverConfigFile() == null) { logger.error("Error creating solver. Configuration file name is null: " + instance); return new ServiceResponse<>( ServiceResponse.ResponseType.FAILURE, "Failed to create solver for container " + containerId + ". Solver configuration file is null: " + instance); } instance.setContainerId(containerId); instance.setSolverId(solverId); try { KieContainerInstanceImpl ci = context.getContainer(containerId); if (ci == null) { logger.error("Error creating solver. Container does not exist: " + containerId); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Failed to create solver. Container does not exist: " + containerId); } synchronized (ci) { if (solvers.containsKey(instance.getSolverInstanceKey())) { logger.error("Error creating solver. Solver '" + solverId + "' already exists for container '" + containerId + "'."); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Failed to create solver. Solver '" + solverId + "' already exists for container '" + containerId + "'."); } SolverInstanceContext sic = new SolverInstanceContext(instance); if (instance.getStatus() == null) { instance.setStatus(SolverInstance.SolverStatus.NOT_SOLVING); } try { Solver<Object> solver = buildSolver(ci.getKieContainer(), instance.getSolverConfigFile()); sic.setSolver(solver); registerListener(solver, solverId); updateSolverInstance(sic); solvers.put(instance.getSolverInstanceKey(), sic); logger.info("Solver '" + solverId + "' successfully created in container '" + containerId + "'"); return new ServiceResponse<>(ServiceResponse.ResponseType.SUCCESS, "Solver '" + solverId + "' successfully created in container '" + containerId + "'", instance); } catch (Exception e) { logger.error("Error creating solver factory for solver " + instance, e); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Error creating solver factory for solver: " + e.getMessage(), instance); } } } catch (Exception e) { logger.error("Error creating solver '" + solverId + "' in container '" + containerId + "'", e); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Error creating solver '" + solverId + "' in container '" + containerId + "': " + e.getMessage(), instance); } } }
SolverServiceBase { public ServiceResponse<SolverInstance> createSolver(String containerId, String solverId, SolverInstance instance) { if (instance == null || instance.getSolverConfigFile() == null) { logger.error("Error creating solver. Configuration file name is null: " + instance); return new ServiceResponse<>( ServiceResponse.ResponseType.FAILURE, "Failed to create solver for container " + containerId + ". Solver configuration file is null: " + instance); } instance.setContainerId(containerId); instance.setSolverId(solverId); try { KieContainerInstanceImpl ci = context.getContainer(containerId); if (ci == null) { logger.error("Error creating solver. Container does not exist: " + containerId); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Failed to create solver. Container does not exist: " + containerId); } synchronized (ci) { if (solvers.containsKey(instance.getSolverInstanceKey())) { logger.error("Error creating solver. Solver '" + solverId + "' already exists for container '" + containerId + "'."); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Failed to create solver. Solver '" + solverId + "' already exists for container '" + containerId + "'."); } SolverInstanceContext sic = new SolverInstanceContext(instance); if (instance.getStatus() == null) { instance.setStatus(SolverInstance.SolverStatus.NOT_SOLVING); } try { Solver<Object> solver = buildSolver(ci.getKieContainer(), instance.getSolverConfigFile()); sic.setSolver(solver); registerListener(solver, solverId); updateSolverInstance(sic); solvers.put(instance.getSolverInstanceKey(), sic); logger.info("Solver '" + solverId + "' successfully created in container '" + containerId + "'"); return new ServiceResponse<>(ServiceResponse.ResponseType.SUCCESS, "Solver '" + solverId + "' successfully created in container '" + containerId + "'", instance); } catch (Exception e) { logger.error("Error creating solver factory for solver " + instance, e); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Error creating solver factory for solver: " + e.getMessage(), instance); } } } catch (Exception e) { logger.error("Error creating solver '" + solverId + "' in container '" + containerId + "'", e); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Error creating solver '" + solverId + "' in container '" + containerId + "': " + e.getMessage(), instance); } } SolverServiceBase(KieServerRegistry context,
                             ExecutorService executorService); }
SolverServiceBase { public ServiceResponse<SolverInstance> createSolver(String containerId, String solverId, SolverInstance instance) { if (instance == null || instance.getSolverConfigFile() == null) { logger.error("Error creating solver. Configuration file name is null: " + instance); return new ServiceResponse<>( ServiceResponse.ResponseType.FAILURE, "Failed to create solver for container " + containerId + ". Solver configuration file is null: " + instance); } instance.setContainerId(containerId); instance.setSolverId(solverId); try { KieContainerInstanceImpl ci = context.getContainer(containerId); if (ci == null) { logger.error("Error creating solver. Container does not exist: " + containerId); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Failed to create solver. Container does not exist: " + containerId); } synchronized (ci) { if (solvers.containsKey(instance.getSolverInstanceKey())) { logger.error("Error creating solver. Solver '" + solverId + "' already exists for container '" + containerId + "'."); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Failed to create solver. Solver '" + solverId + "' already exists for container '" + containerId + "'."); } SolverInstanceContext sic = new SolverInstanceContext(instance); if (instance.getStatus() == null) { instance.setStatus(SolverInstance.SolverStatus.NOT_SOLVING); } try { Solver<Object> solver = buildSolver(ci.getKieContainer(), instance.getSolverConfigFile()); sic.setSolver(solver); registerListener(solver, solverId); updateSolverInstance(sic); solvers.put(instance.getSolverInstanceKey(), sic); logger.info("Solver '" + solverId + "' successfully created in container '" + containerId + "'"); return new ServiceResponse<>(ServiceResponse.ResponseType.SUCCESS, "Solver '" + solverId + "' successfully created in container '" + containerId + "'", instance); } catch (Exception e) { logger.error("Error creating solver factory for solver " + instance, e); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Error creating solver factory for solver: " + e.getMessage(), instance); } } } catch (Exception e) { logger.error("Error creating solver '" + solverId + "' in container '" + containerId + "'", e); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Error creating solver '" + solverId + "' in container '" + containerId + "': " + e.getMessage(), instance); } } SolverServiceBase(KieServerRegistry context,
                             ExecutorService executorService); ServiceResponse<SolverInstance> createSolver(String containerId,
                                                        String solverId,
                                                        SolverInstance instance); ServiceResponse<SolverInstanceList> getSolvers(String containerId); ServiceResponse<SolverInstance> getSolver(String containerId,
                                                     String solverId); ServiceResponse<SolverInstance> getSolverWithBestSolution(String containerId,
                                                                     String solverId); ServiceResponse<Void> solvePlanningProblem(String containerId,
                                                      String solverId,
                                                      Object planningProblem); ServiceResponse<Void> terminateSolverEarly(String containerId,
                                                      String solverId); ServiceResponse<Void> addProblemFactChanges(String containerId,
                                                       String solverId,
                                                       Object problemFactChanges); ServiceResponse<Boolean> isEveryProblemFactChangeProcessed(final String containerId,
                                                                      final String solverId); ServiceResponse<Void> disposeSolver(String containerId,
                                               String solverId); KieServerRegistry getKieServerRegistry(); void disposeSolversForContainer(String containerId,
                                           KieContainerInstance kci); }
SolverServiceBase { public ServiceResponse<SolverInstance> createSolver(String containerId, String solverId, SolverInstance instance) { if (instance == null || instance.getSolverConfigFile() == null) { logger.error("Error creating solver. Configuration file name is null: " + instance); return new ServiceResponse<>( ServiceResponse.ResponseType.FAILURE, "Failed to create solver for container " + containerId + ". Solver configuration file is null: " + instance); } instance.setContainerId(containerId); instance.setSolverId(solverId); try { KieContainerInstanceImpl ci = context.getContainer(containerId); if (ci == null) { logger.error("Error creating solver. Container does not exist: " + containerId); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Failed to create solver. Container does not exist: " + containerId); } synchronized (ci) { if (solvers.containsKey(instance.getSolverInstanceKey())) { logger.error("Error creating solver. Solver '" + solverId + "' already exists for container '" + containerId + "'."); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Failed to create solver. Solver '" + solverId + "' already exists for container '" + containerId + "'."); } SolverInstanceContext sic = new SolverInstanceContext(instance); if (instance.getStatus() == null) { instance.setStatus(SolverInstance.SolverStatus.NOT_SOLVING); } try { Solver<Object> solver = buildSolver(ci.getKieContainer(), instance.getSolverConfigFile()); sic.setSolver(solver); registerListener(solver, solverId); updateSolverInstance(sic); solvers.put(instance.getSolverInstanceKey(), sic); logger.info("Solver '" + solverId + "' successfully created in container '" + containerId + "'"); return new ServiceResponse<>(ServiceResponse.ResponseType.SUCCESS, "Solver '" + solverId + "' successfully created in container '" + containerId + "'", instance); } catch (Exception e) { logger.error("Error creating solver factory for solver " + instance, e); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Error creating solver factory for solver: " + e.getMessage(), instance); } } } catch (Exception e) { logger.error("Error creating solver '" + solverId + "' in container '" + containerId + "'", e); return new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, "Error creating solver '" + solverId + "' in container '" + containerId + "': " + e.getMessage(), instance); } } SolverServiceBase(KieServerRegistry context,
                             ExecutorService executorService); ServiceResponse<SolverInstance> createSolver(String containerId,
                                                        String solverId,
                                                        SolverInstance instance); ServiceResponse<SolverInstanceList> getSolvers(String containerId); ServiceResponse<SolverInstance> getSolver(String containerId,
                                                     String solverId); ServiceResponse<SolverInstance> getSolverWithBestSolution(String containerId,
                                                                     String solverId); ServiceResponse<Void> solvePlanningProblem(String containerId,
                                                      String solverId,
                                                      Object planningProblem); ServiceResponse<Void> terminateSolverEarly(String containerId,
                                                      String solverId); ServiceResponse<Void> addProblemFactChanges(String containerId,
                                                       String solverId,
                                                       Object problemFactChanges); ServiceResponse<Boolean> isEveryProblemFactChangeProcessed(final String containerId,
                                                                      final String solverId); ServiceResponse<Void> disposeSolver(String containerId,
                                               String solverId); KieServerRegistry getKieServerRegistry(); void disposeSolversForContainer(String containerId,
                                           KieContainerInstance kci); static final String SCAN_EXCLUDED_PACKAGES_CONFIG_ITEM; }