Search in sources :

Example 6 with DeploymentException

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

the class PriorityExecutorDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("PriorityExecutor update from file : " + fileName + " has started");
    }
    try {
        PriorityExecutor e = PriorityExecutorFactory.createExecutor(SynapseConstants.SYNAPSE_NAMESPACE, artifactConfig, true, properties);
        if (e == null) {
            handleSynapseArtifactDeploymentError("PriorityExecutor update failed. The artifact " + "defined in the file: " + fileName + " is not a valid executor.");
            return null;
        }
        e.setFileName(new File(fileName).getName());
        if (log.isDebugEnabled()) {
            log.debug("Executor: " + e.getName() + " has been built from the file: " + fileName);
        }
        e.init();
        PriorityExecutor existingExecutor = getSynapseConfiguration().getPriorityExecutors().get(existingArtifactName);
        if (existingArtifactName.equals(e.getName())) {
            getSynapseConfiguration().updatePriorityExecutor(existingArtifactName, e);
        } else {
            // The user has changed the name of the executor
            // We should add the updated executor as a new executor and remove the old one
            getSynapseConfiguration().addPriorityExecutor(e.getName(), e);
            getSynapseConfiguration().removeExecutor(existingArtifactName);
            log.info("Executor: " + existingArtifactName + " has been undeployed");
        }
        waitForCompletion();
        existingExecutor.destroy();
        log.info("PriorityExecutor: " + e.getName() + " has been updated from the file: " + fileName);
        return e.getName();
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the executor from the " + "file: " + fileName);
    } catch (AxisFault e) {
        handleSynapseArtifactDeploymentError("Error while creating the executor from the " + "configuration in file: " + fileName);
    }
    return null;
}
Also used : AxisFault(org.apache.axis2.AxisFault) DeploymentException(org.apache.axis2.deployment.DeploymentException) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) File(java.io.File)

Example 7 with DeploymentException

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

the class SequenceDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    Mediator m = MediatorFactoryFinder.getInstance().getMediator(artifactConfig, properties);
    CustomLogSetter.getInstance().setLogAppender((m != null) ? ((SequenceMediator) m).getArtifactContainerName() : "");
    if (log.isDebugEnabled()) {
        log.debug("Sequence update from file : " + fileName + " has started");
    }
    try {
        if (m == null || !(m instanceof SequenceMediator)) {
            handleSynapseArtifactDeploymentError("Sequence update failed. The artifact " + "defined in the file: " + fileName + " is not a valid sequence.");
            return null;
        }
        SequenceMediator seq = (SequenceMediator) m;
        seq.setFileName(new File(fileName).getName());
        if ((SynapseConstants.MAIN_SEQUENCE_KEY.equals(existingArtifactName) || SynapseConstants.FAULT_SEQUENCE_KEY.equals(existingArtifactName)) && !existingArtifactName.equals(seq.getName())) {
            handleSynapseArtifactDeploymentError(existingArtifactName + " sequence cannot be renamed");
        }
        if (log.isDebugEnabled()) {
            log.debug("Sequence: " + seq.getName() + " has been built from the file: " + fileName);
        }
        seq.init(getSynapseEnvironment());
        SequenceMediator existingSeq = getSynapseConfiguration().getDefinedSequences().get(existingArtifactName);
        if (existingArtifactName.equals(seq.getName())) {
            getSynapseConfiguration().updateSequence(existingArtifactName, seq);
        } else {
            getSynapseConfiguration().addSequence(seq.getName(), seq);
            getSynapseConfiguration().removeSequence(existingArtifactName);
            log.info("Sequence: " + existingArtifactName + " has been undeployed");
        }
        log.info("Sequence: " + seq.getName() + " has been updated from the file: " + fileName);
        // Give some time for worker threads to release the old sequence
        waitForCompletion();
        existingSeq.destroy();
        return seq.getName();
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the sequence from the " + "file: " + fileName);
    }
    return null;
}
Also used : Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) DeploymentException(org.apache.axis2.deployment.DeploymentException) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) File(java.io.File)

Example 8 with DeploymentException

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

the class TemplateDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Template update from file : " + fileName + " has started");
    }
    try {
        OMElement element = artifactConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "endpoint"));
        if (element != null) {
            org.apache.synapse.config.xml.endpoints.TemplateFactory templateFactory = new org.apache.synapse.config.xml.endpoints.TemplateFactory();
            Template tm = templateFactory.createEndpointTemplate(artifactConfig, properties);
            tm.setFileName(new File(fileName).getName());
            if (log.isDebugEnabled()) {
                log.debug("Endpoint Template named '" + tm.getName() + "' has been built from the file " + fileName);
            }
            Template existingSt = getSynapseConfiguration().getEndpointTemplate(existingArtifactName);
            if (existingArtifactName.equals(tm.getName())) {
                getSynapseConfiguration().updateEndpointTemplate(tm.getName(), tm);
            } else {
                getSynapseConfiguration().addEndpointTemplate(tm.getName(), tm);
                getSynapseConfiguration().removeEndpointTemplate(existingSt.getName());
                log.info("Template: " + existingArtifactName + " has been undeployed");
            }
            log.info("Template: " + tm.getName() + " has been updated from the file: " + fileName);
            return tm.getName();
        } else {
            element = artifactConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sequence"));
            if (element != null) {
                Mediator mediator = MediatorFactoryFinder.getInstance().getMediator(artifactConfig, properties);
                if (mediator instanceof TemplateMediator) {
                    TemplateMediator tm = (TemplateMediator) mediator;
                    tm.setFileName((new File(fileName)).getName());
                    if (log.isDebugEnabled()) {
                        log.debug("Sequence Template named '" + tm.getName() + "' has been built from the file " + fileName);
                    }
                    tm.init(getSynapseEnvironment());
                    if (log.isDebugEnabled()) {
                        log.debug("Initialized the Template : " + tm.getName());
                    }
                    TemplateMediator existingSt = getSynapseConfiguration().getSequenceTemplate(existingArtifactName);
                    if (existingArtifactName.equals(tm.getName())) {
                        getSynapseConfiguration().updateSequenceTemplate(tm.getName(), tm);
                    } else {
                        getSynapseConfiguration().addSequenceTemplate(tm.getName(), tm);
                        getSynapseConfiguration().removeSequenceTemplate(existingSt.getName());
                        log.info("Template: " + existingArtifactName + " has been undeployed");
                    }
                    existingSt.destroy();
                    log.info("Template: " + tm.getName() + " has been updated from the file: " + fileName);
                    return tm.getName();
                }
            }
        }
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the Template from the " + "file: " + fileName);
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) Template(org.apache.synapse.endpoints.Template) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) Mediator(org.apache.synapse.Mediator) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 9 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project carbon-business-process by wso2.

the class BPMNAppDeployer method undeployArtifacts.

/**
 * Check the artifact type and if it is a BPMN, delete the file from the BPMN
 * deployment hot folder
 *
 * @param carbonApp  - CarbonApplication instance to check for BPMN artifacts
 * @param axisConfig - - axisConfig of the current tenant
 */
public void undeployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) {
    List<Artifact.Dependency> artifacts = carbonApp.getAppConfig().getApplicationArtifact().getDependencies();
    // loop through all dependencies
    for (Artifact.Dependency dep : artifacts) {
        Deployer deployer;
        Artifact artifact = dep.getArtifact();
        if (artifact == null) {
            continue;
        }
        if (BPMN_TYPE.equals(artifact.getType())) {
            deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, BPMN_DIR, "bar");
        } else {
            continue;
        }
        List<CappFile> files = artifact.getFiles();
        if (files.size() != 1) {
            log.error("A BPMN artifact must have a single file. But " + files.size() + " files found.");
            continue;
        }
        if (deployer != null && AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED.equals(artifact.getDeploymentStatus())) {
            String fileName = artifact.getFiles().get(0).getName();
            String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
            try {
                deployer.undeploy(artifactPath);
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_PENDING);
            } catch (DeploymentException e) {
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                log.error("Error occured while trying to un deploy : " + artifact.getName());
            }
        }
    }
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException) Artifact(org.wso2.carbon.application.deployer.config.Artifact) Deployer(org.apache.axis2.deployment.Deployer) CappFile(org.wso2.carbon.application.deployer.config.CappFile)

Example 10 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project carbon-business-process by wso2.

the class HumanTaskAppDeployer method deployArtifacts.

/**
 * Check the artifact type and if it is a HumanTask artifact, copy it to the HumanTask deployment hot folder
 *
 * @param carbonApp  - CarbonApplication instance to check for HumanTask artifacts
 * @param axisConfig - AxisConfiguration of the current tenant
 */
public void deployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) throws DeploymentException {
    List<Artifact.Dependency> artifacts = carbonApp.getAppConfig().getApplicationArtifact().getDependencies();
    // loop through all dependencies
    for (Artifact.Dependency dep : artifacts) {
        Deployer deployer;
        Artifact artifact = dep.getArtifact();
        if (artifact == null) {
            continue;
        }
        if (!isAccepted(artifact.getType())) {
            log.warn("Can't deploy artifact : " + artifact.getName() + " of type : " + artifact.getType() + ". Required features are not installed in the system");
            continue;
        }
        if (HUMANTASK_TYPE.equals(artifact.getType())) {
            deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, HUMANTASK_DIR, "zip");
        } else {
            continue;
        }
        List<CappFile> files = artifact.getFiles();
        if (files.size() != 1) {
            log.error("HumanTask artifacts must have a single file to " + "be deployed. But " + files.size() + " files found.");
            continue;
        }
        if (deployer != null) {
            String fileName = artifact.getFiles().get(0).getName();
            String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
            try {
                deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
                File artifactFile = new File(artifactPath);
                if (artifactFile.exists() && !artifactFile.delete()) {
                    log.warn("Couldn't delete App artifact file : " + artifactPath);
                }
            } catch (DeploymentException e) {
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                throw e;
            }
        }
    }
}
Also used : DeploymentFileData(org.apache.axis2.deployment.repository.util.DeploymentFileData) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File) CappFile(org.wso2.carbon.application.deployer.config.CappFile) Artifact(org.wso2.carbon.application.deployer.config.Artifact) Deployer(org.apache.axis2.deployment.Deployer) CappFile(org.wso2.carbon.application.deployer.config.CappFile)

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