class K8sAPIDashboardTask {

	private static void loadKubernetesApiDashboard(EnvironmentVO eVo) {
		logger.info("Surveiller task DOK8SAPIDASHBOARDTASK - STARTED : Enviroment -" + eVo.getEnvironmentName());
		try {
			Map<String, Integer> mapApiSts = DBQueryUtil.getK8sCurrentApiDetails(eVo.getEnvironmentId());
			Map<String, Integer> mapContainerSts = DBQueryUtil.getK8sCurrContainerDetails(eVo.getEnvironmentId(),"K8s");
			Map<String, Integer> mapObjPods = DBQueryUtil.getK8sObjPodsContDetails(eVo.getEnvironmentId());
			Map<String, Integer> mapCurrApiSts = DBQueryUtil.getNumOfActiveApisOfApp(eVo.getEnvironmentId(), "K8s");
			//Map<String, Integer> mapPodsSts = DBQueryUtil.getCurrentPodsDetails(eVo.getEnvironmentId());
			//Map<String, Integer> mapCompId = DBQueryUtil.getAllComponentIdForEnv(eVo.getEnvironmentId(),"K8s");
			for (String comp : mapCurrApiSts.keySet()) {
				if (mapApiSts.containsKey(comp)) {
					DBQueryUtil.updateApiDetails(eVo.getEnvironmentId(), comp, mapCurrApiSts.get(comp), "K8s");
				} else {
					DBQueryUtil.loadK8sApiStatus(eVo.getEnvironmentId(), comp, mapCurrApiSts.get(comp));
				}
			}
			String authToken = CommonsUtil.getK8sAuthToken(eVo.getK8sCred());
			if (authToken == null || authToken.equals("")) {
				String errorString = "Got Invalid token for the environment - "
						+ eVo.getEnvironmentName();
				logger.error(errorString);
				throw new GeneralException(errorString);
			}
			Map<String, List<ServiceLabelVO>> depLabelMap = new HashMap<String, List<ServiceLabelVO>>();
			Map<String, ArrayList<Integer>> externalPodsMap = new HashMap<String, ArrayList<Integer>>();
			/* Method to get All the Deployment and its MatchLabels*/
			getDeploymentAndMatchLabels(authToken, eVo, depLabelMap);
			/*Method to get the Pods and Containers associated to each deployment*/
			getPodsAndContainersOfDeployments(authToken, eVo, depLabelMap, externalPodsMap);
		
			for (Entry<String, ArrayList<Integer>> depMap : externalPodsMap.entrySet()) {
				if(mapObjPods.containsKey(depMap.getKey())){
					DBQueryUtil.updateObjPodss(eVo.getEnvironmentId(), depMap.getKey(), depMap.getValue());
				}else{
					DBQueryUtil.loadK8sObjectPods(eVo.getEnvironmentId(), depMap.getKey(), depMap.getValue());
				}
			}
			
			for (Entry<String, List<ServiceLabelVO>> depMap : depLabelMap.entrySet()) {

				for (ServiceLabelVO serviceLabelVO : depMap.getValue()) {
					String componentName = serviceLabelVO.getAppName() + "/" + serviceLabelVO.getServiceName();
					if (mapContainerSts.containsKey(componentName)) {
						if(serviceLabelVO.getNumOfContainers() == mapContainerSts.get(componentName)){
							continue;
						}
						DBQueryUtil.updatePodsAndContainers(eVo.getEnvironmentId(), serviceLabelVO.getServiceName(),
								serviceLabelVO.getNumOfPods(), serviceLabelVO.getAppName(),serviceLabelVO.getNumOfContainers());
					} else {
						DBQueryUtil.loadPodsAndContainers(eVo.getEnvironmentId(), serviceLabelVO.getServiceName(),
								serviceLabelVO.getAppName(), serviceLabelVO.getNumOfPods(), serviceLabelVO.getNumOfContainers());
					}
				}
			}
		} catch (Exception ex) {
			logger.error("Surveiller task DOK8SAPIDASHBOARDTASK - FAILED : Enviroment -" + eVo.getEnvironmentName(),
					ex);
			CommonsUtil.handleException(ex, "DOK8SAPIDASHBOARDTASK");
		}
		logger.info("Surveiller task DOK8SAPIDASHBOARDTASK - COMPLETED : Enviroment -" + eVo.getEnvironmentName());
	}

	private  K8sAPIDashboardTask();

}