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;
}
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;
}
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);
}
}
Aggregations