use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project devspaces-images by redhat-developer.
the class KubernetesMachinesCacheTest method shouldThrowExceptionWhenServerWasNotFoundOnGetting.
@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Server with name 'non-existing' was not found")
public void shouldThrowExceptionWhenServerWasNotFoundOnGetting() throws Exception {
// given
RuntimeIdentity runtimeId = runtimeStates[0].getRuntimeId();
KubernetesMachineImpl machine = machines[0];
// when
machineCache.getServer(runtimeId, machine.getName(), "non-existing");
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project devspaces-images by redhat-developer.
the class KubernetesMachinesCacheTest method shouldPutMachine.
@Test
public void shouldPutMachine() throws Exception {
// given
KubernetesMachineImpl machine = createMachine(workspaces[1].getId(), "machine2", MachineStatus.RUNNING, ImmutableMap.of("myServer", createServer(ServerStatus.RUNNING)));
// when
machineCache.put(runtimeStates[1].getRuntimeId(), machine);
// then
Map<String, KubernetesMachineImpl> fetched = machineCache.getMachines(runtimeStates[1].getRuntimeId());
assertEquals(2, fetched.size());
assertTrue(fetched.containsKey("machine2"));
assertTrue(fetched.containsValue(machine));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project devspaces-images by redhat-developer.
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.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project devspaces-images by redhat-developer.
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.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntime method watchLogsIfDebugEnabled.
private void watchLogsIfDebugEnabled(Map<String, String> startOptions) throws InfrastructureException {
if (LogWatcher.shouldWatchLogs(startOptions)) {
LOG.info("Debug workspace startup. Will watch the logs of '{}'", getContext().getIdentity().getWorkspaceId());
// get all the pods we care about
Set<String> podNames = machines.getMachines(getContext().getIdentity()).values().stream().filter(Objects::nonNull).map(KubernetesMachineImpl::getPodName).filter(Objects::nonNull).collect(Collectors.toSet());
LOG.debug("Watch '{}' pods in workspace '{}'", podNames, getContext().getIdentity().getWorkspaceId());
namespace.deployments().watchLogs(new PodLogToEventPublisher(this.eventPublisher, this.getContext().getIdentity()), this.eventPublisher, LogWatchTimeouts.DEFAULT, podNames, LogWatcher.getLogLimitBytes(startOptions));
}
}
Aggregations