io.fabric8.openshift.api.model.RouteSpec Java Examples

The following examples show how to use io.fabric8.openshift.api.model.RouteSpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TeiidOpenShiftClient.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private RouteStatus getRoute(String openShiftName, ProtocolType protocolType) {
    String namespace = ApplicationProperties.getNamespace();
    OpenShiftClient client = openshiftClient();
    RouteStatus theRoute = null;
    debug(openShiftName, "Getting route of type " + protocolType.id() + " for Service");

    Route route = client.routes().inNamespace(namespace).withName(openShiftName + StringConstants.HYPHEN + protocolType.id()).get();

    if (route != null) {
        ObjectMeta metadata = route.getMetadata();
        String name = metadata.getName();
        RouteSpec spec = route.getSpec();
        String target = spec.getTo().getName();

        theRoute = new RouteStatus(name, protocolType);
        theRoute.setHost(spec.getHost());
        theRoute.setPath(spec.getPath());
        theRoute.setPort(spec.getPort().getTargetPort().getStrVal());
        theRoute.setTarget(target);
        theRoute.setSecure(spec.getTls() != null);
    }
    return theRoute;
}
 
Example #2
Source File: Routes.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * In given {@code routes} finds route that for given {@code service} and {@code port}
 *
 * @return found {@link Route} or {@link Optional#empty()}
 */
public static Optional<Route> findRouteForServicePort(
    Collection<Route> routes, Service service, int port) {
  Optional<ServicePort> foundPort = Services.findPort(service, port);
  if (!foundPort.isPresent()) {
    return Optional.empty();
  }

  for (Route route : routes) {
    RouteSpec spec = route.getSpec();
    if (spec.getTo().getName().equals(service.getMetadata().getName())
        && matchesPort(foundPort.get(), spec.getPort().getTargetPort())) {
      return Optional.of(route);
    }
  }
  return Optional.empty();
}
 
Example #3
Source File: OpenShiftServiceImpl.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<String> getExposedHost(String name) {
    Route route = openShiftClient.routes().withName(openshiftName(name)).get();
    return Optional.ofNullable(route)
        .flatMap(r -> Optional.ofNullable(r.getSpec()))
        .map(RouteSpec::getHost);
}
 
Example #4
Source File: OpenShiftPreviewUrlCommandProvisionerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldUpdateCommandWhenServiceAndIngressFound() throws InfrastructureException {
  int port = 8080;
  List<CommandImpl> commands =
      Collections.singletonList(
          new CommandImpl("a", "a", "a", new PreviewUrlImpl(port, null), Collections.emptyMap()));
  OpenShiftEnvironment env =
      OpenShiftEnvironment.builder().setCommands(new ArrayList<>(commands)).build();

  Mockito.when(mockProject.services()).thenReturn(mockServices);
  Service service = new Service();
  ObjectMeta metadata = new ObjectMeta();
  metadata.setName("servicename");
  service.setMetadata(metadata);
  ServiceSpec spec = new ServiceSpec();
  spec.setPorts(
      Collections.singletonList(
          new ServicePort("8080", null, port, "TCP", new IntOrString(port))));
  service.setSpec(spec);
  Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));

  Route route = new Route();
  RouteSpec routeSpec = new RouteSpec();
  routeSpec.setPort(new RoutePort(new IntOrString("8080")));
  routeSpec.setTo(new RouteTargetReference("a", "servicename", 1));
  routeSpec.setHost("testhost");
  route.setSpec(routeSpec);

  Mockito.when(mockProject.routes()).thenReturn(mockRoutes);
  Mockito.when(mockRoutes.get()).thenReturn(Collections.singletonList(route));

  previewUrlCommandProvisioner.provision(env, mockProject);

  assertTrue(env.getCommands().get(0).getAttributes().containsKey("previewUrl"));
  assertEquals(env.getCommands().get(0).getAttributes().get("previewUrl"), "testhost");
  assertTrue(env.getWarnings().isEmpty());
}
 
Example #5
Source File: OpenShiftInternalRuntimeTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private static Route mockRoute() {
  final Route route = mock(Route.class);
  mockName(ROUTE_NAME, route);
  final RouteSpec spec = mock(RouteSpec.class);
  final RouteTargetReference target = mock(RouteTargetReference.class);
  when(target.getName()).thenReturn(SERVICE_NAME);
  when(spec.getTo()).thenReturn(target);
  when(spec.getHost()).thenReturn(ROUTE_HOST);
  when(route.getSpec()).thenReturn(spec);
  when(route.getMetadata().getLabels())
      .thenReturn(ImmutableMap.of(CHE_ORIGINAL_NAME_LABEL, ROUTE_NAME));
  return route;
}
 
Example #6
Source File: OpenShiftPreviewUrlExposerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldNotProvisionWhenServiceAndRouteFound() throws InternalInfrastructureException {
  final int PORT = 8080;
  final String SERVER_PORT_NAME = "server-" + PORT;

  CommandImpl command =
      new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());

  Service service = new Service();
  ObjectMeta serviceMeta = new ObjectMeta();
  serviceMeta.setName("servicename");
  service.setMetadata(serviceMeta);
  ServiceSpec serviceSpec = new ServiceSpec();
  serviceSpec.setPorts(
      singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
  service.setSpec(serviceSpec);

  Route route = new Route();
  RouteSpec routeSpec = new RouteSpec();
  routeSpec.setPort(new RoutePort(new IntOrString(SERVER_PORT_NAME)));
  routeSpec.setTo(new RouteTargetReference("routekind", "servicename", 1));
  route.setSpec(routeSpec);

  Map<String, Service> services = new HashMap<>();
  services.put("servicename", service);
  Map<String, Route> routes = new HashMap<>();
  routes.put("routename", route);

  OpenShiftEnvironment env =
      OpenShiftEnvironment.builder()
          .setCommands(singletonList(new CommandImpl(command)))
          .setServices(services)
          .setRoutes(routes)
          .build();

  assertEquals(env.getRoutes().size(), 1);
  previewUrlEndpointsProvisioner.expose(env);
  assertEquals(env.getRoutes().size(), 1);
}
 
Example #7
Source File: RoutesTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private Route createRoute(IntOrString port) {
  Route route = new Route();
  RouteSpec routeSpec = new RouteSpec();
  routeSpec.setPort(new RoutePort(port));
  routeSpec.setTo(new RouteTargetReference("a", "servicename", 1));
  routeSpec.setHost("testhost");
  route.setSpec(routeSpec);
  return route;
}
 
Example #8
Source File: ThorntailOnOpenshiftTest.java    From dekorate with Apache License 2.0 4 votes vote down vote up
@Test
void shouldContainDeployment() {
  KubernetesList list = Serialization.unmarshalAsList(ThorntailOnOpenshiftTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/openshift.yml"));
  assertNotNull(list);

  Optional<DeploymentConfig> deploymentConfig = findFirst(list, DeploymentConfig.class);
  assertTrue(deploymentConfig.isPresent());

  DeploymentConfig d = deploymentConfig.get();
  List<Container> containers = d.getSpec().getTemplate().getSpec().getContainers();
  assertEquals(1, containers.size());
  Container container = containers.get(0);

  assertEquals(1, container.getPorts().size());
  assertEquals("http", container.getPorts().get(0).getName());
  assertEquals(8080, container.getPorts().get(0).getContainerPort());

  HTTPGetAction livenessProbe = container.getLivenessProbe().getHttpGet();
  assertNotNull(livenessProbe);
  assertEquals("/health", livenessProbe.getPath());
  assertEquals(8080, livenessProbe.getPort().getIntVal());
  assertEquals(180, container.getLivenessProbe().getInitialDelaySeconds());

  HTTPGetAction readinessProbe = container.getReadinessProbe().getHttpGet();
  assertNotNull(readinessProbe);
  assertEquals("/health", readinessProbe.getPath());
  assertEquals(8080, readinessProbe.getPort().getIntVal());
  assertEquals(20, container.getReadinessProbe().getInitialDelaySeconds());

  Optional<Service> service = findFirst(list, Service.class);
  assertTrue(service.isPresent());
  ServiceSpec s = service.get().getSpec();
  assertEquals(1, s.getPorts().size());
  assertEquals("http", s.getPorts().get(0).getName());
  assertEquals(8080, s.getPorts().get(0).getPort());
  assertEquals(8080, s.getPorts().get(0).getTargetPort().getIntVal());

  Optional<Route> route = findFirst(list, Route.class);
  assertTrue(route.isPresent());
  RouteSpec r = route.get().getSpec();
  assertEquals(8080, r.getPort().getTargetPort().getIntVal());
  assertEquals("/", r.getPath());
}
 
Example #9
Source File: RouteTlsProvisioner.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private void enableTls(final Route route) {
  RouteSpec spec = route.getSpec();
  spec.setTls(getTLSConfig());
}