Search in sources :

Example 26 with ServiceResponsesList

use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.

the class KieServerResource method executeCommands.

@ApiOperation(value = "Executes one or more KIE Server commands for server-related or container-related operations")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = ServiceResponsesList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = EXECUTE_CMD_RESPONSE_JSON) })) })
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response executeCommands(@Context HttpHeaders headers, @ApiParam(value = "command script payload", required = true, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = EXECUTE_CMD_JSON) })) String commandScriptPayload) {
    String contentType = getContentType(headers);
    CommandScript command = marshallerHelper.unmarshal(commandScriptPayload, contentType, CommandScript.class);
    ServiceResponsesList result = delegate.executeScript(command, MarshallerHelper.getFormat(contentType), null);
    return createCorrectVariant(result, headers);
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) CommandScript(org.kie.server.api.commands.CommandScript) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 27 with ServiceResponsesList

use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method activateContainer.

@Override
public ServiceResponse<KieContainerResource> activateContainer(String id) {
    CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new ActivateContainerCommand(id)));
    ServiceResponse<KieContainerResource> response = (ServiceResponse<KieContainerResource>) 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) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) ActivateContainerCommand(org.kie.server.api.commands.ActivateContainerCommand) CommandScript(org.kie.server.api.commands.CommandScript) KieContainerResource(org.kie.server.api.model.KieContainerResource)

Example 28 with ServiceResponsesList

use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method createContainer.

@Override
public ServiceResponse<KieContainerResource> createContainer(String id, KieContainerResource resource) {
    CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new CreateContainerCommand(resource)));
    ServiceResponse<KieContainerResource> response = (ServiceResponse<KieContainerResource>) 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) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) CreateContainerCommand(org.kie.server.api.commands.CreateContainerCommand) CommandScript(org.kie.server.api.commands.CommandScript) KieContainerResource(org.kie.server.api.model.KieContainerResource)

Example 29 with ServiceResponsesList

use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method getScannerInfo.

@Override
public ServiceResponse<KieScannerResource> getScannerInfo(String id) {
    CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new GetScannerInfoCommand(id)));
    ServiceResponse<KieScannerResource> response = (ServiceResponse<KieScannerResource>) sendCommand(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) KieScannerResource(org.kie.server.api.model.KieScannerResource) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) CommandScript(org.kie.server.api.commands.CommandScript) GetScannerInfoCommand(org.kie.server.api.commands.GetScannerInfoCommand)

Example 30 with ServiceResponsesList

use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.

the class CaseKieContainerCommandServiceImpl method executeScript.

@Override
public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {
    List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>();
    for (KieServerCommand command : commands.getCommands()) {
        if (!(command instanceof DescriptorCommand)) {
            logger.warn("Unsupported command '{}' given, will not process it", command.getClass().getName());
            continue;
        }
        try {
            Object result = null;
            Object handler = null;
            DescriptorCommand descriptorCommand = (DescriptorCommand) command;
            // find out the handler to call to process given command
            if ("CaseService".equals(descriptorCommand.getService())) {
                handler = caseManagementServiceBase;
            } else if ("CaseQueryService".equals(descriptorCommand.getService())) {
                handler = caseManagementRuntimeDataService;
            } else if ("CaseAdminService".equals(descriptorCommand.getService())) {
                handler = caseAdminServiceBase;
            } else {
                throw new IllegalStateException("Unable to find handler for " + descriptorCommand.getService() + " service");
            }
            List<Object> arguments = new ArrayList();
            // process and unwrap arguments
            for (Object arg : descriptorCommand.getArguments()) {
                logger.debug("Before :: Argument with type {} and value {}", arg.getClass(), arg);
                if (arg instanceof Wrapped) {
                    arg = ((Wrapped) arg).unwrap();
                }
                logger.debug("After :: Argument with type {} and value {}", arg.getClass(), arg);
                arguments.add(arg);
            }
            if (descriptorCommand.getPayload() != null && !descriptorCommand.getPayload().isEmpty()) {
                arguments.add(descriptorCommand.getPayload());
            }
            if (descriptorCommand.getMarshallerFormat() != null && !descriptorCommand.getMarshallerFormat().isEmpty()) {
                arguments.add(descriptorCommand.getMarshallerFormat());
            }
            logger.debug("About to execute {} operation on {} with args {}", descriptorCommand.getMethod(), handler, arguments);
            // process command via reflection and handler
            result = MethodUtils.invokeMethod(handler, descriptorCommand.getMethod(), arguments.toArray());
            logger.debug("Handler {} returned response {}", handler, result);
            // return successful result
            responses.add(new ServiceResponse(ServiceResponse.ResponseType.SUCCESS, "", result));
        } catch (InvocationTargetException e) {
            responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getTargetException().getMessage()));
        } catch (Throwable e) {
            logger.error("Error while processing {} command", command, e);
            // return failure result
            responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getMessage()));
        }
    }
    logger.debug("About to return responses '{}'", responses);
    return new ServiceResponsesList(responses);
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) Wrapped(org.kie.server.api.model.Wrapped) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)30 ServiceResponse (org.kie.server.api.model.ServiceResponse)23 KieServerCommand (org.kie.server.api.model.KieServerCommand)18 CommandScript (org.kie.server.api.commands.CommandScript)17 WebSocketServiceResponse (org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse)13 ArrayList (java.util.ArrayList)9 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)5 KieContainerResource (org.kie.server.api.model.KieContainerResource)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 JMSException (javax.jms.JMSException)4 CreateContainerCommand (org.kie.server.api.commands.CreateContainerCommand)4 DisposeContainerCommand (org.kie.server.api.commands.DisposeContainerCommand)4 Wrapped (org.kie.server.api.model.Wrapped)4 TextMessage (javax.jms.TextMessage)3 Test (org.junit.Test)3 UpdateReleaseIdCommand (org.kie.server.api.commands.UpdateReleaseIdCommand)3 UpdateScannerCommand (org.kie.server.api.commands.UpdateScannerCommand)3 KieServicesException (org.kie.server.api.exception.KieServicesException)3 ReleaseId (org.kie.server.api.model.ReleaseId)3 IOException (java.io.IOException)2