olp-cpp-sdk  1.22.0
PrefetchPartitionsRequest.h
1 /*
2  * Copyright (C) 2020 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <sstream>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 #include <olp/core/thread/TaskScheduler.h>
28 #include <olp/dataservice/read/DataServiceReadApi.h>
29 #include <olp/dataservice/read/FetchOptions.h>
30 #include <boost/optional.hpp>
31 
32 namespace olp {
33 namespace dataservice {
34 namespace read {
35 
40 class DATASERVICE_READ_API PrefetchPartitionsRequest final {
41  public:
43  using PartitionIds = std::vector<std::string>;
44 
58  PartitionIds partition_ids) {
59  partition_ids_ = std::move(partition_ids);
60  return *this;
61  }
62 
68  inline const PartitionIds& GetPartitionIds() const { return partition_ids_; }
69 
80  inline const boost::optional<std::string>& GetBillingTag() const {
81  return billing_tag_;
82  }
83 
94  boost::optional<std::string> billing_tag) {
95  billing_tag_ = std::move(billing_tag);
96  return *this;
97  }
98 
109  inline PrefetchPartitionsRequest& WithBillingTag(std::string&& billing_tag) {
110  billing_tag_ = std::move(billing_tag);
111  return *this;
112  }
113 
121  inline uint32_t GetPriority() const { return priority_; }
122 
130  inline PrefetchPartitionsRequest& WithPriority(uint32_t priority) {
131  priority_ = priority;
132  return *this;
133  }
134 
143  std::string CreateKey(const std::string& layer_id,
144  boost::optional<int64_t> version = boost::none) const {
145  std::stringstream out;
146  out << layer_id;
147  if (version) {
148  out << "@" << version.get();
149  }
150  out << "^" << partition_ids_.size();
151  if (!partition_ids_.empty()) {
152  out << "[" << partition_ids_.front() << ", ...]";
153  }
154  if (GetBillingTag()) {
155  out << "$" << GetBillingTag().get();
156  }
157  out << "*" << priority_;
158  return out.str();
159  }
160 
161  private:
162  PartitionIds partition_ids_;
163  boost::optional<std::string> billing_tag_;
164  uint32_t priority_{thread::LOW};
165 };
166 
167 } // namespace read
168 } // namespace dataservice
169 } // namespace olp
Encapsulates the fields required to prefetch a list of partitions for the given catalog and layer.
Definition: PrefetchPartitionsRequest.h:40
uint32_t GetPriority() const
Gets the request priority.
Definition: PrefetchPartitionsRequest.h:121
PrefetchPartitionsRequest & WithPartitionIds(PartitionIds partition_ids)
Sets the list of partitions.
Definition: PrefetchPartitionsRequest.h:57
const PartitionIds & GetPartitionIds() const
Gets the list of the partitions.
Definition: PrefetchPartitionsRequest.h:68
PrefetchPartitionsRequest & WithBillingTag(boost::optional< std::string > billing_tag)
Sets the billing tag for the request.
Definition: PrefetchPartitionsRequest.h:93
std::string CreateKey(const std::string &layer_id, boost::optional< int64_t > version=boost::none) const
Creates a readable format for the request.
Definition: PrefetchPartitionsRequest.h:143
PrefetchPartitionsRequest & WithBillingTag(std::string &&billing_tag)
Sets the billing tag for the request.
Definition: PrefetchPartitionsRequest.h:109
std::vector< std::string > PartitionIds
An alias for the vector of partitions IDs.
Definition: PrefetchPartitionsRequest.h:43
PrefetchPartitionsRequest & WithPriority(uint32_t priority)
Sets the priority of the prefetch request.
Definition: PrefetchPartitionsRequest.h:130
const boost::optional< std::string > & GetBillingTag() const
Gets the billing tag to group billing records together.
Definition: PrefetchPartitionsRequest.h:80
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24