Search in sources :

Example 21 with IRoute

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

the class ServerSettingsWizardPageModelTest method should_set_server_route_when_updating_server.

@Test
public void should_set_server_route_when_updating_server() throws CoreException {
    // given
    model.setSelectDefaultRoute(true);
    IRoute route = model.getRoute();
    assertThat(route).isNotNull();
    String routeURL = route.getURL();
    // when
    model.updateServer();
    // then
    verify(server, atLeastOnce()).setAttribute(eq(OpenShiftServerUtils.ATTR_ROUTE), eq(routeURL));
    verify(model, atLeastOnce()).updateServer(anyString(), any(IService.class), anyString(), eq(routeURL), anyString(), anyString(), anyString(), anyString(), any(org.eclipse.core.resources.IProject.class));
}
Also used : IRoute(com.openshift.restclient.model.route.IRoute) Matchers.anyString(org.mockito.Matchers.anyString) IService(com.openshift.restclient.model.IService) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 22 with IRoute

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

the class OpenShiftServerExtendedProperties method getRoute.

/**
 * Opens a dialog for user to select a route from the list.
 * @param routes
 * @return
 */
private IRoute getRoute(List<IRoute> routes) {
    IRouteChooser chooser = OpenShiftCoreUIIntegration.getInstance().getRouteChooser();
    IRoute route = null;
    if (routes == null || routes.isEmpty()) {
        chooser.noRouteErrorDialog();
        return null;
    }
    if (routes.size() > 1) {
        route = chooser.chooseRoute(routes);
        if (route != null && chooser.isRememberChoice()) {
            fireUpdateRoute(server, route.getURL());
        }
    } else {
        route = routes.get(0);
    }
    return route;
}
Also used : IRoute(com.openshift.restclient.model.route.IRoute) IRouteChooser(org.jboss.tools.openshift.core.IRouteChooser)

Example 23 with IRoute

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

the class OpenShiftServerExtendedProperties method getWelcomePageUrl.

@Override
public String getWelcomePageUrl() throws GetWelcomePageURLException {
    String welcomePageUrl = null;
    try {
        // Get connection explicitly to report failure. Try and connect right now to know if it fails.
        // Do not catch OpenShiftException, let it be reported. We are more concerned of NPE.
        Connection connection = OpenShiftServerUtils.getConnection(server);
        if (connection == null || !connection.connect()) {
            throw new GetWelcomePageURLException("Connection is not established.");
        }
        IResource resource = OpenShiftServerUtils.getResource(server, connection, new NullProgressMonitor());
        if (resource == null) {
            throw new GetWelcomePageURLException("Resource is missing.");
        }
        IProject project = resource.getProject();
        if ((project != null) && (resource instanceof IService)) {
            List<IRoute> routes = ResourceUtils.getRoutesFor((IService) resource, project.getResources(ResourceKind.ROUTE));
            IRoute route = getRoute(OpenShiftServerUtils.getRouteURL(server), routes);
            if (route == null) {
                route = getRoute(routes);
            }
            // Reporting route == null is implemented in getRoute.
            if (route != null) {
                welcomePageUrl = route.getURL();
            }
        }
    } catch (OpenShiftException e) {
        throw new GetWelcomePageURLException(e.getMessage(), e);
    }
    return welcomePageUrl;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) IRoute(com.openshift.restclient.model.route.IRoute) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject) IService(com.openshift.restclient.model.IService)

Example 24 with IRoute

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

the class NewApplicationWizardModelTest method setWrongJsonAsTemplateFile.

@Test
public void setWrongJsonAsTemplateFile() throws Exception {
    IRoute route = Mockito.mock(IRoute.class);
    when(route.getKind()).thenReturn(ResourceKind.ROUTE);
    when(factory.create(any(InputStream.class))).thenReturn(route);
    model.setLocalAppSourceFileName("resources/jboss_infinispan-server_ImageStreamImport.json");
    model.loadAppSource(null);
    assertFalse(model.getAppSourceStatus().isOK());
    assertNull(model.getAppSourceStatus().getException());
}
Also used : InputStream(java.io.InputStream) IRoute(com.openshift.restclient.model.route.IRoute) Test(org.junit.Test)

Example 25 with IRoute

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

the class RouteTimeout method set.

/**
 * Sets the given timeout to the route that's found for the given resource.
 * Returns the route that was modified or {@code null} otherwise.
 *
 * @param timeout
 * @param monitor
 * @return the route if it was modified or {@code null}
 * @throws CoreException
 */
public IRoute set(DebugContext context, IProgressMonitor monitor) throws CoreException {
    IRoute route = getRoute(resource, connection, monitor);
    if (route == null) {
        OpenShiftCoreActivator.pluginLog().logInfo(NLS.bind("Could not increase timeout for debugging: could not find any route for resource {0}", resource.getName()));
        return null;
    }
    monitor.subTask(NLS.bind("Setting haproxy timeout for route {0}...", route.getName()));
    String currentTimeout = getAnnotation(route);
    if (!StringUtils.isBlank(currentTimeout)) {
        // store for latter restore
        OpenShiftServerUtils.setRouteTimeout(currentTimeout, context.getServer());
        if (StringUtils.equals(ROUTE_DEBUG_TIMEOUT, currentTimeout)) {
            return null;
        }
    }
    setAnnotation(ROUTE_DEBUG_TIMEOUT, route);
    return route;
}
Also used : IRoute(com.openshift.restclient.model.route.IRoute)

Aggregations

IRoute (com.openshift.restclient.model.route.IRoute)34 Test (org.junit.Test)15 IService (com.openshift.restclient.model.IService)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 List (java.util.List)6 ResourceKind (com.openshift.restclient.ResourceKind)5 Connection (org.jboss.tools.openshift.core.connection.Connection)5 IProject (com.openshift.restclient.model.IProject)4 IResource (com.openshift.restclient.model.IResource)4 Collection (java.util.Collection)4 CoreException (org.eclipse.core.runtime.CoreException)4 NLS (org.eclipse.osgi.util.NLS)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 AbstractHandler (org.eclipse.core.commands.AbstractHandler)3 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 IStatus (org.eclipse.core.runtime.IStatus)3 ISelection (org.eclipse.jface.viewers.ISelection)3