Search in sources :

Example 1 with CallContainerCommand

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

the class RuleServicesClientImpl method executeCommandsWithResults.

@Override
public ServiceResponse<ExecutionResults> executeCommandsWithResults(String id, Command<?> cmd, Status status) {
    if (config.isRest()) {
        return makeHttpPostRequestAndCreateServiceResponse(loadBalancer.getUrl() + "/containers/instances/" + id, cmd, (Class) ExecutionResultImpl.class, getHeaders(cmd), status);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new CallContainerCommand(id, serialize(cmd))));
        ServiceResponse response = executeJmsCommand(script, cmd.getClass().getName(), null, id).getResponses().get(0);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        if (response.getResult() instanceof String) {
            response.setResult(deserialize((String) response.getResult(), (Class) ExecutionResultImpl.class));
        }
        return response;
    }
}
Also used : CallContainerCommand(org.kie.server.api.commands.CallContainerCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) CommandScript(org.kie.server.api.commands.CommandScript)

Example 2 with CallContainerCommand

use of org.kie.server.api.commands.CallContainerCommand 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 CallContainerCommand

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

the class KieServicesClientImpl method executeCommands.

/**
 * This method is deprecated on KieServicesClient as it was moved to RuleServicesClient
 *
 * @see RuleServicesClient#executeCommands(String, Command)
 * @deprecated
 */
@Deprecated
@Override
public ServiceResponse<String> executeCommands(String id, Command<?> cmd, Status status) {
    if (config.isRest()) {
        return makeBackwardCompatibleHttpPostRequestAndCreateServiceResponse(loadBalancer.getUrl() + "/containers/instances/" + id, cmd, String.class, getHeaders(cmd), status);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new CallContainerCommand(id, serialize(cmd))));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, cmd.getClass().getName(), null, id).getResponses().get(0);
        return getResponseOrNullIfNoResponse(response);
    }
}
Also used : CallContainerCommand(org.kie.server.api.commands.CallContainerCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) CommandScript(org.kie.server.api.commands.CommandScript)

Example 4 with CallContainerCommand

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

the class KieServicesClientImpl method executeCommands.

// for backward compatibility reason
/**
 * This method is deprecated on KieServicesClient as it was moved to RuleServicesClient
 *
 * @see RuleServicesClient#executeCommands(String, String)
 * @deprecated
 */
@Deprecated
@Override
public ServiceResponse<String> executeCommands(String id, String payload) {
    if (config.isRest()) {
        return makeBackwardCompatibleHttpPostRequestAndCreateServiceResponse(loadBalancer.getUrl() + "/containers/instances/" + id, payload, String.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new CallContainerCommand(id, payload)));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, null, null, id).getResponses().get(0);
        return getResponseOrNullIfNoResponse(response);
    }
}
Also used : CallContainerCommand(org.kie.server.api.commands.CallContainerCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) CommandScript(org.kie.server.api.commands.CommandScript)

Example 5 with CallContainerCommand

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

the class KieServerDroolsIntegrationTest method testCommandScript.

@Test
@Category(Smoke.class)
public void testCommandScript() throws Exception {
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<Class<?>>(extraClasses.values()), configuration.getMarshallingFormat(), kjarClassLoader);
    Object message = createInstance(MESSAGE_CLASS_NAME);
    KieServerReflections.setValue(message, MESSAGE_TEXT_FIELD, MESSAGE_REQUEST);
    Command<?> insert = commandsFactory.newInsert(message, MESSAGE_OUT_IDENTIFIER);
    Command<?> fire = commandsFactory.newFireAllRules();
    BatchExecutionCommand batch = commandsFactory.newBatchExecution(Arrays.<Command<?>>asList(insert, fire), KIE_SESSION);
    String payload = marshaller.marshall(batch);
    String containerId = "command-script-container";
    KieServerCommand create = new CreateContainerCommand(new KieContainerResource(containerId, releaseIdScript, null));
    KieServerCommand call = new CallContainerCommand(containerId, payload);
    KieServerCommand dispose = new DisposeContainerCommand(containerId);
    List<KieServerCommand> cmds = Arrays.asList(create, call, dispose);
    CommandScript script = new CommandScript(cmds);
    ServiceResponsesList reply = client.executeScript(script);
    for (ServiceResponse<? extends Object> r : reply.getResponses()) {
        Assert.assertEquals(ServiceResponse.ResponseType.SUCCESS, r.getType());
    }
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) Marshaller(org.kie.server.api.marshalling.Marshaller) CallContainerCommand(org.kie.server.api.commands.CallContainerCommand) KieServerCommand(org.kie.server.api.model.KieServerCommand) CommandScript(org.kie.server.api.commands.CommandScript) DisposeContainerCommand(org.kie.server.api.commands.DisposeContainerCommand) CreateContainerCommand(org.kie.server.api.commands.CreateContainerCommand) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BeforeClass(org.junit.BeforeClass) KieContainerResource(org.kie.server.api.model.KieContainerResource) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

CallContainerCommand (org.kie.server.api.commands.CallContainerCommand)6 KieServerCommand (org.kie.server.api.model.KieServerCommand)6 CommandScript (org.kie.server.api.commands.CommandScript)5 ServiceResponse (org.kie.server.api.model.ServiceResponse)5 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)2 CreateContainerCommand (org.kie.server.api.commands.CreateContainerCommand)2 DisposeContainerCommand (org.kie.server.api.commands.DisposeContainerCommand)2 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)2 ArrayList (java.util.ArrayList)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 Category (org.junit.experimental.categories.Category)1 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)1 ActivateContainerCommand (org.kie.server.api.commands.ActivateContainerCommand)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