Search in sources :

Example 1 with RecipeModel

use of com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel in project cloudbreak by hortonworks.

the class OrchestratorRecipeExecutor method uploadRecipes.

public void uploadRecipes(Stack stack, Collection<HostGroup> hostGroups) throws CloudbreakException {
    HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
    Map<String, List<RecipeModel>> recipeMap = hostGroups.stream().filter(hg -> !hg.getRecipes().isEmpty()).collect(Collectors.toMap(HostGroup::getName, h -> convert(h.getRecipes())));
    List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
    recipesEvent(stack.getId(), stack.getStatus(), recipeMap);
    try {
        hostOrchestrator.uploadRecipes(allGatewayConfigs, recipeMap, clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
    } catch (CloudbreakOrchestratorFailedException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Joiner(com.google.api.client.util.Joiner) Base64(org.apache.commons.codec.binary.Base64) ArrayList(java.util.ArrayList) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Status(com.sequenceiq.cloudbreak.api.model.Status) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Collection(java.util.Collection) Set(java.util.Set) DEFAULT_RECIPES(com.sequenceiq.cloudbreak.service.cluster.flow.RecipeEngine.DEFAULT_RECIPES) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) Collectors(java.util.stream.Collectors) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) Component(org.springframework.stereotype.Component) HostOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostOrchestratorResolver) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) Entry(java.util.Map.Entry) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Collections(java.util.Collections) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ArrayList(java.util.ArrayList) List(java.util.List) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 2 with RecipeModel

use of com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel in project cloudbreak by hortonworks.

the class OrchestratorRecipeExecutor method convert.

private List<RecipeModel> convert(Iterable<Recipe> recipes) {
    List<RecipeModel> result = new ArrayList<>();
    for (Recipe recipe : recipes) {
        String decodedContent = new String(Base64.decodeBase64(recipe.getContent()));
        RecipeModel recipeModel = new RecipeModel(recipe.getName(), recipe.getRecipeType(), decodedContent);
        result.add(recipeModel);
    }
    return result;
}
Also used : Recipe(com.sequenceiq.cloudbreak.domain.Recipe) ArrayList(java.util.ArrayList) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel)

Example 3 with RecipeModel

use of com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel in project cloudbreak by hortonworks.

the class OrchestratorRecipeExecutor method recipesEvent.

private void recipesEvent(Long stackId, Status status, Map<String, List<RecipeModel>> recipeMap) {
    List<String> recipes = new ArrayList<>();
    for (Entry<String, List<RecipeModel>> entry : recipeMap.entrySet()) {
        Collection<String> recipeNamesPerHostgroup = new ArrayList<>(entry.getValue().size());
        for (RecipeModel rm : entry.getValue()) {
            // filter out default recipes
            if (!DEFAULT_RECIPES.contains(rm.getName())) {
                recipeNamesPerHostgroup.add(rm.getName());
            }
        }
        if (!recipeNamesPerHostgroup.isEmpty()) {
            String recipeNamesStr = Joiner.on(',').join(recipeNamesPerHostgroup);
            recipes.add(String.format("%s:[%s]", entry.getKey(), recipeNamesStr));
        }
    }
    if (!recipes.isEmpty()) {
        Collections.sort(recipes);
        String messageStr = Joiner.on(';').join(recipes);
        cloudbreakEventService.fireCloudbreakEvent(stackId, status.name(), cloudbreakMessagesService.getMessage(Msg.UPLOAD_RECIPES.code(), Collections.singletonList(messageStr)));
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel)

Example 4 with RecipeModel

use of com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel in project cloudbreak by hortonworks.

the class SaltOrchestrator method uploadRecipes.

@Override
public void uploadRecipes(List<GatewayConfig> allGatewayConfigs, Map<String, List<RecipeModel>> recipes, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorFailedException {
    GatewayConfig primaryGateway = allGatewayConfigs.stream().filter(GatewayConfig::isPrimary).findFirst().get();
    Set<String> gatewayTargets = getGatewayPrivateIps(allGatewayConfigs);
    try (SaltConnector sc = new SaltConnector(primaryGateway, restDebug)) {
        OrchestratorBootstrap scriptPillarSave = new PillarSave(sc, gatewayTargets, recipes);
        Callable<Boolean> saltPillarRunner = runner(scriptPillarSave, exitCriteria, exitModel);
        Future<Boolean> saltPillarRunnerFuture = parallelOrchestratorComponentRunner.submit(saltPillarRunner);
        saltPillarRunnerFuture.get();
        for (List<RecipeModel> recipeList : recipes.values()) {
            for (RecipeModel model : recipeList) {
                uploadRecipe(sc, gatewayTargets, exitModel, model.getName(), model.getScript(), RecipeExecutionPhase.convert(model.getRecipeType()));
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error occurred during recipe upload", e);
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave)

Aggregations

RecipeModel (com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel)4 ArrayList (java.util.ArrayList)3 Recipe (com.sequenceiq.cloudbreak.domain.Recipe)2 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)2 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)2 List (java.util.List)2 Joiner (com.google.api.client.util.Joiner)1 Status (com.sequenceiq.cloudbreak.api.model.Status)1 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)1 ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel (com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel)1 HostOrchestratorResolver (com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostOrchestratorResolver)1 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)1 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)1 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)1 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)1 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)1