Search in sources :

Example 1 with ExitProtocolMessage

use of org.wso2.carbon.bpel.b4p.coordination.context.ExitProtocolMessage in project carbon-business-process by wso2.

the class TerminationTask method invokeProtocolHandler.

private synchronized void invokeProtocolHandler(ExitProtocolMessage message) {
    OMElement payload = message.toOM();
    Options options = new Options();
    options.setTo(new EndpointReference(message.getTaskProtocolHandlerURL()));
    options.setAction(WSConstants.WS_HT_COORDINATION_PROTOCOL_EXIT_ACTION);
    options.setTransportInProtocol(org.apache.axis2.Constants.TRANSPORT_HTTPS);
    ServiceClient serviceClient = null;
    try {
        serviceClient = new ServiceClient();
        serviceClient.setOptions(options);
        // Setting basic auth headers.
        String tenantDomain = MultitenantUtils.getTenantDomainFromUrl(message.getTaskProtocolHandlerURL());
        if (message.getTaskProtocolHandlerURL().equals(tenantDomain)) {
            // this is a Super tenant registration service
            CarbonUtils.setBasicAccessSecurityHeaders(CoordinationConfiguration.getInstance().getProtocolHandlerAdminUser(), CoordinationConfiguration.getInstance().getProtocolHandlerAdminPassword(), serviceClient);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Sending exit protocol message to tenant domain: " + tenantDomain);
            }
            // Tenant's registration service
            String username = "";
            String password = "";
            try {
                UserRegistry configSystemRegistry = B4PContentHolder.getInstance().getRegistryService().getConfigSystemRegistry(tenantID);
                Resource taskCoordination = configSystemRegistry.get(REG_TASK_COORDINATION);
                if (taskCoordination != null) {
                    username = taskCoordination.getProperty(USERNAME);
                    password = taskCoordination.getProperty(PASSWORD);
                } else {
                    log.error("Task coordination is not configured for tenant : " + tenantDomain + ". Dropping Exit Coordination message. Affected Tasks ids : " + message.getTaskIDs());
                    return;
                }
            } catch (RegistryException e) {
                log.warn("Error while accessing Registry Service for tenant : " + tenantDomain + ". Dropping Exit Coordination message. Affected Tasks ids : " + message.getTaskIDs(), e);
                return;
            }
            CarbonUtils.setBasicAccessSecurityHeaders(username, password, serviceClient);
        }
        serviceClient.fireAndForget(payload);
        if (log.isDebugEnabled()) {
            log.debug("Sent exit protocol message to " + message.getTaskProtocolHandlerURL());
        }
    } catch (AxisFault axisFault) {
        log.error("Error occurred while invoking HT Protocol Handler " + message.getTaskProtocolHandlerURL() + ". Affected Tasks ids : " + message.getTaskIDs(), axisFault);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) ServiceClient(org.apache.axis2.client.ServiceClient) Resource(org.wso2.carbon.registry.core.Resource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) OMElement(org.apache.axiom.om.OMElement) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 2 with ExitProtocolMessage

use of org.wso2.carbon.bpel.b4p.coordination.context.ExitProtocolMessage in project carbon-business-process by wso2.

the class TerminationTask method run.

@Override
public void run() {
    PrivilegedCarbonContext.startTenantFlow();
    PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    privilegedCarbonContext.setTenantId(tenantID, true);
    try {
        List<TaskProtocolHandler> taskProtocolHandlers = null;
        try {
            taskProtocolHandlers = getHTProtocolHandlerURLWithTasks(instanceID);
        } catch (Exception e) {
            log.error("Error occurred while retrieving coordination data", e);
        }
        String currentProtocolHandler = "";
        ExitProtocolMessage currentExitMessage = null;
        for (TaskProtocolHandler taskProtocolHandler : taskProtocolHandlers) {
            // Task Protocol Handler and Task ID should be not null
            if (taskProtocolHandler.getProtocolHandlerURL() != null && taskProtocolHandler.getTaskID() != null) {
                if (!currentProtocolHandler.equals(taskProtocolHandler.getProtocolHandlerURL())) {
                    // found a new protocol handler URL, so invoking old exit message.
                    if (currentExitMessage != null) {
                        // To ignore initial condition, we do null check here.
                        invokeProtocolHandler(currentExitMessage);
                    }
                    currentExitMessage = new ExitProtocolMessage(taskProtocolHandler.getProtocolHandlerURL());
                    currentProtocolHandler = taskProtocolHandler.getProtocolHandlerURL();
                }
                currentExitMessage.getTaskIDs().add(taskProtocolHandler.getTaskID());
                if (log.isDebugEnabled()) {
                    log.debug("building exit protocol message for task id:" + taskProtocolHandler.getTaskID());
                }
            }
        }
        if (currentExitMessage != null) {
            // Here we do last invocation.
            invokeProtocolHandler(currentExitMessage);
        }
        // Cleaning coordination data.
        boolean deleted = false;
        try {
            deleted = deleteCoordinationData(instanceID);
        } catch (Exception e) {
            log.error("Error occurred while cleaning coordination data for process instance id " + instanceID, e);
        }
        if (deleted && log.isDebugEnabled()) {
            log.debug("Coordination data are removed from database for process instance id " + instanceID);
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
Also used : ExitProtocolMessage(org.wso2.carbon.bpel.b4p.coordination.context.ExitProtocolMessage) TaskProtocolHandler(org.wso2.carbon.bpel.b4p.coordination.dao.TaskProtocolHandler) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Aggregations

RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)2 OMElement (org.apache.axiom.om.OMElement)1 AxisFault (org.apache.axis2.AxisFault)1 EndpointReference (org.apache.axis2.addressing.EndpointReference)1 Options (org.apache.axis2.client.Options)1 ServiceClient (org.apache.axis2.client.ServiceClient)1 ExitProtocolMessage (org.wso2.carbon.bpel.b4p.coordination.context.ExitProtocolMessage)1 TaskProtocolHandler (org.wso2.carbon.bpel.b4p.coordination.dao.TaskProtocolHandler)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 Resource (org.wso2.carbon.registry.core.Resource)1 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)1