Skip to content
Snippets Groups Projects
Commit bffb76e7 authored by blaakmeer's avatar blaakmeer
Browse files

BugID: 803

First version of OfflineControl
parent 5c3e7a25
No related branches found
No related tags found
No related merge requests found
//# CEPApplicationManager.cc: Implementation of the Virtual CEPApplicationManager task
//#
//# Copyright (C) 2002-2004
//# ASTRON (Netherlands Foundation for Research in Astronomy)
//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
//#
//# This program is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//# This program is distributed in the hope that it will be useful,
//# but WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//# GNU General Public License for more details.
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//#
//# $Id$
#include <lofar_config.h>
#include "CEPApplicationManager.h"
namespace LOFAR
{
using namespace ACC::ALC;
namespace CEPCU
{
INIT_TRACER_CONTEXT(CEPApplicationManager, LOFARLOGGER_PACKAGE);
void CEPApplicationManager::workProc()
{
if (_continuePoll)
{
_acClient.processACmsgFromServer();
}
}
void CEPApplicationManager::handleAckMsg(ACCmd cmd,
uint16 result,
const string& info)
{
LOG_INFO(formatString("command: %d, result: %d, info: %s", cmd, result, info.c_str()));
switch (cmd)
{
case ACCmdBoot:
if (result == AcCmdMaskOk)
{
_lastOkCmd = cmd;
}
_interface.appBooted(_procName, result);
break;
case ACCmdQuit:
if (result == AcCmdMaskOk && result == 0)
{
_continuePoll = false;
}
_interface.appQuitDone(_procName, result);
break;
case ACCmdDefine:
if (result == AcCmdMaskOk)
{
_lastOkCmd = cmd;
}
_interface.appDefined(_procName, result);
break;
case ACCmdInit:
if (result == AcCmdMaskOk)
{
_lastOkCmd = cmd;
}
_interface.appInitialized(_procName, result);
break;
case ACCmdPause:
_interface.appPaused(_procName, result);
break;
case ACCmdRun:
if (result == AcCmdMaskOk)
{
_lastOkCmd = cmd;
}
_interface.appRunDone(_procName, result);
break;
case ACCmdSnapshot:
_interface.appSnapshotDone(_procName, result);
break;
case ACCmdRecover:
_interface.appRecovered(_procName, result);
break;
case ACCmdReinit:
_interface.appReinitialized(_procName, result);
break;
case ACCmdReplace:
_interface.appReplaced(_procName, result);
break;
default:
LOG_WARN_STR("Received command = " << cmd << ", result = " << result
<< ", info = " << info << " not handled!");
break;
}
}
void CEPApplicationManager::handleAnswerMsg (const string& answer)
{
_interface.appSupplyInfoAnswer(_procName, answer);
}
string CEPApplicationManager::supplyInfoFunc (const string& keyList)
{
return _interface.appSupplyInfo(_procName, keyList);
}
} // namespace CEPCU
} // namespace LOFAR
//# CEPApplicationManager.h: factory class for Virtual Backends.
//#
//# Copyright (C) 2002-2005
//# ASTRON (Netherlands Foundation for Research in Astronomy)
//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
//#
//# This program is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//# This program is distributed in the hope that it will be useful,
//# but WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//# GNU General Public License for more details.
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//#
//# $Id$
#ifndef CEPAPPLICATIONMANAGER_H
#define CEPAPPLICATIONMANAGER_H
//# Includes
#include <ALC/ACAsyncClient.h>
#include <GCF/TM/GCF_Handler.h>
//# local includes
//# Common Includes
// forward declaration
namespace LOFAR
{
namespace CEPCU
{
class CEPApplicationManagerInterface
{
protected:
CEPApplicationManagerInterface() {}
public:
virtual ~CEPApplicationManagerInterface() {}
public:
virtual void appBooted(const string& procName, uint16 result) = 0;
virtual void appDefined(const string& procName, uint16 result) = 0;
virtual void appInitialized(const string& procName, uint16 result) = 0;
virtual void appRunDone(const string& procName, uint16 result) = 0;
virtual void appPaused(const string& procName, uint16 result) = 0;
virtual void appQuitDone(const string& procName, uint16 result) = 0;
virtual void appSnapshotDone(const string& procName, uint16 result) = 0;
virtual void appRecovered(const string& procName, uint16 result) = 0;
virtual void appReinitialized(const string& procName, uint16 result) = 0;
virtual void appReplaced(const string& procName, uint16 result) = 0;
virtual string appSupplyInfo(const string& procName, const string& keyList) = 0;
virtual void appSupplyInfoAnswer(const string& procName, const string& answer) = 0;
private:
// protected copy constructor
CEPApplicationManagerInterface(const CEPApplicationManagerInterface&);
// protected assignment operator
CEPApplicationManagerInterface& operator=(const CEPApplicationManagerInterface&);
};
class CEPApplicationManager : public ACC::ALC::ACClientFunctions,
GCF::TM::GCFHandler
{
public:
CEPApplicationManager(CEPApplicationManagerInterface& interface, const string& appName);
virtual ~CEPApplicationManager();
public: // methods may be called from specialized CEPApplicationManagerInterface
bool boot (const time_t scheduleTime,
const string& configID);
bool define (const time_t scheduleTime) const;
bool init (const time_t scheduleTime) const;
bool run (const time_t scheduleTime) const;
bool pause (const time_t scheduleTime,
const time_t maxWaitTime,
const string& condition) const;
bool quit (const time_t scheduleTime) const;
bool shutdown (const time_t scheduleTime) const;
bool snapshot (const time_t scheduleTime,
const string& destination) const;
bool recover (const time_t scheduleTime,
const string& source) const;
bool reinit (const time_t scheduleTime,
const string& configID) const;
bool replace (const time_t scheduleTime,
const string& processList,
const string& nodeList,
const string& configID) const;
string askInfo (const string& keylist) const;
bool cancelCmdQueue () const;
ACC::ALC::ACCmd getLastOkCmd() const;
private: // implemenation of abstract GCFHandler methods
friend class GCF::TM::GCFHandler;
void workProc();
void stop();
private: // implemenation of abstract ACClientFunctions methods
friend class ACC::ALC::ACClientFunctions;
void handleAckMsg (ACC::ALC::ACCmd cmd,
uint16 result,
const string& info);
void handleAnswerMsg (const string& answer);
string supplyInfoFunc (const string& keyList);
protected:
// protected copy constructor
CEPApplicationManager(const CEPApplicationManager&);
// protected assignment operator
CEPApplicationManager& operator=(const CEPApplicationManager&);
private:
CEPApplicationManagerInterface& _interface;
ACC::ALC::ACAsyncClient _acClient;
bool _continuePoll;
ACC::ALC::ACCmd _lastOkCmd;
string _procName;
ALLOC_TRACER_CONTEXT
};
inline CEPApplicationManager::CEPApplicationManager(
CEPApplicationManagerInterface& interface,
const string& appName) :
_interface(interface),
_acClient(this, appName, 10, 100, 1, 0),
_continuePoll(false),
_lastOkCmd(ACC::ALC::ACCmdNone),
_procName(appName)
{
use(); // to avoid that this object will be deleted in GCFTask::stop;
}
inline CEPApplicationManager::~CEPApplicationManager()
{
GCFTask::deregisterHandler(*this);
}
inline bool CEPApplicationManager::boot (const time_t scheduleTime,
const string& configID)
{
_continuePoll = true;
return _acClient.boot(scheduleTime, configID);
}
inline bool CEPApplicationManager::define (const time_t scheduleTime) const
{
return _acClient.define(scheduleTime);
}
inline bool CEPApplicationManager::init (const time_t scheduleTime) const
{
return _acClient.init(scheduleTime);
}
inline bool CEPApplicationManager::run (const time_t scheduleTime) const
{
return _acClient.run(scheduleTime);
}
inline bool CEPApplicationManager::pause (const time_t scheduleTime,
const time_t maxWaitTime,
const string& condition) const
{
return _acClient.pause(scheduleTime, maxWaitTime, condition);
}
inline bool CEPApplicationManager::quit (const time_t scheduleTime) const
{
return _acClient.quit(scheduleTime);
}
inline bool CEPApplicationManager::shutdown (const time_t scheduleTime) const
{
return _acClient.shutdown(scheduleTime);
}
inline bool CEPApplicationManager::snapshot (const time_t scheduleTime,
const string& destination) const
{
return _acClient.snapshot(scheduleTime, destination);
}
inline bool CEPApplicationManager::recover (const time_t scheduleTime,
const string& source) const
{
return _acClient.recover(scheduleTime, source);
}
inline bool CEPApplicationManager::reinit (const time_t scheduleTime,
const string& configID) const
{
return _acClient.reinit(scheduleTime, configID);
}
inline bool CEPApplicationManager::replace (const time_t scheduleTime,
const string& processList,
const string& nodeList,
const string& configID) const
{
return _acClient.replace(scheduleTime, processList, nodeList, configID);
}
inline bool CEPApplicationManager::cancelCmdQueue () const
{
return _acClient.cancelCmdQueue();
}
inline ACC::ALC::ACCmd CEPApplicationManager::getLastOkCmd() const
{
return _lastOkCmd;
}
inline void CEPApplicationManager::stop()
{
}
} // namespace CEPCU
} // namespace LOFAR
#endif
bin_PROGRAMS = OfflineControl
OfflineControl_CPPFLAGS = -Wno-deprecated \
-fmessage-length=0 \
-fdiagnostics-show-location=once
OfflineControl_SOURCES = CEPApplicationManager.cc \
OfflineControl.cc \
OfflineControlMain.cc
OfflineControl_LDADD = $(LOFAR_DEPEND)
OfflineControl_DEPENDENCIES = $(LOFAR_DEPEND)
NOINSTHDRS = CEPApplicationManager.h \
OfflineControl.h \
OfflineControlDefines.h
INSTHDRS =
pkginclude_HEADERS = $(NOINSTHDRS) $(INSTHDRS)
DOCHDRS = $(pkginclude_HEADERS) $(BUILT_SOURCES)
EXTRA_DIST = $(configfiles_DATA) $(sysconf_DATA)
#in case of make install these files will be copied to the bindir beside the test apps
configfilesdir=$(bindir)
configfiles_DATA =
sysconf_DATA = OfflineControl.log_prop
%.log_prop: %.log_prop.in
cp $< $@
clean-local:
rm -f *.ph
include $(top_srcdir)/Makefile.common
This diff is collapsed.
//# OfflineControl.h: Controller for the OfflineControl
//#
//# Copyright (C) 2006
//# ASTRON (Netherlands Foundation for Research in Astronomy)
//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
//#
//# This program is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//# This program is distributed in the hope that it will be useful,
//# but WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//# GNU General Public License for more details.
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//#
//# $Id$
#ifndef OFFLINECONTROL_H
#define OFFLINECONTROL_H
//# Includes
#include <boost/shared_ptr.hpp>
//# GCF Includes
#include <GCF/PAL/GCF_MyPropertySet.h>
#include <GCF/TM/GCF_Port.h>
#include <GCF/TM/GCF_ITCPort.h>
#include <GCF/TM/GCF_TimerPort.h>
#include <GCF/TM/GCF_Task.h>
#include <GCF/TM/GCF_Event.h>
//# local includes
#include <APL/APLCommon/PropertySetAnswerHandlerInterface.h>
#include <APL/APLCommon/PropertySetAnswer.h>
#include <APL/APLCommon/APLCommonExceptions.h>
#include <APL/APLCommon/Controller_Protocol.ph>
#include <APL/APLCommon/ParentControl.h>
#include <APL/APLCommon/CTState.h>
#include <CEPApplicationManager.h>
//# Common Includes
#include <Common/lofar_string.h>
#include <Common/lofar_vector.h>
#include <Common/lofar_datetime.h>
#include <Common/LofarLogger.h>
//# ACC Includes
#include <APS/ParameterSet.h>
// forward declaration
namespace LOFAR {
namespace CEPCU {
using GCF::TM::GCFTimerPort;
using GCF::TM::GCFITCPort;
using GCF::TM::GCFPort;
using GCF::TM::GCFEvent;
using GCF::TM::GCFPortInterface;
using GCF::TM::GCFTask;
using APLCommon::ParentControl;
class OfflineControl : public GCFTask,
public APLCommon::PropertySetAnswerHandlerInterface,
public CEPApplicationManagerInterface
{
public:
explicit OfflineControl(const string& cntlrName);
~OfflineControl();
// PropertySetAnswerHandlerInterface method
void handlePropertySetAnswer(GCFEvent& answer);
// During the initial state all connections with the other programs are made.
GCFEvent::TResult initial_state (GCFEvent& e,
GCFPortInterface& p);
// Normal control mode.
GCFEvent::TResult active_state (GCFEvent& e,
GCFPortInterface& p);
// Finishing mode.
GCFEvent::TResult finished_state(GCFEvent& event,
GCFPortInterface& port);
protected: // implemenation of abstract CEPApplicationManagerInterface methods
void appBooted(const string& procName, uint16 result);
void appDefined(const string& procName, uint16 result);
void appInitialized(const string& procName, uint16 result);
void appRunDone(const string& procName, uint16 result);
void appPaused(const string& procName, uint16 result);
void appQuitDone(const string& procName, uint16 result);
void appSnapshotDone(const string& procName, uint16 result);
void appRecovered(const string& procName, uint16 result);
void appReinitialized(const string& procName, uint16 result);
void appReplaced(const string& procName, uint16 result);
string appSupplyInfo(const string& procName, const string& keyList);
void appSupplyInfoAnswer(const string& procName, const string& answer);
private:
// avoid defaultconstruction and copying
OfflineControl();
OfflineControl(const OfflineControl&);
OfflineControl& operator=(const OfflineControl&);
uint16_t doClaim(const string& cntlrName);
uint16_t doPrepare(const string& cntlrName);
void prepareProcess(const string& cntlrName, const string& procName, const time_t startTime);
void doRelease();
void finishController(uint16_t result);
void _connectedHandler(GCFPortInterface& port);
void _disconnectedHandler(GCFPortInterface& port);
void setState(CTState::CTstateNr newState);
typedef boost::shared_ptr<GCF::PAL::GCFMyPropertySet> GCFMyPropertySetPtr;
typedef boost::shared_ptr<CEPApplicationManager> CEPApplicationManagerPtr;
APLCommon::PropertySetAnswer itsPropertySetAnswer;
GCFMyPropertySetPtr itsPropertySet;
bool itsPropertySetInitialized;
// pointer to parent control task
ParentControl* itsParentControl;
GCFITCPort* itsParentPort;
GCFTimerPort* itsTimerPort;
map<string, CEPApplicationManagerPtr> itsCepApplications;
map<string, ACC::APS::ParameterSet> itsCepAppParams;
ACC::APS::ParameterSet itsResultParams;
map<string, vector<string> > itsProcessDependencies;
CTState::CTstateNr itsState;
// ParameterSet variables
string itsTreePrefix;
uint32 itsInstanceNr;
ptime itsStartTime;
ptime itsStopTime;
uint32 itsClaimPeriod;
uint32 itsPreparePeriod;
string itsCntlrName;
};
};//CEPCU
};//LOFAR
#endif
# add your custom loggers and appenders here
#
log4cplus.rootLogger=DEBUG, STDOUT, FILE
log4cplus.logger.TRC=TRACE2
log4cplus.additivity.TRC=FALSE
log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
log4cplus.appender.STDOUT.layout.ConversionPattern=%D{%d-%m-%y %H:%M:%S.%q} %-5p %c{9} - %m [%.25l]%n
log4cplus.appender.STDOUT.logToStdErr=true
log4cplus.appender.FILE=log4cplus::RollingFileAppender
log4cplus.appender.FILE.File=../log/OfflineControl.log
log4cplus.appender.FILE.MaxFileSize=5MB
log4cplus.appender.FILE.MaxBackupIndex=5
log4cplus.appender.FILE.layout=log4cplus::PatternLayout
log4cplus.appender.FILE.layout.ConversionPattern=%D{%d-%m-%y %H:%M:%S.%q} %-5p %c{3} - %m [%.25l]%n
//# OfflineControlDefines.h: preprocessor definitions of various constants
//#
//# Copyright (C) 2002-2003
//# ASTRON (Netherlands Foundation for Research in Astronomy)
//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
//#
//# This program is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//# This program is distributed in the hope that it will be useful,
//# but WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//# GNU General Public License for more details.
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//#
//# $Id$
#ifndef OFFLINECONTROLDEFINES_H
#define OFFLINECONTROLDEFINES_H
namespace LOFAR {
namespace CEPCU {
#define ONC_TASKNAME "OfflineCtrl"
#define ONC_PROPSET_NAME "LOFAR_ObsSW_ObsCtrl%d_OfflineCtrl"
#define ONC_PROPSET_TYPE "OfflineCtrl"
#define ONC_OBSERVATIONSTATE "observationState"
// next lines should be defined somewhere in Common.
#define PVSSNAME_FSM_STATE "state"
#define PVSSNAME_FSM_ERROR "error"
}; // MCU
}; // LOFAR
#endif
//# OfflineControlMain.cc: Main entry for the OfflineControl controller.
//#
//# Copyright (C) 2006
//# ASTRON (Netherlands Foundation for Research in Astronomy)
//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
//#
//# This program is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//# This program is distributed in the hope that it will be useful,
//# but WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//# GNU General Public License for more details.
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//#
//# $Id$
//#
#include <lofar_config.h>
#include <Common/LofarLogger.h>
#include "OfflineControl.h"
using namespace LOFAR::GCF::TM;
using namespace LOFAR::CEPCU;
int main(int argc, char* argv[])
{
// args: cntlrname
if(argc < 2)
{
printf("Unexpected number of arguments: %d\n",argc);
printf("%s usage: %s <controller name>\n",argv[0],argv[0]);
exit(-1);
}
GCFTask::init(argc, argv);
ParentControl* pc = ParentControl::instance();
pc->start(); // make initial transition
OfflineControl ofc(argv[1]);
ofc.start(); // make initial transition
GCFTask::run();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment