Search in sources :

Example 61 with Blueprint

use of com.sequenceiq.cloudbreak.domain.Blueprint in project cloudbreak by hortonworks.

the class BlueprintService method create.

@Transactional(TxType.NEVER)
public Blueprint create(IdentityUser user, Blueprint blueprint, Collection<Map<String, Map<String, String>>> properties) {
    LOGGER.debug("Creating blueprint: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
    Blueprint savedBlueprint;
    blueprint.setOwner(user.getUserId());
    blueprint.setAccount(user.getAccount());
    if (properties != null && !properties.isEmpty()) {
        LOGGER.info("Extend validation with the following properties: {}", properties);
        Map<String, Map<String, String>> configs = new HashMap<>(properties.size());
        for (Map<String, Map<String, String>> property : properties) {
            for (Entry<String, Map<String, String>> entry : property.entrySet()) {
                Map<String, String> configValues = configs.get(entry.getKey());
                if (configValues != null) {
                    configValues.putAll(entry.getValue());
                } else {
                    configs.put(entry.getKey(), entry.getValue());
                }
            }
        }
        String extendedBlueprint = blueprintProcessorFactory.get(blueprint.getBlueprintText()).extendBlueprintGlobalConfiguration(SiteConfigurations.fromMap(configs), false).asText();
        LOGGER.info("Extended validation result: {}", extendedBlueprint);
        blueprint.setBlueprintText(extendedBlueprint);
    }
    try {
        savedBlueprint = blueprintRepository.save(blueprint);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.BLUEPRINT, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
    return savedBlueprint;
}
Also used : HashMap(java.util.HashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HashMap(java.util.HashMap) Map(java.util.Map) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

Example 62 with Blueprint

use of com.sequenceiq.cloudbreak.domain.Blueprint in project cloudbreak by hortonworks.

the class BlueprintService method delete.

public void delete(Long id, IdentityUser user) {
    Blueprint blueprint = blueprintRepository.findByIdInAccount(id, user.getAccount());
    if (blueprint == null) {
        throw new NotFoundException(String.format("Blueprint '%s' not found.", id));
    }
    delete(blueprint);
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException)

Example 63 with Blueprint

use of com.sequenceiq.cloudbreak.domain.Blueprint in project cloudbreak by hortonworks.

the class BlueprintService method get.

public Blueprint get(String name, String account) {
    Blueprint blueprint = blueprintRepository.findOneByName(name, account);
    if (blueprint == null) {
        throw new NotFoundException(String.format("Blueprint '%s' not found in %s account.", name, account));
    }
    authorizationService.hasReadPermission(blueprint);
    return blueprint;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException)

Example 64 with Blueprint

use of com.sequenceiq.cloudbreak.domain.Blueprint in project cloudbreak by hortonworks.

the class AmbariClusterService method recreate.

@Override
public Cluster recreate(Long stackId, Long blueprintId, Set<HostGroup> hostGroups, boolean validateBlueprint, StackRepoDetails stackRepoDetails, String kerberosPassword, String kerberosPrincipal) {
    if (blueprintId == null || hostGroups == null) {
        throw new BadRequestException("Blueprint id and hostGroup assignments can not be null.");
    }
    Stack stack = stackService.getByIdWithLists(stackId);
    Cluster cluster = getCluster(stack);
    if (cluster != null && stack.getCluster().isSecure()) {
        List<String> missing = Stream.of(Pair.of("password", kerberosPassword), Pair.of("principal", kerberosPrincipal)).filter(p -> !StringUtils.hasLength(p.getRight())).map(Pair::getLeft).collect(Collectors.toList());
        if (!missing.isEmpty()) {
            throw new BadRequestException(String.format("Missing Kerberos credential detail(s): %s", String.join(", ", missing)));
        }
        KerberosConfig kerberosConfig = cluster.getKerberosConfig();
        kerberosConfig.setPassword(kerberosPassword);
        kerberosConfig.setPrincipal(kerberosPrincipal);
        kerberosConfigRepository.save(kerberosConfig);
    }
    Blueprint blueprint = blueprintService.get(blueprintId);
    if (!withEmbeddedAmbariDB(cluster)) {
        throw new BadRequestException("Ambari doesn't support resetting external DB automatically. To reset Ambari Server schema you must first drop " + "and then create it using DDL scripts from /var/lib/ambari-server/resources");
    }
    if (validateBlueprint) {
        blueprintValidator.validateBlueprintForStack(cluster, blueprint, hostGroups, stack.getInstanceGroups());
    }
    Boolean containerOrchestrator;
    try {
        containerOrchestrator = orchestratorTypeResolver.resolveType(stack.getOrchestrator()).containerOrchestrator();
    } catch (CloudbreakException ignored) {
        containerOrchestrator = false;
    }
    if (containerOrchestrator) {
        clusterTerminationService.deleteClusterComponents(cluster.getId());
        cluster = clusterRepository.findById(stack.getCluster().getId());
    }
    hostGroups = hostGroupService.saveOrUpdateWithMetadata(hostGroups, cluster);
    cluster = prepareCluster(hostGroups, stackRepoDetails, blueprint, stack, cluster);
    try {
        triggerClusterInstall(stack, cluster);
    } catch (CloudbreakException e) {
        throw new CloudbreakServiceException(e);
    }
    return stack.getCluster();
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) KerberosConfig(com.sequenceiq.cloudbreak.domain.KerberosConfig) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 65 with Blueprint

use of com.sequenceiq.cloudbreak.domain.Blueprint in project cloudbreak by hortonworks.

the class TestUtil method blueprint.

public static Blueprint blueprint(String name, String blueprintText) {
    Blueprint blueprint = new Blueprint();
    blueprint.setId(1L);
    blueprint.setBlueprintText(blueprintText);
    blueprint.setName(name);
    blueprint.setAmbariName("multi-node-yarn");
    blueprint.setStatus(ResourceStatus.DEFAULT);
    return blueprint;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint)

Aggregations

Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)71 Test (org.junit.Test)29 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)27 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)22 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)22 Stack (com.sequenceiq.cloudbreak.domain.Stack)16 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)7 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)6 List (java.util.List)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)4 BlueprintPreparationObject (com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject)4 BlueprintTextProcessor (com.sequenceiq.cloudbreak.blueprint.BlueprintTextProcessor)4