@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 synchronized void updateContainerSpec(final String serverTemplateId, final String containerId, final ContainerSpec containerSpec) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } if (!containerSpec.getId().equals(containerId)) { throw new KieServerControllerException("Cannot update container " + containerSpec.getId() + " on container " + containerId); } if (!serverTemplate.hasContainerSpec(containerSpec.getId())) { throw new KieServerControllerIllegalArgumentException("Server template with id " + serverTemplateId + " has no container with id " + containerSpec.getId()); } if (!serverTemplate.hasMatchingId(containerSpec.getServerTemplateKey())) { throw new KieServerControllerException("Cannot change container template key during update."); } // make sure correct server template is set containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName())); ContainerSpec currentVersion = serverTemplate.getContainerSpec(containerSpec.getId()); serverTemplate.deleteContainerSpec(currentVersion.getId()); serverTemplate.addContainerSpec(containerSpec); templateStorage.update(serverTemplate); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); // in case container was started before it was update or update comes with status started update container in running servers if (currentVersion.getStatus().equals(KieContainerStatus.STARTED) || containerSpec.getStatus().equals(KieContainerStatus.STARTED)) { List<Container> containers = kieServerInstanceManager.upgradeAndStartContainer(serverTemplate, containerSpec); notificationService.notify(serverTemplate, containerSpec, containers); } }
@Override public synchronized void saveContainerSpec(String serverTemplateId, ContainerSpec containerSpec) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } if (serverTemplate.hasContainerSpec(containerSpec.getId())) { throw new KieServerControllerException("Server template with id " + serverTemplateId + " associated already with container " + containerSpec.getId()); } // make sure correct server template is set containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName())); serverTemplate.addContainerSpec(containerSpec); templateStorage.update(serverTemplate); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); if (containerSpec.getStatus().equals(KieContainerStatus.STARTED)) { List<Container> containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec); notificationService.notify(serverTemplate, containerSpec, containers); } }
@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); } }
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("Get containers using server template id {} and container id {} failed due to {}", serverTemplateId, containerId, e.getMessage(), e);
return createCreatedVariant("", headers, builder); } catch (KieServerControllerException e){ return createCorrectVariant(REQUEST_FAILED_TOBE_PROCESSED + e.getMessage(), headers, Response.Status.BAD_REQUEST); } catch (Exception e) { logger.error("Save server template id {} failed due to {}", serverTemplateId, e.getMessage(), 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("Get server instances using server template id {} failed due to {}", serverTemplateId, e.getMessage(), 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("Get containers using server template id {} and instance id {} failed due to {}", serverTemplateId, instanceId, e.getMessage(), 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("Save container spec request for server template id {} failed due to {}", serverTemplateId, e.getMessage(), 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("Get server templates failed due to {}", e.getMessage(), 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("Get server template id {} failed due to {}", serverTemplateId, e.getMessage(), 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("Save container spec request for server template id {} failed due to {}", serverTemplateId, e.getMessage(), e);
@ApiOperation(value = "Returns all KIE Server templates", response = ServerTemplateList.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "KIE Server templates", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = SERVER_TEMPLATE_LIST_JSON), @ExampleProperty(mediaType = XML, value = SERVER_TEMPLATE_LIST_XML) })), @ApiResponse(code = 404, message = "KIE Server template not found"), @ApiResponse(code = 400, message = "Controller exception"), @ApiResponse(code = 500, message = "Unexpected error") }) @GET @Path("servers") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response listServerTemplates(@Context HttpHeaders headers) { String contentType = getContentType(headers); try { logger.debug("Received get server templates"); String response = marshal(contentType, specManagementService.listServerTemplates()); logger.debug("Returning response for get server templates: {}", response); return createCorrectVariant(response, headers, Response.Status.OK); } 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("Get server templates failed due to {}", e.getMessage(), e); return createCorrectVariant("Unknown error " + e.getMessage(), headers, Response.Status.INTERNAL_SERVER_ERROR); } }
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(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("Get server templates failed due to {}", e.getMessage(), e);