use of org.kie.server.api.commands.DisposeContainerCommand 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);
}
}
use of org.kie.server.api.commands.DisposeContainerCommand 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);
}
use of org.kie.server.api.commands.DisposeContainerCommand in project droolsjbpm-integration by kiegroup.
the class KieServicesClientImpl method disposeContainer.
@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);
}
}
use of org.kie.server.api.commands.DisposeContainerCommand in project droolsjbpm-integration by kiegroup.
the class WebSocketKieServerClient method disposeContainer.
@Override
public ServiceResponse<Void> disposeContainer(String id) {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DisposeContainerCommand(id)));
ServiceResponse<Void> response = (ServiceResponse<Void>) sendCommandToAllSessions(script, new WebSocketServiceResponse(true, (message) -> {
ServiceResponsesList list = WebSocketUtils.unmarshal(message, ServiceResponsesList.class);
return list.getResponses().get(0);
})).getResponses().get(0);
return response;
}
use of org.kie.server.api.commands.DisposeContainerCommand 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());
}
}
Aggregations