Commit 13e70b66 authored by Marco De Marco's avatar Marco De Marco
Browse files

Before ignore timeout property removed

parent d8f8fb3c
Loading
Loading
Loading
Loading

script/fits.sh

deleted100755 → 0
+0 −104
Original line number Diff line number Diff line
#!/bin/bash

#: Title	: fits.sh
#: Date		: 2014/03/03
#: Author	: "Marco De Marco" <demarco@oats.inaf.it>
#: Version	: 0.1
#: Description	: Fits verification and preproccessing script
#: Usage 	: 
#: Response	: 


if [ "$1" == "CHECK" ]; then

	#: Section	: CHECK
	#: Parameter	: none
	#: Response	: CHECK OK
	#: 		: CHECK FATAL

	VERIFY_TOOL="/usr/local/bin/fitsverify"
	CHECK_STRING="conform to the FITS format"

	res=$($VERIFY_TOOL 2>&1)
	check=$(echo $res | grep "$CHECK_STRING" | wc | awk '{print $1}')
	if [ "$check" -ge "1" ]; then
		echo "CHECK OK"
	else
		echo "CHECK FATAL"
	fi
	exit 0

elif [ "$1" == "VERIFY" ]; then

	#: Section	: VERIFY
	#: Parameter	: file path 
	#: Response	: VERIFY OK
	#: 		: VERIFY WAIT
	#: 		: VERIFY FATAL

	VERIFY_TOOL="/usr/local/bin/fitsverify"
	FATAL_ERROR="Fatal"
	EOF_ERROR="End-of-file"

	file=$2
	file_name=${file##*/}

	#Check regular expression -> fatal
	if [[ ! "${file_name,,}" =~ ^[^\.].*\.(fits|fit|fts).*$ ]]; then
		echo "VERIFY FATAL : error on regular expression"
		exit 0
	fi

	#if fits verify tools exists -> fatal
	if [ ! -x $VERIFY_TOOL ]; then
		echo "VERIFY FATAL : verify tools not exists"
		exit 0
	fi

	#if fits file not exists -> fatal
	if [ ! -f $file ]; then
		echo "VERIFY FATAL : file not exists"
		exit 0
	fi

	#Check with fits verify
	res=$($VERIFY_TOOL $file 2>&1)

	#if fitsverify return fatal error -> wait
	fatal=$(echo $res | grep "$FATAL_ERROR" | wc | awk '{print $1}')
	if [ "$fatal" -ge "1" ]; then
		echo "VERIFY WAIT"
		exit 0
	fi

	#if fitsverify return end of file -> wait
	eof=$(echo $res | grep "$EOF_ERROR" | wc | awk '{print $1}')
	if [ "$eof" -ge "1" ]; then
		echo "VERIFY WAIT"
		exit 0
	fi

	#else -> ok
	echo "VERIFY OK"
	exit 0

elif [ "$1" == "PROCESS" ]; then

	#: Section	: PROCESS 
	#: Parameter	: file path 
	#: Response	: PROCESS OK
	#: 		: PROCESS FATAL

	echo "PROCESS OK"
	exit 0

else

	#: Section	: DEFAULT
	#: Parameter	: none
	#: Response	: UNKNOWN

	echo "UNKNOWN"
	exit 0

fi
+107 −0
Original line number Diff line number Diff line
#!/bin/bash

#: Title	: checkfits.sh
#: Date		: 2014/10/28
#: Author	: "Marco De Marco" <demarco@oats.inaf.it>
#: Version	: 1.0
#: Description	: Fits verification and preproccessing script


if [ "$1" == "CHECK" ]; then

	#: Section	: CHECK
	#: Parameter	: none
	#: Response	: CHECK OK
	#: 		: CHECK FATAL
	#: Description	: Check availability of script tools

	echo "CHECK OK"
	exit 0

elif [ "$1" == "VALID" ]; then

	#: Section	: VALID
	#: Parameter	: file path
	#: Response	: VALID OK
	#: 		: VALID IGNORE
	#: Description	: Check file name compliance

	echo "VALID OK"
	exit 0

elif [ "$1" == "VERIFY" ]; then

	#: Section	: VERIFY
	#: Parameter	: file path
	#: Response	: VERIFY OK
	#: 		: VERIFY WAIT
	#: 		: VERIFY FATAL
	#: Description	: Check file compliance to fits format

	file=$2

	echo "VERIFY OK"
	exit 0

elif [ "$1" == "PREPROCESS" ]; then

	#: Section	: PREPROCESS
	#: Parameter	: file path
	#: 		: ingestion result [OK, WAIT, FATAL]
	#: Response	: PREPROCESS OK
	#: 		: PREPROCESS FATAL
	#: Description	: Apply preprocessing before ingestion

	file=$2
	verified=$3

	#Check verified parameter value
	if [ "$verified" != "OK" -a "$verified" != "WAIT" -a "$verified" != "FATAL" ]; then
		echo "PREPROCESS FATAL"
		exit 0
	fi

	echo "PREPROCESS OK"
	exit 0

elif [ "$1" == "POSTPROCESS" ]; then

	#: Section	: POSTPROCESS
	#: Parameter	: file path
	#: 		: ingestion result [OK, WAIT, FATAL]
	#: Response	: POSTPROCESS OK
	#: 		: POSTPROCESS FATAL
	#: Description	: Apply postprocessing after ingestion

	file=$2
	verified=$3

	#Check verified parameter value
	if [ "$verified" != "OK" -a "$verified" != "WAIT" -a "$verified" != "FATAL" ]; then
		echo "POSTPROCESS FATAL"
		exit 0
	fi

	#Post process verified WAIT files
	#if [ "$verified" == "WAIT" ]; then

	#fi

	#Post process verified FATAL files
	#if [ "$verified" == "FATAL" ]; then

	#fi

	echo "POSTPROCESS OK"
	exit 0

else

	#: Section	: DEFAULT
	#: Parameter	: none
	#: Response	: UNKNOWN

	echo "UNKNOWN"
	exit 0

fi
+28 −13
Original line number Diff line number Diff line
@@ -21,12 +21,14 @@ private:
//------------------------------------------------------------------------------
//	[Private] Constructor destructor deleter
//------------------------------------------------------------------------------
	Configuration(std::string watchPath, std::string destPath,
        std::string scriptPath, int workerNumber, int sleepTime, int waitTime,
        uint32_t iNotifyMask) : m_watchPath(watchPath), m_destPath(destPath),
	Configuration(std::string watchPath, std::string regularPath,
		std::string warningPath, std::string errorPath, std::string scriptPath,
		int workerNumber, int sleepTime, int waitTime, uint32_t iNotifyMask,
        bool ignoreTimeout) : m_watchPath(watchPath), m_regularPath(regularPath),
        m_warningPath(warningPath), m_errorPath(errorPath),
        m_scriptPath(scriptPath), m_workerNumber(workerNumber),
        m_sleepTime(sleepTime), m_waitTime(waitTime),
        m_iNotifyMask(iNotifyMask) { }
        m_iNotifyMask(iNotifyMask), m_ignoreTimeout(ignoreTimeout) { }

	virtual ~Configuration() {}

@@ -42,24 +44,28 @@ public:
//------------------------------------------------------------------------------
//	[Public] User methods
//------------------------------------------------------------------------------
	static Configuration::SP create(std::string watchPath, std::string destPath,
	static Configuration::SP create(std::string watchPath,
		std::string regularPath, std::string warningPath, std::string errorPath,
        std::string scriptPath, int workerNumber, int sleepTime, int waitTime,
        uint32_t iNotifyMask)
        uint32_t iNotifyMask, bool ignoreTimeout)
	{
		Configuration::SP c_sp(new Configuration(watchPath, destPath, scriptPath,
             workerNumber, sleepTime, waitTime, iNotifyMask),
             Configuration::Deleter());
		Configuration::SP c_sp(new Configuration(watchPath, regularPath,
			warningPath, errorPath, scriptPath, workerNumber, sleepTime,
			waitTime, iNotifyMask, ignoreTimeout), Configuration::Deleter());

		return c_sp;
	}

	std::string getWatchPath() const { return m_watchPath; }
    std::string getDestPath() const { return m_destPath; }
	std::string getRegularPath() const { return m_regularPath; }
	std::string getWarningPath() const { return m_warningPath; }
	std::string getErrorPath() const { return m_errorPath; }
    std::string getScriptPath() const { return m_scriptPath; }
	unsigned int getWorkerNumber() const { return m_workerNumber; }
    unsigned int getSleepTime() const { return m_sleepTime; }
	unsigned int getWaitTime() const { return m_waitTime; }
	uint32_t getINotifyMask() const { return m_iNotifyMask; }
	bool getIgnoreTimeout() const { return m_ignoreTimeout; }

private:
//------------------------------------------------------------------------------
@@ -68,8 +74,14 @@ private:
	//INotify watch path
	const std::string m_watchPath;

    //File destination path
    const std::string m_destPath;
    //Regular file destination path
    const std::string m_regularPath;

	//Warning file destination path
	const std::string m_warningPath;

	//Error file destination path
	const std::string m_errorPath;

    //Script path file
    const std::string m_scriptPath;
@@ -85,6 +97,9 @@ private:

	//INotify mask
	const uint32_t m_iNotifyMask;

	//Ignore timeout
	const bool m_ignoreTimeout;
};

}   //End of namespace
+0 −14
Original line number Diff line number Diff line
@@ -173,20 +173,6 @@ void EventThread::initEventBuffer() throw(std::runtime_error)
    if(!boost::filesystem::is_directory(path))
        throw std::runtime_error("Watch path \"" +
            watchPath + "\" is not a valid directory");

    /*
    //All files in watch path are inserted into event buffer
    boost::filesystem::directory_iterator startIt(path);
    boost::filesystem::directory_iterator endIt;

    while(startIt != endIt)
    {
        if(boost::filesystem::is_regular_file(startIt->status()))
            m_eventBuffer_sp->insertNew(startIt->path());

        startIt++;
    }
    */
}

//==============================================================================
+127 −41
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@
//================================================================
//  Attributes managed are:
//================================================================
//  IgnoredFileCounter  |  Tango::DevULong	Scalar
//  RegularFileCounter  |  Tango::DevULong	Scalar
//  WarningFileCounter  |  Tango::DevULong	Scalar
//  ErrorFileCounter    |  Tango::DevULong	Scalar
@@ -126,6 +127,7 @@ void PreProcessor::delete_device()
	//	Delete device allocated objects

	/*----- PROTECTED REGION END -----*/	//	PreProcessor::delete_device
	delete[] attr_IgnoredFileCounter_read;
	delete[] attr_RegularFileCounter_read;
	delete[] attr_WarningFileCounter_read;
	delete[] attr_ErrorFileCounter_read;
@@ -151,12 +153,16 @@ void PreProcessor::init_device()
	//	Get the device properties from database
	get_device_property();

	attr_IgnoredFileCounter_read = new Tango::DevULong[1];
	attr_RegularFileCounter_read = new Tango::DevULong[1];
	attr_WarningFileCounter_read = new Tango::DevULong[1];
	attr_ErrorFileCounter_read = new Tango::DevULong[1];

	/*----- PROTECTED REGION ID(PreProcessor::init_device) ENABLED START -----*/

	//Initialize ignored file counters to zero
	*attr_IgnoredFileCounter_read = 0;

    //Initialize regular file counters to zero
	*attr_RegularFileCounter_read = 0;

@@ -215,14 +221,18 @@ void PreProcessor::get_device_property()
	//	Read device properties from database.
	Tango::DbData	dev_prop;
	dev_prop.push_back(Tango::DbDatum("WatchPath"));
	dev_prop.push_back(Tango::DbDatum("DestPath"));
	dev_prop.push_back(Tango::DbDatum("RegularPath"));
	dev_prop.push_back(Tango::DbDatum("WarningPath"));
	dev_prop.push_back(Tango::DbDatum("ErrorPath"));
	dev_prop.push_back(Tango::DbDatum("ScriptPath"));
	dev_prop.push_back(Tango::DbDatum("EventList"));
	dev_prop.push_back(Tango::DbDatum("SleepTime"));
	dev_prop.push_back(Tango::DbDatum("WaitTime"));
	dev_prop.push_back(Tango::DbDatum("WorkerNumber"));
	dev_prop.push_back(Tango::DbDatum("IgnoreTimeout"));
	dev_prop.push_back(Tango::DbDatum("AutoStart"));


	//	is there at least one property to be read ?
	if (dev_prop.size()>0)
	{
@@ -247,16 +257,38 @@ void PreProcessor::get_device_property()
		//	And try to extract WatchPath value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  watchPath;

		//	Try to initialize DestPath from class property
		//	Try to initialize RegularPath from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  regularPath;
		else {
			//	Try to initialize RegularPath from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  regularPath;
		}
		//	And try to extract RegularPath value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  regularPath;

		//	Try to initialize WarningPath from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  warningPath;
		else {
			//	Try to initialize WarningPath from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  warningPath;
		}
		//	And try to extract WarningPath value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  warningPath;

		//	Try to initialize ErrorPath from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  destPath;
		if (cl_prop.is_empty()==false)	cl_prop  >>  errorPath;
		else {
			//	Try to initialize DestPath from default device value
			//	Try to initialize ErrorPath from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  destPath;
			if (def_prop.is_empty()==false)	def_prop  >>  errorPath;
		}
		//	And try to extract DestPath value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  destPath;
		//	And try to extract ErrorPath value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  errorPath;

		//	Try to initialize ScriptPath from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
@@ -313,6 +345,17 @@ void PreProcessor::get_device_property()
		//	And try to extract WorkerNumber value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  workerNumber;

		//	Try to initialize IgnoreTimeout from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  ignoreTimeout;
		else {
			//	Try to initialize IgnoreTimeout from default device value
			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
			if (def_prop.is_empty()==false)	def_prop  >>  ignoreTimeout;
		}
		//	And try to extract IgnoreTimeout value from database
		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  ignoreTimeout;

		//	Try to initialize AutoStart from class property
		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
		if (cl_prop.is_empty()==false)	cl_prop  >>  autoStart;
@@ -335,10 +378,16 @@ void PreProcessor::get_device_property()

        checkIfDirectoryExists(watchPath);

        if(destPath.empty())
            throw(invalid_argument("DestPath property is empty or not defined"));
		if(regularPath.empty())
            throw(invalid_argument("Regular property is empty or not defined"));

		checkIfDirectoryExists(regularPath);

        checkIfDirectoryExists(destPath);
		if(!warningPath.empty())
			checkIfDirectoryExists(warningPath);

		if(!errorPath.empty())
			checkIfDirectoryExists(errorPath);

        if(scriptPath.empty())
            throw(invalid_argument("ScriptPath property is empty or not defined"));
@@ -368,8 +417,8 @@ void PreProcessor::get_device_property()
        if(workerNumber<1 || workerNumber>MAX_WORKER_NUMBER)
            throw(invalid_argument("WorkerNumber property out of range or not defined"));

        m_configuration_sp = Configuration::create(watchPath, destPath, scriptPath,
            workerNumber, sleepTime, waitTime, inotifyMask);
        m_configuration_sp = Configuration::create(watchPath, regularPath, warningPath,
			errorPath, scriptPath, workerNumber, sleepTime, waitTime, inotifyMask, ignoreTimeout);
    }
    catch(invalid_argument& ex)
    {
@@ -390,7 +439,7 @@ void PreProcessor::get_device_property()
//--------------------------------------------------------
void PreProcessor::always_executed_hook()
{
	DEBUG_STREAM << "PreProcessor::always_executed_hook()  " << device_name << endl;
	INFO_STREAM << "PreProcessor::always_executed_hook()  " << device_name << endl;
	/*----- PROTECTED REGION ID(PreProcessor::always_executed_hook) ENABLED START -----*/

	if(get_state() != Tango::FAULT)
@@ -422,6 +471,26 @@ void PreProcessor::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list))
	/*----- PROTECTED REGION END -----*/	//	PreProcessor::read_attr_hardware
}

//--------------------------------------------------------
/**
 *	Read attribute IgnoredFileCounter related method
 *	Description:
 *
 *	Data type:	Tango::DevULong
 *	Attr type:	Scalar
 */
//--------------------------------------------------------
void PreProcessor::read_IgnoredFileCounter(Tango::Attribute &attr)
{
	DEBUG_STREAM << "PreProcessor::read_IgnoredFileCounter(Tango::Attribute &attr) entering... " << endl;
	/*----- PROTECTED REGION ID(PreProcessor::read_IgnoredFileCounter) ENABLED START -----*/

	boost::mutex::scoped_lock ignoredCounterLock(m_ignoredCounterMutex);

	attr.set_value(attr_IgnoredFileCounter_read);

	/*----- PROTECTED REGION END -----*/	//	PreProcessor::read_IgnoredFileCounter
}
//--------------------------------------------------------
/**
 *	Read attribute RegularFileCounter related method
@@ -578,6 +647,11 @@ void PreProcessor::reset_counter()
	DEBUG_STREAM << "PreProcessor::ResetCounter()  - " << device_name << endl;
	/*----- PROTECTED REGION ID(PreProcessor::reset_counter) ENABLED START -----*/

	//Reset ignored file counter
	boost::mutex::scoped_lock ignoredCounterLock(m_ignoredCounterMutex);

	*attr_IgnoredFileCounter_read = 0;

    //Reset regular file counter
    boost::mutex::scoped_lock regularCounterLock(m_regularCounterMutex);

@@ -596,6 +670,20 @@ void PreProcessor::reset_counter()
	/*----- PROTECTED REGION END -----*/	//	PreProcessor::reset_counter
}

/*----- PROTECTED REGION ID(PreProcessor::namespace_ending) ENABLED START -----*/

//==============================================================================
//     PreProcessor::incrementRegularCounter()
//==============================================================================
void PreProcessor::incrementIgnoredCounter()
{
	DEBUG_STREAM << "PreProcessor::incrementIgnoredCounter()  - " << device_name << endl;

	boost::mutex::scoped_lock ignoredCounterLock(m_ignoredCounterMutex);

	++*attr_IgnoredFileCounter_read;
}

//==============================================================================
//     PreProcessor::incrementRegularCounter()
//==============================================================================
@@ -632,8 +720,6 @@ void PreProcessor::incrementErrorCounter()
		++*attr_ErrorFileCounter_read;
}

/*----- PROTECTED REGION ID(PreProcessor::namespace_ending) ENABLED START -----*/

//==============================================================================
//	PreProcessor::create_inotify_mask()
//==============================================================================
Loading