DashboardREST { @GET @Path("/{serviceId}/{appId}") @Produces(MediaType.APPLICATION_JSON) public Response getAppHistoryMetrics(@PathParam("serviceId") String serviceId, @PathParam("appId") String appId, @QueryParam("newerThan") long newerThan, @QueryParam("timeRange") long timeRange) { long now = new Date().getTime(); if (timeRange == 0) timeRange = Constants.DASHBORAD_TIME_RANGE; if (newerThan == 0) { newerThan = now - timeRange * 60 * 1000; } Map<String, Object> responseMap = new HashMap<String, Object>(); List<AppInstanceMetrics> stats = new ArrayList<AppInstanceMetrics>(); ApplicationMetrics appMetrics = MonitorController.getInstance().getAppMetrics(appId); try { if (MonitorController.getInstance().sotore2db()) { stats = AutoScalingDataStoreFactory .getAutoScalingDataStore().getAppStatsHistoryByAppIdAfter(appId, newerThan); } if ( (appMetrics != null) && (stats.size() == 0) ) { AppInstanceMetrics lastestMetrics = appMetrics.mergeToAppInstanceMetrics(false, false); if (lastestMetrics.getInstanceMetrics().size() > 0) stats.add(lastestMetrics); else{ int instanceNumber = appMetrics.getPollerMetricsMap().size(); stats.add(createFakeMetrics(instanceNumber, now)); } } if ( (appMetrics == null) && ( stats.size() > 0) ) { int instanceNumber = stats.get(stats.size()-1).getInstanceMetrics().size(); stats.add(createFakeMetrics(instanceNumber, now)); } responseMap.put("data", stats); MetricConfigManager configService = MetricConfigManager.getInstance(); String appType = null; BoundApp boundApp = MonitorController.getInstance().getBoundApp(serviceId, appId); if (boundApp != null) { appType = boundApp.getAppType(); } Map<String, Object> configMap = configService.loadDefaultConfig(appType, appId); responseMap.put("config", configMap); return RestApiResponseHandler.getResponseOk(mapper.writeValueAsString(responseMap)); } catch (Exception e) { logger.error("Internal_Server_Error", e); return RestApiResponseHandler.getResponse(Status.INTERNAL_SERVER_ERROR); } }  @GET @Path("/{serviceId}") @Produces(MediaType.APPLICATION_JSON) @SuppressWarnings({ "rawtypes", "unchecked" }) Response getAppMetricsLastestData(@PathParam("serviceId") String serviceId, @QueryParam("appId") String appId); @GET @Path("/{serviceId}/{appId}") @Produces(MediaType.APPLICATION_JSON) Response getAppHistoryMetrics(@PathParam("serviceId") String serviceId, @PathParam("appId") String appId,
            @QueryParam("newerThan") long newerThan, @QueryParam("timeRange") long timeRange); @GET @Path("/default/{appType}") @Produces(MediaType.APPLICATION_JSON) Response getAppHistoryMetrics(@PathParam("serviceId") String serviceId, @PathParam("appType") String appType);  }
@Test public void testGetAppHistoryMetrics(){ WebResource webResource = resource(); MultivaluedMap<String, String> map = new MultivaluedMapImpl(); map.add("appId", TESTAPPID); ClientResponse response = webResource.path("/metrics/"+TESTSERVICEID+"/"+TESTAPPID).get(ClientResponse.class); assertEquals(response.getStatus(), STATUS200); }