Search in sources :

Example 1 with RouteSpec

use of io.fabric8.openshift.api.model.RouteSpec in project fabric8-maven-plugin by fabric8io.

the class ApplyMojo method createRouteForService.

private Route createRouteForService(String routeDomainPostfix, String namespace, Service service) {
    Route route = null;
    String id = KubernetesHelper.getName(service);
    if (Strings.isNotBlank(id) && hasExactlyOneService(service, id)) {
        route = new Route();
        String routeId = id;
        KubernetesHelper.setName(route, namespace, routeId);
        RouteSpec routeSpec = new RouteSpec();
        RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build();
        // objectRef.setNamespace(namespace);
        routeSpec.setTo(objectRef);
        if (!Strings.isNullOrBlank(routeDomainPostfix)) {
            String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), ".");
            routeSpec.setHost(host + "." + Strings.stripPrefix(routeDomainPostfix, "."));
        } else {
            routeSpec.setHost("");
        }
        route.setSpec(routeSpec);
        String json;
        try {
            json = KubernetesHelper.toJson(route);
        } catch (JsonProcessingException e) {
            json = e.getMessage() + ". object: " + route;
        }
        log.debug("Created route: " + json);
    }
    return route;
}
Also used : RouteTargetReference(io.fabric8.openshift.api.model.RouteTargetReference) RouteTargetReferenceBuilder(io.fabric8.openshift.api.model.RouteTargetReferenceBuilder) KubernetesHelper.createIntOrString(io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString) RouteSpec(io.fabric8.openshift.api.model.RouteSpec) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Route(io.fabric8.openshift.api.model.Route)

Example 2 with RouteSpec

use of io.fabric8.openshift.api.model.RouteSpec in project fabric8 by fabric8io.

the class Routes method createRouteForService.

public static Route createRouteForService(String routeDomainPostfix, String namespace, Service service, Logger log) {
    Route route = null;
    String id = KubernetesHelper.getName(service);
    if (Strings.isNotBlank(id) && shouldCreateRouteForService(log, service, id)) {
        route = new Route();
        String routeId = id;
        KubernetesHelper.setName(route, namespace, routeId);
        RouteSpec routeSpec = new RouteSpec();
        RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build();
        // objectRef.setNamespace(namespace);
        routeSpec.setTo(objectRef);
        if (Strings.isNotBlank(routeDomainPostfix)) {
            // Let Openshift determine the route host when the domain is not set
            String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), ".");
            String namespaceSuffix = "-" + namespace;
            routeSpec.setHost(host + namespaceSuffix + "." + Strings.stripPrefix(routeDomainPostfix, "."));
        }
        route.setSpec(routeSpec);
        String json = null;
        try {
            json = KubernetesHelper.toJson(route);
        } catch (JsonProcessingException e) {
            json = e.getMessage() + ". object: " + route;
        }
    }
    return route;
}
Also used : RouteTargetReference(io.fabric8.openshift.api.model.RouteTargetReference) RouteTargetReferenceBuilder(io.fabric8.openshift.api.model.RouteTargetReferenceBuilder) RouteSpec(io.fabric8.openshift.api.model.RouteSpec) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Route(io.fabric8.openshift.api.model.Route)

Example 3 with RouteSpec

use of io.fabric8.openshift.api.model.RouteSpec in project kie-wb-common by kiegroup.

the class OpenShiftClient method getRuntimeEndpoint.

public OpenShiftRuntimeEndpoint getRuntimeEndpoint(String id) throws OpenShiftClientException {
    try {
        OpenShiftRuntimeId runtimeId = OpenShiftRuntimeId.fromString(id);
        String prjName = runtimeId.project();
        String svcName = runtimeId.service();
        OpenShiftRuntimeEndpoint endpoint = new OpenShiftRuntimeEndpoint();
        Route route = delegate.routes().inNamespace(prjName).withName(svcName).get();
        if (route != null) {
            RouteSpec routeSpec = route.getSpec();
            endpoint.setProtocol(routeSpec.getTls() != null ? "https" : "http");
            endpoint.setHost(routeSpec.getHost());
            RoutePort routePort = routeSpec.getPort();
            if (routePort != null) {
                IntOrString targetPort = routePort.getTargetPort();
                if (targetPort != null) {
                    endpoint.setPort(targetPort.getIntVal());
                }
            }
        }
        return endpoint;
    } catch (Throwable t) {
        throw new OpenShiftClientException(t.getMessage(), t);
    }
}
Also used : RoutePort(io.fabric8.openshift.api.model.RoutePort) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) RouteSpec(io.fabric8.openshift.api.model.RouteSpec) OpenShiftRuntimeEndpoint(org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint) Route(io.fabric8.openshift.api.model.Route)

Aggregations

Route (io.fabric8.openshift.api.model.Route)3 RouteSpec (io.fabric8.openshift.api.model.RouteSpec)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 RouteTargetReference (io.fabric8.openshift.api.model.RouteTargetReference)2 RouteTargetReferenceBuilder (io.fabric8.openshift.api.model.RouteTargetReferenceBuilder)2 KubernetesHelper.createIntOrString (io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString)1 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)1 RoutePort (io.fabric8.openshift.api.model.RoutePort)1 OpenShiftClientException (org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException)1 OpenShiftRuntimeEndpoint (org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint)1