@Test public void updateHealthCheckStatusInDBTest() throws Exception { Map<String, String> paramDetails = new HashMap<String, String>(); paramDetails.put("URL", "http: ComponentVO comp = new ComponentVO(); comp.setComponentDesc(null); comp.setComponentId(25); comp.setComponentName("Mesos Master 1"); comp.setComponentTypeId(0); comp.setParentComponentId(1); comp.setParentComponentName("CCP - Mesos Master"); HealthCheckVO hv = new HealthCheckVO(); hv.setStatus(new StatusVO(Status.DOWN,"down")); hv.setEnvironmentId(1); hv.setEnvironmentName("ProdSD"); hv.setFailureStatusMessage(null); hv.setHealthCheckTypeClassName("com.tmobile.kardio.surveiller.handler.URLOpenableHandler"); hv.setHealthCheckTypeName("URL2xxCheck"); hv.setRegionName("West Region"); hv.setComponent(comp); hv.setComponentType(ComponentType.INFRA); hv.setCurrentStatus((long) 1); hv.setHealthCheckComponentId((long) 25); hv.setHealthCheckId((long) 1); hv.setHealthCheckRegionId((long) 1); hv.setHealthCheckRetryCurrentCount((long) 0); hv.setHealthCheckRetryMaxCount((long) 3); hv.setParamDetails(paramDetails); List<HealthCheckVO> healthCheckVOs1 = new ArrayList<HealthCheckVO>(); healthCheckVOs1.add(hv); List<HealthCheckVO> output1 = DBQueryUtil.updateHealthCheckStatusInDB(healthCheckVOs1); List<HealthCheckVO> healthCheckVOs2 = new ArrayList<HealthCheckVO>(); hv.setStatus(null); healthCheckVOs2.add(hv); List<HealthCheckVO> output2 = DBQueryUtil.updateHealthCheckStatusInDB(healthCheckVOs2); List<HealthCheckVO> healthCheckVOs3 = new ArrayList<HealthCheckVO>(); hv.setStatus(new StatusVO(Status.DOWN,"down")); hv.setCurrentStatus(null); hv.setHealthCheckRetryCurrentCount(null); healthCheckVOs3.add(hv); List<HealthCheckVO> output3 = DBQueryUtil.updateHealthCheckStatusInDB(healthCheckVOs3); List<HealthCheckVO> healthCheckVOs4 = new ArrayList<HealthCheckVO>(); hv.setStatus(new StatusVO(Status.UP,"up")); hv.setCurrentStatus(null); hv.setHealthCheckRetryMaxCount((long) 3); healthCheckVOs4.add(hv); List<HealthCheckVO> output4 = DBQueryUtil.updateHealthCheckStatusInDB(healthCheckVOs4); List<HealthCheckVO> healthCheckVOs5 = new ArrayList<HealthCheckVO>(); hv.setStatus(new StatusVO(Status.DOWN,"down")); hv.setCurrentStatus(null); hv.setHealthCheckRetryMaxCount((long) 3); healthCheckVOs5.add(hv); List<HealthCheckVO> output5 = DBQueryUtil.updateHealthCheckStatusInDB(healthCheckVOs5); List<HealthCheckVO> healthCheckVOs6 = new ArrayList<HealthCheckVO>(); hv.setStatus(new StatusVO(Status.DOWN,"up")); hv.setCurrentStatus(1L); hv.setHealthCheckRetryMaxCount((long) 0); healthCheckVOs6.add(hv); List<HealthCheckVO> output6 = DBQueryUtil.updateHealthCheckStatusInDB(healthCheckVOs6); assertEquals(output6,healthCheckVOs6); List<HealthCheckVO> healthCheckVOs7 = new ArrayList<HealthCheckVO>(); hv.setStatus(new StatusVO(Status.UP,"up")); hv.setCurrentStatus(1L); hv.setHealthCheckRetryMaxCount((long) 0); hv.setHealthCheckRetryCurrentCount((long)3); healthCheckVOs7.add(hv); List<HealthCheckVO> output7 = DBQueryUtil.updateHealthCheckStatusInDB(healthCheckVOs7); List<HealthCheckVO> healthCheckVOs8 = new ArrayList<HealthCheckVO>(); hv.setHealthCheckId((long) 2); hv.setStatus(new StatusVO(Status.UP,"up")); hv.setCurrentStatus(1L); hv.setHealthCheckRetryMaxCount((long) 0); hv.setHealthCheckRetryCurrentCount((long)3); healthCheckVOs8.add(hv); List<HealthCheckVO> output8 = DBQueryUtil.updateHealthCheckStatusInDB(healthCheckVOs8); }
public static List<HealthCheckVO> updateHealthCheckStatusInDB(List<HealthCheckVO> healthCheckVOs) throws SQLException { List<HealthCheckVO> returnStatusChangedList = new ArrayList<HealthCheckVO>(); for (HealthCheckVO healthCheckVO : healthCheckVOs) { if(healthCheckVO.getStatus() == null) { logger.error("STATUS CHECK FAILED>> ComponentId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId()); continue; } Status status = healthCheckVO.getStatus().getStatus(); if (status == null) { logger.error("STATUS CHECK FAILED>> ComponentId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId()); continue; } if(!status.equals(Status.UP)){ logger.info("STATUS CHECK SUCCESS>> HealthCheckId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId() + "; isSuccess : " + status.getStatusName() + "; Message : " + status.getStatusDesc()); } try { boolean isStatusChanged = updateStatus(healthCheckVO); if(isStatusChanged){ returnStatusChangedList.add(healthCheckVO); } } catch (Exception ex) { logger.error("Exception in DB Update Doing Rollback", ex); throw ex; } } logger.debug("DB Update Success - Doing commit"); return returnStatusChangedList; }
DBQueryUtil { public static List<HealthCheckVO> updateHealthCheckStatusInDB(List<HealthCheckVO> healthCheckVOs) throws SQLException { List<HealthCheckVO> returnStatusChangedList = new ArrayList<HealthCheckVO>(); for (HealthCheckVO healthCheckVO : healthCheckVOs) { if(healthCheckVO.getStatus() == null) { logger.error("STATUS CHECK FAILED>> ComponentId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId()); continue; } Status status = healthCheckVO.getStatus().getStatus(); if (status == null) { logger.error("STATUS CHECK FAILED>> ComponentId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId()); continue; } if(!status.equals(Status.UP)){ logger.info("STATUS CHECK SUCCESS>> HealthCheckId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId() + "; isSuccess : " + status.getStatusName() + "; Message : " + status.getStatusDesc()); } try { boolean isStatusChanged = updateStatus(healthCheckVO); if(isStatusChanged){ returnStatusChangedList.add(healthCheckVO); } } catch (Exception ex) { logger.error("Exception in DB Update Doing Rollback", ex); throw ex; } } logger.debug("DB Update Success - Doing commit"); return returnStatusChangedList; } }
DBQueryUtil { public static List<HealthCheckVO> updateHealthCheckStatusInDB(List<HealthCheckVO> healthCheckVOs) throws SQLException { List<HealthCheckVO> returnStatusChangedList = new ArrayList<HealthCheckVO>(); for (HealthCheckVO healthCheckVO : healthCheckVOs) { if(healthCheckVO.getStatus() == null) { logger.error("STATUS CHECK FAILED>> ComponentId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId()); continue; } Status status = healthCheckVO.getStatus().getStatus(); if (status == null) { logger.error("STATUS CHECK FAILED>> ComponentId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId()); continue; } if(!status.equals(Status.UP)){ logger.info("STATUS CHECK SUCCESS>> HealthCheckId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId() + "; isSuccess : " + status.getStatusName() + "; Message : " + status.getStatusDesc()); } try { boolean isStatusChanged = updateStatus(healthCheckVO); if(isStatusChanged){ returnStatusChangedList.add(healthCheckVO); } } catch (Exception ex) { logger.error("Exception in DB Update Doing Rollback", ex); throw ex; } } logger.debug("DB Update Success - Doing commit"); return returnStatusChangedList; } private  DBQueryUtil(); }
DBQueryUtil { public static List<HealthCheckVO> updateHealthCheckStatusInDB(List<HealthCheckVO> healthCheckVOs) throws SQLException { List<HealthCheckVO> returnStatusChangedList = new ArrayList<HealthCheckVO>(); for (HealthCheckVO healthCheckVO : healthCheckVOs) { if(healthCheckVO.getStatus() == null) { logger.error("STATUS CHECK FAILED>> ComponentId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId()); continue; } Status status = healthCheckVO.getStatus().getStatus(); if (status == null) { logger.error("STATUS CHECK FAILED>> ComponentId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId()); continue; } if(!status.equals(Status.UP)){ logger.info("STATUS CHECK SUCCESS>> HealthCheckId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId() + "; isSuccess : " + status.getStatusName() + "; Message : " + status.getStatusDesc()); } try { boolean isStatusChanged = updateStatus(healthCheckVO); if(isStatusChanged){ returnStatusChangedList.add(healthCheckVO); } } catch (Exception ex) { logger.error("Exception in DB Update Doing Rollback", ex); throw ex; } } logger.debug("DB Update Success - Doing commit"); return returnStatusChangedList; } private  DBQueryUtil(); static List<HealthCheckVO> getSurveillerDetailsOfComponent(boolean isDummyHealth); static List<EnvironmentVO> getAllEnvironments(); static List<HealthCheckVO> updateHealthCheckStatusInDB(List<HealthCheckVO> healthCheckVOs); static void updateEnvironmentDetails(
			List<EnvironmentVO> environmentVOs); static void updateWestMarathonJson(final EnvironmentVO environmentVO); static void updateEastMarathonJson(final EnvironmentVO environmentVO); static boolean checkAndUpdateMessage(final int componentId, final int environmentId,
			final long regionID,final HealthCheckType healthCheckType, final Status currentStatus,
			final String marathonMessage); static void updateMarathonHealthCheckStatus(final int componentId, final int environmentId,
			final long regionID,final HealthCheckType healthCheckType, final Status status, boolean isStatusChanged); static int checkAndInsertComponent(final String appName, final String apiName, final ComponentType compType,
	        final String healthCheckURL, final int environmentId, final long regionID,
	        final HealthCheckType healthCheckType, String platform); static AppTransformConfig readAppTransformConfig(); static int getComponentByNameAndParent(final String name, final int parentId, final int componentTypeId, String platform); static ComponentVO getComponent(final int componentId); static void insertComponent(final String name, final int parentId,
			final int componentType, boolean hasParent, String platform); static void insertHealthCheckParam(final long healthCheckId,
			final String healthCheckParamKey, final String healthCheckPramVal); static void insertHealthCheck(final int componentId,
			final Long regionId, final int environmentId,
			final int healthCheckTypeId, final int maxRetryCount); static List<ComponentVO> getAllAPIComponentDetails(final int environmentId, String platform, long regionId); static void updateDelIndForHealthCheck(final int compId,
			final int delInd, final int enviromentId, final Long regionID); static List<SubscriptionVO> getAllSubscriptions(Set<Integer> compIdSet); static List<CounterDetailVO> getCounterDetails(); static void addCounterMertic(final int environmentCounterId, final float counterMerticValue, Timestamp currDate); static void addCounterMetricHistory(final int environmentCounterId, final float counterMerticValue); static float getTotalTransaction(final int envCountId); static void executeDelete(String query); static float getCCPUpTime(final int envId, final String [] parentComponentNames); static int getNumberOfServices(CounterDetailVO counterDetails); static Map<Integer, Blob> getMarathonJson(); static void loadContainerStatus(final int envId, int compId, final int instanceNum); static int getComponentId(final String compName, final String parentCompName); static Set<Integer> getAppsLauchDateNull(int envId); static void updateAppLaunchDate(String launchDate, int compId, int envId); static void loadApiStatus(final int envId, String compName, int numOfApi); static Map<String, Integer> getCurrentApiDetails(int envId); static void updateApiDetails(final int envId, String compName, int numOfApi, String platform); static Map<String, Integer> getCurrentContainerDetails(int envId); static void updateContainerDetails(final int envId, int compId, int numOfcont); static Map<String, String> getPromLookupDetails(int envId, String platform); static int loadPromLookup(final int envId, int compId, String httpPath); static void updatePromLookup(final int envId, int compId, String httpPath); static Map<String, Integer> getPromLookupHttpPath(int envId, String platform); static List<Integer> getAllCurrentTPS(int envId, String platform); static void updateTpsService(final int envId, int componentId, float tpsVaule, float latencyValue); static void loadTpsService(final int envId, int conponentId , float tpsVaule, float latencyValue); static Map<Integer, List<Float>> getTpsLatencyHsitory(int envId, String platform); static void loadTpsLatencyHistory(final int envId, int conponentId , float tpsVaule, float latencyValue); static void loadK8sTpsLatencyHistory(final int envId, int conponentId , float tpsVaule, float latencyValue); static void updateTpsLatHistory(final int envId, int componentId, float tpsVaule, float latencyValue, String platform); static Map<String, Integer> getK8sCurrentApiDetails(int envId); static Map<String, Integer> getK8sCurrContainerDetails(int envId, String platform); static Map<String, Integer> getK8sObjPodsContDetails(int envId); static Map<String, Integer> getNumOfActiveApisOfApp(int envId, String platform); static void loadK8sApiStatus(final int envId, String compName, int numOfApi); static void updateContainerDetails(final int envId, String compName, int numOfcont, String parentCompName, String platform); static void updateObjPodss(int environmentId, String objName, ArrayList<Integer> podContList); static void loadK8sObjectPods(int environmentId, String objName, ArrayList<Integer> podContList); static void updatePodsAndContainers(final int envId, String compName, int numOfPods, String parentCompName, int numOfCont); static int loadPodsAndContainers(final int envId,final String compName,final String parentCompName, final int numPods, int numCont ); static Map<String, Integer> getAllComponentIdForEnv(int envId,String platform); static void deletePromLookup(int envId, int compId, String lookupVaule); }
DBQueryUtil { public static List<HealthCheckVO> updateHealthCheckStatusInDB(List<HealthCheckVO> healthCheckVOs) throws SQLException { List<HealthCheckVO> returnStatusChangedList = new ArrayList<HealthCheckVO>(); for (HealthCheckVO healthCheckVO : healthCheckVOs) { if(healthCheckVO.getStatus() == null) { logger.error("STATUS CHECK FAILED>> ComponentId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId()); continue; } Status status = healthCheckVO.getStatus().getStatus(); if (status == null) { logger.error("STATUS CHECK FAILED>> ComponentId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId()); continue; } if(!status.equals(Status.UP)){ logger.info("STATUS CHECK SUCCESS>> HealthCheckId : " + healthCheckVO.getHealthCheckId() + "; RegionId : " + healthCheckVO.getHealthCheckRegionId() + "; isSuccess : " + status.getStatusName() + "; Message : " + status.getStatusDesc()); } try { boolean isStatusChanged = updateStatus(healthCheckVO); if(isStatusChanged){ returnStatusChangedList.add(healthCheckVO); } } catch (Exception ex) { logger.error("Exception in DB Update Doing Rollback", ex); throw ex; } } logger.debug("DB Update Success - Doing commit"); return returnStatusChangedList; } private  DBQueryUtil(); static List<HealthCheckVO> getSurveillerDetailsOfComponent(boolean isDummyHealth); static List<EnvironmentVO> getAllEnvironments(); static List<HealthCheckVO> updateHealthCheckStatusInDB(List<HealthCheckVO> healthCheckVOs); static void updateEnvironmentDetails(
			List<EnvironmentVO> environmentVOs); static void updateWestMarathonJson(final EnvironmentVO environmentVO); static void updateEastMarathonJson(final EnvironmentVO environmentVO); static boolean checkAndUpdateMessage(final int componentId, final int environmentId,
			final long regionID,final HealthCheckType healthCheckType, final Status currentStatus,
			final String marathonMessage); static void updateMarathonHealthCheckStatus(final int componentId, final int environmentId,
			final long regionID,final HealthCheckType healthCheckType, final Status status, boolean isStatusChanged); static int checkAndInsertComponent(final String appName, final String apiName, final ComponentType compType,
	        final String healthCheckURL, final int environmentId, final long regionID,
	        final HealthCheckType healthCheckType, String platform); static AppTransformConfig readAppTransformConfig(); static int getComponentByNameAndParent(final String name, final int parentId, final int componentTypeId, String platform); static ComponentVO getComponent(final int componentId); static void insertComponent(final String name, final int parentId,
			final int componentType, boolean hasParent, String platform); static void insertHealthCheckParam(final long healthCheckId,
			final String healthCheckParamKey, final String healthCheckPramVal); static void insertHealthCheck(final int componentId,
			final Long regionId, final int environmentId,
			final int healthCheckTypeId, final int maxRetryCount); static List<ComponentVO> getAllAPIComponentDetails(final int environmentId, String platform, long regionId); static void updateDelIndForHealthCheck(final int compId,
			final int delInd, final int enviromentId, final Long regionID); static List<SubscriptionVO> getAllSubscriptions(Set<Integer> compIdSet); static List<CounterDetailVO> getCounterDetails(); static void addCounterMertic(final int environmentCounterId, final float counterMerticValue, Timestamp currDate); static void addCounterMetricHistory(final int environmentCounterId, final float counterMerticValue); static float getTotalTransaction(final int envCountId); static void executeDelete(String query); static float getCCPUpTime(final int envId, final String [] parentComponentNames); static int getNumberOfServices(CounterDetailVO counterDetails); static Map<Integer, Blob> getMarathonJson(); static void loadContainerStatus(final int envId, int compId, final int instanceNum); static int getComponentId(final String compName, final String parentCompName); static Set<Integer> getAppsLauchDateNull(int envId); static void updateAppLaunchDate(String launchDate, int compId, int envId); static void loadApiStatus(final int envId, String compName, int numOfApi); static Map<String, Integer> getCurrentApiDetails(int envId); static void updateApiDetails(final int envId, String compName, int numOfApi, String platform); static Map<String, Integer> getCurrentContainerDetails(int envId); static void updateContainerDetails(final int envId, int compId, int numOfcont); static Map<String, String> getPromLookupDetails(int envId, String platform); static int loadPromLookup(final int envId, int compId, String httpPath); static void updatePromLookup(final int envId, int compId, String httpPath); static Map<String, Integer> getPromLookupHttpPath(int envId, String platform); static List<Integer> getAllCurrentTPS(int envId, String platform); static void updateTpsService(final int envId, int componentId, float tpsVaule, float latencyValue); static void loadTpsService(final int envId, int conponentId , float tpsVaule, float latencyValue); static Map<Integer, List<Float>> getTpsLatencyHsitory(int envId, String platform); static void loadTpsLatencyHistory(final int envId, int conponentId , float tpsVaule, float latencyValue); static void loadK8sTpsLatencyHistory(final int envId, int conponentId , float tpsVaule, float latencyValue); static void updateTpsLatHistory(final int envId, int componentId, float tpsVaule, float latencyValue, String platform); static Map<String, Integer> getK8sCurrentApiDetails(int envId); static Map<String, Integer> getK8sCurrContainerDetails(int envId, String platform); static Map<String, Integer> getK8sObjPodsContDetails(int envId); static Map<String, Integer> getNumOfActiveApisOfApp(int envId, String platform); static void loadK8sApiStatus(final int envId, String compName, int numOfApi); static void updateContainerDetails(final int envId, String compName, int numOfcont, String parentCompName, String platform); static void updateObjPodss(int environmentId, String objName, ArrayList<Integer> podContList); static void loadK8sObjectPods(int environmentId, String objName, ArrayList<Integer> podContList); static void updatePodsAndContainers(final int envId, String compName, int numOfPods, String parentCompName, int numOfCont); static int loadPodsAndContainers(final int envId,final String compName,final String parentCompName, final int numPods, int numCont ); static Map<String, Integer> getAllComponentIdForEnv(int envId,String platform); static void deletePromLookup(int envId, int compId, String lookupVaule);  }