AwsS3DistributionServiceImpl extends AbstractDistributionService implements AwsS3DistributionService, DistributionService { protected void createAWSBucket() { try { s3.listObjects(bucketName); } catch (AmazonServiceException e) { if (e.getStatusCode() == 404) { try { s3.createBucket(bucketName); Statement allowPublicReadStatement = new Statement(Statement.Effect.Allow).withPrincipals(Principal.AllUsers) .withActions(S3Actions.GetObject).withResources(new S3ObjectResource(bucketName, "*")); Policy policy = new Policy().withStatements(allowPublicReadStatement); s3.setBucketPolicy(bucketName, policy.toJson()); logger.info("AWS S3 bucket {} created", bucketName); } catch (Exception e2) { throw new ConfigurationException("Bucket " + bucketName + " cannot be created: " + e2.getMessage(), e2); } } else { throw new ConfigurationException("Bucket " + bucketName + " exists, but we can't access it: " + e.getMessage(), e); } } } AwsS3DistributionServiceImpl(); @Override void activate(ComponentContext cc); @Override String getDistributionType(); void deactivate(); @Override Job distribute(String pubChannelId, MediaPackage mediaPackage, Set<String> downloadIds,
    boolean checkAvailability, boolean preserveReference); @Override Job distribute(String channelId, MediaPackage mediaPackage, Set<String> elementIds, boolean checkAvailability); @Override Job distribute(String channelId, MediaPackage mediapackage, String elementId); @Override Job distribute(String channelId, MediaPackage mediaPackage, String elementId, boolean checkAvailability); MediaPackageElement[] distributeElements(String channelId, MediaPackage mediapackage, Set<String> elementIds,
          boolean checkAvailability); MediaPackageElement distributeElement(String channelId, final MediaPackage mediaPackage,
          MediaPackageElement element, boolean checkAvailability); @Override Job retract(String channelId, MediaPackage mediapackage, String elementId); @Override Job retract(String channelId, MediaPackage mediapackage, Set<String> elementIds); @Override List<MediaPackageElement> distributeSync(String channelId, MediaPackage mediapackage, Set<String> elementIds,
         boolean checkAvailability); @Override List<MediaPackageElement> retractSync(String channelId, MediaPackage mediaPackage, Set<String> elementIds); @Override Job restore(String channelId, MediaPackage mediaPackage, String elementId); @Override Job restore(String channelId, MediaPackage mediaPackage, String elementId, String fileName); static final String JOB_TYPE; static final String AWS_S3_DISTRIBUTION_ENABLE; static final String AWS_S3_DISTRIBUTION_BASE_CONFIG; static final String AWS_S3_ACCESS_KEY_ID_CONFIG; static final String AWS_S3_SECRET_ACCESS_KEY_CONFIG; static final String AWS_S3_REGION_CONFIG; static final String AWS_S3_BUCKET_CONFIG; static final String AWS_S3_ENDPOINT_CONFIG; static final String AWS_S3_PATH_STYLE_CONFIG; static final String OPENCAST_DOWNLOAD_URL; static final String OPENCAST_STORAGE_DIR; static final String DEFAULT_TEMP_DIR; static final float DEFAULT_DISTRIBUTE_JOB_LOAD; static final float DEFAULT_RETRACT_JOB_LOAD; static final float DEFAULT_RESTORE_JOB_LOAD; static final String DISTRIBUTE_JOB_LOAD_KEY; static final String RETRACT_JOB_LOAD_KEY; static final String RESTORE_JOB_LOAD_KEY; }
@Test public void testCreateAWSBucket() { AmazonServiceException e = EasyMock.createNiceMock(AmazonServiceException.class); EasyMock.expect(e.getStatusCode()).andReturn(404); EasyMock.replay(e); EasyMock.expect(s3.listObjects(BUCKET_NAME)).andThrow(e).once(); EasyMock.expect(s3.createBucket(BUCKET_NAME)).andReturn(EasyMock.anyObject(Bucket.class)).once(); s3.setBucketPolicy(BUCKET_NAME, EasyMock.anyObject(String.class)); EasyMock.expectLastCall().once(); EasyMock.replay(s3); service.createAWSBucket(); EasyMock.verify(s3); }
@Test public void testCreateAWSBucketWhenAlreadyExists() { ObjectListing list = EasyMock.createNiceMock(ObjectListing.class); EasyMock.replay(list); EasyMock.expect(s3.listObjects(BUCKET_NAME)).andReturn(list).once(); EasyMock.replay(s3); service.createAWSBucket(); EasyMock.verify(s3); }