Java Code Examples for io.fabric8.openshift.api.model.Route#getSpec()

The following examples show how to use io.fabric8.openshift.api.model.Route#getSpec() . 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: OpenShiftEnvironmentValidator.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
private void validateRoutesMatchServices(OpenShiftEnvironment env) throws ValidationException {
  Set<String> recipeServices =
      env.getServices()
          .values()
          .stream()
          .map(s -> s.getMetadata().getName())
          .collect(Collectors.toSet());
  for (Route route : env.getRoutes().values()) {
    if (route.getSpec() == null
        || route.getSpec().getTo() == null
        || !route.getSpec().getTo().getKind().equals(SERVICE_KIND)) {
      continue;
    }
    String serviceName = route.getSpec().getTo().getName();
    if (!recipeServices.contains(serviceName)) {
      throw new ValidationException(
          String.format(
              "Route '%s' refers to Service '%s'. Routes must refer to Services included in recipe",
              route.getMetadata().getName(), serviceName));
    }
  }
}
 
Example 3
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 4
Source File: ServiceResourceUtil.java    From kubernetes-pipeline-plugin with Apache License 2.0 5 votes vote down vote up
private String serviceNameFromRoute(Route route) {
    if(route.getSpec() != null && route.getSpec().getTo() != null && route.getSpec().getTo().getKind().equals("Service")) {
        return route.getSpec().getTo().getName();
    } else {
        return null;
    }
}
 
Example 5
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());
}