use of org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_PREFIX 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()));
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_PREFIX 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()));
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_PREFIX in project che-server by eclipse-che.
the class KubernetesServerExposerTest method assertThatServicePortIsExposed.
private ServicePort assertThatServicePortIsExposed(Integer port, Service service) {
Optional<ServicePort> servicePortOpt = service.getSpec().getPorts().stream().filter(p -> p.getTargetPort().getIntVal().equals(port)).findAny();
assertTrue(servicePortOpt.isPresent());
ServicePort servicePort = servicePortOpt.get();
assertEquals(servicePort.getTargetPort().getIntVal(), port);
assertEquals(servicePort.getPort(), port);
assertEquals(servicePort.getName(), SERVER_PREFIX + "-" + port);
return servicePort;
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_PREFIX in project devspaces-images by redhat-developer.
the class KubernetesServerExposerTest method assertThatServicePortIsExposed.
private ServicePort assertThatServicePortIsExposed(Integer port, Service service) {
Optional<ServicePort> servicePortOpt = service.getSpec().getPorts().stream().filter(p -> p.getTargetPort().getIntVal().equals(port)).findAny();
assertTrue(servicePortOpt.isPresent());
ServicePort servicePort = servicePortOpt.get();
assertEquals(servicePort.getTargetPort().getIntVal(), port);
assertEquals(servicePort.getPort(), port);
assertEquals(servicePort.getName(), SERVER_PREFIX + "-" + port);
return servicePort;
}
Aggregations