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
d3dccca0
Commit
d3dccca0
authored
7 years ago
by
Michael Davis
Browse files
Options
Downloads
Patches
Plain Diff
[EOS-CTA] Simplifies exception handling on client side
parent
45678889
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmdline/EosCtaStub.cpp
+5
-37
5 additions, 37 deletions
cmdline/EosCtaStub.cpp
xroot_ssi_pb/XrdSsiPbRequest.h
+34
-46
34 additions, 46 deletions
xroot_ssi_pb/XrdSsiPbRequest.h
with
39 additions
and
83 deletions
cmdline/EosCtaStub.cpp
+
5
−
37
View file @
d3dccca0
...
...
@@ -29,37 +29,14 @@
//! Usage exception
const
std
::
runtime_error
Usage
(
"Usage: eoscta_stub archive|retrieve|delete [options] [--stderr]"
);
// Define the XRootD SSI callbacks
// Define XRootD SSI Alert message callback
namespace
XrdSsiPb
{
/*!
* Response callback.
*
* This is the CTA Front End response to the Notification.
*/
template
<
>
void
RequestCallback
<
eos
::
wfe
::
Response
>::
operator
()(
const
eos
::
wfe
::
Response
&
response
)
{
using
namespace
std
;
std
::
cout
<<
"ResponseCallback():"
<<
std
::
endl
;
OutputJsonString
(
std
::
cout
,
&
response
);
}
/*!
* Alert callback.
*
*
This is for
messages
which
should be logged by EOS or directed to the User.
*
Defines how Alert
messages should be logged by EOS or directed to the User.
*/
template
<
>
...
...
@@ -69,22 +46,13 @@ void RequestCallback<eos::wfe::Alert>::operator()(const eos::wfe::Alert &alert)
OutputJsonString
(
std
::
cout
,
&
alert
);
}
}
// namespace XrdSsiPb
/*!
* Convert exceptions into Alerts.
*
* This tells the framework how to log exceptions received on the client side
*/
template
<
>
void
ExceptionToAlert
<
eos
::
wfe
::
Alert
>::
operator
()(
const
std
::
exception
&
e
,
eos
::
wfe
::
Alert
&
alert
)
{
alert
.
set_audience
(
eos
::
wfe
::
Alert
::
EOSLOG
);
alert
.
set_message_txt
(
e
.
what
());
}
//! Usage exception
}
// namespace XrdSsiPb
const
std
::
runtime_error
Usage
(
"Usage: eoscta_stub archive|retrieve|delete [options] [--stderr]"
);
...
...
This diff is collapsed.
Click to expand it.
xroot_ssi_pb/XrdSsiPbRequest.h
+
34
−
46
View file @
d3dccca0
...
...
@@ -20,6 +20,7 @@
#define __XRD_SSI_PB_REQUEST_H
#include
<future>
#include
<XrdSsi/XrdSsiRequest.hh>
namespace
XrdSsiPb
{
...
...
@@ -39,21 +40,6 @@ public:
/*!
* Convert Exceptions to Alerts
*
* The client should specialize on this class to specify how to log exceptions
*/
template
<
typename
AlertType
>
class
ExceptionToAlert
{
public:
void
operator
()(
const
std
::
exception
&
e
,
AlertType
&
alert
);
};
/*!
* XRootD SSI + Protocol Buffers Request class
*/
...
...
@@ -64,7 +50,7 @@ class Request : public XrdSsiRequest
public:
Request
(
const
std
::
string
&
buffer_str
,
unsigned
int
response_bufsize
,
uint16_t
timeout
)
:
m_request_bufptr
(
buffer_str
.
c_str
()),
m_request_
len
(
buffer_str
.
size
()),
m_request_
bufsize
(
buffer_str
.
size
()),
m_response_bufsize
(
response_bufsize
)
{
#ifdef XRDSSI_DEBUG
...
...
@@ -96,7 +82,7 @@ public:
virtual
char
*
GetRequest
(
int
&
reqlen
)
override
{
reqlen
=
m_request_
len
;
reqlen
=
m_request_
bufsize
;
return
const_cast
<
char
*>
(
m_request_bufptr
);
}
...
...
@@ -129,21 +115,13 @@ public:
auto
GetFuture
()
{
return
m_promise
.
get_future
();
}
private
:
const
char
*
m_request_bufptr
;
//!< Pointer to the Request buffer
int
m_request_len
;
//!< Size of the Request buffer
int
m_response_bufsize
;
//!< Size of the Response buffer
//! Promise a reply of Metadata type
std
::
promise
<
MetadataType
>
m_promise
;
const
char
*
m_request_bufptr
;
//!< Pointer to the Request buffer
int
m_request_bufsize
;
//!< Size of the Request buffer
char
*
m_response_bufptr
;
//!< Pointer to the Response buffer
int
m_response_bufsize
;
//!< Size of the Response buffer
//! Convert exceptions to Alerts. Must be defined on the client side.
ExceptionToAlert
<
AlertType
>
ExceptionHandler
;
// Callbacks for each of the XRootD reply types
RequestCallback
<
AlertType
>
AlertCallback
;
std
::
promise
<
MetadataType
>
m_promise
;
//!< Promise a reply of Metadata type
RequestCallback
<
AlertType
>
AlertCallback
;
//!< Callback for Alerts
// Responses and stream Responses will be implemented as a binary blob/stream. The format of the
// response will not be a protocol buffer. If the response was a protocol buffer we would need to
...
...
@@ -223,16 +201,14 @@ bool Request<RequestType, MetadataType, AlertType>::ProcessResponse(const XrdSsi
{
// Allocate response buffer
char
*
response_bufptr
=
new
char
[
m_response_bufsize
];
m_
response_bufptr
=
new
char
[
m_response_bufsize
];
// Read the first chunk of data into the buffer, and pass it to ProcessResponseData()
GetResponseData
(
response_bufptr
,
m_response_bufsize
);
GetResponseData
(
m_
response_bufptr
,
m_response_bufsize
);
}
}
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
ex
)
{
// Use the exception to fulfil the promise
m_promise
.
set_exception
(
std
::
current_exception
());
...
...
@@ -244,6 +220,9 @@ bool Request<RequestType, MetadataType, AlertType>::ProcessResponse(const XrdSsi
// It is now safe to delete the Request object (which implies that the pointer on the calling side
// will never refer to it again and the destructor of the base class doesn't access any class members).
delete
this
;
}
catch
(...)
{
Finished
();
delete
this
;
}
...
...
@@ -292,22 +271,31 @@ XrdSsiRequest::PRD_Xeq Request<RequestType, MetadataType, AlertType>
template
<
typename
RequestType
,
typename
MetadataType
,
typename
AlertType
>
void
Request
<
RequestType
,
MetadataType
,
AlertType
>::
Alert
(
XrdSsiRespInfoMsg
&
alert_msg
)
{
// Get the Alert
try
{
// Get the Alert
int
alert_len
;
char
*
alert_buffer
=
alert_msg
.
GetMsg
(
alert_len
);
int
alert_len
;
char
*
alert_buffer
=
alert_msg
.
GetMsg
(
alert_len
);
// Deserialize the Alert
// Deserialize the Alert
AlertType
alert
;
AlertType
alert
;
if
(
!
alert
.
ParseFromArray
(
alert_buffer
,
alert_len
))
if
(
alert
.
ParseFromArray
(
alert_buffer
,
alert_len
))
{
AlertCallback
(
alert
);
}
else
{
throw
PbException
(
"alert.ParseFromArray() failed"
);
}
}
catch
(
std
::
exception
&
ex
)
{
PbException
e
(
"alert.ParseFromArray() failed"
);
ExceptionHandler
(
e
,
alert
);
m_promise
.
set_exception
(
std
::
current_exception
());
}
AlertCallback
(
alert
);
catch
(...)
{}
// Recycle the message to free memory
...
...
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