Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gekkofs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hpc
gekkofs
Commits
6cff06b9
Commit
6cff06b9
authored
4 years ago
by
David Auer
Browse files
Options
Downloads
Patches
Plain Diff
Duplicate hostsfile utils for daemon
parent
67d4c829
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/daemon/util.hpp
+6
-0
6 additions, 0 deletions
include/daemon/util.hpp
src/daemon/util.cpp
+66
-0
66 additions, 0 deletions
src/daemon/util.cpp
with
72 additions
and
0 deletions
include/daemon/util.hpp
+
6
−
0
View file @
6cff06b9
...
...
@@ -14,6 +14,9 @@
#ifndef GEKKOFS_DAEMON_UTIL_HPP
#define GEKKOFS_DAEMON_UTIL_HPP
#include
<vector>
#include
<string>
namespace
gkfs
{
namespace
util
{
void
...
...
@@ -21,6 +24,9 @@ populate_hosts_file();
void
destroy_hosts_file
();
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
read_hosts_file
();
}
// namespace util
}
// namespace gkfs
...
...
This diff is collapsed.
Click to expand it.
src/daemon/util.cpp
+
66
−
0
View file @
6cff06b9
...
...
@@ -18,6 +18,8 @@
#include
<fstream>
#include
<iostream>
#include
<regex>
using
namespace
std
;
namespace
gkfs
::
util
{
...
...
@@ -48,4 +50,68 @@ destroy_hosts_file() {
std
::
remove
(
GKFS_DATA
->
hosts_file
().
c_str
());
}
// hosts file functions copied from daemon - need Modifications for LOG and hostsfile path source
// TODO clean that up, probably best into global utilities - TBD How do we do logging there?
/**
* Reads the daemon generator hosts file by a given path, returning hosts and URI addresses
* @param path to hosts file
* @return vector<pair<hosts, URI>>
* @throws std::runtime_error
*/
vector
<
pair
<
string
,
string
>>
load_hostfile
(
const
std
::
string
&
path
)
{
//LOG(DEBUG, "Loading hosts file: \"{}\"", path);
ifstream
lf
(
path
);
if
(
!
lf
)
{
throw
runtime_error
(
fmt
::
format
(
"Failed to open hosts file '{}': {}"
,
path
,
strerror
(
errno
)));
}
vector
<
pair
<
string
,
string
>>
hosts
;
const
regex
line_re
(
"^(
\\
S+)
\\
s+(
\\
S+)$"
,
regex
::
ECMAScript
|
regex
::
optimize
);
string
line
;
string
host
;
string
uri
;
std
::
smatch
match
;
while
(
getline
(
lf
,
line
))
{
if
(
!
regex_match
(
line
,
match
,
line_re
))
{
//LOG(ERROR, "Unrecognized line format: [path: '{}', line: '{}']",
// path, line);
throw
runtime_error
(
fmt
::
format
(
"unrecognized line format: '{}'"
,
line
));
}
host
=
match
[
1
];
uri
=
match
[
2
];
hosts
.
emplace_back
(
host
,
uri
);
}
if
(
hosts
.
empty
())
{
throw
runtime_error
(
"Hosts file found but no suitable addresses could be extracted"
);
}
// ??? extract_protocol(hosts[0].second);
return
hosts
;
}
vector
<
pair
<
string
,
string
>>
read_hosts_file
()
{
string
hostfile
=
GKFS_DATA
->
hosts_file
();
vector
<
pair
<
string
,
string
>>
hosts
;
try
{
hosts
=
load_hostfile
(
hostfile
);
}
catch
(
const
exception
&
e
)
{
auto
emsg
=
fmt
::
format
(
"Failed to load hosts file: {}"
,
e
.
what
());
throw
runtime_error
(
emsg
);
}
if
(
hosts
.
empty
())
{
throw
runtime_error
(
fmt
::
format
(
"Hostfile empty: '{}'"
,
hostfile
));
}
GKFS_DATA
->
spdlogger
()
->
info
(
"Hosts pool size: {}"
,
hosts
.
size
());
return
hosts
;
}
}
// namespace gkfs::util
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment