Search in sources :

Example 11 with RuntimeIdentityImpl

use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.

the class WorkspaceRuntimesTest method runtimeIsNotRecoveredIfNoWorkspaceFound.

@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Workspace configuration is missing for the runtime 'workspace123:my-env'. Runtime won't be recovered")
public void runtimeIsNotRecoveredIfNoWorkspaceFound() throws Exception {
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace");
    when(workspaceDao.get(identity.getWorkspaceId())).thenThrow(new NotFoundException("no!"));
    // try recover
    runtimes.recoverOne(infrastructure, identity);
    assertFalse(runtimes.hasRuntime(identity.getWorkspaceId()));
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) NotFoundException(org.eclipse.che.api.core.NotFoundException) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 12 with RuntimeIdentityImpl

use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.

the class WorkspaceRuntimesTest method shouldUseInfraNamespaceAttributeOnStartAsync.

@Test
public void shouldUseInfraNamespaceAttributeOnStartAsync() throws Exception {
    EnvironmentContext.getCurrent().setSubject(new SubjectImpl("username", "user123", null, false));
    WorkspaceImpl workspace = mockWorkspaceWithDevfile("workspace123", "env");
    workspace.getAttributes().put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "infraNamespace");
    RuntimeContext context = mockContext(new RuntimeIdentityImpl("workspace123", "env", "user123", "infraNamespace"));
    doReturn(context.getEnvironment()).when(testEnvFactory).create(any());
    runtimes.startAsync(workspace, null, emptyMap());
    ArgumentCaptor<RuntimeIdentity> runtimeIdCaptor = ArgumentCaptor.forClass(RuntimeIdentity.class);
    verify(infrastructure).prepare(runtimeIdCaptor.capture(), any());
    RuntimeIdentity runtimeId = runtimeIdCaptor.getValue();
    assertEquals(runtimeId.getInfrastructureNamespace(), "infraNamespace");
    assertWorkspaceEventFired("workspace123", WorkspaceStatus.STARTING, WorkspaceStatus.STOPPED, null, true, Collections.emptyMap());
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 13 with RuntimeIdentityImpl

use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.

the class WorkspaceRuntimesTest method shouldSuspendRecoverIfEnvironmentFactoryCannotBeFound.

@Test
public void shouldSuspendRecoverIfEnvironmentFactoryCannotBeFound() throws Exception {
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "default", "myId", "infraNamespace");
    WorkspaceConfigImpl config = mock(WorkspaceConfigImpl.class);
    EnvironmentImpl environment = mock(EnvironmentImpl.class);
    when(environment.getRecipe()).thenReturn(new RecipeImpl("UNKNOWN", "contentType1", "content1", null));
    doReturn(ImmutableMap.of(identity.getEnvName(), environment)).when(config).getEnvironments();
    WorkspaceImpl workspace = mock(WorkspaceImpl.class);
    when(workspace.getConfig()).thenReturn(config);
    when(workspaceDao.get(identity.getWorkspaceId())).thenReturn(workspace);
    // try recover
    try {
        runtimes.recoverOne(infrastructure, identity);
        fail("Not expected");
    } catch (ServerException e) {
    }
    ;
    verify(statuses).remove("workspace123");
    assertWorkspaceEventFired("workspace123", WorkspaceStatus.STOPPED, WorkspaceStatus.STOPPING, "Workspace is stopped. Reason: InternalEnvironmentFactory is not configured for recipe type: 'UNKNOWN'", false, Collections.emptyMap());
    assertFalse(runtimesMap.containsKey("workspace123"));
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 14 with RuntimeIdentityImpl

use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.

the class WorkspaceRuntimesTest method shouldReturnRuntimesIdsOfActiveWorkspacesForGivenOwner.

@Test
public void shouldReturnRuntimesIdsOfActiveWorkspacesForGivenOwner() throws Exception {
    // given
    String ws1 = generate("workspace", 6);
    String ws2 = generate("workspace", 6);
    String ws3 = generate("workspace", 6);
    String owner = generate("user", 6);
    when(statuses.asMap()).thenReturn(ImmutableMap.of(ws1, WorkspaceStatus.STARTING, ws2, WorkspaceStatus.RUNNING, ws3, WorkspaceStatus.STOPPING));
    RuntimeIdentityImpl runtimeIdentity1 = new RuntimeIdentityImpl(ws1, generate("env", 6), owner, generate("infraNamespace", 6));
    RuntimeIdentityImpl runtimeIdentity2 = new RuntimeIdentityImpl(ws2, generate("env", 6), generate("user", 6), generate("infraNamespace", 6));
    RuntimeIdentityImpl runtimeIdentity3 = new RuntimeIdentityImpl(ws3, generate("env", 6), generate("user", 6), generate("infraNamespace", 6));
    mockWorkspaceWithConfig(runtimeIdentity1);
    mockWorkspaceWithConfig(runtimeIdentity2);
    mockWorkspaceWithConfig(runtimeIdentity3);
    RuntimeContext context1 = mockContext(runtimeIdentity1);
    RuntimeContext context2 = mockContext(runtimeIdentity2);
    RuntimeContext context3 = mockContext(runtimeIdentity3);
    when(context1.getRuntime()).thenReturn(new TestInternalRuntime(context1, emptyMap(), WorkspaceStatus.STARTING));
    when(context2.getRuntime()).thenReturn(new TestInternalRuntime(context2, emptyMap(), WorkspaceStatus.RUNNING));
    when(context3.getRuntime()).thenReturn(new TestInternalRuntime(context3, emptyMap(), WorkspaceStatus.STOPPING));
    doReturn(context1).when(infrastructure).prepare(eq(runtimeIdentity1), any());
    doReturn(context2).when(infrastructure).prepare(eq(runtimeIdentity2), any());
    doReturn(context3).when(infrastructure).prepare(eq(runtimeIdentity3), any());
    Set<RuntimeIdentity> identities = ImmutableSet.of(runtimeIdentity1, runtimeIdentity2, runtimeIdentity3);
    doReturn(identities).when(infrastructure).getIdentities();
    InternalEnvironment internalEnvironment = mock(InternalEnvironment.class);
    doReturn(internalEnvironment).when(testEnvFactory).create(any(Environment.class));
    // when
    Set<String> active = runtimes.getActive(owner);
    // then
    assertEquals(active.size(), 1);
    assertTrue(active.containsAll(asList(ws1)));
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) Environment(org.eclipse.che.api.core.model.workspace.config.Environment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 15 with RuntimeIdentityImpl

use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.

the class WorkspaceRuntimesTest method runtimeIsRecoveredForWorkspaceWithDevfile.

@Test
public void runtimeIsRecoveredForWorkspaceWithDevfile() throws Exception {
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "default", "myId", "infraNamespace");
    WorkspaceImpl workspaceMock = mockWorkspaceWithDevfile(identity);
    RuntimeContext context = mockContext(identity);
    when(context.getRuntime()).thenReturn(new TestInternalRuntime(context, emptyMap(), WorkspaceStatus.STARTING));
    doReturn(context).when(infrastructure).prepare(eq(identity), any());
    doReturn(mock(InternalEnvironment.class)).when(testEnvFactory).create(any());
    when(statuses.get(anyString())).thenReturn(WorkspaceStatus.STARTING);
    // try recover
    runtimes.recoverOne(infrastructure, identity);
    WorkspaceImpl workspace = WorkspaceImpl.builder().setId(identity.getWorkspaceId()).build();
    runtimes.injectRuntime(workspace);
    assertNotNull(workspace.getRuntime());
    assertEquals(workspace.getStatus(), WorkspaceStatus.STARTING);
    verify(devfileConverter).convert(workspaceMock.getDevfile());
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Aggregations

RuntimeIdentityImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl)98 Test (org.testng.annotations.Test)92 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)68 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)22 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)18 RuntimeContext (org.eclipse.che.api.workspace.server.spi.RuntimeContext)18 InternalEnvironment (org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment)16 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)14 SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)10 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)8 Secret (io.fabric8.kubernetes.api.model.Secret)8 ValidationException (org.eclipse.che.api.core.ValidationException)8 Environment (org.eclipse.che.api.core.model.workspace.config.Environment)8 EventService (org.eclipse.che.api.core.notification.EventService)8 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)8 CredentialsSecretConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.CredentialsSecretConfigurator)8 PreferencesConfigMapConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.PreferencesConfigMapConfigurator)8 WorkspaceServiceAccountConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.WorkspaceServiceAccountConfigurator)8