use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackValidationRequestToStackValidationConverter method convert.
@Override
public StackValidation convert(StackValidationRequest stackValidationRequest) {
StackValidation stackValidation = new StackValidation();
Set<InstanceGroup> instanceGroups = convertInstanceGroups(stackValidationRequest.getInstanceGroups());
stackValidation.setInstanceGroups(instanceGroups);
stackValidation.setHostGroups(convertHostGroupsFromJson(instanceGroups, stackValidationRequest.getHostGroups()));
try {
validateBlueprint(stackValidationRequest, stackValidation);
} catch (AccessDeniedException e) {
throw new AccessDeniedException(String.format("Access to validation '%s' is denied or validation doesn't exist.", stackValidationRequest.getBlueprintId()), e);
}
try {
validateCredential(stackValidationRequest, stackValidation);
} catch (AccessDeniedException e) {
throw new AccessDeniedException(String.format("Access to credential '%s' is denied or credential doesn't exist.", stackValidationRequest.getCredentialId()), e);
}
try {
validateNetwork(stackValidationRequest.getNetworkId(), stackValidationRequest.getNetwork(), stackValidation);
} catch (AccessDeniedException e) {
throw new AccessDeniedException(String.format("Access to network '%s' is denied or network doesn't exist.", stackValidationRequest.getNetworkId()), e);
}
return stackValidation;
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceGroupRequestToInstanceGroupConverter method convert.
@Override
public InstanceGroup convert(InstanceGroupRequest json) {
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setGroupName(json.getGroup());
instanceGroup.setNodeCount(json.getNodeCount());
instanceGroup.setInstanceGroupType(json.getType());
try {
if (json.getSecurityGroupId() != null) {
instanceGroup.setSecurityGroup(securityGroupService.get(json.getSecurityGroupId()));
}
} catch (AccessDeniedException e) {
throw new AccessDeniedException(String.format("Access to securitygroup '%s' is denied or securitygroup doesn't exist.", json.getSecurityGroupId()), e);
}
try {
if (json.getTemplateId() != null) {
instanceGroup.setTemplate(templateService.get(json.getTemplateId()));
}
} catch (AccessDeniedException e) {
throw new AccessDeniedException(String.format("Access to template '%s' is denied or template doesn't exist.", json.getTemplateId()), e);
}
if (json.getTemplate() != null) {
Template template = getConversionService().convert(json.getTemplate(), Template.class);
instanceGroup.setTemplate(template);
}
if (json.getSecurityGroup() != null) {
instanceGroup.setSecurityGroup(getConversionService().convert(json.getSecurityGroup(), SecurityGroup.class));
}
try {
Json jsonProperties = new Json(json.getParameters());
instanceGroup.setAttributes(jsonProperties);
} catch (JsonProcessingException ignored) {
instanceGroup.setAttributes(null);
}
return instanceGroup;
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class HostGroupDecorator method decorateConstraint.
private Constraint decorateConstraint(Long stackId, IdentityUser user, Constraint constraint, String instanceGroupName, String constraintTemplateName) {
if (instanceGroupName != null) {
InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(stackId, instanceGroupName);
if (instanceGroup == null) {
LOGGER.error("Instance group not found: {}", instanceGroupName);
throw new BadRequestException(String.format("Instance group '%s' not found on stack.", instanceGroupName));
}
constraint.setInstanceGroup(instanceGroup);
}
if (constraintTemplateName != null) {
ConstraintTemplate constraintTemplate = constraintTemplateRepository.findByNameInAccount(constraintTemplateName, user.getAccount(), user.getUserId());
if (constraintTemplate == null) {
throw new BadRequestException(String.format("Couldn't find constraint template with name: %s", constraintTemplateName));
}
constraint.setConstraintTemplate(constraintTemplate);
}
return constraint;
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackDecorator method prepareInstanceGroups.
private void prepareInstanceGroups(Stack subject, StackRequest request, Credential credential, IdentityUser user) {
Map<String, InstanceGroupParameterResponse> instanceGroupParameterResponse = cloudParameterService.getInstanceGroupParameters(credential, getInstanceGroupParameterRequests(subject));
for (InstanceGroup instanceGroup : subject.getInstanceGroups()) {
updateInstanceGroupParameters(instanceGroupParameterResponse, instanceGroup);
if (instanceGroup.getTemplate() != null) {
Template template = instanceGroup.getTemplate();
if (template.getId() == null) {
template.setPublicInAccount(subject.isPublicInAccount());
template.setCloudPlatform(getCloudPlatform(subject, request, template.cloudPlatform()));
templateValidator.validateTemplateRequest(credential, instanceGroup.getTemplate(), request.getRegion(), request.getAvailabilityZone(), request.getPlatformVariant());
template = templateDecorator.decorate(credential, template, request.getRegion(), request.getAvailabilityZone(), request.getPlatformVariant());
template = templateService.create(user, template);
}
instanceGroup.setTemplate(template);
}
if (instanceGroup.getSecurityGroup() != null) {
SecurityGroup securityGroup = instanceGroup.getSecurityGroup();
if (securityGroup.getId() == null) {
securityGroup.setPublicInAccount(subject.isPublicInAccount());
securityGroup.setCloudPlatform(getCloudPlatform(subject, request, securityGroup.getCloudPlatform()));
securityGroup = securityGroupService.create(user, securityGroup);
instanceGroup.setSecurityGroup(securityGroup);
}
}
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackDecorator method getInstanceGroupParameterRequests.
private Set<InstanceGroupParameterRequest> getInstanceGroupParameterRequests(Stack subject) {
Set<InstanceGroupParameterRequest> instanceGroupParameterRequests = new HashSet<>();
for (InstanceGroup instanceGroup : subject.getInstanceGroups()) {
InstanceGroupParameterRequest convert = conversionService.convert(instanceGroup, InstanceGroupParameterRequest.class);
convert.setStackName(subject.getName());
instanceGroupParameterRequests.add(convert);
}
return instanceGroupParameterRequests;
}
Aggregations