Search in sources :

Example 41 with RuntimeIdentity

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;
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) ServerException(org.eclipse.che.api.core.ServerException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 42 with RuntimeIdentity

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");
    }
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 43 with RuntimeIdentity

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");
    }
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 44 with RuntimeIdentity

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")));
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 45 with RuntimeIdentity

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());
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Aggregations

RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)128 Test (org.testng.annotations.Test)88 RuntimeIdentityImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl)70 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)40 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)28 InternalEnvironment (org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment)24 RuntimeContext (org.eclipse.che.api.workspace.server.spi.RuntimeContext)22 Map (java.util.Map)20 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)18 List (java.util.List)16 Set (java.util.Set)14 ServerException (org.eclipse.che.api.core.ServerException)14 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)14 Traced (org.eclipse.che.commons.annotation.Traced)14 KubernetesMachineImpl (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)12 Secret (io.fabric8.kubernetes.api.model.Secret)12 String.format (java.lang.String.format)12 Collectors (java.util.stream.Collectors)12 Named (javax.inject.Named)12