Search in sources :

Example 66 with Blueprint

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

the class BlueprintLoaderService method collectDeviationOfExistingBlueprintsAndDefaultBlueprints.

private Map<String, Blueprint> collectDeviationOfExistingBlueprintsAndDefaultBlueprints(Iterable<Blueprint> blueprints) {
    LOGGER.info("Collecting Blueprints which are missing from the defaults.");
    Map<String, Blueprint> diff = new HashMap<>();
    for (Entry<String, Blueprint> stringBlueprintEntry : defaultBlueprintCache.defaultBlueprints().entrySet()) {
        boolean contains = false;
        for (Blueprint blueprint : blueprints) {
            if (isRegisteregBlueprintAndDefaultBlueprintIsTheSame(stringBlueprintEntry, blueprint)) {
                contains = true;
                break;
            }
        }
        if (!contains) {
            diff.put(stringBlueprintEntry.getKey(), stringBlueprintEntry.getValue());
        }
    }
    LOGGER.info("Finished to collect the default blueprints which are missing: {}.", diff);
    return diff;
}
Also used : HashMap(java.util.HashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint)

Example 67 with Blueprint

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

the class DefaultBlueprintCache method loadBlueprintsFromFile.

@PostConstruct
public void loadBlueprintsFromFile() {
    for (String blueprintStrings : blueprintArray) {
        try {
            String[] split = blueprintStrings.split("=");
            if (blueprintUtils.isBlueprintNamePreConfigured(blueprintStrings, split)) {
                LOGGER.info("Load default validation '{}'.", blueprintStrings);
                BlueprintRequest blueprintJson = new BlueprintRequest();
                blueprintJson.setName(split[0].trim());
                JsonNode jsonNode = blueprintUtils.convertStringToJsonNode(blueprintUtils.readDefaultBlueprintFromFile(split));
                blueprintJson.setAmbariBlueprint(jsonNode.get("blueprint").toString());
                Blueprint bp = converter.convert(blueprintJson);
                JsonNode inputs = jsonNode.get("inputs");
                JsonNode description = jsonNode.get("description");
                bp.setDescription(description == null ? split[0] : description.asText(split[0]));
                BlueprintInputParameters inputParameters = new BlueprintInputParameters(blueprintUtils.prepareInputs(inputs));
                bp.setInputParameters(new Json(inputParameters));
                defaultBlueprints.put(bp.getName(), bp);
            }
        } catch (IOException e) {
            LOGGER.info("Can not read default validation from file: ", e);
        }
    }
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) JsonNode(com.fasterxml.jackson.databind.JsonNode) Json(com.sequenceiq.cloudbreak.domain.json.Json) IOException(java.io.IOException) BlueprintRequest(com.sequenceiq.cloudbreak.api.model.BlueprintRequest) BlueprintInputParameters(com.sequenceiq.cloudbreak.domain.BlueprintInputParameters) PostConstruct(javax.annotation.PostConstruct)

Example 68 with Blueprint

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

the class UsageGeneratorService method openNewUsage.

public CloudbreakUsage openNewUsage(Stack stack, String instanceType, Integer instanceNum, String groupName, TemporalAccessor started) {
    CloudbreakUsage usage = new CloudbreakUsage();
    usage.setStackUuid(stack.getUuid());
    usage.setParentUuid(cloudbreakNodeConfig.getInstanceUUID());
    usage.setOwner(stack.getOwner());
    usage.setAccount(stack.getAccount());
    usage.setProvider(stack.cloudPlatform());
    usage.setRegion(stack.getRegion());
    usage.setAvailabilityZone(stack.getAvailabilityZone());
    usage.setInstanceHours(0L);
    usage.setCosts(0.0);
    Date day = Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
    usage.setDay(day);
    usage.setStackId(stack.getId());
    usage.setStackName(stack.getName());
    usage.setInstanceType(instanceType);
    usage.setInstanceNum(instanceNum);
    usage.setPeak(instanceNum);
    usage.setInstanceGroup(groupName);
    if (stack.getCluster() != null && stack.getCluster().getBlueprint() != null) {
        Blueprint bp = stack.getCluster().getBlueprint();
        usage.setBlueprintId(bp.getId());
        usage.setBlueprintName(bp.getAmbariName());
    }
    usage.setPeriodStarted(Date.from(LocalDateTime.from(started).atZone(ZoneId.systemDefault()).toInstant()));
    usage.setStatus(UsageStatus.OPEN);
    FlexSubscription flexSubscription = stack.getFlexSubscription();
    if (flexSubscription != null && flexSubscription.getSmartSenseSubscription() != null) {
        usage.setFlexId(flexSubscription.getSubscriptionId());
        usage.setSmartSenseId(flexSubscription.getSmartSenseSubscription().getSubscriptionId());
    }
    return usage;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) FlexSubscription(com.sequenceiq.cloudbreak.domain.FlexSubscription) Date(java.util.Date) LocalDate(java.time.LocalDate) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 69 with Blueprint

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

the class UserResourceCheck method hasResources.

@Transactional(readOnly = true)
public boolean hasResources(IdentityUser admin, String userId) {
    IdentityUser user = userDetailsService.getDetails(userId, UserFilterField.USERID);
    LOGGER.info("{} / {} checks resources of {}", admin.getUserId(), admin.getUsername(), userId);
    String errorMessage = null;
    if (!admin.getRoles().contains(IdentityUserRole.ADMIN)) {
        errorMessage = "Forbidden: user (%s) is not authorized for this operation on %s";
    }
    if (!admin.getAccount().equals(user.getAccount())) {
        errorMessage = "Forbidden: admin (%s) and user (%s) are not under the same account.";
    }
    if (!Strings.isNullOrEmpty(errorMessage)) {
        throw new AccessDeniedException(String.format(errorMessage, admin.getUsername(), user.getUsername()));
    }
    Set<Template> templates = templateRepository.findForUser(user.getUserId());
    Set<Credential> credentials = credentialRepository.findForUser(user.getUserId());
    Set<Blueprint> blueprints = blueprintRepository.findForUser(user.getUserId());
    Set<Network> networks = networkRepository.findForUser(user.getUserId());
    Set<Stack> stacks = stackRepository.findForUser(user.getUserId());
    return !(stacks.isEmpty() && templates.isEmpty() && credentials.isEmpty() && blueprints.isEmpty() && networks.isEmpty());
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Credential(com.sequenceiq.cloudbreak.domain.Credential) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Template(com.sequenceiq.cloudbreak.domain.Template) Stack(com.sequenceiq.cloudbreak.domain.Stack) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Network(com.sequenceiq.cloudbreak.domain.Network) Transactional(org.springframework.transaction.annotation.Transactional)

Example 70 with Blueprint

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

the class StructuredFlowEventFactory method createStructuredNotificationEvent.

public StructuredNotificationEvent createStructuredNotificationEvent(Long stackId, String notificationType, String message, String instanceGroupName) {
    Stack stack = stackService.getById(stackId);
    UserProfile userProfile = userProfileService.get(stack.getAccount(), stack.getOwner());
    OperationDetails operationDetails = new OperationDetails("NOTIFICATION", "STACK", stackId, stack.getAccount(), stack.getOwner(), userProfile.getUserName(), cloudbreakNodeConfig.getInstanceUUID(), cbVersion);
    NotificationDetails notificationDetails = new NotificationDetails();
    notificationDetails.setNotificationType(notificationType);
    notificationDetails.setNotification(message);
    notificationDetails.setCloud(stack.cloudPlatform());
    notificationDetails.setRegion(stack.getRegion());
    notificationDetails.setAvailabiltyZone(stack.getAvailabilityZone());
    notificationDetails.setStackId(stackId);
    notificationDetails.setStackName(stack.getDisplayName());
    notificationDetails.setStackStatus(stack.getStatus().name());
    notificationDetails.setNodeCount(stack.getRunningInstanceMetaData().size());
    notificationDetails.setInstanceGroup(instanceGroupName);
    Cluster cluster = stack.getCluster();
    if (cluster != null) {
        notificationDetails.setClusterId(cluster.getId());
        notificationDetails.setClusterName(cluster.getName());
        notificationDetails.setClusterStatus(cluster.getStatus().name());
        Blueprint blueprint = cluster.getBlueprint();
        if (blueprint != null) {
            notificationDetails.setBlueprintId(blueprint.getId());
            notificationDetails.setBlueprintName(blueprint.getAmbariName());
        }
    }
    return new StructuredNotificationEvent(operationDetails, notificationDetails);
}
Also used : OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.OperationDetails) NotificationDetails(com.sequenceiq.cloudbreak.structuredevent.event.NotificationDetails) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) StructuredNotificationEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent) Stack(com.sequenceiq.cloudbreak.domain.Stack)

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