@Test public void testDoApiDashboardDataLoad() throws Exception{ TestDaoService daoService = new TestDaoService(); new MockUp<DBQueryUtil>() { @Mock public List<EnvironmentVO> getAllEnvironments() throws SerialException, SQLException{ EnvironmentVO env = new EnvironmentVO(); env.setEnvironmentName("Development"); File resourcesDirectory = new File("src/test/data"); String content = null; try { content = new String ( Files.readAllBytes( Paths.get(resourcesDirectory.getAbsolutePath()+"/marathonJson.txt") ) ); } catch (IOException e) { e.printStackTrace(); } env.setMarathonJson(content); List<EnvironmentVO> envList = new ArrayList<EnvironmentVO>(); envList.add(env); return envList; } @Mock public Map<String, String> getPromLookupDetails(int envId, String platform){ Map<String, String> promMap = new HashMap<String, String>(); promMap.put("ssp/prod/dc2/ssp-prod-dc2-promotion-v1", "http: return promMap; } @Mock public Set<Integer> getAppsLauchDateNull(int envId) { Set<Integer> compSet = new HashSet<Integer>(); compSet.add(1); return compSet; } }; APIDashboardTask.doApiDashboardDataLoad(); }
public static void doApiDashboardDataLoad() throws Exception { logger.info("************** STARTED doApiDashboardDataLoad **************"); List<EnvironmentVO> envMarInfoList = DBQueryUtil.getAllEnvironments(); AppTransformConfig config = DBQueryUtil.readAppTransformConfig(); for(EnvironmentVO envInfo :envMarInfoList){ logger.info("Surveiller task DOAPIDASHBOARDTASK - STARTED : Enviroment -"+envInfo.getEnvironmentName()); if(envInfo.getMarathonJson() == null){ continue; } Map<String, String> mapPromLookup = DBQueryUtil.getPromLookupDetails(envInfo.getEnvironmentId(), SurveillerConstants.MESOS_PLATFORM); Map<String, Integer> mapCompId = DBQueryUtil.getAllComponentIdForEnv(envInfo.getEnvironmentId(), SurveillerConstants.MESOS_PLATFORM); String json = envInfo.getMarathonJson(); Map<String, Integer> mapApiSts = DBQueryUtil.getCurrentApiDetails(envInfo.getEnvironmentId()); Map<String, Integer> mapContainerSts = DBQueryUtil.getCurrentContainerDetails(envInfo.getEnvironmentId()); Set<Integer> componentsListWithNoCreatedDate = DBQueryUtil.getAppsLauchDateNull(envInfo.getEnvironmentId()); ObjectMapper mapper = new ObjectMapper(); JsonNode rootNode = mapper.readTree(json); Map<String , Integer> appApiMap = new HashMap<String , Integer>(); ArrayNode appsNode = (ArrayNode) rootNode.get("apps"); Iterator<JsonNode> appsIterator = appsNode.getElements(); while (appsIterator.hasNext()) { JsonNode appsInNode = appsIterator.next(); JsonNode id = appsInNode.get("id"); String idStr = id.getTextValue(); @SuppressWarnings("deprecation") String idSubStr = idStr.substring(id.getValueAsText().indexOf('/') + 1); if (idSubStr.indexOf('/') < 0) { logger.info("Unable to process App Id : " + idStr); continue; } String appName = idSubStr.substring(0, idSubStr.indexOf('/')); String apiName = idSubStr.substring(idSubStr.indexOf('/') + 1); if (config != null && config.getTransformName().containsKey(appName)) { appName = config.getTransformName().get(appName); } String fullAppName = appName + "/" + apiName; if(!mapCompId.containsKey(fullAppName)){ logger.info("This Service - " + apiName + " is not available in the System"); continue; } int compId = mapCompId.get(fullAppName); int instance = appsInNode.get("instances").getIntValue(); if(mapContainerSts.containsKey(appName + "/" + apiName)){ if(instance != mapContainerSts.get(appName + "/" + apiName)){ DBQueryUtil.updateContainerDetails(envInfo.getEnvironmentId(), compId, instance); } } else { DBQueryUtil.loadContainerStatus(envInfo.getEnvironmentId(), compId, instance); if(componentsListWithNoCreatedDate.contains(compId)){ String createdDate = getMarathonAppLaunchDate(envInfo, idSubStr); if(createdDate != null){ DBQueryUtil.updateAppLaunchDate(createdDate, compId, envInfo.getEnvironmentId()); } } } Integer tasksRunning = appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING) == null ? null : appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING).getIntValue(); Integer tasksStaged = appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING) == null ? null : appsInNode.get(SurveillerConstants.NUM_OF_TASKS_STAGED).getIntValue(); if(tasksRunning != null && tasksRunning.intValue() == 0 && tasksStaged != null && tasksStaged.intValue() == 0){ continue; } if(appApiMap.containsKey(appName)){ appApiMap.put(appName, appApiMap.get(appName) + 1); }else{ appApiMap.put(appName, 1); } JsonNode lblNode = appsInNode.get("labels"); String httpPath = null; if(lblNode != null){ if(lblNode.get(SurveillerConstants.LABEL_HTTP_PATH_URL) != null){ String httpPathUrl = lblNode.get(SurveillerConstants.LABEL_HTTP_PATH_URL).getTextValue(); if(httpPathUrl != null && !httpPathUrl.trim().equals("")){ httpPath = httpPathUrl+SurveillerConstants.URL_SUFFIX_BACKEND; }else{ String httpPortIdx = lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME).getTextValue(); String httpPathUri = lblNode.get("HTTP_PATH_URI").getTextValue(); httpPath = httpPortIdx+httpPathUri.replaceAll("/", "_") + SurveillerConstants.URL_SUFFIX_BACKEND; } }else if(lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME) != null){ httpPath = lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME).getTextValue()+SurveillerConstants.URL_SUFFIX_BACKEND; }else{ logger.info("Label empty for the application - " + fullAppName); continue; } if(mapPromLookup.isEmpty() || mapPromLookup == null){ DBQueryUtil.loadPromLookup(envInfo.getEnvironmentId(), compId, httpPath); }else{ if(mapPromLookup.containsKey(fullAppName)){ if(mapPromLookup.get(fullAppName) == null || !mapPromLookup.get(fullAppName).equalsIgnoreCase(httpPath)){ DBQueryUtil.updatePromLookup(envInfo.getEnvironmentId(), compId, httpPath); } }else{ DBQueryUtil.loadPromLookup(envInfo.getEnvironmentId(), compId, httpPath); } } } } for(Entry<String, Integer> appApiInfo : appApiMap.entrySet()){ if(mapApiSts.containsKey(appApiInfo.getKey())){ if(appApiInfo.getValue() != mapApiSts.get(appApiInfo.getKey())){ DBQueryUtil.updateApiDetails(envInfo.getEnvironmentId(),appApiInfo.getKey(),appApiInfo.getValue(), SurveillerConstants.MESOS_PLATFORM); } } else { DBQueryUtil.loadApiStatus(envInfo.getEnvironmentId(), appApiInfo.getKey(), appApiInfo.getValue()); } } logger.info("Surveiller task DOAPIDASHBOARDTASK - COMPLETED : Enviroment -"+envInfo.getEnvironmentName()); } logger.info("************** COMPLETED doApiDashboardDataLoad **************"); }
APIDashboardTask { public static void doApiDashboardDataLoad() throws Exception { logger.info("************** STARTED doApiDashboardDataLoad **************"); List<EnvironmentVO> envMarInfoList = DBQueryUtil.getAllEnvironments(); AppTransformConfig config = DBQueryUtil.readAppTransformConfig(); for(EnvironmentVO envInfo :envMarInfoList){ logger.info("Surveiller task DOAPIDASHBOARDTASK - STARTED : Enviroment -"+envInfo.getEnvironmentName()); if(envInfo.getMarathonJson() == null){ continue; } Map<String, String> mapPromLookup = DBQueryUtil.getPromLookupDetails(envInfo.getEnvironmentId(), SurveillerConstants.MESOS_PLATFORM); Map<String, Integer> mapCompId = DBQueryUtil.getAllComponentIdForEnv(envInfo.getEnvironmentId(), SurveillerConstants.MESOS_PLATFORM); String json = envInfo.getMarathonJson(); Map<String, Integer> mapApiSts = DBQueryUtil.getCurrentApiDetails(envInfo.getEnvironmentId()); Map<String, Integer> mapContainerSts = DBQueryUtil.getCurrentContainerDetails(envInfo.getEnvironmentId()); Set<Integer> componentsListWithNoCreatedDate = DBQueryUtil.getAppsLauchDateNull(envInfo.getEnvironmentId()); ObjectMapper mapper = new ObjectMapper(); JsonNode rootNode = mapper.readTree(json); Map<String , Integer> appApiMap = new HashMap<String , Integer>(); ArrayNode appsNode = (ArrayNode) rootNode.get("apps"); Iterator<JsonNode> appsIterator = appsNode.getElements(); while (appsIterator.hasNext()) { JsonNode appsInNode = appsIterator.next(); JsonNode id = appsInNode.get("id"); String idStr = id.getTextValue(); @SuppressWarnings("deprecation") String idSubStr = idStr.substring(id.getValueAsText().indexOf('/') + 1); if (idSubStr.indexOf('/') < 0) { logger.info("Unable to process App Id : " + idStr); continue; } String appName = idSubStr.substring(0, idSubStr.indexOf('/')); String apiName = idSubStr.substring(idSubStr.indexOf('/') + 1); if (config != null && config.getTransformName().containsKey(appName)) { appName = config.getTransformName().get(appName); } String fullAppName = appName + "/" + apiName; if(!mapCompId.containsKey(fullAppName)){ logger.info("This Service - " + apiName + " is not available in the System"); continue; } int compId = mapCompId.get(fullAppName); int instance = appsInNode.get("instances").getIntValue(); if(mapContainerSts.containsKey(appName + "/" + apiName)){ if(instance != mapContainerSts.get(appName + "/" + apiName)){ DBQueryUtil.updateContainerDetails(envInfo.getEnvironmentId(), compId, instance); } } else { DBQueryUtil.loadContainerStatus(envInfo.getEnvironmentId(), compId, instance); if(componentsListWithNoCreatedDate.contains(compId)){ String createdDate = getMarathonAppLaunchDate(envInfo, idSubStr); if(createdDate != null){ DBQueryUtil.updateAppLaunchDate(createdDate, compId, envInfo.getEnvironmentId()); } } } Integer tasksRunning = appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING) == null ? null : appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING).getIntValue(); Integer tasksStaged = appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING) == null ? null : appsInNode.get(SurveillerConstants.NUM_OF_TASKS_STAGED).getIntValue(); if(tasksRunning != null && tasksRunning.intValue() == 0 && tasksStaged != null && tasksStaged.intValue() == 0){ continue; } if(appApiMap.containsKey(appName)){ appApiMap.put(appName, appApiMap.get(appName) + 1); }else{ appApiMap.put(appName, 1); } JsonNode lblNode = appsInNode.get("labels"); String httpPath = null; if(lblNode != null){ if(lblNode.get(SurveillerConstants.LABEL_HTTP_PATH_URL) != null){ String httpPathUrl = lblNode.get(SurveillerConstants.LABEL_HTTP_PATH_URL).getTextValue(); if(httpPathUrl != null && !httpPathUrl.trim().equals("")){ httpPath = httpPathUrl+SurveillerConstants.URL_SUFFIX_BACKEND; }else{ String httpPortIdx = lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME).getTextValue(); String httpPathUri = lblNode.get("HTTP_PATH_URI").getTextValue(); httpPath = httpPortIdx+httpPathUri.replaceAll("/", "_") + SurveillerConstants.URL_SUFFIX_BACKEND; } }else if(lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME) != null){ httpPath = lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME).getTextValue()+SurveillerConstants.URL_SUFFIX_BACKEND; }else{ logger.info("Label empty for the application - " + fullAppName); continue; } if(mapPromLookup.isEmpty() || mapPromLookup == null){ DBQueryUtil.loadPromLookup(envInfo.getEnvironmentId(), compId, httpPath); }else{ if(mapPromLookup.containsKey(fullAppName)){ if(mapPromLookup.get(fullAppName) == null || !mapPromLookup.get(fullAppName).equalsIgnoreCase(httpPath)){ DBQueryUtil.updatePromLookup(envInfo.getEnvironmentId(), compId, httpPath); } }else{ DBQueryUtil.loadPromLookup(envInfo.getEnvironmentId(), compId, httpPath); } } } } for(Entry<String, Integer> appApiInfo : appApiMap.entrySet()){ if(mapApiSts.containsKey(appApiInfo.getKey())){ if(appApiInfo.getValue() != mapApiSts.get(appApiInfo.getKey())){ DBQueryUtil.updateApiDetails(envInfo.getEnvironmentId(),appApiInfo.getKey(),appApiInfo.getValue(), SurveillerConstants.MESOS_PLATFORM); } } else { DBQueryUtil.loadApiStatus(envInfo.getEnvironmentId(), appApiInfo.getKey(), appApiInfo.getValue()); } } logger.info("Surveiller task DOAPIDASHBOARDTASK - COMPLETED : Enviroment -"+envInfo.getEnvironmentName()); } logger.info("************** COMPLETED doApiDashboardDataLoad **************"); } }
APIDashboardTask { public static void doApiDashboardDataLoad() throws Exception { logger.info("************** STARTED doApiDashboardDataLoad **************"); List<EnvironmentVO> envMarInfoList = DBQueryUtil.getAllEnvironments(); AppTransformConfig config = DBQueryUtil.readAppTransformConfig(); for(EnvironmentVO envInfo :envMarInfoList){ logger.info("Surveiller task DOAPIDASHBOARDTASK - STARTED : Enviroment -"+envInfo.getEnvironmentName()); if(envInfo.getMarathonJson() == null){ continue; } Map<String, String> mapPromLookup = DBQueryUtil.getPromLookupDetails(envInfo.getEnvironmentId(), SurveillerConstants.MESOS_PLATFORM); Map<String, Integer> mapCompId = DBQueryUtil.getAllComponentIdForEnv(envInfo.getEnvironmentId(), SurveillerConstants.MESOS_PLATFORM); String json = envInfo.getMarathonJson(); Map<String, Integer> mapApiSts = DBQueryUtil.getCurrentApiDetails(envInfo.getEnvironmentId()); Map<String, Integer> mapContainerSts = DBQueryUtil.getCurrentContainerDetails(envInfo.getEnvironmentId()); Set<Integer> componentsListWithNoCreatedDate = DBQueryUtil.getAppsLauchDateNull(envInfo.getEnvironmentId()); ObjectMapper mapper = new ObjectMapper(); JsonNode rootNode = mapper.readTree(json); Map<String , Integer> appApiMap = new HashMap<String , Integer>(); ArrayNode appsNode = (ArrayNode) rootNode.get("apps"); Iterator<JsonNode> appsIterator = appsNode.getElements(); while (appsIterator.hasNext()) { JsonNode appsInNode = appsIterator.next(); JsonNode id = appsInNode.get("id"); String idStr = id.getTextValue(); @SuppressWarnings("deprecation") String idSubStr = idStr.substring(id.getValueAsText().indexOf('/') + 1); if (idSubStr.indexOf('/') < 0) { logger.info("Unable to process App Id : " + idStr); continue; } String appName = idSubStr.substring(0, idSubStr.indexOf('/')); String apiName = idSubStr.substring(idSubStr.indexOf('/') + 1); if (config != null && config.getTransformName().containsKey(appName)) { appName = config.getTransformName().get(appName); } String fullAppName = appName + "/" + apiName; if(!mapCompId.containsKey(fullAppName)){ logger.info("This Service - " + apiName + " is not available in the System"); continue; } int compId = mapCompId.get(fullAppName); int instance = appsInNode.get("instances").getIntValue(); if(mapContainerSts.containsKey(appName + "/" + apiName)){ if(instance != mapContainerSts.get(appName + "/" + apiName)){ DBQueryUtil.updateContainerDetails(envInfo.getEnvironmentId(), compId, instance); } } else { DBQueryUtil.loadContainerStatus(envInfo.getEnvironmentId(), compId, instance); if(componentsListWithNoCreatedDate.contains(compId)){ String createdDate = getMarathonAppLaunchDate(envInfo, idSubStr); if(createdDate != null){ DBQueryUtil.updateAppLaunchDate(createdDate, compId, envInfo.getEnvironmentId()); } } } Integer tasksRunning = appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING) == null ? null : appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING).getIntValue(); Integer tasksStaged = appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING) == null ? null : appsInNode.get(SurveillerConstants.NUM_OF_TASKS_STAGED).getIntValue(); if(tasksRunning != null && tasksRunning.intValue() == 0 && tasksStaged != null && tasksStaged.intValue() == 0){ continue; } if(appApiMap.containsKey(appName)){ appApiMap.put(appName, appApiMap.get(appName) + 1); }else{ appApiMap.put(appName, 1); } JsonNode lblNode = appsInNode.get("labels"); String httpPath = null; if(lblNode != null){ if(lblNode.get(SurveillerConstants.LABEL_HTTP_PATH_URL) != null){ String httpPathUrl = lblNode.get(SurveillerConstants.LABEL_HTTP_PATH_URL).getTextValue(); if(httpPathUrl != null && !httpPathUrl.trim().equals("")){ httpPath = httpPathUrl+SurveillerConstants.URL_SUFFIX_BACKEND; }else{ String httpPortIdx = lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME).getTextValue(); String httpPathUri = lblNode.get("HTTP_PATH_URI").getTextValue(); httpPath = httpPortIdx+httpPathUri.replaceAll("/", "_") + SurveillerConstants.URL_SUFFIX_BACKEND; } }else if(lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME) != null){ httpPath = lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME).getTextValue()+SurveillerConstants.URL_SUFFIX_BACKEND; }else{ logger.info("Label empty for the application - " + fullAppName); continue; } if(mapPromLookup.isEmpty() || mapPromLookup == null){ DBQueryUtil.loadPromLookup(envInfo.getEnvironmentId(), compId, httpPath); }else{ if(mapPromLookup.containsKey(fullAppName)){ if(mapPromLookup.get(fullAppName) == null || !mapPromLookup.get(fullAppName).equalsIgnoreCase(httpPath)){ DBQueryUtil.updatePromLookup(envInfo.getEnvironmentId(), compId, httpPath); } }else{ DBQueryUtil.loadPromLookup(envInfo.getEnvironmentId(), compId, httpPath); } } } } for(Entry<String, Integer> appApiInfo : appApiMap.entrySet()){ if(mapApiSts.containsKey(appApiInfo.getKey())){ if(appApiInfo.getValue() != mapApiSts.get(appApiInfo.getKey())){ DBQueryUtil.updateApiDetails(envInfo.getEnvironmentId(),appApiInfo.getKey(),appApiInfo.getValue(), SurveillerConstants.MESOS_PLATFORM); } } else { DBQueryUtil.loadApiStatus(envInfo.getEnvironmentId(), appApiInfo.getKey(), appApiInfo.getValue()); } } logger.info("Surveiller task DOAPIDASHBOARDTASK - COMPLETED : Enviroment -"+envInfo.getEnvironmentName()); } logger.info("************** COMPLETED doApiDashboardDataLoad **************"); } private  APIDashboardTask(); }
APIDashboardTask { public static void doApiDashboardDataLoad() throws Exception { logger.info("************** STARTED doApiDashboardDataLoad **************"); List<EnvironmentVO> envMarInfoList = DBQueryUtil.getAllEnvironments(); AppTransformConfig config = DBQueryUtil.readAppTransformConfig(); for(EnvironmentVO envInfo :envMarInfoList){ logger.info("Surveiller task DOAPIDASHBOARDTASK - STARTED : Enviroment -"+envInfo.getEnvironmentName()); if(envInfo.getMarathonJson() == null){ continue; } Map<String, String> mapPromLookup = DBQueryUtil.getPromLookupDetails(envInfo.getEnvironmentId(), SurveillerConstants.MESOS_PLATFORM); Map<String, Integer> mapCompId = DBQueryUtil.getAllComponentIdForEnv(envInfo.getEnvironmentId(), SurveillerConstants.MESOS_PLATFORM); String json = envInfo.getMarathonJson(); Map<String, Integer> mapApiSts = DBQueryUtil.getCurrentApiDetails(envInfo.getEnvironmentId()); Map<String, Integer> mapContainerSts = DBQueryUtil.getCurrentContainerDetails(envInfo.getEnvironmentId()); Set<Integer> componentsListWithNoCreatedDate = DBQueryUtil.getAppsLauchDateNull(envInfo.getEnvironmentId()); ObjectMapper mapper = new ObjectMapper(); JsonNode rootNode = mapper.readTree(json); Map<String , Integer> appApiMap = new HashMap<String , Integer>(); ArrayNode appsNode = (ArrayNode) rootNode.get("apps"); Iterator<JsonNode> appsIterator = appsNode.getElements(); while (appsIterator.hasNext()) { JsonNode appsInNode = appsIterator.next(); JsonNode id = appsInNode.get("id"); String idStr = id.getTextValue(); @SuppressWarnings("deprecation") String idSubStr = idStr.substring(id.getValueAsText().indexOf('/') + 1); if (idSubStr.indexOf('/') < 0) { logger.info("Unable to process App Id : " + idStr); continue; } String appName = idSubStr.substring(0, idSubStr.indexOf('/')); String apiName = idSubStr.substring(idSubStr.indexOf('/') + 1); if (config != null && config.getTransformName().containsKey(appName)) { appName = config.getTransformName().get(appName); } String fullAppName = appName + "/" + apiName; if(!mapCompId.containsKey(fullAppName)){ logger.info("This Service - " + apiName + " is not available in the System"); continue; } int compId = mapCompId.get(fullAppName); int instance = appsInNode.get("instances").getIntValue(); if(mapContainerSts.containsKey(appName + "/" + apiName)){ if(instance != mapContainerSts.get(appName + "/" + apiName)){ DBQueryUtil.updateContainerDetails(envInfo.getEnvironmentId(), compId, instance); } } else { DBQueryUtil.loadContainerStatus(envInfo.getEnvironmentId(), compId, instance); if(componentsListWithNoCreatedDate.contains(compId)){ String createdDate = getMarathonAppLaunchDate(envInfo, idSubStr); if(createdDate != null){ DBQueryUtil.updateAppLaunchDate(createdDate, compId, envInfo.getEnvironmentId()); } } } Integer tasksRunning = appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING) == null ? null : appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING).getIntValue(); Integer tasksStaged = appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING) == null ? null : appsInNode.get(SurveillerConstants.NUM_OF_TASKS_STAGED).getIntValue(); if(tasksRunning != null && tasksRunning.intValue() == 0 && tasksStaged != null && tasksStaged.intValue() == 0){ continue; } if(appApiMap.containsKey(appName)){ appApiMap.put(appName, appApiMap.get(appName) + 1); }else{ appApiMap.put(appName, 1); } JsonNode lblNode = appsInNode.get("labels"); String httpPath = null; if(lblNode != null){ if(lblNode.get(SurveillerConstants.LABEL_HTTP_PATH_URL) != null){ String httpPathUrl = lblNode.get(SurveillerConstants.LABEL_HTTP_PATH_URL).getTextValue(); if(httpPathUrl != null && !httpPathUrl.trim().equals("")){ httpPath = httpPathUrl+SurveillerConstants.URL_SUFFIX_BACKEND; }else{ String httpPortIdx = lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME).getTextValue(); String httpPathUri = lblNode.get("HTTP_PATH_URI").getTextValue(); httpPath = httpPortIdx+httpPathUri.replaceAll("/", "_") + SurveillerConstants.URL_SUFFIX_BACKEND; } }else if(lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME) != null){ httpPath = lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME).getTextValue()+SurveillerConstants.URL_SUFFIX_BACKEND; }else{ logger.info("Label empty for the application - " + fullAppName); continue; } if(mapPromLookup.isEmpty() || mapPromLookup == null){ DBQueryUtil.loadPromLookup(envInfo.getEnvironmentId(), compId, httpPath); }else{ if(mapPromLookup.containsKey(fullAppName)){ if(mapPromLookup.get(fullAppName) == null || !mapPromLookup.get(fullAppName).equalsIgnoreCase(httpPath)){ DBQueryUtil.updatePromLookup(envInfo.getEnvironmentId(), compId, httpPath); } }else{ DBQueryUtil.loadPromLookup(envInfo.getEnvironmentId(), compId, httpPath); } } } } for(Entry<String, Integer> appApiInfo : appApiMap.entrySet()){ if(mapApiSts.containsKey(appApiInfo.getKey())){ if(appApiInfo.getValue() != mapApiSts.get(appApiInfo.getKey())){ DBQueryUtil.updateApiDetails(envInfo.getEnvironmentId(),appApiInfo.getKey(),appApiInfo.getValue(), SurveillerConstants.MESOS_PLATFORM); } } else { DBQueryUtil.loadApiStatus(envInfo.getEnvironmentId(), appApiInfo.getKey(), appApiInfo.getValue()); } } logger.info("Surveiller task DOAPIDASHBOARDTASK - COMPLETED : Enviroment -"+envInfo.getEnvironmentName()); } logger.info("************** COMPLETED doApiDashboardDataLoad **************"); } private  APIDashboardTask(); static void doApiDashboardDataLoad(); }
APIDashboardTask { public static void doApiDashboardDataLoad() throws Exception { logger.info("************** STARTED doApiDashboardDataLoad **************"); List<EnvironmentVO> envMarInfoList = DBQueryUtil.getAllEnvironments(); AppTransformConfig config = DBQueryUtil.readAppTransformConfig(); for(EnvironmentVO envInfo :envMarInfoList){ logger.info("Surveiller task DOAPIDASHBOARDTASK - STARTED : Enviroment -"+envInfo.getEnvironmentName()); if(envInfo.getMarathonJson() == null){ continue; } Map<String, String> mapPromLookup = DBQueryUtil.getPromLookupDetails(envInfo.getEnvironmentId(), SurveillerConstants.MESOS_PLATFORM); Map<String, Integer> mapCompId = DBQueryUtil.getAllComponentIdForEnv(envInfo.getEnvironmentId(), SurveillerConstants.MESOS_PLATFORM); String json = envInfo.getMarathonJson(); Map<String, Integer> mapApiSts = DBQueryUtil.getCurrentApiDetails(envInfo.getEnvironmentId()); Map<String, Integer> mapContainerSts = DBQueryUtil.getCurrentContainerDetails(envInfo.getEnvironmentId()); Set<Integer> componentsListWithNoCreatedDate = DBQueryUtil.getAppsLauchDateNull(envInfo.getEnvironmentId()); ObjectMapper mapper = new ObjectMapper(); JsonNode rootNode = mapper.readTree(json); Map<String , Integer> appApiMap = new HashMap<String , Integer>(); ArrayNode appsNode = (ArrayNode) rootNode.get("apps"); Iterator<JsonNode> appsIterator = appsNode.getElements(); while (appsIterator.hasNext()) { JsonNode appsInNode = appsIterator.next(); JsonNode id = appsInNode.get("id"); String idStr = id.getTextValue(); @SuppressWarnings("deprecation") String idSubStr = idStr.substring(id.getValueAsText().indexOf('/') + 1); if (idSubStr.indexOf('/') < 0) { logger.info("Unable to process App Id : " + idStr); continue; } String appName = idSubStr.substring(0, idSubStr.indexOf('/')); String apiName = idSubStr.substring(idSubStr.indexOf('/') + 1); if (config != null && config.getTransformName().containsKey(appName)) { appName = config.getTransformName().get(appName); } String fullAppName = appName + "/" + apiName; if(!mapCompId.containsKey(fullAppName)){ logger.info("This Service - " + apiName + " is not available in the System"); continue; } int compId = mapCompId.get(fullAppName); int instance = appsInNode.get("instances").getIntValue(); if(mapContainerSts.containsKey(appName + "/" + apiName)){ if(instance != mapContainerSts.get(appName + "/" + apiName)){ DBQueryUtil.updateContainerDetails(envInfo.getEnvironmentId(), compId, instance); } } else { DBQueryUtil.loadContainerStatus(envInfo.getEnvironmentId(), compId, instance); if(componentsListWithNoCreatedDate.contains(compId)){ String createdDate = getMarathonAppLaunchDate(envInfo, idSubStr); if(createdDate != null){ DBQueryUtil.updateAppLaunchDate(createdDate, compId, envInfo.getEnvironmentId()); } } } Integer tasksRunning = appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING) == null ? null : appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING).getIntValue(); Integer tasksStaged = appsInNode.get(SurveillerConstants.NUM_OF_TASKS_RUNNING) == null ? null : appsInNode.get(SurveillerConstants.NUM_OF_TASKS_STAGED).getIntValue(); if(tasksRunning != null && tasksRunning.intValue() == 0 && tasksStaged != null && tasksStaged.intValue() == 0){ continue; } if(appApiMap.containsKey(appName)){ appApiMap.put(appName, appApiMap.get(appName) + 1); }else{ appApiMap.put(appName, 1); } JsonNode lblNode = appsInNode.get("labels"); String httpPath = null; if(lblNode != null){ if(lblNode.get(SurveillerConstants.LABEL_HTTP_PATH_URL) != null){ String httpPathUrl = lblNode.get(SurveillerConstants.LABEL_HTTP_PATH_URL).getTextValue(); if(httpPathUrl != null && !httpPathUrl.trim().equals("")){ httpPath = httpPathUrl+SurveillerConstants.URL_SUFFIX_BACKEND; }else{ String httpPortIdx = lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME).getTextValue(); String httpPathUri = lblNode.get("HTTP_PATH_URI").getTextValue(); httpPath = httpPortIdx+httpPathUri.replaceAll("/", "_") + SurveillerConstants.URL_SUFFIX_BACKEND; } }else if(lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME) != null){ httpPath = lblNode.get(SurveillerConstants.LABEL_HTTP_PORT_IDX_0_NAME).getTextValue()+SurveillerConstants.URL_SUFFIX_BACKEND; }else{ logger.info("Label empty for the application - " + fullAppName); continue; } if(mapPromLookup.isEmpty() || mapPromLookup == null){ DBQueryUtil.loadPromLookup(envInfo.getEnvironmentId(), compId, httpPath); }else{ if(mapPromLookup.containsKey(fullAppName)){ if(mapPromLookup.get(fullAppName) == null || !mapPromLookup.get(fullAppName).equalsIgnoreCase(httpPath)){ DBQueryUtil.updatePromLookup(envInfo.getEnvironmentId(), compId, httpPath); } }else{ DBQueryUtil.loadPromLookup(envInfo.getEnvironmentId(), compId, httpPath); } } } } for(Entry<String, Integer> appApiInfo : appApiMap.entrySet()){ if(mapApiSts.containsKey(appApiInfo.getKey())){ if(appApiInfo.getValue() != mapApiSts.get(appApiInfo.getKey())){ DBQueryUtil.updateApiDetails(envInfo.getEnvironmentId(),appApiInfo.getKey(),appApiInfo.getValue(), SurveillerConstants.MESOS_PLATFORM); } } else { DBQueryUtil.loadApiStatus(envInfo.getEnvironmentId(), appApiInfo.getKey(), appApiInfo.getValue()); } } logger.info("Surveiller task DOAPIDASHBOARDTASK - COMPLETED : Enviroment -"+envInfo.getEnvironmentName()); } logger.info("************** COMPLETED doApiDashboardDataLoad **************"); } private  APIDashboardTask(); static void doApiDashboardDataLoad();  }