CarbonAppPersistenceManager capm = getPersistenceManager(axisConfig);
String tenantId = AppDeployerUtils.getTenantIdString(axisConfig);
archPath = AppDeployerUtils.formatPath(archPath);
String fileName = archPath.substring(archPath.lastIndexOf('/') + 1);
//check whether this app already exists..
CarbonApplication existingApp = null;
for (CarbonApplication carbonApp : getCarbonApps(tenantId)) {
if (archPath.equals(carbonApp.getAppFilePath())) {
existingApp = carbonApp;
break;
}
}
//If the app already exists, check the last updated time and redeploy if needed.
//Return if not updated..
if (existingApp != null) {
File file = new File(archPath);
if (file.exists()) {
String hashValue = CarbonUtils.getMD5(CarbonUtils.getBytesFromFile(file));
String hashValueFromRegistry = capm.getHashValue(existingApp.getAppName());
if (hashValueFromRegistry != null && hashValueFromRegistry.equals(hashValue)) {
existingApp.setDeploymentCompleted(true);
return;
} else {
// we are going to do an update for the application
log.warn("Carbon Application : " + fileName + " has been updated. Removing" +
" the existing application and redeploying...");
// undeploy the existing one before proceeding
undeployCarbonApp(existingApp, axisConfig);
}
}
}
log.info("Deploying Carbon Application : " + fileName + "...");
CarbonApplication currentApp = new CarbonApplication();
currentApp.setAppFilePath(archPath);
String extractedPath = AppDeployerUtils.extractCarbonApp(archPath);
// Build the app configuration by providing the artifacts.xml path
ApplicationConfiguration appConfig = new ApplicationConfiguration(capm, extractedPath +
ApplicationConfiguration.ARTIFACTS_XML);
// If we don't have features (artifacts) for this server, ignore
if (appConfig.getApplicationArtifact().getDependencies().size() == 0) {
log.warn("No artifacts found to be deployed in this server. " +
"Ignoring Carbon Application : " + fileName);
return;
}
currentApp.setExtractedPath(extractedPath);
currentApp.setAppConfig(appConfig);
String appName = appConfig.getAppName();
if (appName == null) {
log.warn("No application name found in Carbon Application : " + fileName + ". Using " +
"the file name as the application name");
appName = fileName.substring(0, fileName.lastIndexOf("."));
}
if (appExists(appName, axisConfig)) {
String msg = "Carbon Application : " + appName + " already exists. Two applications " +
"can't have the same Id. Deployment aborted.";
log.error(msg);
throw new Exception(msg);
}
currentApp.setAppName(appName);
// lock.lock();
// try {
// installArtifactFeatures(currentApp);
// } catch (Exception e) {
// handleException("Failed to installed features for cApp : " + appName, e);
// } finally {
// lock.unlock();
// }
// deploy sub artifacts of this cApp
this.searchArtifacts(currentApp.getExtractedPath(), currentApp);
// If all dependencies are resolved, we deploy the entire app
if (isArtifactReadyToDeploy(currentApp.getAppConfig().getApplicationArtifact())) {
// persist the completed cApp into registry..
capm.persistCarbonApp(currentApp);
// send the CarbonApplication instance through the handler chain
for (AppDeploymentHandler handler : appDeploymentHandlers) {
handler.deployArtifacts(currentApp, axisConfig);
}
} else {
log.error("Some dependencies in cApp : " + appName + " were not satisfied. Check " +
"whether all dependent artifacts are included in cApp file : " + archPath);
return;
}
currentApp.setDeploymentCompleted(true);
this.addCarbonApp(tenantId, currentApp);
log.info("Successfully Deployed Carbon Application : " + currentApp.getAppName()
+ AppDeployerUtils.getTenantIdLogString(AppDeployerUtils.getTenantId(axisConfig)));
}