use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class OpenShiftProjectFactoryTest method testAllConfiguratorsAreCalledWhenCreatingProject.
@Test
public void testAllConfiguratorsAreCalledWhenCreatingProject() throws InfrastructureException {
// given
String projectName = "testprojectname";
NamespaceConfigurator configurator1 = Mockito.mock(NamespaceConfigurator.class);
NamespaceConfigurator configurator2 = Mockito.mock(NamespaceConfigurator.class);
Set<NamespaceConfigurator> namespaceConfigurators = Set.of(configurator1, configurator2);
projectFactory = spy(new OpenShiftProjectFactory("<username>-che", true, true, true, NAMESPACE_LABELS, "try_placeholder_here=<username>", true, namespaceConfigurators, clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER));
EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "123", null, false));
OpenShiftProject toReturnProject = mock(OpenShiftProject.class);
when(toReturnProject.getName()).thenReturn(projectName);
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "old-che");
doReturn(toReturnProject).when(projectFactory).get(identity);
// when
OpenShiftProject project = projectFactory.getOrCreate(identity);
// then
NamespaceResolutionContext resolutionCtx = new NamespaceResolutionContext("workspace123", "123", "jondoe");
verify(configurator1).configure(resolutionCtx, projectName);
verify(configurator2).configure(resolutionCtx, projectName);
assertEquals(project, toReturnProject);
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class OpenShiftProjectFactoryTest method shouldCreateCredentialsSecretIfNotExists.
@Test
public void shouldCreateCredentialsSecretIfNotExists() 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);
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> nullSecret = mock(Resource.class);
when(namespaceOperation.withName(CREDENTIALS_SECRET_NAME)).thenReturn(nullSecret);
when(nullSecret.get()).thenReturn(null);
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "namespace123");
projectFactory.getOrCreate(identity);
// then
ArgumentCaptor<Secret> secretsCaptor = ArgumentCaptor.forClass(Secret.class);
verify(namespaceOperation).create(secretsCaptor.capture());
Secret secret = secretsCaptor.getValue();
Assert.assertEquals(secret.getMetadata().getName(), CREDENTIALS_SECRET_NAME);
Assert.assertEquals(secret.getType(), "opaque");
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class OpenShiftProjectFactoryTest method shouldCreatePreferencesConfigmapIfNotExists.
@Test
public void shouldCreatePreferencesConfigmapIfNotExists() throws Exception {
// given
projectFactory = spy(new OpenShiftProjectFactory("<userid>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, true, Set.of(new PreferencesConfigMapConfigurator(clientFactory)), clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER));
OpenShiftProject toReturnProject = mock(OpenShiftProject.class);
doReturn(toReturnProject).when(projectFactory).doCreateProjectAccess(any(), any());
when(toReturnProject.getName()).thenReturn("namespace123");
NonNamespaceOperation namespaceOperation = mock(NonNamespaceOperation.class);
MixedOperation mixedOperation = mock(MixedOperation.class);
when(osClient.configMaps()).thenReturn(mixedOperation);
when(mixedOperation.inNamespace(anyString())).thenReturn(namespaceOperation);
Resource<ConfigMap> nullCm = mock(Resource.class);
when(namespaceOperation.withName(PREFERENCES_CONFIGMAP_NAME)).thenReturn(nullCm);
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
projectFactory.getOrCreate(identity);
// then
ArgumentCaptor<ConfigMap> configMapCaptor = ArgumentCaptor.forClass(ConfigMap.class);
verify(namespaceOperation).create(configMapCaptor.capture());
ConfigMap configmap = configMapCaptor.getValue();
Assert.assertEquals(configmap.getMetadata().getName(), PREFERENCES_CONFIGMAP_NAME);
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class WorkspaceRuntimesTest method shouldNotInjectRuntimeIfExceptionOccurredOnRuntimeFetching.
@Test
public void shouldNotInjectRuntimeIfExceptionOccurredOnRuntimeFetching() throws Exception {
// given
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace");
mockWorkspaceWithConfig(identity);
when(statuses.get("workspace123")).thenReturn(WorkspaceStatus.STARTING);
mockContext(identity);
doThrow(new InfrastructureException("error")).when(infrastructure).prepare(eq(identity), any());
doReturn(ImmutableSet.of(identity)).when(infrastructure).getIdentities();
// when
WorkspaceImpl workspace = new WorkspaceImpl();
workspace.setId("workspace123");
runtimes.injectRuntime(workspace);
// then
verify(statuses).remove(eq(identity.getWorkspaceId()));
assertEquals(workspace.getStatus(), WorkspaceStatus.STOPPED);
assertNull(workspace.getRuntime());
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class WorkspaceRuntimesTest method runtimeRecoveryContinuesThroughRuntimeException.
@Test
public void runtimeRecoveryContinuesThroughRuntimeException() throws Exception {
// Given
RuntimeIdentityImpl identity1 = new RuntimeIdentityImpl("workspace1", "env1", "owner1", "infraNamespace");
RuntimeIdentityImpl identity2 = new RuntimeIdentityImpl("workspace2", "env2", "owner2", "infraNamespace");
RuntimeIdentityImpl identity3 = new RuntimeIdentityImpl("workspace3", "env3", "owner3", "infraNamespace");
Set<RuntimeIdentity> identities = ImmutableSet.<RuntimeIdentity>builder().add(identity1).add(identity2).add(identity3).build();
mockWorkspaceWithConfig(identity1);
mockWorkspaceWithConfig(identity2);
mockWorkspaceWithConfig(identity3);
when(statuses.get(anyString())).thenReturn(WorkspaceStatus.STARTING);
RuntimeContext context1 = mockContext(identity1);
when(context1.getRuntime()).thenReturn(new TestInternalRuntime(context1, emptyMap(), WorkspaceStatus.STARTING));
doReturn(context1).when(infrastructure).prepare(eq(identity1), any());
RuntimeContext context2 = mockContext(identity2);
RuntimeContext context3 = mockContext(identity3);
when(context3.getRuntime()).thenReturn(new TestInternalRuntime(context3, emptyMap(), WorkspaceStatus.STARTING));
doReturn(context3).when(infrastructure).prepare(eq(identity3), any());
InternalEnvironment internalEnvironment = mock(InternalEnvironment.class);
doReturn(internalEnvironment).when(testEnvFactory).create(any(Environment.class));
// Want to fail recovery of identity2
doThrow(new RuntimeException("oops!")).when(infrastructure).prepare(eq(identity2), any(InternalEnvironment.class));
// When
runtimes.new RecoverRuntimesTask(identities).run();
// Then
verify(infrastructure).prepare(identity1, internalEnvironment);
verify(infrastructure).prepare(identity2, internalEnvironment);
verify(infrastructure).prepare(identity3, internalEnvironment);
WorkspaceImpl workspace1 = WorkspaceImpl.builder().setId(identity1.getWorkspaceId()).build();
runtimes.injectRuntime(workspace1);
assertNotNull(workspace1.getRuntime());
assertEquals(workspace1.getStatus(), WorkspaceStatus.STARTING);
WorkspaceImpl workspace3 = WorkspaceImpl.builder().setId(identity3.getWorkspaceId()).build();
runtimes.injectRuntime(workspace3);
assertNotNull(workspace3.getRuntime());
assertEquals(workspace3.getStatus(), WorkspaceStatus.STARTING);
}
Aggregations