Index: /branches/rel_apv_10_4_0_112_india/usr/click/lib/libkernelapi/addCommands.pm
===================================================================
--- /branches/rel_apv_10_4_0_112_india/usr/click/lib/libkernelapi/addCommands.pm	(revision 37874)
+++ /branches/rel_apv_10_4_0_112_india/usr/click/lib/libkernelapi/addCommands.pm	(working copy)
@@ -3699,6 +3699,13 @@
                 {type => "OUTDATA"},
             ],
     },
+    {
+        cmd_attribute => "CMD_KERN_API",
+        function_name => "is_duplicate_session_qos_name",
+        function_args => [
+            {type => "STRING"},
+            ],
+    },
     # Bug 14949(QoS), end
 #WRITE cache_filter_kern add by zhangjz
     {
@@ -4135,6 +4142,15 @@
 			{type => "INDATA"},
 		    ],
 	},
+        {
+                cmd_attribute => "CMD_KERN_API",
+                function_name => "handle_session_qos_cleanup",
+                function_args => [
+                        {type => "STRING"},
+                        {type => "U32"},
+                        {type => "STRING"},
+                ],
+        },
 	# Bug 14949(QoS), end
 	# bug 8720, tangmeng, 20060406
 	{
Index: /branches/rel_apv_10_4_0_112_india/usr/click/webui/htdocs/new/src/hive/model/ajax.py
===================================================================
--- /branches/rel_apv_10_4_0_112_india/usr/click/webui/htdocs/new/src/hive/model/ajax.py	(revision 37874)
+++ /branches/rel_apv_10_4_0_112_india/usr/click/webui/htdocs/new/src/hive/model/ajax.py	(working copy)
@@ -12,16 +12,16 @@
 from hive.model.loading import get_app, get_model
 from django.http import Http404
 import json
-from hive.exceptions import ValidationError, ModelQueryException, ActionPerformException, FieldDoesNotExist, ManagerImplError, BadRequestException
+from hive.exceptions import ValidationError, ModelQueryException, ActionPerformException, FieldDoesNotExist, ManagerImplError, BadRequestException, UpdateException
 import copy
 import time
 from jinja2 import Environment, PackageLoader, ChoiceLoader
-from hive.utils import HiveEnvironment, andebug, anerror, url2obj, IntRange, get_time_internal, get_need_db_list
+from hive.utils import HiveEnvironment, andebug, anerror, url2obj, IntRange, get_time_internal
 from hive.model.utils import reduce_asso_value_item, get_complex_field, get_config_list_data, save_config_list_data
 from jinja2.exceptions import TemplateNotFound
 from django.template import RequestContext
 import urllib
-from hive.model.query import mark_expire_all, update_cache_field, mark_expire_one
+from hive.model.query import mark_expire_all, update_cache_field
 from hive.notification import send_notification
 from hive.model.legacycli import cli_parse, EasyParser, RegexParser, MATCHONE, MATCHALL
 from django.utils.importlib import import_module
@@ -29,11 +29,8 @@
 from djproject.an_settings import TEST_IP_POOL, DIR_STR, MAX_FILES_COUNT, RRDCACHED_SOCKET
 from django.utils.translation import ugettext_lazy as _
 from djproject.an_settings import GRAPH_DB_FILE_LIST
-from hive.utils import escapehtml 
 import sqlite3, re
 
-TIMEFORMAT='%Y-%m-%d %X'
-        
 def main():
     pass
 
@@ -72,7 +69,7 @@
             template = env.get_template('/'.join(self.model._meta.path) + '/box_' + sub_action + '.html')
         except TemplateNotFound:
             template = env.get_template('box_' + sub_action + '.html')
-        ctx = {'REQUEST':self.request, 'SESSION':self.session, 'MEDIA':'/media/', 'app_name': self.app._meta.app_label,
+        ctx = {'REQUEST':self.request, 'SESSION':self.session, 'MEDIA':'/media/',
                'MODEL':self.model, 'MANAGER':self.manager, 'csrf_token':django_ctx['csrf_token'], 'PARAMS':kwargs}
         
         if "action=BatchMemberAttr" in self.request.META["REQUEST_URI"]:
@@ -160,13 +157,7 @@
         """
         if 'filter' in kwargs:
             filters = json.loads(urllib.unquote(kwargs['filter']))
-            if 'with_fields' not in kwargs and not filters:
-                try:
-                    return self.manager.list()
-                except ManagerImplError:
-                    qs = self.manager.filter(filters)
-            else:
-                qs = self.manager.filter(filters)
+            qs = self.manager.filter(filters)
         else:
             qs = copy.copy(self.manager.all())
             
@@ -193,12 +184,12 @@
         try:
             new_obj.clean_fields()
         except ValidationError, e:
-            return json.dumps([False, escapehtml(unicode(e))])
+            return json.dumps([False, unicode(e)])
         try:
             self.manager.insert(new_obj)
         except ModelQueryException, e:
             if e.has_error():
-                return json.dumps([False, escapehtml(unicode(e))])
+                return json.dumps([False, unicode(e)])
             elif e.get_detail():
                 return json.dumps([True, new_obj.url_params(), e.get_detail()])
             elif unicode(e):
@@ -207,113 +198,18 @@
         send_notification('info', 'A new %s is added.' % self.model._meta.verbose_name) 
         return json.dumps([True, new_obj.url_params(), []])
 
-    def batch_add(self, **kwargs):
-        new_instance_list = []
-        added_pk_list = []
-        ex_ins_list = []
-        try:
-            json_str = kwargs['post_data']
-            json_list = json.loads(json_str)
-            deriving_fields = self.model._meta.conditional_deriving_fields
-            for each_json in json_list:
-                concrete_dict = {}
-                if self.model._meta.abstract:
-                    for field in deriving_fields:
-                        concrete_dict[field] = each_json[field]
-                    real_model = self.model._meta.get_child_by_field_cond(concrete_dict)
-                else:
-                    real_model = self.model
-                json_data = {}
-                for key in real_model._meta.field_groups['default'].fields:
-                    if key.attname in each_json:
-                        json_data[key.attname] = each_json[key.attname]
-                if "/group/Group/" in self.request.path:
-                    if 'gphc' in each_json and each_json['gphc']:
-                        json_data['healthchecks'] = [{'hc_name':each_json['gphc']}]
-                if "/rs/RealService/" in self.request.path:
-                    if 'hc' in each_json and each_json['hc']:
-                        each_json['hc']['hc_name'] = 'Built-in HealthCheck of %s' % each_json['service_name']
-                        ex_ins_list.append(each_json['hc'])
-                new_obj = real_model(**json_data)
-                try:
-                    new_obj.clean_fields()
-                except ValidationError, e:
-                    return json.dumps([False, 'Add %s Failed: %s' % (new_obj.repr(), unicode(e))])
-                new_instance_list.append(new_obj)
-
-        except KeyError:
-            raise
-        for ins in new_instance_list:
-            try:
-                real_manager = self.session.get_model_manager(self.app._meta.app, ins._meta.path)
-                real_manager.insert(ins)
-                if "/group/Group/" in self.request.path:
-                    real_manager._update_healthchecks(ins)
-            except ModelQueryException, e:
-                mark_expire_all(self.model, clear_all_if_has_asso=True)
-                try:
-                    self.manager.delete(added_pk_list)
-                except:
-                    pass
-                return json.dumps([False, 'Add %s Failed: %s' %(ins.repr(), unicode(e))])
-            added_pk_list.append(ins.pk_dict())
-        try:
-            if "/rs/RealService/" in self.request.path:
-                if len(ex_ins_list):
-                    HCManager = self.session.get_model_manager(self.app._meta.app, 'loadbalancing.slb.healthcheck.HealthCheck')
-                    for hc_info in ex_ins_list:
-                        hc_pk = {"hc_name":hc_info["hc_name"]}
-                        hc_ins = HCManager.get(hc_pk)
-                        old_value_dict = dict(hc_ins.get_field_dict(withstats=False))
-                        for key,value in hc_info.iteritems():
-                            update_cache_field(hc_ins, key, value, False)
-                        try:
-                            hc_ins.clean_fields()
-                        except ValidationError, e:
-                            # roll back
-                            for key,value in old_value_dict.iteritems():
-                                setattr(hc_ins, key, value)
-                            mark_expire_all(self.model, clear_all_if_has_asso=True)
-                            try:
-                                self.manager.delete(added_pk_list)
-                            except:
-                                pass
-                            return json.dumps([False, 'Set %s Failed: %s' %(hc_ins.repr(), unicode(e))])
-                        try:
-                            real_manager = self.session.get_model_manager(self.app._meta.app, hc_ins._meta.path)
-                            real_manager.update(hc_ins,  old_values=old_value_dict)
-                        except ModelQueryException, e:
-                            mark_expire_all(self.model, clear_all_if_has_asso=True)
-                            try:
-                                self.manager.delete(added_pk_list)
-                            except:
-                                pass
-                            return json.dumps([False, 'Set %s Failed: %s' %(hc_ins.repr(), unicode(e))])
-        except ModelQueryException, e:
-            mark_expire_all(self.model, clear_all_if_has_asso=True)
-            try:
-                self.manager.delete(added_pk_list)
-            except:
-                pass
-            return json.dumps([False, 'Set Health Check Failed' + unicode(e)])
-        return json.dumps([True, '', []])
-
     def delete(self, **kwargs):
         try:
             pk_str_list = kwargs['pk'].split('ÿÿÿÿÿ')
             pk_list = [json.loads(pk_str) for pk_str in pk_str_list]
-            if 'additional_field' in kwargs:
-                additional_field = kwargs['additional_field'].split('ÿÿÿÿÿ')
-            else:
-                additional_field = None
+            additional_field = kwargs['additional_field'].split('ÿÿÿÿÿ')
 
-            if additional_field and "/rs/RealService/_delete" in self.request.path:
+            if "/rs/RealService/_delete" in self.request.path:
                 return self.delete_rs_custom(pk_list, additional_field)
             if len(pk_list) == 1:
                 # first try to get the instance, so we can get the real instance model.
                 instance = self.manager.get(pk_list[0])
-                if instance:
-                    send_notification('info', '%s (%s) is deleted.' % (instance.repr_by_pk(pk_list[0]), instance._meta.verbose_name))
+                send_notification('info', '%s (%s) is deleted.' % (instance.repr_by_pk(pk_list[0]), instance._meta.verbose_name))
             else:
                 send_notification('info', '%d %s are deleted.' % (len(pk_list), self.model._meta.verbose_name))
             return self.manager.delete(pk_list)
@@ -359,20 +255,12 @@
         map_dict = {'HTTP': 'http', 'HTTPS': 'https', 'DNS': 'dns', 'FTP': 'ftp', 'SIP over TCP': 'siptcp', 'SIP over UDP': 'sipudp', 
         'RTSP': 'rtsp', 'RDP': 'rdp', 'RADAUTH': 'radauth', 'RADACCT': 'radacct', 'Diameter': 'diameter', 'TCP': 'tcp', 'TCPS': 'tcps',
         'UDP': 'udp', 'Tuxedo': 'tuxedo', 'IP': 'ip', 'Fwdmac': 'fwdmac', 'Fwdip': 'fwdip', 'L2 MAC': 'l2mac', 'L2 IP': 'l2ip'}
-        map_class = {'HTTP': 'L4L7RealService', 'HTTPS': 'L4L7RealService', 'DNS': 'L4L7RealService', 'FTP': 'L4L7RealService', 'SIP over TCP': 'L4L7RealService',
-        'SIP over UDP': 'L4L7RealService',  'Fwdip': 'L4L7RealService','RTSP': 'L4L7RealService', 'RDP': 'L4L7RealService', 'RADAUTH': 'L4L7RealService',
-        'RADACCT': 'L4L7RealService', 'Diameter': 'L4L7RealService', 'TCP': 'L4L7RealService', 'TCPS': 'L4L7RealService','UDP': 'L4L7RealService', 
-        'Tuxedo': 'TUXEDORealService', 'IP': 'IPRealService', 'Fwdmac': 'FWDMACRealService','L2 MAC': 'L2MACRealService', 'L2 IP': 'L2IPRealService'}
         
         mod = get_model('apv', ['loadbalancing', 'slb', 'rs', 'RealService'])    
         for i in range(len(pk_list)):
             each = pk_list[i]
             output = self.session.cli.cmd('no slb real %s "%s"' % (map_dict[additional_field[i]], each['service_name']))
-            rs_mod = get_model('apv', ['loadbalancing', 'slb', 'rs', '%s'%map_class[additional_field[i]]])
-            mark_expire_one(rs_mod, pk_list[i])
             mark_expire_all(mod)
-        node_mod = get_model('apv', ['loadbalancing', 'slb', 'node', 'Node'])    
-        mark_expire_all(node_mod)
         return output
 
     def get_delete_error_msg(self, e_dict):
@@ -650,6 +538,7 @@
                         # To update interface value for Both direction
                         if 'both' in str(sub_ret['direction']).lower():
                             sub_ret['interface'] = str(sub_ret['interface']).replace('&nbsp; &nbsp; &nbsp;</a>', 'BOTH&nbsp; &nbsp; &nbsp;</a>')
+
                     #add hide data in response, hide data include "pk_str", "action", "functions"
                     hide_data = ins_manager.get_internal_data_for_list(each)
                     sub_ret['internal'] = hide_data
@@ -972,57 +861,21 @@
             value_list = [time_str, num(value)]
         return value_list
 
-    def get_sql_select_info(self, table_name, instance):
-        instance_str = instance.pk_str()
-        if not instance_str:
-            instance_str = '{}'
-        where_str = " where pk is '"
-        if "VirtualService" in table_name:
-            table_name = "GlobalVirtualServiceStats"
-            where_str =  " where service_name is '"
-            instance_str = instance.service_name
-        if "RealService" in table_name:
-            table_name = "GlobalRealServiceStats"
-            where_str =  " where service_name is '"
-            instance_str = instance.service_name
-        if table_name == "PervsCompressStatistics":
-            where_str =  " where service_name is '"
-            instance_str = instance.service_name
-        if table_name in ["LLBLinkRoute"]:
-            table_name = "ExLLBLinkStatistics"
-            where_str =  " where name is '"
-            instance_str = instance.name
-        if table_name in ["ExSSLRealHostStatistics", "ExSSLVirtualHostStatistics"]:
-            where_str =  " where name is '"
-            instance_str = instance.name
-        if table_name in ["LLBGlobalStatistics"]:
-            table_name = "ExLLBLinkStatistics"
-            where_str =  " where name is '"
-            instance_str = instance.service_name
-        if table_name == "DefaultPolicy":
-            if model_list[-2] == "types":
-                # for slb default policy, set table name to slb_DefaultPolicy
-                table_name = "slb_DefaultPolicy"
-        if table_name in ['SystemInterface', 'BondInterface']:
-            instance_str = '{"name": "' + instance.id + '"}'
-        return table_name, where_str, instance_str
-
     def get_statistics_data(self, **kwargs):
         # {'instance':[pk_dict1, pk_dict2, ...], 'field':[xxx, ...]}
         keys = json.loads(kwargs['keys'])
         field_sum = 1
         last_time = ''
+        TIMEFORMAT='%Y-%m-%d %X'
         ret = {}
-        ret['data'] = []
-        ret['data_name'] = []
         if 'key' in kwargs:
             ret['key'] = kwargs['key']
         for field in keys['field']:
             field_sum += 1
         last_value = [0] * field_sum
-
         start = int(kwargs['start_time'])
         end = int(kwargs['end_time'])
+
         end_time = time.time() + end
         if not start:
             start_time = end_time - 1800.0
@@ -1030,19 +883,24 @@
             start_time = time.time() + start
         ret['start_time'] = time.strftime(TIMEFORMAT, time.localtime(start_time))
         ret['end_time'] = time.strftime(TIMEFORMAT, time.localtime(end_time))
-        
-        if "LLBLinkRoute" in self.request.path_info:
-            need_db_list = ["storemon_1.db"]
-            start_db = "storemon_1.db"
-            end_db = "storemon_1.db"
+        ret['data'] = []
+        ret['data_name'] = []
+        u_start = time.strftime(TIMEFORMAT, time.gmtime(start_time))
+        u_end = time.strftime(TIMEFORMAT, time.gmtime(end_time))
+        start_db = u_start.split(' ')[0]+'.db'
+        end_db = u_end.split(' ')[0]+'.db'
+        all_db = filter(lambda e: e.endswith('.db'), os.listdir(GRAPH_DB_FILE_LIST))
+        all_db_list = sorted(all_db)
+        if end_db in all_db_list and start_db in all_db_list:
+            start_index = all_db_list.index(start_db)
+            end_index = all_db_list.index(end_db)
+        elif end_db in all_db_list and start_db not in all_db_list:
+            start_index = 0
+            end_index = all_db_list.index(end_db)
         else:
-            db_info = get_need_db_list(start_time, end_time)
-            start_db = db_info['start_db']
-            end_db = db_info['end_db']
-            need_db_list = db_info['need_db_list']
-            if need_db_list is None:
-                ret['error'] = unicode(_('Fail to query the data.')) 
-                return json.dumps(ret)
+            ret['error'] = unicode(_('Fail to query the data.')) 
+            return json.dumps(ret)
+        need_db_list = all_db_list[start_index:end_index+1]
         for each_db in need_db_list:
             db_file_exist = os.path.isfile(GRAPH_DB_FILE_LIST+each_db)
             if db_file_exist:
@@ -1075,23 +933,29 @@
                             data_name += '('+ unicode(field_obj.unit_name) + ')'
                         ret['data_name'].append(data_name)
                         ret['data'].append([])
-                    
+                    instance_str = instance.pk_str()
+                    if not instance_str:
+                        instance_str = '{}'
                     model_list = instance._meta._model._meta.path
                     table_name = model_list[-1]
-                    table_name, where_str, instance_str = self.get_sql_select_info(table_name, instance)
-                    
+                    if table_name == "DefaultPolicy":
+                        if model_list[-2] == "types":
+                            # for slb default policy, set table name to slb_DefaultPolicy
+                            table_name = "slb_DefaultPolicy"
+                    if table_name in ['SystemInterface', 'BondInterface']:
+                        instance_str = '{"name": "' + instance.id + '"}'
                     if start_db == end_db:
-                        cmd += " from " + table_name + where_str + instance_str +"' and time > " + str(int(start_time)) + " and time < " + str(int(end_time)) + " group by timef"
+                        cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(int(start_time)) + " and time < " + str(int(end_time)) + " group by timef"
                     elif each_db == start_db:
-                        cmd += " from " +  table_name + where_str + instance_str +"' and time > " + str(int(start_time)) + " group by timef"
+                        cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(int(start_time)) + " group by timef"
                     elif each_db == end_db:
-                        cmd += " from " +  table_name + where_str + instance_str +"' and time < " + str(int(end_time)) + " group by timef"
+                        cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time < " + str(int(end_time)) + " group by timef"
                     else:
                         (y,m,d) = each_db.split('.db')[0].split('-')
                         t = (int(y), int(m), int(d), 0, 0, 0, 0, 0, 0)
                         start_secs = int(time.mktime( t ))
                         end_secs = int(time.mktime( t )) + 86400
-                        cmd += " from " +  table_name + where_str + instance_str +"' and time > " + str(start_secs) + " and time < " + str(end_secs) + " group by timef"
+                        cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(start_secs) + " and time < " + str(end_secs) + " group by timef"
                     try:
                         db.execute(cmd)
                     except sqlite3.OperationalError, e:
@@ -1204,7 +1068,7 @@
             return template.render({'THEME': self.session.theme})
 
         group_basic = False
-        if sub_action == "instance_config" and "slb/group/methods" in self.request.path and 'group_name' in self.request.GET and self.request.GET['group_name'] == 'default':
+        if sub_action == "instance_config" and "slb/group/methods" in self.request.path and self.request.GET['group_name'] == 'default':
             group_basic = True
         try:
             template = env.get_template('/'.join(self.model._meta.path) + '/box_' + sub_action + '.html')
@@ -1334,16 +1198,14 @@
             # roll back
             for key,value in old_value_dict.iteritems():
                 setattr(self.object, key, value)
-            return json.dumps([False, escapehtml(unicode(e))])
+            raise UpdateException([False, unicode(e)], 400)
+            # return json.dumps([False, unicode(e)])
         try:
             self.manager.update(self.object, field_list=json_dict.keys(), old_values=old_value_dict)
         except ModelQueryException, e:
             andebug('hive.debug', 'raising exception at ajax\'s update: %s' % old_value_dict)
             if e.has_error():
-                for key, value in old_value_dict.iteritems():
-                    if key in json_dict:
-                        setattr(self.object, key, value)
-                return json.dumps([False, escapehtml(unicode(e))])
+                return json.dumps([False, unicode(e)])
             elif e.get_detail():
                 return json.dumps([True, self.object.url_params(), e.get_detail()])
             else:
@@ -1448,6 +1310,7 @@
         keys = json.loads(kwargs['keys'])
         field_sum = 1
         last_time = ''
+        TIMEFORMAT='%Y-%m-%d %X'
         
         ret = {}
         if 'key' in kwargs:
@@ -1468,19 +1331,23 @@
         ret['data'] = []
         ret['data_name'] = []
         
-        if "LLBGlobalStatistics" in self.request.path_info:
-            need_db_list = ["storemon_1.db"]
-            start_db = "storemon_1.db"
-            end_db = "storemon_1.db"
+        u_start = time.strftime(TIMEFORMAT, time.gmtime(start_time))
+        u_end = time.strftime(TIMEFORMAT, time.gmtime(end_time))
+        start_db = u_start.split(' ')[0]+'.db'
+        end_db = u_end.split(' ')[0]+'.db'
+        
+        all_db = filter(lambda e: e.endswith('.db'), os.listdir(GRAPH_DB_FILE_LIST))
+        all_db_list = sorted(all_db)
+        if end_db in all_db_list and start_db in all_db_list:
+            start_index = all_db_list.index(start_db)
+            end_index = all_db_list.index(end_db)
+        elif end_db in all_db_list and start_db not in all_db_list:
+            start_index = 0
+            end_index = all_db_list.index(end_db)
         else:
-            db_info = get_need_db_list(start_time, end_time)
-            if db_info is None:
-                ret['error'] = unicode(_('Fail to query the data.')) 
-                return json.dumps(ret)
-            start_db = db_info['start_db']
-            end_db = db_info['end_db']
-            need_db_list = db_info['need_db_list']
-            
+            ret['error'] = unicode(_('Fail to query the data.')) 
+            return json.dumps(ret)
+        need_db_list = all_db_list[start_index:end_index+1]
         for each_db in need_db_list:
             db_file_exist = os.path.isfile(GRAPH_DB_FILE_LIST+each_db)
             if db_file_exist:
@@ -1508,11 +1375,6 @@
                 instance_str = instance.pk_str()
                 model_list = instance._meta._model._meta.path
                 table_name = model_list[-1]
-                where_str = " where "
-                if table_name == "SystemStatusGraph":
-                    table_name = "SystemStatus"
-                # if table_name in["GlobalStatistics","GlobalSSLThroughStats", "InterfaceThroughputStatistics"]:
-                #     where_str = " where "
                 if table_name == "DefaultPolicy":
                     if model_list[-2] == "types":
                         # for slb default policy, set table name to slb_DefaultPolicy
@@ -1522,20 +1384,17 @@
                 if not instance_str:
                     instance_str = '{}'
                 if start_db == end_db:
-                    if "LLBGlobalStatistics" in self.request.path_info:
-                        cmd += " from ExLLBLinkStatistics where time > " + str(int(start_time)) + " and time < " + str(int(end_time)) + " group by timef"
-                    else:
-                        cmd += " from " +  table_name + where_str +" time > " + str(int(start_time)) + " and time < " + str(int(end_time)) + " group by timef"
+                    cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(int(start_time)) + " and time < " + str(int(end_time)) + " group by timef"
                 elif each_db == start_db:
-                    cmd += " from " +  table_name + where_str +" time > " + str(int(start_time)) + " group by timef"
+                    cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(int(start_time)) + " group by timef"
                 elif each_db == end_db:
-                    cmd += " from " +  table_name + where_str +" time < " + str(int(end_time)) + " group by timef"
+                    cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time < " + str(int(end_time)) + " group by timef"
                 else:
                     (y,m,d) = each_db.split('.db')[0].split('-')
                     t = (int(y), int(m), int(d), 0, 0, 0, 0, 0, 0)
                     start_secs = int(time.mktime( t ))
                     end_secs = int(time.mktime( t )) + 86400
-                    cmd += " from " +  table_name + where_str +" time > " + str(start_secs) + " and time < " + str(end_secs) + " group by timef"
+                    cmd += " from " +  table_name + " where pk is '" + instance_str +"' and time > " + str(start_secs) + " and time < " + str(end_secs) + " group by timef"
                 try:
                     db.execute(cmd)
                 except sqlite3.OperationalError, e:
@@ -1626,35 +1485,6 @@
                 conn.close()
         return json.dumps(ret)
 
-    def config_sync(self, **kwargs):
-        try:
-            json_str = kwargs['post_data']
-            json_dict = json.loads(json_str)
-            fields = json_dict['fields']
-            tgt_instances = json_dict['instances']
-        except KeyError:
-            raise Http404
-        try:
-            result = self.manager.config_sync(self.object, fields=fields, target_instances=tgt_instances)
-            return json.dumps(result)
-        except ModelQueryException, e:
-            andebug('hive.debug', 'raising exception at ajax\'s config_sync: %s' % json_str)
-            return json.dumps([False, [unicode(e)]])
-
-    def get_syncable_instance_list(self, **kwargs):
-        try:
-            result = self.manager.get_syncable_instance_list(self.object)
-            return result
-        except ManagerImplError:
-            try:
-                return self.manager.list()
-            except ManagerImplError:
-                qs = copy.copy(self.manager.all())
-                rtn = []
-                for each in qs:
-                    each_rtn = {'pk':each.pk_dict(), 'repr':each.repr()}
-                    rtn.append(each_rtn)
-                return json.dumps(rtn)
 if __name__ == '__main__':
     main()
 
