private Optional<URL> createUrlForService(Service service) { final String scheme = (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) ? service.getMetadata().getAnnotations().get("api.service.kubernetes.io/scheme") : "http"; final String path = (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) ? service.getMetadata().getAnnotations().get("api.service.kubernetes.io/path") : "/"; final int port = resolvePort(service); try { if (port > 0) { return Optional.of(new URL(scheme, LOCALHOST, port, path)); } else { return Optional.of(new URL(scheme, LOCALHOST, path)); } } catch (MalformedURLException e) { throw new IllegalStateException( "Cannot resolve URL for service: [" + service.getMetadata().getName() + "] in namespace:[" + namespace + "]."); } }
private Optional<URL> createUrlForService(Service service) { final String scheme = (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) ? service.getMetadata().getAnnotations().get("api.service.kubernetes.io/scheme") : "http"; final String path = (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) ? service.getMetadata().getAnnotations().get("api.service.kubernetes.io/path") : "/"; final int port = resolvePort(service); try { if (port > 0) { return Optional.of(new URL(scheme, LOCALHOST, port, path)); } else { return Optional.of(new URL(scheme, LOCALHOST, path)); } } catch (MalformedURLException e) { throw new IllegalStateException( "Cannot resolve URL for service: [" + service.getMetadata().getName() + "] in namespace:[" + namespace + "]."); } }
/** * Find the path to use . * Uses java annotations first and if not found, uses kubernetes annotations on the service object. * * @param service * The target service. * @param qualifiers * The set of qualifiers. * * @return Returns the resolved path of '/' as a fallback. */ private static String getPath(Service service, Annotation... qualifiers) { for (Annotation q : qualifiers) { if (q instanceof Scheme) { return ((Scheme) q).value(); } } if (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) { String s = service.getMetadata().getAnnotations().get(SERVICE_SCHEME); if (s != null && s.isEmpty()) { return s; } } return DEFAULT_PATH; }
/** * Find the scheme to use to connect to the service. * Uses java annotations first and if not found, uses kubernetes annotations on the service object. * * @param service * The target service. * @param qualifiers * The set of qualifiers. * * @return Returns the resolved scheme of 'http' as a fallback. */ private static String getScheme(Service service, Annotation... qualifiers) { for (Annotation q : qualifiers) { if (q instanceof Scheme) { return ((Scheme) q).value(); } } if (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) { String s = service.getMetadata().getAnnotations().get(SERVICE_SCHEME); if (s != null && s.isEmpty()) { return s; } } return DEFAULT_SCHEME; }
/** * Find the path to use . * Uses java annotations first and if not found, uses kubernetes annotations on the service object. * * @param service * The target service. * @param qualifiers * The set of qualifiers. * * @return Returns the resolved path of '/' as a fallback. */ private static String getPath(Service service, Annotation... qualifiers) { for (Annotation q : qualifiers) { if (q instanceof Scheme) { return ((Scheme) q).value(); } } if (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) { String s = service.getMetadata().getAnnotations().get(SERVICE_SCHEME); if (s != null && s.isEmpty()) { return s; } } return DEFAULT_PATH; }
/** * Find the scheme to use to connect to the service. * Uses java annotations first and if not found, uses kubernetes annotations on the service object. * * @param service * The target service. * @param qualifiers * The set of qualifiers. * * @return Returns the resolved scheme of 'http' as a fallback. */ private static String getScheme(Service service, Annotation... qualifiers) { for (Annotation q : qualifiers) { if (q instanceof Scheme) { return ((Scheme) q).value(); } } if (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) { String s = service.getMetadata().getAnnotations().get(SERVICE_SCHEME); if (s != null && s.isEmpty()) { return s; } } return DEFAULT_SCHEME; }
public ServiceCube(Service resource, OpenShiftClient client, CubeOpenShiftConfiguration configuration) { this.id = resource.getMetadata().getName(); this.resource = resource; this.client = client; this.configuration = configuration; this.portBindings = new PortBindings(); addDefaultMetadata(); }
@Override public void stop() throws CubeControlException { try { if (configuration.isNamespaceCleanupEnabled()) { client.destroy(resource); } else { logger.info("Ignoring cleanup for service " + resource.getMetadata().getName()); } this.state = State.STOPPED; } catch (Exception e) { this.state = State.STOP_FAILED; throw CubeControlException.failedStop(getId(), e); } }
public void destroy(Service resource) throws Exception { getClient().services().inNamespace(namespace).withName(resource.getMetadata().getName()).delete(); }
private int resolvePort(Service service) { final Pod pod = getRandomPod(client, service.getMetadata().getName(), namespace); final ServicePort servicePort = (service.getSpec() != null && service.getSpec().getPorts() != null) ? service.getSpec().getPorts().get(0) : null; final int containerPort = servicePort != null ? servicePort.getTargetPort().getIntVal() : 0; return portForward(pod.getMetadata().getName(), containerPort, namespace); }
private int resolvePort(Service service) { final Pod pod = getRandomPod(client, service.getMetadata().getName(), namespace); final ServicePort servicePort = (service.getSpec() != null && service.getSpec().getPorts() != null) ? service.getSpec().getPorts().get(0) : null; final int containerPort = servicePort != null ? servicePort.getTargetPort().getIntVal() : 0; return portForward(pod.getMetadata().getName(), containerPort, namespace); }
sb.append("Service: [").append(service.getMetadata().getName()).append("]") .append(" IP: [").append(service.getSpec().getClusterIP()).append("]") .append(" Ports: [ ");
sb.append("Service: [").append(service.getMetadata().getName()).append("]") .append(" IP: [").append(service.getSpec().getClusterIP()).append("]") .append(" Ports: [ ");
public void shutdown() throws Exception { if (forwarder != null) { forwarder.close(); } if (service != null) { client.services().inNamespace(namespace).withName(service.getMetadata().getName()).delete(); } if (server != null) { client.pods().inNamespace(namespace).withName(server.getMetadata().getName()).delete(); client.secrets().inNamespace(namespace).withName("gitserver-config").delete(); } }