Index: src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizard.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizard.java (revision 39655) +++ src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizard.java (working copy) @@ -187,12 +187,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 @@ -205,7 +207,7 @@ } } - }, null, getContainer(), 300); + }, delegatingMonitor, getContainer(), 300); return status.isOK(); } catch (Exception e) { return false; Index: src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java (revision 39655) +++ src/org/jboss/tools/openshift/express/internal/ui/wizard/OpenShiftExpressApplicationWizardModel.java (working copy) @@ -8,6 +8,11 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +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 +29,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; @@ -40,7 +46,7 @@ protected HashMap dataModel = new HashMap(); - 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, IProject project, IApplication application, boolean useExistingApplication) { @@ -326,7 +332,8 @@ @Override public boolean setUseExistingApplication(boolean useExistingApplication) { - Boolean isUseExistingApplication = (Boolean) setProperty(USE_EXISTING_APPLICATION, useExistingApplication); + Boolean isUseExistingApplication = (Boolean) setProperty( + USE_EXISTING_APPLICATION, useExistingApplication); return isUseExistingApplication != null && isUseExistingApplication; } @@ -334,29 +341,66 @@ setUseExistingApplication(application != null); } - private void waitForAccessible(IApplication application, IProgressMonitor monitor) - throws OpenShiftApplicationNotAvailableException, OpenShiftException { - // monitor.subTask("waiting for application to become accessible..."); + private void waitForAccessible(IApplication application, + IProgressMonitor monitor) + throws OpenShiftApplicationNotAvailableException, + OpenShiftException { if (!application.waitForAccessible(APP_CREATION_TIMEOUT * 1000)) { throw new OpenShiftApplicationNotAvailableException(NLS.bind( - OpenShiftExpressUIMessages.HOSTNAME_NOT_ANSWERING, application.getApplicationUrl())); + OpenShiftExpressUIMessages.HOSTNAME_NOT_ANSWERING, + application.getApplicationUrl())); } } - protected IApplication createApplication(String name, ICartridge cartridge, IProgressMonitor monitor) - throws OpenShiftApplicationNotAvailableException, OpenShiftException { - IUser user = getUser(); + protected IApplication createApplication(final String name, + final ICartridge cartridge, final IProgressMonitor monitor) + throws OpenShiftApplicationNotAvailableException, + OpenShiftException { + final IUser user = getUser(); if (user == null) { - throw new OpenShiftException("Could not create application, have no valid user credentials"); + throw new OpenShiftException( + "Could not create application, have no valid user credentials"); } - IApplication application = user.createApplication(name, cartridge); - waitForAccessible(application, monitor); - return application; + try { + ExecutorService executor = Executors.newFixedThreadPool(1); + FutureTask future = new FutureTask( + new Callable() { + @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 (InterruptedException e) { + Logger.error("Failed to monitor application creation", e); + throw new OpenShiftException(e, "Failed to monitor application creation"); + } catch (ExecutionException e) { + Logger.error("Failed to monitor application creation", e); + throw new OpenShiftException(e, "Failed to monitor application creation"); + } } - public void createApplication(IProgressMonitor monitor) throws OpenShiftApplicationNotAvailableException, + public void createApplication(IProgressMonitor monitor) + throws OpenShiftApplicationNotAvailableException, OpenShiftException { - IApplication application = createApplication(getApplicationName(), getApplicationCartridge(), monitor); + IApplication application = createApplication(getApplicationName(), + getApplicationCartridge(), monitor); setApplication(application); } @@ -364,7 +408,7 @@ public Set getSelectedEmbeddableCartridges() { @SuppressWarnings("unchecked") Set selectedEmbeddableCartridges = - (Set) getProperty(KEY_SELECTED_EMBEDDABLE_CARTRIDGES); + (Set) getProperty(KEY_SELECTED_EMBEDDABLE_CARTRIDGES); if (selectedEmbeddableCartridges == null) { selectedEmbeddableCartridges = new HashSet(); setSelectedEmbeddableCartridges(selectedEmbeddableCartridges);