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;
}
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);
}
}
}
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;
}
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());
}
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);
}
Aggregations