use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class KubernetesInternalRuntime method checkServers.
/**
* Returns a function, the result of which the completable stage that performs servers checks and
* start of servers probes.
*/
private Function<Void, CompletionStage<Void>> checkServers(List<CompletableFuture<?>> toCancelFutures, KubernetesMachineImpl machine) {
// Need to get active span here to allow use in returned function;
final Span activeSpan = tracer.activeSpan();
return ignored -> {
// Span must be created within this lambda block, otherwise the span begins as soon as
// this function is called (i.e. before the previous steps in the machine boot chain
// are complete
final Span tracingSpan = tracer.buildSpan(CHECK_SERVERS).asChildOf(activeSpan).start();
TracingTags.WORKSPACE_ID.set(tracingSpan, getContext().getIdentity().getWorkspaceId());
TracingTags.MACHINE_NAME.set(tracingSpan, machine.getName());
// This completable future is used to unity the servers checks and start of probes
final CompletableFuture<Void> serversAndProbesFuture = new CompletableFuture<>();
final String machineName = machine.getName();
final RuntimeIdentity runtimeId = getContext().getIdentity();
final ServersChecker serverCheck = serverCheckerFactory.create(runtimeId, machineName, machine.getServers());
final CompletableFuture<?> serversReadyFuture;
LOG.debug("Performing servers check for machine '{}' in workspace '{}'", machineName, runtimeId.getWorkspaceId());
try {
serversReadyFuture = serverCheck.startAsync(new ServerReadinessHandler(machineName));
toCancelFutures.add(serversReadyFuture);
serversAndProbesFuture.whenComplete((ok, ex) -> {
LOG.debug("Servers checks done for machine '{}' in workspace '{}'", machineName, runtimeId.getWorkspaceId());
serversReadyFuture.cancel(true);
});
} catch (InfrastructureException ex) {
serversAndProbesFuture.completeExceptionally(ex);
TracingTags.setErrorStatus(tracingSpan, ex);
tracingSpan.finish();
return serversAndProbesFuture;
}
serversReadyFuture.whenComplete((BiConsumer<Object, Throwable>) (ok, ex) -> {
if (ex != null) {
serversAndProbesFuture.completeExceptionally(ex);
TracingTags.setErrorStatus(tracingSpan, ex);
tracingSpan.finish();
return;
}
try {
probeScheduler.schedule(probesFactory.getProbes(runtimeId, machineName, machine.getServers()), new ServerLivenessHandler());
} catch (InfrastructureException iex) {
serversAndProbesFuture.completeExceptionally(iex);
}
serversAndProbesFuture.complete(null);
tracingSpan.finish();
});
return serversAndProbesFuture;
};
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class KubernetesInternalRuntime method storeStartingMachine.
/**
* Puts createdPod in the {@code machines} map and sends the starting event for this machine
*/
private void storeStartingMachine(Pod createdPod, ObjectMeta toCreateMeta, Map<String, InternalMachineConfig> machineConfigs, ServerResolver serverResolver) throws InfrastructureException {
final String workspaceId = getContext().getIdentity().getWorkspaceId();
for (Container container : createdPod.getSpec().getContainers()) {
String machineName = Names.machineName(toCreateMeta, container);
LOG.debug("Creating machine '{}' in workspace '{}'", machineName, workspaceId);
// Sometimes we facing NPE trying to retrieve machine config. Possible names mismatch. Need to
// get more info on that cases.
InternalMachineConfig machineConfig = Optional.ofNullable(machineConfigs.get(machineName)).orElseThrow(() -> {
LOG.error("Workspace '{}' start failed. Machine with name '{}' requested but not found in configs map. Present machines are: {}.", workspaceId, machineName, String.join(",", machineConfigs.keySet()));
return new InfrastructureException(format("Unable to start the workspace '%s' due to an internal inconsistency while composing the workspace runtime." + "Please report a bug. If possible, include the details from Che devfile and server log in bug report (your admin can help with that)", workspaceId));
});
machines.put(getContext().getIdentity(), new KubernetesMachineImpl(workspaceId, machineName, createdPod.getMetadata().getName(), container.getName(), MachineStatus.STARTING, machineConfig.getAttributes(), serverResolver.resolve(machineName)));
eventPublisher.sendStartingEvent(machineName, getContext().getIdentity());
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class KubernetesInternalRuntime method internalStop.
@Traced
@Override
protected void internalStop(Map<String, String> stopOptions) throws InfrastructureException {
RuntimeIdentity identity = getContext().getIdentity();
TracingTags.WORKSPACE_ID.set(identity.getWorkspaceId());
runtimeHangingDetector.stopTracking(getContext().getIdentity());
if (startSynchronizer.interrupt()) {
// runtime is STARTING. Need to wait until start will be interrupted properly
try {
if (!startSynchronizer.awaitInterruption(workspaceStartTimeoutMin, TimeUnit.MINUTES)) {
// Runtime is not interrupted yet. It may occur when start was performing by another
// Che Server that is crashed so start is hung up in STOPPING phase.
// Need to clean up runtime resources
probeScheduler.cancel(identity.getWorkspaceId());
runtimeCleaner.cleanUp(namespace, identity.getWorkspaceId());
}
} catch (InterruptedException e) {
throw new InfrastructureException("Interrupted while waiting for start task cancellation", e);
}
} else {
// runtime is RUNNING. Clean up used resources
// Cancels workspace servers probes if any
probeScheduler.cancel(identity.getWorkspaceId());
runtimeCleaner.cleanUp(namespace, identity.getWorkspaceId());
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class DirectKubernetesAPIAccessHelper method call.
/**
* This method just performs an HTTP request of given {@code httpMethod} on an URL composed of the
* {@code masterUrl} and {@code relativeUri} using the provided {@code httpClient}, optionally
* sending the provided {@code body}.
*
* @param masterUrl the base of the final URL
* @param httpClient the HTTP client to perform the request with
* @param httpMethod the HTTP method of the request
* @param relativeUri the relative URI that should be appended ot the {@code masterUrl}
* @param body the body to send with the request, if any
* @return the HTTP response received
* @throws InfrastructureException on failure to validate or perform the request
*/
public static Response call(String masterUrl, OkHttpClient httpClient, String httpMethod, URI relativeUri, @Nullable HttpHeaders headers, @Nullable InputStream body) throws InfrastructureException {
if (relativeUri.isAbsolute() || relativeUri.isOpaque()) {
throw new InfrastructureException("The direct infrastructure URL must be relative and not opaque.");
}
try {
URL fullUrl = new URI(masterUrl).resolve(relativeUri).toURL();
okhttp3.Response response = callApi(httpClient, fullUrl, httpMethod, headers, body);
return convertResponse(response);
} catch (URISyntaxException | MalformedURLException e) {
throw new InfrastructureException("Could not compose the direct URI.", e);
} catch (IOException e) {
throw new InfrastructureException("Error sending the direct infrastructure request.", e);
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class InconsistentRuntimesDetector method checkOne.
@VisibleForTesting
void checkOne(String workspaceId) throws InfrastructureException {
LOG.debug("Checking consistency of runtime for workspace `{}`", workspaceId);
KubernetesInternalRuntime k8sRuntime = getKubernetesInternalRuntime(workspaceId);
RuntimeIdentity runtimeId = k8sRuntime.getContext().getIdentity();
try {
if (k8sRuntime.isConsistent()) {
return;
}
} catch (InfrastructureException e) {
throw new InfrastructureException(format("Error occurred during runtime '%s:%s' consistency checking. Cause: %s", runtimeId.getWorkspaceId(), runtimeId.getOwnerId(), e.getMessage()), e);
}
// not to initialize abnormal stop for a runtime that is not RUNNING anymore
if (!isRunning(k8sRuntime)) {
return;
}
LOG.warn("Found runtime `{}:{}` with inconsistent state. It's going to be stopped automatically", runtimeId.getWorkspaceId(), runtimeId.getOwnerId());
stopAbnormally(k8sRuntime);
LOG.debug("Checking consistency of runtime for workspace `{}` is finished", workspaceId);
}
Aggregations