Search in sources :

Example 1 with IServicePort

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

the class DeployImageJob method stubRoute.

private IResource stubRoute(IResourceFactory factory, String name, String serviceName) {
    IRoute route = factory.stub(ResourceKind.ROUTE, name, parameters.getProject().getName());
    route.setServiceName(serviceName);
    String hostname = parameters.getRouteHostname();
    if (StringUtils.isNotBlank(hostname)) {
        route.setHost(hostname);
    }
    IServicePort port = parameters.getRoutingPort();
    if (port != null) {
        ITargetPort targetPort = route.createPort();
        if (port.getName() != null) {
            targetPort.setTargetPortName(port.getName());
        } else {
            targetPort.setTargetPort(port.getPort());
        }
    }
    return route;
}
Also used : IServicePort(com.openshift.restclient.model.IServicePort) ITargetPort(com.openshift.restclient.model.route.ITargetPort) IRoute(com.openshift.restclient.model.route.IRoute)

Example 2 with IServicePort

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

the class ServicesAndRoutingPage method createExposedPortsControl.

private void createExposedPortsControl(Composite parent, DataBindingContext dbc) {
    Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(container);
    Label label = new Label(container, SWT.NONE);
    label.setText("Service Ports:");
    label.setToolTipText("The exposed ports of the image.");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(label);
    Composite tableContainer = new Composite(container, SWT.NONE);
    IObservableList<IServicePort> portsObservable = BeanProperties.list(IServiceAndRoutingPageModel.PROPERTY_SERVICE_PORTS).observe(model);
    portsViewer = createTable(tableContainer);
    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    portsViewer.setContentProvider(contentProvider);
    ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider(Properties.observeEach(contentProvider.getKnownElements(), BeanProperties.values(ServicePortAdapter.NAME, ServicePortAdapter.PORT, ServicePortAdapter.TARGET_PORT, /* ROUTE_PORT_COLUMN_INDEX = 3 */
    ServicePortAdapter.ROUTE_PORT))) {

        @Override
        public Image getColumnImage(Object element, int columnIndex) {
            if (columnIndex == ROUTE_PORT_COLUMN_INDEX) {
                Object selected = attributeMaps[columnIndex].get(element);
                return selected != null && (boolean) selected ? OpenShiftImages.CHECKED_IMG : OpenShiftImages.UNCHECKED_IMG;
            }
            return null;
        }

        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (columnIndex != ROUTE_PORT_COLUMN_INDEX) {
                Object result = attributeMaps[columnIndex].get(element);
                // $NON-NLS-1$
                return result == null ? "" : result.toString();
            }
            return null;
        }
    };
    portsViewer.setLabelProvider(labelProvider);
    GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
    ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(portsViewer)).to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_SELECTED_SERVICE_PORT).observe(model)).in(dbc);
    portsViewer.setInput(portsObservable);
    dbc.addValidationStatusProvider(new MultiValidator() {

        @Override
        protected IStatus validate() {
            if (portsObservable.isEmpty()) {
                return ValidationStatus.error("At least 1 port is required when generating the service for the deployed image");
            }
            return Status.OK_STATUS;
        }
    });
    portsViewer.getTable().addMouseListener(onTableCellClicked());
    Button btnEdit = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(btnEdit);
    btnEdit.setText("Edit...");
    btnEdit.setToolTipText("Edit a port to be exposed by the service.");
    btnEdit.addSelectionListener(new EditHandler());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnEdit)).notUpdatingParticipant().to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_SELECTED_SERVICE_PORT).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
    UIUtils.setDefaultButtonWidth(btnEdit);
    Button btnReset = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(btnReset);
    btnReset.setText("Reset");
    btnReset.setToolTipText("Resets the list of ports to the exposed ports of the image.");
    btnReset.addSelectionListener(onReset());
    UIUtils.setDefaultButtonWidth(btnReset);
}
Also used : ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) ObservableMapLabelProvider(org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) IServicePort(com.openshift.restclient.model.IServicePort) Button(org.eclipse.swt.widgets.Button) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter)

Example 3 with IServicePort

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

the class ServicesAndRoutingPage method onTableCellClicked.

private MouseListener onTableCellClicked() {
    return new TableCellMouseAdapter(ROUTE_PORT_COLUMN_INDEX) {

        @Override
        public void mouseUpCell(MouseEvent event) {
            IServicePort port = model.getSelectedServicePort();
            ServicePortAdapter target = new ServicePortAdapter((ServicePortAdapter) port);
            target.setRoutePort(!target.isRoutePort());
            target.setName(NLS.bind("{0}-tcp", target.getPort()));
            model.updateServicePort(port, target);
            model.setSelectedServicePort(target);
            Display.getDefault().asyncExec(() -> {
                if (portsViewer != null && portsViewer.getTable() != null && !portsViewer.getTable().isDisposed()) {
                    portsViewer.refresh();
                }
            });
        }
    };
}
Also used : IServicePort(com.openshift.restclient.model.IServicePort) MouseEvent(org.eclipse.swt.events.MouseEvent) TableCellMouseAdapter(org.jboss.tools.openshift.internal.common.ui.TableCellMouseAdapter)

Example 4 with IServicePort

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

the class ServicesAndRoutingPage method doCreateControls.

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);
    createExposedPortsControl(parent, dbc);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).applyTo(new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL));
    // routing
    Composite routingContainer = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(routingContainer);
    GridLayoutFactory.fillDefaults().margins(6, 6).numColumns(2).applyTo(routingContainer);
    Button btnAddRoute = new Button(routingContainer, SWT.CHECK);
    btnAddRoute.setText("Add Route");
    btnAddRoute.setToolTipText("Adding a route to the service will make the image accessible\noutside of the OpenShift cluster on all the available service ports. \nYou can target a specific port by editing the route later.");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, false).span(2, 1).applyTo(btnAddRoute);
    final IObservableValue<Boolean> addRouteModelObservable = BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ADD_ROUTE).observe(model);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(btnAddRoute)).to(addRouteModelObservable).in(dbc);
    Label labelRouteHostname = new Label(routingContainer, SWT.NONE);
    labelRouteHostname.setText("Hostname:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(labelRouteHostname);
    Text textRouteHostname = new Text(routingContainer, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(textRouteHostname);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(textRouteHostname)).to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ADD_ROUTE).observe(model)).in(dbc);
    final IObservableValue<String> routeHostnameObservable = WidgetProperties.text(SWT.Modify).observe(textRouteHostname);
    ValueBindingBuilder.bind(routeHostnameObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ROUTE_HOSTNAME).observe(model)).in(dbc);
    MultiValidator validator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            IStatus status = ValidationStatus.ok();
            boolean isAddRoute = addRouteModelObservable.getValue();
            String hostName = routeHostnameObservable.getValue();
            final IObservableList<IServicePort> portsObservable = BeanProperties.list(IServiceAndRoutingPageModel.PROPERTY_SERVICE_PORTS).observe(model);
            final IServicePort routingPort = (IServicePort) BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ROUTING_PORT).observe(model).getValue();
            if (isAddRoute) {
                if (StringUtils.isBlank(hostName)) {
                    status = ValidationStatus.info(NLS.bind(OpenShiftUIMessages.EmptyHostNameErrorMessage, hostName));
                } else if (!DomainValidator.getInstance(true).isValid(hostName)) {
                    status = ValidationStatus.error(NLS.bind(OpenShiftUIMessages.InvalidHostNameErrorMessage, hostName));
                }
                if (!status.matches(IStatus.ERROR) && isAddRoute && (portsObservable.size() > 1) && (routingPort == null)) {
                    if (status.matches(IStatus.INFO)) {
                        status = ValidationStatus.info(status.getMessage() + "\n " + OpenShiftUIMessages.RoundRobinRoutingMessage);
                    } else {
                        status = ValidationStatus.info(OpenShiftUIMessages.RoundRobinRoutingMessage);
                    }
                }
            }
            return status;
        }
    };
    dbc.addValidationStatusProvider(validator);
    ControlDecorationSupport.create(validator, SWT.LEFT | SWT.TOP);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) TrimmingStringConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter) IServicePort(com.openshift.restclient.model.IServicePort) Button(org.eclipse.swt.widgets.Button)

Example 5 with IServicePort

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

the class PodPortValidatorTest method createPodPortValidator.

static PodPortValidator createPodPortValidator() {
    IServicePort port1 = Mockito.mock(IServicePort.class);
    Mockito.when(port1.getPort()).thenReturn(1000);
    Mockito.when(port1.getTargetPort()).thenReturn("3000");
    IServicePort port2 = Mockito.mock(IServicePort.class);
    Mockito.when(port2.getPort()).thenReturn(2000);
    Mockito.when(port2.getTargetPort()).thenReturn("home");
    return new PodPortValidator(CURRENT_VALUE, Arrays.asList(port1, port2));
}
Also used : IServicePort(com.openshift.restclient.model.IServicePort) PodPortValidator(org.jboss.tools.openshift.internal.ui.wizard.deployimage.PodPortValidator)

Aggregations

IServicePort (com.openshift.restclient.model.IServicePort)7 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)2 IStatus (org.eclipse.core.runtime.IStatus)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 IPort (com.openshift.restclient.model.IPort)1 IRoute (com.openshift.restclient.model.route.IRoute)1 ITargetPort (com.openshift.restclient.model.route.ITargetPort)1 ArrayList (java.util.ArrayList)1 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)1 ObservableMapLabelProvider (org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider)1 IDockerImageInfo (org.eclipse.linuxtools.docker.core.IDockerImageInfo)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 Text (org.eclipse.swt.widgets.Text)1 TableCellMouseAdapter (org.jboss.tools.openshift.internal.common.ui.TableCellMouseAdapter)1 IsNotNull2BooleanConverter (org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter)1 TrimmingStringConverter (org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter)1 PortSpecAdapter (org.jboss.tools.openshift.internal.core.models.PortSpecAdapter)1 PodPortValidator (org.jboss.tools.openshift.internal.ui.wizard.deployimage.PodPortValidator)1