Search in sources :

Example 21 with AmazonInfo

use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.

the class BackUpRegistryTest method createRemoteInstance.

private InstanceInfo createRemoteInstance(String instanceHostName) {
    InstanceInfo.Builder instanceBuilder = InstanceInfo.Builder.newBuilder();
    instanceBuilder.setAppName(REMOTE_REGION_APP_NAME);
    instanceBuilder.setVIPAddress(ALL_REGIONS_VIP_ADDR);
    instanceBuilder.setHostName(instanceHostName);
    instanceBuilder.setIPAddr("10.10.101.1");
    AmazonInfo amazonInfo = getAmazonInfo(REMOTE_ZONE, instanceHostName);
    instanceBuilder.setDataCenterInfo(amazonInfo);
    instanceBuilder.setMetadata(amazonInfo.getMetadata());
    return instanceBuilder.build();
}
Also used : AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 22 with AmazonInfo

use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.

the class EurekaJsonAndXmlJacksonCodecTest method doAmazonInfoEncodeDecodeTest.

private void doAmazonInfoEncodeDecodeTest(AbstractEurekaJacksonCodec codec) throws Exception {
    AmazonInfo amazonInfo = (AmazonInfo) infoIterator.next().getDataCenterInfo();
    String encodedString = codec.getObjectMapper(DataCenterInfo.class).writeValueAsString(amazonInfo);
    DataCenterInfo decodedValue = codec.getObjectMapper(DataCenterInfo.class).readValue(encodedString, DataCenterInfo.class);
    assertThat(EurekaEntityComparators.equal(amazonInfo, decodedValue), is(true));
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo) AmazonInfo(com.netflix.appinfo.AmazonInfo)

Example 23 with AmazonInfo

use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.

the class PeerAwareInstanceRegistryImpl method isRegisterable.

/**
     * Checks if an instance is registerable in this region. Instances from other regions are rejected.
     *
     * @param instanceInfo  th instance info information of the instance
     * @return true, if it can be registered in this server, false otherwise.
     */
public boolean isRegisterable(InstanceInfo instanceInfo) {
    DataCenterInfo datacenterInfo = instanceInfo.getDataCenterInfo();
    String serverRegion = clientConfig.getRegion();
    if (AmazonInfo.class.isInstance(datacenterInfo)) {
        AmazonInfo info = AmazonInfo.class.cast(instanceInfo.getDataCenterInfo());
        String availabilityZone = info.get(MetaDataKey.availabilityZone);
        // Can be null for dev environments in non-AWS data center
        if (availabilityZone == null && US_EAST_1.equalsIgnoreCase(serverRegion)) {
            return true;
        } else if ((availabilityZone != null) && (availabilityZone.contains(serverRegion))) {
            // If in the same region as server, then consider it registerable
            return true;
        }
    }
    // Everything non-amazon is registrable.
    return true;
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo) AmazonInfo(com.netflix.appinfo.AmazonInfo)

Example 24 with AmazonInfo

use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.

the class AwsAsgUtil method getAccountId.

private String getAccountId(InstanceInfo instanceInfo, String fallbackId) {
    String localAccountId = null;
    DataCenterInfo dataCenterInfo = instanceInfo.getDataCenterInfo();
    if (dataCenterInfo instanceof AmazonInfo) {
        localAccountId = ((AmazonInfo) dataCenterInfo).get(MetaDataKey.accountId);
    }
    return localAccountId == null ? fallbackId : localAccountId;
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo) AmazonInfo(com.netflix.appinfo.AmazonInfo)

Example 25 with AmazonInfo

use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.

the class EIPManager method isEIPBound.

/**
     * Checks if an EIP is already bound to the instance.
     * @return true if an EIP is bound, false otherwise
     */
public boolean isEIPBound() {
    InstanceInfo myInfo = applicationInfoManager.getInfo();
    String myInstanceId = ((AmazonInfo) myInfo.getDataCenterInfo()).get(MetaDataKey.instanceId);
    String myZone = ((AmazonInfo) myInfo.getDataCenterInfo()).get(MetaDataKey.availabilityZone);
    String myPublicIP = ((AmazonInfo) myInfo.getDataCenterInfo()).get(MetaDataKey.publicIpv4);
    Collection<String> candidateEIPs = getCandidateEIPs(myInstanceId, myZone);
    for (String eipEntry : candidateEIPs) {
        if (eipEntry.equals(myPublicIP)) {
            logger.info("My instance {} seems to be already associated with the public ip {}", myInstanceId, myPublicIP);
            return true;
        }
    }
    return false;
}
Also used : AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Aggregations

AmazonInfo (com.netflix.appinfo.AmazonInfo)30 InstanceInfo (com.netflix.appinfo.InstanceInfo)21 Test (org.junit.Test)7 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)6 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)4 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)2 Builder (com.netflix.appinfo.InstanceInfo.Builder)2 DiscoveryClient (com.netflix.discovery.DiscoveryClient)2 Address (com.amazonaws.services.ec2.model.Address)1 AssociateAddressRequest (com.amazonaws.services.ec2.model.AssociateAddressRequest)1 DescribeAddressesRequest (com.amazonaws.services.ec2.model.DescribeAddressesRequest)1 DescribeAddressesResult (com.amazonaws.services.ec2.model.DescribeAddressesResult)1 Ec2EurekaArchaius2InstanceConfig (com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig)1 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)1 LeaseInfo (com.netflix.appinfo.LeaseInfo)1 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)1 UniqueIdentifier (com.netflix.appinfo.UniqueIdentifier)1 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)1 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)1 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)1