com.netflix.eureka.util.StatusInfo Java Examples

The following examples show how to use com.netflix.eureka.util.StatusInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EurekaControllerReplicasTest.java    From didi-eureka-server with MIT License 6 votes vote down vote up
@Test
public void testFilterReplicasAuth() throws Exception {
	Map<String, Object> model = new HashMap<>();
	StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
			.add("registered-replicas", authList2)
			.add("available-replicas", authList1)
			.add("unavailable-replicas", empty)
			.withInstanceInfo(instanceInfo).build();
	EurekaController controller = new EurekaController(null);

	controller.filterReplicas(model, statusInfo);

	@SuppressWarnings("unchecked")
	Map<String, String> results = (Map<String, String>) model.get("applicationStats");
	assertEquals(empty, results.get("unavailable-replicas"));
	assertEquals(noAuthList1, results.get("available-replicas"));
	assertEquals(noAuthList2, results.get("registered-replicas"));

}
 
Example #2
Source File: EurekaControllerReplicasTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterReplicasAuthWithCombinationList() throws Exception {
	Map<String, Object> model = new HashMap<>();
	StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
			.add("registered-replicas", totalAutoList)
			.add("available-replicas", combinationAuthList1)
			.add("unavailable-replicas", combinationAuthList2)
			.withInstanceInfo(instanceInfo).build();
	EurekaController controller = new EurekaController(null);

	controller.filterReplicas(model, statusInfo);

	@SuppressWarnings("unchecked")
	Map<String, String> results = (Map<String, String>) model.get("applicationStats");
	assertThat(results.get("registered-replicas")).isEqualTo(totalNoAutoList);
	assertThat(results.get("available-replicas")).isEqualTo(combinationNoAuthList1);
	assertThat(results.get("unavailable-replicas")).isEqualTo(combinationNoAuthList2);
}
 
Example #3
Source File: EurekaControllerReplicasTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterReplicasAuth() throws Exception {
	Map<String, Object> model = new HashMap<>();
	StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
			.add("registered-replicas", authList2)
			.add("available-replicas", authList1).add("unavailable-replicas", empty)
			.withInstanceInfo(instanceInfo).build();
	EurekaController controller = new EurekaController(null);

	controller.filterReplicas(model, statusInfo);

	@SuppressWarnings("unchecked")
	Map<String, String> results = (Map<String, String>) model.get("applicationStats");
	assertThat(results.get("unavailable-replicas")).isEqualTo(empty);
	assertThat(results.get("available-replicas")).isEqualTo(noAuthList1);
	assertThat(results.get("registered-replicas")).isEqualTo(noAuthList2);

}
 
Example #4
Source File: EurekaControllerReplicasTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterReplicasNoAuth() throws Exception {
	Map<String, Object> model = new HashMap<>();
	StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
			.add("registered-replicas", empty).add("available-replicas", noAuthList1)
			.add("unavailable-replicas", noAuthList2)
			.withInstanceInfo(this.instanceInfo).build();
	EurekaController controller = new EurekaController(null);

	controller.filterReplicas(model, statusInfo);

	@SuppressWarnings("unchecked")
	Map<String, String> results = (Map<String, String>) model.get("applicationStats");
	assertThat(results.get("registered-replicas")).isEqualTo(empty);
	assertThat(results.get("available-replicas")).isEqualTo(noAuthList1);
	assertThat(results.get("unavailable-replicas")).isEqualTo(noAuthList2);

}
 
Example #5
Source File: EurekaController.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
protected void filterReplicas(Map<String, Object> model, StatusInfo statusInfo) {
	Map<String, String> applicationStats = statusInfo.getApplicationStats();
	if (applicationStats.get("registered-replicas").contains("@")) {
		applicationStats.put("registered-replicas",
				scrubBasicAuth(applicationStats.get("registered-replicas")));
	}
	if (applicationStats.get("unavailable-replicas").contains("@")) {
		applicationStats.put("unavailable-replicas",
				scrubBasicAuth(applicationStats.get("unavailable-replicas")));
	}
	if (applicationStats.get("available-replicas").contains("@")) {
		applicationStats.put("available-replicas",
				scrubBasicAuth(applicationStats.get("available-replicas")));
	}
	model.put("applicationStats", applicationStats);
}
 
Example #6
Source File: EurekaController.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #7
Source File: EurekaController.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
private void populateHeader(Map<String, Object> model) {
	model.put("currentTime", StatusResource.getCurrentTimeAsString());
	model.put("upTime", StatusInfo.getUpTime());
	model.put("environment", "N/A"); // FIXME:
	model.put("datacenter", "N/A"); // FIXME:
	PeerAwareInstanceRegistry registry = getRegistry();
	model.put("registry", registry);
	model.put("isBelowRenewThresold", registry.isBelowRenewThresold() == 1);
	DataCenterInfo info = applicationInfoManager.getInfo().getDataCenterInfo();
	if (info.getName() == DataCenterInfo.Name.Amazon) {
		AmazonInfo amazonInfo = (AmazonInfo) info;
		model.put("amazonInfo", amazonInfo);
		model.put("amiId", amazonInfo.get(AmazonInfo.MetaDataKey.amiId));
		model.put("availabilityZone",
				amazonInfo.get(AmazonInfo.MetaDataKey.availabilityZone));
		model.put("instanceId", amazonInfo.get(AmazonInfo.MetaDataKey.instanceId));
	}
}
 
Example #8
Source File: EurekaController.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@RequestMapping(method = RequestMethod.GET)
public String status(HttpServletRequest request, Map<String, Object> model) {
	populateBase(request, model);
	populateApps(model);
	StatusInfo statusInfo;
	try {
		statusInfo = new StatusResource().getStatusInfo();
	}
	catch (Exception e) {
		statusInfo = StatusInfo.Builder.newBuilder().isHealthy(false).build();
	}
	model.put("statusInfo", statusInfo);
	populateInstanceInfo(model, statusInfo);
	filterReplicas(model, statusInfo);
	return "eureka/status";
}
 
Example #9
Source File: EurekaResource.java    From jhipster-registry with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
 
Example #10
Source File: EurekaResource.java    From jhipster-registry with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> getEurekaStatus() {

        Map<String, Object> stats = new HashMap<>();
        stats.put("time", new Date());
        stats.put("currentTime", StatusResource.getCurrentTimeAsString());
        stats.put("upTime", StatusInfo.getUpTime());
        stats.put("environment", ConfigurationManager.getDeploymentContext()
            .getDeploymentEnvironment());
        stats.put("datacenter", ConfigurationManager.getDeploymentContext()
            .getDeploymentDatacenter());

        PeerAwareInstanceRegistry registry = getRegistry();

        stats.put("isBelowRenewThreshold", registry.isBelowRenewThresold() == 1);

        populateInstanceInfo(stats);

        return stats;
    }
 
Example #11
Source File: EurekaResource.java    From flair-registry with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> getEurekaStatus() {

        Map<String, Object> stats = new HashMap<>();
        stats.put("time", new Date());
        stats.put("currentTime", StatusResource.getCurrentTimeAsString());
        stats.put("upTime", StatusInfo.getUpTime());
        stats.put("environment", ConfigurationManager.getDeploymentContext()
            .getDeploymentEnvironment());
        stats.put("datacenter", ConfigurationManager.getDeploymentContext()
            .getDeploymentDatacenter());

        PeerAwareInstanceRegistry registry = getRegistry();

        stats.put("isBelowRenewThreshold", registry.isBelowRenewThresold() == 1);

        populateInstanceInfo(stats);

        return stats;
    }
 
Example #12
Source File: EurekaControllerReplicasTest.java    From didi-eureka-server with MIT License 6 votes vote down vote up
@Test
public void testFilterReplicasNoAuth() throws Exception {
	Map<String, Object> model = new HashMap<>();
	StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
			.add("registered-replicas", empty)
			.add("available-replicas", noAuthList1)
			.add("unavailable-replicas", noAuthList2)
			.withInstanceInfo(this.instanceInfo).build();
	EurekaController controller = new EurekaController(null);

	controller.filterReplicas(model, statusInfo);

	@SuppressWarnings("unchecked")
	Map<String, String> results = (Map<String, String>) model.get("applicationStats");
	assertEquals(empty, results.get("registered-replicas"));
	assertEquals(noAuthList1, results.get("available-replicas"));
	assertEquals(noAuthList2, results.get("unavailable-replicas"));

}
 
Example #13
Source File: EurekaController.java    From didi-eureka-server with MIT License 6 votes vote down vote up
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);
}
 
Example #14
Source File: EurekaController.java    From didi-eureka-server with MIT License 6 votes vote down vote up
private void populateHeader(Map<String, Object> model) {
	model.put("currentTime", StatusResource.getCurrentTimeAsString());
	model.put("upTime", StatusInfo.getUpTime());
	model.put("environment", ConfigurationManager.getDeploymentContext()
			.getDeploymentEnvironment());
	model.put("datacenter", ConfigurationManager.getDeploymentContext()
			.getDeploymentDatacenter());
	PeerAwareInstanceRegistry registry = getRegistry();
	model.put("registry", registry);
	model.put("isBelowRenewThresold", registry.isBelowRenewThresold() == 1);
	DataCenterInfo info = applicationInfoManager.getInfo().getDataCenterInfo();
	if (info.getName() == DataCenterInfo.Name.Amazon) {
		AmazonInfo amazonInfo = (AmazonInfo) info;
		model.put("amazonInfo", amazonInfo);
		model.put("amiId", amazonInfo.get(AmazonInfo.MetaDataKey.amiId));
		model.put("availabilityZone",
				amazonInfo.get(AmazonInfo.MetaDataKey.availabilityZone));
		model.put("instanceId", amazonInfo.get(AmazonInfo.MetaDataKey.instanceId));
	}
}
 
Example #15
Source File: EurekaController.java    From didi-eureka-server with MIT License 6 votes vote down vote up
@RequestMapping(method = RequestMethod.GET)
public String status(HttpServletRequest request, Map<String, Object> model) {
	populateBase(request, model);
	populateApps(model);
	StatusInfo statusInfo;
	try {
		statusInfo = new StatusResource().getStatusInfo();
	}
	catch (Exception e) {
		statusInfo = StatusInfo.Builder.newBuilder().isHealthy(false).build();
	}
	model.put("statusInfo", statusInfo);
	populateInstanceInfo(model, statusInfo);
	filterReplicas(model, statusInfo);
	return "eureka/status";
}
 
Example #16
Source File: EurekaResource.java    From jhipster-microservices-example with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
 
Example #17
Source File: EurekaResource.java    From jhipster-microservices-example with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> getEurekaStatus() {

        Map<String, Object> stats = new HashMap<>();
        stats.put("time", new Date());
        stats.put("currentTime", StatusResource.getCurrentTimeAsString());
        stats.put("upTime", StatusInfo.getUpTime());
        stats.put("environment", ConfigurationManager.getDeploymentContext()
            .getDeploymentEnvironment());
        stats.put("datacenter", ConfigurationManager.getDeploymentContext()
            .getDeploymentDatacenter());

        PeerAwareInstanceRegistry registry = getRegistry();

        stats.put("isBelowRenewThreshold", registry.isBelowRenewThresold() == 1);

        populateInstanceInfo(stats);

        return stats;
    }
 
Example #18
Source File: EurekaResource.java    From flair-registry with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
 
Example #19
Source File: EurekaController.java    From didi-eureka-server with MIT License 5 votes vote down vote up
protected void filterReplicas(Map<String, Object> model, StatusInfo statusInfo) {
	Map<String, String> applicationStats = statusInfo.getApplicationStats();
	if(applicationStats.get("registered-replicas").contains("@")){
		applicationStats.put("registered-replicas", scrubBasicAuth(applicationStats.get("registered-replicas")));
	}
	if(applicationStats.get("unavailable-replicas").contains("@")){
		applicationStats.put("unavailable-replicas",scrubBasicAuth(applicationStats.get("unavailable-replicas")));
	}
	if(applicationStats.get("available-replicas").contains("@")){
		applicationStats.put("available-replicas",scrubBasicAuth(applicationStats.get("available-replicas")));
	}
	model.put("applicationStats", applicationStats);
}