Search in sources :

Example 11 with SecurityGroup

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

the class SecurityGroupService method delete.

public void delete(String name, IdentityUser user) {
    LOGGER.info("Deleting SecurityGroup with name: {}", name);
    SecurityGroup securityGroup = groupRepository.findByNameInAccount(name, user.getAccount());
    if (securityGroup == null) {
        throw new NotFoundException(String.format("SecurityGroup '%s' not found.", name));
    }
    delete(securityGroup);
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup)

Example 12 with SecurityGroup

use of com.sequenceiq.cloudbreak.domain.SecurityGroup 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 13 with SecurityGroup

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

the class SecurityGroupRequestToSecurityGroupConverter method convert.

@Override
public SecurityGroup convert(SecurityGroupRequest source) {
    SecurityGroup entity = new SecurityGroup();
    if (Strings.isNullOrEmpty(source.getName())) {
        entity.setName(missingResourceNameGenerator.generateName(APIResourceType.SECURITY_GROUP));
    } else {
        entity.setName(source.getName());
    }
    entity.setDescription(source.getDescription());
    entity.setStatus(ResourceStatus.USER_MANAGED);
    entity.setSecurityGroupId(source.getSecurityGroupId());
    entity.setSecurityRules(convertSecurityRules(source.getSecurityRules(), entity));
    entity.setCloudPlatform(source.getCloudPlatform());
    return entity;
}
Also used : SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup)

Example 14 with SecurityGroup

use of com.sequenceiq.cloudbreak.domain.SecurityGroup 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 15 with SecurityGroup

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

the class TestUtil method securityGroup.

public static SecurityGroup securityGroup(Set<SecurityRule> securityRules) {
    SecurityGroup securityGroup = new SecurityGroup();
    securityGroup.setPublicInAccount(true);
    securityGroup.setDescription(DUMMY_DESCRIPTION);
    securityGroup.setId(1L);
    securityGroup.setName(DUMMY_NAME);
    securityGroup.setStatus(ResourceStatus.DEFAULT);
    securityGroup.setSecurityRules(securityRules);
    securityGroup.setSecurityGroupId(DUMMY_SECURITY_GROUP_ID);
    securityGroup.setCloudPlatform(AWS);
    return securityGroup;
}
Also used : SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup)

Aggregations

SecurityGroup (com.sequenceiq.cloudbreak.domain.SecurityGroup)16 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)4 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)2 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)2 SecurityRule (com.sequenceiq.cloudbreak.domain.SecurityRule)2 Template (com.sequenceiq.cloudbreak.domain.Template)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 InstanceGroupParameterResponse (com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterResponse)1 Json (com.sequenceiq.cloudbreak.domain.json.Json)1 Test (org.junit.Test)1 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1