Search in sources :

Example 1 with UpdateScannerCommand

use of org.kie.server.api.commands.UpdateScannerCommand in project droolsjbpm-integration by kiegroup.

the class AbstractKieServerImplTest method testManagementDisabledConfiguredViaCommandService.

@Test
public void testManagementDisabledConfiguredViaCommandService() {
    System.setProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED, "true");
    try {
        kieServer.destroy();
        kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR));
        kieServer.init();
        KieContainerCommandServiceImpl commandService = new KieContainerCommandServiceImpl(kieServer, kieServer.getServerRegistry());
        List<KieServerCommand> commands = new ArrayList<>();
        commands.add(new CreateContainerCommand());
        commands.add(new DisposeContainerCommand());
        commands.add(new UpdateScannerCommand());
        commands.add(new UpdateReleaseIdCommand());
        CommandScript commandScript = new CommandScript(commands);
        ServiceResponsesList responseList = commandService.executeScript(commandScript, MarshallingFormat.JAXB, null);
        assertNotNull(responseList);
        List<ServiceResponse<?>> responses = responseList.getResponses();
        assertEquals(4, responses.size());
        for (ServiceResponse<?> forbidden : responses) {
            assertForbiddenResponse(forbidden);
        }
    } finally {
        System.clearProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED);
    }
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) KieServerCommand(org.kie.server.api.model.KieServerCommand) ArrayList(java.util.ArrayList) CommandScript(org.kie.server.api.commands.CommandScript) DisposeContainerCommand(org.kie.server.api.commands.DisposeContainerCommand) UpdateReleaseIdCommand(org.kie.server.api.commands.UpdateReleaseIdCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServiceResponse(org.kie.server.api.model.KieServiceResponse) UpdateScannerCommand(org.kie.server.api.commands.UpdateScannerCommand) CreateContainerCommand(org.kie.server.api.commands.CreateContainerCommand) Test(org.junit.Test)

Example 2 with UpdateScannerCommand

use of org.kie.server.api.commands.UpdateScannerCommand in project droolsjbpm-integration by kiegroup.

the class KieContainerCommandServiceImpl method executeScript.

@Override
public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {
    List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>();
    if (commands != null) {
        for (KieServerCommand command : commands.getCommands()) {
            if (command instanceof CreateContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.createContainer(((CreateContainerCommand) command).getContainer().getContainerId(), ((CreateContainerCommand) command).getContainer()));
            } else if (command instanceof GetServerInfoCommand) {
                responses.add(this.kieServer.getInfo());
            } else if (command instanceof ListContainersCommand) {
                responses.add(this.kieServer.listContainers(((ListContainersCommand) command).getKieContainerResourceFilter()));
            } else if (command instanceof CallContainerCommand) {
                ServiceResponse response = callContainer(((CallContainerCommand) command).getContainerId(), ((CallContainerCommand) command).getPayload(), marshallingFormat, classType, true);
                responses.add(response);
            } else if (command instanceof DisposeContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.disposeContainer(((DisposeContainerCommand) command).getContainerId()));
            } else if (command instanceof GetContainerInfoCommand) {
                responses.add(this.kieServer.getContainerInfo(((GetContainerInfoCommand) command).getContainerId()));
            } else if (command instanceof GetScannerInfoCommand) {
                responses.add(this.kieServer.getScannerInfo(((GetScannerInfoCommand) command).getContainerId()));
            } else if (command instanceof UpdateScannerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.updateScanner(((UpdateScannerCommand) command).getContainerId(), ((UpdateScannerCommand) command).getScanner()));
            } else if (command instanceof GetReleaseIdCommand) {
                responses.add(this.kieServer.getContainerReleaseId(((GetReleaseIdCommand) command).getContainerId()));
            } else if (command instanceof UpdateReleaseIdCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.updateContainerReleaseId(((UpdateReleaseIdCommand) command).getContainerId(), ((UpdateReleaseIdCommand) command).getReleaseId(), ((UpdateReleaseIdCommand) command).isResetBeforeUpdate()));
            } else if (command instanceof GetServerStateCommand) {
                responses.add(this.kieServer.getServerState());
            } else if (command instanceof ActivateContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.activateContainer(((ActivateContainerCommand) command).getContainerId()));
            } else if (command instanceof DeactivateContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.deactivateContainer(((DeactivateContainerCommand) command).getContainerId()));
            }
        }
    }
    return new ServiceResponsesList(responses);
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) CallContainerCommand(org.kie.server.api.commands.CallContainerCommand) KieServerCommand(org.kie.server.api.model.KieServerCommand) ActivateContainerCommand(org.kie.server.api.commands.ActivateContainerCommand) ArrayList(java.util.ArrayList) DisposeContainerCommand(org.kie.server.api.commands.DisposeContainerCommand) DeactivateContainerCommand(org.kie.server.api.commands.DeactivateContainerCommand) GetContainerInfoCommand(org.kie.server.api.commands.GetContainerInfoCommand) GetReleaseIdCommand(org.kie.server.api.commands.GetReleaseIdCommand) UpdateReleaseIdCommand(org.kie.server.api.commands.UpdateReleaseIdCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) ListContainersCommand(org.kie.server.api.commands.ListContainersCommand) GetServerStateCommand(org.kie.server.api.commands.GetServerStateCommand) UpdateScannerCommand(org.kie.server.api.commands.UpdateScannerCommand) CreateContainerCommand(org.kie.server.api.commands.CreateContainerCommand) GetServerInfoCommand(org.kie.server.api.commands.GetServerInfoCommand) GetScannerInfoCommand(org.kie.server.api.commands.GetScannerInfoCommand)

Example 3 with UpdateScannerCommand

use of org.kie.server.api.commands.UpdateScannerCommand in project droolsjbpm-integration by kiegroup.

the class KieServicesClientImpl method updateScanner.

@Override
public ServiceResponse<KieScannerResource> updateScanner(String id, KieScannerResource resource) {
    if (config.isRest()) {
        return makeHttpPostRequestAndCreateServiceResponse(loadBalancer.getUrl() + "/containers/" + id + "/scanner", resource, KieScannerResource.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new UpdateScannerCommand(id, resource)));
        ServiceResponse<KieScannerResource> response = (ServiceResponse<KieScannerResource>) executeJmsCommand(script, null, null, id).getResponses().get(0);
        return getResponseOrNullIfNoResponse(response);
    }
}
Also used : ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) UpdateScannerCommand(org.kie.server.api.commands.UpdateScannerCommand) KieScannerResource(org.kie.server.api.model.KieScannerResource) CommandScript(org.kie.server.api.commands.CommandScript)

Example 4 with UpdateScannerCommand

use of org.kie.server.api.commands.UpdateScannerCommand in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method updateScanner.

@Override
public ServiceResponse<KieScannerResource> updateScanner(String id, KieScannerResource resource) {
    CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new UpdateScannerCommand(id, resource)));
    ServiceResponse<KieScannerResource> response = (ServiceResponse<KieScannerResource>) sendCommandToAllSessions(script, new WebSocketServiceResponse(true, (message) -> {
        ServiceResponsesList list = WebSocketUtils.unmarshal(message, ServiceResponsesList.class);
        return list.getResponses().get(0);
    })).getResponses().get(0);
    return response;
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) UpdateScannerCommand(org.kie.server.api.commands.UpdateScannerCommand) KieScannerResource(org.kie.server.api.model.KieScannerResource) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) CommandScript(org.kie.server.api.commands.CommandScript)

Aggregations

UpdateScannerCommand (org.kie.server.api.commands.UpdateScannerCommand)4 KieServerCommand (org.kie.server.api.model.KieServerCommand)4 ServiceResponse (org.kie.server.api.model.ServiceResponse)4 CommandScript (org.kie.server.api.commands.CommandScript)3 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)3 ArrayList (java.util.ArrayList)2 CreateContainerCommand (org.kie.server.api.commands.CreateContainerCommand)2 DisposeContainerCommand (org.kie.server.api.commands.DisposeContainerCommand)2 UpdateReleaseIdCommand (org.kie.server.api.commands.UpdateReleaseIdCommand)2 KieScannerResource (org.kie.server.api.model.KieScannerResource)2 Test (org.junit.Test)1 ActivateContainerCommand (org.kie.server.api.commands.ActivateContainerCommand)1 CallContainerCommand (org.kie.server.api.commands.CallContainerCommand)1 DeactivateContainerCommand (org.kie.server.api.commands.DeactivateContainerCommand)1 GetContainerInfoCommand (org.kie.server.api.commands.GetContainerInfoCommand)1 GetReleaseIdCommand (org.kie.server.api.commands.GetReleaseIdCommand)1 GetScannerInfoCommand (org.kie.server.api.commands.GetScannerInfoCommand)1 GetServerInfoCommand (org.kie.server.api.commands.GetServerInfoCommand)1 GetServerStateCommand (org.kie.server.api.commands.GetServerStateCommand)1 ListContainersCommand (org.kie.server.api.commands.ListContainersCommand)1