Search in sources :

Example 76 with InstanceGroup

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;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) StackValidation(com.sequenceiq.cloudbreak.domain.StackValidation) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 77 with InstanceGroup

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;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Json(com.sequenceiq.cloudbreak.domain.json.Json) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 78 with 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;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) ConstraintTemplate(com.sequenceiq.cloudbreak.domain.ConstraintTemplate) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 79 with InstanceGroup

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);
            }
        }
    }
}
Also used : InstanceGroupParameterResponse(com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterResponse) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 80 with InstanceGroup

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;
}
Also used : InstanceGroupParameterRequest(com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterRequest) HashSet(java.util.HashSet) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Aggregations

InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)89 Test (org.junit.Test)32 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)27 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)27 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)24 HashSet (java.util.HashSet)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Stack (com.sequenceiq.cloudbreak.domain.Stack)14 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)9 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)8 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)8 Matchers.anyString (org.mockito.Matchers.anyString)8 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)6 StackAuthentication (com.sequenceiq.cloudbreak.domain.StackAuthentication)6 Template (com.sequenceiq.cloudbreak.domain.Template)6 ArrayList (java.util.ArrayList)6 InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)5 StackAuthenticationRequest (com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest)5 FailurePolicy (com.sequenceiq.cloudbreak.domain.FailurePolicy)5