use of com.netflix.appinfo.DataCenterInfo in project eureka by Netflix.
the class DiscoveryClientRegistryTest method testApplyDeltaWithBadInstanceInfoDataCenterInfoAsNull.
@Test
public void testApplyDeltaWithBadInstanceInfoDataCenterInfoAsNull() throws Exception {
InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build();
// Full fetch with one item
InstanceInfo first = instanceGen.first();
Applications initial = toApplications(first);
when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, initial).type(MediaType.APPLICATION_JSON_TYPE).build());
EurekaClient client = discoveryClientResource.getClient();
assertThat(client.getApplications().getAppsHashCode(), is(equalTo("UP_1_")));
// Delta with one add
InstanceInfo second = new InstanceInfo.Builder(instanceGen.take(1)).setInstanceId("foo1").setStatus(InstanceStatus.DOWN).setDataCenterInfo(null).build();
InstanceInfo third = new InstanceInfo.Builder(instanceGen.take(1)).setInstanceId("foo2").setStatus(InstanceStatus.UP).setDataCenterInfo(new DataCenterInfo() {
@Override
public Name getName() {
return null;
}
}).build();
Applications delta = toApplications(second, third);
delta.setAppsHashCode("DOWN_1_UP_2_");
when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build());
assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
assertThat(client.getApplications().getAppsHashCode(), is(equalTo("DOWN_1_UP_2_")));
}
use of com.netflix.appinfo.DataCenterInfo in project eureka by Netflix.
the class ResolverUtils method instanceInfoToEndpoint.
public static AwsEndpoint instanceInfoToEndpoint(EurekaClientConfig clientConfig, EurekaTransportConfig transportConfig, InstanceInfo instanceInfo) {
String zone = null;
DataCenterInfo dataCenterInfo = instanceInfo.getDataCenterInfo();
if (dataCenterInfo instanceof AmazonInfo) {
zone = ((AmazonInfo) dataCenterInfo).get(AmazonInfo.MetaDataKey.availabilityZone);
}
String networkAddress;
if (transportConfig.applicationsResolverUseIp()) {
if (instanceInfo.getDataCenterInfo() instanceof AmazonInfo) {
networkAddress = ((AmazonInfo) instanceInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.localIpv4);
} else {
networkAddress = instanceInfo.getIPAddr();
}
} else {
networkAddress = instanceInfo.getHostName();
}
if (networkAddress == null) {
// final check
logger.error("Cannot resolve InstanceInfo {} to a proper resolver endpoint, skipping", instanceInfo);
return null;
}
return new AwsEndpoint(networkAddress, instanceInfo.getPort(), false, clientConfig.getEurekaServerURLContext(), clientConfig.getRegion(), zone);
}
use of com.netflix.appinfo.DataCenterInfo in project eureka by Netflix.
the class DiscoveryClientDisableRegistryTest method setUp.
@Before
public void setUp() throws Exception {
mockLocalEurekaServer = new MockRemoteEurekaServer();
mockLocalEurekaServer.start();
ConfigurationManager.getConfigInstance().setProperty("eureka.registration.enabled", "false");
ConfigurationManager.getConfigInstance().setProperty("eureka.shouldFetchRegistry", "false");
ConfigurationManager.getConfigInstance().setProperty("eureka.serviceUrl.default", "http://localhost:" + mockLocalEurekaServer.getPort() + MockRemoteEurekaServer.EUREKA_API_BASE_PATH);
InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder();
builder.setIPAddr("10.10.101.00");
builder.setHostName("Hosttt");
builder.setAppName("EurekaTestApp-" + UUID.randomUUID());
builder.setDataCenterInfo(new DataCenterInfo() {
@Override
public Name getName() {
return Name.MyOwn;
}
});
ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), builder.build());
client = new DiscoveryClient(applicationInfoManager, new DefaultEurekaClientConfig());
}
use of com.netflix.appinfo.DataCenterInfo in project eureka by Netflix.
the class EurekaUtilsTest method testIsInVpc.
@Test
public void testIsInVpc() {
InstanceInfo instanceInfo1 = new InstanceInfo.Builder(InstanceInfoGenerator.takeOne()).setDataCenterInfo(new DataCenterInfo() {
@Override
public Name getName() {
return Name.MyOwn;
}
}).build();
Assert.assertFalse(EurekaUtils.isInVpc(instanceInfo1));
InstanceInfo instanceInfo2 = InstanceInfoGenerator.takeOne();
Assert.assertFalse(EurekaUtils.isInVpc(instanceInfo2));
InstanceInfo instanceInfo3 = InstanceInfoGenerator.takeOne();
((AmazonInfo) instanceInfo3.getDataCenterInfo()).getMetadata().put(AmazonInfo.MetaDataKey.vpcId.getName(), "vpc-123456");
Assert.assertTrue(EurekaUtils.isInVpc(instanceInfo3));
}
use of com.netflix.appinfo.DataCenterInfo in project eureka by Netflix.
the class ApplicationResource method addInstance.
/**
* Registers information about a particular instance for an
* {@link com.netflix.discovery.shared.Application}.
*
* @param info
* {@link InstanceInfo} information of the instance.
* @param isReplication
* a header parameter containing information whether this is
* replicated from other nodes.
*/
@POST
@Consumes({ "application/json", "application/xml" })
public Response addInstance(InstanceInfo info, @HeaderParam(PeerEurekaNode.HEADER_REPLICATION) String isReplication) {
logger.debug("Registering instance {} (replication={})", info.getId(), isReplication);
// validate that the instanceinfo contains all the necessary required fields
if (isBlank(info.getId())) {
return Response.status(400).entity("Missing instanceId").build();
} else if (isBlank(info.getHostName())) {
return Response.status(400).entity("Missing hostname").build();
} else if (isBlank(info.getAppName())) {
return Response.status(400).entity("Missing appName").build();
} else if (!appName.equals(info.getAppName())) {
return Response.status(400).entity("Mismatched appName, expecting " + appName + " but was " + info.getAppName()).build();
} else if (info.getDataCenterInfo() == null) {
return Response.status(400).entity("Missing dataCenterInfo").build();
} else if (info.getDataCenterInfo().getName() == null) {
return Response.status(400).entity("Missing dataCenterInfo Name").build();
}
// handle cases where clients may be registering with bad DataCenterInfo with missing data
DataCenterInfo dataCenterInfo = info.getDataCenterInfo();
if (dataCenterInfo instanceof UniqueIdentifier) {
String dataCenterInfoId = ((UniqueIdentifier) dataCenterInfo).getId();
if (isBlank(dataCenterInfoId)) {
boolean experimental = "true".equalsIgnoreCase(serverConfig.getExperimental("registration.validation.dataCenterInfoId"));
if (experimental) {
String entity = "DataCenterInfo of type " + dataCenterInfo.getClass() + " must contain a valid id";
return Response.status(400).entity(entity).build();
} else if (dataCenterInfo instanceof AmazonInfo) {
AmazonInfo amazonInfo = (AmazonInfo) dataCenterInfo;
String effectiveId = amazonInfo.get(AmazonInfo.MetaDataKey.instanceId);
if (effectiveId == null) {
amazonInfo.getMetadata().put(AmazonInfo.MetaDataKey.instanceId.getName(), info.getId());
}
} else {
logger.warn("Registering DataCenterInfo of type {} without an appropriate id", dataCenterInfo.getClass());
}
}
}
registry.register(info, "true".equals(isReplication));
// 204 to be backwards compatible
return Response.status(204).build();
}
Aggregations