Friday, June 28, 2013

CarbonApp Deployment Process


In this artical I will discuss about the deployment process of CApp artifacts. CApp namly CarbonApplication Deployer is an collection of different artifacts bundled to a single deployable component. When deploying a CApp on any WSO2 product it directly deploy all the relevent artifacts for the product by calling the relevant artifact deployers programmatically. This will be done by the CAppDeployer when the corresponding CApp get deployed. According to this process the deployment of the artifacts will be synchronous and the artifact deployment will be atomic. So if the CApp successfully deployed we can guarantee that all the artifacts have successfully deployed.



Steps involved during deployment of CarbonApp,
  • Artifacts inside CApp get extracted to temp location
  • CAppDeployer then call the relevant deployer based on the artifact and deploy the artifacts
  • When the CApp get deployed all its artifacts are up and running


The sample code to the new implementation is shown in the below segments. In this case I have given the example code for webapp deployment. The deployment of the other artifacts will be in same fashion except synapse artifacts.


package org.wso2.carbon.application.deployer.webapp

/**
*  Check the artifact type and if it is a WAR, copy it to the WAR deployment hot folder
*/

List<Artifact.Dependency> artifacts = carbonApp.getAppConfig().getApplicationArtifact().getDependencies();

// loop through all artifacts and deploy them iteratively
for (Artifact.Dependency dep : artifacts) {
Deployer deployer;
Artifact artifact = dep.getArtifact();
if (artifact == null) {
continue;
}

/**
* for each service type, select the correct deployer
* for this we need to provide the relevent deployment directory on carbon server and the extension of the artifact
* these details are read from the configurations for the corresponding artifact type
* since webapps may have two artifact types we should get the correct deployer
*/
if (WAR_TYPE.equals(artifact.getType())) {
deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, WAR_DIR, "war");
} else if (JAX_WAR_TYPE.equals(artifact.getType())) {
deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, JAX_WAR_DIR, "war");
} else {
continue;
}

// once the deployer get called we execute the webapp deployer to deploy
if (deployer != null) {
String fileName = artifact.getFiles().get(0).getName();
String artifactPath = artifact.getExtractedPath() + File.separator + fileName; // extracted path is our artifact extracted temp location . this details is available is the artifact
try {
// deploy the artifact
deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
// set the deployment state artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
} catch (DeploymentException e) {
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
throw e;
}
}


package org.wso2.carbon.application.deployer

/**
* Finds the correct deployer for the given directory and extension
*
* @param axisConfig - AxisConfiguration instance
* @param directory - Directory to retrieve the deployer
* @param extension - Extension of the deployable artifact
* @return Deployer instance
*
*/
public static Deployer getArtifactDeployer(AxisConfiguration axisConfig, String directory, String extension) {
// access the deployment engine through axis config
DeploymentEngine deploymentEngine = (DeploymentEngine) axisConfig.getConfigurator();
return deploymentEngine.getDeployer(directory, extension); // return the corresponding deployer to the required artifact type
}

No comments:

Post a Comment