protected boolean shouldReturnWithNullResponse(ServiceResponse<?> serviceResponse) { if (serviceResponse != null && ServiceResponse.ResponseType.NO_RESPONSE.equals(serviceResponse.getType())){ logger.debug("Returning null as the response type is NO_RESPONSE"); return true; } return false; }
if (ServiceResponse.ResponseType.FAILURE.equals(reply.getType())) { throw new KieServicesException(reply.getMsg());
if (response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) {
if (ResponseType.FAILURE.equals(scannerResponse.getType())) { String errorMessage = "Failed to create scanner for container " + containerId + " with module " + releaseId + "."; messages.add(new Message(Severity.ERROR, errorMessage));
if (kci.getScanner() == null) { ServiceResponse<KieScannerResource> response = createScanner(id, kci); if (ResponseType.FAILURE.equals(response.getType())) { return response;
if (response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) { KieContainerResourceList resourceList = response.getResult();
@Override public void apply(KieServerRegistry kieServerRegistry, KieServer kieServer) { DefaultRestControllerImpl controller = new DefaultRestControllerImpl(kieServerRegistry); List<String> containerAliases = kieServerRegistry.getContainerAliases(); if (containerAliases.isEmpty()) { logger.debug("No containers found, quiting"); return; } for (String alias : containerAliases) { List<KieContainerInstanceImpl> containerInstances = kieServerRegistry.getContainersForAlias(alias); if (containerInstances.isEmpty() || containerInstances.size() == 1) { logger.debug("Containers for alias {} are already on expected level (number of containers is {})", alias, containerInstances.size()); continue; } String latestContainerId = LatestContainerLocator.get().locateContainer(alias, containerInstances); final Map<String, String> report = new HashMap<>(); containerInstances.stream() .filter(kci -> !kci.getContainerId().equals(latestContainerId)) .filter(kci -> !kci.getStatus().equals(KieContainerStatus.CREATING)) .forEach(kci -> { ServiceResponse<Void> response = kieServer.disposeContainer(kci.getContainerId()); report.put(kci.getContainerId(), response.getType().toString()); logger.debug("Dispose of container {} completed with {} message {}", kci.getContainerId(), response.getType().toString(), response.getMsg()); if (response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) { controller.stopContainer(kci.getContainerId()); } }); logger.info("KeepLatestContainerOnlyPolicy applied to {} successfully (report {})", alias, report); } }
private ServiceResponse<KieScannerResource> disposeScanner(String id, KieContainerInstanceImpl kci) { List<Message> messages = getMessagesForContainer(id); messages.clear(); if (kci.getScanner() == null) { return new ServiceResponse<KieScannerResource>(ServiceResponse.ResponseType.SUCCESS, "Invalid call. Scanner already disposed.", getScannerResource(kci)); } if (KieScannerStatus.STARTED.equals(mapScannerStatus(kci)) || KieScannerStatus.SCANNING.equals(mapScannerStatus(kci))) { ServiceResponse<KieScannerResource> response = stopScanner(id, kci); if (ResponseType.FAILURE.equals(response.getType())) { return response; } } kci.disposeScanner(); messages.add(new Message(Severity.INFO, "Kie scanner successfully disposed (shut down).")); return new ServiceResponse<KieScannerResource>(ServiceResponse.ResponseType.SUCCESS, "Kie scanner successfully disposed (shut down).", getScannerResource(kci)); }
@Override public Void doOperation(KieServicesClient client, Container container) { KieScannerResource scannerResource = new KieScannerResource(); scannerResource.setPollInterval(interval); scannerResource.setStatus(KieScannerStatus.STARTED); ServiceResponse<KieScannerResource> response = client.updateScanner(containerSpec.getId(), scannerResource); if (!response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) { logger.debug("Scanner failed to start on server instance {} due to {}", container.getUrl(), response.getMsg()); } collectContainerInfo(containerSpec, client, container); return null; } });
@Override public Void doOperation(KieServicesClient client, Container container) { KieScannerResource scannerResource = new KieScannerResource(); scannerResource.setPollInterval(null); scannerResource.setStatus(KieScannerStatus.SCANNING); ServiceResponse<KieScannerResource> response = client.updateScanner(containerSpec.getId(), scannerResource); if (!response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) { logger.debug("Scanner (scan now) failed on server instance {} due to {}", container.getUrl(), response.getMsg()); } collectContainerInfo(containerSpec, client, container); return null; } });
@Override public Void doOperation(KieServicesClient client, Container container) { KieScannerResource scannerResource = new KieScannerResource(); scannerResource.setPollInterval(null); scannerResource.setStatus(KieScannerStatus.STOPPED); ServiceResponse<KieScannerResource> response = client.updateScanner(containerSpec.getId(), scannerResource); if (!response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) { logger.debug("Scanner failed to stop on server instance {} due to {}", container.getUrl(), response.getMsg()); } collectContainerInfo(containerSpec, client, container); return null; } });
@Override public Void doOperation(KieServicesClient client, Container container) { final ServiceResponse<KieContainerResource> response = client.getContainerInfo(containerSpec.getId()); final KieContainerResource containerResource = response.getResult(); if (response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) { container.setContainerSpecId(containerResource.getContainerId()); container.setContainerName(containerResource.getContainerAlias()); container.setResolvedReleasedId(containerResource.getResolvedReleaseId() == null ? containerResource.getReleaseId() : containerResource.getResolvedReleaseId()); container.setServerTemplateId(serverTemplate.getId()); container.setStatus(containerResource.getStatus()); container.setMessages(containerResource.getMessages()); } return null; } };
@Override public Void doOperation(KieServicesClient client, Container container) { ServiceResponse<Void> response = client.disposeContainer(containerSpec.getId()); if (!response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) { logger.debug("Container {} failed to stop on server instance {} due to {}", containerSpec.getId(), container.getUrl(), response.getMsg()); } collectContainerInfo(containerSpec, client, container); return null; } });
@BeforeClass public static void buildAndDeployArtifacts() { KieServerDeployer.buildAndDeployCommonMavenParent(); KieServerDeployer.buildAndDeployMavenProjectFromResource("/kjars-sources/query-definition-project"); kieContainer = KieServices.Factory.get().newKieContainer(releaseId); // Having timeout issues due to kjar dependencies -> raised timeout. KieServicesClient client = createDefaultStaticClient(EXTENDED_TIMEOUT); ServiceResponse<KieContainerResource> reply = client.createContainer(CONTAINER_ID, new KieContainerResource(CONTAINER_ID, releaseId)); Assume.assumeTrue(reply.getType().equals(ServiceResponse.ResponseType.SUCCESS)); }
protected void throwExceptionOnFailure(ServiceResponse<?> serviceResponse) { if (serviceResponse != null && ServiceResponse.ResponseType.FAILURE.equals(serviceResponse.getType())){ throw new KieServicesException(serviceResponse.getMsg()); } }
protected void throwExceptionOnFailure(ServiceResponse<?> serviceResponse) { if (serviceResponse != null && ServiceResponse.ResponseType.FAILURE.equals(serviceResponse.getType())) { throw new KieServicesException(serviceResponse.getMsg()); } } }
protected void collectContainerInfo(ContainerSpec containerSpec, KieServicesClient client, Container container) { // collect up to date information ServiceResponse<KieContainerResource> serviceResponse = client.getContainerInfo(containerSpec.getId()); if (serviceResponse.getType().equals(ServiceResponse.ResponseType.SUCCESS)) { KieContainerResource containerResource = serviceResponse.getResult(); container.setResolvedReleasedId(containerResource.getResolvedReleaseId() == null ? containerResource.getReleaseId() : containerResource.getResolvedReleaseId()); container.setMessages(containerResource.getMessages()); } }