use of com.openshift.restclient.model.IService in project wildfly-swarm by wildfly-swarm.
the class ServiceWatcher method registrationsForService.
private Set<Registration> registrationsForService(IService service) {
Set<Registration> newEntries = new HashSet<>();
// Only expose the service's default port and anything running on the https port
service.getPorts().stream().filter(servicePort -> servicePort.getPort() == service.getPort() || servicePort.getPort() == DEFAULT_HTTPS_PORT).forEach(servicePort -> {
Registration registration = new Registration(TOPOLOGY_SOURCE_KEY, service.getName(), service.getName(), servicePort.getPort());
if (servicePort.getPort() == DEFAULT_HTTPS_PORT) {
registration.addTags(Collections.singletonList("https"));
} else if (servicePort.getPort() == service.getPort()) {
registration.addTags(Collections.singletonList("http"));
}
newEntries.add(registration);
});
return newEntries;
}
use of com.openshift.restclient.model.IService in project wildfly-swarm by wildfly-swarm.
the class ServiceWatcher method received.
@Override
public void received(IResource resource, ChangeType change) {
if (change.equals(ChangeType.ADDED)) {
// Add new Service to topology
IService service = (IService) resource;
registrationsForService(service).forEach(topologyManagerInjector.getValue()::register);
} else if (change.equals(ChangeType.DELETED)) {
// Remove Service from topology
topologyManagerInjector.getValue().unregisterAll(TOPOLOGY_SOURCE_KEY, resource.getName());
}
}
use of com.openshift.restclient.model.IService in project jbosstools-openshift by jbosstools.
the class OpenShiftDebugModeTest method createRouteFor.
/**
* Returns a route that points to a service, that's related to the given deployment config.
* Creating the route it will stub 2 services and 2 routes to the given connection.
*
* @param dc to create a route for
* @param connection to create the route, services and routes in
* @return
*/
private IRoute createRouteFor(IDeploymentConfig dc, IProject project, Connection connection) {
@SuppressWarnings("serial") Map<String, String> selectors = new HashMap<String, String>() {
{
put("aSelector", "42");
}
};
doReturn(selectors).when(dc).getReplicaSelector();
// doesnt match dc
IService service1 = createService("service1", project, new HashMap<String, String>());
// matches dc
IService service2 = createService("service2", project, selectors);
when(connection.getResources(ResourceKind.SERVICE, project.getNamespaceName())).thenReturn(Arrays.asList(service1, service2));
// matches inexistent service
IRoute route1 = createRoute("route1", project, "service42");
// matches service2
IRoute route2 = createRoute("route2", project, "service2");
when(connection.getResources(ResourceKind.ROUTE, project.getNamespaceName())).thenReturn(Arrays.asList(route1, route2));
return route2;
}
use of com.openshift.restclient.model.IService in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithServiceTest method shouldReturnNewServiceItemsIfLoadResourcesWithConnection.
@Test
public void shouldReturnNewServiceItemsIfLoadResourcesWithConnection() {
// given
List<ObservableTreeItem> serviceItems = new ArrayList<>(model.getResourceItems());
Connection connection = ResourceMocks.createConnection("http://localhost:8080", "dev@42.org");
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
List<ObservableTreeItem> newServiceItems = model.getResourceItems();
assertThat(newServiceItems).isNotEqualTo(serviceItems);
}
use of com.openshift.restclient.model.IService in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithServiceTest method shouldReturnServiceForGivenName.
@Test
public void shouldReturnServiceForGivenName() {
// given
// when
IService service = model.getService(ResourceMocks.PROJECT2_SERVICES[2].getName());
// then
assertThat(service).isEqualTo(ResourceMocks.PROJECT2_SERVICES[2]);
}
Aggregations