}
@Override
protected void performDeployment(CloudFoundryApplicationModule appModule, IProgressMonitor monitor)
throws CoreException {
final Server server = (Server) getServer();
final CloudFoundryServer cloudServer = getCloudFoundryServer();
final IModule module = modules[0];
try {
// Update the local cloud module representing the application
// first.
appModule.setErrorStatus(null);
server.setModuleState(modules, IServer.STATE_STARTING);
final String deploymentName = appModule.getDeploymentInfo().getDeploymentName();
// This request does three things:
// 1. Checks if the application external or mapped to a local
// project. If mapped to a local project
// it creates an archive of the application's content
// 2. If an archive file was created, it pushes the archive
// file.
// 3. While pushing the archive file, a check is made to see if
// the application exists remotely. If not, the application is
// created in the
// CF server.
if (!modules[0].isExternal()) {
printlnToConsole(appModule, Messages.CONSOLE_GENERATING_ARCHIVE);
final ApplicationArchive applicationArchive = generateApplicationArchiveFile(
appModule.getDeploymentInfo(), appModule, modules, server, incrementalPublish, monitor);
File warFile = null;
if (applicationArchive == null) {
// Create a full war archive
warFile = CloudUtil.createWarFile(modules, server, monitor);
if (warFile == null || !warFile.exists()) {
throw new CoreException(new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID,
"Unable to create war file for application: " + deploymentName)); //$NON-NLS-1$
}
CloudFoundryPlugin.trace("War file " + warFile.getName() + " created"); //$NON-NLS-1$ //$NON-NLS-2$
}
// Tell webtools the module has been published
setModulePublishState(modules, IServer.PUBLISH_STATE_NONE);
// update server publish status
IModule[] serverModules = server.getModules();
boolean allSynched = true;
for (IModule serverModule : serverModules) {
int modulePublishState = server.getModulePublishState(new IModule[] { serverModule });
if (modulePublishState == IServer.PUBLISH_STATE_INCREMENTAL
|| modulePublishState == IServer.PUBLISH_STATE_FULL) {
allSynched = false;
}
}
if (allSynched) {
server.setServerPublishState(IServer.PUBLISH_STATE_NONE);
}
final File warFileFin = warFile;
final CloudFoundryApplicationModule appModuleFin = appModule;
// Now push the application resources to the server
new BehaviourRequest<Void>("Pushing the application " + deploymentName) { //$NON-NLS-1$
@Override
protected Void doRun(final CloudFoundryOperations client, SubMonitor progress)
throws CoreException {
pushApplication(client, appModuleFin, warFileFin, applicationArchive, progress);
CloudFoundryPlugin.trace("Application " + deploymentName //$NON-NLS-1$
+ " pushed to Cloud Foundry server."); //$NON-NLS-1$
cloudServer.tagAsDeployed(module);
return null;
}
}.run(monitor);
printlnToConsole(appModule, Messages.CONSOLE_APP_PUSHED_MESSAGE);
}
// Verify the application exists in the server
CloudApplication application = getDeployedCloudApplication(client,
appModule.getDeployedApplicationName(), monitor);
if (application == null) {
throw CloudErrorUtil
.toCoreException("No cloud application obtained from the Cloud Foundry server for : " //$NON-NLS-1$
+ appModule.getDeployedApplicationName()
+ ". Application may not have deployed correctly to the Cloud Foundry server, or there are connection problems to the server."); //$NON-NLS-1$
}
// At this stage, the app is either created or it already
// exists.
// Set the environment variables BEFORE starting the app, and
// BEFORE updating
// the cloud application mapping in the module, which will
// replace the deployment info
updateEnvironmentVariables(appModule, monitor);
// Update instances if it is more than 1. By default, app starts
// with 1 instance.
int instances = appModule.getDeploymentInfo().getInstances();
if (instances > 1) {
updateApplicationInstances(appModule, instances, monitor);
}
// If reached here it means the application creation and content
// pushing probably succeeded without errors, therefore attempt
// to
// start the application
super.performDeployment(appModule, monitor);
}
catch (CoreException e) {
appModule.setErrorStatus(e);
server.setModulePublishState(modules, IServer.PUBLISH_STATE_UNKNOWN);
throw e;
}
}