[jbosstools-commits] JBoss Tools SVN: r39772 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Mar 22 11:33:08 EDT 2012


Author: xcoulon
Date: 2012-03-22 11:33:07 -0400 (Thu, 22 Mar 2012)
New Revision: 39772

Modified:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizard.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java
Log:
Fixed - JBIDE-11361
Increase OpenShift wizards timeouts

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizard.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizard.java	2012-03-22 15:01:58 UTC (rev 39771)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizard.java	2012-03-22 15:33:07 UTC (rev 39772)
@@ -169,12 +169,14 @@
 	private boolean createApplication() {
 		try {
 			final String applicationName = wizardModel.getApplicationName();
+			final DelegatingProgressMonitor delegatingMonitor = new DelegatingProgressMonitor();
 			IStatus status = WizardUtils.runInWizard(
 					new Job(NLS.bind("Creating application \"{0}\"...", applicationName)) {
 						@Override
 						protected IStatus run(IProgressMonitor monitor) {
 							try {
-								getWizardModel().createApplication(monitor);
+								delegatingMonitor.add(monitor);
+								getWizardModel().createApplication(delegatingMonitor);
 								return Status.OK_STATUS;
 							} catch (OpenShiftEndpointException e) {
 								// TODO: refresh user
@@ -187,7 +189,7 @@
 							}
 						}
 
-					}, null, getContainer(), 300);
+					}, delegatingMonitor, getContainer(), 300);
 			return status.isOK();
 		} catch (Exception e) {
 			return false;
@@ -323,4 +325,5 @@
 	public void dispose() {
 		wizardModel.dispose();
 	}
+
 }

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java	2012-03-22 15:01:58 UTC (rev 39771)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java	2012-03-22 15:33:07 UTC (rev 39772)
@@ -8,6 +8,10 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
@@ -24,6 +28,7 @@
 import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
 import org.jboss.tools.openshift.express.internal.core.console.UserModel;
 import org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages;
+import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
 import org.jboss.tools.openshift.express.internal.ui.wizard.appimport.ConfigureGitSharedProject;
 import org.jboss.tools.openshift.express.internal.ui.wizard.appimport.ConfigureUnsharedProject;
 import org.jboss.tools.openshift.express.internal.ui.wizard.appimport.ImportNewProject;
@@ -39,7 +44,7 @@
 
 	protected HashMap<String, Object> dataModel = new HashMap<String, Object>();
 
-	private static final int APP_CREATION_TIMEOUT = 120;
+	private static final int APP_CREATION_TIMEOUT = 180;
 	private static final String KEY_SELECTED_EMBEDDABLE_CARTRIDGES = "selectedEmbeddableCartridges";
 
 	public OpenShiftExpressApplicationWizardModel(UserDelegate user) {
@@ -163,13 +168,14 @@
 
 	private void createServerAdapter(IProgressMonitor monitor, List<IProject> importedProjects)
 			throws OpenShiftException {
-		if (isCreateServerAdapter()) {
+		Assert.isTrue(importedProjects.size() > 0);
+		if (isCreateServerAdapter()) {	
 			Assert.isTrue(importedProjects.size() > 0);
 			IProject project = importedProjects.get(0);
 			new ServerAdapterFactory().create(project, this, monitor);
 		}
 	}
-
+	
 	@Override
 	public File getRepositoryFile() {
 		String repositoryPath = getRepositoryPath();
@@ -346,15 +352,45 @@
 		}
 	}
 
-	protected IApplication createApplication(String name, ICartridge cartridge, IProgressMonitor monitor)
+	protected IApplication createApplication(final String name, final ICartridge cartridge, final IProgressMonitor monitor)
 			throws OpenShiftApplicationNotAvailableException, OpenShiftException {
-		UserDelegate user = getUser();
+		final UserDelegate user = getUser();
 		if (user == null) {
 			throw new OpenShiftException("Could not create application, have no valid user credentials");
 		}
-		IApplication application = user.createApplication(name, cartridge);
-		waitForAccessible(application, monitor);
-		return application;
+		ExecutorService executor = Executors.newFixedThreadPool(1);
+		try {
+			FutureTask<IApplication> future = new FutureTask<IApplication>(
+					new Callable<IApplication>() {
+						@Override
+						public IApplication call() throws Exception {
+							monitor.setTaskName("Creating application \"" + name + "\"...");
+							Logger.debug("creating application...");
+							final IApplication application
+							= user.createApplication(name, cartridge);
+							monitor.beginTask("Waiting for application to be reachable...",
+									IProgressMonitor.UNKNOWN);
+							Logger.debug("Waiting for application to be reachable...");
+							waitForAccessible(application, monitor);
+							return application;
+						}
+					});
+			executor.execute(future);
+			while (!future.isDone()) {
+				if(monitor.isCanceled()) {
+					throw new OpenShiftException("Operation was cancelled by user.");
+				}
+				Thread.sleep(1000);
+			}
+			final IApplication application = future.get();
+			return application;
+		} catch (Exception e) { // InterruptedException and ExecutionException
+			Throwable cause = e.getCause() !=null ?e.getCause() : e;
+			Logger.error("Failed to create application", cause);
+			throw new OpenShiftException("Failed to create application: {0}", cause.getMessage());
+		} finally {
+			executor.shutdown();
+		}
 	}
 
 	public void createApplication(IProgressMonitor monitor) throws OpenShiftApplicationNotAvailableException,



More information about the jbosstools-commits mailing list