use of com.sequenceiq.cloudbreak.domain.Blueprint in project cloudbreak by hortonworks.
the class StackService method validateHostGroupAdjustment.
private void validateHostGroupAdjustment(InstanceGroupAdjustmentJson instanceGroupAdjustmentJson, Stack stack, Integer adjustment) {
Blueprint blueprint = stack.getCluster().getBlueprint();
Optional<HostGroup> hostGroup = stack.getCluster().getHostGroups().stream().filter(input -> input.getConstraint().getInstanceGroup().getGroupName().equals(instanceGroupAdjustmentJson.getInstanceGroup())).findFirst();
if (!hostGroup.isPresent()) {
throw new BadRequestException(String.format("Instancegroup '%s' not found or not part of stack '%s'", instanceGroupAdjustmentJson.getInstanceGroup(), stack.getName()));
}
blueprintValidator.validateHostGroupScalingRequest(blueprint, hostGroup.get(), adjustment);
}
use of com.sequenceiq.cloudbreak.domain.Blueprint in project cloudbreak by hortonworks.
the class StackValidationRequestToStackValidationConverter method validateBlueprint.
private void validateBlueprint(StackValidationRequest stackValidationRequest, StackValidation stackValidation) {
if (stackValidationRequest.getBlueprintId() != null) {
Blueprint blueprint = blueprintService.get(stackValidationRequest.getBlueprintId());
stackValidation.setBlueprint(blueprint);
} else if (stackValidationRequest.getBlueprintName() != null) {
Blueprint blueprint = blueprintService.get(stackValidationRequest.getBlueprintName(), stackValidationRequest.getAccount());
stackValidation.setBlueprint(blueprint);
} else if (stackValidationRequest.getBlueprint() != null) {
Blueprint blueprint = conversionService.convert(stackValidationRequest.getBlueprint(), Blueprint.class);
stackValidation.setBlueprint(blueprint);
} else {
throw new BadRequestException("Blueprint is not configured for the validation request!");
}
}
use of com.sequenceiq.cloudbreak.domain.Blueprint in project cloudbreak by hortonworks.
the class ClusterToClusterResponseConverter method prepareServiceEndpointsMap.
private Map<String, String> prepareServiceEndpointsMap(Cluster cluster, String ambariIp) {
Set<HostGroup> hostGroups = cluster.getHostGroups();
Blueprint blueprint = cluster.getBlueprint();
Map<String, String> result = new HashMap<>();
List<Port> ports = NetworkUtils.getPorts(Optional.empty());
try {
JsonNode hostGroupsNode = blueprintValidator.getHostGroupNode(blueprint);
Map<String, HostGroup> hostGroupMap = blueprintValidator.createHostGroupMap(hostGroups);
for (JsonNode hostGroupNode : hostGroupsNode) {
String hostGroupName = blueprintValidator.getHostGroupName(hostGroupNode);
JsonNode componentsNode = blueprintValidator.getComponentsNode(hostGroupNode);
HostGroup actualHostgroup = hostGroupMap.get(hostGroupName);
String serviceAddress;
if (actualHostgroup.getConstraint().getInstanceGroup() != null) {
InstanceMetaData next = actualHostgroup.getConstraint().getInstanceGroup().getInstanceMetaData().iterator().next();
serviceAddress = next.getPublicIpWrapper();
} else {
serviceAddress = actualHostgroup.getHostMetadata().iterator().next().getHostName();
}
for (JsonNode componentNode : componentsNode) {
String componentName = componentNode.get("name").asText();
StackServiceComponentDescriptor componentDescriptor = stackServiceComponentDescs.get(componentName);
collectServicePorts(result, ports, ambariIp, serviceAddress, componentDescriptor, cluster);
}
}
} catch (Exception ignored) {
return result;
}
return result;
}
use of com.sequenceiq.cloudbreak.domain.Blueprint in project cloudbreak by hortonworks.
the class BlueprintRequestToBlueprintConverter method convert.
public Blueprint convert(String name, String blueprintText, boolean publicInAccount) {
Blueprint blueprint = new Blueprint();
blueprint.setName(name);
blueprint.setBlueprintText(blueprintText);
blueprint.setPublicInAccount(publicInAccount);
validateBlueprint(blueprint.getBlueprintText());
try {
JsonNode root = JsonUtil.readTree(blueprint.getBlueprintText());
blueprint.setAmbariName(blueprintUtils.getBlueprintName(root));
blueprint.setHostGroupCount(blueprintUtils.countHostGroups(root));
} catch (IOException e) {
throw new BadRequestException("Invalid Blueprint: Failed to parse JSON.", e);
}
return blueprint;
}
use of com.sequenceiq.cloudbreak.domain.Blueprint in project cloudbreak by hortonworks.
the class BlueprintRequestToBlueprintConverter method convert.
@Override
public Blueprint convert(BlueprintRequest json) {
Blueprint blueprint = new Blueprint();
if (json.getUrl() != null && !json.getUrl().isEmpty()) {
String sourceUrl = json.getUrl().trim();
try {
String urlText = URLUtils.readUrl(sourceUrl);
jsonHelper.createJsonFromString(urlText);
blueprint.setBlueprintText(urlText);
} catch (Exception e) {
throw new BadRequestException("Cannot download ambari validation from: " + sourceUrl, e);
}
} else {
blueprint.setBlueprintText(json.getAmbariBlueprint());
}
validateBlueprint(blueprint.getBlueprintText());
if (Strings.isNullOrEmpty(json.getName())) {
blueprint.setName(missingResourceNameGenerator.generateName(APIResourceType.BLUEPRINT));
} else {
blueprint.setName(json.getName());
}
blueprint.setDescription(json.getDescription());
blueprint.setStatus(ResourceStatus.USER_MANAGED);
prepareBlueprintInputs(json, blueprint);
try {
JsonNode root = JsonUtil.readTree(blueprint.getBlueprintText());
blueprint.setAmbariName(blueprintUtils.getBlueprintName(root));
blueprint.setHostGroupCount(blueprintUtils.countHostGroups(root));
} catch (IOException e) {
throw new BadRequestException("Invalid Blueprint: Failed to parse JSON.", e);
}
return blueprint;
}
Aggregations