Search in sources :

Example 1 with Library

use of org.apache.synapse.libraries.model.Library in project wso2-synapse by wso2.

the class ImportDeployer method undeploySynapseArtifact.

@Override
public void undeploySynapseArtifact(String artifactName) {
    if (log.isDebugEnabled()) {
        log.debug("Undeployment of the Synapse Import named : " + artifactName + " : Started");
    }
    try {
        SynapseImport undeployingImport = getSynapseConfiguration().getSynapseImports().get(artifactName);
        if (undeployingImport != null) {
            getSynapseConfiguration().removeSynapseImport(artifactName);
            // get corresponding library for un-loading this import
            Library synLib = getSynapseConfiguration().getSynapseLibraries().get(artifactName);
            if (synLib != null) {
                // this is a important step -> we need to unload what ever the components loaded thru this import
                synLib.unLoadLibrary();
                synLib.setLibStatus(false);
            }
            log.info("Synapse Import : " + artifactName + "' has been undeployed");
        } else {
            log.warn("Synapse Import : " + artifactName + " has already been undeployed");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Undeployement of Synapse Import named : " + artifactName + " : Failed", e);
    }
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Library(org.apache.synapse.libraries.model.Library) IOException(java.io.IOException) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 2 with Library

use of org.apache.synapse.libraries.model.Library in project wso2-synapse by wso2.

the class ImportDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Synapse Import Deployment from file : " + fileName + " : Started");
    }
    try {
        SynapseImport synImport = SynapseImportFactory.createImport(artifactConfig, properties);
        String synImportQualfiedName = LibDeployerUtils.getQualifiedName(synImport);
        if (synImport == null) {
            handleSynapseArtifactDeploymentError("Synapse Import update failed. The artifact " + "defined in the file: " + fileName + " is not a valid import.");
            return null;
        }
        if (log.isDebugEnabled()) {
            log.debug("Synapse Import: " + synImportQualfiedName + " has been built from the file: " + fileName);
        }
        if (existingArtifactName.equals(synImportQualfiedName)) {
            // normal update ,import Qualified Name(lib name + version) has not changed
            synImport.setFileName((new File(fileName)).getName());
            getSynapseConfiguration().addSynapseImport(synImportQualfiedName, synImport);
            // get corresponding library for loading imports if available
            Library synLib = getSynapseConfiguration().getSynapseLibraries().get(synImportQualfiedName);
            if (synLib != null) {
                // then reload
                if (synImport.isStatus()) {
                    synLib.unLoadLibrary();
                    LibDeployerUtils.loadLibArtifacts(synImport, synLib);
                } else {
                    synLib.setLibStatus(false);
                    synLib.unLoadLibrary();
                }
            }
            log.info("Synapse Library Import named '" + synImportQualfiedName + " has been deployed from file : " + fileName);
        } else {
            // when updating ,import Qualified Name has been changed !!
            // check for any other import with the same name
            SynapseImport existingImport = getSynapseConfiguration().getSynapseImports().get(synImportQualfiedName);
            if (existingImport != null) {
                // a synapse import with the same name (name + version) already exists
                // we should not allow multiple such imports
                log.warn("Synapse Import with the name : " + synImportQualfiedName + " already exists! " + "Could not load multiple Imports of same type.");
                String backedUp = backupFile(new File(fileName));
                log.info("Synapse Import with the name : " + synImportQualfiedName + " is now backed up in : " + backedUp);
                return null;
            } else {
                synImport.setFileName((new File(fileName)).getName());
                getSynapseConfiguration().addSynapseImport(synImportQualfiedName, synImport);
                // get corresponding library for loading imports if available
                Library synLib = getSynapseConfiguration().getSynapseLibraries().get(synImportQualfiedName);
                // this is a important step -> we need to unload what ever the components loaded previously
                synLib.unLoadLibrary();
                // then reload
                if (synLib != null) {
                    LibDeployerUtils.loadLibArtifacts(synImport, synLib);
                }
                log.info("Synapse Library Import named '" + synImportQualfiedName + " has been deployed from file : " + fileName);
            }
        }
        log.info("Synapse Import: " + synImportQualfiedName + " has been updated from the file: " + fileName);
        // Give some time for worker threads to release the old sequence
        waitForCompletion();
        return synImportQualfiedName;
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Error while updating the Synapse Import from the " + "file: " + fileName);
    }
    return null;
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Library(org.apache.synapse.libraries.model.Library) File(java.io.File) IOException(java.io.IOException) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 3 with Library

use of org.apache.synapse.libraries.model.Library in project wso2-synapse by wso2.

the class ImportDeployer method deploySynapseArtifact.

@Override
public String deploySynapseArtifact(OMElement artifactConfig, String fileName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Synapse Import Deployment from file : " + fileName + " : Started");
    }
    try {
        SynapseImport synImport = SynapseImportFactory.createImport(artifactConfig, properties);
        String synImportQualfiedName = LibDeployerUtils.getQualifiedName(synImport);
        SynapseImport existingImport = getSynapseConfiguration().getSynapseImports().get(synImportQualfiedName);
        if (existingImport != null) {
            // a synapse import with the same name (name + version) already exists
            // we should not allow multiple such imports
            log.warn("Synapse Import with the name : " + synImportQualfiedName + " already exists! " + "Could not load multiple Imports of same type.");
            String backedUp = backupFile(new File(fileName));
            log.info("Synapse Import with the name : " + synImportQualfiedName + " is now backed up in : " + backedUp);
            return null;
        } else {
            if (synImport != null) {
                synImport.setFileName((new File(fileName)).getName());
                getSynapseConfiguration().addSynapseImport(synImportQualfiedName, synImport);
                // get corresponding library for loading imports if available
                Library synLib = getSynapseConfiguration().getSynapseLibraries().get(synImportQualfiedName);
                if (synLib != null) {
                    if (synImport.isStatus()) {
                        LibDeployerUtils.loadLibArtifacts(synImport, synLib);
                    } else {
                        synLib.setLibStatus(false);
                        synLib.unLoadLibrary();
                    }
                }
                log.info("Synapse Library Import named '" + synImportQualfiedName + " has been deployed from file : " + fileName);
                return synImportQualfiedName;
            } else {
                handleSynapseArtifactDeploymentError("Synapse Import Deployment Failed. " + "The artifact described in the file " + fileName + " is not a valid import");
            }
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Sequence Deployment from the file : " + fileName + " : Failed.", e);
    }
    return null;
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Library(org.apache.synapse.libraries.model.Library) File(java.io.File) IOException(java.io.IOException) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 4 with Library

use of org.apache.synapse.libraries.model.Library in project wso2-synapse by wso2.

the class LibraryArtifactDeployer method deploy.

public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
    String libFilePath = FilenameUtils.normalize(deploymentFileData.getAbsolutePath());
    if (log.isDebugEnabled()) {
        log.debug("Deployment of the synapse library artifact from file : " + libFilePath + " : STARTED");
    }
    // }
    try {
        SynapseArtifactDeploymentStore deploymentStore = getSynapseConfiguration().getArtifactDeploymentStore();
        Library lib = LibDeployerUtils.createSynapseLibrary(libFilePath);
        String libArtifactName = lib.getQName().toString();
        if (this.getSynapseConfiguration().getSynapseLibraries().get(lib.getQName().toString()) != null) {
            log.warn("Hot deployment thread picked up an already deployed synapse library - Ignoring");
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Created the Synapse Library : " + libArtifactName + "  from : " + libFilePath);
            }
            if (deploymentStore.isUpdatingArtifact(libFilePath)) {
                if (log.isDebugEnabled()) {
                    log.debug("Updating Library artifact detected with filename : " + libFilePath);
                }
                // this is an hot-update case
                String existingArtifactName = deploymentStore.getUpdatingArtifactWithFileName(libFilePath);
                deploymentStore.removeUpdatingArtifact(libFilePath);
                undeploySynapseArtifact(existingArtifactName);
                // deploy from beginning
                // add the library to synapse Config
                completeDeployment(lib, libArtifactName);
            } else {
                // new artifact hot-deployment case
                try {
                    // add the library to synapse Config
                    completeDeployment(lib, libArtifactName);
                } catch (SynapseArtifactDeploymentException sade) {
                    log.error("Deployment of the Synapse Artifact from file : " + libFilePath + " : Failed!", sade);
                /*
		     * log.info("The file has been backed up into : " +
		     * backupFile(deploymentFileData.getFile()));
		     */
                }
            }
            if (libArtifactName != null) {
                deploymentStore.addArtifact(libFilePath, libArtifactName);
            }
            log.info("Synapse Library named '" + lib.toString() + "' has been deployed from file : " + libFilePath);
        }
    } catch (IOException ex) {
        handleDeploymentError("Deployment of synapse artifact failed. Error reading " + libFilePath + " : " + ex.getMessage(), ex);
    } catch (Exception ex) {
        handleDeploymentError("Deployment of synapse artifact failed for synapse libray at : " + libFilePath + " : " + ex.getMessage(), ex);
    }
    if (log.isDebugEnabled()) {
        log.debug("Deployment of the synapse artifact from file : " + libFilePath + " : COMPLETED");
    }
}
Also used : Library(org.apache.synapse.libraries.model.Library) IOException(java.io.IOException) IOException(java.io.IOException) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 5 with Library

use of org.apache.synapse.libraries.model.Library in project wso2-synapse by wso2.

the class SynapseXMLConfigurationFactory method defineImport.

public static SynapseImport defineImport(SynapseConfiguration config, OMElement elt, Properties properties) {
    SynapseImport synImport = SynapseImportFactory.createImport(elt, properties);
    String libIndexString = LibDeployerUtils.getQualifiedName(synImport);
    config.addSynapseImport(libIndexString, synImport);
    // get corresponding library for loading imports if available
    Library synLib = config.getSynapseLibraries().get(libIndexString);
    if (synLib != null) {
        LibDeployerUtils.loadLibArtifacts(synImport, synLib);
    }
    return synImport;
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Library(org.apache.synapse.libraries.model.Library)

Aggregations

Library (org.apache.synapse.libraries.model.Library)8 DeploymentException (org.apache.axis2.deployment.DeploymentException)6 SynapseImport (org.apache.synapse.libraries.imports.SynapseImport)5 IOException (java.io.IOException)4 File (java.io.File)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 SynapseException (org.apache.synapse.SynapseException)1 EventPublisherMediatorFactory (org.apache.synapse.config.xml.eventing.EventPublisherMediatorFactory)1