use of io.fabric8.annotations.ServiceName in project fabric8 by fabric8io.
the class ServiceConverter method getServiceURL.
public String getServiceURL(KubernetesClient client, Service srv, String serviceProtocol, String servicePortName) {
String serviceName = KubernetesHelper.getName(srv);
String serviceProto = serviceProtocol != null ? serviceProtocol : KubernetesServices.serviceToProtocol(serviceName, servicePortName);
if (Strings.isNullOrBlank(servicePortName) && KubernetesHelper.isOpenShift(client)) {
OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class);
RouteList routeList = openShiftClient.routes().list();
for (Route route : routeList.getItems()) {
if (route.getSpec().getTo().getName().equals(serviceName)) {
return (serviceProto + "://" + route.getSpec().getHost()).toLowerCase();
}
}
}
ServicePort port = KubernetesHelper.findServicePortByName(srv, servicePortName);
if (port == null) {
throw new RuntimeException("Couldn't find port: " + servicePortName + " for service:" + serviceName);
}
String clusterIP = srv.getSpec().getClusterIP();
if ("None".equals(clusterIP)) {
throw new IllegalStateException("Service " + serviceName + " is head-less. Search for endpoints instead.");
}
return (serviceProto + "://" + clusterIP + ":" + port.getPort()).toLowerCase();
}
use of io.fabric8.annotations.ServiceName in project fabric8 by fabric8io.
the class KubernetesAssert method service.
/**
* Asserts that the given service name exist
*
* @return the assertion object on the given service
*/
public ServicePodsAssert service(String serviceName) {
Service service = client.services().inNamespace(namespace()).withName(serviceName).get();
assertThat(service).describedAs("No service exists for name: " + serviceName).isNotNull();
return new ServicePodsAssert(client, service);
}
Aggregations