use of org.kie.server.services.impl.KieServerImpl in project droolsjbpm-integration by kiegroup.
the class TaskAssigningPlanningKieServerExtension method prepareContainer.
private KieContainerInstanceImpl prepareContainer(KieContainerResource resource) {
KieContainerInstanceImpl container = registry.getContainer(resource.getContainerId());
if (container == null) {
LOGGER.debug("Container {} is not available in current server. It'll be created now.", resource.getContainerId());
try {
ServiceResponse<KieContainerResource> response = kieServer.createContainer(resource.getContainerId(), resource);
if (response.getType() == KieServiceResponse.ResponseType.FAILURE) {
String msg = String.format(CREATE_CONTAINER_ERROR, resource.getContainerId(), response.getMsg());
LOGGER.error(msg);
registerMessage(Severity.ERROR, msg);
return null;
}
container = registry.getContainer(resource.getContainerId());
if (container == null) {
final String msg = String.format(CONTAINER_NOT_ACCESSIBLE_ERROR, resource.getContainerId());
LOGGER.error(msg);
registerMessage(Severity.ERROR, msg);
return null;
}
} catch (Exception e) {
String msg = String.format(CREATE_CONTAINER_ERROR, resource.getContainerId(), e.getMessage());
LOGGER.error(msg, e);
registerMessage(Severity.ERROR, msg);
return null;
}
}
if (container.getStatus() == KieContainerStatus.DEACTIVATED) {
LOGGER.debug("Container {} is currently {}. It needs to be activated.", resource.getContainerId(), container.getStatus());
try {
ServiceResponse<KieContainerResource> response = ((KieServerImpl) kieServer).activateContainer(resource.getContainerId());
if (response.getType() == KieServiceResponse.ResponseType.FAILURE) {
String msg = String.format(ACTIVATE_CONTAINER_ERROR, resource.getContainerId(), response.getMsg());
LOGGER.error(msg);
registerMessage(Severity.ERROR, msg);
return null;
}
} catch (Exception e) {
String msg = String.format(ACTIVATE_CONTAINER_ERROR, resource.getContainerId(), e.getMessage());
LOGGER.error(msg, e);
registerMessage(Severity.ERROR, msg);
return null;
}
}
if (container.getStatus() != KieContainerStatus.STARTED) {
String msg = String.format(EXTENSION_CONTAINER_NOT_IN_EXPECTED_STATUS_ERROR, resource.getContainerId(), KieContainerStatus.STARTED, container.getStatus());
LOGGER.error(msg);
registerMessage(Severity.ERROR, msg);
return null;
}
return container;
}
use of org.kie.server.services.impl.KieServerImpl in project droolsjbpm-integration by kiegroup.
the class KieServerExecutor method addServerSingletonResources.
private void addServerSingletonResources() {
kieServer = new KieServerImpl();
kieServer.init();
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.setApplication(new Application());
deployment.getResources().add(new KieServerRestImpl(kieServer));
List<KieServerExtension> extensions = kieServer.getServerExtensions();
for (KieServerExtension extension : extensions) {
List<Object> components = extension.getAppComponents(SupportedTransports.REST);
deployment.getResources().addAll(components);
}
server.deploy(deployment);
}
use of org.kie.server.services.impl.KieServerImpl in project droolsjbpm-integration by kiegroup.
the class KieServerTest method testCommandServiceSetup.
@Test
public void testCommandServiceSetup() {
List<String> extensionsWithoutCommandSupport = asList(PrometheusKieServerExtension.EXTENSION_NAME, ScenarioSimulationKieServerExtension.EXTENSION_NAME);
for (KieServerExtension extension : ((KieServerImpl) kieServer).getServerExtensions()) {
KieContainerCommandService<?> kieContainerCommandService = extension.getAppComponents(KieContainerCommandService.class);
String extensionName = extension.getExtensionName();
Objects.requireNonNull(extensionName, "extension.getExtensionName() should not be null");
if (extensionsWithoutCommandSupport.contains(extensionName)) {
assertNull(kieContainerCommandService);
} else {
assertNotNull(kieContainerCommandService);
}
}
}
use of org.kie.server.services.impl.KieServerImpl in project droolsjbpm-integration by kiegroup.
the class JbpmKieServerExtension method configureServices.
protected void configureServices(KieServerImpl kieServer, KieServerRegistry registry) {
KieServerConfig config = registry.getConfig();
// loaded from system property as callback info isn't stored as configuration in kie server repository
String callbackConfig = System.getProperty(KieServerConstants.CFG_HT_CALLBACK);
// if no other callback set, use Elytron or jaas by default
if (callbackConfig == null || callbackConfig.isEmpty()) {
if (ElytronIdentityProvider.available()) {
System.setProperty(KieServerConstants.CFG_HT_CALLBACK, "custom");
String name = ElytronUserGroupCallbackImpl.class.getName();
ElytronUserGroupCallbackImpl.addExternalUserGroupAdapter(new JMSUserGroupAdapter());
System.setProperty(KieServerConstants.CFG_HT_CALLBACK_CLASS, name);
} else {
System.setProperty(KieServerConstants.CFG_HT_CALLBACK, "jaas");
JAASUserGroupCallbackImpl.addExternalUserGroupAdapter(new JMSUserGroupAdapter());
}
}
this.isExecutorAvailable = isExecutorOnClasspath();
EntityManagerFactory emf = build(getPersistenceProperties(config));
EntityManagerFactoryManager.get().addEntityManagerFactory(persistenceUnitName, emf);
formManagerService = new FormManagerServiceImpl();
// build definition service
definitionService = new BPMN2DataServiceImpl();
// build deployment service
deploymentService = new KModuleDeploymentService();
((KModuleDeploymentService) deploymentService).setBpmn2Service(definitionService);
((KModuleDeploymentService) deploymentService).setEmf(emf);
((KModuleDeploymentService) deploymentService).setIdentityProvider(registry.getIdentityProvider());
((KModuleDeploymentService) deploymentService).setManagerFactory(new RuntimeManagerFactoryImpl());
((KModuleDeploymentService) deploymentService).setFormManagerService(formManagerService);
// configure user group callback
UserGroupCallback userGroupCallback = UserDataServiceProvider.getUserGroupCallback();
UserInfo userInfo = UserDataServiceProvider.getUserInfo();
TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).userGroupCallback(userGroupCallback).userInfo(userInfo).getTaskService();
// build runtime data service
runtimeDataService = new RuntimeDataServiceImpl();
((RuntimeDataServiceImpl) runtimeDataService).setCommandService(new TransactionalCommandService(emf));
((RuntimeDataServiceImpl) runtimeDataService).setIdentityProvider(registry.getIdentityProvider());
((RuntimeDataServiceImpl) runtimeDataService).setTaskService(taskService);
((RuntimeDataServiceImpl) runtimeDataService).setTaskAuditService(TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService());
((KModuleDeploymentService) deploymentService).setRuntimeDataService(runtimeDataService);
// build process service
processService = new ProcessServiceImpl();
((ProcessServiceImpl) processService).setDataService(runtimeDataService);
((ProcessServiceImpl) processService).setDeploymentService(deploymentService);
// build user task service
userTaskService = new UserTaskServiceImpl();
((UserTaskServiceImpl) userTaskService).setDataService(runtimeDataService);
((UserTaskServiceImpl) userTaskService).setDeploymentService(deploymentService);
// build query service
queryService = new QueryServiceImpl();
((QueryServiceImpl) queryService).setIdentityProvider(registry.getIdentityProvider());
((QueryServiceImpl) queryService).setCommandService(new TransactionalCommandService(emf));
Function<String, String> kieServerDataSourceResolver = input -> {
String dataSource = input;
Matcher matcher = PARAMETER_MATCHER.matcher(dataSource);
while (matcher.find()) {
String paramName = matcher.group(1);
KieServerConfig configuration = context.getStateRepository().load(KieServerEnvironment.getServerId()).getConfiguration();
dataSource = configuration.getConfigItemValue(paramName, "java:jboss/datasources/ExampleDS");
logger.info("Data source expression {} resolved to {}", input, dataSource);
}
return dataSource;
};
((QueryServiceImpl) queryService).setDataSourceResolver(kieServerDataSourceResolver);
((QueryServiceImpl) queryService).init();
// set runtime data service as listener on deployment service
((KModuleDeploymentService) deploymentService).addListener(((RuntimeDataServiceImpl) runtimeDataService));
((KModuleDeploymentService) deploymentService).addListener(((BPMN2DataServiceImpl) definitionService));
((KModuleDeploymentService) deploymentService).addListener(((QueryServiceImpl) queryService));
if (config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_DISABLED, "false").equalsIgnoreCase("false")) {
String executorQueueName = config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_JMS_QUEUE, "queue/KIE.SERVER.EXECUTOR");
// build executor service
executorService = ExecutorServiceFactory.newExecutorService(emf);
executorService.setInterval(Integer.parseInt(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_INTERVAL, "0")));
executorService.setRetries(Integer.parseInt(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_RETRIES, "3")));
executorService.setThreadPoolSize(Integer.parseInt(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_POOL, "1")));
executorService.setTimeunit(TimeUnit.valueOf(config.getConfigItemValue(KieServerConstants.CFG_EXECUTOR_TIME_UNIT, "SECONDS")));
((ExecutorImpl) ((ExecutorServiceImpl) executorService).getExecutor()).setQueueName(executorQueueName);
((KModuleDeploymentService) deploymentService).setExecutorService(executorService);
}
// admin services
this.processInstanceMigrationService = new ProcessInstanceMigrationServiceImpl();
this.processInstanceAdminService = new ProcessInstanceAdminServiceImpl();
((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setProcessService(processService);
((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setRuntimeDataService(runtimeDataService);
((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setCommandService(new TransactionalCommandService(emf));
((ProcessInstanceAdminServiceImpl) this.processInstanceAdminService).setIdentityProvider(registry.getIdentityProvider());
this.userTaskAdminService = new UserTaskAdminServiceImpl();
((UserTaskAdminServiceImpl) this.userTaskAdminService).setRuntimeDataService(runtimeDataService);
((UserTaskAdminServiceImpl) this.userTaskAdminService).setUserTaskService(userTaskService);
((UserTaskAdminServiceImpl) this.userTaskAdminService).setIdentityProvider(context.getIdentityProvider());
((UserTaskAdminServiceImpl) this.userTaskAdminService).setCommandService(new TransactionalCommandService(emf));
this.advanceRuntimeDataService = new AdvanceRuntimeDataServiceImpl();
((AdvanceRuntimeDataServiceImpl) this.advanceRuntimeDataService).setEmf(emf);
((AdvanceRuntimeDataServiceImpl) this.advanceRuntimeDataService).setCommandService(new TransactionalCommandService(emf));
this.kieContainerCommandService = new JBPMKieContainerCommandServiceImpl(context, deploymentService, new DefinitionServiceBase(definitionService, context), new ProcessServiceBase(processService, definitionService, runtimeDataService, context), new UserTaskServiceBase(userTaskService, context), new RuntimeDataServiceBase(runtimeDataService, advanceRuntimeDataService, context), new ExecutorServiceBase(executorService, context), new QueryDataServiceBase(queryService, context), new DocumentServiceBase(context), new ProcessAdminServiceBase(processInstanceMigrationService, processInstanceAdminService, runtimeDataService, context), new UserTaskAdminServiceBase(userTaskAdminService, context));
}
use of org.kie.server.services.impl.KieServerImpl in project droolsjbpm-integration by kiegroup.
the class KieServerRestImplTest method setupKieServerImpl.
@Before
public void setupKieServerImpl() throws Exception {
System.setProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED, "true");
origServerId = KieServerEnvironment.getServerId();
System.setProperty("org.kie.server.id", KIE_SERVER_ID);
KieServerEnvironment.setServerId(KIE_SERVER_ID);
FileUtils.deleteDirectory(REPOSITORY_DIR);
FileUtils.forceMkdir(REPOSITORY_DIR);
kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR));
kieServer.init();
MultivaluedHashMap<String, String> mockedRequestHeaders = new MultivaluedHashMap<>();
mockedRequestHeaders.add("Accept", "application/json");
when(headers.getRequestHeaders()).thenReturn(mockedRequestHeaders);
}
Aggregations