Search in sources :

Example 91 with Filter

use of com.amazonaws.services.s3.model.Filter in project cloudbreak by hortonworks.

the class AwsPlatformResources method readRegionCoordinates.

private Map<Region, Coordinate> readRegionCoordinates(String displayNames) {
    Map<Region, Coordinate> regionCoordinates = new HashMap<>();
    try {
        RegionCoordinateSpecifications regionCoordinateSpecifications = JsonUtil.readValue(displayNames, RegionCoordinateSpecifications.class);
        for (RegionCoordinateSpecification regionCoordinateSpecification : regionCoordinateSpecifications.getItems()) {
            Region region = region(regionCoordinateSpecification.getName());
            if (!enabledRegions.contains(region)) {
                continue;
            }
            Optional<Entry<Region, DisplayName>> regionEntry = regionDisplayNames.entrySet().stream().filter(e -> e.getKey().getRegionName().equalsIgnoreCase(regionCoordinateSpecification.getName())).findFirst();
            regionCoordinates.put(region, coordinate(regionCoordinateSpecification.getLongitude(), regionCoordinateSpecification.getLatitude(), regionCoordinateSpecification.getDisplayName(), regionEntry.isPresent() ? regionEntry.get().getKey().value() : regionCoordinateSpecification.getDisplayName(), regionCoordinateSpecification.isK8sSupported(), regionCoordinateSpecification.getEntitlements()));
        }
    } catch (IOException ignored) {
        return regionCoordinates;
    }
    return regionCoordinates;
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) MinimalHardwareFilter(com.sequenceiq.cloudbreak.filter.MinimalHardwareFilter) Cacheable(org.springframework.cache.annotation.Cacheable) ListKeysRequest(com.amazonaws.services.kms.model.ListKeysRequest) InstanceProfile(com.amazonaws.services.identitymanagement.model.InstanceProfile) Collections.singletonList(java.util.Collections.singletonList) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) VmType.vmTypeWithMeta(com.sequenceiq.cloudbreak.cloud.model.VmType.vmTypeWithMeta) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) CloudAccessConfig(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig) ListTablesRequest(com.amazonaws.services.dynamodbv2.model.ListTablesRequest) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) AmazonIdentityManagementClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonIdentityManagementClient) CloudEncryptionKey(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey) CloudUnauthorizedException(com.sequenceiq.cloudbreak.cloud.exception.CloudUnauthorizedException) AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeInternetGatewaysResult(com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) Set(java.util.Set) RegionSpecification(com.sequenceiq.cloudbreak.cloud.model.RegionSpecification) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) RegionCoordinateSpecifications(com.sequenceiq.cloudbreak.cloud.model.RegionCoordinateSpecifications) PlatformResourceVpcFilterView(com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceVpcFilterView) CloudSshKey(com.sequenceiq.cloudbreak.cloud.model.CloudSshKey) DescribeRouteTablesRequest(com.amazonaws.services.ec2.model.DescribeRouteTablesRequest) CloudPrivateDnsZones(com.sequenceiq.cloudbreak.cloud.model.dns.CloudPrivateDnsZones) Coordinate.coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate.coordinate) Tag(com.amazonaws.services.ec2.model.Tag) MAGNETIC(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.MAGNETIC) ListInstanceProfilesRequest(com.amazonaws.services.identitymanagement.model.ListInstanceProfilesRequest) RegionsSpecification(com.sequenceiq.cloudbreak.cloud.model.RegionsSpecification) DescribeRegionsResult(com.amazonaws.services.ec2.model.DescribeRegionsResult) CloudbreakResourceReaderService(com.sequenceiq.cloudbreak.service.CloudbreakResourceReaderService) Region(com.sequenceiq.cloudbreak.cloud.model.Region) ListTablesResult(com.amazonaws.services.dynamodbv2.model.ListTablesResult) DescribeKeyPairsRequest(com.amazonaws.services.ec2.model.DescribeKeyPairsRequest) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) CloudParameterConst(com.sequenceiq.cloudbreak.cloud.CloudParameterConst) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Strings(com.google.common.base.Strings) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) AliasListEntry(com.amazonaws.services.kms.model.AliasListEntry) AmazonRdsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient) DescribeInstanceTypesRequest(com.amazonaws.services.ec2.model.DescribeInstanceTypesRequest) AmazonDynamoDBClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient) Service(org.springframework.stereotype.Service) ConfigSpecification(com.sequenceiq.cloudbreak.cloud.model.ConfigSpecification) PlatformResourceSecurityGroupFilterView(com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceSecurityGroupFilterView) DescribeSecurityGroupsRequest(com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest) Filter(com.amazonaws.services.ec2.model.Filter) RouteTable(com.amazonaws.services.ec2.model.RouteTable) PRIVATE(com.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PRIVATE) CloudConstants(com.sequenceiq.cloudbreak.common.type.CloudConstants) LinkedHashSet(java.util.LinkedHashSet) ST1(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.ST1) RegionCoordinateSpecification(com.sequenceiq.cloudbreak.cloud.model.RegionCoordinateSpecification) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) ListInstanceProfilesResult(com.amazonaws.services.identitymanagement.model.ListInstanceProfilesResult) Certificate(com.amazonaws.services.rds.model.Certificate) CloudNoSqlTable(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable) AwsPageCollector(com.sequenceiq.cloudbreak.cloud.aws.common.util.AwsPageCollector) IOException(java.io.IOException) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) SSD(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.SSD) InternetGateway(com.amazonaws.services.ec2.model.InternetGateway) AmazonKmsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonKmsClient) HttpStatus(org.springframework.http.HttpStatus) SdkClientException(com.amazonaws.SdkClientException) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) StringUtils.isNullOrEmpty(com.amazonaws.util.StringUtils.isNullOrEmpty) DescribeInternetGatewaysRequest(com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest) PermanentlyFailedException(com.sequenceiq.cloudbreak.util.PermanentlyFailedException) DisplayName.displayName(com.sequenceiq.cloudbreak.cloud.model.DisplayName.displayName) CloudDatabaseServerSslCertificate(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) ListRolesResult(com.amazonaws.services.identitymanagement.model.ListRolesResult) Role(com.amazonaws.services.identitymanagement.model.Role) LoggerFactory(org.slf4j.LoggerFactory) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) ListAliasesRequest(com.amazonaws.services.kms.model.ListAliasesRequest) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) InternetGatewayAttachment(com.amazonaws.services.ec2.model.InternetGatewayAttachment) DescribeKeyResult(com.amazonaws.services.kms.model.DescribeKeyResult) EPHEMERAL(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.EPHEMERAL) DescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest) InstanceStoreMetadata(com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata) DescribeRegionsRequest(com.amazonaws.services.ec2.model.DescribeRegionsRequest) Predicate(java.util.function.Predicate) Collection(java.util.Collection) CloudResourceGroups(com.sequenceiq.cloudbreak.cloud.model.resourcegroup.CloudResourceGroups) InstanceStorageInfo(com.amazonaws.services.ec2.model.InstanceStorageInfo) Collectors(java.util.stream.Collectors) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) CloudGateWay(com.sequenceiq.cloudbreak.cloud.model.CloudGateWay) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) Objects(java.util.Objects) List(java.util.List) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) DescribeCertificatesRequest(com.amazonaws.services.rds.model.DescribeCertificatesRequest) Coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate) CloudDatabaseServerSslCertificates(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificates) DescribeKeyRequest(com.amazonaws.services.kms.model.DescribeKeyRequest) KeyPairInfo(com.amazonaws.services.ec2.model.KeyPairInfo) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) HashMap(java.util.HashMap) ListKeysResult(com.amazonaws.services.kms.model.ListKeysResult) PlatformResourceSshKeyFilterView(com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceSshKeyFilterView) HashSet(java.util.HashSet) Inject(javax.inject.Inject) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) PUBLIC(com.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PUBLIC) DescribeInstanceTypesResult(com.amazonaws.services.ec2.model.DescribeInstanceTypesResult) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) Objects.requireNonNull(java.util.Objects.requireNonNull) ListRolesRequest(com.amazonaws.services.identitymanagement.model.ListRolesRequest) Subnet(com.amazonaws.services.ec2.model.Subnet) CloudDatabaseServerSslCertificateType(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificateType) LinkedList(java.util.LinkedList) DisplayName(com.sequenceiq.cloudbreak.cloud.model.DisplayName) Logger(org.slf4j.Logger) Vpc(com.amazonaws.services.ec2.model.Vpc) PlatformResources(com.sequenceiq.cloudbreak.cloud.PlatformResources) DiskInfo(com.amazonaws.services.ec2.model.DiskInfo) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) InstanceTypeInfo(com.amazonaws.services.ec2.model.InstanceTypeInfo) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) ListAliasesResult(com.amazonaws.services.kms.model.ListAliasesResult) DescribeInstanceTypeOfferingsRequest(com.amazonaws.services.ec2.model.DescribeInstanceTypeOfferingsRequest) VisibleForTesting(com.google.common.annotations.VisibleForTesting) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) AliasListEntry(com.amazonaws.services.kms.model.AliasListEntry) Entry(java.util.Map.Entry) RegionCoordinateSpecification(com.sequenceiq.cloudbreak.cloud.model.RegionCoordinateSpecification) Coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate) HashMap(java.util.HashMap) Region(com.sequenceiq.cloudbreak.cloud.model.Region) IOException(java.io.IOException) RegionCoordinateSpecifications(com.sequenceiq.cloudbreak.cloud.model.RegionCoordinateSpecifications)

Example 92 with Filter

use of com.amazonaws.services.s3.model.Filter in project nexus-public by sonatype.

the class AmazonS3Factory method create.

public AmazonS3 create(final BlobStoreConfiguration blobStoreConfiguration) {
    NexusS3ClientBuilder builder = NexusS3ClientBuilder.standard();
    NestedAttributesMap s3Configuration = blobStoreConfiguration.attributes(CONFIG_KEY);
    String accessKeyId = s3Configuration.get(ACCESS_KEY_ID_KEY, String.class);
    String secretAccessKey = s3Configuration.get(SECRET_ACCESS_KEY_KEY, String.class);
    String region = s3Configuration.get(REGION_KEY, String.class);
    String signerType = s3Configuration.get(SIGNERTYPE_KEY, String.class);
    String forcePathStyle = s3Configuration.get(FORCE_PATH_STYLE_KEY, String.class);
    int maximumConnectionPoolSize = Optional.ofNullable(s3Configuration.get(MAX_CONNECTION_POOL_KEY, String.class)).filter(Predicates.not(Strings2::isBlank)).map(Integer::valueOf).orElse(-1);
    AWSCredentialsProvider credentialsProvider = null;
    if (!isNullOrEmpty(accessKeyId) && !isNullOrEmpty(secretAccessKey)) {
        String sessionToken = s3Configuration.get(SESSION_TOKEN_KEY, String.class);
        AWSCredentials credentials = buildCredentials(accessKeyId, secretAccessKey, sessionToken);
        String assumeRole = s3Configuration.get(ASSUME_ROLE_KEY, String.class);
        credentialsProvider = buildCredentialsProvider(credentials, region, assumeRole);
        builder = builder.withCredentials(credentialsProvider);
    }
    if (!isNullOrEmptyOrDefault(region)) {
        String endpoint = s3Configuration.get(ENDPOINT_KEY, String.class);
        if (!isNullOrEmpty(endpoint)) {
            builder = builder.withEndpointConfiguration(new AmazonS3ClientBuilder.EndpointConfiguration(endpoint, region));
        } else {
            builder = builder.withRegion(region);
        }
    }
    ClientConfiguration clientConfiguration = PredefinedClientConfigurations.defaultConfig();
    if (defaultConnectionPoolSize > 0 || maximumConnectionPoolSize > 0) {
        clientConfiguration.setMaxConnections(maximumConnectionPoolSize > 0 ? maximumConnectionPoolSize : defaultConnectionPoolSize);
    }
    if (!isNullOrEmptyOrDefault(signerType)) {
        clientConfiguration.setSignerOverride(signerType);
    }
    if (connectionTtl != null) {
        clientConfiguration.setConnectionTTL(connectionTtl.toMillis());
    }
    builder = builder.withClientConfiguration(clientConfiguration);
    builder = builder.withPathStyleAccessEnabled(Boolean.parseBoolean(forcePathStyle));
    builder.withBlobStoreConfig(blobStoreConfiguration);
    if (cloudWatchMetricsEnabled) {
        if (credentialsProvider != null) {
            AwsSdkMetrics.setCredentialProvider(credentialsProvider);
        }
        AwsSdkMetrics.setMetricNameSpace(cloudWatchMetricsNamespace);
        if (!isNullOrEmptyOrDefault(region)) {
            AwsSdkMetrics.setRegion(region);
        }
        AwsSdkMetrics.enableDefaultMetrics();
        log.info("CloudWatch metrics enabled using namespace {}", cloudWatchMetricsNamespace);
    }
    return builder.build();
}
Also used : NexusS3ClientBuilder(com.amazonaws.services.s3.NexusS3ClientBuilder) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) NestedAttributesMap(org.sonatype.nexus.common.collect.NestedAttributesMap) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 93 with Filter

use of com.amazonaws.services.s3.model.Filter in project nexus-public by sonatype.

the class S3BlobStore method getBlobIdUpdatedSinceStream.

@Override
public Stream<BlobId> getBlobIdUpdatedSinceStream(final int sinceDays) {
    if (sinceDays < 0) {
        throw new IllegalArgumentException("sinceDays must >= 0");
    } else {
        Iterable<S3ObjectSummary> summaries = S3Objects.withPrefix(s3, getConfiguredBucket(), getContentPrefix());
        OffsetDateTime offsetDateTime = Instant.now().minus(sinceDays, ChronoUnit.DAYS).atOffset(ZoneOffset.UTC);
        return blobIdStream(stream(summaries.spliterator(), false).filter(s3objectSummary -> s3objectSummary.getLastModified().toInstant().atOffset(ZoneOffset.UTC).isAfter(offsetDateTime)));
    }
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) BlobAttributes(org.sonatype.nexus.blobstore.api.BlobAttributes) BlobStore(org.sonatype.nexus.blobstore.api.BlobStore) FAILED(org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.State.FAILED) DryRunPrefix(org.sonatype.nexus.common.log.DryRunPrefix) DOWNLOAD(org.sonatype.nexus.blobstore.api.OperationType.DOWNLOAD) BlobStoreException(org.sonatype.nexus.blobstore.api.BlobStoreException) BlobIdLocationResolver(org.sonatype.nexus.blobstore.BlobIdLocationResolver) Collections.singletonList(java.util.Collections.singletonList) Guarded(org.sonatype.nexus.common.stateguard.Guarded) Future(java.util.concurrent.Future) MetricsInputStream(org.sonatype.nexus.blobstore.MetricsInputStream) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) NEW(org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.State.NEW) BlobStoreConfiguration(org.sonatype.nexus.blobstore.api.BlobStoreConfiguration) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) BlobId(org.sonatype.nexus.blobstore.api.BlobId) Map(java.util.Map) BlobMetrics(org.sonatype.nexus.blobstore.api.BlobMetrics) ZoneOffset(java.time.ZoneOffset) Path(java.nio.file.Path) S3BlobStoreException.buildException(org.sonatype.nexus.blobstore.s3.internal.S3BlobStoreException.buildException) RawObjectAccess(org.sonatype.nexus.blobstore.api.RawObjectAccess) DIRECT_PATH_ROOT(org.sonatype.nexus.blobstore.DirectPathLocationStrategy.DIRECT_PATH_ROOT) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.emptyList(java.util.Collections.emptyList) UPLOAD(org.sonatype.nexus.blobstore.api.OperationType.UPLOAD) SharedMetricRegistries(com.codahale.metrics.SharedMetricRegistries) S3BlobStoreConfigurationHelper.getConfiguredExpirationInDays(org.sonatype.nexus.blobstore.s3.internal.S3BlobStoreConfigurationHelper.getConfiguredExpirationInDays) Instant(java.time.Instant) BlobStoreQuotaUsageChecker(org.sonatype.nexus.blobstore.quota.BlobStoreQuotaUsageChecker) String.format(java.lang.String.format) SetObjectTaggingRequest(com.amazonaws.services.s3.model.SetObjectTaggingRequest) Preconditions.checkState(com.google.common.base.Preconditions.checkState) CloudBlobStoreSupport(org.sonatype.nexus.blobstore.CloudBlobStoreSupport) Timed(com.codahale.metrics.annotation.Timed) OffsetDateTime(java.time.OffsetDateTime) Stream(java.util.stream.Stream) STARTED(org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.State.STARTED) StreamSupport.stream(java.util.stream.StreamSupport.stream) NexusThreadFactory(org.sonatype.nexus.thread.NexusThreadFactory) Timer(com.codahale.metrics.Timer) CacheBuilder(com.google.common.cache.CacheBuilder) STOPPED(org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.State.STOPPED) SHUTDOWN(org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.State.SHUTDOWN) StreamMetrics(org.sonatype.nexus.blobstore.StreamMetrics) CacheLoader.from(com.google.common.cache.CacheLoader.from) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) CompletableFuture(java.util.concurrent.CompletableFuture) SdkBaseException(com.amazonaws.SdkBaseException) Blob(org.sonatype.nexus.blobstore.api.Blob) Inject(javax.inject.Inject) S3Object(com.amazonaws.services.s3.model.S3Object) DeleteObjectsRequest(com.amazonaws.services.s3.model.DeleteObjectsRequest) OperationType(org.sonatype.nexus.blobstore.api.OperationType) AmazonS3(com.amazonaws.services.s3.AmazonS3) Named(javax.inject.Named) ObjectTagging(com.amazonaws.services.s3.model.ObjectTagging) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) MonitoringBlobStoreMetrics(org.sonatype.nexus.blobstore.metrics.MonitoringBlobStoreMetrics) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) MetricRegistry(com.codahale.metrics.MetricRegistry) HashCode(com.google.common.hash.HashCode) DateTime(org.joda.time.DateTime) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) Tag(com.amazonaws.services.s3.model.Tag) OperationMetrics(org.sonatype.nexus.blobstore.api.OperationMetrics) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) Lock(java.util.concurrent.locks.Lock) ChronoUnit(java.time.temporal.ChronoUnit) BlobSupport(org.sonatype.nexus.blobstore.BlobSupport) BlobStoreMetrics(org.sonatype.nexus.blobstore.api.BlobStoreMetrics) VisibleForTesting(com.google.common.annotations.VisibleForTesting) S3Objects(com.amazonaws.services.s3.iterable.S3Objects) InputStream(java.io.InputStream) OffsetDateTime(java.time.OffsetDateTime) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 94 with Filter

use of com.amazonaws.services.s3.model.Filter in project bff-marvel-api by thomasdacosta.

the class S3UtilTest method testCreateFile.

@Test
@Order(1)
@DisplayName("1 - Criando arquivos em um Bucket S3")
public void testCreateFile() {
    String[] listFiles = new String[4];
    listFiles[0] = "file1.txt";
    listFiles[1] = "file2.txt";
    listFiles[2] = "file3.txt";
    listFiles[3] = "file4.txt";
    S3Util.setEndpointConfiguration(LocalStackUtil.getLocalstack().getEndpointConfiguration(LocalStackContainer.Service.S3));
    AmazonS3 amazonS3 = S3Util.getS3(S3Util.Env.LOCALSTACK);
    Objects.requireNonNull(amazonS3).createBucket(Constants.BUCKET);
    amazonS3.putObject(Constants.BUCKET, listFiles[0], "file1");
    amazonS3.putObject(Constants.BUCKET, listFiles[1], "file2");
    amazonS3.putObject(Constants.BUCKET, listFiles[2], "file3");
    amazonS3.putObject(Constants.BUCKET, listFiles[3], "file4");
    ObjectListing files = amazonS3.listObjects(Constants.BUCKET);
    assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals(listFiles[0])).count());
    assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals(listFiles[1])).count());
    assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals(listFiles[2])).count());
    assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals(listFiles[3])).count());
    S3Util.setAmazonS3(null);
    assertNotNull(S3Util.getS3(S3Util.Env.AWS));
    assertNotNull(S3Util.getS3(S3Util.Env.AWS));
    S3Util.setAmazonS3(null);
    Assertions.assertNull(S3Util.getS3(null));
    S3Util.setAmazonS3(null);
    S3Util.setEndpointConfiguration(null);
    assertNotNull(S3Util.getS3(S3Util.Env.LOCALSTACK));
    assertNotNull(S3Util.getS3(S3Util.Env.LOCALSTACK));
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ObjectListing(com.amazonaws.services.s3.model.ObjectListing)

Example 95 with Filter

use of com.amazonaws.services.s3.model.Filter in project bff-marvel-api by thomasdacosta.

the class ImageUtilTest method testCreateImage.

@Test
@Order(1)
@DisplayName("1 - Criando as imagens em um Bucket S3")
public void testCreateImage() throws URISyntaxException, IOException {
    S3Util.setAmazonS3(null);
    S3Util.setEndpointConfiguration(null);
    WireMockUtils.serverImage();
    S3Util.setEndpointConfiguration(LocalStackUtil.getLocalstack().getEndpointConfiguration(LocalStackContainer.Service.S3));
    AmazonS3 amazonS3 = S3Util.getS3(S3Util.Env.LOCALSTACK);
    Objects.requireNonNull(amazonS3).createBucket(Constants.BUCKET);
    ThumbnailCharacter thumbnailCharacter = new ThumbnailCharacter();
    thumbnailCharacter.setUrl("http://localhost:8082/imageMarvel");
    thumbnailCharacter.setExtension("jpg");
    MarvelCharacter marvelCharacter = new MarvelCharacter();
    marvelCharacter.setId(new BigDecimal(1011355));
    marvelCharacter.setName("Captain Midlands");
    ImageUtil.saveImage(thumbnailCharacter, marvelCharacter);
    ObjectListing files = amazonS3.listObjects(Constants.BUCKET);
    assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals("captain_midlands_1011355_portrait_uncanny.jpg")).count());
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) ThumbnailCharacter(br.com.thomasdacosta.handler.dto.ThumbnailCharacter) MarvelCharacter(br.com.thomasdacosta.handler.dto.MarvelCharacter) BigDecimal(java.math.BigDecimal) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest)

Aggregations

Filter (com.amazonaws.services.ec2.model.Filter)96 ArrayList (java.util.ArrayList)70 List (java.util.List)52 Collectors (java.util.stream.Collectors)46 IOException (java.io.IOException)41 HashMap (java.util.HashMap)38 Map (java.util.Map)35 AmazonS3 (com.amazonaws.services.s3.AmazonS3)34 Set (java.util.Set)31 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)30 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)27 Instance (com.amazonaws.services.ec2.model.Instance)26 HashSet (java.util.HashSet)26 Reservation (com.amazonaws.services.ec2.model.Reservation)24 Collections (java.util.Collections)23 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)21 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)21 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)20 Entry (java.util.Map.Entry)20 Tag (com.amazonaws.services.ec2.model.Tag)18