Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
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
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
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
dCache
cta
Commits
b23f8575
Commit
b23f8575
authored
3 years ago
by
Miguel Barros
Committed by
Michael Davis
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Cta send event cmdline flags
parent
26f09983
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmdline/CtaCmdOptions.hpp
+3
-3
3 additions, 3 deletions
cmdline/CtaCmdOptions.hpp
cmdline/CtaSendEvent.cpp
+49
-7
49 additions, 7 deletions
cmdline/CtaSendEvent.cpp
cmdline/CtaVerifyFile.cpp
+27
-24
27 additions, 24 deletions
cmdline/CtaVerifyFile.cpp
with
79 additions
and
34 deletions
cmdline/Cta
VerifyFile
.hpp
→
cmdline/Cta
CmdOptions
.hpp
+
3
−
3
View file @
b23f8575
...
...
@@ -18,14 +18,14 @@
#pragma once
/*!
* Simple command line option class for
the verification command
* Simple command line option class for
simpler commands like cta-verify-file or cta-send-event
*/
class
Verify
Option
{
class
String
Option
{
public:
/*!
* Constructor
*/
Verify
Option
(
const
std
::
string
&
long_opt
,
const
std
::
string
&
short_opt
,
const
bool
is_optional
)
:
String
Option
(
const
std
::
string
&
long_opt
,
const
std
::
string
&
short_opt
,
const
bool
is_optional
)
:
m_long_opt
(
long_opt
),
m_short_opt
(
short_opt
),
m_is_optional
(
is_optional
),
...
...
This diff is collapsed.
Click to expand it.
cmdline/CtaSendEvent.cpp
+
49
−
7
View file @
b23f8575
...
...
@@ -25,6 +25,7 @@
#include
<common/checksum/ChecksumBlobSerDeser.hpp>
#include
"CtaFrontendApi.hpp"
#include
"version.h"
#include
"CtaCmdOptions.hpp"
const
std
::
string
config_file
=
"/etc/cta/cta-cli.conf"
;
...
...
@@ -47,7 +48,43 @@ void RequestCallback<cta::xrd::Alert>::operator()(const cta::xrd::Alert &alert)
typedef
std
::
map
<
std
::
string
,
std
::
string
>
AttrMap
;
// Usage exception
const
std
::
runtime_error
Usage
(
"Usage: eos --json fileinfo /eos/path | cta-send-event CLOSEW|PREPARE"
);
const
std
::
runtime_error
Usage
(
"Usage: eos --json fileinfo /eos/path | cta-send-event CLOSEW|PREPARE "
"-i/--eos.instance <instance> [-e/--eos.endpoint <url>]"
);
StringOption
option_instance
{
"--eos.instance"
,
"-i"
,
true
};
StringOption
option_endpoint
{
"--eos.endpoint"
,
"-e"
,
false
};
std
::
map
<
std
::
string
,
StringOption
*>
option_map
=
{
{
"-i"
,
&
option_instance
},
{
"--eos.instance"
,
&
option_instance
},
{
"-e"
,
&
option_endpoint
},
{
"--eos.endpoint"
,
&
option_endpoint
},
};
void
validate_cmd
()
{
for
(
auto
&
it
:
option_map
)
{
auto
option
=
it
.
second
;
if
(
!
option
->
is_optional
()
&&
!
option
->
is_present
())
{
std
::
cout
<<
"Error: Option "
<<
option
->
get_name
()
<<
" is mandatory but not present."
<<
std
::
endl
;
throw
Usage
;
}
}
}
void
parse_cmd
(
const
int
argc
,
const
char
*
const
*
const
argv
)
{
for
(
int
i
=
2
;
i
<
argc
;
i
+=
2
)
{
auto
search
=
option_map
.
find
(
argv
[
i
]);
if
(
search
==
option_map
.
end
())
{
std
::
cout
<<
"Error: Unknown option: "
<<
argv
[
i
]
<<
std
::
endl
;
throw
Usage
;
}
auto
option
=
search
->
second
;
option
->
set_present
();
option
->
set_value
(
argv
[
i
+
1
]);
}
}
// remove leading spaces and quotes
void
ltrim
(
std
::
string
&
s
)
{
...
...
@@ -105,17 +142,22 @@ void parseFileInfo(std::istream &in, AttrMap &attr, AttrMap &xattr)
* @param[in] config The XrdSsiPb object containing the configuration parameters
* @param[in] wf_command The workflow command (CLOSEW or PREPARE)
*/
void
fillNotification
(
cta
::
eos
::
Notification
&
notification
,
const
std
::
string
&
wf_command
)
void
fillNotification
(
cta
::
eos
::
Notification
&
notification
,
const
std
::
string
&
wf_command
,
const
int
argc
,
const
char
*
const
*
const
argv
)
{
XrdSsiPb
::
Config
config
(
config_file
,
"eos"
);
for
(
auto
&
conf_option
:
std
::
vector
<
std
::
string
>
({
"instance"
,
"requester.user"
,
"requester.group"
}))
{
for
(
auto
&
conf_option
:
std
::
vector
<
std
::
string
>
({
"requester.user"
,
"requester.group"
}))
{
if
(
!
config
.
getOptionValueStr
(
conf_option
).
first
)
{
throw
std
::
runtime_error
(
conf_option
+
" must be specified in "
+
config_file
);
}
}
const
std
::
string
&
eos_instance
=
config
.
getOptionValueStr
(
"instance"
).
second
;
const
std
::
string
&
eos_endpoint
=
config
.
getOptionValueStr
(
"endpoint"
).
first
?
config
.
getOptionValueStr
(
"endpoint"
).
second
:
"localhost:1095"
;
parse_cmd
(
argc
,
argv
);
validate_cmd
();
const
std
::
string
&
eos_instance
=
option_instance
.
get_value
();
const
std
::
string
&
eos_endpoint
=
option_endpoint
.
is_present
()
?
option_endpoint
.
get_value
()
:
"localhost:1095"
;
const
std
::
string
&
requester_user
=
config
.
getOptionValueStr
(
"requester.user"
).
second
;
const
std
::
string
&
requester_group
=
config
.
getOptionValueStr
(
"requester.group"
).
second
;
...
...
@@ -195,7 +237,7 @@ void fillNotification(cta::eos::Notification ¬ification, const std::string &w
*/
int
exceptionThrowingMain
(
int
argc
,
const
char
*
const
*
const
argv
)
{
if
(
argc
!=
2
)
{
if
(
argc
%
2
)
{
throw
Usage
;
}
...
...
@@ -224,7 +266,7 @@ int exceptionThrowingMain(int argc, const char *const *const argv)
config
.
getEnv
(
"log"
,
"XrdSsiPbLogLevel"
);
// Parse the command line arguments: fill the Notification fields
fillNotification
(
notification
,
argv
[
1
]);
fillNotification
(
notification
,
argv
[
1
]
,
argc
,
argv
);
// Obtain a Service Provider
XrdSsiPbServiceType
cta_service
(
config
);
...
...
This diff is collapsed.
Click to expand it.
cmdline/CtaVerifyFile.cpp
+
27
−
24
View file @
b23f8575
...
...
@@ -21,7 +21,7 @@
#include
"CtaFrontendApi.hpp"
#include
"version.h"
#include
"Cta
VerifyFile
.hpp"
#include
"Cta
CmdOptions
.hpp"
const
std
::
string
config_file
=
"/etc/cta/cta-cli.conf"
;
...
...
@@ -49,17 +49,27 @@ const std::runtime_error Usage("Usage: cta-verify-file <archiveFileID> [-v <vid>
"cta-verify-file <archiveFileID> [--vid <id>] "
"--instance <instance> --request.user <user> --request.group <group>"
);
VerifyOption
option_instance
{
"--instance"
,
"-i"
,
false
};
VerifyOption
option_request_user
{
"--request.user"
,
"-r.user"
,
false
};
VerifyOption
option_request_group
{
"--request.group"
,
"-r.group"
,
false
};
VerifyOption
option_vid
{
"--vid"
,
"-v"
,
true
};
std
::
vector
<
VerifyOption
*>
verify_options
=
{
&
option_instance
,
&
option_request_user
,
&
option_request_group
,
&
option_vid
};
void
validate_cmd
()
{
for
(
auto
&
option
:
verify_options
)
{
StringOption
option_instance
{
"--instance"
,
"-i"
,
false
};
StringOption
option_request_user
{
"--request.user"
,
"-r.user"
,
false
};
StringOption
option_request_group
{
"--request.group"
,
"-r.group"
,
false
};
StringOption
option_vid
{
"--vid"
,
"-v"
,
true
};
std
::
vector
<
StringOption
*>
verify_options
=
{
&
option_instance
,
&
option_request_user
,
&
option_request_group
,
&
option_vid
};
std
::
map
<
std
::
string
,
StringOption
*>
option_map
=
{
{
"-i"
,
&
option_instance
},
{
"--instance"
,
&
option_instance
},
{
"-r.user"
,
&
option_request_user
},
{
"--request.user"
,
&
option_request_user
},
{
"-r.group"
,
&
option_request_group
},
{
"--request.group"
,
&
option_request_group
},
{
"-v"
,
&
option_vid
},
{
"--vid"
,
&
option_vid
},
};
void
validate_cmd
()
{
for
(
auto
&
it
:
option_map
)
{
auto
option
=
it
.
second
;
if
(
!
option
->
is_optional
()
&&
!
option
->
is_present
())
{
std
::
cout
<<
"Error: Option "
<<
option
->
get_name
()
<<
" is mandatory but not present."
<<
std
::
endl
;
throw
Usage
;
...
...
@@ -67,26 +77,19 @@ void validate_cmd()
}
}
void
parse_cmd
(
const
int
argc
,
const
char
*
const
*
const
argv
)
{
for
(
int
i
=
2
;
i
<
argc
;
i
+=
2
)
{
bool
matches
=
false
;
for
(
auto
&
option
:
verify_options
)
{
if
(
*
option
==
argv
[
i
])
{
option
->
set_present
();
option
->
set_value
(
argv
[
i
+
1
]);
matches
=
true
;
break
;
}
}
if
(
!
matches
)
{
auto
search
=
option_map
.
find
(
argv
[
i
]);
if
(
search
==
option_map
.
end
())
{
std
::
cout
<<
"Error: Unknown option: "
<<
argv
[
i
]
<<
std
::
endl
;
throw
Usage
;
}
auto
option
=
search
->
second
;
option
->
set_present
();
option
->
set_value
(
argv
[
i
+
1
]);
}
}
/*
* Fill a Notification message from the command-line parameters and stdin
*
...
...
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