Search in sources :

Example 1 with ExtendedMachineDto

use of org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto in project che by eclipse.

the class StackLoaderTest method dtoShouldBeSerialized.

@Test
public void dtoShouldBeSerialized() {
    StackDto stackDtoDescriptor = newDto(StackDto.class).withName("nameWorkspaceConfig");
    StackComponentDto stackComponentDto = newDto(StackComponentDto.class).withName("java").withVersion("1.8");
    stackDtoDescriptor.setComponents(Collections.singletonList(stackComponentDto));
    stackDtoDescriptor.setTags(Arrays.asList("some teg1", "some teg2"));
    stackDtoDescriptor.setDescription("description");
    stackDtoDescriptor.setId("someId");
    stackDtoDescriptor.setScope("scope");
    stackDtoDescriptor.setCreator("Created in Codenvy");
    Map<String, String> attributes = new HashMap<>();
    attributes.put("attribute1", "valute attribute1");
    Link link = newDto(Link.class).withHref("some url").withMethod("get").withRel("someRel").withConsumes("consumes").withProduces("produces");
    HashMap<String, List<String>> projectMap = new HashMap<>();
    projectMap.put("test", Arrays.asList("test", "test2"));
    ProjectProblemDto projectProblem = newDto(ProjectProblemDto.class).withCode(100).withMessage("message");
    SourceStorageDto sourceStorageDto = newDto(SourceStorageDto.class).withType("some type").withParameters(attributes).withLocation("location");
    ProjectConfigDto projectConfigDto = newDto(ProjectConfigDto.class).withName("project").withPath("somePath").withAttributes(projectMap).withType("maven type").withDescription("some project description").withLinks(Collections.singletonList(link)).withMixins(Collections.singletonList("mixin time")).withProblems(Collections.singletonList(projectProblem)).withSource(sourceStorageDto);
    EnvironmentRecipeDto environmentRecipe = newDto(EnvironmentRecipeDto.class).withContent("some content").withContentType("some content type").withType("someType");
    Map<String, ServerConf2Dto> servers = new HashMap<>();
    servers.put("server1Ref", newDto(ServerConf2Dto.class).withPort("8080/tcp").withProtocol("http").withProperties(singletonMap("key", "value")));
    Map<String, ExtendedMachineDto> machines = new HashMap<>();
    machines.put("someMachineName", newDto(ExtendedMachineDto.class).withAgents(Arrays.asList("agent1", "agent2")).withServers(servers).withAttributes(singletonMap("memoryLimitBytes", "" + 512L * 1024L * 1024L)));
    EnvironmentDto environmentDto = newDto(EnvironmentDto.class).withRecipe(environmentRecipe).withMachines(machines);
    CommandDto commandDto = newDto(CommandDto.class).withType("command type").withName("command name").withCommandLine("command line");
    WorkspaceConfigDto workspaceConfigDto = newDto(WorkspaceConfigDto.class).withName("SomeWorkspaceConfig").withDescription("some workspace").withLinks(Collections.singletonList(link)).withDefaultEnv("some Default Env name").withProjects(Collections.singletonList(projectConfigDto)).withEnvironments(singletonMap("name", environmentDto)).withCommands(Collections.singletonList(commandDto));
    stackDtoDescriptor.setWorkspaceConfig(workspaceConfigDto);
    Gson GSON = new GsonBuilder().create();
    GSON.fromJson(stackDtoDescriptor.toString(), StackImpl.class);
}
Also used : HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) StackComponentDto(org.eclipse.che.api.workspace.shared.dto.stack.StackComponentDto) Gson(com.google.gson.Gson) ServerConf2Dto(org.eclipse.che.api.workspace.shared.dto.ServerConf2Dto) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) List(java.util.List) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) Link(org.eclipse.che.api.core.rest.shared.dto.Link) ProjectProblemDto(org.eclipse.che.api.workspace.shared.dto.ProjectProblemDto) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) Test(org.testng.annotations.Test)

Example 2 with ExtendedMachineDto

use of org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto in project che by eclipse.

the class CheEnvironmentValidatorTest method invalidEnvironmentProvider.

@DataProvider
public static Object[][] invalidEnvironmentProvider() {
    // InvalidEnvironmentObject | ExceptionMessage
    EnvironmentDto env;
    Map.Entry<String, ExtendedMachineDto> machineEntry;
    List<List<Object>> data = new ArrayList<>();
    data.add(asList(createEnv().withRecipe(null), "Environment recipe should not be null"));
    env = createEnv();
    env.getRecipe().setType("docker");
    data.add(asList(env, "Type 'docker' of environment 'env' is not supported. Supported types: compose"));
    env = createEnv();
    env.getRecipe().withLocation(null).withContent(null);
    data.add(asList(env, "Recipe of environment 'env' must contain location or content"));
    env = createEnv();
    env.getRecipe().withLocation("location").withContent("content");
    data.add(asList(env, "Recipe of environment 'env' contains mutually exclusive fields location and content"));
    env = createEnv();
    env.setMachines(null);
    data.add(asList(env, "Environment 'env' doesn't contain machine with 'org.eclipse.che.ws-agent' agent"));
    env = createEnv();
    env.setMachines(emptyMap());
    data.add(asList(env, "Environment 'env' doesn't contain machine with 'org.eclipse.che.ws-agent' agent"));
    env = createEnv();
    env.getMachines().put("missingInEnvMachine", newDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent")));
    data.add(asList(env, "Environment 'env' contains machines that are missing in environment recipe: missingInEnvMachine"));
    env = createEnv();
    env.getMachines().entrySet().forEach(entry -> entry.getValue().getAgents().add("org.eclipse.che.ws-agent"));
    data.add(asList(env, "Environment 'env' should contain exactly 1 machine with agent 'org.eclipse.che.ws-agent', but contains '" + env.getMachines().size() + "'. " + "All machines with this agent: " + Joiner.on(", ").join(env.getMachines().keySet())));
    env = createEnv();
    env.getMachines().entrySet().forEach(entry -> entry.getValue().setAgents(null));
    data.add(asList(env, "Environment 'env' should contain exactly 1 machine with agent 'org.eclipse.che.ws-agent', but contains '0'. All machines with this agent: "));
    env = createEnv();
    env.getMachines().entrySet().forEach(entry -> entry.getValue().getAgents().add(null));
    data.add(asList(env, "Machine 'machine2' in environment 'env' contains invalid agent 'null'"));
    env = createEnv();
    env.getMachines().entrySet().forEach(entry -> entry.getValue().getAgents().add(""));
    data.add(asList(env, "Machine 'machine2' in environment 'env' contains invalid agent ''"));
    env = createEnv();
    machineEntry = env.getMachines().entrySet().iterator().next();
    machineEntry.getValue().setAttributes(singletonMap("memoryLimitBytes", "0"));
    data.add(asList(env, format("Value of attribute 'memoryLimitBytes' of machine '%s' in environment 'env' is illegal", machineEntry.getKey())));
    env = createEnv();
    machineEntry = env.getMachines().entrySet().iterator().next();
    machineEntry.getValue().setAttributes(singletonMap("memoryLimitBytes", "-1"));
    data.add(asList(env, format("Value of attribute 'memoryLimitBytes' of machine '%s' in environment 'env' is illegal", machineEntry.getKey())));
    env = createEnv();
    machineEntry = env.getMachines().entrySet().iterator().next();
    machineEntry.getValue().setAttributes(singletonMap("memoryLimitBytes", ""));
    data.add(asList(env, format("Value of attribute 'memoryLimitBytes' of machine '%s' in environment 'env' is illegal", machineEntry.getKey())));
    return data.stream().map(list -> list.toArray(new Object[list.size()])).toArray(value -> new Object[data.size()][]);
}
Also used : Listeners(org.testng.annotations.Listeners) MachineInstanceProviders(org.eclipse.che.api.machine.server.MachineInstanceProviders) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) DataProvider(org.testng.annotations.DataProvider) Mock(org.mockito.Mock) DtoConverter(org.eclipse.che.api.workspace.server.DtoConverter) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) ServerConfDto(org.eclipse.che.api.machine.shared.dto.ServerConfDto) Mockito.spy(org.mockito.Mockito.spy) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) Collections.singleton(java.util.Collections.singleton) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) Collections.singletonMap(java.util.Collections.singletonMap) InjectMocks(org.mockito.InjectMocks) Collections.emptyMap(java.util.Collections.emptyMap) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) MachineSourceDto(org.eclipse.che.api.machine.shared.dto.MachineSourceDto) Collections.emptyList(java.util.Collections.emptyList) Assert.fail(org.testng.Assert.fail) BeforeMethod(org.testng.annotations.BeforeMethod) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) Mockito.when(org.mockito.Mockito.when) String.format(java.lang.String.format) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Environment(org.eclipse.che.api.core.model.workspace.Environment) ServerException(org.eclipse.che.api.core.ServerException) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Joiner(com.google.common.base.Joiner) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) DataProvider(org.testng.annotations.DataProvider)

Example 3 with ExtendedMachineDto

use of org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto in project che by eclipse.

the class DefaultWorkspaceValidatorTest method createConfig.

private static WorkspaceConfigDto createConfig() {
    final WorkspaceConfigDto workspaceConfigDto = newDto(WorkspaceConfigDto.class).withName("ws-name").withDefaultEnv("dev-env");
    ExtendedMachineDto extendedMachine = newDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent")).withServers(singletonMap("ref1", newDto(ServerConf2Dto.class).withPort("8080/tcp").withProtocol("https").withProperties(singletonMap("some", "prop")))).withAttributes(singletonMap("memoryLimitBytes", "1000000"));
    EnvironmentDto env = newDto(EnvironmentDto.class).withMachines(singletonMap("devmachine1", extendedMachine)).withRecipe(newDto(EnvironmentRecipeDto.class).withType("type").withContent("content").withContentType("content type"));
    workspaceConfigDto.setEnvironments(singletonMap("dev-env", env));
    List<CommandDto> commandDtos = new ArrayList<>();
    commandDtos.add(newDto(CommandDto.class).withName("command_name").withType("maven").withCommandLine("mvn clean install").withAttributes(new HashMap<>(singletonMap("cmd-attribute-name", "cmd-attribute-value"))));
    workspaceConfigDto.setCommands(commandDtos);
    return workspaceConfigDto;
}
Also used : HashMap(java.util.HashMap) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) ArrayList(java.util.ArrayList) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto)

Example 4 with ExtendedMachineDto

use of org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto in project che by eclipse.

the class CreateWorkspacePresenter method getWorkspaceConfig.

private WorkspaceConfigDto getWorkspaceConfig() {
    String wsName = view.getWorkspaceName();
    EnvironmentRecipeDto recipe = dtoFactory.createDto(EnvironmentRecipeDto.class).withType("dockerimage").withLocation(view.getRecipeUrl());
    ExtendedMachineDto machine = dtoFactory.createDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent")).withAttributes(singletonMap("memoryLimitBytes", MEMORY_LIMIT_BYTES));
    EnvironmentDto environment = dtoFactory.createDto(EnvironmentDto.class).withRecipe(recipe).withMachines(singletonMap(WS_MACHINE_NAME, machine));
    return dtoFactory.createDto(WorkspaceConfigDto.class).withName(wsName).withDefaultEnv(wsName).withEnvironments(singletonMap(wsName, environment));
}
Also used : EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto)

Aggregations

EnvironmentDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentDto)4 ExtendedMachineDto (org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto)4 HashMap (java.util.HashMap)3 WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CommandDto (org.eclipse.che.api.machine.shared.dto.CommandDto)2 EnvironmentRecipeDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto)2 Test (org.testng.annotations.Test)2 Joiner (com.google.common.base.Joiner)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 String.format (java.lang.String.format)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singleton (java.util.Collections.singleton)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Map (java.util.Map)1