DRDE/AusRegCliever/server/mdAusReg.cpp

325 lines
10 KiB
C++
Raw Normal View History

2014-01-11 00:58:45 +00:00
#define MD_AUSREG
#include "cliever-md.h"
2014-01-13 03:41:09 +00:00
#include "session/SessionFactory.hpp"
#include "session/SessionManagerProperties.hpp"
2014-01-21 01:34:40 +00:00
#include "session/Transaction.hpp"
2014-01-13 03:41:09 +00:00
#include "common/SystemProperties.hpp"
#include "session/Session.hpp"
#include "session/StatsManager.hpp"
2014-01-18 20:35:18 +00:00
#include "se/DomainCheckCommand.hpp"
#include "se/DomainCheckResponse.hpp"
2014-01-24 20:49:09 +00:00
#include "se/LPE/LPChkCmdExtension.hpp"
2014-01-25 17:23:41 +00:00
#include "se/LPE/LPChkRespExtension.hpp"
2014-01-24 22:17:21 +00:00
#include "se/LPE/LPCrtCmdExtension.hpp"
2014-01-25 17:23:41 +00:00
#include "se/LPE/LPCrtRespExtension.hpp"
2014-01-21 01:34:40 +00:00
#include "se/TransferOp.hpp"
2014-01-21 23:01:41 +00:00
#include "se/IntPostalInfo.hpp"
2014-01-21 01:34:40 +00:00
#include "se/ContactCreateCommand.hpp"
#include "se/ContactCreateResponse.hpp"
2014-01-18 20:35:18 +00:00
#include "se/DomainCreateCommand.hpp"
#include "se/DomainCreateResponse.hpp"
2014-01-27 17:24:42 +00:00
#include "se/DomainTransferApproveCommand.hpp"
#include "se/DomainTransferRequestCommand.hpp"
2014-01-21 01:34:40 +00:00
#include "se/DomainTransferResponse.hpp"
2014-01-28 18:16:48 +00:00
#include <errno.h>
#include <sys/types.h>
#include <sys/inotify.h>
2014-01-29 18:10:26 +00:00
#include <json/json.h>
#include "mdJSON.hpp"
2014-01-07 17:59:27 +00:00
2014-01-31 23:38:13 +00:00
Json::Value parms[MAX_OTE_CASE];
bool JSONBatchInProgress = false;
2014-01-30 23:27:18 +00:00
namespace ACPRODINOTE {
2014-01-30 15:25:00 +00:00
typedef boost::heap::priority_queue<Transaction *> ACWQ;
2014-01-29 23:57:01 +00:00
ACWQ acq;
2014-01-11 00:58:45 +00:00
using namespace std;
2014-01-29 23:57:01 +00:00
#define PRODINOTESLEEP 1 // seconds
#define EODMARGIN 3 // minutes
2014-01-28 18:16:48 +00:00
#define EVENT_SIZE ( sizeof (struct inotify_event) )
2014-01-30 18:17:29 +00:00
#define BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
2014-01-28 18:16:48 +00:00
//char *name1 = "bestever.camera"; //
//char *name3 = "pricey.holdings"; //
//char *name5 = "greedy.ventures"; //
//char *name6 = "shady.ventures"; //
//char *name7 = "hemmarhoid.camera"; //
//char *name3 = "pricey.holdings"; //
2014-01-29 18:10:26 +00:00
const char *name1 = "yoda.guru";
const char *name2 = "unicycles.bike";
const char *name3 = "test-validate.claimsgasix";
const char *name4 = "horny.singles";
const char *name5 = "atmospheric.lighting";
const char *name6 = "mushroomtheory.management";
2014-01-21 01:34:40 +00:00
2014-01-29 18:10:26 +00:00
static TestEnvironment props;
2014-01-07 17:59:27 +00:00
2014-01-29 18:10:26 +00:00
static std::string TEST_SE =
2014-01-13 03:41:09 +00:00
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><epp xmlns=\"urn:ietf:params:xml:ns:epp-1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd\"><hello/></epp>";
2014-01-29 18:10:26 +00:00
#include "AC_OTE.h"
2014-01-11 00:58:45 +00:00
// static void testExecuteParallelTransactions() throw (EPPException);
2014-01-16 15:35:39 +00:00
bool ausRegEPPTK::doNothing(const std::string propertiesFilePath) { // Just verify load
2014-01-07 17:59:27 +00:00
2014-01-10 20:05:42 +00:00
bool did=false;
2014-01-07 17:59:27 +00:00
2014-01-10 20:05:42 +00:00
try {
2014-01-16 15:35:39 +00:00
scenario( 0, propertiesFilePath ); // tkScenario 0 assumed
2014-01-10 20:05:42 +00:00
did = true;
}
catch(std::exception &e) {
2014-01-10 22:01:44 +00:00
theseLogs->logN(2,"Scenario %d TK Exception: %s .",tkScenario,e.what());
2014-01-10 20:05:42 +00:00
}
2014-01-10 22:01:44 +00:00
return did;
2014-01-07 17:59:27 +00:00
}
2014-01-11 00:58:45 +00:00
void ausRegEPPTK::doOTEA()
{
2014-01-13 23:19:10 +00:00
int hours,hoops;
2014-01-11 00:58:45 +00:00
string op("newInstance");
2014-01-16 05:39:38 +00:00
scenario(tkScenario,thisConfig->cfg_path);
2014-01-11 00:58:45 +00:00
try {
2014-01-18 20:35:18 +00:00
Timer::setTime("20140101.010101");
2014-01-11 00:58:45 +00:00
auto_ptr<SessionManager> manager(SessionManagerFactory::newInstance(&props));
2014-01-13 03:41:09 +00:00
auto_ptr<Session> sess(SessionFactory::newInstance(&props));
2014-01-11 00:58:45 +00:00
op = "startup";
manager->startup();
op = "run (keep-alive)";
manager->run();
2014-01-13 23:19:10 +00:00
sess->open();
2014-01-13 03:41:09 +00:00
2014-01-13 23:19:10 +00:00
for (hours=0;hours < 24;hours++) {
2014-01-11 00:58:45 +00:00
// Spawn the keep alive thread.
2014-01-13 23:19:10 +00:00
theseLogs->logN(1,"Send Test SEs on or about start OTE Test Hour %d.",hours);
for (hoops=0;hoops<7;hoops++) {
sess->writeXML(TEST_SE);
sess->read();
2014-01-30 23:27:18 +00:00
sleep(REGISTRY_HANDSHAKE);
2014-01-13 23:19:10 +00:00
}
2014-01-13 03:41:09 +00:00
2014-01-11 00:58:45 +00:00
}
2014-01-13 03:41:09 +00:00
sess->close();
2014-01-11 00:58:45 +00:00
manager->shutdown();
2014-01-11 03:01:32 +00:00
2014-01-11 00:58:45 +00:00
}
catch (EPPException& e)
{ const char *eMsg = e.getMessage().c_str();
const char *opNow = op.c_str();
theseLogs->logN(2,"EPP Exception during OTE A (%s): %s .",opNow,eMsg);
throw e;
}
catch (...)
{
theseLogs->logN(2,"General Exception during OTE A (%s).",op.c_str());
}
2014-01-13 23:19:10 +00:00
}
2014-01-28 18:16:48 +00:00
#include "donutsOTEB.h"
2014-01-29 18:10:26 +00:00
void ausRegEPPTK::registryXOTE() { // PROD in OTE
2014-01-28 18:16:48 +00:00
// This scenario generalizes OTEB so that its operations can be performed
2014-01-29 18:10:26 +00:00
// by json scripting. This is a quick and clean which is meant to allow
// a Registrar to begin quasi-production ops from the established OTE
// baseline. It's main use case is scripted OTE ops however, it's not
// meant to be actual production.
2014-01-28 18:16:48 +00:00
bool actionableFileEvent,monitoring=true;
2014-01-30 18:17:29 +00:00
int length, i = 0, j, mSleeps=0, nSleeps=0,debug=10000;
2014-01-29 18:10:26 +00:00
int fd, wd;
2014-01-28 18:16:48 +00:00
char buffer[BUF_LEN];
2014-01-29 23:57:01 +00:00
theseLogs->logN(0,"Begin RegistryXOTE Session.");
2014-01-29 18:10:26 +00:00
2014-01-30 23:27:18 +00:00
ACPRODINOTE::setFuncs();
2014-01-29 18:10:26 +00:00
fd = inotify_init();
if ( fd < 0 ) {
theseLogs->logN(0,"Fatal error, couldn't init inotify.");
return;
}
2014-01-28 18:16:48 +00:00
2014-01-31 23:38:13 +00:00
theseLogs->logN(0,"Monitoring /json for changes.");
2014-01-28 18:16:48 +00:00
2014-01-31 23:38:13 +00:00
wd = inotify_add_watch( fd, "/json", IN_MODIFY | IN_CREATE | IN_DELETE );
2014-01-29 18:10:26 +00:00
length = read( fd, buffer, BUF_LEN );
if ( length < 0 ) {
2014-01-28 18:16:48 +00:00
theseLogs->logN(0,"Fatal error, initial inotify read failed.");
2014-01-29 23:57:01 +00:00
goto done;
2014-01-29 18:10:26 +00:00
}
2014-01-29 23:57:01 +00:00
2014-01-30 18:17:29 +00:00
while ( length >= 0 && (BUF_LEN - i) >= length && monitoring )
2014-01-29 18:10:26 +00:00
{ actionableFileEvent = false;
struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
2014-01-28 18:16:48 +00:00
2014-01-29 18:10:26 +00:00
if ( event->len ) {
if ( event->mask & IN_CREATE ) {
2014-01-28 18:16:48 +00:00
if ( event->mask & IN_ISDIR ) {
2014-01-29 23:57:01 +00:00
theseLogs->logN(1,"The directory %s was created.", event->name );
2014-01-13 23:19:10 +00:00
}
2014-01-28 18:16:48 +00:00
else {
2014-01-29 23:57:01 +00:00
theseLogs->logN(1,"The file %s was created.", event->name );
2014-01-28 18:16:48 +00:00
actionableFileEvent = true;
2014-01-13 23:19:10 +00:00
}
2014-01-29 18:10:26 +00:00
}
else if ( event->mask & IN_DELETE ) {
2014-01-28 18:16:48 +00:00
if ( event->mask & IN_ISDIR ) {
2014-01-29 23:57:01 +00:00
theseLogs->logN(1,"The directory %s was deleted.", event->name );
2014-01-13 23:19:10 +00:00
}
2014-01-28 18:16:48 +00:00
else {
2014-01-29 23:57:01 +00:00
theseLogs->logN(1,"The file %s was deleted.", event->name );
2014-01-28 18:16:48 +00:00
}
2014-01-29 18:10:26 +00:00
}
else if ( event->mask & IN_MODIFY ) {
2014-01-28 18:16:48 +00:00
if ( event->mask & IN_ISDIR ) {
2014-01-29 23:57:01 +00:00
theseLogs->logN(1, "The directory %s was modified.", event->name );
2014-01-28 18:16:48 +00:00
}
else {
2014-01-29 23:57:01 +00:00
theseLogs->logN(1, "The file %s was modified.", event->name );
theseLogs->logN(0, "Modifications are ignored." );
}
2014-01-28 18:16:48 +00:00
}
2014-01-29 18:10:26 +00:00
2014-01-31 23:38:13 +00:00
if (actionableFileEvent) { char wxyz[100]; sprintf(wxyz,"/json/%s",event->name);
while (JSONBatchInProgress) {
theseLogs->logN(0, "Waiting for pending batch to complete." );
sleep(2);
}
JSONBatchInProgress = true;
2014-01-29 23:57:01 +00:00
mdJSON scriptor;
scriptor.setPath(wxyz);
if (!scriptor.parse()) { didDie = false;
2014-01-31 23:38:13 +00:00
if (scriptor.run()) {
2014-01-29 00:02:24 +00:00
if (didDie) {
monitoring = false;
2014-01-31 23:38:13 +00:00
theseLogs->logN(1, "Run of %s fatal error. /json monitoring stops.", event->name );
2014-01-29 23:57:01 +00:00
theseLogs->logN(0, "Restart process to resume JSON monitoring operations." );
2014-01-29 00:02:24 +00:00
} else {
2014-01-31 23:38:13 +00:00
theseLogs->logN(1, "Run of %s has errors /json monitoring continues.", event->name );
JSONBatchInProgress = false;
2014-01-29 00:02:24 +00:00
}
2014-01-29 23:57:01 +00:00
} else
2014-01-31 23:38:13 +00:00
theseLogs->logN(1, " %s preprocessed OK. /json monitoring continues.", event->name );
2014-01-29 18:10:26 +00:00
}
2014-01-29 23:57:01 +00:00
else {
2014-01-31 23:38:13 +00:00
theseLogs->logN(1, "Parse of %s failed. /json monitoring continues.", event->name );
JSONBatchInProgress = false;
2014-01-29 23:57:01 +00:00
}
}
2014-01-28 18:16:48 +00:00
}
2014-01-30 18:17:29 +00:00
j = i;
if (i >= (BUF_LEN - (EVENT_SIZE + event->len)))
i = 0;
else
i += EVENT_SIZE + event->len;
length = read( fd, &buffer[i], (BUF_LEN - j) );
2014-01-29 23:57:01 +00:00
}
2014-01-30 18:17:29 +00:00
if (monitoring)
2014-01-31 23:38:13 +00:00
theseLogs->logN(2,"JSON monitoring unexpected end: %d %d.",i,length);
2014-01-29 23:57:01 +00:00
done:
( void ) inotify_rm_watch( fd, wd );
( void ) close( fd );
theseLogs->logN(0,"End RegistryXOTE Session.");
2014-01-28 18:16:48 +00:00
}
2014-01-29 18:10:26 +00:00
void ausRegEPPTK::doPROD()
2014-01-18 20:35:18 +00:00
{
2014-01-30 23:27:18 +00:00
int debug=1000000,hours=0,hoops,minutes=0,seconds=0,idleSeconds=0,lastPolicyHandshake=0,
lastSeconds=0,lastMinutes,iqSize=acq.max_size();
2014-01-18 20:35:18 +00:00
string op("newInstance");
scenario(thisConfig->tkScenario,thisConfig->cfg_path);
2014-01-30 23:27:18 +00:00
if (iqSize < MIN_TRANSQ_POLICY) {
acq.reserve(MIN_TRANSQ_POLICY - iqSize);
iqSize=acq.max_size();
theseLogs->logN(1,"Workq size: %d",iqSize);
}
2014-01-18 20:35:18 +00:00
try {
Timer::setTime("20140101.010101");
auto_ptr<SessionManager> manager(SessionManagerFactory::newInstance(&props));
auto_ptr<Session> sess(SessionFactory::newInstance(&props));
op = "startup";
manager->startup();
op = "run (keep-alive)";
manager->run();
sess->open();
2014-01-30 23:27:18 +00:00
// ac_mgr = manager;
2014-01-31 23:38:13 +00:00
// ac_sess = sess;
2014-01-18 20:35:18 +00:00
2014-01-29 23:57:01 +00:00
while ((1440 - minutes) > EODMARGIN) {
2014-01-18 20:35:18 +00:00
2014-01-30 23:27:18 +00:00
if (!acq.empty()) {
2014-01-30 02:30:49 +00:00
Transaction *tx = acq.top();
2014-01-30 15:25:00 +00:00
if (debug > 999)
theseLogs->logN(3,"Tx dequeued @ minute %d second %d (%d waiting).",minutes,seconds,acq.size()-1);
2014-01-31 23:38:13 +00:00
//manager->execute(*tx);
2014-01-30 15:25:00 +00:00
if (debug > 999)
theseLogs->logN(2,"Tx completed @ minute %d second %d.",minutes,seconds);
2014-01-30 23:27:18 +00:00
idleSeconds = 0;
2014-01-31 23:38:13 +00:00
if (!acq.size())
JSONBatchInProgress = false;
2014-01-30 02:30:49 +00:00
acq.pop();
delete tx;
2014-01-29 23:57:01 +00:00
}
2014-01-30 23:27:18 +00:00
if (!lastPolicyHandshake || (seconds - lastPolicyHandshake >= (REGISTRY_HANDSHAKE - 5)))
2014-01-31 23:38:13 +00:00
{lastPolicyHandshake = 1; goto skipHandshake;
idleSeconds = 0;
2014-01-30 23:27:18 +00:00
if (debug > 99)
theseLogs->logN(3,"AC-Registry Policy Handshake %d:%d:%d.",hours-1,minutes,seconds);
lastPolicyHandshake = seconds;
2014-01-29 23:57:01 +00:00
sess->writeXML(TEST_SE);
sess->read();
2014-01-31 23:38:13 +00:00
skipHandshake: ;
2014-01-29 23:57:01 +00:00
}
sleep(PRODINOTESLEEP);
seconds += PRODINOTESLEEP;
idleSeconds += PRODINOTESLEEP;
if ((seconds - lastSeconds) == 60) {
minutes++; lastSeconds = seconds;
}
if (!hours || ((minutes - lastMinutes) >= 59)) {
theseLogs->logN(1,"AC Production Hour %d.",hours++);
lastMinutes = minutes;
}
2014-01-30 15:25:00 +00:00
2014-01-31 23:38:13 +00:00
if (debug > 9999 && !(seconds % 120))
2014-01-30 15:25:00 +00:00
theseLogs->logN(3,"AC Production %d:%d:%d.",hours-1,minutes,seconds);
2014-01-29 23:57:01 +00:00
}
2014-01-18 20:35:18 +00:00
sess->close();
manager->shutdown();
}
catch (EPPException& e)
{ const char *eMsg = e.getMessage().c_str();
const char *opNow = op.c_str();
theseLogs->logN(2,"EPP Exception in Production (%s): %s .",opNow,eMsg);
throw e;
}
catch (...)
{
theseLogs->logN(2,"General Exception Production (%s).",op.c_str());
}
2014-01-29 23:57:01 +00:00
2014-01-18 20:35:18 +00:00
}
2014-01-30 23:27:18 +00:00
}