Search in sources :

Example 16 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project wso2-synapse by wso2.

the class AbstractSynapseArtifactDeployer method deploy.

/**
 * This method is called by the axis2 deployment framework and it performs a synapse artifact
 * specific yet common across all the artifacts, set of tasks and delegate the actual deployment
 * to the respective artifact deployers.
 *
 * @param deploymentFileData file to be used for the deployment
 * @throws org.apache.axis2.deployment.DeploymentException in-case of an error in deploying the file
 *
 * @see org.apache.synapse.deployers.AbstractSynapseArtifactDeployer#deploySynapseArtifact(org.apache.axiom.om.OMElement,
 * String,java.util.Properties)
 */
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
    if (getServerContextInformation().getServerState() != ServerState.STARTED) {
        // synapse server has not yet being started
        if (log.isDebugEnabled()) {
            log.debug("Skipped the artifact deployment (since the Synapse " + "server doesn't seem to be started yet), from file : " + deploymentFileData.getAbsolutePath());
        }
        return;
    }
    // CustomLogSetter.getInstance().setLogAppender(customLogContent);
    if (!isHotDeploymentEnabled()) {
        if (log.isDebugEnabled()) {
            log.debug("Hot deployment has been suspended - Ignoring");
        }
        return;
    }
    String filename = SynapseArtifactDeploymentStore.getNormalizedAbsolutePath(deploymentFileData.getAbsolutePath());
    if (log.isDebugEnabled()) {
        log.debug("Deployment of the synapse artifact from file : " + filename + " : STARTED");
    }
    SynapseArtifactDeploymentStore deploymentStore = getSynapseConfiguration().getArtifactDeploymentStore();
    // deploy it again
    if (deploymentStore.isRestoredFile(filename)) {
        if (log.isDebugEnabled()) {
            log.debug("Restored artifact detected with filename : " + filename);
        }
        // only one deployment trigger can happen after a restore and hence remove it from
        // restoredFiles at the first hit, allowing the further deployments/updates to take
        // place as usual
        deploymentStore.removeRestoredFile(filename);
        return;
    }
    try {
        InputStream in = FileUtils.openInputStream(new File(filename));
        try {
            // construct the xml element from the file, it has to be XML,
            // since all synapse artifacts are XML based
            OMElement element = new StAXOMBuilder(StAXUtils.createXMLStreamReader(in)).getDocumentElement();
            Properties properties = new Properties();
            properties.put(SynapseConstants.CLASS_MEDIATOR_LOADERS, deploymentStore.getClassMediatorClassLoaders());
            properties.put(SynapseConstants.RESOLVE_ROOT, getSynapseEnvironment().getServerContextInformation().getServerConfigurationInformation().getResolveRoot());
            String artifactName = null;
            if (deploymentStore.isUpdatingArtifact(filename)) {
                if (log.isDebugEnabled()) {
                    log.debug("Updating artifact detected with filename : " + filename);
                }
                // this is an hot-update case
                String existingArtifactName = deploymentStore.getUpdatingArtifactWithFileName(filename);
                deploymentStore.removeUpdatingArtifact(filename);
                try {
                    artifactName = updateSynapseArtifact(element, filename, existingArtifactName, properties);
                } catch (SynapseArtifactDeploymentException | OMException ex) {
                    log.error("Update of the Synapse Artifact from file : " + filename + " : Failed!", ex);
                    log.info("The updated file has been backed up into : " + backupFile(deploymentFileData.getFile()));
                    log.info("Restoring the existing artifact into the file : " + filename);
                    restoreSynapseArtifact(existingArtifactName);
                    deploymentStore.addArtifact(filename, existingArtifactName);
                    artifactName = existingArtifactName;
                    throw new DeploymentException(ex);
                }
            } else {
                // new artifact hot-deployment case
                try {
                    // update the existing sequences.
                    if (filename.matches(".*/main-\\d+\\.\\d+\\.\\d+\\.xml")) {
                        artifactName = updateDefaultSequence(filename, element, properties, deploymentStore.getMainSeqLstUpdatedFile(), deploymentStore);
                        String mainSeqFileName = filename.substring(filename.lastIndexOf(File.separator) + 1);
                        deploymentStore.setMainSeqLstUpdatedFile(mainSeqFileName);
                    } else if (filename.matches(".*/fault-\\d+\\.\\d+\\.\\d+\\.xml")) {
                        artifactName = updateDefaultSequence(filename, element, properties, deploymentStore.getFaultSeqLstUpdatedFile(), deploymentStore);
                        String faultSeqFileName = filename.substring(filename.lastIndexOf(File.separator) + 1);
                        deploymentStore.setFaultSeqLstUpdatedFile(faultSeqFileName);
                    } else {
                        artifactName = deploySynapseArtifact(element, filename, properties);
                    }
                // To avoid deployment of service when NoClassDefFoundError thrown while creating a mediator
                } catch (SynapseArtifactDeploymentException | NoClassDefFoundError e) {
                    log.error("Deployment of the Synapse Artifact from file : " + filename + " : Failed!", e);
                    log.info("The file has been backed up into : " + backupFile(deploymentFileData.getFile()));
                    throw new DeploymentException(e);
                }
            }
            if (artifactName != null) {
                deploymentStore.addArtifact(filename, artifactName);
            }
        } finally {
            in.close();
        }
    } catch (IOException ex) {
        handleDeploymentError("Deployment of synapse artifact failed. Error reading " + filename + " : " + ex.getMessage(), ex, filename);
        throw new DeploymentException(ex);
    } catch (XMLStreamException ex) {
        handleDeploymentError("Deployment of synapse artifact failed. Error parsing " + filename + " : " + ex.getMessage(), ex, filename);
        throw new DeploymentException(ex);
    } catch (OMException ex) {
        handleDeploymentError("Deployment of synapse artifact failed. Error parsing " + filename + " : " + ex.getMessage(), ex, filename);
        throw new DeploymentException(ex);
    }
    if (log.isDebugEnabled()) {
        log.debug("Deployment of the synapse artifact from file : " + filename + " : COMPLETED");
    }
}
Also used : InputStream(java.io.InputStream) OMElement(org.apache.axiom.om.OMElement) IOException(java.io.IOException) Properties(java.util.Properties) XMLStreamException(javax.xml.stream.XMLStreamException) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File) OMException(org.apache.axiom.om.OMException)

Example 17 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project wso2-synapse by wso2.

the class EndpointDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    Endpoint ep = EndpointFactory.getEndpointFromElement(artifactConfig, false, properties);
    CustomLogSetter.getInstance().setLogAppender((ep != null) ? ep.getArtifactContainerName() : "");
    if (log.isDebugEnabled()) {
        log.debug("Endpoint update from file : " + fileName + " has started");
    }
    try {
        if (ep == null) {
            handleSynapseArtifactDeploymentError("Endpoint update failed. The artifact " + "defined in the file: " + fileName + " is not a valid endpoint.");
            return null;
        }
        ep.setFileName(new File(fileName).getName());
        if (log.isDebugEnabled()) {
            log.debug("Endpoint: " + ep.getName() + " has been built from the file: " + fileName);
        }
        ep.init(getSynapseEnvironment());
        Endpoint existingEp = getSynapseConfiguration().getDefinedEndpoints().get(existingArtifactName);
        if (existingArtifactName.equals(ep.getName())) {
            getSynapseConfiguration().updateEndpoint(existingArtifactName, ep);
        } else {
            // The user has changed the name of the endpoint
            // We should add the updated endpoint as a new endpoint and remove the old one
            getSynapseConfiguration().addEndpoint(ep.getName(), ep);
            getSynapseConfiguration().removeEndpoint(existingArtifactName);
            log.info("Endpoint: " + existingArtifactName + " has been undeployed");
        }
        log.info("Endpoint: " + ep.getName() + " has been updated from the file: " + fileName);
        waitForCompletion();
        existingEp.destroy();
        if (existingArtifactName.equals(ep.getName())) {
            // If the endpoint name was same as the old one, above method call (destroy)
            // will unregister the endpoint MBean - So we should register it again.
            MBeanRegistrar.getInstance().registerMBean(ep.getMetricsMBean(), "Endpoint", ep.getName());
        }
        return ep.getName();
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the endpoint from the " + "file: " + fileName);
    }
    return null;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 18 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project wso2-synapse by wso2.

the class EventSourceDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("EventSource Update from file : " + fileName + " : Started");
    }
    try {
        SynapseEventSource es = EventSourceFactory.createEventSource(artifactConfig, properties);
        if (es != null) {
            es.setFileName((new File(fileName)).getName());
            if (log.isDebugEnabled()) {
                log.debug("EventSource named '" + es.getName() + "' has been built from the file " + fileName);
            }
            getSynapseConfiguration().removeEventSource(existingArtifactName);
            if (!existingArtifactName.equals(es.getName())) {
                log.info("EventSource named " + existingArtifactName + " has been Undeployed");
            }
            es.buildService(getSynapseConfiguration().getAxisConfiguration());
            if (log.isDebugEnabled()) {
                log.debug("Initialized the EventSource : " + es.getName());
            }
            getSynapseConfiguration().addEventSource(es.getName(), es);
            if (log.isDebugEnabled()) {
                log.debug("EventSource " + (existingArtifactName.equals(es.getName()) ? "update" : "deployment") + " from file : " + fileName + " : Completed");
            }
            log.info("EventSource named '" + es.getName() + "' has been " + (existingArtifactName.equals(es.getName()) ? "update" : "deployed") + " from file : " + fileName);
            return es.getName();
        } else {
            handleSynapseArtifactDeploymentError("EventSource Update Failed. The artifact " + "described in the file " + fileName + " is not a EventSource");
        }
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("EventSource Update from the file : " + fileName + " : Failed.", e);
    } catch (AxisFault e) {
        handleSynapseArtifactDeploymentError("Error while initializing the event source", e);
    }
    return null;
}
Also used : AxisFault(org.apache.axis2.AxisFault) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 19 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project wso2-synapse by wso2.

the class InboundEndpointDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Inbound Endpoint update from file : " + fileName + " has started");
    }
    try {
        /*properties are ignored*/
        InboundEndpoint inboundEndpoint = InboundEndpointFactory.createInboundEndpoint(artifactConfig, getSynapseConfiguration());
        if (inboundEndpoint == null) {
            handleSynapseArtifactDeploymentError("Inbound Endpoint update failed. The artifact " + "defined in the file: " + fileName + " is not a valid Inbound Endpoint.");
            return null;
        }
        CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName());
        inboundEndpoint.setFileName(new File(fileName).getName());
        inboundEndpoint.setArtifactContainerName(customLogContent);
        if (log.isDebugEnabled()) {
            log.debug("Inbound Endpoint: " + inboundEndpoint.getName() + " has been built from the file: " + fileName);
        }
        InboundEndpoint existingInboundEndpoint = getSynapseConfiguration().getInboundEndpoint(existingArtifactName);
        existingInboundEndpoint.destroy();
        inboundEndpoint.init(getSynapseEnvironment());
        if (existingArtifactName.equals(inboundEndpoint.getName())) {
            getSynapseConfiguration().updateInboundEndpoint(existingArtifactName, inboundEndpoint);
        } else {
            // The user has changed the name of the Inbound Endpoint
            // We should add the updated Inbound Endpoint as a new Inbound Endpoint and remove the old one
            getSynapseConfiguration().addInboundEndpoint(inboundEndpoint.getName(), inboundEndpoint);
            getSynapseConfiguration().removeInboundEndpoint(existingArtifactName);
            log.info("Inbound Endpoint: " + existingArtifactName + " has been undeployed");
        }
        log.info("Inbound Endpoint: " + inboundEndpoint.getName() + " has been updated from the file: " + fileName);
        waitForCompletion();
        return inboundEndpoint.getName();
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the Inbound Endpoint from the " + "file: " + fileName);
    }
    return null;
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 20 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project wso2-synapse by wso2.

the class LibraryArtifactDeployer method undeploy.

public void undeploy(String fileName) throws DeploymentException {
    fileName = FilenameUtils.normalize(fileName);
    if (log.isDebugEnabled()) {
        log.debug("UnDeployment of the synapse library from file : " + fileName + " : STARTED");
    }
    SynapseArtifactDeploymentStore deploymentStore = getSynapseConfiguration().getArtifactDeploymentStore();
    if (deploymentStore.containsFileName(fileName)) {
        File undeployingFile = new File(fileName);
        if (fileName.contains(File.separator + "tmp" + File.separator + "carbonapps" + File.separator) && fileName.endsWith(".zip")) {
            undeployingFile.delete();
        }
        // synapse artifacts which are being Hot-deployed
        if (undeployingFile.exists()) {
            if (log.isDebugEnabled()) {
                log.debug("Marking artifact as updating from file : " + fileName);
            }
            // Hot-Update case
            if (!deploymentStore.isRestoredFile(fileName)) {
                deploymentStore.addUpdatingArtifact(fileName, deploymentStore.getArtifactNameForFile(fileName));
                deploymentStore.removeArtifactWithFileName(fileName);
            }
        } else {
            // if the file doesn't exists then it is an actual undeployment
            String artifactName = deploymentStore.getArtifactNameForFile(fileName);
            try {
                // CarbonApplication instance to delete
                Library currentMediationLib = null;
                // undeploying the local entries
                Collection<Library> appList = getSynapseConfiguration().getSynapseLibraries().values();
                for (Library mediationLib : appList) {
                    if (artifactName.equals(mediationLib.getQName().toString())) {
                        currentMediationLib = mediationLib;
                    }
                }
                if (currentMediationLib != null) {
                    for (String localEntry : currentMediationLib.getLocalEntries()) {
                        getSynapseConfiguration().removeEntry(localEntry);
                    }
                }
                // do un-deployment
                undeploySynapseArtifact(artifactName);
                deploymentStore.removeArtifactWithFileName(fileName);
                log.info("Synapse Library named '" + artifactName + "' has been undeployed");
            } catch (SynapseArtifactDeploymentException sade) {
                log.error("Unable to undeploy the synapse library artifact from file : " + fileName, sade);
            }
        }
    } else {
        String msg = "Artifact representing the filename " + fileName + " is not deployed on Synapse";
        log.error(msg);
        throw new DeploymentException(msg);
    }
    if (log.isDebugEnabled()) {
        log.debug("UnDeployment of the synapse library artifact from file : " + fileName + " : COMPLETED");
    }
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException) Library(org.apache.synapse.libraries.model.Library) File(java.io.File)

Aggregations

DeploymentException (org.apache.axis2.deployment.DeploymentException)32 File (java.io.File)23 Deployer (org.apache.axis2.deployment.Deployer)6 Artifact (org.wso2.carbon.application.deployer.config.Artifact)6 CappFile (org.wso2.carbon.application.deployer.config.CappFile)6 IOException (java.io.IOException)4 AxisFault (org.apache.axis2.AxisFault)3 DeploymentFileData (org.apache.axis2.deployment.repository.util.DeploymentFileData)3 Library (org.apache.synapse.libraries.model.Library)3 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)3 QName (javax.xml.namespace.QName)2 OMElement (org.apache.axiom.om.OMElement)2 Mediator (org.apache.synapse.Mediator)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ZipInputStream (java.util.zip.ZipInputStream)1 XMLStreamException (javax.xml.stream.XMLStreamException)1