use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class KafkaExtensionTest method assertExtensionInitialized.
private void assertExtensionInitialized(Map<String, KieServerExtension> extensions, String extensionName) {
KieServerExtension extension = extensions.get(extensionName);
assertNotNull("Extension " + extensionName + " was not found in current server", extension);
assertTrue("Extension " + extensionName + " is expected to be active", extension.isActive());
assertTrue("Extension " + extensionName + " is expected to be initialized", extension.isInitialized());
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class CommandScriptMessageHandler method onMessage.
@Override
public String onMessage(String message) {
CommandScript script = deserialize(message, CommandScript.class);
String capability = TARGET_CAPABILITY;
boolean hasBPMCommand = script.getCommands().stream().anyMatch(cmd -> cmd instanceof DescriptorCommand);
if (hasBPMCommand) {
capability = KieServerConstants.CAPABILITY_BPM;
}
KieContainerCommandService<?> executor = null;
for (KieServerExtension extension : context.getServerExtensions()) {
KieContainerCommandService<?> tmp = extension.getAppComponents(KieContainerCommandService.class);
if (tmp != null && extension.getImplementedCapability().equalsIgnoreCase(capability)) {
executor = tmp;
logger.debug("Extension {} returned command executor {} with capability {}", extension, executor, extension.getImplementedCapability());
break;
}
}
if (executor == null) {
throw new IllegalStateException("No executor found for script execution");
}
// 4. process request
ServiceResponsesList response = executor.executeScript(script, MarshallingFormat.JSON, null);
String reply = serialize(response);
return reply;
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class KafkaServerExtensionProducerTest method setup.
@Before
public void setup() {
System.setProperty(SIGNAL_MAPPING_PROPERTY, Mapping.AUTO.toString());
itemsFactory = new SimpleRegisterableItemsFactory();
itemsFactory.addProcessListener(new KafkaServerProcessListener());
mockProducer = new MockProducer<>(false, new StringSerializer(), new ByteArraySerializer());
extension = new MockKafkaServerExtension(mockProducer);
server = mock(KieServerImpl.class);
registry = mock(KieServerRegistry.class);
KieServerExtension serverExtension = mock(KieServerExtension.class);
when(registry.getServerExtension(Mockito.anyString())).thenReturn(serverExtension);
ListenerSupport deployService = mock(ListenerSupport.class, withSettings().extraInterfaces(DeploymentService.class));
processService = mock(ProcessService.class);
when(serverExtension.getServices()).thenReturn(Arrays.asList(deployService, processService));
extension.init(server, registry);
extension.serverStarted();
pInstance = mock(ProcessInstance.class);
runtime = mock(KieRuntime.class);
nInstance = mock(NodeInstance.class);
node = mock(Node.class);
when(nInstance.getNode()).thenReturn(node);
when(node.getMetaData()).thenReturn(Collections.emptyMap());
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class PrometheusKieServerExtension method init.
@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
this.context = registry;
customMetrics = new PrometheusCustomMetricsSupport(this);
registerDefaultDescriptor();
// Prometheus Monitoring
KieServerExtension jBPMExtension = context.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
if (jBPMExtension != null) {
final KModuleDeploymentService deploymentService = jBPMExtension.getAppComponents(KModuleDeploymentService.class);
if (deploymentService != null) {
List<DeploymentEventListener> metrics = customMetrics.getDeploymentEventListener();
if (!metrics.isEmpty()) {
List<DeploymentEventListener> listeners = new ArrayList<>(metrics);
listeners.forEach(l -> deploymentService.addListener(l));
}
deploymentService.addListener(new PrometheusDeploymentEventListener());
}
final ExecutorServiceImpl executorService = jBPMExtension.getAppComponents(ExecutorServiceImpl.class);
if (executorService != null) {
List<AsynchronousJobListener> metrics = customMetrics.getAsynchronousJobListener();
if (!metrics.isEmpty()) {
List<AsynchronousJobListener> listeners = new ArrayList<>(metrics);
listeners.forEach(l -> executorService.addAsyncJobListener(l));
}
executorService.addAsyncJobListener(new PrometheusJobListener());
}
final QueryServiceImpl queryService = jBPMExtension.getAppComponents(QueryServiceImpl.class);
if (queryService != null) {
final DataSetDefRegistry dataSetDefRegistry = queryService.getDataSetDefRegistry();
final PrometheusDataSetListener listener = new PrometheusDataSetListener(dataSetDefRegistry);
listener.init();
dataSetDefRegistry.addListener(listener);
}
final RuntimeDataService dataService = jBPMExtension.getAppComponents(RuntimeDataService.class);
if (dataService != null) {
final Collection<ProcessInstanceDesc> processInstances = dataService.getProcessInstances(asList(ProcessInstance.STATE_ACTIVE), null, new QueryContext(0, Integer.MAX_VALUE));
processInstances.forEach(pi -> recordRunningProcessInstance(pi.getDeploymentId(), pi.getProcessId()));
}
}
KieServerExtension caseExtension = context.getServerExtension(CaseKieServerExtension.EXTENSION_NAME);
if (caseExtension != null) {
final CaseManagementRuntimeDataServiceBase caseRuntime = caseExtension.getAppComponents(CaseManagementRuntimeDataServiceBase.class);
if (caseRuntime != null) {
final CaseInstanceList caseInstances = caseRuntime.getCaseInstances(asList(CaseStatus.OPEN.getName()), 0, Integer.MAX_VALUE, null, false);
for (CaseInstance instance : caseInstances.getCaseInstances()) {
recordRunningCaseInstance(instance.getCaseDefinitionId());
}
}
}
initialized = true;
if (!customMetrics.hasCustomMetrics()) {
LOGGER.info("{} started", toString());
} else {
LOGGER.info("{} started with custom Prometheus metrics provider(s): {}", toString(), customMetrics.customMetricsProviders());
}
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class JBPMUIKieServerExtension method init.
@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
this.registry = registry;
KieServerExtension jbpmExtension = registry.getServerExtension("jBPM");
if (jbpmExtension == null) {
initialized = false;
logger.warn("jBPM extension not found, jBPM UI cannot work without jBPM extension, disabling itself");
return;
}
List<Object> jbpmServices = jbpmExtension.getServices();
RuntimeDataService runtimeDataService = null;
DefinitionService definitionService = null;
UserTaskService userTaskService = null;
FormManagerService formManagerService = null;
CaseRuntimeDataService caseRuntimeDataService = null;
for (Object object : jbpmServices) {
// in case given service is null (meaning was not configured) continue with next one
if (object == null) {
continue;
}
if (RuntimeDataService.class.isAssignableFrom(object.getClass())) {
runtimeDataService = (RuntimeDataService) object;
continue;
} else if (DefinitionService.class.isAssignableFrom(object.getClass())) {
definitionService = (DefinitionService) object;
continue;
} else if (UserTaskService.class.isAssignableFrom(object.getClass())) {
userTaskService = (UserTaskService) object;
continue;
} else if (FormManagerService.class.isAssignableFrom(object.getClass())) {
formManagerService = (FormManagerService) object;
continue;
} else if (DeploymentService.class.isAssignableFrom(object.getClass())) {
deploymentService = (DeploymentService) object;
continue;
}
}
KieServerExtension caseExtension = registry.getServerExtension("Case-Mgmt");
if (caseExtension != null) {
List<Object> caseMgmtServices = caseExtension.getServices();
for (Object object : caseMgmtServices) {
// in case given service is null (meaning was not configured) continue with next one
if (object == null) {
continue;
}
if (CaseRuntimeDataService.class.isAssignableFrom(object.getClass())) {
caseRuntimeDataService = (CaseRuntimeDataService) object;
continue;
}
}
} else {
logger.warn("Case-Mgmt extension not found, jBPM UI capabilities will be limited");
}
formServiceBase = new FormServiceBase(definitionService, runtimeDataService, userTaskService, formManagerService, registry);
imageServiceBase = new ImageServiceBase(runtimeDataService, imageReferences, registry);
formRendererBase = new FormRendererBase(definitionService, userTaskService, formManagerService, caseRuntimeDataService, registry);
services.add(formServiceBase);
services.add(imageServiceBase);
services.add(formRendererBase);
this.kieContainerCommandService = new JBPMUIKieContainerCommandServiceImpl(null, formServiceBase, imageServiceBase, formRendererBase);
initialized = true;
}
Aggregations