Search in sources :

Example 1 with ResourceManager

use of org.ihtsdo.otf.resourcemanager.ResourceManager in project snomed-drools by IHTSDO.

the class RuleExecutor method newTestResourceProvider.

public TestResourceProvider newTestResourceProvider(String awsKey, String awsSecretKey, String bucket, String path) throws RuleExecutorException {
    try {
        AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withRegion("us-east-1").withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsKey, awsSecretKey))).build();
        ManualResourceConfiguration resourceConfiguration = new ManualResourceConfiguration(true, true, null, new ResourceConfiguration.Cloud(bucket, path));
        ResourceManager resourceManager = new ResourceManager(resourceConfiguration, new SimpleStorageResourceLoader(amazonS3));
        TestResourceProvider testResourceProvider = new TestResourceProvider(resourceManager);
        testResourcesEmpty = !testResourceProvider.isAnyResourcesLoaded();
        return testResourceProvider;
    } catch (IOException e) {
        testResourcesEmpty = true;
        throw new RuleExecutorException("Failed to load test resources.", e);
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) RuleExecutorException(org.ihtsdo.drools.exception.RuleExecutorException) BadRequestRuleExecutorException(org.ihtsdo.drools.exception.BadRequestRuleExecutorException) SimpleStorageResourceLoader(org.springframework.cloud.aws.core.io.s3.SimpleStorageResourceLoader) ResourceManager(org.ihtsdo.otf.resourcemanager.ResourceManager) IOException(java.io.IOException) ManualResourceConfiguration(org.ihtsdo.otf.resourcemanager.ManualResourceConfiguration) TestResourceProvider(org.ihtsdo.drools.service.TestResourceProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ResourceConfiguration(org.ihtsdo.otf.resourcemanager.ResourceConfiguration) ManualResourceConfiguration(org.ihtsdo.otf.resourcemanager.ManualResourceConfiguration)

Example 2 with ResourceManager

use of org.ihtsdo.otf.resourcemanager.ResourceManager in project snomed-drools by IHTSDO.

the class DroolsRF2Validator method getTestResourceManager.

private static ResourceManager getTestResourceManager(boolean loadTestResources) throws IOException {
    if (loadTestResources) {
        Properties properties = new Properties();
        // Load bucket and path for test resources
        properties.load(DroolsRF2Validator.class.getResourceAsStream("/aws.properties"));
        ManualResourceConfiguration testResourcesConfiguration = new ManualResourceConfiguration(true, true, null, new ResourceConfiguration.Cloud(properties.getProperty("test-resources.cloud.bucket"), properties.getProperty("test-resources.cloud.path")));
        // This uses anonymous access
        return new ResourceManager(testResourcesConfiguration, new SimpleStorageResourceLoader(AmazonS3ClientBuilder.standard().withRegion("us-east-1").build()));
    } else {
        return new ResourceManager(BLANK_RESOURCES_CONFIGURATION, null);
    }
}
Also used : SimpleStorageResourceLoader(org.springframework.cloud.aws.core.io.s3.SimpleStorageResourceLoader) ResourceManager(org.ihtsdo.otf.resourcemanager.ResourceManager) ManualResourceConfiguration(org.ihtsdo.otf.resourcemanager.ManualResourceConfiguration) ResourceConfiguration(org.ihtsdo.otf.resourcemanager.ResourceConfiguration) ManualResourceConfiguration(org.ihtsdo.otf.resourcemanager.ManualResourceConfiguration)

Example 3 with ResourceManager

use of org.ihtsdo.otf.resourcemanager.ResourceManager in project snomed-drools by IHTSDO.

the class RulesTestManual method setup.

@Before
public void setup() {
    ManualResourceConfiguration resourceConfiguration = new ManualResourceConfiguration(true, false, new ResourceConfiguration.Local("src/test/resources/dummy-test-resources"), null);
    TestResourceProvider testResourceProvider = this.ruleExecutor.newTestResourceProvider(new ResourceManager(resourceConfiguration, null));
    conceptService = new TestConceptService(concepts);
    descriptionService = new TestDescriptionService(concepts, testResourceProvider);
    relationshipService = new TestRelationshipService(concepts);
}
Also used : TestDescriptionService(org.ihtsdo.drools.rulestestrig.service.TestDescriptionService) TestConceptService(org.ihtsdo.drools.rulestestrig.service.TestConceptService) TestRelationshipService(org.ihtsdo.drools.rulestestrig.service.TestRelationshipService) ResourceManager(org.ihtsdo.otf.resourcemanager.ResourceManager) ManualResourceConfiguration(org.ihtsdo.otf.resourcemanager.ManualResourceConfiguration) TestResourceProvider(org.ihtsdo.drools.service.TestResourceProvider) ResourceConfiguration(org.ihtsdo.otf.resourcemanager.ResourceConfiguration) ManualResourceConfiguration(org.ihtsdo.otf.resourcemanager.ManualResourceConfiguration) Before(org.junit.Before)

Example 4 with ResourceManager

use of org.ihtsdo.otf.resourcemanager.ResourceManager in project snomed-drools by IHTSDO.

the class RuleExecutorTest method setup.

@Before
public void setup() {
    ruleExecutor = new RuleExecutorFactory().createRuleExecutor("src/test/resources/rules");
    ManualResourceConfiguration resourceConfiguration = new ManualResourceConfiguration(true, false, new ResourceConfiguration.Local("src/test/resources/dummy-test-resources"), null);
    TestResourceProvider testResourceProvider = ruleExecutor.newTestResourceProvider(new ResourceManager(resourceConfiguration, null));
    final Map<String, Concept> concepts = new HashMap<>();
    conceptService = new TestConceptService(concepts);
    descriptionService = new TestDescriptionService(concepts, testResourceProvider);
    relationshipService = new TestRelationshipService(concepts);
}
Also used : Concept(org.ihtsdo.drools.domain.Concept) TestDescriptionService(org.ihtsdo.drools.rulestestrig.service.TestDescriptionService) ResourceManager(org.ihtsdo.otf.resourcemanager.ResourceManager) RuleExecutorFactory(org.ihtsdo.drools.RuleExecutorFactory) ManualResourceConfiguration(org.ihtsdo.otf.resourcemanager.ManualResourceConfiguration) TestResourceProvider(org.ihtsdo.drools.service.TestResourceProvider) ResourceConfiguration(org.ihtsdo.otf.resourcemanager.ResourceConfiguration) ManualResourceConfiguration(org.ihtsdo.otf.resourcemanager.ManualResourceConfiguration) TestConceptService(org.ihtsdo.drools.rulestestrig.service.TestConceptService) TestRelationshipService(org.ihtsdo.drools.rulestestrig.service.TestRelationshipService) Before(org.junit.Before)

Example 5 with ResourceManager

use of org.ihtsdo.otf.resourcemanager.ResourceManager in project reporting-engine by IHTSDO.

the class ArchiveDataLoader method download.

public void download(File archive) throws TermServerScriptException {
    if (s3Manager.isUseCloud()) {
        try {
            ResourceManager resourceManager = s3Manager.getResourceManager();
            try (InputStream input = resourceManager.readResourceStream(archive.getName());
                OutputStream out = new FileOutputStream(archive)) {
                TermServerScript.info("Downloading " + archive.getName() + " from S3");
                IOUtils.copy(input, out);
                TermServerScript.info("Download complete");
            }
        } catch (Throwable t) {
            final String msg = "Error when trying to download " + archive.getName() + " from S3 via :" + archiveLoaderConfig;
            throw new TermServerScriptException(msg, t);
        }
    } else {
        LOGGER.info("ArchiveDataLoader set to local source. Will expect " + archive + " to be available.");
    }
}
Also used : ResourceManager(org.ihtsdo.otf.resourcemanager.ResourceManager) TermServerScriptException(org.ihtsdo.otf.exception.TermServerScriptException)

Aggregations

ResourceManager (org.ihtsdo.otf.resourcemanager.ResourceManager)8 TestResourceProvider (org.ihtsdo.drools.service.TestResourceProvider)4 ManualResourceConfiguration (org.ihtsdo.otf.resourcemanager.ManualResourceConfiguration)4 ResourceConfiguration (org.ihtsdo.otf.resourcemanager.ResourceConfiguration)4 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)3 TermServerScriptException (org.ihtsdo.otf.exception.TermServerScriptException)3 Before (org.junit.Before)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)2 EC2ContainerCredentialsProviderWrapper (com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper)2 TestConceptService (org.ihtsdo.drools.rulestestrig.service.TestConceptService)2 TestDescriptionService (org.ihtsdo.drools.rulestestrig.service.TestDescriptionService)2 TestRelationshipService (org.ihtsdo.drools.rulestestrig.service.TestRelationshipService)2 SimpleStorageResourceLoader (org.snomed.otf.script.dao.SimpleStorageResourceLoader)2 SimpleStorageResourceLoader (org.springframework.cloud.aws.core.io.s3.SimpleStorageResourceLoader)2 IOException (java.io.IOException)1 RuleExecutorFactory (org.ihtsdo.drools.RuleExecutorFactory)1 Concept (org.ihtsdo.drools.domain.Concept)1