aboutsummaryrefslogtreecommitdiffstats
path: root/yt/yt/client/queue_client/common.cpp
blob: e7aa1798bd50bea4d3921d8f067cee53d5a1112b (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
61
62
63
64
65
66
67
68
69
70
71
#include "common.h"

#include <yt/yt/client/ypath/rich.h>

#include <yt/yt/core/ytree/fluent.h>

#include <util/string/split.h>

namespace NYT::NQueueClient {

using namespace NYson;
using namespace NYTree;
using namespace NYPath;

////////////////////////////////////////////////////////////////////////////////

bool TCrossClusterReference::operator==(const TCrossClusterReference& other) const
{
    return Cluster == other.Cluster && Path == other.Path;
}

bool TCrossClusterReference::operator<(const TCrossClusterReference& other) const
{
    return std::tie(Cluster, Path) < std::tie(other.Cluster, other.Path);
}

TCrossClusterReference::operator TRichYPath() const
{
    TRichYPath result = Path;
    result.SetCluster(Cluster);
    return result;
}

TCrossClusterReference TCrossClusterReference::FromString(TStringBuf path)
{
    TCrossClusterReference result;
    if (!StringSplitter(path).Split(':').Limit(2).TryCollectInto(&result.Cluster, &result.Path)) {
        THROW_ERROR_EXCEPTION("Ill-formed cross-cluster reference %Qv", path);
    }
    if (result.Cluster.empty()) {
        THROW_ERROR_EXCEPTION("The cluster component of cross-cluster reference %Qv cannot be empty", path);
    }
    if (result.Path.empty()) {
        THROW_ERROR_EXCEPTION("The path component of cross-cluster reference %Qv cannot be empty", path);
    }
    return result;
}

TString ToString(const TCrossClusterReference& queueRef)
{
    return Format("%v:%v", queueRef.Cluster, queueRef.Path);
}

void Serialize(const TCrossClusterReference& queueRef, IYsonConsumer* consumer)
{
    BuildYsonFluently(consumer).Value(ToString(queueRef));
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NQueueClient

size_t THash<NYT::NQueueClient::TCrossClusterReference>::operator()(const NYT::NQueueClient::TCrossClusterReference& crossClusterRef) const
{
    using NYT::HashCombine;

    size_t result = 0;
    HashCombine(result, crossClusterRef.Cluster);
    HashCombine(result, crossClusterRef.Path);
    return result;
}