Search in sources :

Example 1 with EnvironmentRecipe

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;
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) EnvironmentRecipe(org.eclipse.che.api.core.model.workspace.EnvironmentRecipe) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Example 2 with EnvironmentRecipe

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;
}
Also used : CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) EnvironmentRecipe(org.eclipse.che.api.core.model.workspace.EnvironmentRecipe) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Example 3 with EnvironmentRecipe

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);
}
Also used : ComposeEnvironment(org.eclipse.che.plugin.docker.compose.ComposeEnvironment) EnvironmentRecipe(org.eclipse.che.api.core.model.workspace.EnvironmentRecipe)

Example 4 with EnvironmentRecipe

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

Aggregations

EnvironmentRecipe (org.eclipse.che.api.core.model.workspace.EnvironmentRecipe)4 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)3 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)2 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)1 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)1 ComposeEnvironment (org.eclipse.che.plugin.docker.compose.ComposeEnvironment)1