Search in sources :

Example 6 with ExtractionOptions

use of gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions in project beneficiary-fhir-data by CMSgov.

the class CcwRifLoadJobIT method skipDataSetTest.

/**
 * Tests {@link CcwRifLoadJob} when run against a bucket with a single data set that should be
 * skipped (per {@link ExtractionOptions#getDataSetFilter()}).
 *
 * @throws Exception (exceptions indicate test failure)
 */
@Test
public void skipDataSetTest() throws Exception {
    AmazonS3 s3Client = S3Utilities.createS3Client(new ExtractionOptions("foo"));
    Bucket bucket = null;
    try {
        /*
       * Create the (empty) bucket to run against, and populate it with a
       * data set.
       */
        bucket = DataSetTestUtilities.createTestBucket(s3Client);
        ExtractionOptions options = new ExtractionOptions(bucket.getName(), Optional.of(RifFileType.PDE));
        LOGGER.info("Bucket created: '{}:{}'", s3Client.getS3AccountOwner().getDisplayName(), bucket.getName());
        DataSetManifest manifest = new DataSetManifest(Instant.now(), 0, new DataSetManifestEntry("beneficiaries.rif", RifFileType.BENEFICIARY), new DataSetManifestEntry("carrier.rif", RifFileType.CARRIER));
        s3Client.putObject(DataSetTestUtilities.createPutRequest(bucket, manifest));
        s3Client.putObject(DataSetTestUtilities.createPutRequest(bucket, manifest, manifest.getEntries().get(0), StaticRifResource.SAMPLE_A_BENES.getResourceUrl()));
        s3Client.putObject(DataSetTestUtilities.createPutRequest(bucket, manifest, manifest.getEntries().get(1), StaticRifResource.SAMPLE_A_CARRIER.getResourceUrl()));
        // Run the job.
        MockDataSetMonitorListener listener = new MockDataSetMonitorListener();
        S3TaskManager s3TaskManager = new S3TaskManager(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), options);
        CcwRifLoadJob ccwJob = new CcwRifLoadJob(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), options, s3TaskManager, listener);
        ccwJob.call();
        // Verify what was handed off to the DataSetMonitorListener.
        assertEquals(1, listener.getNoDataAvailableEvents());
        assertEquals(0, listener.getDataEvents().size());
        assertEquals(0, listener.getErrorEvents().size());
        // Verify that the data set was not renamed.
        DataSetTestUtilities.waitForBucketObjectCount(s3Client, bucket, CcwRifLoadJob.S3_PREFIX_PENDING_DATA_SETS, 1 + manifest.getEntries().size(), java.time.Duration.ofSeconds(10));
        DataSetTestUtilities.waitForBucketObjectCount(s3Client, bucket, CcwRifLoadJob.S3_PREFIX_COMPLETED_DATA_SETS, 0, java.time.Duration.ofSeconds(10));
    } finally {
        if (bucket != null)
            DataSetTestUtilities.deleteObjectsAndBucket(s3Client, bucket);
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) DataSetManifest(gov.cms.bfd.pipeline.ccw.rif.extract.s3.DataSetManifest) S3TaskManager(gov.cms.bfd.pipeline.ccw.rif.extract.s3.task.S3TaskManager) Bucket(com.amazonaws.services.s3.model.Bucket) ExtractionOptions(gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions) MockDataSetMonitorListener(gov.cms.bfd.pipeline.ccw.rif.extract.s3.MockDataSetMonitorListener) DataSetManifestEntry(gov.cms.bfd.pipeline.ccw.rif.extract.s3.DataSetManifest.DataSetManifestEntry) Test(org.junit.jupiter.api.Test)

Example 7 with ExtractionOptions

use of gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions in project beneficiary-fhir-data by CMSgov.

the class CcwRifLoadJobIT method emptyBucketTest.

/**
 * Tests {@link CcwRifLoadJob} when run against an empty bucket.
 *
 * @throws Exception (exceptions indicate test failure)
 */
@Test
public void emptyBucketTest() throws Exception {
    AmazonS3 s3Client = S3Utilities.createS3Client(new ExtractionOptions("foo"));
    Bucket bucket = null;
    try {
        // Create the (empty) bucket to run against.
        bucket = DataSetTestUtilities.createTestBucket(s3Client);
        ExtractionOptions options = new ExtractionOptions(bucket.getName());
        LOGGER.info("Bucket created: '{}:{}'", s3Client.getS3AccountOwner().getDisplayName(), bucket.getName());
        // Run the job.
        MockDataSetMonitorListener listener = new MockDataSetMonitorListener();
        S3TaskManager s3TaskManager = new S3TaskManager(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), options);
        CcwRifLoadJob ccwJob = new CcwRifLoadJob(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), options, s3TaskManager, listener);
        ccwJob.call();
        // Verify that no data sets were generated.
        assertEquals(1, listener.getNoDataAvailableEvents());
        assertEquals(0, listener.getDataEvents().size());
        assertEquals(0, listener.getErrorEvents().size());
    } finally {
        if (bucket != null)
            s3Client.deleteBucket(bucket.getName());
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) S3TaskManager(gov.cms.bfd.pipeline.ccw.rif.extract.s3.task.S3TaskManager) Bucket(com.amazonaws.services.s3.model.Bucket) ExtractionOptions(gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions) MockDataSetMonitorListener(gov.cms.bfd.pipeline.ccw.rif.extract.s3.MockDataSetMonitorListener) Test(org.junit.jupiter.api.Test)

Example 8 with ExtractionOptions

use of gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions in project beneficiary-fhir-data by CMSgov.

the class AppConfiguration method readCcwRifLoadOptionsFromEnvironmentVariables.

@Nullable
static CcwRifLoadOptions readCcwRifLoadOptionsFromEnvironmentVariables(LoadAppOptions loadOptions) {
    final boolean enabled = readEnvBooleanOptional(ENV_VAR_KEY_CCW_RIF_JOB_ENABLED).orElse(true);
    if (!enabled) {
        return null;
    }
    final String s3BucketName = readEnvStringRequired(ENV_VAR_KEY_BUCKET);
    final Optional<String> rifFilterText = readEnvStringOptional(ENV_VAR_KEY_ALLOWED_RIF_TYPE);
    final Optional<RifFileType> allowedRifFileType;
    if (rifFilterText.isPresent()) {
        try {
            allowedRifFileType = Optional.of(RifFileType.valueOf(rifFilterText.get()));
        } catch (IllegalArgumentException e) {
            throw new AppConfigurationException(String.format("Invalid value for configuration environment variable '%s': '%s'", ENV_VAR_KEY_ALLOWED_RIF_TYPE, rifFilterText), e);
        }
    } else {
        allowedRifFileType = Optional.empty();
    }
    /*
     * Just for convenience: make sure DefaultAWSCredentialsProviderChain
     * has whatever it needs.
     */
    try {
        DefaultAWSCredentialsProviderChain awsCredentialsProvider = new DefaultAWSCredentialsProviderChain();
        awsCredentialsProvider.getCredentials();
    } catch (AmazonClientException e) {
        /*
       * The credentials provider should throw this if it can't find what
       * it needs.
       */
        throw new AppConfigurationException(String.format("Missing configuration for AWS credentials (for %s).", DefaultAWSCredentialsProviderChain.class.getName()), e);
    }
    ExtractionOptions extractionOptions = new ExtractionOptions(s3BucketName, allowedRifFileType);
    CcwRifLoadOptions ccwRifLoadOptions = new CcwRifLoadOptions(extractionOptions, loadOptions);
    return ccwRifLoadOptions;
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AmazonClientException(com.amazonaws.AmazonClientException) ExtractionOptions(gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions) CcwRifLoadOptions(gov.cms.bfd.pipeline.ccw.rif.CcwRifLoadOptions) RifFileType(gov.cms.bfd.model.rif.RifFileType) Nullable(javax.annotation.Nullable)

Example 9 with ExtractionOptions

use of gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions in project beneficiary-fhir-data by CMSgov.

the class SyntheticDataUploader method main.

/**
 * Pushes the synthetic data up to S3, replacing any versions that are already there.
 *
 * @param args (not used)
 * @throws Exception Any {@link Exception}s encountered will be bubbled up, halting the
 *     application.
 */
public static void main(String[] args) throws Exception {
    ExtractionOptions options = new ExtractionOptions(String.format("bb-test-%d", new Random().nextInt(1000)));
    AmazonS3 s3Client = S3Utilities.createS3Client(options);
    LOGGER.info("Uploading original data...");
    uploadSyntheticData(s3Client, TestDataSetLocation.SYNTHETIC_DATA.getS3KeyPrefix().replace("-fixed", ""), syntheticDataFile -> syntheticDataFile.getOriginalFilePath());
    LOGGER.info("Uploading fixed data...");
    uploadSyntheticData(s3Client, TestDataSetLocation.SYNTHETIC_DATA.getS3KeyPrefix(), syntheticDataFile -> syntheticDataFile.getFixedFilePath());
    LOGGER.info("Uploaded all data.");
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Random(java.util.Random) ExtractionOptions(gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions)

Example 10 with ExtractionOptions

use of gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions in project beneficiary-fhir-data by CMSgov.

the class SyntheticDataUploader2 method main.

/**
 * Pushes the synthetic data from {@link SyntheticDataFixer2} up to S3, replacing any versions
 * that are already there.
 *
 * @param args (not used)
 * @throws Exception Any {@link Exception}s encountered will be bubbled up, halting the
 *     application.
 */
public static void main(String[] args) throws Exception {
    ExtractionOptions options = new ExtractionOptions(String.format("bb-test-%d", new Random().nextInt(1000)));
    AmazonS3 s3Client = S3Utilities.createS3Client(options);
    LOGGER.info("Uploading fixed data...");
    uploadSyntheticData(s3Client, TestDataSetLocation.SYNTHETIC_DATA.getS3KeyPrefix(), syntheticDataFile -> syntheticDataFile.getFixedFilePath());
    LOGGER.info("Uploaded all data.");
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Random(java.util.Random) ExtractionOptions(gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions)

Aggregations

ExtractionOptions (gov.cms.bfd.pipeline.ccw.rif.extract.ExtractionOptions)10 AmazonS3 (com.amazonaws.services.s3.AmazonS3)9 Bucket (com.amazonaws.services.s3.model.Bucket)5 DataSetManifest (gov.cms.bfd.pipeline.ccw.rif.extract.s3.DataSetManifest)5 DataSetManifestEntry (gov.cms.bfd.pipeline.ccw.rif.extract.s3.DataSetManifest.DataSetManifestEntry)5 Test (org.junit.jupiter.api.Test)5 MockDataSetMonitorListener (gov.cms.bfd.pipeline.ccw.rif.extract.s3.MockDataSetMonitorListener)4 S3TaskManager (gov.cms.bfd.pipeline.ccw.rif.extract.s3.task.S3TaskManager)4 AmazonClientException (com.amazonaws.AmazonClientException)3 Random (java.util.Random)3 Download (com.amazonaws.services.s3.transfer.Download)2 RifFileType (gov.cms.bfd.model.rif.RifFileType)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 Path (java.nio.file.Path)2 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)1 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)1 TransferManagerBuilder (com.amazonaws.services.s3.transfer.TransferManagerBuilder)1 BeneficiaryColumn (gov.cms.bfd.model.rif.BeneficiaryColumn)1