Search in sources :

Example 1 with InstanceProvider

use of org.eclipse.che.api.machine.server.spi.InstanceProvider in project che by eclipse.

the class CheEnvironmentEngine method removeSnapshot.

/**
     * Removes snapshot of machine.
     *
     * @param snapshot
     *         description of snapshot that should be removed
     * @throws NotFoundException
     *         if snapshot is not found
     * @throws ServerException
     *         if error occurs on snapshot removal
     */
public void removeSnapshot(SnapshotImpl snapshot) throws ServerException, NotFoundException {
    final String instanceType = snapshot.getType();
    final InstanceProvider instanceProvider = machineInstanceProviders.getProvider(instanceType);
    instanceProvider.removeInstanceSnapshot(snapshot.getMachineSource());
}
Also used : InstanceProvider(org.eclipse.che.api.machine.server.spi.InstanceProvider)

Example 2 with InstanceProvider

use of org.eclipse.che.api.machine.server.spi.InstanceProvider in project che by eclipse.

the class CheEnvironmentEngine method startMachine.

/**
     * Starts machine in running environment.
     *
     * @param workspaceId
     *         ID of workspace that owns environment in which machine should be started
     * @param machineConfig
     *         configuration of machine that should be started
     * @return running machine
     * @throws EnvironmentNotRunningException
     *         if environment is not running
     * @throws NotFoundException
     *         if provider of machine implementation is not found
     * @throws ConflictException
     *         if machine with the same name already exists in the environment
     * @throws ServerException
     *         if any other error occurs
     */
public Instance startMachine(String workspaceId, MachineConfig machineConfig, List<String> agents) throws ServerException, NotFoundException, ConflictException, EnvironmentException {
    MachineConfig machineConfigCopy = new MachineConfigImpl(machineConfig);
    EnvironmentHolder environmentHolder;
    try (@SuppressWarnings("unused") Unlocker u = stripedLocks.readLock(workspaceId)) {
        environmentHolder = environments.get(workspaceId);
        if (environmentHolder == null || environmentHolder.status != EnvStatus.RUNNING) {
            throw new EnvironmentNotRunningException(format("Environment '%s' is not running", workspaceId));
        }
        for (Instance machine : environmentHolder.machines) {
            if (machine.getConfig().getName().equals(machineConfigCopy.getName())) {
                throw new ConflictException(format("Machine with name '%s' already exists in environment of workspace '%s'", machineConfigCopy.getName(), workspaceId));
            }
        }
    }
    final String creator = EnvironmentContext.getCurrent().getSubject().getUserId();
    final String namespace = EnvironmentContext.getCurrent().getSubject().getUserName();
    MachineImpl machine = MachineImpl.builder().setConfig(machineConfig).setWorkspaceId(workspaceId).setStatus(MachineStatus.CREATING).setEnvName(environmentHolder.name).setOwner(creator).build();
    MachineStarter machineStarter;
    if ("docker".equals(machineConfig.getType())) {
        // needed to reuse startInstance method and
        // create machine instances by different implementation-specific providers
        CheServiceImpl service = machineConfigToService(machineConfig);
        normalize(namespace, workspaceId, machineConfig.getName(), service);
        machine.setId(service.getId());
        machineStarter = (machineLogger, machineSource) -> {
            CheServiceImpl serviceWithNormalizedSource = normalizeServiceSource(service, machineSource);
            normalize(namespace, workspaceId, machineConfig.getName(), serviceWithNormalizedSource);
            infrastructureProvisioner.provision(new ExtendedMachineImpl().withAgents(agents), serviceWithNormalizedSource);
            return machineProvider.startService(namespace, workspaceId, environmentHolder.name, machineConfig.getName(), machineConfig.isDev(), environmentHolder.networkId, serviceWithNormalizedSource, machineLogger);
        };
    } else {
        try {
            InstanceProvider provider = machineInstanceProviders.getProvider(machineConfig.getType());
            machine.setId(generateMachineId());
            addAgentsProvidedServers(machine, agents);
            machineStarter = (machineLogger, machineSource) -> {
                Machine machineWithNormalizedSource = normalizeMachineSource(machine, machineSource);
                return provider.createInstance(machineWithNormalizedSource, machineLogger);
            };
        } catch (NotFoundException e) {
            throw new NotFoundException(format("Provider of machine type '%s' not found", machineConfig.getType()));
        }
    }
    return startInstance(false, environmentHolder.logger, machine, machineStarter);
}
Also used : ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) Instance(org.eclipse.che.api.machine.server.spi.Instance) ConflictException(org.eclipse.che.api.core.ConflictException) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) SourceNotFoundException(org.eclipse.che.api.machine.server.exception.SourceNotFoundException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) InstanceProvider(org.eclipse.che.api.machine.server.spi.InstanceProvider)

Aggregations

InstanceProvider (org.eclipse.che.api.machine.server.spi.InstanceProvider)2 ConflictException (org.eclipse.che.api.core.ConflictException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 Machine (org.eclipse.che.api.core.model.machine.Machine)1 MachineConfig (org.eclipse.che.api.core.model.machine.MachineConfig)1 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)1 EnvironmentNotRunningException (org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException)1 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)1 SourceNotFoundException (org.eclipse.che.api.machine.server.exception.SourceNotFoundException)1 MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)1 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)1 Instance (org.eclipse.che.api.machine.server.spi.Instance)1 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)1 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)1