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);
}
}
}
}
Aggregations