Search in sources :

Example 11 with AmazonInfo

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

the class EurekaJsonAndXmlJacksonCodecTest method doAmazonInfoCompactEncodeDecodeTest.

private void doAmazonInfoCompactEncodeDecodeTest(AbstractEurekaJacksonCodec codec) throws Exception {
    AmazonInfo amazonInfo = (AmazonInfo) infoIterator.next().getDataCenterInfo();
    String encodedString = codec.getObjectMapper(DataCenterInfo.class).writeValueAsString(amazonInfo);
    AmazonInfo decodedValue = (AmazonInfo) codec.getObjectMapper(DataCenterInfo.class).readValue(encodedString, DataCenterInfo.class);
    assertThat(decodedValue.get(MetaDataKey.publicHostname), is(equalTo(amazonInfo.get(MetaDataKey.publicHostname))));
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo) AmazonInfo(com.netflix.appinfo.AmazonInfo)

Example 12 with AmazonInfo

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

the class EurekaJsonAndXmlJacksonCodecTest method doInstanceInfoIgnoredFieldsAreFilteredOutDuringDeserializationProcess.

public void doInstanceInfoIgnoredFieldsAreFilteredOutDuringDeserializationProcess(AbstractEurekaJacksonCodec fullCodec, AbstractEurekaJacksonCodec compactCodec) throws Exception {
    InstanceInfo instanceInfo = infoIterator.next();
    // We use regular codec here to have all fields serialized
    String encodedString = fullCodec.getObjectMapper(InstanceInfo.class).writeValueAsString(instanceInfo);
    InstanceInfo decodedValue = compactCodec.getObjectMapper(InstanceInfo.class).readValue(encodedString, InstanceInfo.class);
    assertThat(decodedValue.getId(), is(equalTo(instanceInfo.getId())));
    assertThat(decodedValue.getAppName(), is(equalTo(instanceInfo.getAppName())));
    assertThat(decodedValue.getIPAddr(), is(equalTo(instanceInfo.getIPAddr())));
    assertThat(decodedValue.getVIPAddress(), is(equalTo(instanceInfo.getVIPAddress())));
    assertThat(decodedValue.getSecureVipAddress(), is(equalTo(instanceInfo.getSecureVipAddress())));
    assertThat(decodedValue.getHostName(), is(equalTo(instanceInfo.getHostName())));
    assertThat(decodedValue.getStatus(), is(equalTo(instanceInfo.getStatus())));
    assertThat(decodedValue.getActionType(), is(equalTo(instanceInfo.getActionType())));
    assertThat(decodedValue.getASGName(), is(equalTo(instanceInfo.getASGName())));
    assertThat(decodedValue.getLastUpdatedTimestamp(), is(equalTo(instanceInfo.getLastUpdatedTimestamp())));
    AmazonInfo sourceAmazonInfo = (AmazonInfo) instanceInfo.getDataCenterInfo();
    AmazonInfo decodedAmazonInfo = (AmazonInfo) decodedValue.getDataCenterInfo();
    assertThat(decodedAmazonInfo.get(MetaDataKey.accountId), is(equalTo(sourceAmazonInfo.get(MetaDataKey.accountId))));
}
Also used : AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 13 with AmazonInfo

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

the class AwsAsgUtilTest method setUp.

@Before
public void setUp() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("eureka.awsAccessId", "fakeId");
    ConfigurationManager.getConfigInstance().setProperty("eureka.awsSecretKey", "fakeKey");
    AmazonInfo dataCenterInfo = mock(AmazonInfo.class);
    EurekaServerConfig serverConfig = new DefaultEurekaServerConfig();
    InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder();
    builder.setIPAddr("10.10.101.00");
    builder.setHostName("fakeHost");
    builder.setAppName("fake-" + UUID.randomUUID());
    builder.setLeaseInfo(LeaseInfo.Builder.newBuilder().build());
    builder.setDataCenterInfo(dataCenterInfo);
    instanceInfo = builder.build();
    applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), instanceInfo);
    DefaultEurekaClientConfig clientConfig = new DefaultEurekaClientConfig();
    // setup config in advance, used in initialize converter
    client = mock(DiscoveryClient.class);
    registry = mock(PeerAwareInstanceRegistry.class);
    awsAsgUtil = spy(new AwsAsgUtil(serverConfig, clientConfig, registry));
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) DefaultEurekaServerConfig(com.netflix.eureka.DefaultEurekaServerConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) AwsAsgUtil(com.netflix.eureka.aws.AwsAsgUtil) DefaultEurekaServerConfig(com.netflix.eureka.DefaultEurekaServerConfig) EurekaServerConfig(com.netflix.eureka.EurekaServerConfig) DiscoveryClient(com.netflix.discovery.DiscoveryClient) AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) Before(org.junit.Before)

Example 14 with AmazonInfo

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

the class ApplicationResourceTest method testBadRegistrationOfDataCenterInfo.

@Test
public void testBadRegistrationOfDataCenterInfo() throws Exception {
    try {
        // test 400 when configured to return client error
        ConfigurationManager.getConfigInstance().setProperty("eureka.experimental.registration.validation.dataCenterInfoId", "true");
        InstanceInfo instanceInfo = spy(InstanceInfoGenerator.takeOne());
        when(instanceInfo.getDataCenterInfo()).thenReturn(new TestDataCenterInfo());
        Response response = applicationResource.addInstance(instanceInfo, false + "");
        assertThat(response.getStatus(), is(400));
        // test backfill of data for AmazonInfo
        ConfigurationManager.getConfigInstance().setProperty("eureka.experimental.registration.validation.dataCenterInfoId", "false");
        instanceInfo = spy(InstanceInfoGenerator.takeOne());
        assertThat(instanceInfo.getDataCenterInfo(), instanceOf(AmazonInfo.class));
        // clear the Id
        ((AmazonInfo) instanceInfo.getDataCenterInfo()).getMetadata().remove(AmazonInfo.MetaDataKey.instanceId.getName());
        response = applicationResource.addInstance(instanceInfo, false + "");
        assertThat(response.getStatus(), is(204));
    } finally {
        ConfigurationManager.getConfigInstance().clearProperty("eureka.experimental.registration.validation.dataCenterInfoId");
    }
}
Also used : Response(javax.ws.rs.core.Response) AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 15 with AmazonInfo

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

the class InstanceInfoGenerator method generateInstanceInfo.

// useInstanceId to false to generate older InstanceInfo types that does not use instanceId field for instance id.
private InstanceInfo generateInstanceInfo(int appIndex, int appInstanceId, boolean useInstanceId) {
    String appName = appNames[appIndex];
    String hostName = "instance" + appInstanceId + '.' + appName + ".com";
    String privateHostname = "ip-10.0" + appIndex + "." + appInstanceId + ".compute.internal";
    String publicIp = "20.0." + appIndex + '.' + appInstanceId;
    String privateIp = "192.168." + appIndex + '.' + appInstanceId;
    String instanceId = String.format("i-%04d%04d", appIndex, appInstanceId);
    if (taggedId) {
        instanceId = instanceId + '_' + appName;
    }
    AmazonInfo dataCenterInfo = AmazonInfo.Builder.newBuilder().addMetadata(MetaDataKey.accountId, "testAccountId").addMetadata(MetaDataKey.amiId, String.format("ami-%04d%04d", appIndex, appInstanceId)).addMetadata(MetaDataKey.availabilityZone, zone).addMetadata(MetaDataKey.instanceId, instanceId).addMetadata(MetaDataKey.instanceType, "m2.xlarge").addMetadata(MetaDataKey.localHostname, privateHostname).addMetadata(MetaDataKey.localIpv4, privateIp).addMetadata(MetaDataKey.publicHostname, hostName).addMetadata(MetaDataKey.publicIpv4, publicIp).build();
    String unsecureURL = "http://" + hostName + ":8080";
    String secureURL = "https://" + hostName + ":8081";
    long now = System.currentTimeMillis();
    LeaseInfo leaseInfo = LeaseInfo.Builder.newBuilder().setDurationInSecs(3 * RENEW_INTERVAL).setRenewalIntervalInSecs(RENEW_INTERVAL).setServiceUpTimestamp(now - RENEW_INTERVAL).setRegistrationTimestamp(now).setEvictionTimestamp(now + 3 * RENEW_INTERVAL).setRenewalTimestamp(now + RENEW_INTERVAL).build();
    Builder builder = useInstanceId ? InstanceInfo.Builder.newBuilder().setInstanceId(instanceId) : InstanceInfo.Builder.newBuilder();
    builder.setActionType(ActionType.ADDED).setAppGroupName(appName + "Group").setAppName(appName).setHostName(hostName).setIPAddr(publicIp).setPort(8080).setSecurePort(8081).enablePort(PortType.SECURE, true).setHealthCheckUrls("/healthcheck", unsecureURL + "/healthcheck", secureURL + "/healthcheck").setHomePageUrl("/homepage", unsecureURL + "/homepage").setStatusPageUrl("/status", unsecureURL + "/status").setLeaseInfo(leaseInfo).setStatus(InstanceStatus.UP).setVIPAddress(appName + ":8080").setSecureVIPAddress(appName + ":8081").setDataCenterInfo(dataCenterInfo).setLastUpdatedTimestamp(System.currentTimeMillis() - 100).setLastDirtyTimestamp(System.currentTimeMillis() - 100).setIsCoordinatingDiscoveryServer(true).enablePort(PortType.UNSECURE, true);
    if (includeAsg) {
        builder.setASGName(appName + "ASG");
    }
    if (withMetaData) {
        builder.add("appKey" + appIndex, Integer.toString(appInstanceId));
    }
    return builder.build();
}
Also used : Builder(com.netflix.appinfo.InstanceInfo.Builder) LeaseInfo(com.netflix.appinfo.LeaseInfo) AmazonInfo(com.netflix.appinfo.AmazonInfo)

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