Search in sources :

Example 6 with KUBERNETES_COMPONENT_TYPE

use of org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE in project che-server by eclipse-che.

the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionDevfileVolumesIfSpecifiedIntoMachineConfig.

@Test
public void shouldProvisionDevfileVolumesIfSpecifiedIntoMachineConfig() throws Exception {
    // given
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
    doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setAlias(COMPONENT_NAME);
    component.setVolumes(asList(new VolumeImpl("foo", "/foo1"), new VolumeImpl("bar", "/bar1")));
    ArgumentCaptor<Map<String, MachineConfigImpl>> mapCaptor = ArgumentCaptor.forClass(Map.class);
    // when
    applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
    // then
    verify(k8sEnvProvisioner).provision(any(), any(), any(), mapCaptor.capture());
    Map<String, MachineConfigImpl> configMaps = mapCaptor.getValue();
    for (MachineConfig config : configMaps.values()) {
        assertEquals(config.getVolumes().size(), 2);
        assertTrue(config.getVolumes().entrySet().stream().anyMatch(entry -> entry.getKey().equals("foo") && entry.getValue().getPath().equals("/foo1")));
        assertTrue(config.getVolumes().entrySet().stream().anyMatch(entry -> entry.getKey().equals("bar") && entry.getValue().getPath().equals("/bar1")));
    }
}
Also used : Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) MachineConfig(org.eclipse.che.api.core.model.workspace.config.MachineConfig) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) EnvVars(org.eclipse.che.workspace.infrastructure.kubernetes.util.EnvVars) Test(org.testng.annotations.Test) Files(org.testng.reporters.Files) Collections.singletonList(java.util.Collections.singletonList) Mockito.doThrow(org.mockito.Mockito.doThrow) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) REQUIRE_SUBDOMAIN(org.eclipse.che.api.core.model.workspace.config.ServerConfig.REQUIRE_SUBDOMAIN) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertFalse(org.testng.Assert.assertFalse) Serialization.unmarshal(io.fabric8.kubernetes.client.utils.Serialization.unmarshal) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ImmutableMap(com.google.common.collect.ImmutableMap) MULTI_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.MultiHostExternalServiceExposureStrategy.MULTI_HOST_STRATEGY) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) Stream(java.util.stream.Stream) PROJECTS_VOLUME_NAME(org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Assert.assertNull(org.testng.Assert.assertNull) Container(io.fabric8.kubernetes.api.model.Container) DEVFILE_COMPONENT_ALIAS_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.MachineConfig.DEVFILE_COMPONENT_ALIAS_ATTRIBUTE) Mock(org.mockito.Mock) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) Assert.assertEquals(org.testng.Assert.assertEquals) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Captor(org.mockito.Captor) ValidationException(org.eclipse.che.api.core.ValidationException) ArrayList(java.util.ArrayList) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) MACHINE_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE) Collections.singletonMap(java.util.Collections.singletonMap) COMPONENT_ALIAS_COMMAND_ATTRIBUTE(org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Collections.emptyMap(java.util.Collections.emptyMap) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider) OPENSHIFT_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) Mockito.verify(org.mockito.Mockito.verify) EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) SINGLE_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.SingleHostExternalServiceExposureStrategy.SINGLE_HOST_STRATEGY) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Assert.assertTrue(org.testng.Assert.assertTrue) KubernetesRecipeParser(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) MachineConfig(org.eclipse.che.api.core.model.workspace.config.MachineConfig) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.testng.annotations.Test)

Example 7 with KUBERNETES_COMPONENT_TYPE

use of org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE in project che-server by eclipse-che.

the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionMachinesMapWithComponentAttributePreSet.

@Test
public void shouldProvisionMachinesMapWithComponentAttributePreSet() throws Exception {
    @SuppressWarnings("unchecked") ArgumentCaptor<Map<String, MachineConfigImpl>> mapCaptor = ArgumentCaptor.forClass(Map.class);
    // given
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
    doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setAlias(COMPONENT_NAME);
    component.setMountSources(true);
    // when
    applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
    // then
    verify(k8sEnvProvisioner).provision(any(), any(), any(), mapCaptor.capture());
    Map<String, MachineConfigImpl> machines = mapCaptor.getValue();
    assertTrue(machines.values().stream().allMatch(config -> config.getAttributes().get(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE).equals(component.getAlias())));
}
Also used : Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) MachineConfig(org.eclipse.che.api.core.model.workspace.config.MachineConfig) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) EnvVars(org.eclipse.che.workspace.infrastructure.kubernetes.util.EnvVars) Test(org.testng.annotations.Test) Files(org.testng.reporters.Files) Collections.singletonList(java.util.Collections.singletonList) Mockito.doThrow(org.mockito.Mockito.doThrow) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) REQUIRE_SUBDOMAIN(org.eclipse.che.api.core.model.workspace.config.ServerConfig.REQUIRE_SUBDOMAIN) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertFalse(org.testng.Assert.assertFalse) Serialization.unmarshal(io.fabric8.kubernetes.client.utils.Serialization.unmarshal) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ImmutableMap(com.google.common.collect.ImmutableMap) MULTI_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.MultiHostExternalServiceExposureStrategy.MULTI_HOST_STRATEGY) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) Stream(java.util.stream.Stream) PROJECTS_VOLUME_NAME(org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Assert.assertNull(org.testng.Assert.assertNull) Container(io.fabric8.kubernetes.api.model.Container) DEVFILE_COMPONENT_ALIAS_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.MachineConfig.DEVFILE_COMPONENT_ALIAS_ATTRIBUTE) Mock(org.mockito.Mock) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) Assert.assertEquals(org.testng.Assert.assertEquals) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Captor(org.mockito.Captor) ValidationException(org.eclipse.che.api.core.ValidationException) ArrayList(java.util.ArrayList) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) MACHINE_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE) Collections.singletonMap(java.util.Collections.singletonMap) COMPONENT_ALIAS_COMMAND_ATTRIBUTE(org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Collections.emptyMap(java.util.Collections.emptyMap) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider) OPENSHIFT_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) Mockito.verify(org.mockito.Mockito.verify) EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) SINGLE_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.SingleHostExternalServiceExposureStrategy.SINGLE_HOST_STRATEGY) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Assert.assertTrue(org.testng.Assert.assertTrue) KubernetesRecipeParser(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 8 with KUBERNETES_COMPONENT_TYPE

use of org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE in project devspaces-images by redhat-developer.

the class DevfileIntegrityValidator method validateComponents.

private Set<String> validateComponents(Devfile devfile) throws DevfileFormatException {
    Set<String> definedAliases = new HashSet<>();
    Component editorComponent = null;
    Map<String, Set<String>> idsPerComponentType = new HashMap<>();
    for (Component component : devfile.getComponents()) {
        if (component.getAlias() != null && !definedAliases.add(component.getAlias())) {
            throw new DevfileFormatException(format("Duplicate component alias found:'%s'", component.getAlias()));
        }
        Optional<Map.Entry<String, Long>> duplicatedEndpoint = component.getEndpoints().stream().map(Endpoint::getName).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().filter(e -> e.getValue() > 1L).findFirst();
        if (duplicatedEndpoint.isPresent()) {
            throw new DevfileFormatException(format("Duplicated endpoint name '%s' found in '%s' component", duplicatedEndpoint.get().getKey(), getIdentifiableComponentName(component)));
        }
        Set<String> tempSet = new HashSet<>();
        for (Env env : component.getEnv()) {
            if (!tempSet.add(env.getName())) {
                throw new DevfileFormatException(format("Duplicate environment variable '%s' found in component '%s'", env.getName(), getIdentifiableComponentName(component)));
            }
        }
        if (!idsPerComponentType.computeIfAbsent(component.getType(), __ -> new HashSet<>()).add(getIdentifiableComponentName(component))) {
            throw new DevfileFormatException(format("There are multiple components '%s' of type '%s' that cannot be uniquely" + " identified. Please add aliases that would distinguish the components.", getIdentifiableComponentName(component), component.getType()));
        }
        if (component.getAutomountWorkspaceSecrets() != null && component.getAlias() == null) {
            throw new DevfileFormatException(format("The 'automountWorkspaceSecrets' property cannot be used in component which doesn't have alias. " + "Please add alias to component '%s' that would allow to distinguish its containers.", getIdentifiableComponentName(component)));
        }
        switch(component.getType()) {
            case EDITOR_COMPONENT_TYPE:
                if (editorComponent != null) {
                    throw new DevfileFormatException(format("Multiple editor components found: '%s', '%s'", getIdentifiableComponentName(editorComponent), getIdentifiableComponentName(component)));
                }
                editorComponent = component;
                break;
            case PLUGIN_COMPONENT_TYPE:
            case KUBERNETES_COMPONENT_TYPE:
            case OPENSHIFT_COMPONENT_TYPE:
            case DOCKERIMAGE_COMPONENT_TYPE:
                // do nothing
                break;
            default:
                throw new DevfileFormatException(format("One of the components has unsupported component type: '%s'", component.getType()));
        }
    }
    return definedAliases;
}
Also used : KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Env(org.eclipse.che.api.core.model.workspace.devfile.Env) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) PLUGIN_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE) Function(java.util.function.Function) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Map(java.util.Map) Components.getIdentifiableComponentName(org.eclipse.che.api.workspace.server.devfile.Components.getIdentifiableComponentName) EDITOR_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE) DOCKERIMAGE_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) Devfile(org.eclipse.che.api.core.model.workspace.devfile.Devfile) OPENSHIFT_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) Optional(java.util.Optional) Command(org.eclipse.che.api.core.model.workspace.devfile.Command) Project(org.eclipse.che.api.core.model.workspace.devfile.Project) Pattern(java.util.regex.Pattern) Action(org.eclipse.che.api.core.model.workspace.devfile.Action) Endpoint(org.eclipse.che.api.core.model.workspace.devfile.Endpoint) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Env(org.eclipse.che.api.core.model.workspace.devfile.Env) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) HashSet(java.util.HashSet)

Example 9 with KUBERNETES_COMPONENT_TYPE

use of org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE in project devspaces-images by redhat-developer.

the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionMachinesMapWithComponentAttributePreSet.

@Test
public void shouldProvisionMachinesMapWithComponentAttributePreSet() throws Exception {
    @SuppressWarnings("unchecked") ArgumentCaptor<Map<String, MachineConfigImpl>> mapCaptor = ArgumentCaptor.forClass(Map.class);
    // given
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
    doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setAlias(COMPONENT_NAME);
    component.setMountSources(true);
    // when
    applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
    // then
    verify(k8sEnvProvisioner).provision(any(), any(), any(), mapCaptor.capture());
    Map<String, MachineConfigImpl> machines = mapCaptor.getValue();
    assertTrue(machines.values().stream().allMatch(config -> config.getAttributes().get(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE).equals(component.getAlias())));
}
Also used : Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) MachineConfig(org.eclipse.che.api.core.model.workspace.config.MachineConfig) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) EnvVars(org.eclipse.che.workspace.infrastructure.kubernetes.util.EnvVars) Test(org.testng.annotations.Test) Files(org.testng.reporters.Files) Collections.singletonList(java.util.Collections.singletonList) Mockito.doThrow(org.mockito.Mockito.doThrow) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) REQUIRE_SUBDOMAIN(org.eclipse.che.api.core.model.workspace.config.ServerConfig.REQUIRE_SUBDOMAIN) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertFalse(org.testng.Assert.assertFalse) Serialization.unmarshal(io.fabric8.kubernetes.client.utils.Serialization.unmarshal) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ImmutableMap(com.google.common.collect.ImmutableMap) MULTI_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.MultiHostExternalServiceExposureStrategy.MULTI_HOST_STRATEGY) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) Stream(java.util.stream.Stream) PROJECTS_VOLUME_NAME(org.eclipse.che.api.workspace.shared.Constants.PROJECTS_VOLUME_NAME) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Assert.assertNull(org.testng.Assert.assertNull) Container(io.fabric8.kubernetes.api.model.Container) DEVFILE_COMPONENT_ALIAS_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.MachineConfig.DEVFILE_COMPONENT_ALIAS_ATTRIBUTE) Mock(org.mockito.Mock) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) Assert.assertEquals(org.testng.Assert.assertEquals) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Captor(org.mockito.Captor) ValidationException(org.eclipse.che.api.core.ValidationException) ArrayList(java.util.ArrayList) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) MACHINE_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE) Collections.singletonMap(java.util.Collections.singletonMap) COMPONENT_ALIAS_COMMAND_ATTRIBUTE(org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Collections.emptyMap(java.util.Collections.emptyMap) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider) OPENSHIFT_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) Mockito.verify(org.mockito.Mockito.verify) EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) SINGLE_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.SingleHostExternalServiceExposureStrategy.SINGLE_HOST_STRATEGY) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Assert.assertTrue(org.testng.Assert.assertTrue) KubernetesRecipeParser(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesRecipeParser) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 10 with KUBERNETES_COMPONENT_TYPE

use of org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE in project devspaces-images by redhat-developer.

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)

Aggregations

Map (java.util.Map)10 KUBERNETES_COMPONENT_TYPE (org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE)10 IOException (java.io.IOException)8 Collections (java.util.Collections)8 Collections.emptyMap (java.util.Collections.emptyMap)8 Collections.singletonList (java.util.Collections.singletonList)8 Collections.singletonMap (java.util.Collections.singletonMap)8 HashSet (java.util.HashSet)8 List (java.util.List)8 Set (java.util.Set)8 OPENSHIFT_COMPONENT_TYPE (org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE)8 DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)8 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)8 ImmutableMap (com.google.common.collect.ImmutableMap)6 Container (io.fabric8.kubernetes.api.model.Container)6 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)6 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)6 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)6 Pod (io.fabric8.kubernetes.api.model.Pod)6 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)6