Search in sources :

Example 81 with DevfileImpl

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

the class EnvironmentVariableSecretApplierTest method shouldProvisionContainersWithAutomountOverrideTrue.

@Test
public void shouldProvisionContainersWithAutomountOverrideTrue() throws Exception {
    Container container_match1 = new ContainerBuilder().withName("maven").build();
    Container container_match2 = new ContainerBuilder().withName("other").build();
    DevfileImpl mock_defvile = mock(DevfileImpl.class);
    ComponentImpl component = new ComponentImpl();
    component.setAlias("maven");
    component.setAutomountWorkspaceSecrets(true);
    when(podSpec.getContainers()).thenReturn(ImmutableList.of(container_match1, container_match2));
    InternalMachineConfig internalMachineConfig = new InternalMachineConfig();
    internalMachineConfig.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, "maven");
    when(environment.getMachines()).thenReturn(ImmutableMap.of("maven", internalMachineConfig));
    when(environment.getDevfile()).thenReturn(mock_defvile);
    when(mock_defvile.getComponents()).thenReturn(singletonList(component));
    Secret secret = new SecretBuilder().withData(singletonMap("foo", "random")).withMetadata(new ObjectMetaBuilder().withName("test_secret").withAnnotations(ImmutableMap.of(ANNOTATION_ENV_NAME, "MY_FOO", ANNOTATION_MOUNT_AS, "env", ANNOTATION_AUTOMOUNT, "false")).withLabels(emptyMap()).build()).build();
    secretApplier.applySecret(environment, runtimeIdentity, secret);
    // only first container has env set
    assertEquals(container_match1.getEnv().size(), 1);
    EnvVar var = container_match1.getEnv().get(0);
    assertEquals(var.getName(), "MY_FOO");
    assertEquals(var.getValueFrom().getSecretKeyRef().getName(), "test_secret");
    assertEquals(var.getValueFrom().getSecretKeyRef().getKey(), "foo");
    assertEquals(container_match2.getEnv().size(), 0);
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 82 with DevfileImpl

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

the class URLFactoryBuilderTest method checkWithCustomDevfileAndRecipe.

@Test
public void checkWithCustomDevfileAndRecipe() throws Exception {
    DevfileImpl devfile = new DevfileImpl();
    WorkspaceConfigImpl workspaceConfigImpl = new WorkspaceConfigImpl();
    String myLocation = "http://foo-location/";
    RecipeImpl expectedRecipe = new RecipeImpl(KUBERNETES_COMPONENT_TYPE, "application/x-yaml", "content", "");
    EnvironmentImpl expectedEnv = new EnvironmentImpl(expectedRecipe, emptyMap());
    workspaceConfigImpl.setEnvironments(singletonMap("name", expectedEnv));
    workspaceConfigImpl.setDefaultEnv("name");
    when(devfileParser.parseYamlRaw(anyString())).thenReturn(new ObjectNode(JsonNodeFactory.instance));
    when(devfileParser.parseJsonNode(any(JsonNode.class), anyMap())).thenReturn(devfile);
    when(devfileVersionDetector.devfileMajorVersion(any(JsonNode.class))).thenReturn(1);
    FactoryMetaDto factory = urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
    assertNotNull(factory);
    assertNull(factory.getSource());
    assertTrue(factory instanceof FactoryDto);
}
Also used : UnknownScmProviderException(org.eclipse.che.api.factory.server.scm.exception.UnknownScmProviderException) Listeners(org.testng.annotations.Listeners) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) Test(org.testng.annotations.Test) Collections.singletonList(java.util.Collections.singletonList) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DevfileLocation(org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation) DevfileVersionDetector(org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector) FactoryMetaDto(org.eclipse.che.api.factory.shared.dto.FactoryMetaDto) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) MetadataImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl) List(java.util.List) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) FactoryDevfileV2Dto(org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Assert.assertNull(org.testng.Assert.assertNull) DataProvider(org.testng.annotations.DataProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) ScmCommunicationException(org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException) Mock(org.mockito.Mock) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Assert.assertEquals(org.testng.Assert.assertEquals) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DevfileParser(org.eclipse.che.api.workspace.server.devfile.DevfileParser) ApiException(org.eclipse.che.api.core.ApiException) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Collections.singletonMap(java.util.Collections.singletonMap) ExtendedError(org.eclipse.che.api.core.rest.shared.dto.ExtendedError) Collections.emptyMap(java.util.Collections.emptyMap) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) WORKSPACE_TOOLING_EDITOR_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) ScmUnauthorizedException(org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException) ServerException(org.eclipse.che.api.core.ServerException) OverrideParameterException(org.eclipse.che.api.workspace.server.devfile.exception.OverrideParameterException) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) FactoryMetaDto(org.eclipse.che.api.factory.shared.dto.FactoryMetaDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 83 with DevfileImpl

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

the class URLFactoryBuilderTest method devfiles.

@DataProvider
public Object[][] devfiles() {
    final String NAME = "name";
    final String GEN_NAME = "genName";
    DevfileImpl devfileTemplate = new DevfileImpl();
    devfileTemplate.setApiVersion("1.0.0");
    MetadataImpl metadataTemplate = new MetadataImpl();
    metadataTemplate.setName(NAME);
    devfileTemplate.setMetadata(metadataTemplate);
    DevfileImpl justName = new DevfileImpl(devfileTemplate);
    metadataTemplate.setName(null);
    metadataTemplate.setGenerateName(GEN_NAME);
    devfileTemplate.setMetadata(metadataTemplate);
    DevfileImpl justGenerateName = new DevfileImpl(devfileTemplate);
    metadataTemplate.setName(NAME);
    metadataTemplate.setGenerateName(GEN_NAME);
    devfileTemplate.setMetadata(metadataTemplate);
    DevfileImpl bothNames = new DevfileImpl(devfileTemplate);
    return new Object[][] { { justName, NAME }, { justGenerateName, GEN_NAME }, { bothNames, GEN_NAME } };
}
Also used : MetadataImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataProvider(org.testng.annotations.DataProvider)

Example 84 with DevfileImpl

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

the class URLFactoryBuilder method ensureToUseGenerateName.

/**
 * Creates devfile with only `generateName` and no `name`. We take `generateName` with precedence.
 * See doc of {@link URLFactoryBuilder#createFactoryFromDevfile(RemoteFactoryUrl,
 * FileContentProvider, Map)} for explanation why.
 */
private DevfileImpl ensureToUseGenerateName(DevfileImpl devfile) {
    MetadataImpl devfileMetadata = new MetadataImpl(devfile.getMetadata());
    if (isNullOrEmpty(devfileMetadata.getGenerateName())) {
        devfileMetadata.setGenerateName(devfileMetadata.getName());
    }
    devfileMetadata.setName(null);
    DevfileImpl devfileWithProperName = new DevfileImpl(devfile);
    devfileWithProperName.setMetadata(devfileMetadata);
    return devfileWithProperName;
}
Also used : MetadataImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)

Example 85 with DevfileImpl

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

the class WorkspaceManagerTest method startsWorkspaceWithDevfile.

@Test
public void startsWorkspaceWithDevfile() throws Exception {
    DevfileImpl devfile = mock(DevfileImpl.class);
    WorkspaceImpl workspace = createAndMockWorkspace(devfile, NAMESPACE_1, ImmutableMap.of(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, INFRA_NAMESPACE));
    mockAnyWorkspaceStart();
    workspaceManager.startWorkspace(workspace.getId(), null, emptyMap());
    verify(runtimes).startAsync(eq(workspace), eq(null), anyMap());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Test(org.testng.annotations.Test)

Aggregations

DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)162 Test (org.testng.annotations.Test)126 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)76 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)22 FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)20 MetadataImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl)20 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)18 ActionImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl)16 ProjectImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl)16 Container (io.fabric8.kubernetes.api.model.Container)14 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl)14 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 EndpointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl)12 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)10 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)10 Secret (io.fabric8.kubernetes.api.model.Secret)10 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)10 HashMap (java.util.HashMap)10 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)10