コード例 #1
0
        void deploy_svc_service_impl::on_get_cluster_list_cli(void *context, int argc, const char **argv, dsn_cli_reply *reply)
        {
            dassert(context == (void*)this, "context must be this");

            cluster_list clist;
            std::string format;
            if (argc > 0)
            {
                error_code err = unmarshall_json(argv[0], "format", format);
                if (err != ERR_OK)
                {
                    //TODO: need raise error here?
                    format = std::string("");
                }
            }

            on_get_cluster_list_internal(format, clist);

            std::string* resp_json = new std::string();
            *resp_json = marshall_json(clist);
            reply->context = resp_json;
            reply->message = (const char*)resp_json->c_str();
            reply->size = resp_json->size();
            return;
        }
コード例 #2
0
        void deploy_svc_service_impl::on_get_service_list_cli(void *context, int argc, const char **argv, dsn_cli_reply *reply)
        {
            dassert(context == (void*)this, "context must be this");

            deploy_info_list dlist;
            std::string package_id;

            if (argc >=1)
            {
                error_code err = unmarshall_json(argv[0], "package_id", package_id);
                if (err != ERR_OK)
                {
                    //TODO: need raise error here?
                    package_id = std::string("");
                }
            }
            on_get_service_list_internal(package_id, dlist);

            std::string* resp_json = new std::string();
            *resp_json = marshall_json(dlist);
            reply->context = resp_json;
            reply->message = (const char*)resp_json->c_str();
            reply->size = resp_json->size();
            return;
        }
コード例 #3
0
        inline error_code unmarshall_json(const char* json_str, const char* key, deploy_request& val)
        {
            std::string jstr(json_str);
            std::replace(jstr.begin(), jstr.end(), '\'', '\"');
            rapidjson::Document doc;

            TEST_PARAM(!doc.Parse<0>(jstr.c_str()).HasParseError())
            TEST_PARAM(doc.IsObject())
            TEST_PARAM(doc[key].IsObject())
            TEST_PARAM(doc[key].HasMember("cluster_name"))
            TEST_PARAM(!unmarshall_json(doc[key]["cluster_name"], val.cluster_name))
            TEST_PARAM(doc[key].HasMember("name"))
            TEST_PARAM(!unmarshall_json(doc[key]["name"], val.name))
            TEST_PARAM(doc[key].HasMember("package_full_path"))
            TEST_PARAM(!unmarshall_json(doc[key]["package_full_path"], val.package_full_path))
            TEST_PARAM(doc[key].HasMember("package_id"))
            TEST_PARAM(!unmarshall_json(doc[key]["package_id"], val.package_id))
            TEST_PARAM(doc[key].HasMember("package_server"))
            TEST_PARAM(!unmarshall_json(doc[key]["package_server"], val.package_server))

            return ERR_OK;
        };
コード例 #4
0
        inline error_code unmarshall_json(const char* json_str, const char* key, std::string& val)
        {
            std::string jstr(json_str);
            std::replace(jstr.begin(), jstr.end(), '\'', '\"');
            rapidjson::Document doc;

            TEST_PARAM(!doc.Parse<0>(jstr.c_str()).HasParseError())
            TEST_PARAM(doc.IsObject())
            TEST_PARAM(doc.HasMember(key))
            TEST_PARAM(!unmarshall_json(doc[key], val))

            return ERR_OK;
        };
コード例 #5
0
        void deploy_svc_service_impl::on_get_service_info_cli(void *context, int argc, const char **argv, dsn_cli_reply *reply)
        {
            dassert(context == (void*)this, "context must be this");

            deploy_info di;
            std::string service_name;

            if (argc < 1 || ERR_OK != unmarshall_json(argv[0], "service_name", service_name))
            {
                di.error = ERR_INVALID_PARAMETERS;
            }
            else
            {
                on_get_service_info_internal(service_name, di);
            }

            std::string* resp_json = new std::string();
            *resp_json = marshall_json(di);
            reply->context = resp_json;
            reply->message = (const char*)resp_json->c_str();
            reply->size = resp_json->size();
            return;
        }