Search in sources :

Example 1 with EnvironmentVariable

use of org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable in project jbosstools-openshift by jbosstools.

the class ManageEnvironmentVariablesWizard method performFinish.

@Override
public boolean performFinish() {
    new Job("Updating environment variables for deployment config " + dc.getName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                List<EnvironmentVariable> vars = model.getEnvironmentVariables();
                boolean modified = false;
                for (EnvironmentVariable var : vars) {
                    if (model.isEnvironmentVariableModified(var)) {
                        modified = true;
                        String value = var.getValue();
                        if (IEnvironmentVariablesPageModel.DELETED.equals(value)) {
                            dc.removeEnvironmentVariable(var.getKey());
                        } else {
                            dc.setEnvironmentVariable(var.getKey(), var.getValue());
                        }
                    }
                }
                if (modified) {
                    Connection conn = ConnectionsRegistryUtil.getConnectionFor(dc);
                    conn.updateResource(dc);
                }
            } catch (Exception e) {
                String message = "Unable to update environment variables for deployment config " + dc.getName();
                OpenShiftUIActivator.getDefault().getLogger().logError(message, e);
                return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) Connection(org.jboss.tools.openshift.core.connection.Connection) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) List(java.util.List) Job(org.eclipse.core.runtime.jobs.Job) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with EnvironmentVariable

use of org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method shouldInitializeContainerInfoFromRemoteDockerImage.

@Test
public void shouldInitializeContainerInfoFromRemoteDockerImage() throws IOException {
    // no Docker image on local
    when(dockerConnection.hasImage(JBOSS_INFINISPAN_SERVER_IMAGE, LATEST_TAG)).thenReturn(false);
    final IImageStreamImportCapability cap = Mockito.mock(IImageStreamImportCapability.class);
    when(project.supports(IImageStreamImportCapability.class)).thenReturn(true);
    when(project.getCapability(IImageStreamImportCapability.class)).thenReturn(cap);
    final IStatus status = Mockito.mock(IStatus.class);
    final IImageStreamImport streamImport = Mockito.mock(IImageStreamImport.class);
    final DockerImageURI dockerImageURI = new DockerImageURI(JBOSS_INFINISPAN_SERVER_URI);
    when(status.isSuccess()).thenReturn(true);
    when(cap.importImageMetadata(dockerImageURI)).thenReturn(streamImport);
    when(streamImport.getImageJsonFor(dockerImageURI.getTag())).thenReturn(getImageStreamImport("/resources/jboss_infinispan-server_ImageStreamImport.json"));
    when(streamImport.getImageStatus()).thenReturn(Arrays.asList(status));
    // when
    model.setImageName(JBOSS_INFINISPAN_SERVER_URI);
    final boolean result = model.initializeContainerInfo();
    // then
    assertThat(result).isTrue();
    assertThat(model.getEnvironmentVariables()).contains(new EnvironmentVariable("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"), new EnvironmentVariable("JAVA_HOME", "/usr/lib/jvm/java"), new EnvironmentVariable("INFINISPAN_SERVER_HOME", "/opt/jboss/infinispan-server"), new EnvironmentVariable("INFINISPAN_VERSION", "8.2.0.Final"));
    assertThat(model.getPortSpecs()).isEmpty();
    assertThat(model.getVolumes()).isEmpty();
}
Also used : IStatus(com.openshift.restclient.model.IStatus) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStreamImport(com.openshift.restclient.model.image.IImageStreamImport) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) IImageStreamImportCapability(com.openshift.restclient.capability.resources.IImageStreamImportCapability) Test(org.junit.Test)

Example 3 with EnvironmentVariable

use of org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method shouldInitializeContainerInfoFromRemoteDockerImageWithVolumes.

@Test
public void shouldInitializeContainerInfoFromRemoteDockerImageWithVolumes() throws IOException {
    // no Docker image on local
    when(dockerConnection.hasImage(JENKINS_IMAGE, LATEST_TAG)).thenReturn(false);
    final IImageStreamImportCapability cap = Mockito.mock(IImageStreamImportCapability.class);
    when(project.supports(IImageStreamImportCapability.class)).thenReturn(true);
    when(project.getCapability(IImageStreamImportCapability.class)).thenReturn(cap);
    final IStatus status = Mockito.mock(IStatus.class);
    final IImageStreamImport streamImport = Mockito.mock(IImageStreamImport.class);
    final DockerImageURI dockerImageURI = new DockerImageURI(JENKINS_IMAGE_URI);
    when(status.isSuccess()).thenReturn(true);
    when(cap.importImageMetadata(dockerImageURI)).thenReturn(streamImport);
    when(streamImport.getImageJsonFor(dockerImageURI.getTag())).thenReturn(getImageStreamImport("/resources/openshift3_jenkins_1_rhel7_ImageStreamImport.json"));
    when(streamImport.getImageStatus()).thenReturn(Arrays.asList(status));
    // when
    model.setImageName(JENKINS_IMAGE_URI);
    final boolean result = model.initializeContainerInfo();
    // then
    assertThat(result).isTrue();
    assertThat(model.getEnvironmentVariables()).contains(new EnvironmentVariable("PATH", "/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin"), new EnvironmentVariable("JENKINS_VERSION", "1.642"), new EnvironmentVariable("HOME", "/var/lib/jenkins"), new EnvironmentVariable("JENKINS_HOME", "/var/lib/jenkins"));
    assertThat(model.getPortSpecs()).contains(new PortSpecAdapter("50000-tcp", "TCP", 50000), new PortSpecAdapter("8080-tcp", "TCP", 8080));
    assertThat(model.getVolumes()).contains("/var/lib/jenkins");
}
Also used : IStatus(com.openshift.restclient.model.IStatus) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStreamImport(com.openshift.restclient.model.image.IImageStreamImport) PortSpecAdapter(org.jboss.tools.openshift.internal.core.models.PortSpecAdapter) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) IImageStreamImportCapability(com.openshift.restclient.capability.resources.IImageStreamImportCapability) Test(org.junit.Test)

Example 4 with EnvironmentVariable

use of org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method shouldInitializeContainerInfoFromLocalDockerImage.

@Test
public void shouldInitializeContainerInfoFromLocalDockerImage() {
    // assume Docker image is on local
    final IDockerImageInfo dockerImageInfo = Mockito.mock(IDockerImageInfo.class, Mockito.RETURNS_DEEP_STUBS);
    when(dockerConnection.hasImage(WILDFLY_IMAGE, LATEST_TAG)).thenReturn(true);
    when(dockerConnection.getImageInfo(WILDFLY_IMAGE_URI)).thenReturn(dockerImageInfo);
    when(dockerImageInfo.config().env()).thenReturn(Arrays.asList("foo1=bar1", "foo2=bar2"));
    when(dockerImageInfo.config().exposedPorts()).thenReturn(new HashSet<>(Arrays.asList("8080/tcp", "9990/tcp")));
    when(dockerImageInfo.config().volumes()).thenReturn(Collections.emptySet());
    when(dockerImageInfo.containerConfig()).thenReturn(null);
    mockSingleImage(dockerConnection, WILDFLY_IMAGE, LATEST_TAG);
    // when
    model.setImageName(WILDFLY_IMAGE_URI);
    final boolean result = model.initializeContainerInfo();
    // then
    assertThat(result).isTrue();
    assertThat(model.getEnvironmentVariables()).contains(new EnvironmentVariable("foo1", "bar1"), new EnvironmentVariable("foo2", "bar2"));
    assertThat(model.getPortSpecs()).contains(new PortSpecAdapter("8080/tcp"), new PortSpecAdapter("9990/tcp"));
}
Also used : PortSpecAdapter(org.jboss.tools.openshift.internal.core.models.PortSpecAdapter) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) Test(org.junit.Test)

Example 5 with EnvironmentVariable

use of org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method checkThatRemoveANonExistingEnvironmentVariableIsNotEffective.

@Test
public void checkThatRemoveANonExistingEnvironmentVariableIsNotEffective() {
    // assume Docker image is on local
    final IDockerImageInfo dockerImageInfo = Mockito.mock(IDockerImageInfo.class, Mockito.RETURNS_DEEP_STUBS);
    when(dockerConnection.hasImage(WILDFLY_IMAGE, LATEST_TAG)).thenReturn(true);
    when(dockerConnection.getImageInfo(WILDFLY_IMAGE_URI)).thenReturn(dockerImageInfo);
    when(dockerImageInfo.config().env()).thenReturn(Arrays.asList("V1=value1", "V2=value2"));
    when(dockerImageInfo.config().exposedPorts()).thenReturn(Collections.emptySet());
    when(dockerImageInfo.config().volumes()).thenReturn(Collections.emptySet());
    when(dockerImageInfo.containerConfig()).thenReturn(null);
    mockSingleImage(dockerConnection, WILDFLY_IMAGE, LATEST_TAG);
    // when
    model.setImageName(WILDFLY_IMAGE_URI);
    final boolean result = model.initializeContainerInfo();
    // then
    assertThat(result).isTrue();
    model.removeEnvironmentVariable(new EnvironmentVariable("V3", "value3"));
    assertThat(model.getEnvironmentVariables()).hasSize(2);
    assertThat(model.getEnvironmentVariables()).isEqualTo(Arrays.asList(new EnvironmentVariable("V1", "value1"), new EnvironmentVariable("V2", "value2")));
}
Also used : EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) Test(org.junit.Test)

Aggregations

EnvironmentVariable (org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable)7 Test (org.junit.Test)5 IDockerImageInfo (org.eclipse.linuxtools.docker.core.IDockerImageInfo)4 DockerImageURI (com.openshift.restclient.images.DockerImageURI)3 PortSpecAdapter (org.jboss.tools.openshift.internal.core.models.PortSpecAdapter)3 IImageStreamImportCapability (com.openshift.restclient.capability.resources.IImageStreamImportCapability)2 IStatus (com.openshift.restclient.model.IStatus)2 IImageStreamImport (com.openshift.restclient.model.image.IImageStreamImport)2 List (java.util.List)2 Connection (org.jboss.tools.openshift.core.connection.Connection)2 ResourceKind (com.openshift.restclient.ResourceKind)1 IPort (com.openshift.restclient.model.IPort)1 IProject (com.openshift.restclient.model.IProject)1 IServicePort (com.openshift.restclient.model.IServicePort)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1