Search in sources :

Example 11 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class DefaultServicesStartStrategyTest method shouldFailIfMachineLinksByItSelf.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "A machine can not link to itself: .*")
public void shouldFailIfMachineLinksByItSelf() {
    // given
    CheServicesEnvironmentImpl composeEnvironment = new CheServicesEnvironmentImpl();
    composeEnvironment.getServices().put("first", new CheServiceImpl().withLinks(singletonList("first")));
    // when
    strategy.order(composeEnvironment);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 12 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class CheEnvironmentEngine method initializeEnvironment.

private void initializeEnvironment(String namespace, String workspaceId, String envName, EnvironmentImpl envConfig, String networkId, MessageConsumer<MachineLogMessage> messageConsumer) throws ServerException, ConflictException, EnvironmentException {
    CheServicesEnvironmentImpl internalEnv = environmentParser.parse(envConfig);
    internalEnv.setWorkspaceId(workspaceId);
    infrastructureProvisioner.provision(envConfig, internalEnv);
    normalize(namespace, workspaceId, internalEnv);
    List<String> servicesOrder = startStrategy.order(internalEnv);
    normalizeNames(internalEnv);
    EnvironmentHolder environmentHolder = new EnvironmentHolder(servicesOrder, internalEnv, envConfig, messageConsumer, EnvStatus.STARTING, envName, networkId);
    try (@SuppressWarnings("unused") Unlocker u = stripedLocks.writeLock(workspaceId)) {
        if (environments.putIfAbsent(workspaceId, environmentHolder) != null) {
            throw new ConflictException(format("Environment of workspace '%s' already exists", workspaceId));
        }
    }
}
Also used : ConflictException(org.eclipse.che.api.core.ConflictException) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Example 13 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class CheEnvironmentValidator method validate.

// TODO fix error messages: fields mentioning, usage of service term
public void validate(String envName, Environment env) throws IllegalArgumentException, ServerException {
    checkArgument(!isNullOrEmpty(envName), "Environment name should not be neither null nor empty");
    checkNotNull(env.getRecipe(), "Environment recipe should not be null");
    checkArgument(environmentParser.getEnvironmentTypes().contains(env.getRecipe().getType()), "Type '%s' of environment '%s' is not supported. Supported types: %s", env.getRecipe().getType(), envName, Joiner.on(',').join(environmentParser.getEnvironmentTypes()));
    checkArgument(env.getRecipe().getContent() != null || env.getRecipe().getLocation() != null, "Recipe of environment '%s' must contain location or content", envName);
    checkArgument(env.getRecipe().getContent() == null || env.getRecipe().getLocation() == null, "Recipe of environment '%s' contains mutually exclusive fields location and content", envName);
    CheServicesEnvironmentImpl cheServicesEnvironment;
    try {
        cheServicesEnvironment = environmentParser.parse(env);
    } catch (ServerException e) {
        throw new ServerException(format("Parsing of recipe of environment '%s' failed. Error: %s", envName, e.getLocalizedMessage()));
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(format("Parsing of recipe of environment '%s' failed. Error: %s", envName, e.getLocalizedMessage()));
    }
    checkArgument(cheServicesEnvironment.getServices() != null && !cheServicesEnvironment.getServices().isEmpty(), "Environment '%s' should contain at least 1 machine", envName);
    checkArgument(env.getMachines() != null && !env.getMachines().isEmpty(), "Environment '%s' doesn't contain machine with 'org.eclipse.che.ws-agent' agent", envName);
    List<String> missingServices = env.getMachines().keySet().stream().filter(machineName -> !cheServicesEnvironment.getServices().containsKey(machineName)).collect(toList());
    checkArgument(missingServices.isEmpty(), "Environment '%s' contains machines that are missing in environment recipe: %s", envName, Joiner.on(", ").join(missingServices));
    List<String> devMachines = env.getMachines().entrySet().stream().filter(entry -> entry.getValue().getAgents() != null && entry.getValue().getAgents().contains("org.eclipse.che.ws-agent")).map(Map.Entry::getKey).collect(toList());
    checkArgument(devMachines.size() == 1, "Environment '%s' should contain exactly 1 machine with agent 'org.eclipse.che.ws-agent', but contains '%s'. " + "All machines with this agent: %s", envName, devMachines.size(), Joiner.on(", ").join(devMachines));
    // needed to validate different kinds of dependencies in services to other services
    Set<String> servicesNames = cheServicesEnvironment.getServices().keySet();
    cheServicesEnvironment.getServices().forEach((serviceName, service) -> validateMachine(serviceName, env.getMachines().get(serviceName), service, envName, servicesNames));
    // check that order can be resolved
    try {
        startStrategy.order(cheServicesEnvironment);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(format("Start order of machine in environment '%s' is not resolvable. Error: %s", envName, e.getLocalizedMessage()));
    }
}
Also used : MachineInstanceProviders(org.eclipse.che.api.machine.server.MachineInstanceProviders) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) ServerConf(org.eclipse.che.api.core.model.machine.ServerConf) Set(java.util.Set) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Nullable(org.eclipse.che.commons.annotation.Nullable) String.format(java.lang.String.format) Inject(javax.inject.Inject) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Collectors.toList(java.util.stream.Collectors.toList) Environment(org.eclipse.che.api.core.model.workspace.Environment) Matcher(java.util.regex.Matcher) ServerException(org.eclipse.che.api.core.ServerException) ServerConf2(org.eclipse.che.api.core.model.workspace.ServerConf2) Map(java.util.Map) Pattern(java.util.regex.Pattern) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Joiner(com.google.common.base.Joiner) ServerException(org.eclipse.che.api.core.ServerException) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Map(java.util.Map)

Example 14 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class EnvironmentParser method parse.

/**
     * Parses {@link Environment} into {@link CheServicesEnvironmentImpl}.
     *
     * @param environment
     *         environment to parse
     * @return environment representation as compose environment
     * @throws IllegalArgumentException
     *         if provided environment is illegal
     * @throws ServerException
     *         if fetching of environment recipe content fails
     */
public CheServicesEnvironmentImpl parse(Environment environment) throws IllegalArgumentException, ServerException {
    checkNotNull(environment, "Environment should not be null");
    EnvironmentRecipe recipe = environment.getRecipe();
    checkNotNull(recipe, "Environment recipe should not be null");
    checkNotNull(recipe.getType(), "Environment recipe type should not be null");
    checkArgument(recipe.getContent() != null || recipe.getLocation() != null, "Recipe of environment must contain location or content");
    String envType = recipe.getType();
    Set<String> envTypes = getEnvironmentTypes();
    if (!envTypes.contains(envType)) {
        throw new IllegalArgumentException(format("Environment type '%s' is not supported. " + "Supported environment types: %s", envType, Joiner.on(", ").join(envTypes)));
    }
    TypeSpecificEnvironmentParser parser = environmentParsers.get(envType);
    CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
    cheServicesEnvironment.getServices().forEach((name, service) -> {
        ExtendedMachine extendedMachine = environment.getMachines().get(name);
        if (extendedMachine != null) {
            normalizeMachine(name, service, extendedMachine);
        }
    });
    return cheServicesEnvironment;
}
Also used : EnvironmentRecipe(org.eclipse.che.api.core.model.workspace.EnvironmentRecipe) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine)

Example 15 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class CheEnvironmentValidatorTest method createServicesEnv.

private static CheServicesEnvironmentImpl createServicesEnv() {
    CheServicesEnvironmentImpl cheServicesEnvironment = new CheServicesEnvironmentImpl();
    Map<String, CheServiceImpl> services = new HashMap<>();
    Map<String, String> buildArgs = new HashMap<String, String>() {

        {
            put("argkey", "argvalue");
        }
    };
    cheServicesEnvironment.setServices(services);
    services.put("dev-machine", createCheService("_dev", 1024L * 1024L * 1024L, singletonList("machine2"), singletonList("machine2"), singletonList("machine2")));
    CheServiceImpl service = createCheService("_machine2", 100L, null, emptyList(), null);
    service.setBuild(new CheServiceBuildContextImpl("context", "file", null, buildArgs));
    services.put("machine2", service);
    return cheServicesEnvironment;
}
Also used : CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) HashMap(java.util.HashMap) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Aggregations

CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)54 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)44 Test (org.testng.annotations.Test)38 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)15 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)13 Matchers.anyString (org.mockito.Matchers.anyString)8 HashMap (java.util.HashMap)7 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)7 Environment (org.eclipse.che.api.core.model.workspace.Environment)6 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)6 Map (java.util.Map)3 EnvironmentRecipe (org.eclipse.che.api.core.model.workspace.EnvironmentRecipe)3 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)3 EnvironmentRecipeImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl)3 Joiner (com.google.common.base.Joiner)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2