Search in sources :

Example 91 with RuntimeIdentityImpl

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

the class OpenShiftProjectFactoryTest method shouldNotCreateCredentialsSecretIfExist.

@Test
public void shouldNotCreateCredentialsSecretIfExist() throws Exception {
    // given
    projectFactory = spy(new OpenShiftProjectFactory("<userid>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, true, Set.of(new CredentialsSecretConfigurator(clientFactory)), 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(toReturnProject.getName()).thenReturn("namespace123");
    NonNamespaceOperation namespaceOperation = mock(NonNamespaceOperation.class);
    MixedOperation mixedOperation = mock(MixedOperation.class);
    when(osClient.secrets()).thenReturn(mixedOperation);
    when(mixedOperation.inNamespace(anyString())).thenReturn(namespaceOperation);
    Resource<Secret> secretResource = mock(Resource.class);
    when(namespaceOperation.withName(CREDENTIALS_SECRET_NAME)).thenReturn(secretResource);
    when(secretResource.get()).thenReturn(mock(Secret.class));
    // when
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
    projectFactory.getOrCreate(identity);
    // then
    verify(namespaceOperation, never()).create(any());
}
Also used : CredentialsSecretConfigurator(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.CredentialsSecretConfigurator) Secret(io.fabric8.kubernetes.api.model.Secret) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 92 with RuntimeIdentityImpl

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

the class OpenShiftProjectFactoryTest method shouldCallStopWorkspaceRoleProvisionWhenIdentityProviderIsDefined.

@Test
public void shouldCallStopWorkspaceRoleProvisionWhenIdentityProviderIsDefined() throws Exception {
    var saConf = spy(new OpenShiftWorkspaceServiceAccountConfigurator("serviceAccount", "", clientFactory));
    projectFactory = spy(new OpenShiftProjectFactory("<userid>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, true, Set.of(saConf), clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, OAUTH_IDENTITY_PROVIDER));
    OpenShiftProject toReturnProject = mock(OpenShiftProject.class);
    when(toReturnProject.getName()).thenReturn("workspace123");
    prepareProject(toReturnProject);
    doReturn(toReturnProject).when(projectFactory).doCreateProjectAccess(any(), any());
    OpenShiftWorkspaceServiceAccount serviceAccount = mock(OpenShiftWorkspaceServiceAccount.class);
    doReturn(serviceAccount).when(saConf).createServiceAccount("workspace123", "workspace123");
    // when
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
    projectFactory.getOrCreate(identity);
    // then
    verify(serviceAccount).prepare();
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) OpenShiftWorkspaceServiceAccountConfigurator(org.eclipse.che.workspace.infrastructure.openshift.project.configurator.OpenShiftWorkspaceServiceAccountConfigurator) Test(org.testng.annotations.Test)

Example 93 with RuntimeIdentityImpl

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

the class WorkspaceRuntimesTest method runtimeIsRecoveredForWorkspaceWithConfig.

@Test
public void runtimeIsRecoveredForWorkspaceWithConfig() throws Exception {
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace");
    mockWorkspaceWithConfig(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);
}
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)

Example 94 with RuntimeIdentityImpl

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

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 95 with RuntimeIdentityImpl

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

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