Commit 2652dbcc authored by Eric Cano's avatar Eric Cano
Browse files

Added support for end of session in ClientSimulator.

parent 4a796daa
......@@ -29,6 +29,8 @@
#include "../../tapegateway/GatewayMessage.hpp"
#include "castor/tape/tapegateway/Volume.hpp"
#include "castor/tape/tapegateway/EndNotificationErrorReport.hpp"
#include "castor/tape/tapegateway/EndNotification.hpp"
#include "castor/tape/tapegateway/NotificationAcknowledge.hpp"
namespace castor {
namespace tape {
......@@ -94,6 +96,51 @@ throw (castor::exception::Exception) {
clientConnection->sendObject(vol);
}
void ClientSimulator::waitEndSession()
throw (castor::exception::Exception) {
// Accept the next connection
std::auto_ptr<castor::io::ServerSocket> clientConnection(m_callbackSock.accept());
// Read in the message sent by the tapebridge
std::auto_ptr<castor::IObject> obj(clientConnection->readObject());
// Cast the message to a GatewayMessage or die
tapegateway::GatewayMessage & msg(
dynamic_cast<tapegateway::GatewayMessage &> (*obj.get()));
// Check the mount transaction ID
if (msg.mountTransactionId() != (uint64_t) m_volReqId) {
std::stringstream oss;
oss <<
"Mount transaction ID mismatch" <<
": actual=" << msg.mountTransactionId() <<
" expected=" << m_volReqId;
sendEndNotificationErrorReport(msg.aggregatorTransactionId(), EBADMSG,
oss.str(), *clientConnection);
castor::exception::Exception ex(EBADMSG);
ex.getMessage() << oss.str();
throw ex;
}
// We expect with tape EndNotification or EndNotificationErrorReport
try {
(void)dynamic_cast<tapegateway::EndNotification &> (*obj);
} catch (std::bad_cast) {
try {
(void)dynamic_cast<tapegateway::EndNotificationErrorReport &> (*obj);
} catch (std::bad_cast) {
std::stringstream oss;
oss <<
"Expected a tapegateway::EndNotification or tapegateway::EndNotificationErrorReport, got " << typeid (msg).name();
sendEndNotificationErrorReport(msg.aggregatorTransactionId(), EBADMSG,
oss.str(), *clientConnection);
castor::exception::Exception ex(EBADMSG);
ex.getMessage() << oss.str();
throw ex;
}
}
tapegateway::NotificationAcknowledge ack;
ack.setAggregatorTransactionId(msg.aggregatorTransactionId());
ack.setMountTransactionId(m_volReqId);
clientConnection->sendObject(ack);
}
void ClientSimulator::sendEndNotificationErrorReport(
const uint64_t tapebridgeTransactionId,
const int errorCode,
......
......@@ -67,6 +67,7 @@ namespace daemon {
}
void sessionLoop() {
processFirstRequest();
waitEndSession();
m_callbackSock.close();
}
......@@ -98,6 +99,8 @@ namespace daemon {
private:
// Process the first request which should be getVolume
void processFirstRequest() throw(castor::exception::Exception);
// Expect an end sessions (with or without error)
void waitEndSession() throw(castor::exception::Exception);
// Notify the client
void sendEndNotificationErrorReport(
const uint64_t tapebridgeTransactionId,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment