Skip to content

Commit

Permalink
[JBIDE-23210] made sure deploying docker image is using selected proj
Browse files Browse the repository at this point in the history
  • Loading branch information
adietish committed Oct 3, 2016
1 parent c8aa38c commit 34141b6
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
connection = OpenShiftUIUtils.getExplorerDefaultConnection(Connection.class);
}

runWizard(HandlerUtil.getActiveWorkbenchWindow(event).getShell(), image, project,connection);
runWizard(HandlerUtil.getActiveWorkbenchWindow(event).getShell(), image, project, connection);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ protected void onPageActivated(final DataBindingContext dbc) {
((Composite) getControl()).layout(true, true);
}


@Override
protected void setupWizardPageSupport(DataBindingContext dbc) {
ParametrizableWizardPageSupport.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.jboss.tools.openshift.internal.ui.wizard.deployimage;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.databinding.Binding;
Expand Down Expand Up @@ -67,6 +66,7 @@
import org.jboss.tools.openshift.common.core.connection.IConnection;
import org.jboss.tools.openshift.common.core.utils.UrlUtils;
import org.jboss.tools.openshift.core.connection.Connection;
import org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob;
import org.jboss.tools.openshift.internal.common.ui.connection.ConnectionColumLabelProvider;
import org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter;
import org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater;
Expand Down Expand Up @@ -178,8 +178,32 @@ protected void onPageWillGetActivated(final Direction progress, final PageChangi
if(imageNameProposalAdapter != null) {
imageNameProposalAdapter.setEnabled(true);
}
if (Direction.FORWARDS == progress) {
loadResources(dbc);
}
}

private void loadResources(DataBindingContext dbc) {
Job job = new AbstractDelegatingMonitorJob("Loading projects...") {

@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
model.loadResources();
return Status.OK_STATUS;
} catch(Exception e) {
return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID,
NLS.bind("Unable to load the OpenShift projects from connection {0}.", model.getConnection()), e);
}
}
};
try {
WizardUtils.runInWizard(job, getContainer(), dbc);
} catch (InvocationTargetException | InterruptedException e) {
// swallowed on purpose
}
}

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
GridLayoutFactory.fillDefaults().numColumns(NUM_COLUMS)
Expand Down Expand Up @@ -668,9 +692,7 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
// reload projects to reflect changes that happened in
// projects wizard
if (newProjectWizard.getProject() != null) {
List<IProject> projects = new ArrayList<>(model.getProjects());
projects.add(newProjectWizard.getProject());
model.setProjects(projects);
model.addProject(newProjectWizard.getProject());
}
if (Dialog.OK == result) {
IProject selectedProject = newProjectWizard.getProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public DeployImageWizard(IDockerImage image, Connection connection, IProject pro
model.setImageName(getImageNameWithTag(image));
}
model.setStartedWithActiveConnection(isAuthorized);
model.initModel(connection, project, isAuthorized);

model.setConnection(connection);
model.setProject(project);

setNeedsProgressMonitor(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
import java.util.stream.Collectors;

import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerConnectionManagerListener2;
Expand All @@ -36,11 +32,9 @@
import org.jboss.tools.openshift.common.core.connection.ConnectionsRegistrySingleton;
import org.jboss.tools.openshift.core.ICommonAttributes;
import org.jboss.tools.openshift.core.connection.Connection;
import org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob;
import org.jboss.tools.openshift.internal.core.IDockerImageMetadata;
import org.jboss.tools.openshift.internal.core.models.PortSpecAdapter;
import org.jboss.tools.openshift.internal.core.util.OpenShiftProjectUtils;
import org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.internal.ui.dockerutils.DockerImageUtils;
import org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable;
import org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariablesPageModel;
Expand All @@ -55,19 +49,20 @@
/**
* The Wizard model to support deploying an image to OpenShift
* @author jeff.cantrill
* @author Andre Dietisheim
*
*/
public class DeployImageWizardModel
extends ResourceLabelsPageModel
implements IDeployImageParameters, IDockerConnectionManagerListener2, PropertyChangeListener{
implements IDeployImageParameters, IDockerConnectionManagerListener2, PropertyChangeListener {

private static final int DEFAULT_REPLICA_COUNT = 1;

private Connection connection;
private IProject project;
private String resourceName;
private String imageName;
private List<IProject> projects = Collections.emptyList();
private List<IProject> projects = new ArrayList<>();

private EnvironmentVariablesPageModel envModel = new EnvironmentVariablesPageModel();

Expand Down Expand Up @@ -110,16 +105,16 @@ public DeployImageWizardModel() {
public void dispose() {
super.dispose();
DockerConnectionManager.getInstance().removeConnectionManagerListener(this);
((EnvironmentVariablesPageModel)envModel).dispose();
connection = null;
project = null;
dockerConnection = null;
projects.clear();
volumes.clear();
portSpecs.clear();
((EnvironmentVariablesPageModel) envModel).dispose();
this.connection = null;
this.project = null;
this.dockerConnection = null;
this.projects.clear();
this.volumes.clear();
this.portSpecs.clear();
if(imagePorts != null) {
imagePorts.clear();
imagePorts = null;
this.imagePorts = null;
}
}

Expand Down Expand Up @@ -156,9 +151,9 @@ public List<IDockerConnection> getDockerConnections() {

@Override
public IDockerConnection getDockerConnection() {
if(dockerConnection == null) {
if (dockerConnection == null) {
List<IDockerConnection> all = getDockerConnections();
if(all.size() == 1) {
if (all.size() == 1) {
setDockerConnection(all.get(0));
}
}
Expand All @@ -180,72 +175,49 @@ public Connection getConnection() {
}
return connection;
}

/**
* Loads all projects for the given {@code connection} and sets this model's project from the given {@code project}.
* @param connection the connection from which the projects will be retrieved
* @param project the project to set in the model
*/
public void initModel(final Connection connection, final IProject project, boolean loadResources) {
firePropertyChange(PROPERTY_CONNECTION, this.connection, this.connection = connection);

private void initImageRegistry(Connection connection) {
if(connection == null) {
return;
}

initModelRegistry(connection);

if (loadResources) {
Job job = new AbstractDelegatingMonitorJob("Loading projects...") {

@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
List<IProject> projects = connection.getResources(ResourceKind.PROJECT);
setProjects(projects);
setProjectOrDefault(project);
return Status.OK_STATUS;
} catch (Exception e) {
return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID,
"Unable to load the OpenShift projects for the selected connection.", e);
}
}

};
job.schedule();
}
}

private void initModelRegistry(Connection connection) {
if(connection != null) {
setTargetRegistryLocation(
(String) connection.getExtendedProperties().get(ICommonAttributes.IMAGE_REGISTRY_URL_KEY));
setTargetRegistryUsername(connection.getUsername());
setTargetRegistryPassword(connection.getToken());
}
setTargetRegistryLocation(
(String) connection.getExtendedProperties().get(ICommonAttributes.IMAGE_REGISTRY_URL_KEY));
setTargetRegistryUsername(connection.getUsername());
setTargetRegistryPassword(connection.getToken());
}

@Override
public void setConnection(final Connection connection) {
initModel(connection, null, true);
firePropertyChange(PROPERTY_CONNECTION, this.connection, this.connection = connection);
initImageRegistry(connection);
}

@Override
public void setProjects(List<IProject> projects) {
if(projects == null) projects = Collections.emptyList();
firePropertyChange(PROPERTY_PROJECTS, this.projects, this.projects = projects);
if(!projects.isEmpty() && !projects.contains(getProject())) {
setProject(null);
}
if(projects.size() == 1) {
setProject(projects.iterator().next());
public void loadResources() {
List<IProject> projects = connection.getResources(ResourceKind.PROJECT);
setProjects(projects);
setProjectOrDefault(project);
}

protected void setProjects(List<IProject> projects) {
if(projects == null) {
projects = Collections.emptyList();
}
firePropertyChange(PROPERTY_PROJECTS, this.projects, this.projects = projects);
}

@Override
public List<IProject> getProjects() {
return projects;
}

@Override
public void addProject(IProject project) {
if (project == null) {
return;
}
projects.add(project);
}

@Override
public IProject getProject() {
return this.project;
Expand Down Expand Up @@ -659,8 +631,11 @@ public void changeEvent(int event) {
}
@Override
public void changeEvent(IDockerConnection connection, int event) {
if ((event == ADD_EVENT) || (event == REMOVE_EVENT)) {
firePropertyChange(PROPERTY_DOCKER_CONNECTIONS, dockerConnections, dockerConnections = Arrays.asList(DockerConnectionManager.getInstance().getConnections()));
if ((event == ADD_EVENT)
|| (event == REMOVE_EVENT)) {
firePropertyChange(PROPERTY_DOCKER_CONNECTIONS,
dockerConnections,
dockerConnections = Arrays.asList(DockerConnectionManager.getInstance().getConnections()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ public interface IDeployImagePageModel extends IConnectionAware<Connection>{
* @return
*/
List<IProject> getProjects();

void setProjects(List<IProject> projects);

/**
* Adds the given project to the list of projects in this model.
* Does nothing if the project is {@code null}.
*
* @param project the project that should be added
*/
void addProject(IProject project);

void setProjectsComparator(Comparator<IProject> comparator);

Expand All @@ -80,6 +86,7 @@ public interface IDeployImagePageModel extends IConnectionAware<Connection>{
* @return
*/
IProject getProject();

void setProject(IProject project);

/**
Expand Down Expand Up @@ -171,6 +178,8 @@ public interface IDeployImagePageModel extends IConnectionAware<Connection>{
*/
boolean initializeContainerInfo();

public void loadResources();

/**
* Free any resource
*/
Expand Down

0 comments on commit 34141b6

Please sign in to comment.