use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.
the class KubernetesPersistentVolumeClaims method waitBound.
/**
* Waits until persistent volume claim state is bound. If used k8s Storage Class has
* 'volumeBindingMode: WaitForFirstConsumer', we don't wait to avoid deadlock.
*
* @param name name of persistent volume claim that should be watched
* @param timeoutMillis waiting timeout in milliseconds
* @return persistent volume claim that is bound or in waiting for consumer state
* @throws InfrastructureException when specified timeout is reached
* @throws InfrastructureException when {@link Thread} is interrupted while waiting
* @throws InfrastructureException when any other exception occurs
*/
public PersistentVolumeClaim waitBound(String name, long timeoutMillis) throws InfrastructureException {
try {
Resource<PersistentVolumeClaim> pvcResource = clientFactory.create(workspaceId).persistentVolumeClaims().inNamespace(namespace).withName(name);
PersistentVolumeClaim actualPvc = pvcResource.get();
if (actualPvc.getStatus().getPhase().equals(PVC_BOUND_PHASE)) {
return actualPvc;
}
CompletableFuture<PersistentVolumeClaim> future = new CompletableFuture<>();
// any of these watchers can finish the operation resolving the future
try (Watch boundWatcher = pvcIsBoundWatcher(future, pvcResource);
Watch waitingWatcher = pvcIsWaitingForConsumerWatcher(future, actualPvc)) {
return future.get(timeoutMillis, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
// should take a look.
throw new InternalInfrastructureException(e.getCause().getMessage(), e);
} catch (TimeoutException e) {
// issues that admin should take a look.
throw new InternalInfrastructureException("Waiting for persistent volume claim '" + name + "' reached timeout");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new InfrastructureException("Waiting for persistent volume claim '" + name + "' was interrupted");
}
} catch (KubernetesClientException e) {
throw new KubernetesInfrastructureException(e);
}
}
use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.
the class TerminalServerLivenessProbeConfigFactory method get.
@Override
public HttpProbeConfig get(String userId, String workspaceId, Server server) throws InternalInfrastructureException {
URI uri;
try {
uri = new URI(server.getUrl());
} catch (URISyntaxException e) {
throw new InternalInfrastructureException("Terminal agent server liveness probe url is invalid. Error: " + e.getMessage());
}
String protocol;
if ("wss".equals(uri.getScheme())) {
protocol = "https";
} else {
protocol = "http";
}
int port;
if (uri.getPort() == -1) {
if ("http".equals(protocol)) {
port = 80;
} else {
port = 443;
}
} else {
port = uri.getPort();
}
String path = uri.getPath().replaceFirst("/pty$", "/liveness");
return new HttpProbeConfig(port, uri.getHost(), protocol, path, null, successThreshold, 3, 120, 10, 10);
}
use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.
the class ServersChecker method getChecker.
private ServerChecker getChecker(String serverRef, Server server) throws InfrastructureException {
// TODO replace with correct behaviour
// workaround needed because we don't have server readiness check in the model
// Create server readiness endpoint URL
URL url;
String token;
try {
String serverUrl = server.getUrl();
if ("terminal".equals(serverRef)) {
serverUrl = serverUrl.replaceFirst("^ws", "http").replaceFirst("/pty$", "/");
}
if ("wsagent/http".equals(serverRef) && !serverUrl.endsWith("/")) {
// add trailing slash if it is not present
serverUrl = serverUrl + '/';
}
token = machineTokenProvider.getToken(runtimeIdentity.getOwnerId(), runtimeIdentity.getWorkspaceId());
url = UriBuilder.fromUri(serverUrl).build().toURL();
} catch (MalformedURLException e) {
throw new InternalInfrastructureException("Server " + serverRef + " URL is invalid. Error: " + e.getMessage(), e);
}
return doCreateChecker(url, serverRef, token);
}
use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException 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.api.workspace.server.spi.InternalInfrastructureException in project devspaces-images by redhat-developer.
the class JwtProxyConfigBuilder method build.
public String build() throws InternalInfrastructureException {
List<VerifierProxyConfig> proxyConfigs = new ArrayList<>();
Config config = new Config().withJWTProxy(new JWTProxy().withSignerProxy(new SignerProxyConfig().withEnabled(false)).withVerifiedProxyConfigs(proxyConfigs));
for (VerifierProxy verifierProxy : verifierProxies) {
VerifierConfig verifierConfig = new VerifierConfig().withAudience(workspaceId).withUpstream(verifierProxy.upstream).withMaxSkew("1m").withMaxTtl(ttl).withKeyServer(new RegistrableComponentConfig().withType("preshared").withOptions(ImmutableMap.of("issuer", issuer, "key_id", workspaceId, "public_key_path", JWT_PROXY_CONFIG_FOLDER + '/' + JWT_PROXY_PUBLIC_KEY_FILE))).withCookiesEnabled(verifierProxy.cookiesAuthEnabled).withCookiePath(ensureStartsWithSlash(verifierProxy.cookiePath)).withClaimsVerifier(Collections.singleton(new RegistrableComponentConfig().withType("static").withOptions(ImmutableMap.of("iss", issuer)))).withNonceStorage(new RegistrableComponentConfig().withType("void"));
if (!verifierProxy.excludes.isEmpty()) {
verifierConfig.setExcludes(verifierProxy.excludes);
}
if (verifierProxy.cookiesAuthEnabled && authPageUrl != null) {
verifierConfig.setAuthUrl(authPageUrl.toString());
}
if (verifierProxy.publicBasePath != null) {
verifierConfig.setPublicBasePath(verifierProxy.publicBasePath);
}
VerifierProxyConfig proxyConfig = new VerifierProxyConfig().withListenAddr(":" + verifierProxy.listenPort).withVerifierConfig(verifierConfig);
proxyConfigs.add(proxyConfig);
}
try {
return YAML_PARSER.writeValueAsString(config);
} catch (JsonProcessingException e) {
throw new InternalInfrastructureException("Error during creation of JWTProxy config YAML: " + e.getMessage(), e);
}
}
Aggregations