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