Search in sources :

Example 1 with AbstractSynapseArtifactDeployer

use of org.apache.synapse.deployers.AbstractSynapseArtifactDeployer in project carbon-mediation by wso2.

the class SynapseAppDeployer method undeployArtifactType.

/**
 * Un deploy a given artifact type
 * @param carbonApplication
 * @param axisConfig
 * @param artifacts
 */
private void undeployArtifactType(CarbonApplication carbonApplication, AxisConfiguration axisConfig, List<Artifact.Dependency> artifacts) {
    for (Artifact.Dependency dep : artifacts) {
        Artifact artifact = dep.getArtifact();
        if (!validateArtifact(artifact)) {
            continue;
        }
        Deployer deployer;
        String artifactDir = null;
        if (SynapseAppDeployerConstants.MEDIATOR_TYPE.endsWith(artifact.getType())) {
            deployer = getClassMediatorDeployer(axisConfig);
        } else if (SynapseAppDeployerConstants.SYNAPSE_LIBRARY_TYPE.equals(artifact.getType())) {
            deployer = getSynapseLibraryDeployer(axisConfig);
        } else {
            String artifactDirName = getArtifactDirName(artifact);
            if (artifactDirName == null) {
                continue;
            }
            deployer = getDeployer(axisConfig, artifactDirName);
            artifactDir = getArtifactDirPath(axisConfig, artifactDirName);
        }
        if (deployer != null && AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED.equals(artifact.getDeploymentStatus())) {
            String fileName = artifact.getFiles().get(0).getName();
            String artifactName = artifact.getName();
            String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
            File artifactInRepo = new File(artifactDir + File.separator + fileName);
            try {
                // version in its name in the synapse config (ex: MyAPI:v1 instead of MyAPI)
                if (SynapseAppDeployerConstants.API_TYPE.equals(artifact.getType())) {
                    Properties properties = new Properties();
                    SynapseArtifactDeploymentStore deploymentStore = getSynapseConfiguration(axisConfig).getArtifactDeploymentStore();
                    if (deploymentStore != null) {
                        properties.put(SynapseConstants.CLASS_MEDIATOR_LOADERS, deploymentStore.getClassMediatorClassLoaders());
                    }
                    artifactName = extractApiNameFromArtifact(artifact, fileName, properties);
                }
                if (SynapseAppDeployerConstants.MEDIATOR_TYPE.endsWith(artifact.getType())) {
                    if (deployer instanceof AbstractSynapseArtifactDeployer) {
                        ((AbstractSynapseArtifactDeployer) deployer).setCustomLog(carbonApplication.getAppName(), AppDeployerUtils.getTenantIdLogString(AppDeployerUtils.getTenantId()));
                    }
                    deployer.undeploy(artifactPath);
                } else if (SynapseAppDeployerConstants.SYNAPSE_LIBRARY_TYPE.equals(artifact.getType())) {
                    String libQName = getArtifactName(artifactPath, axisConfig);
                    deleteImport(libQName, axisConfig);
                    deployer.undeploy(artifactPath);
                } else if (SynapseAppDeployerConstants.SEQUENCE_TYPE.equals(artifact.getType()) && handleMainFaultSeqUndeployment(artifact, axisConfig)) {
                } else if (artifactInRepo.exists()) {
                    log.info("Deleting artifact at " + artifactInRepo.getAbsolutePath());
                    if (!artifactInRepo.delete()) {
                        log.error("Unable to delete " + artifactInRepo.getAbsolutePath());
                    }
                } else {
                    // use reflection to avoid having synapse as a dependency
                    Class[] paramString = new Class[1];
                    paramString[0] = String.class;
                    Method method = deployer.getClass().getDeclaredMethod("undeploySynapseArtifact", paramString);
                    method.invoke(deployer, artifactName);
                }
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_PENDING);
                File artifactFile = new File(artifactPath);
                if (artifactFile.exists() && !artifactFile.delete()) {
                    log.warn("Couldn't delete App artifact file : " + artifactPath);
                }
            } catch (Exception e) {
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                log.error("Error occured while trying to un deploy : " + artifactName);
            }
        }
    }
}
Also used : SynapseArtifactDeploymentStore(org.apache.synapse.deployers.SynapseArtifactDeploymentStore) Method(java.lang.reflect.Method) Properties(java.util.Properties) CappFile(org.wso2.carbon.application.deployer.config.CappFile) File(java.io.File) AbstractSynapseArtifactDeployer(org.apache.synapse.deployers.AbstractSynapseArtifactDeployer) Artifact(org.wso2.carbon.application.deployer.config.Artifact) Deployer(org.apache.axis2.deployment.Deployer) AbstractSynapseArtifactDeployer(org.apache.synapse.deployers.AbstractSynapseArtifactDeployer) LibraryArtifactDeployer(org.apache.synapse.deployers.LibraryArtifactDeployer) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentException(org.apache.axis2.deployment.DeploymentException) SynapseException(org.apache.synapse.SynapseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Properties (java.util.Properties)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 OMException (org.apache.axiom.om.OMException)1 Deployer (org.apache.axis2.deployment.Deployer)1 DeploymentException (org.apache.axis2.deployment.DeploymentException)1 SynapseException (org.apache.synapse.SynapseException)1 AbstractSynapseArtifactDeployer (org.apache.synapse.deployers.AbstractSynapseArtifactDeployer)1 LibraryArtifactDeployer (org.apache.synapse.deployers.LibraryArtifactDeployer)1 SynapseArtifactDeploymentStore (org.apache.synapse.deployers.SynapseArtifactDeploymentStore)1 Artifact (org.wso2.carbon.application.deployer.config.Artifact)1 CappFile (org.wso2.carbon.application.deployer.config.CappFile)1