Index: /branches/amp_3_7/extensions/license_server/license_server/server/http_server.c
===================================================================
--- /branches/amp_3_7/extensions/license_server/license_server/server/http_server.c	(revision 2647)
+++ /branches/amp_3_7/extensions/license_server/license_server/server/http_server.c	(working copy)
@@ -693,144 +693,131 @@
 
     /* get the device version and update the version and connection of device. */
     version_json = cJSON_GetObjectItem(root_json, "version");
+    host = cJSON_GetObjectItem(root_json, "device_id")->valuestring;
     real_bandwidth = cJSON_GetObjectItem(root_json, "bandwidth")->valuestring;
-    char select_sql[100];
-    PGresult *result = NULL;
+    strncpy(device_host, host, sizeof(device_host));
+    strncpy(version, version_json->valuestring, sizeof(version));
+    /* check if the host is already registered */
+    if (!check_device(device_host)) {
+        response = make_response_json(FAILURE_STATUS, "The device was not registered.", NULL, action_name, host);
+        goto end;
+    }
 
-    sprintf(select_sql, "select id from device2;");
-    result = db_fetch(select_sql);
+    sprintf(update_sql, "update device2 set version = '%s', connection = 'connected', rel_bandwith = '%s' where id = '%s';", version, real_bandwidth, device_host);
 
-    if (result) {
-        for (i = 0; i < PQntuples(result); i++) {
-            if (PQgetvalue(result, i, 0)) {
-                host = PQgetvalue(result, i, 0);
-                strncpy(device_host, host, sizeof(device_host));
-                strncpy(version, version_json->valuestring, sizeof(version));
-                /* check if the host is already registered */
-                if (!check_device(device_host)) {
-                    response = make_response_json(FAILURE_STATUS, "The device was not registered.", NULL, action_name, host);
-                    goto end;
-                }
+    if (db_execute(update_sql) < 0) {
+        response = make_response_json(FAILURE_STATUS, "Update device heartbeat info error.", NULL, action_name, host);
+        goto end;
+    }
 
-                sprintf(update_sql, "update device2 set version = '%s', connection = 'connected', rel_bandwith = '%s' where id = '%s';", version, real_bandwidth, device_host);
+    /* here need to query the AMP serial number and insert it into response data. */
+    serial_number = get_cm_serial_number();
+    if (!serial_number) {
+        response = make_response_json(FAILURE_STATUS, "Cannot get the AMP serial number.", NULL, action_name, host);
+        goto end;
+    }
 
-                if (db_execute(update_sql) < 0) {
-                    response = make_response_json(FAILURE_STATUS, "Update device heartbeat info error.", NULL, action_name, host);
-                    goto end;
-                }
+    /* check the deivce memory. */
+    memory = get_device_memory_from_version(device_host);
+    if (!memory) {
+        response = make_response_json(FAILURE_STATUS, "The memory of this device is wrong.", NULL, action_name, host);
+        goto end;
+    }
 
-                /* here need to query the AMP serial number and insert it into response data. */
-                serial_number = get_cm_serial_number();
-                if (!serial_number) {
-                    response = make_response_json(FAILURE_STATUS, "Cannot get the AMP serial number.", NULL, action_name, host);
-                    goto end;
-                }
+    /* check the device status. 1->enabled, 0->new(disbaled). */
+    device_status = get_device_status(device_host);
+
+    /* record the timestmap of this device heartbeat request. */
+    record_timestamp_by_device_id(device_host, device_status);
 
-                /* check the deivce memory. */
-                memory = get_device_memory_from_version(device_host);
-                if (!memory) {
-                    response = make_response_json(FAILURE_STATUS, "The memory of this device is wrong.", NULL, action_name, host);
-                    goto end;
+    /* build a json object for response data and this space will be freed in function `make_response_json`. */
+    response_data = cJSON_CreateObject();
+    cJSON_AddStringToObject(response_data, "device_id", device_host);
+    // cJSON_AddNumberToObject(response_data, "status", device_status);
+    /* serial number for device to check the validation of AMP. */
+    cJSON_AddStringToObject(response_data, "serial_number", serial_number);
+
+    if (device_status) { /* device is enabled. */
+
+        /* get the license key which enabled this device from DB and this license_key need to be freed. */
+        license_name = get_licesne_info_by_device_id(device_host, "license_name");
+        license_key = get_licesne_key_by_license_name(license_name);
+
+        /* check the license key expire time. */
+        expire_date = get_license_value(license_name, "expiration_date");
+
+        if (check_date(expire_date) == 0) {
+            device_status = 0;
+            cJSON_AddNumberToObject(response_data, "status", device_status);
+            cJSON_AddStringToObject(response_data, "msg", "The license is expired.");
+            response = make_response_json(SUCCESS_STATUS, "The license is expired.", response_data, action_name, host);
+
+            /* update device set license_name, resources, status*/      
+            char resource_str[1024];
+
+            for(i = 0; i < RESOURCES_NUM; i++) {
+                if (resource_db_mapping[i].resource_id && resource_db_mapping[i].active) {
+                    sprintf(resource_str, ", %s = %d", resource_db_mapping[i].occupied_col, (i != 2) ? 1 : 0);
                 }
+            }
+            char sql_update[100];
+            sprintf(sql_update, "update device2 set status = 'new', license_name = NULL%s  where id = '%s';", resource_str, device_host);
 
-                /* check the device status. 1->enabled, 0->new(disbaled). */
-                device_status = get_device_status(device_host);
+            db_execute(sql_update);
+            goto end;
+        }
 
-                /* record the timestmap of this device heartbeat request. */
-                record_timestamp_by_device_id(device_host, device_status);
+        cJSON_AddNumberToObject(response_data, "status", device_status);
 
-                /* build a json object for response data and this space will be freed in function `make_response_json`. */
-                response_data = cJSON_CreateObject();
-                cJSON_AddStringToObject(response_data, "device_id", device_host);
-                // cJSON_AddNumberToObject(response_data, "status", device_status);
-                /* serial number for device to check the validation of AMP. */
-                cJSON_AddStringToObject(response_data, "serial_number", serial_number);
-
-                if (device_status) { /* device is enabled. */
-
-                    /* get the license key which enabled this device from DB and this license_key need to be freed. */
-                    license_name = get_licesne_info_by_device_id(device_host, "license_name");
-                    license_key = get_licesne_key_by_license_name(license_name);
-
-                    /* check the license key expire time. */
-                    expire_date = get_license_value(license_name, "expiration_date");
-
-                    if (check_date(expire_date) == 0) {
-                        device_status = 0;
-                        cJSON_AddNumberToObject(response_data, "status", device_status);
-                        cJSON_AddStringToObject(response_data, "msg", "The license is expired.");
-                        response = make_response_json(SUCCESS_STATUS, "The license is expired.", response_data, action_name, host);
-
-                        /* update device set license_name, resources, status*/      
-                        char resource_str[1024];
-
-                        for(i = 0; i < RESOURCES_NUM; i++) {
-                            if (resource_db_mapping[i].resource_id && resource_db_mapping[i].active) {
-                                sprintf(resource_str, ", %s = %d", resource_db_mapping[i].occupied_col, (i != 3) ? 1 : 0);
-                            }
-                        }
-                        char sql_update[100];
-                        sprintf(sql_update, "update device2 set status = 'new', license_name = NULL%s  where id = '%s';", resource_str, device_host);
-
-                        db_execute(sql_update);
-                        goto end;
-                    }
-
-                    cJSON_AddNumberToObject(response_data, "status", device_status);
-
-                    free(expire_date);
-
-                    if (license_key) {
-                        cJSON_AddStringToObject(response_data, "license_key", license_key);
-                    }
-                    if (license_name) {
-                        cJSON_AddStringToObject(response_data, "license_name", license_name);
-                    }
-
-                    /* query the resource this device can take by using this license key and insert resource into the response data. */
-
-                    assign_result = assign_resource(license_name, device_host, resource_table, CONNECTED, device_status, memory);
-
-                    free(license_name);
-
-                    /* 
-                       insert this resource table into the response data. 
-                       build a array json and insert each resource into this array.
-                       */
-                    resource_list = cJSON_CreateArray();
-
-                    if (assign_result > 0) {
-
-                        for (i = 0; i < assign_result; i++) {
-                            int index = resource_table[i].resource_id - 1;
-                            char *column_name = resource_db_mapping[index].occupied_col;
-                            sprintf(resource_str, "%s = %d", column_name, resource_table[i].quantity);
-                            char heartbeat_sql[100];
-                            sprintf(heartbeat_sql, "update device2 set %s where id = '%s';", resource_str, device_host);
-                            db_execute(heartbeat_sql);
-
-                            resource_data = cJSON_CreateObject();
-                            cJSON_AddNumberToObject(resource_data, "resource_id", resource_table[i].resource_id);
-                            cJSON_AddStringToObject(resource_data, "resource_name", resource_table[i].resource_name);
-                            cJSON_AddNumberToObject(resource_data, "quantity", resource_table[i].quantity);
-
-                            cJSON_AddItemToArray(resource_list, resource_data);
-                        }
-                        cJSON_AddItemToObject(response_data, "resource", resource_list);
-                    } else if (assign_result == -1) {
-                        cJSON_AddNumberToObject(response_data, "status", FAILURE_STATUS);
-                        cJSON_AddStringToObject(response_data, "msg", "Cannot enable this device because the license does not manage this memory type or the number of management has reached the upper limit.");
-                    }
-                } else {
-                    cJSON_AddNumberToObject(response_data, "status", device_status);
-                    cJSON_AddStringToObject(response_data, "msg", "This device is not enabled.");
-                }
+        free(expire_date);
+
+        if (license_key) {
+            cJSON_AddStringToObject(response_data, "license_key", license_key);
+        }
+        if (license_name) {
+            cJSON_AddStringToObject(response_data, "license_name", license_name);
+        }
+
+        /* query the resource this device can take by using this license key and insert resource into the response data. */
 
-                response = make_response_json(SUCCESS_STATUS, "Heartbeat successfully.", response_data, action_name, host);
+        assign_result = assign_resource(license_name, device_host, resource_table, CONNECTED, device_status, memory);
+
+        free(license_name);
+
+        /* 
+           insert this resource table into the response data. 
+           build a array json and insert each resource into this array.
+           */
+        resource_list = cJSON_CreateArray();
+
+        if (assign_result > 0) {
+
+            for (i = 0; i < assign_result; i++) {
+                int index = resource_table[i].resource_id - 1;
+                char *column_name = resource_db_mapping[index].occupied_col;
+                sprintf(resource_str, "%s = %d", column_name, resource_table[i].quantity);
+                char heartbeat_sql[100];
+                sprintf(heartbeat_sql, "update device2 set %s where id = '%s';", resource_str, device_host);
+                db_execute(heartbeat_sql);
+
+                resource_data = cJSON_CreateObject();
+                cJSON_AddNumberToObject(resource_data, "resource_id", resource_table[i].resource_id);
+                cJSON_AddStringToObject(resource_data, "resource_name", resource_table[i].resource_name);
+                cJSON_AddNumberToObject(resource_data, "quantity", resource_table[i].quantity);
+
+                cJSON_AddItemToArray(resource_list, resource_data);
             }
+            cJSON_AddItemToObject(response_data, "resource", resource_list);
+        } else if (assign_result == -1) {
+            cJSON_AddNumberToObject(response_data, "status", FAILURE_STATUS);
+            cJSON_AddStringToObject(response_data, "msg", "Cannot enable this device because the license does not manage this memory type or the number of management has reached the upper limit.");
         }
-        db_free(result);
+    } else {
+        cJSON_AddNumberToObject(response_data, "status", device_status);
+        cJSON_AddStringToObject(response_data, "msg", "This device is not enabled.");
     }
+
+    response = make_response_json(SUCCESS_STATUS, "Heartbeat successfully.", response_data, action_name, host);
 end:
     /* if it did not query all license info, remove a specified number of bytes data from the beginning of an evbuffer. */
     if (len) {
Index: /branches/amp_3_7/extensions/license_server/license_server/server/license_kernel.c
===================================================================
--- /branches/amp_3_7/extensions/license_server/license_server/server/license_kernel.c	(revision 2647)
+++ /branches/amp_3_7/extensions/license_server/license_server/server/license_kernel.c	(working copy)
@@ -551,7 +551,7 @@
 
     for(i = 0; i < RESOURCES_NUM; i++) {
         if (resource_db_mapping[i].resource_id && resource_db_mapping[i].active) {
-            sprintf(resource_str, ", %s = %d", resource_db_mapping[i].occupied_col, (i != 3) ? 1 : 0);
+            sprintf(resource_str, ", %s = %d", resource_db_mapping[i].occupied_col, (i != 2) ? 1 : 0);
         }
     }
 
Index: /branches/amp_3_7/scripts/install.sh
===================================================================
--- /branches/amp_3_7/scripts/install.sh	(revision 2647)
+++ /branches/amp_3_7/scripts/install.sh	(working copy)
@@ -25,7 +25,6 @@
 echo '* hard nofile 65536' >> /etc/security/limits.conf
 echo 'vm.max_map_count=655360' >> /etc/sysctl.conf
 
-mv $DIR/exts/license_server-3.7.0-1.el7.centos.x86_64.rpm $DIR/exts/license_server-3.7.0-1.el7.centos.x86_64.rpm.backup
 cd $DIR/system && rpm -Uvh *.rpm
 cd $DIR/exts && rpm -Uvh *.rpm
 /bin/cp -rf /ca/webui/exfiles/python/lib/* /usr/lib/python2.7/site-packages/
