MCPcopy Create free account
hub / github.com/apache/mesos / parse

Method parse

src/hdfs/hdfs.cpp:141–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139
140
141Try<mesos::URI> HDFS::parse(const string& uri)
142{
143 size_t schemePos = uri.find("://");
144 if (schemePos == string::npos) {
145 return Error("Missing scheme in url string");
146 }
147
148 const string uriPath = uri.substr(schemePos + 3);
149
150 size_t pathPos = uriPath.find_first_of('/');
151 if (pathPos == 0) {
152 return mesos::uri::hdfs(uriPath);
153 }
154
155 // If path is specified in the URL, try to capture the host and path
156 // separately.
157 string host = uriPath;
158 string path = "/";
159 if (pathPos != string::npos) {
160 host = host.substr(0, pathPos);
161 path = uriPath.substr(pathPos);
162 }
163
164 if (host.empty()) {
165 return mesos::uri::hdfs(path);
166 }
167
168 const vector<string> tokens = strings::tokenize(host, ":");
169
170 if (tokens[0].empty()) {
171 return Error("Host not found in url");
172 }
173
174 if (tokens.size() > 2) {
175 return Error("Found multiple ports in url");
176 }
177
178 Option<int> port;
179 if (tokens.size() == 2) {
180 Try<int> numifyPort = numify<int>(tokens[1]);
181 if (numifyPort.isError()) {
182 return Error("Failed to parse port: " + numifyPort.error());
183 }
184
185 port = numifyPort.get();
186 } else {
187 // Default port for HDFS.
188 port = 8020;
189 }
190
191 return mesos::uri::hdfs(path, tokens[0], port.get());
192}
193
194
195// An HDFS client path must be either a full URI or an absolute path. If it is

Callers

nothing calls this directly

Calls 9

hdfsFunction · 0.85
tokenizeFunction · 0.85
errorMethod · 0.65
ErrorFunction · 0.50
findMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
isErrorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected