GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/receiver/params.cc Lines: 0 89 0.0 %
Date: 2019-02-03 02:48:13 Branches: 0 46 0.0 %

Line Branch Exec Source
1
/**
2
 * This file is part of the CernVM File System.
3
 */
4
5
#include "params.h"
6
7
#include <vector>
8
9
#include "options.h"
10
#include "util/string.h"
11
12
namespace receiver {
13
14
std::string GetSpoolerTempDir(const std::string& spooler_config) {
15
  const std::vector<std::string> tokens = SplitString(spooler_config, ',');
16
  assert(tokens.size() == 3);
17
  return tokens[1];
18
}
19
20
bool GetParamsFromFile(const std::string& repo_name, Params* params) {
21
  const std::string repo_config_file =
22
      "/etc/cvmfs/repositories.d/" + repo_name + "/server.conf";
23
24
  SimpleOptionsParser parser = SimpleOptionsParser(
25
    new DefaultOptionsTemplateManager(repo_name));
26
  if (!parser.TryParsePath(repo_config_file)) {
27
    LogCvmfs(kLogReceiver, kLogSyslogErr,
28
             "Could not parse repository configuration: %s.",
29
             repo_config_file.c_str());
30
    return false;
31
  }
32
33
  if (!parser.GetValue("CVMFS_STRATUM0", &params->stratum0)) {
34
    LogCvmfs(kLogReceiver, kLogSyslogErr,
35
             "Missing parameter %s in repository configuration file.",
36
             "CVMFS_STRATUM0");
37
    return false;
38
  }
39
40
  // Note: TEST_CVMFS_RECEIVER_UPSTREAM_STORAGE is used to provide an
41
  //       an overriding value for CVMFS_UPSTREAM_STORAGE, to be used
42
  //       only by the cvmfs_receiver application. Useful for testing
43
  //       when the release manager and the repository gateway are
44
  //       running on the same machine.
45
  if (parser.IsDefined("TEST_CVMFS_RECEIVER_UPSTREAM_STORAGE")) {
46
    parser.GetValue("TEST_CVMFS_RECEIVER_UPSTREAM_STORAGE",
47
                    &params->spooler_configuration);
48
  } else {
49
    if (!parser.GetValue("CVMFS_UPSTREAM_STORAGE",
50
                         &params->spooler_configuration)) {
51
      LogCvmfs(kLogReceiver, kLogSyslogErr,
52
               "Missing parameter %s in repository configuration file.",
53
               "CVMFS_UPSTREAM_STORAGE");
54
      return false;
55
    }
56
  }
57
58
59
  std::string hash_algorithm_str;
60
  if (!parser.GetValue("CVMFS_HASH_ALGORITHM", &hash_algorithm_str)) {
61
    LogCvmfs(kLogReceiver, kLogSyslogErr,
62
             "Missing parameter %s in repository configuration file.",
63
             "CVMFS_HASH_ALGORITHM");
64
    return false;
65
  }
66
  params->hash_alg = shash::ParseHashAlgorithm(hash_algorithm_str);
67
  params->hash_alg_str = hash_algorithm_str;
68
69
  std::string compression_algorithm_str;
70
  if (!parser.GetValue("CVMFS_COMPRESSION_ALGORITHM",
71
                       &compression_algorithm_str)) {
72
    LogCvmfs(kLogReceiver, kLogSyslogErr,
73
             "Missing parameter %s in repository configuration file.",
74
             "CVMFS_COMPRESSION_ALGORITHM");
75
    return false;
76
  }
77
  params->compression_alg =
78
      zlib::ParseCompressionAlgorithm(compression_algorithm_str);
79
80
  /**
81
   * The receiver does not store files, only catalogs.  We can safely disable
82
   * this option.
83
   */
84
  params->generate_legacy_bulk_chunks = false;
85
86
  std::string use_chunking_str;
87
  if (!parser.GetValue("CVMFS_USE_FILE_CHUNKING", &use_chunking_str)) {
88
    LogCvmfs(kLogReceiver, kLogSyslogErr,
89
             "Missing parameter %s in repository configuration file.",
90
             "CVMFS_USE_FILE_CHUNKING");
91
    return false;
92
  }
93
  if (use_chunking_str == "true") {
94
    params->use_file_chunking = true;
95
  } else if (use_chunking_str == "false") {
96
    params->use_file_chunking = false;
97
  } else {
98
    LogCvmfs(kLogReceiver, kLogSyslogErr,
99
             "Invalid value of repository parameter %s: %s",
100
             "CVMFS_USE_FILE_CHUNKING", use_chunking_str.c_str());
101
    return false;
102
  }
103
104
  std::string min_chunk_size_str;
105
  if (!parser.GetValue("CVMFS_MIN_CHUNK_SIZE", &min_chunk_size_str)) {
106
    LogCvmfs(kLogReceiver, kLogSyslogErr,
107
             "Missing parameter %s in repository configuration file.",
108
             "CVMFS_MIN_CHUNK_SIZE");
109
    return false;
110
  }
111
  params->min_chunk_size = String2Uint64(min_chunk_size_str);
112
113
  std::string avg_chunk_size_str;
114
  if (!parser.GetValue("CVMFS_AVG_CHUNK_SIZE", &avg_chunk_size_str)) {
115
    LogCvmfs(kLogReceiver, kLogSyslogErr,
116
             "Missing parameter %s in repository configuration file.",
117
             "CVMFS_AVG_CHUNK_SIZE");
118
    return false;
119
  }
120
  params->avg_chunk_size = String2Uint64(avg_chunk_size_str);
121
122
  std::string max_chunk_size_str;
123
  if (!parser.GetValue("CVMFS_MAX_CHUNK_SIZE", &max_chunk_size_str)) {
124
    LogCvmfs(kLogReceiver, kLogSyslogErr,
125
             "Missing parameter %s in repository configuration file.",
126
             "CVMFS_MAX_CHUNK_SIZE");
127
    return false;
128
  }
129
  params->max_chunk_size = String2Uint64(max_chunk_size_str);
130
131
  std::string use_autocatalogs_str;
132
  if (!parser.GetValue("CVMFS_AUTOCATALOGS", &use_autocatalogs_str)) {
133
    LogCvmfs(kLogReceiver, kLogSyslogErr,
134
             "Missing parameter %s in repository configuration file.",
135
             "CVMFS_AUTOCATALOGS");
136
    return false;
137
  }
138
  if (use_autocatalogs_str == "true") {
139
    params->use_autocatalogs = true;
140
  } else if (use_autocatalogs_str == "false") {
141
    params->use_autocatalogs = false;
142
  } else {
143
    LogCvmfs(kLogReceiver, kLogSyslogErr,
144
             "Invalid value of repository parameter %s: %s.",
145
             "CVMFS_AUTOCATALOGS", use_autocatalogs_str.c_str());
146
    return false;
147
  }
148
149
  std::string max_weight_str;
150
  if (parser.GetValue("CVMFS_AUTOCATALOGS_MAX_WEIGHT", &max_weight_str)) {
151
    params->max_weight = String2Uint64(max_weight_str);
152
  }
153
154
  std::string min_weight_str;
155
  if (parser.GetValue("CVMFS_AUTOCATALOGS_MIN_WEIGHT", &min_weight_str)) {
156
    params->min_weight = String2Uint64(min_weight_str);
157
  }
158
159
  params->enforce_limits = false;
160
  std::string enforce_limits_str;
161
  if (parser.GetValue("CVMFS_ENFORCE_LIMITS", &enforce_limits_str)) {
162
    if (enforce_limits_str == "true") {
163
      params->enforce_limits = true;
164
    }
165
  }
166
167
  // TODO(dwd): the next 3 limit variables should take defaults from
168
  // SyncParameters
169
  params->nested_kcatalog_limit = 0;
170
  std::string nested_kcatalog_limit_str;
171
  if (parser.GetValue("CVMFS_NESTED_KCATALOG_LIMIT",
172
                      &nested_kcatalog_limit_str)) {
173
    params->nested_kcatalog_limit = String2Uint64(nested_kcatalog_limit_str);
174
  }
175
176
  params->root_kcatalog_limit = 0;
177
  std::string root_kcatalog_limit_str;
178
  if (parser.GetValue("CVMFS_ROOT_KCATALOG_LIMIT", &root_kcatalog_limit_str)) {
179
    params->root_kcatalog_limit = String2Uint64(root_kcatalog_limit_str);
180
  }
181
182
  params->file_mbyte_limit = 0;
183
  std::string file_mbyte_limit_str;
184
  if (parser.GetValue("CVMFS_FILE_MBYTE_LIMIT", &file_mbyte_limit_str)) {
185
    params->file_mbyte_limit = String2Uint64(file_mbyte_limit_str);
186
  }
187
188
  return true;
189
}
190
191
}  // namespace receiver