当前位置: 首页>>代码示例>>Java>>正文


Java InstanceInfo类代码示例

本文整理汇总了Java中com.netflix.appinfo.InstanceInfo的典型用法代码示例。如果您正苦于以下问题:Java InstanceInfo类的具体用法?Java InstanceInfo怎么用?Java InstanceInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InstanceInfo类属于com.netflix.appinfo包,在下文中一共展示了InstanceInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getApplications

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
private List<Map<String, Object>> getApplications() {
    List<Application> sortedApplications = getRegistry().getSortedApplications();
    ArrayList<Map<String, Object>> apps = new ArrayList<>();
    for (Application app : sortedApplications) {
        LinkedHashMap<String, Object> appData = new LinkedHashMap<>();
        apps.add(appData);
        appData.put("name", app.getName());
        List<Map<String, Object>> instances = new ArrayList<>();
        for (InstanceInfo info : app.getInstances()) {
            Map<String, Object> instance = new HashMap<>();
            instance.put("instanceId", info.getInstanceId());
            instance.put("homePageUrl", info.getHomePageUrl());
            instance.put("healthCheckUrl", info.getHealthCheckUrl());
            instance.put("statusPageUrl", info.getStatusPageUrl());
            instance.put("status", info.getStatus().name());
            instance.put("metadata", info.getMetadata());
            instances.add(instance);
        }
        appData.put("instances", instances);
    }
    return apps;
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:23,代码来源:EurekaResource.java

示例2: populateInstanceInfo

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
private void populateInstanceInfo(Map<String, Object> model) {

        StatusInfo statusInfo;
        try {
            statusInfo = new StatusResource().getStatusInfo();
        } catch (Exception e) {
            log.error(e.getMessage());
            statusInfo = StatusInfo.Builder.newBuilder().isHealthy(false).build();
        }
        if (statusInfo != null && statusInfo.getGeneralStats() != null) {
            model.put("generalStats", statusInfo.getGeneralStats());
        }
        if (statusInfo != null && statusInfo.getInstanceInfo() != null) {
            InstanceInfo instanceInfo = statusInfo.getInstanceInfo();
            Map<String, String> instanceMap = new HashMap<>();
            instanceMap.put("ipAddr", instanceInfo.getIPAddr());
            instanceMap.put("status", instanceInfo.getStatus().toString());
            model.put("instanceInfo", instanceMap);
        }
    }
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:21,代码来源:EurekaResource.java

示例3: getAllUsingCereebroMetadata

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
@Test
public void getAllUsingCereebroMetadata() throws IOException {
    Mockito.when(eurekaServerContextMock.getRegistry()).thenReturn(instanceRegistryMock);
    String uri = "http://not-used.never.nope";
    String json = "{}";
    Map<String, String> metadata = new HashMap<>();
    metadata.put(CereebroMetadata.KEY_SNITCH_URI, uri);
    metadata.put(CereebroMetadata.KEY_SNITCH_SYSTEM_FRAGMENT_JSON, json);
    // @formatter:off
    InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
            .setInstanceId("id")
            .setAppName("a")
            .setMetadata(metadata)
            .build();
    // @formatter:on
    Application application = new Application("a", Arrays.asList(instanceInfo));
    Mockito.when(instanceRegistryMock.getSortedApplications()).thenReturn(Arrays.asList(application));
    Mockito.when(objectMapperMock.readValue(json, SystemFragment.class)).thenReturn(SystemFragment.empty());
    List<Snitch> result = registry.getAll();
    Assertions.assertThat(result).hasSize(1);
    Snitch snitch = result.get(0);
    Assertions.assertThat(snitch.getUri()).isEqualTo(URI.create(uri));
    Assertions.assertThat(snitch.snitch()).isEqualTo(SystemFragment.empty());
}
 
开发者ID:cereebro,项目名称:cereebro,代码行数:25,代码来源:EurekaServerSnitchRegistryTest.java

示例4: getAllWithoutCereebroMetadataShouldUseServiceInstanceInfo

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
@Test
public void getAllWithoutCereebroMetadataShouldUseServiceInstanceInfo() {
    Mockito.when(eurekaServerContextMock.getRegistry()).thenReturn(instanceRegistryMock);

    // @formatter:off
    InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
            .setInstanceId("id")
            .setAppName("a")
            .setMetadata(new HashMap<>())
            .setHostName("service-instance")
            .setPort(6090)
            .build();
    // @formatter:on
    Application application = new Application("a", Arrays.asList(instanceInfo));
    Mockito.when(instanceRegistryMock.getSortedApplications()).thenReturn(Arrays.asList(application));
    List<Snitch> result = registry.getAll();
    Assertions.assertThat(result).hasSize(1);
    Snitch snitch = result.get(0);
    Assertions.assertThat(snitch.getUri()).isEqualTo(URI.create("http://service-instance:6090"));
    Component expectedComponent = Component.of("a", ComponentType.HTTP_APPLICATION);
    SystemFragment expected = SystemFragment.of(ComponentRelationships.of(expectedComponent));
    Assertions.assertThat(snitch.snitch()).isEqualTo(expected);
}
 
开发者ID:cereebro,项目名称:cereebro,代码行数:24,代码来源:EurekaServerSnitchRegistryTest.java

示例5: populateInstanceInfo

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
private void populateInstanceInfo(Map<String, Object> model, StatusInfo statusInfo) {
	InstanceInfo instanceInfo = statusInfo.getInstanceInfo();
	Map<String, String> instanceMap = new HashMap<>();
	instanceMap.put("ipAddr", instanceInfo.getIPAddr());
	instanceMap.put("status", instanceInfo.getStatus().toString());
	if (instanceInfo.getDataCenterInfo().getName() == DataCenterInfo.Name.Amazon) {
		AmazonInfo info = (AmazonInfo) instanceInfo.getDataCenterInfo();
		instanceMap.put("availability-zone",
				info.get(AmazonInfo.MetaDataKey.availabilityZone));
		instanceMap.put("public-ipv4", info.get(AmazonInfo.MetaDataKey.publicIpv4));
		instanceMap.put("instance-id", info.get(AmazonInfo.MetaDataKey.instanceId));
		instanceMap.put("public-hostname",
				info.get(AmazonInfo.MetaDataKey.publicHostname));
		instanceMap.put("ami-id", info.get(AmazonInfo.MetaDataKey.amiId));
		instanceMap.put("instance-type",
				info.get(AmazonInfo.MetaDataKey.instanceType));
	}
	model.put("instanceInfo", instanceMap);
}
 
开发者ID:dyc87112,项目名称:didi-eureka-server,代码行数:20,代码来源:EurekaController.java

示例6: renew

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
@Override
public boolean renew(final String appName, final String serverId,
		boolean isReplication) {
	log("renew " + appName + " serverId " + serverId + ", isReplication {}"
			+ isReplication);
	List<Application> applications = getSortedApplications();
	for (Application input : applications) {
		if (input.getName().equals(appName)) {
			InstanceInfo instance = null;
			for (InstanceInfo info : input.getInstances()) {
				if (info.getId().equals(serverId)) {
					instance = info;
					break;
				}
			}
			publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId,
					instance, isReplication));
			break;
		}
	}
	return super.renew(appName, serverId, isReplication);
}
 
开发者ID:dyc87112,项目名称:didi-eureka-server,代码行数:23,代码来源:InstanceRegistry.java

示例7: testRegister

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
@Test
public void testRegister() throws Exception {
	// creating instance info
	final LeaseInfo leaseInfo = getLeaseInfo();
	final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, leaseInfo);
	// calling tested method
	instanceRegistry.register(instanceInfo, false);
	// event of proper type is registered
	assertEquals(1, this.testEvents.applicationEvents.size());
	assertTrue(this.testEvents.applicationEvents.get(0) instanceof EurekaInstanceRegisteredEvent);
	// event details are correct
	final EurekaInstanceRegisteredEvent registeredEvent =
			(EurekaInstanceRegisteredEvent) (this.testEvents.applicationEvents.get(0));
	assertEquals(instanceInfo, registeredEvent.getInstanceInfo());
	assertEquals(leaseInfo.getDurationInSecs(), registeredEvent.getLeaseDuration());
	assertEquals(instanceRegistry, registeredEvent.getSource());
	assertFalse(registeredEvent.isReplication());
}
 
开发者ID:dyc87112,项目名称:didi-eureka-server,代码行数:19,代码来源:InstanceRegistryTest.java

示例8: getApplications

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
private List<Map<String, Object>> getApplications() {
    List<Application> sortedApplications = getRegistry().getSortedApplications();
    ArrayList<Map<String, Object>> apps = new ArrayList<>();
    for (Application app : sortedApplications) {
        LinkedHashMap<String, Object> appData = new LinkedHashMap<>();
        apps.add(appData);
        appData.put("name", app.getName());
        List<Map<String, String>> instances = new ArrayList<>();
        for (InstanceInfo info : app.getInstances()) {
            Map<String, String> instance = new HashMap<>();
            instance.put("instanceId", info.getInstanceId());
            instance.put("homePageUrl", info.getHomePageUrl());
            instance.put("healthCheckUrl", info.getHealthCheckUrl());
            instance.put("statusPageUrl", info.getStatusPageUrl());
            instance.put("status", info.getStatus().name());
            instances.add(instance);
        }
        appData.put("instances", instances);
    }
    return apps;
}
 
开发者ID:mraible,项目名称:devoxxus-jhipster-microservices-demo,代码行数:22,代码来源:EurekaResource.java

示例9: getServerIP

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
public String getServerIP(String microservice){
	try{
		List<InstanceInfo> infos = getEurekaClient().getApplication(microservice.toUpperCase()).getInstances();
		Iterator<InstanceInfo> it = infos.iterator();
		StringBuffer ips = new StringBuffer();
		
		while(it.hasNext()){
			InstanceInfo info = it.next();
			String serverPort =  "http://" + info.getIPAddr() + ":" + info.getPort();
			ips.append(serverPort);
			if (it.hasNext())
				ips.append(",");
		}
		return ips.toString();
	}catch(Exception e){
		throw new RuntimeException("Could not get Microservice IP:PORT. EX: " + e);
	}
}
 
开发者ID:diegopacheco,项目名称:Building_Effective_Microservices,代码行数:19,代码来源:BaseRibbonTemplate.java

示例10: getMetaService

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
@RequestMapping("/meta")
public List<ServiceDTO> getMetaService() {
  List<InstanceInfo> instances = discoveryService.getMetaServiceInstances();
  List<ServiceDTO> result = instances.stream().map(new Function<InstanceInfo, ServiceDTO>() {

    @Override
    public ServiceDTO apply(InstanceInfo instance) {
      ServiceDTO service = new ServiceDTO();
      service.setAppName(instance.getAppName());
      service.setInstanceId(instance.getInstanceId());
      service.setHomepageUrl(instance.getHomePageUrl());
      return service;
    }

  }).collect(Collectors.toList());
  return result;
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:18,代码来源:ServiceController.java

示例11: getConfigService

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
@RequestMapping("/config")
public List<ServiceDTO> getConfigService(
    @RequestParam(value = "appId", defaultValue = "") String appId,
    @RequestParam(value = "ip", required = false) String clientIp) {
  List<InstanceInfo> instances = discoveryService.getConfigServiceInstances();
  List<ServiceDTO> result = instances.stream().map(new Function<InstanceInfo, ServiceDTO>() {

    @Override
    public ServiceDTO apply(InstanceInfo instance) {
      ServiceDTO service = new ServiceDTO();
      service.setAppName(instance.getAppName());
      service.setInstanceId(instance.getInstanceId());
      service.setHomepageUrl(instance.getHomePageUrl());
      return service;
    }

  }).collect(Collectors.toList());
  return result;
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:20,代码来源:ServiceController.java

示例12: getAdminService

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
@RequestMapping("/admin")
public List<ServiceDTO> getAdminService() {
  List<InstanceInfo> instances = discoveryService.getAdminServiceInstances();
  List<ServiceDTO> result = instances.stream().map(new Function<InstanceInfo, ServiceDTO>() {

    @Override
    public ServiceDTO apply(InstanceInfo instance) {
      ServiceDTO service = new ServiceDTO();
      service.setAppName(instance.getAppName());
      service.setInstanceId(instance.getInstanceId());
      service.setHomepageUrl(instance.getHomePageUrl());
      return service;
    }

  }).collect(Collectors.toList());
  return result;
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:18,代码来源:ServiceController.java

示例13: shouldOnlyDiscoverInstancesWithUpStatus

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
@Test
public void shouldOnlyDiscoverInstancesWithUpStatus(){
    Application application = new Application();
    List<InstanceInfo> infoList = InstanceInfoGenerator
            .newBuilder(5, 1)
            .build()
            .toInstanceList();
    for (InstanceInfo info : infoList) {
        info.setStatus(InstanceInfo.InstanceStatus.DOWN);
        application.addInstance(info);
    }

    when(eurekaClient.getApplication(APPLICATION_NAME)).thenReturn(application);

    Iterable<DiscoveryNode> nodes = strategy.discoverNodes();
    assertThat(nodes.iterator().hasNext(), is(false));
}
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:18,代码来源:EurekaOneDiscoveryStrategyTest.java

示例14: shouldOnlyDiscoverInstancesWithValidAddress

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
@Test
public void shouldOnlyDiscoverInstancesWithValidAddress(){
    Application application = new Application();
    InstanceInfo mockInfo = mock(InstanceInfo.class);
    when(mockInfo.getId()).thenReturn(RandomStringUtils.random(42));
    when(mockInfo.getStatus()).thenReturn(InstanceInfo.InstanceStatus.UP);
    when(mockInfo.getIPAddr()).thenReturn("local");

    application.addInstance(mockInfo);

    when(eurekaClient.getApplication(APPLICATION_NAME)).thenReturn(application);

    Iterable<DiscoveryNode> nodes = strategy.discoverNodes();

    verify(eurekaClient).getApplication(APPLICATION_NAME);
    verify(mockInfo).getStatus();
    verify(mockInfo).getIPAddr();

    assertThat(nodes.iterator().hasNext(), is(false));
}
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:21,代码来源:EurekaOneDiscoveryStrategyTest.java

示例15: testSimpleDiscovery

import com.netflix.appinfo.InstanceInfo; //导入依赖的package包/类
@Test
public void testSimpleDiscovery(){
    ArgumentCaptor<InstanceInfo> captor = ArgumentCaptor.forClass(InstanceInfo.class);

    EurekaHttpResponse<Applications> response = generateMockResponse(Collections.<InstanceInfo>emptyList());
    when(requestHandler.getApplications()).thenReturn(response);

    HazelcastInstance hz1 = factory.newHazelcastInstance();
    HazelcastInstance hz2 = factory.newHazelcastInstance();

    verify(requestHandler, timeout(5000).times(2)).register(captor.capture());
    response = generateMockResponse(captor.getAllValues());
    when(requestHandler.getApplications()).thenReturn(response);

    assertClusterSizeEventually(2, hz1);
    assertClusterSizeEventually(2, hz2);

    HazelcastInstance client = factory.newHazelcastClient();
    reset(requestHandler);
    when(requestHandler.getApplications()).thenReturn(response);
    verify(requestHandler, timeout(1000).times(0)).register(Matchers.<InstanceInfo>any());
    assertClusterSizeEventually(2, client);
}
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:24,代码来源:HazelcastClientTestCase.java


注:本文中的com.netflix.appinfo.InstanceInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。