protected KieServicesClient getClient(final String url) { KieServicesClientProvider clientProvider = clientProviders.stream().filter(provider -> provider.supports(url)).findFirst().orElseThrow(() -> new KieServerControllerIllegalArgumentException("Kie Services Client Provider not found for url: " + url)); logger.debug("Using client provider {}", clientProvider); KieServicesClient client = clientProvider.get(url); logger.debug("Using client {}", client); if(client == null){ throw new KieServerControllerIllegalArgumentException("Kie Services Client not found for url: " + url); } return client; }
@ApiOperation(value = "Disposes a specified KIE container in a specified KIE Server template.", code = 204) @ApiResponses(value = { @ApiResponse(code = 204, message = "KIE container successfully disposed"), @ApiResponse(code = 404, message = "Container Specification or KIE Server template not found"), @ApiResponse(code = 400, message = "Controller exception"), @ApiResponse(code = 500, message = "Unexpected error") }) @DELETE @Path("servers/{serverTemplateId}/containers/{containerId}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response deleteContainerSpec(@Context HttpHeaders headers, @ApiParam(name = "serverTemplateId", value = "ID of the KIE Server template associated with the KIE container", required = true, example = "test-kie-server") @PathParam("serverTemplateId") String serverTemplateId, @ApiParam(name = "containerId", value = "ID of the KIE container to be disposed", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam("containerId") String containerSpecId) { try { specManagementService.deleteContainerSpec(serverTemplateId, containerSpecId); // return null to produce 204 return null; } catch (KieServerControllerIllegalArgumentException e) { return createCorrectVariant(e.getMessage(), headers, Response.Status.NOT_FOUND); } catch (KieServerControllerException e){ return createCorrectVariant(REQUEST_FAILED_TOBE_PROCESSED + e.getMessage(), headers, Response.Status.BAD_REQUEST); } catch (Exception e) { logger.error("Remove container with id {} from server template with id {} failed due to {}", containerSpecId, serverTemplateId, e.getMessage(), e); return createCorrectVariant("Unknown error " + e.getMessage(), headers, Response.Status.INTERNAL_SERVER_ERROR); } }
protected ServerTemplate getServerTemplate(final String serverTemplateId){ final ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } return serverTemplate; }
@ApiOperation(value = "Deletes a specified KIE Server template", code = 204) @ApiResponses(value = { @ApiResponse(code = 204, message = "KIE Server template successfully deleted"), @ApiResponse(code = 404, message = "KIE Server template not found"), @ApiResponse(code = 400, message = "Controller exception"), @ApiResponse(code = 500, message = "Unexpected error") }) @DELETE @Path("servers/{serverTemplateId}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response deleteServerTemplate(@Context HttpHeaders headers, @ApiParam(name = "serverTemplateId", value = "ID of the KIE Server template to be deleted", required = true, example = "test-kie-server") @PathParam("serverTemplateId") String serverTemplateId) { try { specManagementService.deleteServerTemplate(serverTemplateId); // return null to produce 204 return null; } catch (KieServerControllerIllegalArgumentException e) { return createCorrectVariant(e.getMessage(), headers, Response.Status.NOT_FOUND); } catch (KieServerControllerException e){ return createCorrectVariant(REQUEST_FAILED_TOBE_PROCESSED + e.getMessage(), headers, Response.Status.BAD_REQUEST); } catch (Exception e) { logger.error("Remove server template with id {} failed due to {}", serverTemplateId, e.getMessage(), e); return createCorrectVariant("Unknown error " + e.getMessage(), headers, Response.Status.INTERNAL_SERVER_ERROR); } }
@Override public ServerTemplate getServerTemplate(String serverTemplateId) { final ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } return serverTemplate; }
return createCorrectVariant(e.getMessage(), headers, Response.Status.NOT_FOUND); } catch (KieServerControllerException e){ return createCorrectVariant(REQUEST_FAILED_TOBE_PROCESSED + e.getMessage(), headers, Response.Status.BAD_REQUEST);
@Override public ContainerSpec getContainerInfo(String serverTemplateId, String containerId) { final ServerTemplate serverTemplate = getServerTemplate(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } final ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerId); if (containerSpec == null) { throw new KieServerControllerIllegalArgumentException("Server template " + serverTemplateId + " does not have container with id " + containerId); } return containerSpec; }
@ApiOperation(value = "Stops a specified KIE container in a specified KIE Server template") @ApiResponses(value = { @ApiResponse(code = 200, message = "KIE container successfully stopped"), @ApiResponse(code = 404, message = "KIE container or KIE Server template not found"), @ApiResponse(code = 400, message = "Controller exception"), @ApiResponse(code = 500, message = "Unexpected error") }) @POST @Path("servers/{serverTemplateId}/containers/{containerId}/status/stopped") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response stopContainer(@Context HttpHeaders headers, @ApiParam(name = "serverTemplateId", value = "ID of the KIE Server template associated with the KIE container", required = true, example = "test-kie-server") @PathParam("serverTemplateId") String serverTemplateId, @ApiParam(name = "containerId", value = "ID of the KIE container to be stopped", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam("containerId") String containerId) { logger.debug("Requesting stop container with id {} server instance: {}", containerId, serverTemplateId); try { ContainerSpecKey containerSpecKey = new ContainerSpecKey(); containerSpecKey.setId(containerId); containerSpecKey.setServerTemplateKey(new ServerTemplateKey(serverTemplateId, "")); specManagementService.stopContainer(containerSpecKey); logger.debug("Returning response for stop container with id {} server instance: {}", containerId, serverTemplateId); return createCorrectVariant("", headers, Response.Status.OK); } catch (KieServerControllerIllegalArgumentException e) { return createCorrectVariant(e.getMessage(), headers, Response.Status.NOT_FOUND); } catch (Exception e) { logger.error("Stop container failed due to {}", e.getMessage(), e); return createCorrectVariant("Unknown error " + e.getMessage(), headers, Response.Status.INTERNAL_SERVER_ERROR); } }
@Override public ContainerSpecList listContainerSpec(String serverTemplateId) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } return new ContainerSpecList(serverTemplate.getContainersSpec()); }
return createCorrectVariant(e.getMessage(), headers, Response.Status.NOT_FOUND); } catch (KieServerControllerException e){ return createCorrectVariant(REQUEST_FAILED_TOBE_PROCESSED + e.getMessage(), headers, Response.Status.BAD_REQUEST);
@Override public synchronized void copyServerTemplate(String serverTemplateId, String newServerTemplateId, String newServerTemplateName) { final ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } final Map<Capability, ServerConfig> configMap = new HashMap<Capability, ServerConfig>(serverTemplate.getConfigs().size()); for (final Map.Entry<Capability, ServerConfig> entry : serverTemplate.getConfigs().entrySet()) { configMap.put(entry.getKey(), copy(entry.getValue())); } final Collection<ContainerSpec> containerSpecs = new ArrayList<ContainerSpec>(serverTemplate.getContainersSpec().size()); for (final ContainerSpec entry : serverTemplate.getContainersSpec()) { containerSpecs.add(copy(entry, newServerTemplateId, newServerTemplateName)); } final ServerTemplate copy = new ServerTemplate(newServerTemplateId, newServerTemplateName, serverTemplate.getCapabilities(), configMap, containerSpecs); templateStorage.store(copy); }
@ApiOperation(value = "Starts a specified KIE container in a specified KIE Server template") @ApiResponses(value = { @ApiResponse(code = 200, message = "KIE Container successfully started"), @ApiResponse(code = 404, message = "KIE container or KIE Server template not found"), @ApiResponse(code = 400, message = "Controller exception"), @ApiResponse(code = 500, message = "Unexpected error") }) @POST @Path("servers/{serverTemplateId}/containers/{containerId}/status/started") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response startContainer(@Context HttpHeaders headers, @ApiParam(name = "serverTemplateId", value = "ID of the KIE Server template associated with the KIE container", required = true, example = "test-kie-server") @PathParam("serverTemplateId") String serverTemplateId, @ApiParam(name = "containerId", value = "ID of the KIE container to be started", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam("containerId") String containerId) { logger.debug("Requesting start container with id {} server instance: {}", containerId, serverTemplateId); try { ContainerSpecKey containerSpecKey = new ContainerSpecKey(); containerSpecKey.setId(containerId); containerSpecKey.setServerTemplateKey(new ServerTemplateKey(serverTemplateId, "")); specManagementService.startContainer(containerSpecKey); logger.debug("Returning response for start container with id {} server instance: {}", containerId, serverTemplateId); return createCorrectVariant("", headers, Response.Status.OK); } catch (KieServerControllerIllegalArgumentException e) { return createCorrectVariant(e.getMessage(), headers, Response.Status.NOT_FOUND); } catch (Exception e) { logger.error("Start container failed due to {}", e.getMessage(), e); return createCorrectVariant("Unknown error " + e.getMessage(), headers, Response.Status.INTERNAL_SERVER_ERROR); } }
@Override public synchronized void deleteServerTemplate(String serverTemplateId) { if (!templateStorage.exists(serverTemplateId)) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } templateStorage.delete(serverTemplateId); notificationService.notify(new ServerTemplateDeleted(serverTemplateId)); }
@ApiOperation(value = "Activates a specified KIE container in a specified KIE Server template") @ApiResponses(value = { @ApiResponse(code = 200, message = "KIE container successfully activated"), @ApiResponse(code = 404, message = "KIE container or KIE Server template not found"), @ApiResponse(code = 400, message = "Controller exception"), @ApiResponse(code = 500, message = "Unexpected error") }) @POST @Path("servers/{serverTemplateId}/containers/{containerId}/status/activated") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response activateContainer(@Context HttpHeaders headers, @ApiParam(name = "serverTemplateId", value = "ID of the KIE Server template associated with the KIE container", required = true, example = "test-kie-server") @PathParam("serverTemplateId") String serverTemplateId, @ApiParam(name = "containerId", value = "ID of the KIE container to be activated", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam("containerId") String containerId) { logger.debug("Requesting activate container with id {} server instance: {}", containerId, serverTemplateId); try { ContainerSpecKey containerSpecKey = new ContainerSpecKey(); containerSpecKey.setId(containerId); containerSpecKey.setServerTemplateKey(new ServerTemplateKey(serverTemplateId, "")); specManagementService.activateContainer(containerSpecKey); logger.debug("Returning response for activate container with id {} server instance: {}", containerId, serverTemplateId); return createCorrectVariant("", headers, Response.Status.OK); } catch (KieServerControllerIllegalArgumentException e) { return createCorrectVariant(e.getMessage(), headers, Response.Status.NOT_FOUND); } catch (Exception e) { logger.error("Stop container failed due to {}", e.getMessage(), e); return createCorrectVariant("Unknown error " + e.getMessage(), headers, Response.Status.INTERNAL_SERVER_ERROR); } }
@Override public synchronized void deleteContainerSpec(String serverTemplateId, String containerSpecId) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } if (serverTemplate.hasContainerSpec(containerSpecId)) { ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecId); kieServerInstanceManager.stopContainer(serverTemplate, containerSpec); serverTemplate.deleteContainerSpec(containerSpecId); templateStorage.update(serverTemplate); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); } else { throw new KieServerControllerIllegalArgumentException("Container " + containerSpecId + " not found"); } }
@ApiOperation(value = "Deactivates a specified KIE container in a specified KIE Server template") @ApiResponses(value = { @ApiResponse(code = 200, message = "KIE container successfully deactivated"), @ApiResponse(code = 404, message = "KIE container or KIE Server template not found"), @ApiResponse(code = 400, message = "Controller exception"), @ApiResponse(code = 500, message = "Unexpected error") }) @POST @Path("servers/{serverTemplateId}/containers/{containerId}/status/deactivated") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response deactivateContainer(@Context HttpHeaders headers, @ApiParam(name = "serverTemplateId", value = "ID of the KIE Server template associated with the KIE container", required = true, example = "test-kie-server") @PathParam("serverTemplateId") String serverTemplateId, @ApiParam(name = "containerId", value = "ID of the KIE container to be deactivated", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam("containerId") String containerId) { logger.debug("Requesting deactivate container with id {} server instance: {}", containerId, serverTemplateId); try { ContainerSpecKey containerSpecKey = new ContainerSpecKey(); containerSpecKey.setId(containerId); containerSpecKey.setServerTemplateKey(new ServerTemplateKey(serverTemplateId, "")); specManagementService.deactivateContainer(containerSpecKey); logger.debug("Returning response for deactivate container with id {} server instance: {}", containerId, serverTemplateId); return createCorrectVariant("", headers, Response.Status.OK); } catch (KieServerControllerIllegalArgumentException e) { return createCorrectVariant(e.getMessage(), headers, Response.Status.NOT_FOUND); } catch (Exception e) { logger.error("Start container failed due to {}", e.getMessage(), e); return createCorrectVariant("Unknown error " + e.getMessage(), headers, Response.Status.INTERNAL_SERVER_ERROR); } }
@Override public synchronized void updateServerTemplateConfig(String serverTemplateId, Capability capability, ServerConfig serverTemplateConfig) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } Map<Capability, ServerConfig> configs = serverTemplate.getConfigs(); configs.put(capability, serverTemplateConfig); serverTemplate.setConfigs(configs); templateStorage.update(serverTemplate); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); }
return createCorrectVariant("", headers, Response.Status.CREATED); } catch (KieServerControllerIllegalArgumentException e) { return createCorrectVariant(e.getMessage(), headers, Response.Status.NOT_FOUND); } catch (KieServerControllerException e){ return createCorrectVariant(REQUEST_FAILED_TOBE_PROCESSED + e.getMessage(), headers, Response.Status.BAD_REQUEST);
public ContainerList getServerTemplateContainers(final String serverTemplateId, final String containerSpecId) { final ServerTemplate serverTemplate = getServerTemplate(serverTemplateId); if (serverTemplate.hasContainerSpec(containerSpecId) == false) { throw new KieServerControllerIllegalArgumentException("Server template with id " + serverTemplateId + " has no container with id " + containerSpecId); } final ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecId); Collection<Container> containers = kieServerInstanceManager.getContainers(serverTemplate, containerSpec); return new ContainerList(containers); }
return createCorrectVariant(e.getMessage(), headers, Response.Status.NOT_FOUND); } catch (KieServerControllerException e){ return createCorrectVariant(REQUEST_FAILED_TOBE_PROCESSED + e.getMessage(), headers, Response.Status.BAD_REQUEST);