Search in sources :

Example 1 with ResourceType

use of com.amazonaws.services.ec2.model.ResourceType in project pathling by aehrc.

the class FhirServer method buildUpdateProviders.

@Nonnull
private List<IResourceProvider> buildUpdateProviders() {
    final List<IResourceProvider> providers = new ArrayList<>();
    for (final ResourceType resourceType : ResourceType.values()) {
        final IResourceProvider updateProvider = resourceProviderFactory.createUpdateResourceProvider(resourceType);
        providers.add(updateProvider);
    }
    return providers;
}
Also used : IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) ArrayList(java.util.ArrayList) ResourceType(org.hl7.fhir.r4.model.ResourceType) Nonnull(javax.annotation.Nonnull)

Example 2 with ResourceType

use of com.amazonaws.services.ec2.model.ResourceType in project CRD by HL7-DaVinci.

the class QueryBatchRequest method performQueryBatchRequest.

/**
 * Backfills the missing required values of the response that prefetch may have missed.
 * This implementation pulls the IDs of the required references from the request object's draft
 * orders, checks which of those values are missing from the current CRD response, builds the
 * Query Batch JSON request using
 * http://build.fhir.org/ig/HL7/davinci-crd/hooks.html#fhir-resource-access,
 * then populates the CRD response with the response from the Query Batch.
 */
public void performQueryBatchRequest(CdsRequest<?, ?> cdsRequest, CrdPrefetch crdPrefetch) {
    logger.info("***** ***** Performing Query Batch Request.");
    CrdPrefetch crdResponse = crdPrefetch;
    // The list of references that should be queried in the batch request.
    List<String> requiredReferences = new ArrayList<String>();
    // Get the IDs of references in the request's draft orders.
    Bundle draftOrdersBundle = cdsRequest.getContext().getDraftOrders();
    // This assumes that only the first draft order is relevant.
    Resource initialRequestResource = draftOrdersBundle.getEntry().get(0).getResource();
    ResourceType requestType = initialRequestResource.getResourceType();
    // Extract the references by iterating through the JSON.
    Gson gson = new Gson();
    final JsonObject jsonObject = gson.toJsonTree(initialRequestResource).getAsJsonObject();
    for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
        FhirRequestProcessor.extractReferenceIds(requiredReferences, entry.getValue());
    }
    // Filter out references that already exist in the CRD Response.
    requiredReferences = requiredReferences.stream().filter(referenceId -> !crdResponse.containsRequestResourceId(referenceId)).collect(Collectors.toList());
    logger.info("References to query: " + requiredReferences);
    if (requiredReferences.isEmpty()) {
        logger.info("A Query Batch Request is not needed: all references have already already fetched.");
        return;
    }
    // Build the Query Batch Request JSON.
    Bundle queryBatchRequestBundle = buildQueryBatchRequestBundle(requiredReferences);
    String queryBatchRequestBody = FhirContext.forR4().newJsonParser().encodeResourceToString(queryBatchRequestBundle);
    // Make the query batch request to the EHR server.
    Bundle queryResponseBundle = null;
    try {
        logger.info("Executing Query Batch Request: " + queryBatchRequestBody);
        queryResponseBundle = (Bundle) FhirRequestProcessor.executeFhirQueryBody(queryBatchRequestBody, cdsRequest, this.fhirComponents, HttpMethod.POST);
        queryResponseBundle = extractNestedBundledResources(queryResponseBundle);
        logger.info("Extracted Query Batch Resources: " + (queryResponseBundle).getEntry().stream().map(entry -> entry.getResource()).collect(Collectors.toList()));
    } catch (Exception e) {
        logger.error("Failed to backfill prefetch with Query Batch Request " + queryBatchRequestBody, e);
    }
    if (queryResponseBundle == null) {
        logger.error("No response recieved from the Query Batch Request.");
        return;
    }
    // Add the request resource to the query batch response as it may be missing.
    // Coverage and Subject are not automatically being
    // linked to the request object. It seems to somehow automatically link during
    // standard prefetch, but not here so we're doing it manually.
    List<Coverage> coverages = FhirRequestProcessor.extractCoverageFromBundle(queryResponseBundle);
    List<Patient> patients = FhirRequestProcessor.extractPatientsFromBundle(queryResponseBundle);
    FhirRequestProcessor.addInsuranceAndSubject(initialRequestResource, patients, coverages);
    BundleEntryComponent newEntry = new BundleEntryComponent();
    newEntry.setResource(initialRequestResource);
    queryResponseBundle.addEntry(newEntry);
    // Add the query batch response resources to the CRD Prefetch request.
    logger.info("Query Batch Response Entries: " + queryResponseBundle.getEntry());
    FhirRequestProcessor.addToCrdPrefetchRequest(crdResponse, requestType, queryResponseBundle.getEntry());
    logger.info("Post-Query Batch CRDResponse: " + crdResponse);
}
Also used : CrdPrefetch(org.hl7.davinci.r4.crdhook.CrdPrefetch) JsonObject(com.google.gson.JsonObject) Logger(org.slf4j.Logger) FhirRequestProcessor(org.hl7.davinci.endpoint.cdshooks.services.crd.r4.FhirRequestProcessor) LoggerFactory(org.slf4j.LoggerFactory) HttpMethod(org.springframework.http.HttpMethod) Resource(org.hl7.fhir.r4.model.Resource) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HTTPVerb(org.hl7.fhir.r4.model.Bundle.HTTPVerb) JsonElement(com.google.gson.JsonElement) FhirComponentsT(org.hl7.davinci.FhirComponentsT) BundleEntryRequestComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent) ResourceType(org.hl7.fhir.r4.model.ResourceType) FhirContext(ca.uhn.fhir.context.FhirContext) List(java.util.List) Gson(com.google.gson.Gson) Map(java.util.Map) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) CdsRequest(org.cdshooks.CdsRequest) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) Coverage(org.hl7.fhir.r4.model.Coverage) Patient(org.hl7.fhir.r4.model.Patient) Bundle(org.hl7.fhir.r4.model.Bundle) ArrayList(java.util.ArrayList) Resource(org.hl7.fhir.r4.model.Resource) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) Patient(org.hl7.fhir.r4.model.Patient) ResourceType(org.hl7.fhir.r4.model.ResourceType) Coverage(org.hl7.fhir.r4.model.Coverage) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) JsonElement(com.google.gson.JsonElement) CrdPrefetch(org.hl7.davinci.r4.crdhook.CrdPrefetch) Map(java.util.Map)

Example 3 with ResourceType

use of com.amazonaws.services.ec2.model.ResourceType in project SimianArmy by Netflix.

the class TestInstanceJanitorCrawler method testInstancesWithResourceType.

@Test
public void testInstancesWithResourceType() {
    List<AutoScalingInstanceDetails> instanceDetailsList = createInstanceDetailsList();
    List<Instance> instanceList = createInstanceList();
    AWSClient awsMock = createMockAWSClient(instanceDetailsList, instanceList);
    InstanceJanitorCrawler crawler = new InstanceJanitorCrawler(awsMock);
    for (AWSResourceType resourceType : AWSResourceType.values()) {
        List<Resource> resources = crawler.resources(resourceType);
        if (resourceType == AWSResourceType.INSTANCE) {
            verifyInstanceList(resources, instanceDetailsList);
        } else {
            Assert.assertTrue(resources.isEmpty());
        }
    }
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AutoScalingInstanceDetails(com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) Test(org.testng.annotations.Test)

Example 4 with ResourceType

use of com.amazonaws.services.ec2.model.ResourceType in project cloudbreak by hortonworks.

the class AwsAttachmentResourceBuilder method checkResources.

@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AwsContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
    AmazonEc2Client client = getAmazonEc2Client(auth);
    Pair<List<String>, List<CloudResource>> volumes = volumeResourceCollector.getVolumeIdsByVolumeResources(resources, resourceType(), volumeSetAttributes());
    if (volumes.getFirst().isEmpty()) {
        return collectCloudResourceStatuses(volumes.getSecond(), ResourceStatus.CREATED);
    }
    DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest(volumes.getFirst());
    DescribeVolumesResult result = client.describeVolumes(describeVolumesRequest);
    ResourceStatus volumeSetStatus = result.getVolumes().stream().map(com.amazonaws.services.ec2.model.Volume::getState).allMatch("in-use"::equals) ? ResourceStatus.CREATED : ResourceStatus.IN_PROGRESS;
    LOGGER.debug("[{}] volume set status is {}", String.join(",", volumes.getFirst()), volumeSetStatus);
    return collectCloudResourceStatuses(volumes.getSecond(), volumeSetStatus);
}
Also used : ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) List(java.util.List) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest)

Example 5 with ResourceType

use of com.amazonaws.services.ec2.model.ResourceType in project cloudbreak by hortonworks.

the class AwsVolumeResourceBuilder method checkResources.

@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AwsContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
    AmazonEc2Client client = getAmazonEC2Client(auth);
    Pair<List<String>, List<CloudResource>> volumes = volumeResourceCollector.getVolumeIdsByVolumeResources(resources, resourceType(), volumeSetAttributes());
    DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest(volumes.getFirst());
    LOGGER.debug("Going to describe volume(s) with id(s): [{}]", String.join(",", describeVolumesRequest.getVolumeIds()));
    AtomicReference<ResourceStatus> volumeSetStatus = new AtomicReference<>();
    try {
        DescribeVolumesResult result = client.describeVolumes(describeVolumesRequest);
        volumeSetStatus.set(getResourceStatus(result));
    } catch (AmazonEC2Exception e) {
        if (!"InvalidVolume.NotFound".equals(e.getErrorCode())) {
            throw e;
        }
        LOGGER.info("The volume doesn't need to be deleted as it does not exist on the provider side. Reason: {}", e.getMessage());
        volumeSetStatus.set(DELETED);
    }
    LOGGER.debug("[{}] volume set status is {}", String.join(",", volumes.getFirst()), volumeSetStatus);
    return volumes.getSecond().stream().map(resource -> new CloudResourceStatus(resource, volumeSetStatus.get())).collect(Collectors.toList());
}
Also used : AwsResourceNameService(com.sequenceiq.cloudbreak.cloud.aws.common.service.AwsResourceNameService) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) CREATED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.CREATED) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) LoggerFactory(org.slf4j.LoggerFactory) AwsDiskType(com.sequenceiq.common.model.AwsDiskType) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TagSpecification(com.amazonaws.services.ec2.model.TagSpecification) StringUtils(org.apache.commons.lang3.StringUtils) DeviceNameGenerator(com.sequenceiq.cloudbreak.util.DeviceNameGenerator) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) Future(java.util.concurrent.Future) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) FAILED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.FAILED) CreateVolumeRequest(com.amazonaws.services.ec2.model.CreateVolumeRequest) Map(java.util.Map) EbsInstanceBlockDeviceSpecification(com.amazonaws.services.ec2.model.EbsInstanceBlockDeviceSpecification) Pair(org.springframework.data.util.Pair) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudVolumeUsageType(com.sequenceiq.cloudbreak.cloud.model.CloudVolumeUsageType) IN_PROGRESS(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.IN_PROGRESS) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Optional(java.util.Optional) AwsMethodExecutor(com.sequenceiq.cloudbreak.cloud.aws.common.util.AwsMethodExecutor) NotNull(org.jetbrains.annotations.NotNull) AwsInstanceView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceView) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ResourceRetriever(com.sequenceiq.cloudbreak.cloud.service.ResourceRetriever) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) InstanceBlockDeviceMappingSpecification(com.amazonaws.services.ec2.model.InstanceBlockDeviceMappingSpecification) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CreateVolumeResult(com.amazonaws.services.ec2.model.CreateVolumeResult) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) AwsContext(com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Subnet(com.amazonaws.services.ec2.model.Subnet) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) ATTACHED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.ATTACHED) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) DELETED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.DELETED) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) ModifyInstanceAttributeResult(com.amazonaws.services.ec2.model.ModifyInstanceAttributeResult) Component(org.springframework.stereotype.Component) PreserveResourceException(com.sequenceiq.cloudbreak.cloud.template.compute.PreserveResourceException) ModifyInstanceAttributeRequest(com.amazonaws.services.ec2.model.ModifyInstanceAttributeRequest) DeleteVolumeRequest(com.amazonaws.services.ec2.model.DeleteVolumeRequest) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) Collections(java.util.Collections) Volume(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes.Volume) AwsTaggingService(com.sequenceiq.cloudbreak.cloud.aws.common.AwsTaggingService) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) List(java.util.List) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception)

Aggregations

ArrayList (java.util.ArrayList)9 ResourceType (org.hl7.fhir.r4.model.ResourceType)6 List (java.util.List)5 IResourceProvider (ca.uhn.fhir.rest.server.IResourceProvider)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Resource (com.netflix.simianarmy.Resource)3 AWSResource (com.netflix.simianarmy.aws.AWSResource)3 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)3 HashMap (java.util.HashMap)3 Nonnull (javax.annotation.Nonnull)3 DescribeVolumesRequest (com.amazonaws.services.ec2.model.DescribeVolumesRequest)2 DescribeVolumesResult (com.amazonaws.services.ec2.model.DescribeVolumesResult)2 Tag (com.amazonaws.services.ec2.model.Tag)2 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 ResourceStatus (com.sequenceiq.cloudbreak.cloud.model.ResourceStatus)2 AWSConstants (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants)2 AWSUriPaths (com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths)2 AWSClientManager (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager)2