Search in sources :

Example 1 with MediationPersistenceManager

use of org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager in project carbon-mediation by wso2.

the class ConfigAdmin method updateConfiguration.

/**
 * Update the active configuration with the new configuration
 *
 * @param configElement a SOAPElement for the configuration
 * @return true if the update is successful
 * @throws org.apache.axis2.AxisFault if an error occurs
 */
public boolean updateConfiguration(OMElement configElement) throws AxisFault {
    Exception error = null;
    final Lock lock = getLock();
    try {
        lock.lock();
        ConfigurationUpdater updater = new ConfigurationUpdater(getServerContextInformation(), getConfigContext(), getMediationPersistenceManager(), (UserRegistry) getConfigSystemRegistry());
        updater.update(configElement);
        if (!Boolean.parseBoolean(System.getProperty("NonRegistryMode"))) {
            MediationPersistenceManager pm = getMediationPersistenceManager();
            if (pm != null) {
                pm.saveItem(null, ServiceBusConstants.ITEM_TYPE_FULL_CONFIG);
            }
        }
    } catch (Exception e) {
        handleException("Error while updating the Synapse configuration", e);
    } finally {
        lock.unlock();
    }
    return true;
}
Also used : MediationPersistenceManager(org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager) SynapseException(org.apache.synapse.SynapseException) XMLStreamException(javax.xml.stream.XMLStreamException) Lock(java.util.concurrent.locks.Lock)

Example 2 with MediationPersistenceManager

use of org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager in project carbon-mediation by wso2.

the class TemplateEditorAdmin method deleteTemplate.

/*
    */
/**
 * Deletes the sequence with the given name from SynapseConfiguration
 *
 * @param templateName - Name of the sequence to delete
 * @throws AxisFault if the Sequence described by the given name doesnt
 *                                 exists in the Synapse Configuration
 */
public void deleteTemplate(String templateName) throws AxisFault {
    final Lock lock = getLock();
    try {
        lock.lock();
        SynapseConfiguration synCfg = getSynapseConfiguration();
        TemplateMediator sequence = synCfg.getSequenceTemplates().get(templateName);
        if (sequence != null) {
            synCfg.removeSequenceTemplate(templateName);
            if (!Boolean.parseBoolean(System.getProperty("NonRegistryMode"))) {
                MediationPersistenceManager pm = getMediationPersistenceManager();
                pm.deleteItem(templateName, sequence.getFileName(), ServiceBusConstants.ITEM_TYPE_TEMPLATE);
            }
        } else {
            handleException("No defined sequence with name " + templateName + " found to delete in the Synapse configuration");
        }
    } catch (Exception fault) {
        handleException("Couldn't get the Synapse Configuration to delete the sequence", fault);
    } finally {
        lock.unlock();
    }
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) MediationPersistenceManager(org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) SynapseException(org.apache.synapse.SynapseException) Lock(java.util.concurrent.locks.Lock)

Example 3 with MediationPersistenceManager

use of org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager in project carbon-mediation by wso2.

the class EndpointTemplateEditorAdmin method persistTemplate.

private void persistTemplate(Template template) throws AxisFault {
    if (template instanceof Template) {
        if (!Boolean.parseBoolean(System.getProperty("NonRegistryMode"))) {
            MediationPersistenceManager pm = getMediationPersistenceManager();
            pm.saveItem(((Template) template).getName(), ServiceBusConstants.ITEM_TYPE_TEMPLATE_ENDPOINTS);
        }
    }
}
Also used : MediationPersistenceManager(org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager) Template(org.apache.synapse.endpoints.Template)

Example 4 with MediationPersistenceManager

use of org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager in project carbon-mediation by wso2.

the class ProxyObserver method serviceUpdate.

public void serviceUpdate(AxisEvent event, AxisService axisService) {
    Parameter serviceTypeParam = axisService.getParameter(SynapseConstants.SERVICE_TYPE_PARAM_NAME);
    if (serviceTypeParam == null || !SynapseConstants.PROXY_SERVICE_TYPE.equals(serviceTypeParam.getValue().toString())) {
        // We are only interested about the proxy services
        return;
    }
    if (getSynapseConfiguration() == null) {
        // through the OSGi console or the system is shutting down.
        if (log.isDebugEnabled()) {
            log.debug("SynapseConfiguration in ProxyObserver is null. The service" + " update event will not be processed further.");
        }
        return;
    }
    if (CarbonConstants.POLICY_ADDED == event.getEventType()) {
        updateProxyServicePolicies(axisService, getSynapseConfiguration());
    }
    if (CarbonConstants.AxisEvent.TRANSPORT_BINDING_ADDED == event.getEventType()) {
        ProxyService proxy = getSynapseConfiguration().getProxyService(axisService.getName());
        if (proxy != null && proxy.getTransports() != null) {
            List<String> transports = axisService.getExposedTransports();
            for (String trp : transports) {
                if (!proxy.getTransports().contains(trp)) {
                    proxy.getTransports().add(trp);
                }
            }
        }
    }
    ProxyService proxy = getSynapseConfiguration().getProxyService(axisService.getName());
    if (proxy != null && proxy.getTransports() != null) {
        proxy.setRunning(axisService.isActive());
    }
    if (AxisEvent.SERVICE_REMOVE == event.getEventType()) {
        Parameter keepServiceHistoryParam = axisService.getParameter(CarbonConstants.KEEP_SERVICE_HISTORY_PARAM);
        Parameter originator = axisService.getParameter("originator");
        boolean keepHistory = keepServiceHistoryParam != null && JavaUtils.isTrue(keepServiceHistoryParam.getValue());
        // during hot update
        if (originator != null && "ServiceAdmin".equals(originator.getValue().toString())) {
            if (!keepHistory) {
                ProxyService proxySvc = getSynapseConfiguration().getProxyService(axisService.getName());
                if (proxySvc != null) {
                    getSynapseConfiguration().removeProxyService(axisService.getName());
                    if (!Boolean.parseBoolean(System.getProperty("NonRegistryMode"))) {
                        MediationPersistenceManager pm = getMediationPersistenceManager();
                        pm.deleteItem(proxySvc.getName(), proxySvc.getFileName(), ServiceBusConstants.ITEM_TYPE_PROXY_SERVICE);
                    }
                    log.info("Deleted the proxy service : " + proxySvc.getName());
                } else if (log.isDebugEnabled()) {
                    log.debug("Proxy Service representing the service " + axisService.getName() + " of type proxy is not found in the SynapseConfiguration");
                }
            }
        }
    }
}
Also used : ProxyService(org.apache.synapse.core.axis2.ProxyService) MediationPersistenceManager(org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager)

Example 5 with MediationPersistenceManager

use of org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager in project carbon-mediation by wso2.

the class ProxyServiceAdmin method deleteProxyService.

/**
 * Deletes a proxy service from the synapse configuration
 *
 * @param proxyName name of the proxy service which needs to be deleted
 * @throws ProxyAdminException if the proxy service name given is not existent in the
 *                   synapse configuration
 * @return <code>successful</code> on success or <code>failed</code> otherwise
 */
public String deleteProxyService(String proxyName) throws ProxyAdminException {
    final Lock lock = getLock();
    try {
        lock.lock();
        if (log.isDebugEnabled()) {
            log.debug("Deleting proxy service : " + proxyName);
        }
        SynapseConfiguration synapseConfiguration = getSynapseConfiguration();
        ProxyService proxy = synapseConfiguration.getProxyService(proxyName);
        if (proxy != null) {
            synapseConfiguration.removeProxyService(proxyName);
            if (!Boolean.parseBoolean(System.getProperty("NonRegistryMode"))) {
                MediationPersistenceManager pm = getMediationPersistenceManager();
                pm.deleteItem(proxyName, proxy.getFileName(), ServiceBusConstants.ITEM_TYPE_PROXY_SERVICE);
            }
            if (log.isDebugEnabled()) {
                log.debug("Proxy service : " + proxyName + " deleted");
            }
            return SUCCESSFUL;
        } else {
            log.warn("No proxy service exists by the name : " + proxyName);
            return FAILED;
        }
    } catch (Exception e) {
        handleException(log, "Unable to delete proxy service : " + proxyName, e);
    } finally {
        lock.unlock();
    }
    return FAILED;
}
Also used : ProxyService(org.apache.synapse.core.axis2.ProxyService) MediationPersistenceManager(org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) Lock(java.util.concurrent.locks.Lock)

Aggregations

MediationPersistenceManager (org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager)53 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)35 Lock (java.util.concurrent.locks.Lock)27 XMLStreamException (javax.xml.stream.XMLStreamException)16 SynapseException (org.apache.synapse.SynapseException)15 OMElement (org.apache.axiom.om.OMElement)10 QName (javax.xml.namespace.QName)9 Entry (org.apache.synapse.config.Entry)7 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)7 IOException (java.io.IOException)6 API (org.apache.synapse.api.API)6 OMException (org.apache.axiom.om.OMException)5 DeploymentException (org.apache.axis2.deployment.DeploymentException)5 Parameter (org.apache.axis2.description.Parameter)5 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)5 Properties (java.util.Properties)4 ReentrantLock (java.util.concurrent.locks.ReentrantLock)4 AxisFault (org.apache.axis2.AxisFault)4 ProxyService (org.apache.synapse.core.axis2.ProxyService)4 Endpoint (org.apache.synapse.endpoints.Endpoint)4