Search in sources :

Example 1 with IService

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;
}
Also used : Registration(org.wildfly.swarm.topology.runtime.Registration) IResource(com.openshift.restclient.model.IResource) Service(org.jboss.msc.service.Service) ResourceKind(com.openshift.restclient.ResourceKind) IOpenShiftWatchListener(com.openshift.restclient.IOpenShiftWatchListener) StopContext(org.jboss.msc.service.StopContext) Set(java.util.Set) StartContext(org.jboss.msc.service.StartContext) TopologyManager(org.wildfly.swarm.topology.runtime.TopologyManager) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) List(java.util.List) IClient(com.openshift.restclient.IClient) ServiceName(org.jboss.msc.service.ServiceName) Collections(java.util.Collections) IWatcher(com.openshift.restclient.IWatcher) InjectedValue(org.jboss.msc.value.InjectedValue) IService(com.openshift.restclient.model.IService) Injector(org.jboss.msc.inject.Injector) StartException(org.jboss.msc.service.StartException) Registration(org.wildfly.swarm.topology.runtime.Registration) HashSet(java.util.HashSet)

Example 2 with IService

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());
    }
}
Also used : IService(com.openshift.restclient.model.IService)

Example 3 with IService

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;
}
Also used : HashMap(java.util.HashMap) IRoute(com.openshift.restclient.model.route.IRoute) Matchers.anyString(org.mockito.Matchers.anyString) IService(com.openshift.restclient.model.IService)

Example 4 with IService

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);
}
Also used : ArrayList(java.util.ArrayList) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IProject(com.openshift.restclient.model.IProject) IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 5 with IService

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]);
}
Also used : IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

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