@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); } }
@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); } }
@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); } }
@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); } }
@Test public void testOnSelectedContainerSpec() { final ContainerPresenter.View containerView = mock( ContainerPresenter.View.class ); when( containerPresenter.getView() ).thenReturn( containerView ); presenter.onSelected( new ContainerSpecSelected( new ContainerSpecKey() ) ); verify( view ).setContent( containerView ); }
@Test public void testRefresh() { final ContainerSpecKey containerSpecKey = new ContainerSpecKey( "id", "name", new ServerTemplateKey() ); presenter.setup( containerSpecKey ); presenter.refresh(); final ArgumentCaptor<RefreshRemoteServers> refreshRemoteServersCaptor = ArgumentCaptor.forClass( RefreshRemoteServers.class ); verify( refreshRemoteServersEvent ).fire( refreshRemoteServersCaptor.capture() ); assertEquals( containerSpecKey, refreshRemoteServersCaptor.getValue().getContainerSpecKey() ); }
private ContainerSpecKey buildContainerSpecKey( final Container container ) { return new ContainerSpecKey( container.getContainerSpecId(), container.getContainerName(), new ServerTemplateKey( container.getServerInstanceKey().getServerTemplateId(), "" ) ); } }
@Test //Test fix for GUVNOR-3579 public void testLoadWhenRuntimeManagementServiceReturnsInvalidData() { ContainerSpecData badData = new ContainerSpecData(null, null); when(runtimeManagementService.getContainersByContainerSpec(anyObject(), anyObject())).thenReturn(badData); ContainerSpecKey lookupKey = new ContainerSpecKey("dummyId", "dummyName", new ServerTemplateKey("keyId", "keyName")); presenter.load(lookupKey); // Doesn't throw NPE when ContainerSpecData contain nulls verify(view, never()).setContainerName(anyString()); }
@Test public void testOnConfigUpdateNoUpdate() { final RuleConfigUpdated ruleConfigUpdated = new RuleConfigUpdated(); ruleConfigUpdated.setContainerSpecKey(new ContainerSpecKey()); ruleConfigUpdated.setRuleConfig(new RuleConfig()); presenter.setup(containerSpec, ruleConfig); presenter.onConfigUpdate(ruleConfigUpdated); verify(view).setContent(anyString(), anyString(), any(State.class), any(State.class), any(State.class), any(State.class)); }
@Test public void testSetup() { final ContainerSpecKey containerSpecKey = new ContainerSpecKey( "id", "container-name", new ServerTemplateKey( "template-id", "template-name" ) ); final ProcessConfig processConfig = new ProcessConfig( RuntimeStrategy.PER_REQUEST.toString(), "kbase", "ksession", MergeMode.KEEP_ALL.toString() ); presenter.setup( containerSpecKey, processConfig ); verify( view ).enableActions(); verify( processConfigPresenter ).setup( containerSpecKey, processConfig ); verify( processConfigPresenter ).setProcessConfig( processConfig ); }
linkTitlePresenter.onSelect(); final ContainerSpecKey containerSpecKey = new ContainerSpecKey( container.getContainerSpecId(), container.getContainerName(), new ServerTemplateKey( container.getServerInstanceKey().getServerTemplateId(), "" ) );
@Test public void testOnContainerSelect() { final ServerTemplateKey serverTemplateKey = new ServerTemplateKey( "ServerTemplateKeyId", "ServerTemplateKeyName" ); final ContainerSpecKey containerSpecKey = new ContainerSpecKey( "containerId", "containerName", serverTemplateKey ); presenter.onContainerSelect( new ContainerSpecSelected( containerSpecKey ) ); verify( view ).selectContainer( serverTemplateKey.getId(), containerSpecKey.getId() ); }
@Test public void testStartScanner() { final ContainerSpecKey containerSpecKey = new ContainerSpecKey("id", "name", new ServerTemplateKey("serverTemplateId", "stname")); KieServerControllerDescriptorCommand command = new KieServerControllerDescriptorCommand(RuleCapabilitiesService.class.getName(), "startScanner", null, null, containerSpecKey, new Long(1)); final String content = WebSocketUtils.marshal(command); LOGGER.debug("JSON content\n{}", content); KieServerControllerServiceResponse response = service.executeCommand(WebSocketUtils.unmarshal(content, KieServerControllerDescriptorCommand.class)); assertNotNull(response); assertEquals(FAILURE, response.getType()); assertEquals("No server template found for id serverTemplateId", response.getMsg()); assertNull(response.getResult()); } }
@Test public void testCommandUpgradeContainer() { final ContainerSpecKey serverTemplate = new ContainerSpecKey("id", "name", new ServerTemplateKey("stid", "stname")); final ReleaseId releaseId = new ReleaseId("group", "artifact", "version"); KieServerControllerDescriptorCommand command = new KieServerControllerDescriptorCommand(RuleCapabilitiesService.class.getName(), "upgradeContainer", serverTemplate, releaseId); final String content = WebSocketUtils.marshal(command); LOGGER.debug("JSON content\n{}", content); KieServerControllerServiceResponse response = service.executeCommand(WebSocketUtils.unmarshal(content, KieServerControllerDescriptorCommand.class)); assertNotNull(response); assertEquals(FAILURE, response.getType()); assertEquals("No server template found for id stid", response.getMsg()); assertNull(response.getResult()); }
@Test public void testSetup() { final ContainerSpecKey containerSpecKey = new ContainerSpecKey(); final ProcessConfig processConfig = new ProcessConfig( ClientRuntimeStrategy.PER_CASE.toString(), "kBase", "kSession", ClientMergeMode.KEEP_ALL.toString() ); presenter.setup( containerSpecKey, processConfig ); verify( view ).setContent( ClientRuntimeStrategy.PER_CASE.getValue( translationService ), processConfig.getKBase(), processConfig.getKSession(), ClientMergeMode.convert( processConfig.getMergeMode(), translationService ).getValue( translationService ) ); assertEquals( containerSpecKey, presenter.getContainerSpecKey() ); assertEquals( processConfig, presenter.getProcessConfig() ); presenter.clear(); assertNull( presenter.getContainerSpecKey() ); assertNull( presenter.getProcessConfig() ); }