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