<commit_before>// Copyright (c) 2016, Baidu.com, Inc. All Rights Reserved
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <map>
#include <boost/algorithm/string.hpp>
#include "rapidjson/document.h"
#include "rapidjson/filereadstream.h"
#include "galaxy_util.h"

namespace baidu {
namespace galaxy {
namespace client {

int ParseDeploy(const rapidjson::Value& deploy_json, ::baidu::galaxy::sdk::Deploy* deploy) {
    //deploy config:replica
    if (!deploy_json.HasMember("replica") || deploy_json["replica"].GetInt() < 0) {
        fprintf(stderr, "replica is required in deploy\n");
        return -1;
    }
    deploy->replica = deploy_json["replica"].GetInt();

    //deploy config:step
    if (!deploy_json.HasMember("step") || deploy_json["step"].GetInt() < 0) {
        fprintf(stderr, "step is required in deploy\n");
        return -1;
    }
    deploy->step = deploy_json["step"].GetInt();

    //deploy config:interval
    if (!deploy_json.HasMember("interval") || deploy_json["interval"].GetInt() < 0) {
        fprintf(stderr, "interval is required in deploy\n");
        return -1;
    }
    deploy->interval = deploy_json["interval"].GetInt();

    //deploy config:max_per_host
    if (!deploy_json.HasMember("max_per_host") || deploy_json["max_per_host"].GetInt() <= 0) {
        fprintf(stderr, "max_per_host is required in deploy\n");
        return -1;
    }
    deploy->max_per_host = deploy_json["max_per_host"].GetInt();
    if (!deploy_json.HasMember("tag")) {
        fprintf(stderr, "tag is needed in deploy\n");
        return false;
    } 
    deploy->tag = deploy_json["tag"].GetString();
    boost::trim(deploy->tag);

    std::vector<std::string> pools;
    std::string str_pools = deploy_json["pools"].GetString();
    boost::trim(str_pools);
    ::baidu::common::SplitString(str_pools, ",", &pools);
    if (pools.size() == 0) {
        fprintf(stderr, "pools are needed in deploy\n");
        return false;
    }
    deploy->pools.assign(pools.begin(), pools.end());
    return 0;
}

int ParseVolum(const rapidjson::Value& volum_json, ::baidu::galaxy::sdk::VolumRequired* volum) {
    int ok = 0;
    //size<commit_msg>remove token from RemoveUser, GrantUser, AssignQuota<commit_after>// Copyright (c) 2016, Baidu.com, Inc. All Rights Reserved
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <map>
#include <boost/algorithm/string.hpp>
#include "rapidjson/document.h"
#include "rapidjson/filereadstream.h"
#include "galaxy_util.h"

namespace baidu {
namespace galaxy {
namespace client {

int ParseDeploy(const rapidjson::Value& deploy_json, ::baidu::galaxy::sdk::Deploy* deploy) {
    //deploy config:replica
    if (!deploy_json.HasMember("replica") || deploy_json["replica"].GetInt() < 0) {
        fprintf(stderr, "replica is required in deploy\n");
        return -1;
    }
    deploy->replica = deploy_json["replica"].GetInt();

    //deploy config:step
    if (!deploy_json.HasMember("step") || deploy_json["step"].GetInt() < 0) {
        fprintf(stderr, "step is required in deploy\n");
        return -1;
    }
    deploy->step = deploy_json["step"].GetInt();

    //deploy config:interval
    if (!deploy_json.HasMember("interval") || deploy_json["interval"].GetInt() < 0) {
        fprintf(stderr, "interval is required in deploy\n");
        return -1;
    }
    deploy->interval = deploy_json["interval"].GetInt();

    //deploy config:max_per_host
    if (!deploy_json.HasMember("max_per_host") || deploy_json["max_per_host"].GetInt() <= 0) {
        fprintf(stderr, "max_per_host is required in deploy\n");
        return -1;
    }
    deploy->max_per_host = deploy_json["max_per_host"].GetInt();
    if (!deploy_json.HasMember("tag")) {
        fprintf(stderr, "tag is needed in deploy\n");
        return -1;
    } 
    deploy->tag = deploy_json["tag"].GetString();
    boost::trim(deploy->tag);

    std::vector<std::string> pools;
    std::string str_pools = deploy_json["pools"].GetString();
    boost::trim(str_pools);
    ::baidu::common::SplitString(str_pools, ",", &pools);
    if (pools.size() == 0) {
        fprintf(stderr, "pools are needed in deploy\n");
        return -1;
    }
    deploy->pools.assign(pools.begin(), pools.end());
    return 0;
}

int ParseVolum(const rapidjson::Value& volum_json, ::baidu::galaxy::sdk::VolumRequired* volum) {
    int ok = 0;
    //size
{'fraction_non_alphanumeric': 0.16118200134318333, 'fraction_numerical': 0.007163644504141482, 'mean_word_length': 3.5685071574642127, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6481429', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1468, 'n_words': 324}