Search in sources :

Example 16 with RecipeImpl

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

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 17 with RecipeImpl

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

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 18 with RecipeImpl

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

the class TestObjects method createEnvironment.

public static EnvironmentImpl createEnvironment(String... machineRams) throws Exception {
    final Map<String, MachineConfig> machines = new HashMap<>();
    for (String machineRam : machineRams) {
        final MachineConfigImpl machineConfig = new MachineConfigImpl();
        machineConfig.setAttributes(ImmutableMap.of(MachineConfig.MEMORY_LIMIT_ATTRIBUTE, machineRam));
        machines.put("dev-machine", machineConfig);
    }
    final RecipeImpl recipe = new RecipeImpl("compose", "application/x-yaml", "", null);
    return new EnvironmentImpl(recipe, machines);
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) MachineConfig(org.eclipse.che.api.core.model.workspace.config.MachineConfig) HashMap(java.util.HashMap) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)

Example 19 with RecipeImpl

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

the class FactoryDaoTest method createWorkspaceConfig.

private static WorkspaceConfigImpl createWorkspaceConfig(int index) {
    // Project Sources configuration
    final SourceStorageImpl source1 = new SourceStorageImpl();
    source1.setType("type1");
    source1.setLocation("location1");
    source1.setParameters(new HashMap<>(ImmutableMap.of("param1", "value1")));
    final SourceStorageImpl source2 = new SourceStorageImpl();
    source2.setType("type2");
    source2.setLocation("location2");
    source2.setParameters(new HashMap<>(ImmutableMap.of("param4", "value1")));
    // Project Configuration
    final ProjectConfigImpl pCfg1 = new ProjectConfigImpl();
    pCfg1.setPath("/path1");
    pCfg1.setType("type1");
    pCfg1.setName("project1");
    pCfg1.setDescription("description1");
    pCfg1.getMixins().addAll(asList("mixin1", "mixin2"));
    pCfg1.setSource(source1);
    final ProjectConfigImpl pCfg2 = new ProjectConfigImpl();
    pCfg2.setPath("/path2");
    pCfg2.setType("type2");
    pCfg2.setName("project2");
    pCfg2.setDescription("description2");
    pCfg2.getMixins().addAll(asList("mixin3", "mixin4"));
    pCfg2.setSource(source2);
    final List<ProjectConfigImpl> projects = new ArrayList<>(asList(pCfg1, pCfg2));
    // Commands
    final CommandImpl cmd1 = new CommandImpl("name1", "cmd1", "type1");
    cmd1.getAttributes().putAll(ImmutableMap.of("key1", "value1"));
    final CommandImpl cmd2 = new CommandImpl("name2", "cmd2", "type2");
    cmd2.getAttributes().putAll(ImmutableMap.of("key4", "value4"));
    final List<CommandImpl> commands = new ArrayList<>(asList(cmd1, cmd2));
    // Machine configs
    final MachineConfigImpl exMachine1 = new MachineConfigImpl();
    final ServerConfigImpl serverConf1 = new ServerConfigImpl("2265", "http", "/path1", singletonMap("key", "value"));
    final ServerConfigImpl serverConf2 = new ServerConfigImpl("2266", "ftp", "/path2", singletonMap("key", "value"));
    exMachine1.setServers(ImmutableMap.of("ref1", serverConf1, "ref2", serverConf2));
    exMachine1.setAttributes(singletonMap("att1", "val"));
    exMachine1.setEnv(singletonMap("CHE_ENV", "value"));
    final MachineConfigImpl exMachine2 = new MachineConfigImpl();
    final ServerConfigImpl serverConf3 = new ServerConfigImpl("2333", "https", "/path1", singletonMap("key", "value"));
    final ServerConfigImpl serverConf4 = new ServerConfigImpl("2334", "wss", "/path2", singletonMap("key", "value"));
    exMachine2.setServers(ImmutableMap.of("ref1", serverConf3, "ref2", serverConf4));
    exMachine2.setAttributes(singletonMap("att1", "val"));
    exMachine2.setEnv(singletonMap("CHE_ENV2", "value"));
    final MachineConfigImpl exMachine3 = new MachineConfigImpl();
    final ServerConfigImpl serverConf5 = new ServerConfigImpl("2333", "https", "/path3", singletonMap("key", "value"));
    exMachine3.setServers(singletonMap("ref1", serverConf5));
    exMachine3.setAttributes(singletonMap("att1", "val"));
    exMachine3.setEnv(singletonMap("CHE_ENV3", "value"));
    // Environments
    final RecipeImpl recipe1 = new RecipeImpl();
    recipe1.setLocation("https://eclipse.che/Dockerfile");
    recipe1.setType("dockerfile");
    recipe1.setContentType("text/x-dockerfile");
    recipe1.setContent("content");
    final EnvironmentImpl env1 = new EnvironmentImpl();
    env1.setMachines(new HashMap<>(ImmutableMap.of("machine1", exMachine1, "machine2", exMachine2, "machine3", exMachine3)));
    env1.setRecipe(recipe1);
    final RecipeImpl recipe2 = new RecipeImpl();
    recipe2.setLocation("https://eclipse.che/Dockerfile");
    recipe2.setType("dockerfile");
    recipe2.setContentType("text/x-dockerfile");
    recipe2.setContent("content");
    final EnvironmentImpl env2 = new EnvironmentImpl();
    env2.setMachines(new HashMap<>(ImmutableMap.of("machine1", exMachine1, "machine3", exMachine3)));
    env2.setRecipe(recipe2);
    final Map<String, EnvironmentImpl> environments = ImmutableMap.of("env1", env1, "env2", env2);
    // Workspace configuration
    final WorkspaceConfigImpl wCfg = new WorkspaceConfigImpl();
    wCfg.setDefaultEnv("env1");
    wCfg.setName("cfgName_" + index);
    wCfg.setDescription("description");
    wCfg.setCommands(commands);
    wCfg.setProjects(projects);
    wCfg.setEnvironments(environments);
    return wCfg;
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ArrayList(java.util.ArrayList) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 20 with RecipeImpl

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

the class FactoryServiceTest method createEnvDto.

private static EnvironmentDto createEnvDto() {
    final RecipeImpl environmentRecipe = new RecipeImpl();
    environmentRecipe.setType("type");
    environmentRecipe.setContent("content");
    environmentRecipe.setContentType("compose");
    environmentRecipe.setLocation("location");
    final EnvironmentImpl env = new EnvironmentImpl();
    final MachineConfigImpl extendedMachine = new MachineConfigImpl();
    extendedMachine.setAttributes(singletonMap("att1", "value"));
    extendedMachine.setServers(singletonMap("agent", new ServerConfigImpl("5555", "https", "path", singletonMap("key", "value"))));
    env.setRecipe(environmentRecipe);
    env.setMachines(singletonMap("machine1", extendedMachine));
    return org.eclipse.che.api.workspace.server.DtoConverter.asDto(env);
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)

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