Search in sources :

Example 1 with DeploymentFileData

use of org.apache.axis2.deployment.repository.util.DeploymentFileData in project wso2-synapse by wso2.

the class ExtensionDeployer method deploy.

/**
 * This will be called when there is a change in the specified deployment
 * folder (in the axis2.xml) and this will load the relevant classes to the system and
 * register them with the MediatorFactoryFinder
 *
 * @param deploymentFileData - describes the updated file
 * @throws DeploymentException - in case an error on the deployment
 */
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
    log.info("Loading extensions from: " + deploymentFileData.getAbsolutePath());
    // get the context class loader for the later restore of the context class loader
    ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
    try {
        boolean isDirectory = deploymentFileData.getFile().isDirectory();
        deploymentFileData.setClassLoader(isDirectory, getClass().getClassLoader(), (File) cfgCtx.getAxisConfiguration().getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR), cfgCtx.getAxisConfiguration().isChildFirstClassLoading());
        DeploymentClassLoader urlCl = (DeploymentClassLoader) deploymentFileData.getClassLoader();
        Thread.currentThread().setContextClassLoader(urlCl);
        // StartupFactory registration
        for (StartupFactory factory : getProviders(StartupFactory.class, urlCl)) {
            QName tagQName = factory.getTagQName();
            Class<? extends StartupFactory> clazz = factory.getClass();
            StartupFinder finder = StartupFinder.getInstance();
            finder.getFactoryMap().put(tagQName, clazz);
            finder.getSerializerMap().put(tagQName, factory.getSerializerClass());
            log.info("Registered startup factory and serializer for " + tagQName);
        }
        // MediatorFactory registration
        for (MediatorFactory factory : getProviders(MediatorFactory.class, urlCl)) {
            QName tagQName = factory.getTagQName();
            Class<? extends MediatorFactory> clazz = factory.getClass();
            MediatorFactoryFinder.getInstance().getFactoryMap().put(tagQName, clazz);
            log.info("Registered mediator factory " + clazz.getName() + " for " + tagQName);
        }
        // MediatorSerializer registration
        for (MediatorSerializer serializer : getProviders(MediatorSerializer.class, urlCl)) {
            String mediatorClassName = serializer.getMediatorClassName();
            MediatorSerializerFinder.getInstance().getSerializerMap().put(mediatorClassName, serializer);
            log.info("Registered mediator serializer " + serializer.getClass().getName() + " for " + mediatorClassName);
        }
    } catch (IOException e) {
        handleException("I/O error in reading the mediator jar file", e);
    } catch (Exception e) {
        handleException("Error occurred while trying to deploy mediator jar file", e);
    } catch (Throwable t) {
        handleException("Error occurred while trying to deploy the mediator jar file", t);
    } finally {
        // restore the class loader back
        if (log.isDebugEnabled()) {
            log.debug("Restoring the context class loader to the original");
        }
        Thread.currentThread().setContextClassLoader(prevCl);
    }
}
Also used : QName(javax.xml.namespace.QName) StartupFinder(org.apache.synapse.config.xml.StartupFinder) IOException(java.io.IOException) StartupFactory(org.apache.synapse.config.xml.StartupFactory) IOException(java.io.IOException) DeploymentException(org.apache.axis2.deployment.DeploymentException) DeploymentClassLoader(org.apache.axis2.deployment.DeploymentClassLoader) MediatorSerializer(org.apache.synapse.config.xml.MediatorSerializer) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) DeploymentClassLoader(org.apache.axis2.deployment.DeploymentClassLoader) URLClassLoader(java.net.URLClassLoader)

Example 2 with DeploymentFileData

use of org.apache.axis2.deployment.repository.util.DeploymentFileData 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 3 with DeploymentFileData

use of org.apache.axis2.deployment.repository.util.DeploymentFileData 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)

Example 4 with DeploymentFileData

use of org.apache.axis2.deployment.repository.util.DeploymentFileData in project carbon-business-process by wso2.

the class BPMNDeployer method deploy.

/**
 * Deploys a given bpmn package in acitiviti bpmn engine.
 * @param deploymentFileData Provide information about the deployment file
 * @throws DeploymentException On failure , deployment exception is thrown
 */
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
    // Worker nodes cannot deploy BPMN packages, hence return
    if (isWorkerNode()) {
        return;
    }
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    log.info("Deploying BPMN archive " + deploymentFileData.getFile().getName() + " for tenant: " + tenantId);
    try {
        BPMNDeploymentContext deploymentContext = new BPMNDeploymentContext(tenantId);
        deploymentContext.setBpmnArchive(deploymentFileData.getFile());
        tenantRepository.deploy(deploymentContext);
    // log.info( "Deployment Status " + deploymentFileData.getFile() + " deployed = " + deployed );
    } catch (DeploymentException e) {
        String errorMessage = "Failed to deploy the archive: " + deploymentFileData.getAbsolutePath();
        throw new DeploymentException(errorMessage, e);
    }
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 5 with DeploymentFileData

use of org.apache.axis2.deployment.repository.util.DeploymentFileData 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)

Aggregations

DeploymentException (org.apache.axis2.deployment.DeploymentException)7 File (java.io.File)4 IOException (java.io.IOException)3 Deployer (org.apache.axis2.deployment.Deployer)3 DeploymentFileData (org.apache.axis2.deployment.repository.util.DeploymentFileData)3 Artifact (org.wso2.carbon.application.deployer.config.Artifact)3 CappFile (org.wso2.carbon.application.deployer.config.CappFile)3 InputStream (java.io.InputStream)1 URLClassLoader (java.net.URLClassLoader)1 Properties (java.util.Properties)1 QName (javax.xml.namespace.QName)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 OMElement (org.apache.axiom.om.OMElement)1 OMException (org.apache.axiom.om.OMException)1 StAXOMBuilder (org.apache.axiom.om.impl.builder.StAXOMBuilder)1 DeploymentClassLoader (org.apache.axis2.deployment.DeploymentClassLoader)1 MediatorFactory (org.apache.synapse.config.xml.MediatorFactory)1 MediatorSerializer (org.apache.synapse.config.xml.MediatorSerializer)1 StartupFactory (org.apache.synapse.config.xml.StartupFactory)1 StartupFinder (org.apache.synapse.config.xml.StartupFinder)1