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))));
}
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))));
}
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));
}
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");
}
}
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();
}
Aggregations