use of org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException in project che-server by eclipse-che.
the class KubernetesDeployments method waitAsync.
/**
* Returns a future which completes when pod state satisfies the specified predicate.
*
* <p>Note that for resource cleanup, the resulting future must be explicitly cancelled when its
* completion no longer important.
*
* @param name name of pod or deployment containing pod that should be watched
* @param predicate predicate to perform state check
* @return pod that satisfies the specified predicate
* @throws InfrastructureException when specified pod or deployment does not exist
* @throws InfrastructureException when any other exception occurs
*/
public CompletableFuture<Pod> waitAsync(String name, Predicate<Pod> predicate) throws InfrastructureException {
String podName = getPodName(name);
CompletableFuture<Pod> future = new CompletableFuture<>();
try {
PodResource<Pod> podResource = clientFactory.create(workspaceId).pods().inNamespace(namespace).withName(podName);
Watch watch = podResource.watch(new Watcher<>() {
@Override
public void eventReceived(Action action, Pod pod) {
if (predicate.test(pod)) {
future.complete(pod);
}
}
@Override
public void onClose(WatcherException cause) {
future.completeExceptionally(new InfrastructureException("Waiting for pod '" + podName + "' was interrupted"));
}
});
Pod actualPod = podResource.get();
if (actualPod == null) {
if (name.equals(podName)) {
// `name` refers to a bare pod
throw new InfrastructureException("Specified pod " + podName + " doesn't exist");
} else {
// `name` refers to a deployment
throw new InfrastructureException("No pod in deployment " + name + " found.");
}
}
if (predicate.test(actualPod)) {
return CompletableFuture.completedFuture(actualPod);
}
future.whenComplete((ok, ex) -> watch.close());
return future;
} catch (KubernetesClientException e) {
throw new KubernetesInfrastructureException(e);
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException in project che-server by eclipse-che.
the class KubernetesServices method create.
/**
* Creates specified service.
*
* @param service service to create
* @return created service
* @throws InfrastructureException when any exception occurs
*/
public Service create(Service service) throws InfrastructureException {
putLabel(service, CHE_WORKSPACE_ID_LABEL, workspaceId);
putSelector(service, CHE_WORKSPACE_ID_LABEL, workspaceId);
try {
return clientFactory.create(workspaceId).services().inNamespace(namespace).create(service);
} catch (KubernetesClientException e) {
throw new KubernetesInfrastructureException(e);
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException in project che-server by eclipse-che.
the class AsyncStoragePodInterceptor method deleteAsyncStoragePod.
private CompletableFuture<Void> deleteAsyncStoragePod(PodResource<Pod> podResource) throws InfrastructureException {
Watch toCloseOnException = null;
try {
final CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
final Watch watch = podResource.watch(new DeleteWatcher<>(deleteFuture));
toCloseOnException = watch;
Boolean deleteSucceeded = podResource.withPropagationPolicy(BACKGROUND).delete();
if (deleteSucceeded == null || !deleteSucceeded) {
deleteFuture.complete(null);
}
return deleteFuture.whenComplete((v, e) -> {
if (e != null) {
LOG.warn("Failed to remove pod {} cause {}", ASYNC_STORAGE, e.getMessage());
}
watch.close();
});
} catch (KubernetesClientException e) {
if (toCloseOnException != null) {
toCloseOnException.close();
}
throw new KubernetesInfrastructureException(e);
} catch (Exception e) {
if (toCloseOnException != null) {
toCloseOnException.close();
}
throw e;
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException in project che-server by eclipse-che.
the class AsyncStoragePodInterceptor method deleteAsyncStorageDeployment.
private CompletableFuture<Void> deleteAsyncStorageDeployment(RollableScalableResource<Deployment> resource) throws InfrastructureException {
Watch toCloseOnException = null;
try {
final CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
final Watch watch = resource.watch(new DeleteWatcher<>(deleteFuture));
toCloseOnException = watch;
Boolean deleteSucceeded = resource.withPropagationPolicy(BACKGROUND).delete();
if (deleteSucceeded == null || !deleteSucceeded) {
deleteFuture.complete(null);
}
return deleteFuture.whenComplete((v, e) -> {
if (e != null) {
LOG.warn("Failed to remove deployment {} cause {}", ASYNC_STORAGE, e.getMessage());
}
watch.close();
});
} catch (KubernetesClientException e) {
if (toCloseOnException != null) {
toCloseOnException.close();
}
throw new KubernetesInfrastructureException(e);
} catch (Exception e) {
if (toCloseOnException != null) {
toCloseOnException.close();
}
throw e;
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException in project che-server by eclipse-che.
the class OpenShiftProject method delete.
/**
* Deletes the project. Deleting a non-existent projects is not an error as is not an attempt to
* delete a project that is already being deleted.
*
* @throws InfrastructureException if any unexpected exception occurs during project deletion
*/
void delete() throws InfrastructureException {
String workspaceId = getWorkspaceId();
String projectName = getName();
OpenShiftClient osClient = clientFactory.createOC(workspaceId);
try {
delete(projectName, osClient);
} catch (KubernetesClientException e) {
if (e.getCode() == 403) {
throw new InfrastructureException(format("Could not access the project %s when deleting it for workspace %s", projectName, workspaceId), e);
}
throw new KubernetesInfrastructureException(e);
}
}
Aggregations