Search in sources :

Example 21 with RecipeImpl

use of org.eclipse.che.api.workspace.server.model.impl.RecipeImpl 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 22 with RecipeImpl

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

the class WorkspaceRuntimesTest method internalEnvironmentShouldThrowExceptionWhenNoEnvironmentFactoryFoundForRecipeType.

@Test(expectedExceptions = NotFoundException.class, expectedExceptionsMessageRegExp = "InternalEnvironmentFactory is not configured for recipe type: 'not-supported-type'")
public void internalEnvironmentShouldThrowExceptionWhenNoEnvironmentFactoryFoundForRecipeType() throws Exception {
    EnvironmentImpl environment = new EnvironmentImpl();
    environment.setRecipe(new RecipeImpl("not-supported-type", "", "", null));
    runtimes.createInternalEnvironment(environment, emptyMap(), emptyList(), null);
}
Also used : RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Test(org.testng.annotations.Test)

Example 23 with RecipeImpl

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

the class KubernetesEnvironmentProvisionerTest method shouldProvisionComponentObjectsIntoExistingKubernetesRecipe.

@Test
public void shouldProvisionComponentObjectsIntoExistingKubernetesRecipe() throws Exception {
    // given
    workspaceConfig.setDefaultEnv("default");
    RecipeImpl existingRecipe = new RecipeImpl(KUBERNETES_COMPONENT_TYPE, "yaml", "existing-content", null);
    workspaceConfig.getEnvironments().put("default", new EnvironmentImpl(existingRecipe, emptyMap()));
    List<HasMetadata> recipeObjects = new ArrayList<>();
    Deployment recipeDeployment = new DeploymentBuilder().withNewMetadata().withName("db").endMetadata().withNewSpec().endSpec().build();
    recipeObjects.add(new DeploymentBuilder(recipeDeployment).build());
    doReturn(recipeObjects).when(k8sRecipeParser).parse(anyString());
    List<HasMetadata> componentsObject = new ArrayList<>();
    Deployment componentDeployment = new DeploymentBuilder().withNewMetadata().withName("web-app").endMetadata().withNewSpec().endSpec().build();
    componentsObject.add(new DeploymentBuilder(componentDeployment).build());
    // when
    k8sEnvProvisioner.provision(workspaceConfig, KubernetesEnvironment.TYPE, componentsObject, emptyMap());
    // then
    // it is expected that applier wrap original recipes objects in new Kubernetes list
    KubernetesList expectedKubernetesList = new KubernetesListBuilder().withItems(Arrays.asList(recipeDeployment, componentDeployment)).build();
    EnvironmentImpl resultEnv = workspaceConfig.getEnvironments().get(workspaceConfig.getDefaultEnv());
    assertEquals(toK8SList(resultEnv.getRecipe().getContent()).getItems(), expectedKubernetesList.getItems());
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.testng.annotations.Test)

Example 24 with RecipeImpl

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

the class KubernetesEnvironmentProvisionerTest method shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromK8SList.

@Test
public void shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromK8SList() throws Exception {
    // given
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    List<HasMetadata> componentsObjects = toK8SList(yamlRecipeContent).getItems();
    // when
    k8sEnvProvisioner.provision(workspaceConfig, KubernetesEnvironment.TYPE, componentsObjects, emptyMap());
    // then
    String defaultEnv = workspaceConfig.getDefaultEnv();
    assertNotNull(defaultEnv);
    EnvironmentImpl environment = workspaceConfig.getEnvironments().get(defaultEnv);
    assertNotNull(environment);
    RecipeImpl recipe = environment.getRecipe();
    assertNotNull(recipe);
    assertEquals(recipe.getType(), KUBERNETES_COMPONENT_TYPE);
    assertEquals(recipe.getContentType(), YAML_CONTENT_TYPE);
    // it is expected that applier wrap original recipes objects in new Kubernetes list
    KubernetesList expectedKubernetesList = new KubernetesListBuilder().withItems(toK8SList(yamlRecipeContent).getItems()).build();
    assertEquals(toK8SList(recipe.getContent()).getItems(), expectedKubernetesList.getItems());
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.testng.annotations.Test)

Example 25 with RecipeImpl

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

the class KubernetesEnvironmentProvisionerTest method shouldUpgradeKubernetesEnvironmentToOpenShiftTypeOnOpenShiftComponentProvisioning.

@Test
public void shouldUpgradeKubernetesEnvironmentToOpenShiftTypeOnOpenShiftComponentProvisioning() throws Exception {
    // given
    workspaceConfig.setDefaultEnv("default");
    RecipeImpl existingRecipe = new RecipeImpl(KubernetesEnvironment.TYPE, "yaml", "existing-content", null);
    workspaceConfig.getEnvironments().put("default", new EnvironmentImpl(existingRecipe, emptyMap()));
    List<HasMetadata> componentsObject = new ArrayList<>();
    Deployment componentDeployment = new DeploymentBuilder().withNewMetadata().withName("web-app").endMetadata().withNewSpec().endSpec().build();
    componentsObject.add(new DeploymentBuilder(componentDeployment).build());
    doReturn(new ArrayList<>()).when(k8sRecipeParser).parse(anyString());
    // when
    k8sEnvProvisioner.provision(workspaceConfig, "openshift", componentsObject, emptyMap());
    // then
    EnvironmentImpl resultEnv = workspaceConfig.getEnvironments().get(workspaceConfig.getDefaultEnv());
    RecipeImpl resultRecipe = resultEnv.getRecipe();
    assertEquals(resultRecipe.getType(), "openshift");
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.testng.annotations.Test)

Aggregations

RecipeImpl (org.eclipse.che.api.workspace.server.model.impl.RecipeImpl)42 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)38 Test (org.testng.annotations.Test)20 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)18 ArrayList (java.util.ArrayList)16 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)12 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)12 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)12 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)8 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)7 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)7 SourceStorageImpl (org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl)7 HashMap (java.util.HashMap)6 AccountImpl (org.eclipse.che.account.spi.AccountImpl)6 WorkspaceDao (org.eclipse.che.api.workspace.server.spi.WorkspaceDao)6 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)5 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)5 VolumeImpl (org.eclipse.che.api.workspace.server.model.impl.VolumeImpl)5 ServerException (org.eclipse.che.api.core.ServerException)4 TypeLiteral (com.google.inject.TypeLiteral)3