public function feedbackAction() { $this->setNoViewRender(true); $hostname = $this->getRequest("hostname", ""); $ip = $this->getRequest("ip", ""); $node_whole = $this->getRequest("node_whole", ""); $idc = $this->getRequest("idc", ""); $value_md5 = $this->getRequest("value_md5", ""); $value = $this->getRequest("value", ""); $update_time = $this->getRequest("update_time", ""); $data_type = $this->getRequest("data_type", ""); // 0. get client ip $client_ip = self::getClientIp(); QconfMgrLog::err(__FILE__, __LINE__, "client_ip({$client_ip})" . "hostname({$hostname}), node_whole({$node_whole}), idc({$idc}), value_md5({$value_md5}) or data_type({$data_type})!"); // 1. validation for parameters if ($hostname === "" || $node_whole === "" || $idc === "" || $value_md5 === "" || $data_type === "") { //$res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "hostname({$hostname}), node_whole({$node_whole}), idc({$idc}), value_md5({$value_md5}) or data_type({$data_type}) is NULL!"); echo InfoDescUtil::ERR_BAD_ARGS; return; } $md5_len = strlen($value_md5); if ($md5_len != 32) { //$res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MD5_VALUE); QconfMgrLog::err(__FILE__, __LINE__, "Error length value_md5(value_md5) : {$md5_len}!"); echo InfoDescUtil::ERR_MD5_VALUE; return; } $format_time = date('Y-m-d H:i:s', $update_time); if ($format_time === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "error update_time format: {$update_time}"); //$res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); echo InfoDescUtil::ERR_UPDATE_TIME; return; } if ($data_type != InfoDescUtil::QCONF_DATA_TYPE_NODE && $data_type != InfoDescUtil::QCONF_DATA_TYPE_SERVICE) { QconfMgrLog::err(__FILE__, __LINE__, "error data_type: {$data_type}"); //$res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); echo InfoDescUtil::ERR_DATA_TYPE; return; } if (!ZkConf::isLegalIdc($idc)) { QconfMgrLog::err(__FILE__, __LINE__, "error idc: {$idc}"); $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_EXIST); echo InfoDescUtil::ERR_IDC_NOT_EXIST; return; } // 2.distinguish situation need add new item and modify old item $fd_item = FeedbackServ::checkFeedback($hostname, $node_whole, $idc, $data_type); $result = FALSE; if ($fd_item === FALSE) { //add new item $retry_time = 0; while ($result === FALSE && $retry_time < InfoDescUtil::MYSQL_MAX_RETRY_TIME) { $result = FeedbackServ::addFeedback($hostname, $ip, $node_whole, $idc, $data_type, $value_md5, $value, $format_time); if ($retry_time++ > 0) { QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} to add feedback with hostname({$hostname})" . " node_whole({$node_whole}) idc({$idc}), data_type({$data_type})!"); } } if ($result != FALSE) { FeedbackOpServ::recordOp(InfoDescUtil::OP_TYPE_FEEDBACK_ADD, $hostname, $node_whole, $idc, $data_type, $value_md5, $format_time); } } else { $old_update_time = $fd_item["update_time"]; if ($update_time < strtotime($old_update_time)) { QconfMgrLog::err(__FILE__, __LINE__, "update_time early than the last one, discard hostname({$hostname})," . " node_whole({$node_whole}) idc({$idc}), data_type({$data_type})!"); $result = TRUE; } else { $feedback_id = $fd_item["feedback_id"]; $retry_time = 0; while ($result === FALSE && $retry_time < InfoDescUtil::MYSQL_MAX_RETRY_TIME) { $result = FeedbackServ::modifyFeedback($feedback_id, $ip, $value_md5, $value, $format_time); if ($retry_time++ > 0) { QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} to modify feedback with hostname({$hostname})" . " node_whole({$node_whole}) idc({$idc}), data_type({$data_type})!"); } } if ($result != FALSE) { FeedbackOpServ::recordOp(InfoDescUtil::OP_TYPE_FEEDBACK_MODIFY, $hostname, $node_whole, $idc, $data_type, $value_md5, $format_time); } } } // 3. record feedback failed if ($result === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "Failed to record feedback for hostname({$hostname}),\n node_whole({$node_whole}), idc({$idc})!"); echo InfoDescUtil::ERR_MYSQL_FAIL; return; } echo InfoDescUtil::QCONF_OK; return; }