use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class InconsistentRuntimesDetector method getKubernetesInternalRuntime.
private KubernetesInternalRuntime getKubernetesInternalRuntime(String workspaceId) throws InfrastructureException {
InternalRuntime<?> internalRuntime;
try {
internalRuntime = workspaceRuntimes.getInternalRuntime(workspaceId);
} catch (InfrastructureException | ServerException e) {
throw new InfrastructureException(format("Failed to get internal runtime for workspace `%s` to check consistency. Cause: %s", workspaceId, e.getMessage()), e);
}
RuntimeIdentity runtimeId = internalRuntime.getContext().getIdentity();
if (!(internalRuntime instanceof KubernetesInternalRuntime)) {
// must not happen
throw new InfrastructureException(format("Fetched internal runtime '%s:%s' is not Kubernetes, it is not possible to check consistency.", runtimeId.getWorkspaceId(), runtimeId.getOwnerId()));
}
return (KubernetesInternalRuntime) internalRuntime;
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class RuntimeHangingDetector method handleHangingStartingRuntime.
private void handleHangingStartingRuntime(KubernetesInternalRuntime runtime) {
RuntimeIdentity runtimeId = runtime.getContext().getIdentity();
eventPublisher.sendAbnormalStoppingEvent(runtimeId, "Workspace is not started in time. Trying interrupt runtime start");
try {
runtime.stop(emptyMap());
LOG.info("Start of hanging runtime '{}:{}:{}' is interrupted", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId());
} catch (InfrastructureException e) {
LOG.error("Error occurred during start interruption of hanging runtime '{}:{}:{}'. Error: {}", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId(), e.getMessage(), e);
} finally {
eventPublisher.sendAbnormalStoppedEvent(runtimeId, "Workspace start reached timeout");
}
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class RuntimeHangingDetector method handleHangingStoppingRuntime.
private void handleHangingStoppingRuntime(KubernetesInternalRuntime runtime) {
RuntimeIdentity runtimeId = runtime.getContext().getIdentity();
eventPublisher.sendAbnormalStoppingEvent(runtimeId, "Workspace is not stopped in time. Trying to stop it forcibly");
try {
LOG.info("Runtime '{}:{}:{}' is not stopped in time. Stopped it forcibly", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId());
runtime.internalStop(emptyMap());
} catch (InfrastructureException e) {
LOG.error("Error occurred during forcibly stopping of hanging runtime '{}:{}:{}'. Error: {}", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId(), e.getMessage(), e);
} finally {
try {
runtime.markStopped();
} catch (InfrastructureException e) {
LOG.error("Error occurred during marking hanging runtime as stopped '{}:{}:{}'. Error: {}", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId(), e.getMessage(), e);
}
eventPublisher.sendAbnormalStoppedEvent(runtimeId, "Workspace stop reached timeout");
}
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project devspaces-images by redhat-developer.
the class OpenShiftProjectFactoryTest method testUsernamePlaceholderInAnnotationsIsEvaluated.
@Test
public void testUsernamePlaceholderInAnnotationsIsEvaluated() throws InfrastructureException {
// given
projectFactory = spy(new OpenShiftProjectFactory("<userid>-che", true, true, true, NAMESPACE_LABELS, "try_placeholder_here=<username>", true, emptySet(), clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER));
EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "123", null, false));
OpenShiftProject toReturnProject = mock(OpenShiftProject.class);
prepareProject(toReturnProject);
doReturn(toReturnProject).when(projectFactory).doCreateProjectAccess(any(), any());
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "old-che");
OpenShiftProject project = projectFactory.getOrCreate(identity);
// then
assertEquals(toReturnProject, project);
verify(toReturnProject).prepare(eq(false), eq(false), any(), eq(Map.of("try_placeholder_here", "jondoe")));
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project devspaces-images by redhat-developer.
the class OpenShiftProjectFactoryTest method shouldRequireNamespacePriorExistenceIfDifferentFromDefaultAndUserDefinedIsNotAllowed.
@Test
public void shouldRequireNamespacePriorExistenceIfDifferentFromDefaultAndUserDefinedIsNotAllowed() throws Exception {
// There is only one scenario where this can happen. The workspace was created and started in
// some default namespace. Then server was reconfigured to use a different default namespace
// AND the namespace of the workspace was MANUALLY deleted in the cluster. In this case, we
// should NOT try to re-create the namespace because it would be created in a namespace that
// is not configured. We DO allow it to start if the namespace still exists though.
// given
projectFactory = spy(new OpenShiftProjectFactory("<userid>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, true, emptySet(), clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER));
OpenShiftProject toReturnProject = mock(OpenShiftProject.class);
prepareProject(toReturnProject);
doReturn(toReturnProject).when(projectFactory).doCreateProjectAccess(any(), any());
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "old-default");
OpenShiftProject project = projectFactory.getOrCreate(identity);
// then
assertEquals(toReturnProject, project);
verify(toReturnProject).prepare(eq(false), eq(false), any(), any());
}
Aggregations