Namespaces unified (sal+fi -> fail), Code cleanups (-> coding-style.txt), Doxygen-comments fixed.
git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1319 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
#include "JobClient.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace fi {
|
||||
namespace fail {
|
||||
|
||||
JobClient::JobClient(std::string server, int port)
|
||||
{
|
||||
@ -10,6 +11,7 @@ JobClient::JobClient(std::string server, int port)
|
||||
m_server_ent = gethostbyname(m_server.c_str());
|
||||
if(m_server_ent == NULL) {
|
||||
perror("[Client@gethostbyname()]");
|
||||
// TODO: Log-level?
|
||||
exit(1);
|
||||
}
|
||||
srand(time(NULL)); // needed for random backoff (see connectToServer)
|
||||
@ -22,6 +24,7 @@ bool JobClient::connectToServer()
|
||||
m_sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(m_sockfd < 0) {
|
||||
perror("[Client@socket()]");
|
||||
// TODO: Log-level?
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@ -38,10 +41,12 @@ bool JobClient::connectToServer()
|
||||
while(true) {
|
||||
if(connect(m_sockfd, (sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
|
||||
perror("[Client@connect()]");
|
||||
// TODO: Log-level?
|
||||
if(retries > 0) {
|
||||
// Wait CLIENT_RAND_BACKOFF_TSTART to RAND_BACKOFF_TEND seconds:
|
||||
int delay = rand() % (CLIENT_RAND_BACKOFF_TEND-CLIENT_RAND_BACKOFF_TSTART) + CLIENT_RAND_BACKOFF_TSTART;
|
||||
cout << "[Client] Retrying to connect to server in ~" << delay << "s..." << endl;
|
||||
// TODO: Log-level?
|
||||
sleep(delay);
|
||||
usleep(rand() % 1000000);
|
||||
--retries;
|
||||
@ -49,11 +54,13 @@ bool JobClient::connectToServer()
|
||||
}
|
||||
cout << "[Client] Unable to reconnect (tried " << CLIENT_RETRY_COUNT << " times); "
|
||||
<< "I'll give it up!" << endl;
|
||||
// TODO: Log-level?
|
||||
return false; // finally: unable to connect, give it up :-(
|
||||
}
|
||||
break; // connected! :-)
|
||||
}
|
||||
cout << "[Client] Connection established!" << endl;
|
||||
// TODO: Log-level?
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -110,6 +117,7 @@ bool JobClient::sendResult(ExperimentData& result)
|
||||
ctrlmsg.set_build_id(42);
|
||||
ctrlmsg.set_workloadid(result.getWorkloadID());
|
||||
cout << "[Client] Sending back result [" << std::dec << result.getWorkloadID() << "]..." << endl;
|
||||
// TODO: Log-level?
|
||||
SocketComm::send_msg(m_sockfd, ctrlmsg);
|
||||
SocketComm::send_msg(m_sockfd, result.getMessage());
|
||||
// close connection.
|
||||
@ -117,5 +125,4 @@ bool JobClient::sendResult(ExperimentData& result)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // end-of-namespace: fail
|
||||
|
||||
@ -12,48 +12,48 @@
|
||||
#include "jobserver/messagedefs/FailControlMessage.pb.h"
|
||||
#include "config/FailConfig.hpp"
|
||||
|
||||
namespace fi {
|
||||
namespace fail {
|
||||
|
||||
/**
|
||||
* \class JobClient
|
||||
*
|
||||
* \brief Manages communication with JobServer
|
||||
* The Minion's JobClient requests ExperimentData and returns results.
|
||||
*
|
||||
*/
|
||||
class JobClient {
|
||||
/**
|
||||
* \class JobClient
|
||||
*
|
||||
* \brief Manages communication with JobServer
|
||||
* The Minion's JobClient requests ExperimentData and returns results.
|
||||
*/
|
||||
class JobClient {
|
||||
private:
|
||||
std::string m_server;
|
||||
int m_server_port;
|
||||
struct hostent* m_server_ent;
|
||||
int m_sockfd;
|
||||
|
||||
std::string m_server;
|
||||
int m_server_port;
|
||||
struct hostent* m_server_ent;
|
||||
int m_sockfd;
|
||||
bool connectToServer();
|
||||
|
||||
bool connectToServer();
|
||||
FailControlMessage_Command tryToGetExperimentData(ExperimentData& exp);
|
||||
public:
|
||||
// FIXME: This should be a const reference to std::string...
|
||||
JobClient(std::string server = "localhost", int port = 1111);
|
||||
/**
|
||||
* Receive experiment data set from (remote) JobServer
|
||||
* The caller (experiment developer) is responsible for
|
||||
* allocating his ExperimentData object.
|
||||
*
|
||||
* @param exp Reference to a ExperimentData object allocated by the caller!
|
||||
* @return \c true if parameter have been received and put into \c exp, \c false else.
|
||||
*/
|
||||
bool getParam(ExperimentData& exp);
|
||||
|
||||
FailControlMessage_Command tryToGetExperimentData(ExperimentData& exp);
|
||||
public:
|
||||
JobClient(std::string server = "localhost", int port = 1111);
|
||||
/**
|
||||
* Receive experiment data set from (remote) JobServer
|
||||
* The caller (experiment developer) is responsible for
|
||||
* allocating his ExperimentData object.
|
||||
*
|
||||
* @param exp Reference to a ExperimentData object allocated by the caller!
|
||||
* @return \c true if parameter have been received and put into \c exp, \c false else.
|
||||
*/
|
||||
bool getParam(ExperimentData& exp);
|
||||
/**
|
||||
* Send back experiment result to the (remote) JobServer
|
||||
* The caller (experiment developer) is responsible for
|
||||
* destroying his ExperimentData object afterwards.
|
||||
*
|
||||
* @param result Reference to the ExperimentData holding result values
|
||||
* @return \c true Result successfully sent, \c false else.
|
||||
*/
|
||||
bool sendResult(ExperimentData& result);
|
||||
};
|
||||
|
||||
/**
|
||||
* Send back experiment result to the (remote) JobServer
|
||||
* The caller (experiment developer) is responsible for
|
||||
* destroying his ExperimentData object afterwards.
|
||||
*
|
||||
* @param result Reference to the ExperimentData holding result values
|
||||
* @return \c true Result successfully sent, \c false else.
|
||||
*/
|
||||
bool sendResult(ExperimentData& result);
|
||||
|
||||
};
|
||||
}
|
||||
} // end-of-namespace: fail
|
||||
|
||||
#endif // __JOB_CLIENT_H__
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
// <iostream> needs to be included before *.pb.h, otherwise ac++/Puma chokes on the latter
|
||||
#include <iostream>
|
||||
|
||||
#include "JobServer.hpp"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -11,6 +9,7 @@
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "JobServer.hpp"
|
||||
#include "jobserver/messagedefs/FailControlMessage.pb.h"
|
||||
#include "SocketComm.hpp"
|
||||
#include "controller/Minion.hpp"
|
||||
@ -22,9 +21,10 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace fi {
|
||||
namespace fail {
|
||||
|
||||
void JobServer::addParam(ExperimentData* exp){
|
||||
void JobServer::addParam(ExperimentData* exp)
|
||||
{
|
||||
#ifndef __puma
|
||||
m_undoneJobs.Enqueue(exp);
|
||||
#endif
|
||||
@ -58,6 +58,7 @@ ExperimentData *JobServer::getDone()
|
||||
#ifdef SERVER_PERFORMANCE_MEASURE
|
||||
void JobServer::measure()
|
||||
{
|
||||
// TODO: Log-level?
|
||||
cout << "\n[Server] Logging throughput in \"" << SERVER_PERF_LOG_PATH << "\"..." << endl;
|
||||
ofstream m_file(SERVER_PERF_LOG_PATH, std::ios::trunc); // overwrite existing perf-logs
|
||||
if(!m_file.is_open()) {
|
||||
@ -303,4 +304,4 @@ void CommThread::receiveExperimentResults(Minion& minion, uint32_t workloadID)
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
} // end-of-namespace: fail
|
||||
|
||||
@ -8,11 +8,12 @@
|
||||
#include "config/FailConfig.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
#ifndef __puma
|
||||
#include <boost/thread.hpp>
|
||||
#endif
|
||||
|
||||
namespace fi {
|
||||
namespace fail {
|
||||
|
||||
class CommThread;
|
||||
|
||||
@ -133,7 +134,6 @@ public:
|
||||
void done() { m_finish = true; };
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @class CommThread
|
||||
* Implementation of the communication threads.
|
||||
@ -171,6 +171,6 @@ private:
|
||||
void receiveExperimentResults(Minion& minion, uint32_t workloadID);
|
||||
};
|
||||
|
||||
};
|
||||
} // end-of-namespace: fail
|
||||
|
||||
#endif //__JOB_SERVER_H__
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#include <string>
|
||||
|
||||
#include "SocketComm.hpp"
|
||||
|
||||
namespace fi {
|
||||
namespace fail {
|
||||
|
||||
bool SocketComm::send_msg(int sockfd, google::protobuf::Message& msg)
|
||||
{
|
||||
@ -39,11 +41,12 @@ bool SocketComm::rcv_msg(int sockfd, google::protobuf::Message& msg)
|
||||
return false;
|
||||
}
|
||||
std::string st(buf, size);
|
||||
delete[] buf;
|
||||
delete [] buf;
|
||||
msg.ParseFromString(st);
|
||||
return true;
|
||||
#else
|
||||
return msg.ParseFromFileDescriptor(sockfd);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
} // end-of-namespace: fail
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
/**
|
||||
* \brief Socket based communictaion
|
||||
*
|
||||
* \author Horst Schirmeier, Martin Hoffmann
|
||||
* \brief Socket based communictaion wrapper functions.
|
||||
*/
|
||||
|
||||
#ifndef __SOCKETCOMM_HPP__
|
||||
#define __SOCKETCOMM_HPP__
|
||||
#ifndef __SOCKET_COMM_HPP__
|
||||
#define __SOCKET_COMM_HPP__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
@ -15,13 +13,13 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <google/protobuf/message.h>
|
||||
|
||||
#define USE_SIZE_PREFIX
|
||||
|
||||
namespace fi {
|
||||
namespace fail {
|
||||
|
||||
class SocketComm {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Send Protobuf-generated message
|
||||
* @param sockfd open socket descriptor to write to
|
||||
@ -29,7 +27,6 @@ public:
|
||||
* \return false if message sending failed
|
||||
*/
|
||||
static bool send_msg(int sockfd, google::protobuf::Message& msg);
|
||||
|
||||
/**
|
||||
* Receive Protobuf-generated message
|
||||
* @param sockfd open socket descriptor to read from
|
||||
@ -39,6 +36,6 @@ public:
|
||||
static bool rcv_msg(int sockfd, google::protobuf::Message& msg);
|
||||
};
|
||||
|
||||
}
|
||||
} // end-of-namespace: fail
|
||||
|
||||
#endif
|
||||
#endif // __SOCKET_COMM_HPP__
|
||||
|
||||
Reference in New Issue
Block a user