Search in sources :

Example 6 with EnvironmentImpl

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

the class WorkspaceManagerTest method usesProvidedEnvironmentInsteadOfDefault.

@Test
public void usesProvidedEnvironmentInsteadOfDefault() throws Exception {
    WorkspaceConfigImpl config = createConfig();
    config.getEnvironments().put("non-default-env", new EnvironmentImpl(null, null));
    WorkspaceImpl workspace = createAndMockWorkspace(config, NAMESPACE);
    mockStart(workspace);
    workspaceManager.startWorkspace(workspace.getId(), "non-default-env", false);
    verify(runtimes).startAsync(workspaceCaptor.capture(), eq("non-default-env"), eq(false));
    assertEquals(workspaceCaptor.getValue().getConfig(), config);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Test(org.testng.annotations.Test)

Example 7 with EnvironmentImpl

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

the class WorkspaceServiceTest method shouldDeleteEnvironment.

@Test
public void shouldDeleteEnvironment() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    Map.Entry<String, EnvironmentImpl> envEntry = workspace.getConfig().getEnvironments().entrySet().iterator().next();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().delete(SECURE_PATH + "/workspace/" + workspace.getId() + "/environment/" + envEntry.getKey());
    assertEquals(response.getStatusCode(), 204);
    verify(wsManager).updateWorkspace(any(), any());
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.testng.annotations.Test)

Example 8 with EnvironmentImpl

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

the class FactoryDaoTest method createWorkspaceConfig.

public 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);
    pCfg1.getAttributes().putAll(ImmutableMap.of("key1", asList("v1", "v2"), "key2", asList("v1", "v2")));
    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);
    pCfg2.getAttributes().putAll(ImmutableMap.of("key3", asList("v1", "v2"), "key4", asList("v1", "v2")));
    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 ExtendedMachineImpl exMachine1 = new ExtendedMachineImpl();
    final ServerConf2Impl serverConf1 = new ServerConf2Impl("2265", "http", singletonMap("prop1", "val"));
    final ServerConf2Impl serverConf2 = new ServerConf2Impl("2266", "ftp", singletonMap("prop1", "val"));
    exMachine1.setServers(ImmutableMap.of("ref1", serverConf1, "ref2", serverConf2));
    exMachine1.setAgents(ImmutableList.of("agent5", "agent4"));
    exMachine1.setAttributes(singletonMap("att1", "val"));
    final ExtendedMachineImpl exMachine2 = new ExtendedMachineImpl();
    final ServerConf2Impl serverConf3 = new ServerConf2Impl("2333", "https", singletonMap("prop2", "val"));
    final ServerConf2Impl serverConf4 = new ServerConf2Impl("2334", "wss", singletonMap("prop2", "val"));
    exMachine2.setServers(ImmutableMap.of("ref1", serverConf3, "ref2", serverConf4));
    exMachine2.setAgents(ImmutableList.of("agent2", "agent1"));
    exMachine2.setAttributes(singletonMap("att1", "val"));
    final ExtendedMachineImpl exMachine3 = new ExtendedMachineImpl();
    final ServerConf2Impl serverConf5 = new ServerConf2Impl("2333", "https", singletonMap("prop2", "val"));
    exMachine3.setServers(singletonMap("ref1", serverConf5));
    exMachine3.setAgents(ImmutableList.of("agent6", "agent2"));
    exMachine3.setAttributes(singletonMap("att1", "val"));
    // Environments
    final EnvironmentRecipeImpl recipe1 = new EnvironmentRecipeImpl();
    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 EnvironmentRecipeImpl recipe2 = new EnvironmentRecipeImpl();
    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.machine.server.model.impl.CommandImpl) ArrayList(java.util.ArrayList) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl)

Example 9 with EnvironmentImpl

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

the class CheEnvironmentEngine method start.

/**
     * Starts provided environment.
     *
     * <p>Environment starts if and only all machines in environment definition start successfully.<br/>
     * Otherwise exception is thrown by this method.<br/>
     * It is not defined whether environment start fails right after first failure or in the end of the process.<br/>
     * Starting order of machines is not guarantied. Machines can start sequentially or in parallel.
     *
     * @param workspaceId
     *         ID of workspace that owns provided environment
     * @param envName
     *         name of environment
     * @param env
     *         environment to start
     * @param recover
     *         whether machines from environment should be recovered or not
     * @param messageConsumer
     *         consumer of log messages from machines in the environment
     * @param startedHandler
     *         handler for started machines
     * @return list of running machines of this environment
     * @throws ServerException
     *         if other error occurs
     */
public List<Instance> start(String workspaceId, String envName, Environment env, boolean recover, MessageConsumer<MachineLogMessage> messageConsumer, MachineStartedHandler startedHandler) throws ServerException, EnvironmentException, ConflictException {
    EnvironmentImpl environment = new EnvironmentImpl(env);
    // TODO move to machines provider
    // add random chars to ensure that old environments that weren't removed by some reason won't prevent start
    String networkId = NameGenerator.generate(workspaceId + "_", 16);
    String namespace = EnvironmentContext.getCurrent().getSubject().getUserName();
    initializeEnvironment(namespace, workspaceId, envName, environment, networkId, messageConsumer);
    String devMachineName = getDevMachineName(environment);
    if (devMachineName == null) {
        throw new ServerException("Agent 'org.eclipse.che.ws-agent' is not found in any of environment machines");
    }
    startEnvironmentQueue(namespace, workspaceId, devMachineName, networkId, recover, startedHandler);
    try (@SuppressWarnings("unused") Unlocker u = stripedLocks.writeLock(workspaceId)) {
        EnvironmentHolder environmentHolder = environments.get(workspaceId);
        // possible only if environment was stopped during its start
        if (environmentHolder == null) {
            throw new ServerException("Environment start was interrupted by environment stopping");
        }
        environmentHolder.status = EnvStatus.RUNNING;
        // prevent list modification
        return new ArrayList<>(environmentHolder.machines);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Example 10 with EnvironmentImpl

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

the class WorkspaceService method updateEnvironment.

@PUT
@Path("/{id}/environment/{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace environment by replacing it with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The environment successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the environment"), @ApiResponse(code = 404, message = "The workspace or the environment not found"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateEnvironment(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the environment") @PathParam("name") String envName, @ApiParam(value = "The environment update", required = true) EnvironmentDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
    requiredNotNull(update, "Environment description");
    relativizeRecipeLinks(update);
    final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
    EnvironmentImpl previous = workspace.getConfig().getEnvironments().put(envName, new EnvironmentImpl(update));
    if (previous == null) {
        throw new NotFoundException(format("Workspace '%s' doesn't contain environment '%s'", id, envName));
    }
    validator.validateConfig(workspace.getConfig());
    return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(id, workspace)), getServiceContext());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)40 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)27 Test (org.testng.annotations.Test)23 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)17 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)15 Matchers.anyString (org.mockito.Matchers.anyString)14 EnvironmentRecipeImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl)10 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 ServerConf2Impl (org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl)7 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 Instance (org.eclipse.che.api.machine.server.spi.Instance)5 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)5 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)4 CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 ServerException (org.eclipse.che.api.core.ServerException)3 Machine (org.eclipse.che.api.core.model.machine.Machine)3 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)3