Search in sources :

Example 1 with IContainer

use of com.openshift.restclient.model.IContainer in project jbosstools-openshift by jbosstools.

the class EditResourceLimitsPage method createResourceWidgets.

private void createResourceWidgets(String label, String property, String[] suffixes, String[] labels, Group parent, DataBindingContext dbc) {
    // label
    Label labelComp = new Label(parent, SWT.NONE);
    labelComp.setText(label);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(labelComp);
    // value text
    Text text = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(text);
    // unit combo
    ComboViewer combo = new ComboViewer(parent);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(140, SWT.DEFAULT).applyTo(combo.getControl());
    combo.setContentProvider(ArrayContentProvider.getInstance());
    combo.setInput(suffixes);
    combo.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return getLabelForSuffix(element, suffixes, labels);
        }

        private String getLabelForSuffix(Object element, String[] suffixes, String[] labels) {
            String label = (String) element;
            for (int i = 0; i < suffixes.length; ++i) {
                if (element.equals(suffixes[i])) {
                    label = labels[i];
                    break;
                }
            }
            return label;
        }
    });
    IObservableValue<String> valueObservable = WidgetProperties.text(SWT.Modify).observe(text);
    IObservableValue<String> selectedUnitObservable = ViewerProperties.singleSelection().observe(combo);
    IObservableValue<IContainer> master = BeanProperties.value(EditResourceLimitsPageModel.SELECTED_CONTAINER).observe(model);
    ValueBindingBuilder.bind(valueObservable).validatingAfterGet(new NumericValidator("integer", Integer::parseInt)).converting(new AggregatingConverter(selectedUnitObservable, true)).to(PojoProperties.value(property).observeDetail(master)).converting(new KeywordConverter(suffixes, true)).in(dbc);
    ValueBindingBuilder.bind(selectedUnitObservable).converting(new AggregatingConverter(valueObservable, false)).to(PojoProperties.value(property).observeDetail(master)).converting(new KeywordConverter(suffixes, false)).in(dbc);
}
Also used : AggregatingConverter(org.jboss.tools.openshift.internal.common.ui.databinding.AggregatingConverter) KeywordConverter(org.jboss.tools.openshift.internal.common.ui.databinding.KeywordConverter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) NumericValidator(org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IContainer(com.openshift.restclient.model.IContainer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 2 with IContainer

use of com.openshift.restclient.model.IContainer in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugModeTest method shouldReplaceContainerDebugPortIfExistingPortDiffersFromRequestedPort.

@Test
public void shouldReplaceContainerDebugPortIfExistingPortDiffersFromRequestedPort() throws CoreException, UnsupportedEncodingException, MalformedURLException {
    // given
    mockGetEnvironmentVariables(asList(createEnvironmentVariable(KEY_DEVMODE, Boolean.FALSE.toString()), createEnvironmentVariable(KEY_DEBUGPORT, VALUE_DEBUGPORT)), dc);
    // has container port 88, should have port matching env var
    Set<IPort> ports = singleton(createPort(toInt(String.valueOf("88"))));
    IContainer container = createContainer("someDc-container1", ports);
    mockGetContainers(asList(container), dc);
    context.setDebugEnabled(true);
    // when
    debugMode.execute(new NullProgressMonitor());
    // then
    verify(container, atLeastOnce()).setPorts(and(// new set of ports contains requested port
    argThat(aSetThatContainsPort(toInt(VALUE_DEBUGPORT))), // but not previously existing port
    argThat(not(aSetThatContainsPort(88)))));
    // send updated dc
    verify(debugMode, times(1)).send(eq(dc), eq(connection), any(IProgressMonitor.class));
}
Also used : IPort(com.openshift.restclient.model.IPort) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IContainer(com.openshift.restclient.model.IContainer) Test(org.junit.Test)

Example 3 with IContainer

use of com.openshift.restclient.model.IContainer in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugModeTest method shouldAddContainerDebugPortGivenNoPortExistsYet.

@Test
public void shouldAddContainerDebugPortGivenNoPortExistsYet() throws CoreException, UnsupportedEncodingException, MalformedURLException {
    // given
    mockGetEnvironmentVariables(asList(createEnvironmentVariable(KEY_DEVMODE, Boolean.FALSE.toString())), dc);
    final IPort existingContainerPort = new PortSpecAdapter("papaSmurf", "transport", 42);
    Set<IPort> ports = singleton(existingContainerPort);
    IContainer container = createContainer("someDc-container1", ports);
    mockGetContainers(asList(container), dc);
    context.setDebugEnabled(true);
    // when
    debugMode.execute(new NullProgressMonitor());
    // then
    verify(container, atLeastOnce()).setPorts(argThat(aSetEqualTo(existingContainerPort, createPort(toInt(VALUE_DEBUGPORT)))));
    // send updated dc
    verify(debugMode, times(1)).send(eq(dc), eq(connection), any(IProgressMonitor.class));
}
Also used : IPort(com.openshift.restclient.model.IPort) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PortSpecAdapter(org.jboss.tools.openshift.internal.core.models.PortSpecAdapter) IContainer(com.openshift.restclient.model.IContainer) Test(org.junit.Test)

Example 4 with IContainer

use of com.openshift.restclient.model.IContainer in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugModeTest method shouldNotCreateLivenessProbeIfDoesntExistYet.

@Test
public void shouldNotCreateLivenessProbeIfDoesntExistYet() throws CoreException {
    // given
    IContainer container = createContainer("someDc-container1", // no lifeness probe
    Collections.singleton(createPort(NumberUtils.toInt(VALUE_DEBUGPORT))), // no lifeness probe
    null, createProbe(20, 21, 22, 23, 24));
    mockGetContainers(Arrays.asList(container), dc);
    // when
    context.setDebugEnabled(true);
    debugMode.execute(new NullProgressMonitor());
    // then
    assertThat(container.getLivenessProbe()).isNull();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IContainer(com.openshift.restclient.model.IContainer) Test(org.junit.Test)

Example 5 with IContainer

use of com.openshift.restclient.model.IContainer in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugModeTest method shouldNotReplaceContainerDebugPortGivenExistingPortMatchesRequestedPort.

@Test
public void shouldNotReplaceContainerDebugPortGivenExistingPortMatchesRequestedPort() throws CoreException, UnsupportedEncodingException, MalformedURLException {
    // given
    mockGetEnvironmentVariables(asList(createEnvironmentVariable(KEY_DEVMODE, Boolean.FALSE.toString()), createEnvironmentVariable(KEY_DEBUGPORT, VALUE_DEBUGPORT)), dc);
    Set<IPort> ports = singleton(createPort(toInt(VALUE_DEBUGPORT)));
    IContainer container = createContainer("someDc-container1", ports);
    mockGetContainers(asList(container), dc);
    context.setDebugEnabled(true);
    // when
    debugMode.execute(new NullProgressMonitor());
    // then
    verify(container, never()).setPorts(any());
    // send updated dc
    verify(debugMode, times(1)).send(eq(dc), eq(connection), any(IProgressMonitor.class));
}
Also used : IPort(com.openshift.restclient.model.IPort) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IContainer(com.openshift.restclient.model.IContainer) Test(org.junit.Test)

Aggregations

IContainer (com.openshift.restclient.model.IContainer)10 Test (org.junit.Test)5 IPort (com.openshift.restclient.model.IPort)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 ResourceKind (com.openshift.restclient.ResourceKind)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2 Connection (org.jboss.tools.openshift.core.connection.Connection)2 ResourceFactory (com.openshift.internal.restclient.ResourceFactory)1 IClient (com.openshift.restclient.IClient)1 IResourceFactory (com.openshift.restclient.IResourceFactory)1 DockerImageURI (com.openshift.restclient.images.DockerImageURI)1 IBuild (com.openshift.restclient.model.IBuild)1 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)1 IImageStream (com.openshift.restclient.model.IImageStream)1 IPod (com.openshift.restclient.model.IPod)1 IProject (com.openshift.restclient.model.IProject)1