Search in sources :

Example 1 with SERVER_UNIQUE_PART_SIZE

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_UNIQUE_PART_SIZE in project devspaces-images by redhat-developer.

the class PreviewUrlExposer method expose.

public void expose(T env) throws InternalInfrastructureException {
    List<CommandImpl> previewUrlCommands = env.getCommands().stream().filter(c -> c.getPreviewUrl() != null).collect(Collectors.toList());
    List<ServicePort> portsToProvision = new ArrayList<>();
    for (CommandImpl command : previewUrlCommands) {
        int port = command.getPreviewUrl().getPort();
        Optional<Service> foundService = Services.findServiceWithPort(env.getServices().values(), port);
        if (foundService.isPresent()) {
            if (!hasMatchingEndpoint(env, foundService.get(), port)) {
                ServicePort servicePort = Services.findPort(foundService.get(), port).orElseThrow(() -> new InternalInfrastructureException(String.format("Port '%d' in service '%s' not found. This is not expected, please report a bug!", port, foundService.get().getMetadata().getName())));
                String serviceName = foundService.get().getMetadata().getName();
                externalServerExposer.expose(env, null, serviceName, serviceName, servicePort, Collections.emptyMap());
            }
        } else {
            portsToProvision.add(createServicePort(port));
        }
    }
    if (!portsToProvision.isEmpty()) {
        String serverName = generate(SERVER_PREFIX, SERVER_UNIQUE_PART_SIZE) + "-previewUrl";
        Service service = new ServerServiceBuilder().withName(serverName).withPorts(portsToProvision).build();
        env.getServices().put(serverName, service);
        portsToProvision.forEach(port -> externalServerExposer.expose(env, null, service.getMetadata().getName(), service.getMetadata().getName(), port, Collections.emptyMap()));
    }
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ExternalServerExposerProvider(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServerExposerProvider) NameGenerator.generate(org.eclipse.che.commons.lang.NameGenerator.generate) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ExternalServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServerExposer) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) SERVER_UNIQUE_PART_SIZE(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_UNIQUE_PART_SIZE) Inject(javax.inject.Inject) SERVER_PREFIX(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_PREFIX) List(java.util.List) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Services(org.eclipse.che.workspace.infrastructure.kubernetes.util.Services) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Service(io.fabric8.kubernetes.api.model.Service) Collections(java.util.Collections) Ingresses(org.eclipse.che.workspace.infrastructure.kubernetes.util.Ingresses) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Example 2 with SERVER_UNIQUE_PART_SIZE

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_UNIQUE_PART_SIZE in project che-server by eclipse-che.

the class PreviewUrlExposer method expose.

public void expose(T env) throws InternalInfrastructureException {
    List<CommandImpl> previewUrlCommands = env.getCommands().stream().filter(c -> c.getPreviewUrl() != null).collect(Collectors.toList());
    List<ServicePort> portsToProvision = new ArrayList<>();
    for (CommandImpl command : previewUrlCommands) {
        int port = command.getPreviewUrl().getPort();
        Optional<Service> foundService = Services.findServiceWithPort(env.getServices().values(), port);
        if (foundService.isPresent()) {
            if (!hasMatchingEndpoint(env, foundService.get(), port)) {
                ServicePort servicePort = Services.findPort(foundService.get(), port).orElseThrow(() -> new InternalInfrastructureException(String.format("Port '%d' in service '%s' not found. This is not expected, please report a bug!", port, foundService.get().getMetadata().getName())));
                String serviceName = foundService.get().getMetadata().getName();
                externalServerExposer.expose(env, null, serviceName, serviceName, servicePort, Collections.emptyMap());
            }
        } else {
            portsToProvision.add(createServicePort(port));
        }
    }
    if (!portsToProvision.isEmpty()) {
        String serverName = generate(SERVER_PREFIX, SERVER_UNIQUE_PART_SIZE) + "-previewUrl";
        Service service = new ServerServiceBuilder().withName(serverName).withPorts(portsToProvision).build();
        env.getServices().put(serverName, service);
        portsToProvision.forEach(port -> externalServerExposer.expose(env, null, service.getMetadata().getName(), service.getMetadata().getName(), port, Collections.emptyMap()));
    }
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ExternalServerExposerProvider(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServerExposerProvider) NameGenerator.generate(org.eclipse.che.commons.lang.NameGenerator.generate) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ExternalServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServerExposer) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) SERVER_UNIQUE_PART_SIZE(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_UNIQUE_PART_SIZE) Inject(javax.inject.Inject) SERVER_PREFIX(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_PREFIX) List(java.util.List) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Services(org.eclipse.che.workspace.infrastructure.kubernetes.util.Services) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Service(io.fabric8.kubernetes.api.model.Service) Collections(java.util.Collections) Ingresses(org.eclipse.che.workspace.infrastructure.kubernetes.util.Ingresses) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 Service (io.fabric8.kubernetes.api.model.Service)2 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)2 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)2 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)2 NameGenerator.generate (org.eclipse.che.commons.lang.NameGenerator.generate)2 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)2 SERVER_PREFIX (org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_PREFIX)2 SERVER_UNIQUE_PART_SIZE (org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_UNIQUE_PART_SIZE)2 ExternalServerExposer (org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServerExposer)2 ExternalServerExposerProvider (org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServerExposerProvider)2