aboutsummaryrefslogtreecommitdiffstats
path: root/ydb/library/schlab/schoot/schoot_gen_cfg.cpp
blob: 92f721c73a68726cbe1b5fa6bec902ffae3439d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "schoot_gen_cfg.h"
#include <ydb/library/schlab/protos/schlab.pb.h>
#include <library/cpp/protobuf/json/json2proto.h>
#include <util/stream/str.h>
#include <google/protobuf/text_format.h>

namespace NKikimr {
namespace NSchLab {

TSchOotGenCfgSet::TSchOotGenCfgSet(const TString &json) {
    IsValid = true;
    NSchlab::TGenCfgSet message;
    try {
        message = NProtobufJson::Json2Proto<NSchlab::TGenCfgSet>(json);
    } catch (yexception e) {
        IsValid = false;
        TStringStream str;
        str << "Error reading json schoot gen config, Marker# SGC01. ";
        str << e.what();
        ErrorDetails = str.Str();
        return;
    }

    ui64 size = message.cfgSize();
    for (ui64 idx = 0; idx < size; ++idx) {
        const auto &s = message.Getcfg(idx);
        Cfg.emplace_back();
        auto &d = Cfg.back();
        d.Label = (s.Getlabel() == nullptr ? "" : s.Getlabel());
        d.StartTime = s.GetstartTime();
        d.Period = s.Getperiod();
        d.PeriodCount = s.GetperiodCount();
        d.ReqSizeBytes = s.GetreqSizeBytes();
        d.ReqCount = s.GetreqCount();
        d.ReqInterval = s.GetreqInterval();
        d.User = (s.Getuser() == nullptr ? "" : s.Getuser());
        d.Desc = (s.Getdesc() == nullptr ? "" : s.Getdesc());

        if (d.Period <= 0.0) {
            IsValid = false;
            TStringStream str;
            str << "Error in json schoot gen config, Marker# SGC02.";
            str << " period# " << d.Period << " is <= 0.0 at label# \"" << d.Label << "\".";
            ErrorDetails = str.Str();
            return;
        }
        if (d.ReqInterval < 0.0) {
            IsValid = false;
            TStringStream str;
            str << "Error in json schoot gen config, Marker# SGC03.";
            str << " reqInterval# " << d.ReqInterval << " is < 0.0 at label# \"" << d.Label << "\".";
            ErrorDetails = str.Str();
            return;
        }
    }
}

}; // NSchLab
}; // NKikimr