Search in sources :

Example 26 with ProxyService

use of org.apache.synapse.core.axis2.ProxyService in project wso2-synapse by wso2.

the class ProxyServiceDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("ProxyService Update from file : " + fileName + " : Started");
    }
    try {
        ProxyService proxy = ProxyServiceFactory.createProxy(artifactConfig, properties);
        if (proxy != null) {
            proxy.setLogSetterValue();
            proxy.setFileName((new File(fileName)).getName());
            if (log.isDebugEnabled()) {
                log.debug("ProxyService named '" + proxy.getName() + "' has been built from the file " + fileName);
            }
            initializeProxy(proxy);
            if (log.isDebugEnabled()) {
                log.debug("Initialized the ProxyService : " + proxy.getName());
            }
            ProxyService currentProxy = getSynapseConfiguration().getProxyService(existingArtifactName);
            currentProxy.stop(getSynapseConfiguration());
            getSynapseConfiguration().removeProxyService(existingArtifactName);
            if (!existingArtifactName.equals(proxy.getName())) {
                log.info("ProxyService named " + existingArtifactName + " has been Undeployed");
            }
            AxisService axisService = proxy.buildAxisService(getSynapseConfiguration(), getSynapseConfiguration().getAxisConfiguration());
            getSynapseConfiguration().addProxyService(proxy.getName(), proxy);
            if (axisService == null) {
                if (log.isDebugEnabled()) {
                    log.debug("Skipping proxy Startup for ProxyService : " + proxy.getName());
                }
                return proxy.getName();
            }
            if (log.isDebugEnabled()) {
                log.debug("Started the ProxyService : " + proxy.getName());
                log.debug("ProxyService " + (existingArtifactName.equals(proxy.getName()) ? "update" : "deployment") + " from file : " + fileName + " : Completed");
            }
            log.info("ProxyService named '" + proxy.getName() + "' has been " + (existingArtifactName.equals(proxy.getName()) ? "update" : "deployed") + " from file : " + fileName);
            return proxy.getName();
        } else {
            handleSynapseArtifactDeploymentError("ProxyService Update Failed. The artifact " + "described in the file " + fileName + " is not a ProxyService");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("ProxyService Update from the file : " + fileName + " : Failed.", e);
    }
    return null;
}
Also used : ProxyService(org.apache.synapse.core.axis2.ProxyService) AxisService(org.apache.axis2.description.AxisService) File(java.io.File) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 27 with ProxyService

use of org.apache.synapse.core.axis2.ProxyService in project wso2-synapse by wso2.

the class ProxyServiceDeployer method deploySynapseArtifact.

@Override
public String deploySynapseArtifact(OMElement artifactConfig, String filePath, Properties properties) {
    CustomLogSetter.getInstance().setLogAppender(customLogContent);
    if (log.isDebugEnabled()) {
        log.debug("ProxyService Deployment from file : " + filePath + " : Started");
    }
    try {
        ProxyService proxy = ProxyServiceFactory.createProxy(artifactConfig, properties);
        proxy.setArtifactContainerName(customLogContent);
        if (proxy != null) {
            if (getSynapseConfiguration().getProxyService(proxy.getName()) != null) {
                log.warn("Hot deployment thread picked up an already deployed proxy - Ignoring");
                return proxy.getName();
            }
            File proxyFile = new File(filePath);
            proxy.setFileName(proxyFile.getName());
            proxy.setFilePath(proxyFile.toURI().toURL());
            if (log.isDebugEnabled()) {
                log.debug("ProxyService named '" + proxy.getName() + "' has been built from the file " + filePath);
            }
            initializeProxy(proxy);
            if (log.isDebugEnabled()) {
                log.debug("Initialized the ProxyService : " + proxy.getName());
            }
            getSynapseConfiguration().addProxyService(proxy.getName(), proxy);
            AxisService axisService = proxy.buildAxisService(getSynapseConfiguration(), getSynapseConfiguration().getAxisConfiguration());
            if (axisService == null) {
                if (log.isDebugEnabled()) {
                    log.debug("Skipping proxy Startup for ProxyService : " + proxy.getName());
                }
                return proxy.getName();
            }
            if (log.isDebugEnabled()) {
                log.debug("Started the ProxyService : " + proxy.getName());
                log.debug("ProxyService Deployment from file : " + filePath + " : Completed");
            }
            log.info("ProxyService named '" + proxy.getName() + "' has been deployed from file : " + filePath);
            if (!proxy.isStartOnLoad() || !axisService.isActive()) {
                proxy.stop(getSynapseConfiguration());
                log.info("ProxyService named '" + proxy.getName() + "' has been stopped as startOnLoad parameter is set to false");
            }
            return proxy.getName();
        } else {
            handleSynapseArtifactDeploymentError("ProxyService Deployment Failed. The " + "artifact described in the file " + filePath + " is not a ProxyService");
        }
    } catch (Exception e) {
        /*if (failSafeProxyEnabled) {
                log.warn("Proxy service hot deployment from file: " + filePath + " failed - " +
                        "Continue in fail-safe mode", e);
            } else {
                handleSynapseArtifactDeploymentError(
                        "ProxyService Deployment from the file : " + filePath + " : Failed.", e);
            }*/
        handleSynapseArtifactDeploymentError("ProxyService Deployment from the file : " + filePath + " : Failed.", e);
    }
    return null;
}
Also used : ProxyService(org.apache.synapse.core.axis2.ProxyService) AxisService(org.apache.axis2.description.AxisService) File(java.io.File) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 28 with ProxyService

use of org.apache.synapse.core.axis2.ProxyService in project wso2-synapse by wso2.

the class SynapseConfiguration method init.

/**
 * This method will be called in the startup of Synapse or in an initiation
 * and will initialize all the managed parts of the Synapse Configuration
 *
 * @param se SynapseEnvironment specifying the env to be initialized
 */
public synchronized void init(SynapseEnvironment se) {
    SynapseConfiguration previouseConfiguration = null;
    if (log.isDebugEnabled()) {
        log.debug("Initializing the Synapse Configuration using the SynapseEnvironment");
    }
    // initialize registry
    if (registry != null && registry instanceof ManagedLifecycle) {
        ((ManagedLifecycle) registry).init(se);
    }
    // we initialize xpath extensions here since synapse environment is available
    initXpathExtensions(se);
    initCarbonTenantConfigurator(se);
    // initialize endpoints
    for (Endpoint endpoint : getDefinedEndpoints().values()) {
        try {
            endpoint.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing endpoint [" + endpoint.getName() + "] " + e.getMessage());
        }
    }
    // initialize sequence templates
    for (TemplateMediator seqTemplate : getSequenceTemplates().values()) {
        try {
            seqTemplate.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing Sequence Template [" + seqTemplate.getName() + "] " + e.getMessage());
        }
    }
    String tenantDomain = getTenantDomain(se);
    if (tenantDomain != null) {
        previouseConfiguration = SynapseConfigUtils.getSynapseConfiguration(tenantDomain);
        SynapseConfigUtils.addSynapseConfiguration(tenantDomain, this);
    }
    if (previouseConfiguration != null) {
        destroyExistingInbounds(previouseConfiguration);
    }
    for (InboundEndpoint endpoint : getInboundEndpoints()) {
        try {
            endpoint.init(se);
        } catch (Exception e) {
            inboundEndpointMap.remove(endpoint.getName());
            log.error(" Error in initializing inbound endpoint [" + endpoint.getName() + "] " + e.getMessage());
        }
    }
    // initialize managed mediators
    for (ManagedLifecycle seq : getDefinedSequences().values()) {
        if (seq != null) {
            try {
                seq.init(se);
            } catch (Exception e) {
                log.error(" Error in initializing Sequence " + e.getMessage());
            }
        }
    }
    // initialize all the proxy services
    for (ProxyService proxy : getProxyServices()) {
        try {
            if (proxy.getTargetInLineEndpoint() != null) {
                proxy.getTargetInLineEndpoint().init(se);
            }
            if (proxy.getTargetInLineInSequence() != null) {
                proxy.getTargetInLineInSequence().init(se);
            }
            if (proxy.getTargetInLineOutSequence() != null) {
                proxy.getTargetInLineOutSequence().init(se);
            }
            if (proxy.getTargetInLineFaultSequence() != null) {
                proxy.getTargetInLineFaultSequence().init(se);
            }
        } catch (Exception e) {
            log.error(" Error in initializing Proxy Service [ " + proxy.getName() + "] " + e.getMessage());
        }
    }
    // initialize the startups
    for (ManagedLifecycle stp : getStartups()) {
        if (stp != null) {
            try {
                stp.init(se);
            } catch (Exception e) {
                log.error(" Error in initializing Stratups " + e.getMessage());
            }
        }
    }
    // initialize sequence executors
    for (PriorityExecutor executor : getPriorityExecutors().values()) {
        try {
            executor.init();
        } catch (Exception e) {
            log.error(" Error in initializing Executor [ " + executor.getName() + "] " + e.getMessage());
        }
    }
    // initialize message stores
    for (MessageStore messageStore : messageStores.values()) {
        try {
            messageStore.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing Message Store [ " + messageStore.getName() + "] " + e.getMessage());
        }
    }
    // initialize message processors
    for (MessageProcessor messageProcessor : messageProcessors.values()) {
        try {
            messageProcessor.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing Message Processor [ " + messageProcessor.getName() + "] " + e.getMessage());
        }
    }
    for (API api : apiTable.values()) {
        try {
            api.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing API [ " + api.getName() + "] " + e.getMessage());
        }
    }
    initImportedLibraries(se);
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) MessageStore(org.apache.synapse.message.store.MessageStore) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) ProxyService(org.apache.synapse.core.axis2.ProxyService) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) API(org.apache.synapse.rest.API) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) ManagedLifecycle(org.apache.synapse.ManagedLifecycle) SynapseException(org.apache.synapse.SynapseException) IOException(java.io.IOException)

Example 29 with ProxyService

use of org.apache.synapse.core.axis2.ProxyService in project wso2-synapse by wso2.

the class SynapseConfiguration method destroy.

public synchronized void destroy(boolean preserverState) {
    if (log.isDebugEnabled()) {
        log.debug("Destroying the Synapse Configuration");
    }
    // clear the timer tasks of Synapse
    synapseTimer.cancel();
    synapseTimer = null;
    // stop and shutdown all the proxy services
    for (ProxyService p : getProxyServices()) {
        if (p.getTargetInLineInSequence() != null) {
            p.getTargetInLineInSequence().destroy();
        }
        if (p.getTargetInLineOutSequence() != null) {
            p.getTargetInLineOutSequence().destroy();
        }
    }
    // destroy the managed mediators
    for (ManagedLifecycle seq : getDefinedSequences().values()) {
        seq.destroy();
    }
    // destroy sequence templates
    for (TemplateMediator seqTemplate : getSequenceTemplates().values()) {
        seqTemplate.destroy();
    }
    // destroy inbound endpoint
    for (InboundEndpoint endpoint : getInboundEndpoints()) {
        // This path trigger from server shutdown hook. So we don't want to remove scheduled inbound tasks
        // from registry. Only un-deployment should remove task from registry. Ref product-ei#1206
        endpoint.destroy(false);
    }
    // destroy the managed endpoints
    for (Endpoint endpoint : getDefinedEndpoints().values()) {
        endpoint.destroy();
    }
    // destroy the startups
    for (ManagedLifecycle stp : startups.values()) {
        stp.destroy();
    }
    // clear session information used for SA load balancing
    try {
        SALSessions.getInstance().reset();
        DataSourceRepositoryHolder.getInstance().getDataSourceRepositoryManager().clear();
    } catch (Throwable ignored) {
    }
    // destroy the priority executors.
    for (PriorityExecutor pe : executors.values()) {
        pe.destroy();
    }
    // destroy the Message Stores
    for (MessageStore ms : messageStores.values()) {
        if (ms instanceof AbstractMessageProcessor) {
            ((AbstractMessageProcessor) ms).destroy(preserverState);
        } else {
            ms.destroy();
        }
    }
    // destroy the Message processors
    for (MessageProcessor mp : messageProcessors.values()) {
        mp.destroy();
    }
    for (API api : apiTable.values()) {
        api.destroy();
    }
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) MessageStore(org.apache.synapse.message.store.MessageStore) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) ProxyService(org.apache.synapse.core.axis2.ProxyService) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) API(org.apache.synapse.rest.API) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 30 with ProxyService

use of org.apache.synapse.core.axis2.ProxyService in project wso2-synapse by wso2.

the class DebugManagerTest method testDebugManagerProcessCommandSetSkipProxyOutSequence.

public void testDebugManagerProcessCommandSetSkipProxyOutSequence() throws Exception {
    ProxyService ps = new ProxyService("test_proxy_6");
    TestMediator in1 = new TestMediator();
    TestMediator in2 = new TestMediator();
    TestMediator in3 = new TestMediator();
    SequenceMediator inSeq = new SequenceMediator();
    inSeq.addChild(in1);
    inSeq.addChild(in2);
    inSeq.addChild(in3);
    TestMediator out1 = new TestMediator();
    TestMediator out2 = new TestMediator();
    TestMediator out3 = new TestMediator();
    SequenceMediator outSeq = new SequenceMediator();
    outSeq.addChild(out1);
    outSeq.addChild(out2);
    outSeq.addChild(out3);
    ps.setTargetInLineInSequence(inSeq);
    ps.setTargetInLineOutSequence(inSeq);
    synConfig.addProxyService(ps.getName(), ps);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_6\",\"sequence-type\":\"proxy_outseq\"," + "\"mediator-position\":\"0\"}}}";
    dm.processDebugCommand(debug_command);
    assertTrue(((AbstractMediator) ps.getTargetInLineOutSequence().getChild(0)).isSkipEnabled());
}
Also used : ProxyService(org.apache.synapse.core.axis2.ProxyService) TestMediator(org.apache.synapse.mediators.TestMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Aggregations

ProxyService (org.apache.synapse.core.axis2.ProxyService)33 OMElement (org.apache.axiom.om.OMElement)13 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)12 Properties (java.util.Properties)8 TestMediator (org.apache.synapse.mediators.TestMediator)8 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)6 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)5 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)5 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)4 Endpoint (org.apache.synapse.endpoints.Endpoint)4 API (org.apache.synapse.rest.API)4 File (java.io.File)3 SynapseEventSource (org.apache.synapse.eventing.SynapseEventSource)3 MessageProcessor (org.apache.synapse.message.processor.MessageProcessor)3 MessageStore (org.apache.synapse.message.store.MessageStore)3 Test (org.junit.Test)3 Iterator (java.util.Iterator)2 AxisService (org.apache.axis2.description.AxisService)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2