use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class InstanceInfoXmlBeanSerializer method serializeFields.
@Override
protected void serializeFields(Object bean, JsonGenerator jgen0, SerializerProvider provider) throws IOException {
super.serializeFields(bean, jgen0, provider);
InstanceInfo instanceInfo = (InstanceInfo) bean;
ToXmlGenerator xgen = (ToXmlGenerator) jgen0;
xgen.writeFieldName("port");
xgen.writeStartObject();
xgen.setNextIsAttribute(true);
xgen.writeFieldName("enabled");
xgen.writeBoolean(instanceInfo.isPortEnabled(PortType.UNSECURE));
xgen.setNextIsAttribute(false);
xgen.writeFieldName("port");
xgen.setNextIsUnwrapped(true);
xgen.writeString(Integer.toString(instanceInfo.getPort()));
xgen.writeEndObject();
xgen.writeFieldName("securePort");
xgen.writeStartObject();
xgen.setNextIsAttribute(true);
xgen.writeStringField("enabled", Boolean.toString(instanceInfo.isPortEnabled(PortType.SECURE)));
xgen.setNextIsAttribute(false);
xgen.writeFieldName("securePort");
xgen.setNextIsUnwrapped(true);
xgen.writeString(Integer.toString(instanceInfo.getSecurePort()));
xgen.writeEndObject();
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class DiscoveryManager method initComponent.
/**
* Initializes the <tt>Discovery Client</tt> with the given configuration.
*
* @param config
* the instance info configuration that will be used for
* registration with Eureka.
* @param eurekaConfig the eureka client configuration of the instance.
*/
public void initComponent(EurekaInstanceConfig config, EurekaClientConfig eurekaConfig, AbstractDiscoveryClientOptionalArgs args) {
this.eurekaInstanceConfig = config;
this.eurekaClientConfig = eurekaConfig;
if (ApplicationInfoManager.getInstance().getInfo() == null) {
// Initialize application info
ApplicationInfoManager.getInstance().initComponent(config);
}
InstanceInfo info = ApplicationInfoManager.getInstance().getInfo();
discoveryClient = new DiscoveryClient(info, eurekaConfig, args);
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class AbstractJersey2EurekaHttpClient method getInstanceInternal.
private EurekaHttpResponse<InstanceInfo> getInstanceInternal(String urlPath) {
Response response = null;
try {
Builder requestBuilder = jerseyClient.target(serviceUrl).path(urlPath).request();
addExtraProperties(requestBuilder);
addExtraHeaders(requestBuilder);
response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get();
InstanceInfo infoFromPeer = null;
if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
infoFromPeer = response.readEntity(InstanceInfo.class);
}
return anEurekaHttpResponse(response.getStatus(), infoFromPeer).headers(headersOf(response)).build();
} finally {
if (logger.isDebugEnabled()) {
logger.debug("Jersey2 HTTP GET {}/{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
}
if (response != null) {
response.close();
}
}
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class Jersey2EurekaModuleTest method testDI.
@SuppressWarnings("deprecation")
@Test
public void testDI() {
InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
EurekaClient eurekaClient = injector.getInstance(EurekaClient.class);
DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClient(), eurekaClient);
Assert.assertEquals(DiscoveryManager.getInstance().getDiscoveryClient(), discoveryClient);
Assert.assertEquals(eurekaClient, discoveryClient);
EurekaClientConfig eurekaClientConfig = injector.getInstance(EurekaClientConfig.class);
Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClientConfig(), eurekaClientConfig);
EurekaInstanceConfig eurekaInstanceConfig = injector.getInstance(EurekaInstanceConfig.class);
Assert.assertEquals(DiscoveryManager.getInstance().getEurekaInstanceConfig(), eurekaInstanceConfig);
Binding<TransportClientFactories> binding = injector.getExistingBinding(Key.get(TransportClientFactories.class));
// has a binding for jersey2
Assert.assertNotNull(binding);
TransportClientFactories transportClientFactories = injector.getInstance(TransportClientFactories.class);
Assert.assertTrue(transportClientFactories instanceof Jersey2TransportClientFactories);
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class Application method _shuffleAndStoreInstances.
private void _shuffleAndStoreInstances(boolean filterUpInstances, boolean indexByRemoteRegions, @Nullable Map<String, Applications> remoteRegionsRegistry, @Nullable EurekaClientConfig clientConfig, @Nullable InstanceRegionChecker instanceRegionChecker) {
List<InstanceInfo> instanceInfoList;
synchronized (instances) {
instanceInfoList = new ArrayList<InstanceInfo>(instances);
}
if (indexByRemoteRegions || filterUpInstances) {
Iterator<InstanceInfo> it = instanceInfoList.iterator();
while (it.hasNext()) {
InstanceInfo instanceInfo = it.next();
if (filterUpInstances && !InstanceStatus.UP.equals(instanceInfo.getStatus())) {
it.remove();
} else if (indexByRemoteRegions && null != instanceRegionChecker && null != clientConfig && null != remoteRegionsRegistry) {
String instanceRegion = instanceRegionChecker.getInstanceRegion(instanceInfo);
if (!instanceRegionChecker.isLocalRegion(instanceRegion)) {
Applications appsForRemoteRegion = remoteRegionsRegistry.get(instanceRegion);
if (null == appsForRemoteRegion) {
appsForRemoteRegion = new Applications();
remoteRegionsRegistry.put(instanceRegion, appsForRemoteRegion);
}
Application remoteApp = appsForRemoteRegion.getRegisteredApplications(instanceInfo.getAppName());
if (null == remoteApp) {
remoteApp = new Application(instanceInfo.getAppName());
appsForRemoteRegion.addApplication(remoteApp);
}
remoteApp.addInstance(instanceInfo);
this.removeInstance(instanceInfo, false);
it.remove();
}
}
}
}
Collections.shuffle(instanceInfoList);
this.shuffledInstances.set(instanceInfoList);
}
Aggregations