Skip to content
Snippets Groups Projects
Commit 09337fb9 authored by Michael Davis's avatar Michael Davis
Browse files

[cta_frontend] Sends cta_admin protocol buffer to CTA Frontend endpoint

parent 90fc094c
Branches
Tags
No related merge requests found
......@@ -33,7 +33,7 @@ include_directories (${CMAKE_SOURCE_DIR}/tapeserver/)
#
# Get some extra debug messages on stdout
#add_definitions(-DXRDSSI_DEBUG)
add_definitions(-DXRDSSI_DEBUG)
find_package(xrootd REQUIRED)
find_package(Protobuf3 REQUIRED)
......@@ -48,7 +48,7 @@ install(TARGETS eoscta_stub DESTINATION usr/bin)
# cta_admin is a drop-in replacement for "cta <admin_command>"
#
add_executable(cta_admin CtaAdminCmd.cpp CtaAdminCmdParse.cpp)
add_executable(cta_admin CtaAdminCmd.cpp CtaAdminCmdParse.cpp Configuration.cpp)
target_link_libraries(cta_admin XrdCtaMessages XrdSsi-4 XrdSsiLib)
install(TARGETS cta_admin DESTINATION usr/bin)
......@@ -20,11 +20,31 @@
#include <sstream>
#include <iostream>
#include "cmdline/Configuration.hpp"
#include "CtaAdminCmd.hpp"
#include "XrdSsiPbDebug.hpp"
// Define XRootD SSI Alert message callback
namespace XrdSsiPb {
/*!
* Alert callback.
*
* Defines how Alert messages should be logged
*/
template<>
void RequestCallback<cta::xrd::Alert>::operator()(const cta::xrd::Alert &alert)
{
std::cout << "AlertCallback():" << std::endl;
OutputJsonString(std::cout, &alert);
}
} // namespace XrdSsiPb
namespace cta {
namespace admin {
......@@ -94,8 +114,36 @@ void CtaAdminCmd::send() const
throwUsage(ex.what());
}
// Send the Protocol Buffer
#ifdef XRDSSI_DEBUG
XrdSsiPb::OutputJsonString(std::cout, &m_request.admincmd());
#endif
// Get socket address of CTA Frontend endpoint
cta::cmdline::Configuration cliConf("/etc/cta/cta-cli.conf");
std::string endpoint = cliConf.getFrontendHostAndPort();
// Obtain a Service Provider
std::string resource("/ctafrontend");
XrdSsiPbServiceType cta_service(endpoint, resource);
// Send the Request to the Service and get a Response
cta::xrd::Response response = cta_service.Send(m_request);
// Handle responses
switch(response.type())
{
using namespace cta::xrd;
case Response::RSP_SUCCESS: std::cout << response.message_txt() << std::endl; break;
case Response::RSP_ERR_PROTOBUF: throw XrdSsiPb::PbException(response.message_txt());
case Response::RSP_ERR_CTA: throw std::runtime_error(response.message_txt());
default: throw XrdSsiPb::PbException("Invalid response type.");
}
}
......@@ -228,6 +276,9 @@ int main(int argc, const char **argv)
// Send the protocol buffer
cmd.send();
// Delete all global objects allocated by libprotobuf
google::protobuf::ShutdownProtobufLibrary();
return 0;
} catch (XrdSsiPb::PbException &ex) {
std::cerr << "Error in Google Protocol Buffers: " << ex.what() << std::endl;
......
......@@ -18,6 +18,10 @@
#pragma once
#ifdef XRDSSI_DEBUG
#include <iostream>
#endif
#include <XrdSsi/XrdSsiProvider.hh>
#include <XrdSsi/XrdSsiService.hh>
#include "XrdSsiPbException.hpp"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment