Search in sources :

Example 16 with Address

use of com.amazonaws.services.ec2.model.Address in project gpconnect-demonstrator by nhsconnect.

the class LocationResourceProvider method createAddress.

/**
 * Some of the assignments look rather odd but they are deliberate.
 * They result from a change to spec to remove the state attribute from the address
 * See the commit cd26528 by James Cox 6/3/18 see also OrganizationResourceProvider.getValidAddress
 * @param locationDetails
 * @return Address Resource
 */
private Address createAddress(LocationDetails locationDetails) {
    Address address = new Address();
    List<StringType> list = new LinkedList<>();
    list.add(new StringType(locationDetails.getAddressLine()));
    list.add(new StringType(locationDetails.getAddressCity()));
    address.setLine(list);
    address.setCity(locationDetails.getAddressDistrict());
    address.setDistrict(locationDetails.getAddressState());
    address.setPostalCode(locationDetails.getAddressPostalCode());
    address.setCountry(locationDetails.getAddressCountry());
    return address;
}
Also used : Address(org.hl7.fhir.dstu3.model.Address) StringType(org.hl7.fhir.dstu3.model.StringType) LinkedList(java.util.LinkedList)

Example 17 with Address

use of com.amazonaws.services.ec2.model.Address in project gpconnect-demonstrator by nhsconnect.

the class OrganizationResourceProvider method getValidAddress.

private Address getValidAddress(Organization organization) {
    List<LocationDetails> locationsDetails = locationSearch.findAllLocations();
    LocationDetails location = null;
    for (LocationDetails locationDetails : locationsDetails) {
        if (locationDetails.getOrgOdsCode().equals(organization.getIdentifierFirstRep().getValue())) {
            location = locationDetails;
            break;
        }
    }
    Address orgAddress = null;
    if (location != null) {
        orgAddress = new Address();
        orgAddress.setUse(AddressUse.WORK);
        // #152
        // this looks very odd but is deliberate, there's a similar issue in locationResourceProvider.createAddress
        // They result from a change to spec to remove the state attribute from the address
        // See the commit cd26528 by James Cox 6/3/18
        orgAddress.addLine(location.getAddressLine());
        orgAddress.addLine(location.getAddressCity());
        orgAddress.setCity(location.getAddressDistrict());
        orgAddress.setDistrict(location.getAddressState());
        orgAddress.setPostalCode(location.getAddressPostalCode());
    }
    return orgAddress;
}
Also used : Address(org.hl7.fhir.dstu3.model.Address) LocationDetails(uk.gov.hscic.model.location.LocationDetails)

Example 18 with Address

use of com.amazonaws.services.ec2.model.Address in project druid by druid-io.

the class EC2AutoScalerTest method testIptoIdLookup.

@Test
public void testIptoIdLookup() throws Exception {
    EC2AutoScaler autoScaler = new EC2AutoScaler(0, 1, ENV_CONFIG, amazonEC2Client, managementConfig);
    final int n = 150;
    Assert.assertTrue(n <= 2 * EC2AutoScaler.MAX_AWS_FILTER_VALUES);
    List<String> ips = Lists.transform(ContiguousSet.create(Range.closedOpen(0, n), DiscreteDomain.integers()).asList(), Functions.toStringFunction());
    EasyMock.expect(amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("private-ip-address", ips.subList(0, EC2AutoScaler.MAX_AWS_FILTER_VALUES))))).andReturn(describeInstancesResult);
    EasyMock.expect(amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("private-ip-address", ips.subList(EC2AutoScaler.MAX_AWS_FILTER_VALUES, n))))).andReturn(describeInstancesResult);
    EasyMock.replay(amazonEC2Client);
    final Reservation[] chunk1 = new Reservation[EC2AutoScaler.MAX_AWS_FILTER_VALUES];
    Arrays.fill(chunk1, reservation);
    final Reservation[] chunk2 = new Reservation[n - EC2AutoScaler.MAX_AWS_FILTER_VALUES];
    Arrays.fill(chunk2, reservation);
    EasyMock.expect(describeInstancesResult.getReservations()).andReturn(Lists.newArrayList(chunk1));
    EasyMock.expect(describeInstancesResult.getReservations()).andReturn(Lists.newArrayList(chunk2));
    EasyMock.replay(describeInstancesResult);
    EasyMock.expect(reservation.getInstances()).andReturn(Arrays.asList(instance)).times(n);
    EasyMock.replay(reservation);
    List<String> ids = autoScaler.ipToIdLookup(ips);
    Assert.assertEquals(n, ids.size());
}
Also used : Reservation(com.amazonaws.services.ec2.model.Reservation) Filter(com.amazonaws.services.ec2.model.Filter) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) EC2AutoScaler(io.druid.indexing.overlord.autoscaling.ec2.EC2AutoScaler) Test(org.junit.Test)

Example 19 with Address

use of com.amazonaws.services.ec2.model.Address in project druid by druid-io.

the class EC2AutoScaler method ipToIdLookup.

@Override
public List<String> ipToIdLookup(List<String> ips) {
    final List<String> retVal = FluentIterable.from(Lists.partition(ips, MAX_AWS_FILTER_VALUES)).transformAndConcat(new Function<List<String>, Iterable<Reservation>>() {

        @Override
        public Iterable<Reservation> apply(List<String> input) {
            return amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("private-ip-address", input))).getReservations();
        }
    }).transformAndConcat(new Function<Reservation, Iterable<Instance>>() {

        @Override
        public Iterable<Instance> apply(Reservation reservation) {
            return reservation.getInstances();
        }
    }).transform(new Function<Instance, String>() {

        @Override
        public String apply(Instance instance) {
            return instance.getInstanceId();
        }
    }).toList();
    log.debug("Performing lookup: %s --> %s", ips, retVal);
    return retVal;
}
Also used : Function(com.google.common.base.Function) Reservation(com.amazonaws.services.ec2.model.Reservation) FluentIterable(com.google.common.collect.FluentIterable) Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance) List(java.util.List) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 20 with Address

use of com.amazonaws.services.ec2.model.Address in project GNS by MobilityFirst.

the class AWSEC2 method associateAddress.

/**
   *
   * @param ec2
   * @param ip
   * @param instance
   */
public static void associateAddress(AmazonEC2 ec2, String ip, Instance instance) {
    Address address;
    if ((address = findElasticIP(ec2, ip)) != null) {
        if (address.getDomain().equals("vpc")) {
            System.out.println("VPC Elastic IP:  " + ip);
            ec2.associateAddress(new AssociateAddressRequest().withInstanceId(instance.getInstanceId()).withAllocationId(address.getAllocationId()));
        } else {
            System.out.println("EC2 Classic Elastic IP:  " + ip);
            ec2.associateAddress(new AssociateAddressRequest(instance.getInstanceId(), ip));
        }
    }
}
Also used : Address(com.amazonaws.services.ec2.model.Address) AssociateAddressRequest(com.amazonaws.services.ec2.model.AssociateAddressRequest)

Aggregations

AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)8 Address (com.amazonaws.services.ec2.model.Address)7 Instance (com.amazonaws.services.ec2.model.Instance)7 Reservation (com.amazonaws.services.ec2.model.Reservation)7 DescribeAddressesResult (com.amazonaws.services.ec2.model.DescribeAddressesResult)6 Filter (com.amazonaws.services.ec2.model.Filter)6 List (java.util.List)6 Test (org.junit.Test)6 DescribeAddressesRequest (com.amazonaws.services.ec2.model.DescribeAddressesRequest)5 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)5 ArrayList (java.util.ArrayList)5 ReleaseAddressRequest (com.amazonaws.services.ec2.model.ReleaseAddressRequest)4 Address (com.google.api.services.people.v1.model.Address)4 Person (com.google.api.services.people.v1.model.Person)4 Address (org.hl7.fhir.dstu3.model.Address)4 AssociateAddressRequest (com.amazonaws.services.ec2.model.AssociateAddressRequest)3 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)3 Tag (com.amazonaws.services.ec2.model.Tag)3 Function (com.google.common.base.Function)3 TransportAddress (org.elasticsearch.common.transport.TransportAddress)3