Search in sources :

Example 6 with RecipeScript

use of com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript in project cloudbreak by hortonworks.

the class AbstractFileSystemConfigurator method getScripts.

@Override
public List<RecipeScript> getScripts(Credential credential, T fsConfig) {
    List<RecipeScript> scripts = new ArrayList<>();
    try {
        for (FileSystemScriptConfig fsScriptConfig : getScriptConfigs(credential, fsConfig)) {
            String script = FileReaderUtils.readFileFromClasspath(fsScriptConfig.getScriptLocation());
            for (Entry<String, String> entry : fsScriptConfig.getProperties().entrySet()) {
                script = script.replaceAll("\\$" + entry.getKey(), entry.getValue());
            }
            scripts.add(new RecipeScript(script, fsScriptConfig.getExecutionType(), fsScriptConfig.getRecipeType()));
        }
    } catch (IOException e) {
        throw new FileSystemConfigException("Filesystem configuration scripts cannot be read.", e);
    }
    return scripts;
}
Also used : RecipeScript(com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 7 with RecipeScript

use of com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript in project cloudbreak by hortonworks.

the class RecipeBuilder method buildRecipes.

public List<Recipe> buildRecipes(String recipeName, Collection<RecipeScript> recipeScripts) {
    List<Recipe> recipes = new ArrayList<>();
    int index = 0;
    for (RecipeScript script : recipeScripts) {
        Recipe recipe = new Recipe();
        if (recipeScripts.size() > 1) {
            recipe.setName(recipeName + '-' + index);
        } else {
            recipe.setName(recipeName);
        }
        recipe.setContent(Base64.encodeBase64String(script.getScript().getBytes()));
        recipe.setRecipeType(script.getRecipeType());
        index++;
        recipes.add(recipe);
    }
    return recipes;
}
Also used : RecipeScript(com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) ArrayList(java.util.ArrayList)

Example 8 with RecipeScript

use of com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript in project cloudbreak by hortonworks.

the class RecipeEngine method addFsRecipesToHostGroups.

private void addFsRecipesToHostGroups(Credential credential, Iterable<HostGroup> hostGroups, String blueprintText, FileSystem fs) throws IOException {
    String scriptName = fs.getType().toLowerCase();
    FileSystemConfigurator fsConfigurator = fileSystemConfigurators.get(FileSystemType.valueOf(fs.getType()));
    FileSystemConfiguration fsConfiguration = getFileSystemConfiguration(fs);
    List<RecipeScript> recipeScripts = fsConfigurator.getScripts(credential, fsConfiguration);
    List<Recipe> fsRecipes = recipeBuilder.buildRecipes(scriptName, recipeScripts);
    for (int i = 0; i < fsRecipes.size(); i++) {
        RecipeScript recipeScript = recipeScripts.get(i);
        Recipe recipe = fsRecipes.get(i);
        for (HostGroup hostGroup : hostGroups) {
            if (ExecutionType.ALL_NODES == recipeScript.getExecutionType()) {
                hostGroup.addRecipe(recipe);
            } else if (ExecutionType.ONE_NODE == recipeScript.getExecutionType() && isComponentPresent(blueprintText, "NAMENODE", hostGroup)) {
                hostGroup.addRecipe(recipe);
                break;
            }
        }
    }
}
Also used : FileSystemConfigurator(com.sequenceiq.cloudbreak.blueprint.filesystem.FileSystemConfigurator) RecipeScript(com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) FileSystemConfiguration(com.sequenceiq.cloudbreak.api.model.FileSystemConfiguration)

Aggregations

RecipeScript (com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript)8 Recipe (com.sequenceiq.cloudbreak.domain.Recipe)5 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)4 IOException (java.io.IOException)4 FileSystemConfiguration (com.sequenceiq.cloudbreak.api.model.FileSystemConfiguration)3 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)2 Credential (com.sequenceiq.cloudbreak.domain.Credential)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 FileSystemConfigurator (com.sequenceiq.cloudbreak.blueprint.filesystem.FileSystemConfigurator)1