Search in sources :

Example 1 with CloudSecurityGroup

use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup 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);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) PlatformResourceSecurityGroupFilterView(com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceSecurityGroupFilterView) DescribeSecurityGroupsRequest(com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) Filter(com.amazonaws.services.ec2.model.Filter) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet)

Example 2 with CloudSecurityGroup

use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup in project cloudbreak by hortonworks.

the class CloudSecurityGroupsToPlatformSecurityGroupsResponseConverter method convert.

@Override
public PlatformSecurityGroupsResponse convert(CloudSecurityGroups source) {
    Map<String, Set<PlatformSecurityGroupResponse>> result = new HashMap<>();
    for (Entry<String, Set<CloudSecurityGroup>> entry : source.getCloudSecurityGroupsResponses().entrySet()) {
        Set<PlatformSecurityGroupResponse> securityGroupResponses = new HashSet<>();
        for (CloudSecurityGroup securityGroup : entry.getValue()) {
            PlatformSecurityGroupResponse actual = new PlatformSecurityGroupResponse(securityGroup.getGroupName(), securityGroup.getGroupId(), securityGroup.getProperties());
            securityGroupResponses.add(actual);
        }
        result.put(entry.getKey(), securityGroupResponses);
    }
    return new PlatformSecurityGroupsResponse(result);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) PlatformSecurityGroupsResponse(com.sequenceiq.cloudbreak.api.model.PlatformSecurityGroupsResponse) PlatformSecurityGroupResponse(com.sequenceiq.cloudbreak.api.model.PlatformSecurityGroupResponse) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet)

Example 3 with CloudSecurityGroup

use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup 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);
}
Also used : FirewallList(com.google.api.services.compute.model.FirewallList) Arrays(java.util.Arrays) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Cacheable(org.springframework.cache.annotation.Cacheable) HashMap(java.util.HashMap) Network(com.google.api.services.compute.model.Network) StringUtils(org.apache.commons.lang3.StringUtils) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Strings(com.google.common.base.Strings) NetworkList(com.google.api.services.compute.model.NetworkList) Firewall(com.google.api.services.compute.model.Firewall) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) Service(org.springframework.stereotype.Service) Map(java.util.Map) RegionList(com.google.api.services.compute.model.RegionList) GcpStackUtil(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil) VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) Subnetwork(com.google.api.services.compute.model.Subnetwork) PlatformResources(com.sequenceiq.cloudbreak.cloud.PlatformResources) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) IOException(java.io.IOException) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) MachineType(com.google.api.services.compute.model.MachineType) List(java.util.List) MachineTypeList(com.google.api.services.compute.model.MachineTypeList) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) FirewallList(com.google.api.services.compute.model.FirewallList) Collections(java.util.Collections) Compute(com.google.api.services.compute.Compute) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Firewall(com.google.api.services.compute.model.Firewall) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) Compute(com.google.api.services.compute.Compute) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet)

Example 4 with CloudSecurityGroup

use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup 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);
}
Also used : SecGroupExtension(org.openstack4j.model.compute.SecGroupExtension) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) KeystoneCredentialView(com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet)

Example 5 with CloudSecurityGroup

use of com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup in project cloudbreak by hortonworks.

the class AzurePlatformResources method securityGroups.

@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    AzureClient client = azureClientService.getClient(cloudCredential);
    Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
    for (NetworkSecurityGroup securityGroup : client.getSecurityGroups().list()) {
        String actualRegion = securityGroup.region().label();
        if (regionMatch(actualRegion, region)) {
            Map<String, Object> properties = new HashMap<>();
            properties.put("resourceGroupName", securityGroup.resourceGroupName());
            properties.put("networkInterfaceIds", securityGroup.networkInterfaceIds());
            CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(securityGroup.name(), securityGroup.id(), properties);
            result.computeIfAbsent(actualRegion, s -> new HashSet<>()).add(cloudSecurityGroup);
        }
    }
    if (result.isEmpty() && Objects.nonNull(region)) {
        result.put(region.value(), new HashSet<>());
    }
    return new CloudSecurityGroups(result);
}
Also used : VolumeParameterType.values(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.values) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Cacheable(org.springframework.cache.annotation.Cacheable) Subnet(com.microsoft.azure.management.network.Subnet) HashMap(java.util.HashMap) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Strings(com.google.common.base.Strings) Network(com.microsoft.azure.management.network.Network) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) Service(org.springframework.stereotype.Service) Map(java.util.Map) PlatformResources(com.sequenceiq.cloudbreak.cloud.PlatformResources) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) Objects(java.util.Objects) List(java.util.List) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) Entry(java.util.Map.Entry) AzureClientService(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClientService) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) MAGNETIC(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.MAGNETIC) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet)

Aggregations

CloudSecurityGroup (com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 CloudSecurityGroups (com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups)4 Strings (com.google.common.base.Strings)2 PlatformResources (com.sequenceiq.cloudbreak.cloud.PlatformResources)2 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)2 CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudGateWays (com.sequenceiq.cloudbreak.cloud.model.CloudGateWays)2 CloudIpPools (com.sequenceiq.cloudbreak.cloud.model.CloudIpPools)2 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)2 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)2 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)2 CloudSshKeys (com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys)2 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)2 Region (com.sequenceiq.cloudbreak.cloud.model.Region)2 Region.region (com.sequenceiq.cloudbreak.cloud.model.Region.region)2 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)2