Search in sources :

Example 1 with SHARED_PROJECT_ID

use of com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.SHARED_PROJECT_ID in project cloudbreak by hortonworks.

the class GcpPlatformResources method securityGroups.

@Override
public CloudSecurityGroups securityGroups(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters) throws IOException {
    Compute compute = gcpComputeFactory.buildCompute(cloudCredential);
    String projectId = gcpStackUtil.getProjectId(cloudCredential);
    Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
    FirewallList firewallList = compute.firewalls().list(projectId).execute();
    if (firewallList.getItems() != null) {
        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);
        }
    }
    if (filters != null) {
        String sharedProjectId = filters.get(SHARED_PROJECT_ID);
        if (!Strings.isNullOrEmpty(sharedProjectId)) {
            try {
                FirewallList sharedProjectFirewalls = compute.firewalls().list(sharedProjectId).execute();
                if (sharedProjectFirewalls.getItems() != null) {
                    for (Firewall firewall : sharedProjectFirewalls.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);
                    }
                }
            } catch (Exception ex) {
                LOGGER.warn(String.format("We can not read the host project with id %s", sharedProjectId));
            }
        }
    }
    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) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) MinimalHardwareFilter(com.sequenceiq.cloudbreak.filter.MinimalHardwareFilter) Cacheable(org.springframework.cache.annotation.Cacheable) LoggerFactory(org.slf4j.LoggerFactory) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Network(com.google.api.services.compute.model.Network) StringUtils(org.apache.commons.lang3.StringUtils) Matcher(java.util.regex.Matcher) CloudAccessConfig(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) GcpComputeFactory(com.sequenceiq.cloudbreak.cloud.gcp.client.GcpComputeFactory) Map(java.util.Map) RegionList(com.google.api.services.compute.model.RegionList) CloudEncryptionKey(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey) GcpStackUtil(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil) VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) Predicate(java.util.function.Predicate) ListCryptoKeysResponse(com.google.api.services.cloudkms.v1.model.ListCryptoKeysResponse) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) CloudResourceGroups(com.sequenceiq.cloudbreak.cloud.model.resourcegroup.CloudResourceGroups) Set(java.util.Set) CryptoKey(com.google.api.services.cloudkms.v1.model.CryptoKey) Collectors(java.util.stream.Collectors) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) RegionCoordinateSpecifications(com.sequenceiq.cloudbreak.cloud.model.RegionCoordinateSpecifications) List(java.util.List) MachineTypeList(com.google.api.services.compute.model.MachineTypeList) CloudKMS(com.google.api.services.cloudkms.v1.CloudKMS) SubnetworkList(com.google.api.services.compute.model.SubnetworkList) CloudPrivateDnsZones(com.sequenceiq.cloudbreak.cloud.model.dns.CloudPrivateDnsZones) Coordinate.coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate.coordinate) GcpCloudKMSFactory(com.sequenceiq.cloudbreak.cloud.gcp.client.GcpCloudKMSFactory) PostConstruct(javax.annotation.PostConstruct) FirewallList(com.google.api.services.compute.model.FirewallList) Optional(java.util.Optional) Coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate) Pattern(java.util.regex.Pattern) Compute(com.google.api.services.compute.Compute) ListKeyRingsResponse(com.google.api.services.cloudkms.v1.model.ListKeyRingsResponse) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) CloudbreakResourceReaderService(com.sequenceiq.cloudbreak.service.CloudbreakResourceReaderService) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Region(com.sequenceiq.cloudbreak.cloud.model.Region) HashMap(java.util.HashMap) Function(java.util.function.Function) 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) PUBLIC(com.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PUBLIC) NetworkList(com.google.api.services.compute.model.NetworkList) Firewall(com.google.api.services.compute.model.Firewall) Service(org.springframework.stereotype.Service) GcpIamFactory(com.sequenceiq.cloudbreak.cloud.gcp.client.GcpIamFactory) KeyRing(com.google.api.services.cloudkms.v1.model.KeyRing) PRIVATE(com.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PRIVATE) RegionCoordinateSpecification(com.sequenceiq.cloudbreak.cloud.model.RegionCoordinateSpecification) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) ListServiceAccountsResponse(com.google.api.services.iam.v1.model.ListServiceAccountsResponse) 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) IOException(java.io.IOException) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) MachineType(com.google.api.services.compute.model.MachineType) TokenResponseException(com.google.api.client.auth.oauth2.TokenResponseException) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) Iam(com.google.api.services.iam.v1.Iam) Collections(java.util.Collections) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) SHARED_PROJECT_ID(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.SHARED_PROJECT_ID) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) IOException(java.io.IOException) TokenResponseException(com.google.api.client.auth.oauth2.TokenResponseException) 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)

Aggregations

TokenResponseException (com.google.api.client.auth.oauth2.TokenResponseException)1 CloudKMS (com.google.api.services.cloudkms.v1.CloudKMS)1 CryptoKey (com.google.api.services.cloudkms.v1.model.CryptoKey)1 KeyRing (com.google.api.services.cloudkms.v1.model.KeyRing)1 ListCryptoKeysResponse (com.google.api.services.cloudkms.v1.model.ListCryptoKeysResponse)1 ListKeyRingsResponse (com.google.api.services.cloudkms.v1.model.ListKeyRingsResponse)1 Compute (com.google.api.services.compute.Compute)1 Firewall (com.google.api.services.compute.model.Firewall)1 FirewallList (com.google.api.services.compute.model.FirewallList)1 MachineType (com.google.api.services.compute.model.MachineType)1 MachineTypeList (com.google.api.services.compute.model.MachineTypeList)1 Network (com.google.api.services.compute.model.Network)1 NetworkList (com.google.api.services.compute.model.NetworkList)1 RegionList (com.google.api.services.compute.model.RegionList)1 Subnetwork (com.google.api.services.compute.model.Subnetwork)1 SubnetworkList (com.google.api.services.compute.model.SubnetworkList)1 Iam (com.google.api.services.iam.v1.Iam)1 ListServiceAccountsResponse (com.google.api.services.iam.v1.model.ListServiceAccountsResponse)1 Strings (com.google.common.base.Strings)1 PlatformResources (com.sequenceiq.cloudbreak.cloud.PlatformResources)1