use of org.eclipse.che.api.core.model.workspace.EnvironmentRecipe in project che by eclipse.
the class DockerImageEnvironmentParser method parse.
@Override
public CheServicesEnvironmentImpl parse(Environment environment) throws IllegalArgumentException, ServerException {
EnvironmentRecipe recipe = environment.getRecipe();
if (!"dockerimage".equals(recipe.getType())) {
throw new IllegalArgumentException(format("Docker image environment parser doesn't support recipe type '%s'", recipe.getType()));
}
CheServicesEnvironmentImpl cheServiceEnv = new CheServicesEnvironmentImpl();
CheServiceImpl service = new CheServiceImpl();
cheServiceEnv.getServices().put(getMachineName(environment), service);
service.setImage(recipe.getLocation());
return cheServiceEnv;
}
use of org.eclipse.che.api.core.model.workspace.EnvironmentRecipe in project che by eclipse.
the class DockerfileEnvironmentParser method parse.
@Override
public CheServicesEnvironmentImpl parse(Environment environment) throws IllegalArgumentException, ServerException {
EnvironmentRecipe recipe = environment.getRecipe();
if (!"dockerfile".equals(recipe.getType())) {
throw new IllegalArgumentException(format("Dockerfile environment parser doesn't support recipe type '%s'", recipe.getType()));
}
if (!"text/x-dockerfile".equals(recipe.getContentType())) {
throw new IllegalArgumentException(format("Content type '%s' of recipe of environment is unsupported." + " Supported values are: text/x-dockerfile", recipe.getContentType()));
}
CheServicesEnvironmentImpl cheServiceEnv = new CheServicesEnvironmentImpl();
CheServiceImpl service = new CheServiceImpl();
cheServiceEnv.getServices().put(getMachineName(environment), service);
if (recipe.getLocation() != null) {
service.setBuild(new CheServiceBuildContextImpl().withContext(recipe.getLocation()));
} else {
service.setBuild(new CheServiceBuildContextImpl().withDockerfileContent(recipe.getContent()));
}
return cheServiceEnv;
}
use of org.eclipse.che.api.core.model.workspace.EnvironmentRecipe in project che by eclipse.
the class ComposeEnvironmentParser method parse.
/**
* Parses compose file from {@link Environment} into {@link CheServicesEnvironmentImpl}.
*
* @param environment
* environment with {@link EnvironmentRecipe} to parse.
* {@link EnvironmentRecipe} contains {@link CheServicesEnvironmentImpl} definition.
* @throws IllegalArgumentException
* when environment or environment recipe is invalid
* @throws ServerException
* when environment recipe can not be retrieved
*/
@Override
public CheServicesEnvironmentImpl parse(Environment environment) throws ServerException {
requireNonNull(environment, "Environment should not be null");
EnvironmentRecipe recipe = environment.getRecipe();
requireNonNull(environment.getRecipe(), "Environment recipe should not be null");
String content = getContentOfRecipe(recipe);
ComposeEnvironment composeEnvironment = parse(content, recipe.getContentType());
return asCheEnvironment(composeEnvironment);
}
use of org.eclipse.che.api.core.model.workspace.EnvironmentRecipe 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;
}
Aggregations