com.amazonaws.SDKGlobalConfiguration Java Examples

The following examples show how to use com.amazonaws.SDKGlobalConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudStreamKinesisToWebfluxApplicationTests.java    From spring-cloud-stream-samples with Apache License 2.0 6 votes vote down vote up
@Bean
public AmazonKinesisAsync amazonKinesis() {
	// See https://github.com/mhart/kinesalite#cbor-protocol-issues-with-the-java-sdk
	System.setProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true");

	return AmazonKinesisAsyncClientBuilder.standard()
			.withClientConfiguration(
					new ClientConfiguration()
							.withMaxErrorRetry(0)
							.withConnectionTimeout(1000))
			.withEndpointConfiguration(
					new AwsClientBuilder.EndpointConfiguration("http://localhost:" + DEFAULT_KINESALITE_PORT,
							Regions.DEFAULT_REGION.getName()))
			.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("", "")))
			.build();
}
 
Example #2
Source File: ImportResourceIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public Entity payloadBuilder() {

        String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR );
        String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR );

        Entity storage_info = new Entity();
        storage_info.put("s3_key", secretKey);
        storage_info.put("s3_access_id", accessId);
        storage_info.put("bucket_location", bucketName) ;

        Entity properties = new Entity();
        properties.put("storage_provider", "s3");
        properties.put("storage_info", storage_info);

        Entity payload = new Entity();
        payload.put("properties", properties);

        return payload;
    }
 
Example #3
Source File: ImportResourceIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/**
 * Delete the configured s3 bucket.
 */
public void deleteBucket() {

    logger.debug("\n\nDelete bucket\n");

    String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR );
    String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR );

    Properties overrides = new Properties();
    overrides.setProperty("s3" + ".identity", accessId);
    overrides.setProperty("s3" + ".credential", secretKey);

    final Iterable<? extends Module> MODULES = ImmutableSet.of(new JavaUrlHttpCommandExecutorServiceModule(),
        new Log4JLoggingModule(), new NettyPayloadModule());

    BlobStoreContext context =
        ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES)
            .overrides(overrides ).buildView(BlobStoreContext.class);

    BlobStore blobStore = context.getBlobStore();
    blobStore.deleteContainer(bucketName);
}
 
Example #4
Source File: ImportResourceIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Before
    public void before() {
        configured =
                   !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ))
                && !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ))
                && !StringUtils.isEmpty(System.getProperty("bucketName"));


        if (!configured) {
            logger.warn("Skipping test because {}, {} and bucketName not " +
                    "specified as system properties, e.g. in your Maven settings.xml file.",
                new Object[]{
                    "s3_key",
                    "s3_access_id"
                });
        }

//        if (!StringUtils.isEmpty(bucketPrefix)) {
//            deleteBucketsWithPrefix();
//        }

        bucketName = bucketPrefix + RandomStringUtils.randomAlphanumeric(10).toLowerCase();
    }
 
Example #5
Source File: ExportServiceIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public HashMap<String, Object> payloadBuilder( String orgOrAppName ) {
    HashMap<String, Object> payload = new HashMap<String, Object>();
    Map<String, Object> properties = new HashMap<String, Object>();
    Map<String, Object> storage_info = new HashMap<String, Object>();
    storage_info.put( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR,
        System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ) );
    storage_info.put( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR,
        System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ) );
    storage_info.put( "bucket_location",  bucketName );

    properties.put( "storage_provider", "s3" );
    properties.put( "storage_info", storage_info );

    payload.put( "path", orgOrAppName );
    payload.put( "properties", properties );
    return payload;
}
 
Example #6
Source File: ExportServiceIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Before
public void before() {

    boolean configured =
        !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR))
            && !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR))
            && !StringUtils.isEmpty(System.getProperty("bucketName"));

    if ( !configured ) {
        logger.warn("Skipping test because {}, {} and bucketName not " +
                "specified as system properties, e.g. in your Maven settings.xml file.",
            new Object[] {
                SDKGlobalConfiguration.SECRET_KEY_ENV_VAR,
                SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR
            });
    }

    Assume.assumeTrue( configured );

    adminUser = newOrgAppAdminRule.getAdminInfo();
    organization = newOrgAppAdminRule.getOrganizationInfo();
    applicationId = newOrgAppAdminRule.getApplicationInfo().getId();

    bucketPrefix = System.getProperty( "bucketName" );
    bucketName = bucketPrefix + RandomStringUtils.randomAlphanumeric(10).toLowerCase();
}
 
Example #7
Source File: ImportServiceIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public void deleteBucket() {

        String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR );
        String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR );

        Properties overrides = new Properties();
        overrides.setProperty( "s3" + ".identity", accessId );
        overrides.setProperty( "s3" + ".credential", secretKey );

        Blob bo = null;
        BlobStore blobStore = null;
        final Iterable<? extends Module> MODULES = ImmutableSet
                .of(new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(),
                        new NettyPayloadModule());

        BlobStoreContext context =
                ContextBuilder.newBuilder("s3").credentials( accessId, secretKey ).modules( MODULES )
                        .overrides( overrides ).buildView( BlobStoreContext.class );

        blobStore = context.getBlobStore();
        blobStore.deleteContainer( bucketName );
    }
 
Example #8
Source File: ImportServiceIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public HashMap<String, Object> payloadBuilder() {

        HashMap<String, Object> payload = new HashMap<String, Object>();
        Map<String, Object> properties = new HashMap<String, Object>();
        Map<String, Object> storage_info = new HashMap<String, Object>();
        storage_info.put( "bucket_location", bucketName );

        storage_info.put( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR,
            System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ) );
        storage_info.put( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR,
            System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ) );

        properties.put( "storage_provider", "s3" );
        properties.put( "storage_info", storage_info );

        payload.put( "path","test-organization/test-app" );
        payload.put( "properties", properties );
        return payload;
    }
 
Example #9
Source File: ImportServiceIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Before
 public void before() {

     boolean configured =
                !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR))
             && !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR))
             && !StringUtils.isEmpty(System.getProperty("bucketName"));

     if ( !configured ) {
         logger.warn("Skipping test because {}, {} and bucketName not " +
             "specified as system properties, e.g. in your Maven settings.xml file.",
             new Object[] {
                 SDKGlobalConfiguration.SECRET_KEY_ENV_VAR,
                 SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR
             });
     }

     Assume.assumeTrue( configured );
}
 
Example #10
Source File: ImportCollectionIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/**
 * Delete the configured s3 bucket.
 */
public void deleteBucket() {

    logger.debug("\n\nDelete bucket\n");

    String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
    String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);

    Properties overrides = new Properties();
    overrides.setProperty("s3" + ".identity", accessId);
    overrides.setProperty("s3" + ".credential", secretKey);

    final Iterable<? extends Module> MODULES = ImmutableSet
        .of(new JavaUrlHttpCommandExecutorServiceModule(),
            new Log4JLoggingModule(),
            new NettyPayloadModule());

    BlobStoreContext context =
        ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES)
            .overrides(overrides).buildView(BlobStoreContext.class);

    BlobStore blobStore = context.getBlobStore();
    blobStore.deleteContainer( bucketName );
}
 
Example #11
Source File: ImportCollectionIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Before
public void before() {

    boolean configured =
               !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR))
            && !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR))
            && !StringUtils.isEmpty(System.getProperty("bucketName"));

    if ( !configured ) {
        logger.warn("Skipping test because {}, {} and bucketName not " +
            "specified as system properties, e.g. in your Maven settings.xml file.",
            new Object[] {
                SDKGlobalConfiguration.SECRET_KEY_ENV_VAR,
                SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR
            });
    }

    Assume.assumeTrue( configured );

    adminUser = newOrgAppAdminRule.getAdminInfo();
    organization = newOrgAppAdminRule.getOrganizationInfo();
    applicationId = newOrgAppAdminRule.getApplicationInfo().getId();


    bucketName = bucketPrefix + RandomStringUtils.randomAlphanumeric(10).toLowerCase();
}
 
Example #12
Source File: InstanceProfileCredentialsProvider.java    From bazel with Apache License 2.0 6 votes vote down vote up
private InstanceProfileCredentialsProvider(boolean refreshCredentialsAsync, final boolean eagerlyRefreshCredentialsAsync) {

        credentialsFetcher = new EC2CredentialsFetcher(new InstanceMetadataCredentialsEndpointProvider());

        if (!SDKGlobalConfiguration.isEc2MetadataDisabled()) {
            if (refreshCredentialsAsync) {
                executor = Executors.newScheduledThreadPool(1);
                executor.scheduleWithFixedDelay(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            if (shouldRefresh) credentialsFetcher.getCredentials();
                        } catch (AmazonClientException ace) {
                            handleError(ace);
                        } catch (RuntimeException re) {
                            handleError(re);
                        }
                    }
                }, 0, ASYNC_REFRESH_INTERVAL_TIME_MINUTES, TimeUnit.MINUTES);
            }
        }
    }
 
Example #13
Source File: UsergridAwsCredentials.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public String getAWSSecretKeyJson(Map<String,Object> jsonObject){
    String secretKey = (String) jsonObject.get( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR );
    if ( StringUtils.isEmpty( secretKey ) ){
        secretKey = (String) jsonObject.get( SDKGlobalConfiguration.ALTERNATE_SECRET_KEY_ENV_VAR );
    }
    if(StringUtils.isEmpty(secretKey)){
        throw new AmazonClientException("Could not get aws secret key from json object.");
    }
    return StringUtils.trim( secretKey );
}
 
Example #14
Source File: UsergridAwsCredentials.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public String getAWSAccessKeyIdJson(Map<String,Object> jsonObject){
    String accessKey = (String) jsonObject.get( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR );
    if ( StringUtils.isEmpty( accessKey ) ){
        accessKey = (String) jsonObject.get( SDKGlobalConfiguration.ALTERNATE_ACCESS_KEY_ENV_VAR );
    }

    if(StringUtils.isEmpty(accessKey)){
        throw new AmazonClientException("Could not get aws access key from json object.");
    }

    return StringUtils.trim( accessKey );
}
 
Example #15
Source File: UsergridAwsCredentials.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public String getAWSSecretKey() {
    String secret = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);
    if(StringUtils.isEmpty(secret)){
        secret = System.getProperty(SDKGlobalConfiguration.ALTERNATE_SECRET_KEY_ENV_VAR);
    }

    return StringUtils.trim(secret);
}
 
Example #16
Source File: UsergridAwsCredentials.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public String getAWSAccessKeyId() {
    String accessKey = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
    if( StringUtils.isEmpty( accessKey )){
        accessKey = System.getProperty(SDKGlobalConfiguration.ALTERNATE_ACCESS_KEY_ENV_VAR);
    }
    return StringUtils.trim(accessKey);
}
 
Example #17
Source File: ImportResourceIT.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private static void deleteBucketsWithPrefix() {

        logger.debug("\n\nDelete buckets with prefix {}\n", bucketPrefix);

        String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR );
        String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR );

        Properties overrides = new Properties();
        overrides.setProperty("s3" + ".identity", accessId);
        overrides.setProperty("s3" + ".credential", secretKey);

        final Iterable<? extends Module> MODULES = ImmutableSet
            .of(new JavaUrlHttpCommandExecutorServiceModule(),
                new Log4JLoggingModule(),
                new NettyPayloadModule());

        BlobStoreContext context =
            ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES)
                .overrides(overrides ).buildView(BlobStoreContext.class);

        BlobStore blobStore = context.getBlobStore();
        final PageSet<? extends StorageMetadata> blobStoreList = blobStore.list();

        for (Object o : blobStoreList.toArray()) {
            StorageMetadata s = (StorageMetadata) o;

            if (s.getName().startsWith(bucketPrefix)) {
                try {
                    blobStore.deleteContainer(s.getName());
                } catch (ContainerNotFoundException cnfe) {
                    logger.warn("Attempted to delete bucket {} but it is already deleted", cnfe);
                }
                logger.debug("Deleted bucket {}", s.getName());
            }
        }
    }
 
Example #18
Source File: ParquetOutputPlugin.java    From embulk-output-parquet with MIT License 5 votes vote down vote up
private ParquetWriter<PageReader> createWriter(PluginTask task, Schema schema, int processorIndex)
{
    //In case of using Frankurt (eu-central-1) with Signature Version 4 Signing Process
    System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, task.getSignature());

    final TimestampFormatter[] timestampFormatters = Timestamps.newTimestampColumnFormatters(task, schema, task.getColumnOptions());
    final boolean addUTF8 = task.getAddUTF8();

    final Path path = new Path(buildPath(task, processorIndex));
    final CompressionCodecName codec = CompressionCodecName.valueOf(task.getCompressionCodec());
    final int blockSize = task.getBlockSize();
    final int pageSize = task.getPageSize();
    final Configuration conf = createConfiguration(task.getExtraConfigurations(), task.getConfigFiles());
    final boolean overwrite = task.getOverwrite();

    ParquetWriter<PageReader> writer = null;
    try {
        EmbulkWriterBuilder builder = new EmbulkWriterBuilder(path, schema, timestampFormatters, addUTF8)
                .withCompressionCodec(codec)
                .withRowGroupSize(blockSize)
                .withPageSize(pageSize)
                .withDictionaryPageSize(pageSize)
                .withConf(conf);

        if (overwrite) {
            builder.withWriteMode(ParquetFileWriter.Mode.OVERWRITE);
        }

        writer = builder.build();
    } catch (IOException e) {
        Throwables.propagate(e);
    }
    return writer;
}
 
Example #19
Source File: ConfigEnvVarOverrideLocationProvider.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public File getLocation() {
    String overrideLocation = System.getenv(SDKGlobalConfiguration.AWS_CONFIG_FILE_ENV_VAR);
    if (overrideLocation != null) {
        return new File(overrideLocation);
    }
    return null;
}
 
Example #20
Source File: AwsAssetResourceIT.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Test
     public void errorCheckingInvalidProperties() throws Exception {
    Map<String, Object> errorTestProperties;
    errorTestProperties = getRemoteTestProperties();
    //test that we fail gracefully if we have missing properties
    setTestProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, "xxx");
    setTestProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, "xxx" );
    setTestProperty( "usergrid.binary.bucketname", "xxx" );

    try {

        Map<String, String> payload = hashMap( "name", "assetname" );
        ApiResponse postResponse = pathResource( getOrgAppPath( "foos" ) ).post( payload );
        UUID assetId = postResponse.getEntities().get( 0 ).getUuid();
        assertNotNull( assetId );

        // post a binary asset to that entity

        byte[] data = IOUtils.toByteArray( getClass().getResourceAsStream( "/cassandra_eye.jpg" ) );
        ApiResponse putResponse =
            pathResource( getOrgAppPath( "foos/" + assetId ) ).put( data, MediaType.APPLICATION_OCTET_STREAM_TYPE );


    }catch ( AwsPropertiesNotFoundException e ){
        fail("Shouldn't interrupt runtime if access key isnt found.");
    }
    catch( InternalServerErrorException uie){
        assertEquals( 500, uie.getResponse().getStatus() );
    }
    finally{
        setTestProperties( errorTestProperties );
    }
}
 
Example #21
Source File: AwsAssetResourceIT.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Test
public void errorCheckingMissingProperties() throws Exception {
    Map<String, Object> errorTestProperties;
    errorTestProperties = getRemoteTestProperties();
    //test that we fail gracefully if we have missing properties
    setTestProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, "xxx" );

    try {

        Map<String, String> payload = hashMap( "name", "assetname" );
        ApiResponse postResponse = pathResource( getOrgAppPath( "foos" ) ).post( payload );
        UUID assetId = postResponse.getEntities().get( 0 ).getUuid();
        assertNotNull( assetId );

        // post a binary asset to that entity

        byte[] data = IOUtils.toByteArray( getClass().getResourceAsStream( "/cassandra_eye.jpg" ) );
        ApiResponse putResponse =
            pathResource( getOrgAppPath( "foos/" + assetId ) ).put( data, MediaType.APPLICATION_OCTET_STREAM_TYPE );


    }catch ( AwsPropertiesNotFoundException e ){
        fail("Shouldn't interrupt runtime if access key isnt found.");
    }
    catch( ClientErrorException uie){
        assertEquals(500,uie.getResponse().getStatus());
    }
    finally{
        setTestProperties( errorTestProperties );
    }
}
 
Example #22
Source File: InstanceProfileCredentialsProvider.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @throws AmazonClientException if {@link SDKGlobalConfiguration#isEc2MetadataDisabled()} is true
 */
@Override
public AWSCredentials getCredentials() {
    if (SDKGlobalConfiguration.isEc2MetadataDisabled()) {
        throw new AmazonClientException("AWS_EC2_METADATA_DISABLED is set to true, not loading credentials from EC2 Instance "
                                     + "Metadata service");
    }
    AWSCredentials creds = credentialsFetcher.getCredentials();
    shouldRefresh = true;
    return creds;
}
 
Example #23
Source File: ImportCollectionIT.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private static void deleteBucketsWithPrefix() {

        logger.debug("\n\nDelete buckets with prefix {}\n", bucketPrefix );

        String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
        String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);

        Properties overrides = new Properties();
        overrides.setProperty("s3" + ".identity", accessId);
        overrides.setProperty("s3" + ".credential", secretKey);

        final Iterable<? extends Module> MODULES = ImmutableSet
            .of(new JavaUrlHttpCommandExecutorServiceModule(),
                new Log4JLoggingModule(),
                new NettyPayloadModule());

        BlobStoreContext context =
            ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES)
                .overrides(overrides).buildView(BlobStoreContext.class);

        BlobStore blobStore = context.getBlobStore();
        final PageSet<? extends StorageMetadata> blobStoreList = blobStore.list();

        for ( Object o : blobStoreList.toArray() ) {
            StorageMetadata s = (StorageMetadata)o;

            if ( s.getName().startsWith( bucketPrefix )) {
                try {
                    blobStore.deleteContainer(s.getName());
                } catch ( ContainerNotFoundException cnfe ) {
                    logger.warn("Attempted to delete bucket {} but it is already deleted", cnfe );
                }
                logger.debug("Deleted bucket {}", s.getName());
            }
        }
    }
 
Example #24
Source File: ImportCollectionIT.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * Start export job that wilk export a specific collection to the S3 bucket.
 */
private void exportCollection(
    final EntityManager em, final String collectionName ) throws Exception {

    logger.debug("\n\nExporting {} collection from application {}\n",
        collectionName, em.getApplication().getName() );
    setup.getEntityIndex().refresh(em.getApplicationId());


    ExportService exportService = setup.getExportService();
    UUID exportUUID = exportService.schedule( new HashMap<String, Object>() {{
        put( "path", organization.getName() + em.getApplication().getName());
        put( "organizationId",  organization.getUuid());
        put( "applicationId", em.getApplication().getUuid() );
        put( "collectionName", collectionName);
        put( "properties", new HashMap<String, Object>() {{
             put( "storage_provider", "s3" );
             put( "storage_info", new HashMap<String, Object>() {{
                 put( "s3_access_id",
                     System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR) );
                 put("s3_key",
                     System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR));
                put( "bucket_location", bucketName );
            }});
        }});
    }});

    int maxRetries = 30;
    int retries = 0;
    while ( !exportService.getState( exportUUID ).equals( "FINISHED" ) && retries++ < maxRetries ) {
        logger.debug("Waiting for export...");
        Thread.sleep(1000);
    }

    if ( retries >= maxRetries ) {
        throw new RuntimeException("Max retries reached");
    }
}
 
Example #25
Source File: AmazonEc2InstanceDataPropertySourceTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
private static void resetMetadataEndpointUrlOverwrite() {
	System.clearProperty(
			SDKGlobalConfiguration.EC2_METADATA_SERVICE_OVERRIDE_SYSTEM_PROPERTY);
}
 
Example #26
Source File: MetaDataServer.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
private static void resetMetadataEndpointUrlOverwrite() {
	System.clearProperty(
			SDKGlobalConfiguration.EC2_METADATA_SERVICE_OVERRIDE_SYSTEM_PROPERTY);
}
 
Example #27
Source File: TestStackInstanceIdService.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
private static void overwriteMetadataEndpointUrl(
		String localMetadataServiceEndpointUrl) {
	System.setProperty(
			SDKGlobalConfiguration.EC2_METADATA_SERVICE_OVERRIDE_SYSTEM_PROPERTY,
			localMetadataServiceEndpointUrl);
}
 
Example #28
Source File: TestStackInstanceIdService.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
private static void resetMetadataEndpointUrlOverwrite() {
	System.clearProperty(
			SDKGlobalConfiguration.EC2_METADATA_SERVICE_OVERRIDE_SYSTEM_PROPERTY);
}
 
Example #29
Source File: AmazonEc2InstanceDataPropertySourceAwsTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
private static void overwriteMetadataEndpointUrl(
		String localMetadataServiceEndpointUrl) {
	System.setProperty(
			SDKGlobalConfiguration.EC2_METADATA_SERVICE_OVERRIDE_SYSTEM_PROPERTY,
			localMetadataServiceEndpointUrl);
}
 
Example #30
Source File: S3Manager.java    From ReplicaDB with Apache License 2.0 4 votes vote down vote up
@Override
public int insertDataToTable(ResultSet resultSet, int taskId) throws Exception {

    URI s3Uri = new URI(options.getSinkConnect());
    // Get Service Endpoint
    // Secure by default
    String serviceEndpoint = "https://";
    if (!isSecuereConnection()) {
        serviceEndpoint = "http://";
    }

    // Get Service Port
    String servicePort = "";
    if (s3Uri.getPort() != -1) {
        servicePort = ":" + s3Uri.getPort();
    }

    serviceEndpoint = serviceEndpoint + s3Uri.getHost() + servicePort;
    LOG.debug("Using serviceEndpoint: " + serviceEndpoint);

    // Get Bucket name
    String bucketName = s3Uri.getPath().replaceAll("/$", "");

    LOG.debug(this.toString());

    // S3 Client
    System.setProperty(SDKGlobalConfiguration.DISABLE_CERT_CHECKING_SYSTEM_PROPERTY, "true");
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonS3 s3Client = AmazonS3ClientBuilder
            .standard()
            .withRegion("")
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(serviceEndpoint, null))
            .withPathStyleAccessEnabled(true)
            .withCredentials(new AWSStaticCredentialsProvider(credentials))
            .build();


    if (!isObjectPerRow()) {
        // All rows are only one CSV object in s3
        putCsvToS3(resultSet, taskId, s3Client, bucketName);
    } else {
        // Each row is a different object in s3
        putObjectToS3(resultSet, taskId, s3Client, bucketName);
    }

    return 0;

}