use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project devspaces-images by redhat-developer.
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 ServersChecker method startAsync.
/**
* Asynchronously starts checking readiness of servers of a machine. Method {@link #await()} waits
* the result of this asynchronous check.
*
* @param serverReadinessHandler consumer which will be called with server reference as the
* argument when server become available
* @throws InternalInfrastructureException if check of a server failed due to an unexpected error
* @throws InfrastructureException if check of a server failed due to an error
*/
public CompletableFuture<?> startAsync(Consumer<String> serverReadinessHandler) throws InfrastructureException {
timer = new Timer("ServersChecker", true);
List<ServerChecker> serverCheckers = getServerCheckers();
// should be completed with an exception if a server considered unavailable
CompletableFuture<Void> firstNonAvailable = new CompletableFuture<>();
CompletableFuture[] checkTasks = serverCheckers.stream().map(ServerChecker::getReportCompFuture).map(compFut -> compFut.thenAccept(serverReadinessHandler).exceptionally(e -> {
// cleanup checkers tasks
timer.cancel();
firstNonAvailable.completeExceptionally(e);
return null;
})).toArray(CompletableFuture[]::new);
resultTimeoutSeconds = checkTasks.length * 180;
// should complete when all servers checks reported availability
CompletableFuture<Void> allAvailable = CompletableFuture.allOf(checkTasks);
// should complete when all servers are available or any server is unavailable
result = CompletableFuture.anyOf(allAvailable, firstNonAvailable);
for (ServerChecker serverChecker : serverCheckers) {
serverChecker.start();
}
return result;
}
use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project devspaces-images by redhat-developer.
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);
}
}
Aggregations