void RestRollupsUri::handle_post(http_request request) { std::cout << request.method() << " : " << request.absolute_uri().path() << std::endl; int rc = 0; std::string resultstr; std::pair<bool, std::string> result {true, std::string()}; char json[1024]; // extract json from request snprintf(json, sizeof(json), "%s", request.extract_string(true).get().c_str()); std::cout << "JSON:\n" << json << std::endl; rapidjson::Document document; if (document.Parse(json).HasParseError()) { rc = 1; resultstr += "document invalid"; } rapidjson::SchemaValidator validator(*_schema); if (!document.Accept(validator)) { rc = 1; resultstr += get_schema_validation_error(&validator); } rapidjson::Value::MemberIterator name = document.FindMember("name"); rapidjson::Value::MemberIterator nocsv = document.FindMember("nocsv"); rapidjson::Value::MemberIterator quantity = document.FindMember("quantity"); rapidjson::Value::MemberIterator maxdroop = document.FindMember("maxDroop"); rapidjson::Value::MemberIterator maxsdroop_validation = document.FindMember("maxDroopMaxtoMinIOPSSection"); // Execute Ivy Engine command if (rc == 0) { std::unique_lock<std::mutex> u_lk(goStatementMutex); std::pair<int, std::string> rslt = m_s.create_rollup(name->value.GetString(), (nocsv != document.MemberEnd() ? nocsv->value.GetBool() : false), false /* have_quantity_validation */, (maxsdroop_validation != document.MemberEnd() ? maxsdroop_validation->value.GetBool() : false), (quantity != document.MemberEnd() ? quantity->value.GetInt() : 1), (maxdroop != document.MemberEnd() ? maxdroop->value.GetDouble() : 6.95323e-310)); } http_response response(status_codes::OK); make_response(response, resultstr, result); request.reply(response); }
// Respond to HTTP::POST messages // Post data will contain the postal code or location string. // Aggregate location data from different services and reply to the POST request. void CasaLens::handle_post(http_request message) { auto path = message.relative_uri().path(); if (0 == path.compare(U("/"))) { message.extract_string() .then([=](const utility::string_t& location) { get_data(message, location); }) .then([](pplx::task<void> t) { handle_error(t); }); } else { message.reply(status_codes::NotFound, U("Path not found")).then([](pplx::task<void> t) { handle_error(t); }); } }
// Respond to HTTP::POST messages // Post data will contain the postal code or location string. // Aggregate location data from different services and reply to the POST request. void CasaLens::handle_post(http_request message) { auto path = message.relative_uri().path(); if (0 == path.compare(U("/"))) { message.extract_string().then([=](const utility::string_t& location) { get_data(message, location); }).then(std::bind(&handle_error, std::placeholders::_1)); } else { message.reply(status_codes::NotFound, U("Path not found")).then(std::bind(&handle_error, std::placeholders::_1)); } }
void RestRollupsUri::handle_put(http_request request) { std::cout << request.method() << " : " << request.absolute_uri().path() << std::endl; int rc = 0; std::string resultstr; std::pair<bool, std::string> result {true, std::string()}; char json[1024]; // extract json from request snprintf(json, sizeof(json), "%s", request.extract_string(true).get().c_str()); std::cout << "JSON:\n" << json << std::endl; rapidjson::Document document; if (document.Parse(json).HasParseError()) { rc = 1; resultstr += "document invalid"; } rapidjson::SchemaValidator validator(*_schema); if (!document.Accept(validator)) { rc = 1; resultstr += get_schema_validation_error(&validator); } rapidjson::Value::MemberIterator name = document.FindMember("name"); rapidjson::Value::MemberIterator parameters = document.FindMember("parameters"); // Execute Ivy Engine command if (rc == 0) { std::unique_lock<std::mutex> u_lk(goStatementMutex); std::pair<int, std::string> rslt = m_s.edit_rollup(name->value.GetString(), parameters->value.GetString()); } http_response response(status_codes::OK); make_response(response, resultstr, result); request.reply(response); }
void RestEngineUri::handle_post(http_request request) { std::cout << request.method() << " : " << request.absolute_uri().path() << std::endl; std::cout << request.method() << " : " << request.headers()["Cookie"] << std::endl; int rc = 0; std::string resultstr; std::pair<bool, std::string> result {true, std::string()}; std::string cookie = request.headers()["Cookie"]; if (cookie != "session_cookie=" + _active_session_token) { //http_response response(status_codes::Locked); //make_response(response, resultstr, result); //request.reply(response); //return; } if (!is_session_owner(request)) { send_busy_response(request); return; } ostringstream o; o << "COOKIE:" << cookie << std::endl; o << "ACTIVE COOKIE:" << _active_session_token << std::endl; std::cout << o.str(); log (m_s.masterlogfile,o.str()); char json[1024]; // extract json from request snprintf(json, sizeof(json), "%s", request.extract_string(true).get().c_str()); std::cout << "JSON:\n" << json << std::endl; rapidjson::Document document; if (document.Parse(json).HasParseError()) { rc = 1; resultstr += "document invalid"; } rapidjson::SchemaValidator validator(*_schema); if (!document.Accept(validator)) { rc = 1; resultstr += get_schema_validation_error(&validator); } std::string select_str; std::string hosts_list; const Value& hosts = document["hosts"]; json_to_host_list(hosts, hosts_list); const Value& select = document["select"]; json_to_select_str(select, select_str); // Execute Ivy Engine command if (rc == 0) { std::unique_lock<std::mutex> u_lk(goStatementMutex); std::string outputfolder = m_s.get("output_folder_root").second; std::string testname = m_s.get("test_name").second; result = m_s.startup(outputfolder, testname, m_s.ivyscript_filename, hosts_list, select_str); } http_response response(status_codes::OK); make_response(response, resultstr, result); request.reply(response); }
void RestEngineUri::handle_put(http_request request) { std::cout << request.method() << " : " << request.absolute_uri().path() << std::endl; int rc = 0; std::string resultstr; std::pair<bool, std::string> result {true, std::string()}; uri req_uri = request.absolute_uri(); std::map<utility::string_t, utility::string_t> qmap = req_uri.split_query(req_uri.query()); for (auto& kv : qmap) { if (kv.first == "output_folder_root" || kv.first == "test_name") { std::cout << kv.first << " = " << kv.second << std::endl; // Execute Ivy Engine command if (rc == 0) { std::unique_lock<std::mutex> u_lk(goStatementMutex); if (kv.first == "output_folder_root") m_s.outputFolderRoot = kv.second; if (kv.first == "test_name") m_s.testName = kv.second; http_response response(status_codes::OK); make_response(response, resultstr, result); request.reply(response); return; } } } char json[1024]; // extract json from request snprintf(json, sizeof(json), "%s", request.extract_string(true).get().c_str()); std::cout << "JSON:\n" << json << std::endl; rapidjson::Document document; if (document.Parse(json).HasParseError()) { rc = 1; resultstr += "document invalid"; } rapidjson::SchemaValidator validator(*_schema); if (!document.Accept(validator)) { rc = 1; resultstr += get_schema_validation_error(&validator); } rapidjson::Value::MemberIterator step = document.FindMember("stepname"); rapidjson::Value::MemberIterator warmup = document.FindMember("warmup_seconds"); rapidjson::Value::MemberIterator measure_seconds = document.FindMember("measure_seconds"); rapidjson::Value::MemberIterator subinterval = document.FindMember("subinterval_seconds"); rapidjson::Value::MemberIterator measure = document.FindMember("measure"); rapidjson::Value::MemberIterator accuracy = document.FindMember("accuracy_plus_minus"); rapidjson::Value::MemberIterator timeout_seconds = document.FindMember("timeout_seconds"); rapidjson::Value::MemberIterator max_wp = document.FindMember("max_wp"); rapidjson::Value::MemberIterator min_wp = document.FindMember("min_wp"); rapidjson::Value::MemberIterator max_wp_change = document.FindMember("max_wp_change"); rapidjson::Value::MemberIterator dfc = document.FindMember("dfc"); rapidjson::Value::MemberIterator low_IOPS = document.FindMember("low_IOPS"); rapidjson::Value::MemberIterator low_target = document.FindMember("low_target"); rapidjson::Value::MemberIterator high_IOPS = document.FindMember("high_IOPS"); rapidjson::Value::MemberIterator high_target = document.FindMember("high_target"); rapidjson::Value::MemberIterator target_value = document.FindMember("target_value"); std::ostringstream parameters; parameters << "stepname=\"" << step->value.GetString() << "\""; if (warmup != document.MemberEnd()) parameters << ", warmup_seconds=" << warmup->value.GetInt(); if (measure_seconds != document.MemberEnd()) parameters << ", measure_seconds=" << measure_seconds->value.GetInt(); if (subinterval != document.MemberEnd()) parameters << ", subinterval_seconds=" << subinterval->value.GetInt(); if (measure != document.MemberEnd()) parameters << ", measure=" << measure->value.GetString(); if (accuracy != document.MemberEnd()) parameters << ", accuracy_plus_minus=\"" << accuracy->value.GetString() << "\""; if (timeout_seconds != document.MemberEnd()) { if (timeout_seconds->value.IsString()) parameters << ", timeout_seconds=\"" << timeout_seconds->value.GetString() << "\""; else parameters << ", timeout_seconds=\"" << timeout_seconds->value.GetInt() << "\""; } if (max_wp != document.MemberEnd()) parameters << ", max_wp=\"" << max_wp->value.GetString() << "\""; if (min_wp != document.MemberEnd()) parameters << ", min_wp=\"" << min_wp->value.GetString() << "\""; if (max_wp_change != document.MemberEnd()) parameters << ", max_wp_change=\"" << max_wp_change->value.GetString() << "\""; if (dfc != document.MemberEnd()) parameters << ", dfc=" << dfc->value.GetString(); if (low_IOPS != document.MemberEnd()) parameters << ", low_IOPS=\"" << low_IOPS->value.GetString() << "\""; if (low_target != document.MemberEnd()) parameters << ", low_target=\"" << low_target->value.GetString() << "\""; if (high_IOPS != document.MemberEnd()) parameters << ", high_IOPS=\"" << high_IOPS->value.GetString() << "\""; if (high_target != document.MemberEnd()) parameters << ", high_target=\"" << high_target->value.GetString() << "\""; if (target_value != document.MemberEnd()) parameters << ", target_value=\"" << target_value->value.GetString() << "\""; // Execute Ivy Engine command if (rc == 0) { std::unique_lock<std::mutex> u_lk(goStatementMutex); result = m_s.go(parameters.str()); } //resultstr += (result.first ? "Successful" : "Failed"); //resultstr += " Reason: "; //resultstr += result.second; http_response response(status_codes::OK); make_response(response, resultstr, result); request.reply(response); }