Search in sources :

Example 11 with KieServerExtension

use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.

the class KieServerImpl method markAsReady.

public void markAsReady() {
    kieServerReady.set(true);
    logger.info("KieServer {} is ready to receive requests", KieServerEnvironment.getServerId());
    for (KieServerExtension extension : context.getServerExtensions()) {
        try {
            extension.serverStarted();
        } catch (Exception e) {
            logger.error("Error when destroying server extension of type {}", extension, e);
        }
    }
}
Also used : KieServerExtension(org.kie.server.services.api.KieServerExtension)

Example 12 with KieServerExtension

use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.

the class KieServerImpl method getInfoInternal.

protected KieServerInfo getInfoInternal() {
    Version version = KieServerEnvironment.getVersion();
    String serverId = KieServerEnvironment.getServerId();
    String serverName = KieServerEnvironment.getServerName();
    String versionStr = version != null ? version.toString() : "Unknown-Version";
    List<String> capabilities = new ArrayList<String>();
    for (KieServerExtension extension : context.getServerExtensions()) {
        capabilities.add(extension.getImplementedCapability());
    }
    return new KieServerInfo(serverId, serverName, versionStr, capabilities, kieServerLocation, mode);
}
Also used : Version(org.kie.server.api.Version) KieServerExtension(org.kie.server.services.api.KieServerExtension) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) KieServerInfo(org.kie.server.api.model.KieServerInfo)

Example 13 with KieServerExtension

use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.

the class KieServerImpl method healthCheck.

public List<Message> healthCheck(boolean report) throws IllegalStateException {
    List<Message> healthMessages = new ArrayList<>();
    long start = System.currentTimeMillis();
    if (!isKieServerReady()) {
        healthMessages.add(new Message(Severity.ERROR, String.format("KIE Server '%s' is not ready to serve requests", KieServerEnvironment.getServerId())));
    }
    if (report) {
        List<String> mainInfo = new ArrayList<>();
        mainInfo.add(String.format("KIE Server '%s' is ready to serve requests %s", KieServerEnvironment.getServerId(), isKieServerReady()));
        mainInfo.add("Server is up for " + calculateUptime());
        Message header = new Message(Severity.INFO, mainInfo);
        healthMessages.add(header);
    }
    // first check of KIE Server's containers if any of them is in failed state
    for (KieContainerInstance container : getContainers()) {
        // RHPAM-1793 - relax health check in case of management is enabled.
        if (container.getStatus().equals(KieContainerStatus.FAILED) && !managementDisabled) {
            healthMessages.add(new Message(Severity.WARN, String.format("KIE Container '%s' is in FAILED state", container.getContainerId())));
        } else if (container.getStatus().equals(KieContainerStatus.FAILED) && managementDisabled) {
            healthMessages.add(new Message(Severity.ERROR, String.format("KIE Container '%s' is in FAILED state", container.getContainerId())));
        }
    }
    // next check all extensions for their health
    for (KieServerExtension extension : getServerExtensions()) {
        List<Message> extensionMessages = extension.healthCheck(report);
        healthMessages.addAll(extensionMessages);
    }
    if (report) {
        Message footer = new Message(Severity.INFO, "Health check done in " + (System.currentTimeMillis() - start) + " ms");
        healthMessages.add(footer);
    }
    return healthMessages;
}
Also used : Message(org.kie.server.api.model.Message) KieServerExtension(org.kie.server.services.api.KieServerExtension) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) KieContainerInstance(org.kie.server.services.api.KieContainerInstance)

Example 14 with KieServerExtension

use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.

the class KieServerImpl method destroy.

public void destroy() {
    eventSupport.fireBeforeServerStopped(this);
    kieServerActive.set(false);
    policyManager.stop();
    // disconnect from controller
    KieServerController kieController = getDefaultController();
    kieController.disconnect(getInfoInternal());
    for (KieServerExtension extension : context.getServerExtensions()) {
        try {
            extension.destroy(this, this.context);
            this.context.unregisterServerExtension(extension);
            logger.info("{} has been successfully unregistered as server extension", extension);
        } catch (Exception e) {
            logger.error("Error when destroying server extension of type {}", extension, e);
        }
    }
    eventSupport.fireAfterServerStopped(this);
}
Also used : KieServerController(org.kie.server.controller.api.KieServerController) KieServerExtension(org.kie.server.services.api.KieServerExtension)

Example 15 with KieServerExtension

use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.

the class KieServerImpl method updateContainerReleaseId.

@Override
public ServiceResponse<ReleaseId> updateContainerReleaseId(String containerId, ReleaseId releaseId, boolean resetBeforeUpdate) {
    Optional<ServiceResponse<ReleaseId>> optional = Optional.ofNullable(validateReleaseAndMode("Error updating releaseId for container '" + containerId + "'.", releaseId));
    if (optional.isPresent()) {
        ServiceResponse<ReleaseId> response = optional.get();
        logger.error(response.getMsg());
        return optional.get();
    }
    List<Message> messages = getMessagesForContainer(containerId);
    messages.clear();
    try {
        KieContainerInstanceImpl kci = context.getContainer(containerId);
        // call do dispose() is executed.
        if (kci != null && kci.getKieContainer() != null) {
            // before upgrade check with all extensions if that is allowed
            KieModuleMetaData metadata = buildKieModuleMetadata(releaseId);
            Map<String, Object> parameters = getReleaseUpdateParameters(metadata, releaseId, kci.getKieContainer(), messages, resetBeforeUpdate);
            // process server extensions
            List<KieServerExtension> extensions = getServerExtensions();
            for (KieServerExtension extension : extensions) {
                boolean allowed = extension.isUpdateContainerAllowed(containerId, kci, parameters);
                if (!allowed) {
                    String message = (String) parameters.get(KieServerConstants.FAILURE_REASON_PROP);
                    logger.warn("Container {} (for release id {}) on {} cannot be updated due to {}", containerId, releaseId, extension, message);
                    if (messages != null) {
                        messages.add(new Message(Severity.WARN, message));
                    }
                    return new ServiceResponse<ReleaseId>(ServiceResponse.ResponseType.FAILURE, message);
                }
                logger.debug("Container {} (for release id {}) on {} ready to be updated", containerId, releaseId, extension);
            }
            prepareUpdateExtensions(metadata, kci, releaseId, messages, resetBeforeUpdate);
            ReleaseId originalReleaseId = kci.getResource().getReleaseId();
            Message updateMessage = updateKieContainerToVersion(kci, releaseId);
            if (updateMessage.getSeverity().equals(Severity.WARN)) {
                messages.add(updateMessage);
                return new ServiceResponse<ReleaseId>(ServiceResponse.ResponseType.FAILURE, "Error updating release id on container " + containerId + " to " + releaseId, kci.getResource().getReleaseId());
            }
            updateExtensions(metadata, kci, releaseId, messages, resetBeforeUpdate);
            // If extension update fails then restore previous container
            if (messages.stream().anyMatch(m -> m.getSeverity().equals(Severity.ERROR))) {
                logger.warn("Update of container {} (for release id {}) failed, putting it back to original release id {}", containerId, releaseId, originalReleaseId);
                updateMessage = updateKieContainerToVersion(kci, originalReleaseId);
                if (updateMessage.getSeverity().equals(Severity.WARN)) {
                    messages.add(updateMessage);
                    return new ServiceResponse<ReleaseId>(ServiceResponse.ResponseType.FAILURE, "Error reverting release id update on container " + containerId + " to original release id " + originalReleaseId, kci.getResource().getReleaseId());
                }
                updateExtensions(metadata, kci, originalReleaseId, messages, resetBeforeUpdate);
                messages.add(new Message(Severity.WARN, "Error updating release id on container " + containerId + " to " + releaseId + ", release id returned back to " + kci.getResource().getReleaseId()));
                return new ServiceResponse<ReleaseId>(ServiceResponse.ResponseType.FAILURE, "Error updating release id on container " + containerId + " to " + releaseId + ", release id returned back to " + kci.getResource().getReleaseId(), kci.getResource().getReleaseId());
            }
            // store the current state of the server
            storeServerState(currentState -> {
                List<KieContainerResource> containers = new ArrayList<>();
                currentState.getContainers().forEach(containerResource -> {
                    if (containerId.equals(containerResource.getContainerId())) {
                        containerResource.setReleaseId(releaseId);
                        containerResource.setResolvedReleaseId(new ReleaseId(kci.getKieContainer().getContainerReleaseId()));
                    }
                    containers.add(containerResource);
                });
                currentState.setContainers(new HashSet<KieContainerResource>(containers));
            });
            logger.info("Container {} successfully updated to release id {}", containerId, releaseId);
            ks.getRepository().removeKieModule(originalReleaseId);
            notifyStatusToControllers();
            messages.add(new Message(Severity.INFO, "Release id successfully updated for container " + containerId));
            return new ServiceResponse<ReleaseId>(ServiceResponse.ResponseType.SUCCESS, "Release id successfully updated.", kci.getResource().getReleaseId());
        } else {
            return new ServiceResponse<ReleaseId>(ServiceResponse.ResponseType.FAILURE, "Container " + containerId + " is not instantiated.");
        }
    } catch (Exception e) {
        if (messages != null) {
            messages.add(new Message(Severity.WARN, "Error updating releaseId for container '" + containerId + "' due to " + e.getMessage()));
        }
        logger.error("Error updating releaseId for container '" + containerId + "'", e);
        return new ServiceResponse<ReleaseId>(ServiceResponse.ResponseType.FAILURE, "Error updating releaseId for container " + containerId + ": " + e.getClass().getName() + ": " + e.getMessage());
    }
}
Also used : Message(org.kie.server.api.model.Message) KieServerExtension(org.kie.server.services.api.KieServerExtension) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ReleaseId(org.kie.server.api.model.ReleaseId) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieContainerResource(org.kie.server.api.model.KieContainerResource)

Aggregations

KieServerExtension (org.kie.server.services.api.KieServerExtension)43 Message (org.kie.server.api.model.Message)10 ArrayList (java.util.ArrayList)9 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)9 ReleaseId (org.kie.server.api.model.ReleaseId)8 Test (org.junit.Test)6 KieModuleMetaData (org.kie.scanner.KieModuleMetaData)6 KieContainerResource (org.kie.server.api.model.KieContainerResource)6 ServiceResponse (org.kie.server.api.model.ServiceResponse)6 Matchers.anyString (org.mockito.Matchers.anyString)6 JbpmKieServerExtension (org.kie.server.services.jbpm.JbpmKieServerExtension)5 DeploymentService (org.jbpm.services.api.DeploymentService)4 ProcessService (org.jbpm.services.api.ProcessService)4 KieContainerInstance (org.kie.server.services.api.KieContainerInstance)4 KieServerRegistry (org.kie.server.services.api.KieServerRegistry)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)3 RuntimeDataService (org.jbpm.services.api.RuntimeDataService)3