IoT DAS Frameworks - IT Infra Monitoring and Analytics/IOT_Applications/Performance_Dashboard_Application(Reference App)/source/SA-DashBoard/src/java/com/merit/dashboard/updatethresholds/UpdateMetricThreshold.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                    throws ServletException, IOException {

        log.debug("==============================UpdateMetricThreshold===========================================");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        PropertyUtil propertyUtil=null;
        Statement st=null;
        PreparedStatement prest=null;
        ResultSet rs = null;
                String sql="";
                int record_count = 0;
        try {
        	propertyUtil=new PropertyUtil();
       String customer=request.getParameter("CustomerName");
       String ServiceName=request.getParameter("ServiceName");
       MetricName=propertyUtil.getreverseMapping_Properties().get(request.getParameter("MetricName"));
       String SLAValue=request.getParameter("SLAValue");
       String resourceId=request.getParameter("resourceId");
       String host=request.getParameter("host");
       String resourceType=request.getParameter("resourceTypeName");

        Connection uniqueconnection=ConnectionDAO.getConnection(customer);
       sql="update servicemetrics set SLA= ? where metrictype= ? and host=? and resourceid=? and timestamp1=(select max(timestamp1) from servicemetrics where resourceType='"+resourceType+"' and metrictype='"+MetricName+"' and host='"+host+"' and resourceid='"+resourceId+"')";

        prest=uniqueconnection.prepareStatement(sql);
         prest.setDouble(1,Double.parseDouble(SLAValue));
        prest.setString(2, MetricName);
        prest.setString(3, host);
        prest.setString(4, resourceId);
       prest.executeUpdate();
     String check_query="select count(*) as count from smetricslathresholds where metrictype ='"+MetricName+"' and service ='"+ServiceName+"' and host='"+host+"' and resourceid='"+resourceId+"'";

       st=uniqueconnection.createStatement();
       rs = st.executeQuery(check_query);
        while (rs.next()) {
        record_count=rs.getInt("count");
            }
        if(record_count==0)
        {
            sql="insert into smetricslathresholds (metricthresholdvalue,metrictype,service,host,resourceid,resourcetype) values(?,?,?,?,?,?)";
            System.out.println(sql);
        }
         else
        {
         sql="update smetricslathresholds set metricthresholdvalue= ? where metrictype= ? and service= ? and host=? and resourceid=? and resourcetype=?";
        }

			prest = uniqueconnection.prepareStatement(sql);
			prest.setDouble(1, Double.parseDouble(SLAValue));
			prest.setString(2, MetricName);
			prest.setString(3, ServiceName);
			prest.setString(4, host);
			prest.setString(5, resourceId);
			prest.setString(6, resourceType);


			prest.executeUpdate();
			char[] stringArray = MetricName.toCharArray();
			stringArray[0] = Character.toUpperCase(stringArray[0]);
			String MetricNameWithFirstCharCaps = new String(stringArray);
			log.info("in Update metric threshold \n ServiceName=" + ServiceName
					+ "MetricName=" + MetricName + "SLAValue=" + SLAValue);
			response.getWriter().write(
					MetricNameWithFirstCharCaps + " Successfully Updated");
			MetricNameWithFirstCharCaps=null;
			log.debug("==============================End of UpdateMetricThreshold===========================================");
		} catch (Exception e) {
			char[] stringArray = MetricName.toCharArray();
			stringArray[0] = Character.toUpperCase(stringArray[0]);
			String MetricNameWithFirstCharCaps = new String(stringArray);
			response.getWriter().write(MetricNameWithFirstCharCaps + "Not  Successfully Updated");
			MetricNameWithFirstCharCaps=null;
			log.error("IN UpdateMetricThreshold some ERROR is here :"
					+ e.getMessage());
			e.printStackTrace();
		}
            finally {
            out.close();

        }
    }
/**
 * ************************************************************************************************
 * This method is for updating threshold values of each metric type of each service
 * and then returning JSON String for creating JSON Files for generating Chart
 * *************************************************************************************************
 */
This method is for updating threshold values of each metric type of each service
and then returning JSON String for creating JSON Files for generating Chart
This method is for updating threshold values of each metric type of each service and then returning JSON String for creating JSON Files for generating Chart
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                    throws ServletException, IOException {
        log.debug("==============================UpdateMetricThreshold===========================================");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        PropertyUtil propertyUtil=null;
        Statement st=null;
        PreparedStatement prest=null;
        ResultSet rs = null;
                String sql="";
                int record_count = 0;
        try {
        	propertyUtil=new PropertyUtil();
       String customer=request.getParameter("CustomerName");
       String ServiceName=request.getParameter("ServiceName");
       MetricName=propertyUtil.getreverseMapping_Properties().get(request.getParameter("MetricName"));
       String SLAValue=request.getParameter("SLAValue");
       String resourceId=request.getParameter("resourceId");
       String host=request.getParameter("host");
       String resourceType=request.getParameter("resourceTypeName");
        Connection uniqueconnection=ConnectionDAO.getConnection(customer);
       sql="update servicemetrics set SLA= ? where metrictype= ? and host=? and resourceid=? and timestamp1=(select max(timestamp1) from servicemetrics where resourceType='"+resourceType+"' and metrictype='"+MetricName+"' and host='"+host+"' and resourceid='"+resourceId+"')";
        prest=uniqueconnection.prepareStatement(sql);
         prest.setDouble(1,Double.parseDouble(SLAValue));
        prest.setString(2, MetricName);
        prest.setString(3, host);
        prest.setString(4, resourceId);
       prest.executeUpdate();
     String check_query="select count(*) as count from smetricslathresholds where metrictype ='"+MetricName+"' and service ='"+ServiceName+"' and host='"+host+"' and resourceid='"+resourceId+"'";
       st=uniqueconnection.createStatement();
       rs = st.executeQuery(check_query);
        while (rs.next()) {
        record_count=rs.getInt("count");
            }
        if(record_count==0)
        {
            sql="insert into smetricslathresholds (metricthresholdvalue,metrictype,service,host,resourceid,resourcetype) values(?,?,?,?,?,?)";
            System.out.println(sql);
        }
         else
        {
         sql="update smetricslathresholds set metricthresholdvalue= ? where metrictype= ? and service= ? and host=? and resourceid=? and resourcetype=?";
        }
			prest = uniqueconnection.prepareStatement(sql);
			prest.setDouble(1, Double.parseDouble(SLAValue));
			prest.setString(2, MetricName);
			prest.setString(3, ServiceName);
			prest.setString(4, host);
			prest.setString(5, resourceId);
			prest.setString(6, resourceType);
			prest.executeUpdate();
			char[] stringArray = MetricName.toCharArray();
			stringArray[0] = Character.toUpperCase(stringArray[0]);
			String MetricNameWithFirstCharCaps = new String(stringArray);
			log.info("in Update metric threshold \n ServiceName=" + ServiceName
					+ "MetricName=" + MetricName + "SLAValue=" + SLAValue);
			response.getWriter().write(
					MetricNameWithFirstCharCaps + " Successfully Updated");
			MetricNameWithFirstCharCaps=null;
			log.debug("==============================End of UpdateMetricThreshold===========================================");
		} catch (Exception e) {
			char[] stringArray = MetricName.toCharArray();
			stringArray[0] = Character.toUpperCase(stringArray[0]);
			String MetricNameWithFirstCharCaps = new String(stringArray);
			response.getWriter().write(MetricNameWithFirstCharCaps + "Not  Successfully Updated");
			MetricNameWithFirstCharCaps=null;
			log.error("IN UpdateMetricThreshold some ERROR is here :"
					+ e.getMessage());
			e.printStackTrace();
		}
            finally {
            out.close();
        }
    }
protected void processRequest ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { log . debug ( "==============================UpdateMetricThreshold===========================================" ) ; response . setContentType ( "text/html;charset=UTF-8" ) ; PrintWriter out = response . getWriter ( ) ; PropertyUtil propertyUtil = null ; Statement st = null ; PreparedStatement prest = null ; ResultSet rs = null ; String sql = "" ; int record_count = 0 ; try { propertyUtil = new PropertyUtil ( ) ; String customer = request . getParameter ( "CustomerName" ) ; String ServiceName = request . getParameter ( "ServiceName" ) ; MetricName = propertyUtil . getreverseMapping_Properties ( ) . get ( request . getParameter ( "MetricName" ) ) ; String SLAValue = request . getParameter ( "SLAValue" ) ; String resourceId = request . getParameter ( "resourceId" ) ; String host = request . getParameter ( "host" ) ; String resourceType = request . getParameter ( "resourceTypeName" ) ; Connection uniqueconnection = ConnectionDAO . getConnection ( customer ) ; sql = "update servicemetrics set SLA= ? where metrictype= ? and host=? and resourceid=? and timestamp1=(select max(timestamp1) from servicemetrics where resourceType='" + resourceType + "' and metrictype='" + MetricName + "' and host='" + host + "' and resourceid='" + resourceId + "')" ; prest = uniqueconnection . prepareStatement ( sql ) ; prest . setDouble ( 1 , Double . parseDouble ( SLAValue ) ) ; prest . setString ( 2 , MetricName ) ; prest . setString ( 3 , host ) ; prest . setString ( 4 , resourceId ) ; prest . executeUpdate ( ) ; String check_query = "select count(*) as count from smetricslathresholds where metrictype ='" + MetricName + "' and service ='" + ServiceName + "' and host='" + host + "' and resourceid='" + resourceId + "'" ; st = uniqueconnection . createStatement ( ) ; rs = st . executeQuery ( check_query ) ; while ( rs . next ( ) ) { record_count = rs . getInt ( "count" ) ; } if ( record_count == 0 ) { sql = "insert into smetricslathresholds (metricthresholdvalue,metrictype,service,host,resourceid,resourcetype) values(?,?,?,?,?,?)" ; System . out . println ( sql ) ; } else { sql = "update smetricslathresholds set metricthresholdvalue= ? where metrictype= ? and service= ? and host=? and resourceid=? and resourcetype=?" ; } prest = uniqueconnection . prepareStatement ( sql ) ; prest . setDouble ( 1 , Double . parseDouble ( SLAValue ) ) ; prest . setString ( 2 , MetricName ) ; prest . setString ( 3 , ServiceName ) ; prest . setString ( 4 , host ) ; prest . setString ( 5 , resourceId ) ; prest . setString ( 6 , resourceType ) ; prest . executeUpdate ( ) ; char [ ] stringArray = MetricName . toCharArray ( ) ; stringArray [ 0 ] = Character . toUpperCase ( stringArray [ 0 ] ) ; String MetricNameWithFirstCharCaps = new String ( stringArray ) ; log . info ( "in Update metric threshold \n ServiceName=" + ServiceName + "MetricName=" + MetricName + "SLAValue=" + SLAValue ) ; response . getWriter ( ) . write ( MetricNameWithFirstCharCaps + " Successfully Updated" ) ; MetricNameWithFirstCharCaps = null ; log . debug ( "==============================End of UpdateMetricThreshold===========================================" ) ; } catch ( Exception e ) { char [ ] stringArray = MetricName . toCharArray ( ) ; stringArray [ 0 ] = Character . toUpperCase ( stringArray [ 0 ] ) ; String MetricNameWithFirstCharCaps = new String ( stringArray ) ; response . getWriter ( ) . write ( MetricNameWithFirstCharCaps + "Not  Successfully Updated" ) ; MetricNameWithFirstCharCaps = null ; log . error ( "IN UpdateMetricThreshold some ERROR is here :" + e . getMessage ( ) ) ; e . printStackTrace ( ) ; } finally { out . close ( ) ; } }
This method is for updating threshold values of each metric type of each service
 and then returning JSON String for creating JSON Files for generating Chart
This method is for updating threshold values of each metric type of each service and then returning JSON String for creating JSON Files for generating Chart