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);
}
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()][]);
}
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;
}
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));
}
Aggregations