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);
}
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));
}
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));
}
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();
}
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));
}
Aggregations