use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups in project cloudbreak by hortonworks.
the class AwsPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>();
AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), region.value());
// create securitygroup filter view
PlatformResourceSecurityGroupFilterView filter = new PlatformResourceSecurityGroupFilterView(filters);
DescribeSecurityGroupsRequest describeSecurityGroupsRequest = new DescribeSecurityGroupsRequest();
// If the filtervalue is provided then we should filter only for those securitygroups
if (!Strings.isNullOrEmpty(filter.getVpcId())) {
describeSecurityGroupsRequest.withFilters(new Filter("vpc-id", singletonList(filter.getVpcId())));
}
if (!Strings.isNullOrEmpty(filter.getGroupId())) {
describeSecurityGroupsRequest.withGroupIds(filter.getGroupId());
}
if (!Strings.isNullOrEmpty(filter.getGroupName())) {
describeSecurityGroupsRequest.withGroupNames(filter.getGroupName());
}
for (SecurityGroup securityGroup : ec2Client.describeSecurityGroups(describeSecurityGroupsRequest).getSecurityGroups()) {
Map<String, Object> properties = new HashMap<>();
properties.put("vpcId", securityGroup.getVpcId());
properties.put("description", securityGroup.getDescription());
properties.put("ipPermissions", securityGroup.getIpPermissions());
properties.put("ipPermissionsEgress", securityGroup.getIpPermissionsEgress());
cloudSecurityGroups.add(new CloudSecurityGroup(securityGroup.getGroupName(), securityGroup.getGroupId(), properties));
}
result.put(region.value(), cloudSecurityGroups);
return new CloudSecurityGroups(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups in project cloudbreak by hortonworks.
the class GetPlatformSecurityGroupsHandler method accept.
@Override
public void accept(Event<GetPlatformSecurityGroupsRequest> getPlatformSecurityGroupsRequest) {
LOGGER.info("Received event: {}", getPlatformSecurityGroupsRequest);
GetPlatformSecurityGroupsRequest request = getPlatformSecurityGroupsRequest.getData();
try {
CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant(Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant()));
CloudSecurityGroups securityGroups = cloudPlatformConnectors.get(cloudPlatformVariant).platformResources().securityGroups(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters());
GetPlatformSecurityGroupsResult getPlatformSecurityGroupsResult = new GetPlatformSecurityGroupsResult(request, securityGroups);
request.getResult().onNext(getPlatformSecurityGroupsResult);
LOGGER.info("Query platform networks types finished.");
} catch (Exception e) {
request.getResult().onNext(new GetPlatformSecurityGroupsResult(e.getMessage(), e, request));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups in project cloudbreak by hortonworks.
the class PlatformParameterV1Controller method getSecurityGroups.
@Override
public PlatformSecurityGroupsResponse getSecurityGroups(PlatformResourceRequestJson resourceRequestJson) {
resourceRequestJson = prepareAccountAndOwner(resourceRequestJson, authenticatedUserService.getCbUser());
PlatformResourceRequest convert = conversionService.convert(resourceRequestJson, PlatformResourceRequest.class);
CloudSecurityGroups securityGroups = cloudParameterService.getSecurityGroups(convert.getCredential(), convert.getRegion(), convert.getPlatformVariant(), convert.getFilters());
return conversionService.convert(securityGroups, PlatformSecurityGroupsResponse.class);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups in project cloudbreak by hortonworks.
the class GcpPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws IOException {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
if (compute != null) {
FirewallList firewallList = compute.firewalls().list(projectId).execute();
for (Firewall firewall : firewallList.getItems()) {
Map<String, Object> properties = new HashMap<>();
properties.put("network", getNetworkName(firewall));
CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(firewall.getName(), firewall.getName(), properties);
result.computeIfAbsent(region.value(), k -> new HashSet<>()).add(cloudSecurityGroup);
}
}
return new CloudSecurityGroups(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups in project cloudbreak by hortonworks.
the class OpenStackPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);
Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>();
List<? extends SecGroupExtension> osSecurityGroups = osClient.compute().securityGroups().list();
LOGGER.info("security groups from openstack: {}", osSecurityGroups);
for (SecGroupExtension secGroup : osSecurityGroups) {
Map<String, Object> properties = new HashMap<>();
properties.put("tenantId", secGroup.getTenantId());
properties.put("rules", secGroup.getRules());
CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(secGroup.getName(), secGroup.getId(), properties);
cloudSecurityGroups.add(cloudSecurityGroup);
}
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudSecurityGroups);
LOGGER.info("openstack security groups result: {}", result);
return new CloudSecurityGroups(result);
}
Aggregations