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