List of usage examples for com.amazonaws SDKGlobalConfiguration ACCESS_KEY_ENV_VAR
String ACCESS_KEY_ENV_VAR
To view the source code for com.amazonaws SDKGlobalConfiguration ACCESS_KEY_ENV_VAR.
Click Source Link
From source file:org.apache.usergrid.rest.management.ImportResourceIT.java
License:Apache License
/** * TODO: Test that importing bad JSON will result in an informative error message. *//*from ww w . j av a 2s.c om*/ @Test public void testImportBadJson() throws Exception { // import from a bad JSON file Assume.assumeTrue(configured); String org = clientSetup.getOrganizationName(); String app = clientSetup.getAppName(); String basePath = System.getProperty("target.directory") + File.separator + "test-classes" + File.separator; List<String> filenames = new ArrayList<>(1); filenames.add(basePath + "testimport-bad-json-testapp.3.json"); // create 10 applications each with collection of 10 things, export all to S3 S3Upload s3Upload = new S3Upload(); s3Upload.copyToS3(System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR), System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR), bucketName, filenames); // import all those exports from S3 into the default test application Entity importEntity = importCollection(); // we should now have 100 Entities in the default app Entity importGet = this.management().orgs().org(org).app().addToPath(app).addToPath("imports") .addToPath(importEntity.getUuid().toString()).get(); Entity importGetIncludes = this.management().orgs().org(org).app().addToPath(app).addToPath("imports") .addToPath(importEntity.getUuid().toString()).addToPath("files").get(); assertNotNull(importGet); //TODO: needs better error checking assertNotNull(importGetIncludes); // check that error message indicates JSON parsing error }
From source file:org.apache.usergrid.rest.management.ImportResourceIT.java
License:Apache License
/** * Call importService to import files from the configured S3 bucket. *///from w ww. j ava 2 s . com private Entity importCollection() throws Exception { String org = clientSetup.getOrganizationName(); String app = clientSetup.getAppName(); logger.debug("\n\nImport into new app {}\n", app); Entity importPayload = new Entity(new HashMap<String, Object>() { { put("properties", new HashMap<String, Object>() { { put("storage_provider", "s3"); put("storage_info", new HashMap<String, Object>() { { put("s3_key", System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR)); put("s3_access_id", System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR)); put("bucket_location", bucketName); } }); } }); } }); Entity importEntity = this.management().orgs().org(org).app().addToPath(app).addToPath("imports") .post(Entity.class, importPayload); int maxRetries = 120; int retries = 0; while (retries++ < maxRetries) { Entity importGet = this.management().orgs().org(org).app().addToPath(app).addToPath("imports") .addToPath(importEntity.getUuid().toString()).get(); if (importGet.get("state").equals("FINISHED") || importGet.get("state").equals("FAILED")) { break; } if (logger.isDebugEnabled()) { logger.debug("Waiting for import..."); } Thread.sleep(1000); } refreshIndex(); return importEntity; }
From source file:org.apache.usergrid.rest.management.ImportResourceIT.java
License:Apache License
/** * Delete the configured s3 bucket./*from www . j a v a 2 s .c o m*/ */ 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); }
From source file:org.apache.usergrid.rest.management.ImportResourceIT.java
License:Apache License
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); }// ww w. j a v a 2s . c om logger.debug("Deleted bucket {}", s.getName()); } } }
From source file:org.apache.usergrid.rest.management.ImportResourceIT.java
License:Apache License
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; }