Search in sources :

Example 21 with IService

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

the class ServicePodsExist method test.

@Override
public boolean test() {
    IService service = connection.getResource(ResourceKind.SERVICE, projectName, serviceName);
    if (service == null) {
        return true;
    }
    if (!hasDesiredReplicas(service)) {
        return true;
    }
    List<IPod> pods = connection.getResources(ResourceKind.POD, projectName);
    return !ResourceUtils.getPodsFor(service, pods).isEmpty();
}
Also used : IService(com.openshift.restclient.model.IService) IPod(com.openshift.restclient.model.IPod)

Example 22 with IService

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

the class OpenShiftExplorerLabelProviderTest method getStyledTextForAService.

@Test
public void getStyledTextForAService() {
    IService service = givenAResource(IService.class, ResourceKind.SERVICE);
    when(service.getPortalIP()).thenReturn("172.17.2.226");
    when(service.getPort()).thenReturn(5432);
    when(service.getTargetPort()).thenReturn("3306");
    Map<String, String> labels = new HashMap<>();
    labels.put("foo", "bar");
    when(service.getSelector()).thenReturn(labels);
    String exp = String.format("%s selector: foo=bar", service.getName());
    assertEquals(exp, provider.getStyledText(service).getString());
}
Also used : HashMap(java.util.HashMap) StyledString(org.eclipse.jface.viewers.StyledString) IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 23 with IService

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

the class ServerResourceViewModelWithServiceTest method shouldReturnNewSelectedServiceIfLoadResourcesWithConnection.

@Test
public void shouldReturnNewSelectedServiceIfLoadResourcesWithConnection() {
    // given
    IResource selectedService = model.getResource();
    Connection connection = ResourceMocks.createConnection("https://localhost:8181", "ops@42.org");
    ConnectionsRegistrySingleton.getInstance().add(connection);
    try {
        IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
        when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
        IService service = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE);
        when(project.getResources(ResourceKind.SERVICE)).thenReturn(Collections.singletonList(service));
        // when
        model.loadResources(connection);
        // then
        IResource newSelectedService = model.getResource();
        assertThat(selectedService).isNotEqualTo(newSelectedService);
    } finally {
        ConnectionsRegistrySingleton.getInstance().remove(connection);
    }
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject) IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 24 with IService

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

the class ServerResourceViewModelWithServiceTest method shouldReturn1stServiceInListIfInitializedServiceIsNotInListOfAllServices.

@Test
public void shouldReturn1stServiceInListIfInitializedServiceIsNotInListOfAllServices() {
    // given
    IService otherService = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE);
    ServerResourceViewModel model = new ServerResourceViewModel(otherService, connection);
    model.loadResources();
    // when
    IResource service = model.getResource();
    // then
    assertThat(service).isEqualTo(ResourceMocks.PROJECT2_SERVICES[0]);
}
Also used : ServerResourceViewModel(org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel) IService(com.openshift.restclient.model.IService) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 25 with IService

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

the class RouteTimeout method getRoute.

private IRoute getRoute(IResource resource, Connection connection, IProgressMonitor monitor) {
    SubMonitor routeMonitor = SubMonitor.convert(monitor);
    routeMonitor.beginTask("Determine route to set the haproxy timeout for...", 2);
    if (routeMonitor.isCanceled()) {
        return null;
    }
    List<IService> services = connection.getResources(ResourceKind.SERVICE, resource.getNamespaceName());
    Collection<IService> matchingServices = ResourceUtils.getServicesFor(resource, services);
    routeMonitor.worked(1);
    if (routeMonitor.isCanceled()) {
        return null;
    }
    List<IRoute> routes = connection.getResources(ResourceKind.ROUTE, resource.getNamespaceName());
    // TODO: support multiple matching routes, for now only get first
    Optional<IRoute> matchingRoute = matchingServices.stream().flatMap(service -> ResourceUtils.getRoutesFor(service, routes).stream()).findFirst();
    routeMonitor.worked(1);
    routeMonitor.done();
    return matchingRoute.orElse(null);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) SubMonitor(org.eclipse.core.runtime.SubMonitor) Collection(java.util.Collection) OpenShiftServerUtils(org.jboss.tools.openshift.core.server.OpenShiftServerUtils) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) CoreException(org.eclipse.core.runtime.CoreException) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) Connection(org.jboss.tools.openshift.core.connection.Connection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IRoute(com.openshift.restclient.model.route.IRoute) Optional(java.util.Optional) IService(com.openshift.restclient.model.IService) SubMonitor(org.eclipse.core.runtime.SubMonitor) IRoute(com.openshift.restclient.model.route.IRoute) IService(com.openshift.restclient.model.IService)

Aggregations

IService (com.openshift.restclient.model.IService)32 Test (org.junit.Test)15 Connection (org.jboss.tools.openshift.core.connection.Connection)10 IResource (com.openshift.restclient.model.IResource)9 IRoute (com.openshift.restclient.model.route.IRoute)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)6 IProject (com.openshift.restclient.model.IProject)5 ResourceKind (com.openshift.restclient.ResourceKind)4 IBuildConfig (com.openshift.restclient.model.IBuildConfig)4 IPod (com.openshift.restclient.model.IPod)4 IReplicationController (com.openshift.restclient.model.IReplicationController)4 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)3 CoreException (org.eclipse.core.runtime.CoreException)3 ResourceUtils (org.jboss.tools.openshift.internal.core.util.ResourceUtils)3 IClient (com.openshift.restclient.IClient)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2