Search in sources :

Example 6 with ComposeEnvironment

use of org.eclipse.che.plugin.docker.compose.ComposeEnvironment in project che by eclipse.

the class ComposeEnvironmentParser method parse.

/**
     * Parses compose file into Docker Compose model.
     *
     * @param recipeContent
     *         compose file to parse
     * @throws IllegalArgumentException
     *         when environment or environment recipe is invalid
     * @throws ServerException
     *         when environment recipe can not be retrieved
     */
public ComposeEnvironment parse(String recipeContent, String contentType) throws ServerException {
    requireNonNull(recipeContent, "Recipe content should not be null");
    requireNonNull(contentType, "Recipe content type should not be null");
    ComposeEnvironment composeEnvironment;
    switch(contentType) {
        case "application/x-yaml":
        case "text/yaml":
        case "text/x-yaml":
            try {
                composeEnvironment = YAML_PARSER.readValue(recipeContent, ComposeEnvironment.class);
            } catch (IOException e) {
                throw new IllegalArgumentException("Parsing of environment configuration failed. " + e.getLocalizedMessage());
            }
            break;
        default:
            throw new IllegalArgumentException("Provided environment recipe content type '" + contentType + "' is unsupported. Supported values are: " + "application/x-yaml, text/yaml, text/x-yaml");
    }
    return composeEnvironment;
}
Also used : ComposeEnvironment(org.eclipse.che.plugin.docker.compose.ComposeEnvironment) IOException(java.io.IOException)

Aggregations

ComposeEnvironment (org.eclipse.che.plugin.docker.compose.ComposeEnvironment)6 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 EnvironmentRecipe (org.eclipse.che.api.core.model.workspace.EnvironmentRecipe)1 ComposeServiceImpl (org.eclipse.che.plugin.docker.compose.ComposeServiceImpl)1