private static DisposeContainerCommand createDisposeContainerCommand() { return new DisposeContainerCommand("some-container-id"); }
public ServiceResponsesList executeScript(CommandScript commands) { List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>(); if( commands != null ) { for (KieServerCommand command : commands.getCommands()) { if (command instanceof CreateContainerCommand) { responses.add(createContainer(((CreateContainerCommand) command).getContainer().getContainerId(), ((CreateContainerCommand) command).getContainer())); } else if (command instanceof GetServerInfoCommand) { responses.add(getInfo()); } else if (command instanceof ListContainersCommand) { responses.add(listContainers()); } else if (command instanceof CallContainerCommand) { responses.add(callContainer(((CallContainerCommand) command).getContainerId(), ((CallContainerCommand) command).getPayload())); } else if (command instanceof DisposeContainerCommand) { responses.add(disposeContainer(((DisposeContainerCommand) command).getContainerId())); } else if (command instanceof GetContainerInfoCommand ) { responses.add(getContainerInfo(((GetContainerInfoCommand) command).getContainerId())); } else if (command instanceof GetScannerInfoCommand ) { responses.add(getScannerInfo(((GetScannerInfoCommand) command).getContainerId())); } else if (command instanceof UpdateScannerCommand ) { responses.add(updateScanner(((UpdateScannerCommand) command).getContainerId(), ((UpdateScannerCommand) command).getScanner())); } else if (command instanceof UpdateReleaseIdCommand ) { responses.add(updateContainerReleaseId(((UpdateReleaseIdCommand) command).getContainerId(), ((UpdateReleaseIdCommand) command).getReleaseId())); } } } return new ServiceResponsesList(responses); }
@Override public ServiceResponse<KieContainerResourceList> listContainers() { if( config.isRest() ) { return makeHttpGetRequestAndCreateServiceResponse( baseURI + "/containers", KieContainerResourceList.class ); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new ListContainersCommand() ) ); return (ServiceResponse<KieContainerResourceList>) executeJmsCommand( script ).getResponses().get( 0 ); } }
@Override public void claimTask(String containerId, Long taskId, String userId) { if( config.isRest() ) { sendTaskOperation(containerId, taskId, TASK_URI + "/" + TASK_INSTANCE_CLAIM_PUT_URI, getUserQueryStr(userId)); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "UserTaskService", "claim", new Object[]{containerId, taskId, userId}) ) ); ServiceResponse<Object> response = (ServiceResponse<Object>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); } }
@Override public ServiceResponse<Void> disposeContainer(String id) { if( config.isRest() ) { return makeHttpDeleteRequestAndCreateServiceResponse( baseURI + "/containers/" + id, Void.class ); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DisposeContainerCommand( id ) ) ); return (ServiceResponse<Void>) executeJmsCommand( script ).getResponses().get( 0 ); } }
@Override public ServiceResponse<KieScannerResource> updateScanner(String id, KieScannerResource resource) { if( config.isRest() ) { return makeHttpPostRequestAndCreateServiceResponse( baseURI + "/containers/" + id + "/scanner", resource, KieScannerResource.class ); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new UpdateScannerCommand( id, resource ) ) ); return (ServiceResponse<KieScannerResource>) executeJmsCommand( script ).getResponses().get( 0 ); } }
@Override public ServiceResponse<KieContainerResource> getContainerInfo(String id) { if( config.isRest() ) { return makeHttpGetRequestAndCreateServiceResponse( baseURI + "/containers/" + id, KieContainerResource.class ); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new GetContainerInfoCommand( id ) ) ); return (ServiceResponse<KieContainerResource>) executeJmsCommand( script ).getResponses().get( 0 ); } }
@Override public ServiceResponse<ReleaseId> updateReleaseId(String id, ReleaseId releaseId) { if( config.isRest() ) { return makeHttpPostRequestAndCreateServiceResponse( baseURI + "/containers/" + id + "/release-id", releaseId, ReleaseId.class ); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new UpdateReleaseIdCommand( id, releaseId ) ) ); return (ServiceResponse<ReleaseId>) executeJmsCommand( script ).getResponses().get( 0 ); } }
@Override public ServiceResponse<KieServerInfo> getServerInfo() { if( config.isRest() ) { return makeHttpGetRequestAndCreateServiceResponse( baseURI, KieServerInfo.class ); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new GetServerInfoCommand() ) ); return (ServiceResponse<KieServerInfo>) executeJmsCommand( script ).getResponses().get( 0 ); } }
@Override public ServiceResponse<KieContainerResource> createContainer(String id, KieContainerResource resource) { if( config.isRest() ) { return makeHttpPutRequestAndCreateServiceResponse( baseURI + "/containers/" + id, resource, KieContainerResource.class ); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new CreateContainerCommand( resource ) ) ); return (ServiceResponse<KieContainerResource>) executeJmsCommand( script ).getResponses().get( 0 ); } }
@Override public ServiceResponse<KieScannerResource> getScannerInfo(String id) { if( config.isRest() ) { return makeHttpGetRequestAndCreateServiceResponse( baseURI + "/containers/" + id + "/scanner", KieScannerResource.class ); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new GetScannerInfoCommand( id ) ) ); return (ServiceResponse<KieScannerResource>) executeJmsCommand( script ).getResponses().get( 0 ); } }
@Override public ServiceResponse<String> executeCommands(String id, String payload) { if( config.isRest() ) { return makeHttpPostRequestAndCreateServiceResponse( baseURI + "/containers/" + id, payload, String.class ); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new CallContainerCommand( id, payload ) ) ); return (ServiceResponse<String>) executeJmsCommand( script ).getResponses().get( 0 ); } }
@Override public ServiceResponse<KieContainerResource> deactivateContainer(String id) { CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DeactivateContainerCommand(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; }
@Override public ServiceResponse<ReleaseId> getReleaseId(String containerId) { if (config.isRest()) { return makeHttpGetRequestAndCreateServiceResponse(loadBalancer.getUrl() + "/containers/" + containerId + "/release-id", ReleaseId.class); } else { CommandScript script = new CommandScript(Collections.singletonList(new GetReleaseIdCommand(containerId))); ServiceResponse<ReleaseId> response = (ServiceResponse<ReleaseId>) executeJmsCommand(script).getResponses().get(0); return getResponseOrNullIfNoResponse(response); } }
private static ListContainersCommand createListContainersCommand() { return new ListContainersCommand(createKieContainerResourceFilter()); }
@Override public void resumeTask(String containerId, Long taskId, String userId) { if( config.isRest() ) { sendTaskOperation(containerId, taskId, TASK_URI + "/" + TASK_INSTANCE_RESUME_PUT_URI, getUserQueryStr(userId)); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "UserTaskService", "resume", new Object[]{containerId, taskId, userId}) ) ); ServiceResponse<Object> response = (ServiceResponse<Object>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); } }
@Override public ServiceResponse<Void> disposeContainer(String id) { if( config.isRest() ) { return makeHttpDeleteRequestAndCreateServiceResponse( loadBalancer.getUrl() + "/containers/" + id, Void.class ); } else { CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DisposeContainerCommand(id))); ServiceResponse<Void> response = (ServiceResponse<Void>) executeJmsCommand(script, null, null, id).getResponses().get(0); return getResponseOrNullIfNoResponse(response); } }
@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); } }
@Override public void releaseTask(String containerId, Long taskId, String userId) { if( config.isRest() ) { sendTaskOperation(containerId, taskId, TASK_URI + "/" + TASK_INSTANCE_RELEASE_PUT_URI, getUserQueryStr(userId)); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "UserTaskService", "release", new Object[]{containerId, taskId, userId}) ) ); ServiceResponse<TaskOutputsDefinition> response = (ServiceResponse<TaskOutputsDefinition>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); } }
@Override public void startTask(String containerId, Long taskId, String userId) { if( config.isRest() ) { sendTaskOperation(containerId, taskId, TASK_URI + "/" + TASK_INSTANCE_START_PUT_URI, getUserQueryStr(userId)); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "UserTaskService", "start", new Object[]{containerId, taskId, userId}) ) ); ServiceResponse<Object> response = (ServiceResponse<Object>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); } }