diff --git a/castor/tape/python/Constants.hpp b/castor/tape/python/Constants.hpp deleted file mode 100644 index e9cbd4055df3a2f5cb1de3388636d344bd8d486a..0000000000000000000000000000000000000000 --- a/castor/tape/python/Constants.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************** - * castor/tape/python/Constants.hpp - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * 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. - * - * - * - * @author Giulia Taurelli - *****************************************************************************/ - -#ifndef CASTOR_TAPE_PYTHON_CONSTANTS_HPP -#define CASTOR_TAPE_PYTHON_CONSTANTS_HPP 1 - -namespace castor { -namespace tape { -namespace python { - -/** - * The directory that contains the CASTOR policies implemented as Python - * modules. - */ -const char *const CASTOR_POLICIES_DIRECTORY = "/etc/castor/policies"; - -} // namespace python -} // namespace tape -} // namespace castor - -#endif // CASTOR_TAPE_PYTHON_CONSTANTS_HPP diff --git a/castor/tape/python/Imakefile b/castor/tape/python/Imakefile deleted file mode 100644 index 59e366fb06fd51a86b47de1abf8849baa56e3fd9..0000000000000000000000000000000000000000 --- a/castor/tape/python/Imakefile +++ /dev/null @@ -1,37 +0,0 @@ -COMM -COMM castor/tape/python/Imakefile -COMM -COMM This file is part of the Castor project. -COMM See http://castor.web.cern.ch/castor -COMM -COMM Copyright (C) 2003 CERN -COMM This program is free software; you can redistribute it and/or -COMM modify it under the terms of the GNU General Public License -COMM as published by the Free Software Foundation; either version 2 -COMM of the License, or (at your option) any later version. -COMM This program is distributed in the hope that it will be useful, -COMM but WITHOUT ANY WARRANTY; without even the implied warranty of -COMM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -COMM GNU General Public License for more details. -COMM You should have received a copy of the GNU General Public License -COMM along with this program; if not, write to the Free Software -COMM Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -COMM -COMM -COMM @author Giulia Taurelli -COMM - -CPPFLAGS += $(PYTHON_INC) -AddLdFlags($(PYTHON_LIBS) -lstdc++) - -TAPEPYTHONLIB_SRCS = \ - python.cpp \ - ScopedPythonLock.cpp \ - SmartPyObjectPtr.cpp - -TAPEPYTHONLIB_OBJS = $(TAPEPYTHONLIB_SRCS:.cpp=.o) - -DependsOnLibrary(common,castorcommon) -DependsOnLibrary(castor,castorclient) -DependsOnLibrary(castor/tape/utils,castortapeutils) -SharedLibraryTarget(castortapepython,$(TAPEPYTHONLIB_OBJS),,) diff --git a/castor/tape/python/ScopedPythonLock.cpp b/castor/tape/python/ScopedPythonLock.cpp deleted file mode 100644 index ec3c2165461662e8eccc4499ed7d8a512698e187..0000000000000000000000000000000000000000 --- a/castor/tape/python/ScopedPythonLock.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * castor/tape/python/ScopedPythonLock.cpp - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * 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. - * - * - * - * @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch - *****************************************************************************/ - -// Include Python.h before any standard headers because Python.h may define -// some pre-processor definitions which affect the standard headers -#include <Python.h> - -#include "castor/tape/python/ScopedPythonLock.hpp" - - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::tape::python::ScopedPythonLock::ScopedPythonLock() throw() : - m_gstate(PyGILState_Ensure()) { -} - - -//----------------------------------------------------------------------------- -// destructor -//----------------------------------------------------------------------------- -castor::tape::python::ScopedPythonLock::~ScopedPythonLock() throw() { - - PyGILState_Release(m_gstate); -} - diff --git a/castor/tape/python/ScopedPythonLock.hpp b/castor/tape/python/ScopedPythonLock.hpp deleted file mode 100644 index 4d96ce75860f40b3fd7431b385ebab10a8d32f1f..0000000000000000000000000000000000000000 --- a/castor/tape/python/ScopedPythonLock.hpp +++ /dev/null @@ -1,78 +0,0 @@ -/****************************************************************************** - * castor/tape/python/ScopedPythonLock.hpp - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * 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. - * - * - * - * @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch - *****************************************************************************/ - -#ifndef CASTOR_TAPE_PYTHON_SCOPEPYTHONLOCK_HPP -#define CASTOR_TAPE_PYTHON_SCOPEPYTHONLOCK_HPP 1 - -// Include Python.h before any standard headers because Python.h may define -// some pre-processor definitions which affect the standard headers -#include <Python.h> - - -namespace castor { -namespace tape { -namespace python { - -/** - * As scoped lock which calls PyCGILState_Ensure() and PyGILState_Release() - * in order to ensure the current thread is ready to call the Python C API - * regardless of the current state of the embedded Python interpreter, or the - * state of the global interpreter lock. - */ -class ScopedPythonLock { - -public: - - /** - * Constructor that immediately calls PyCGILState_Ensure() to ensure the - * current thread is ready to call the Python C API regardless of the current - * state of the embedded Python interpreter, or the state of the global - * interpreter lock. - */ - ScopedPythonLock() throw(); - - /** - * Destructor that calls PyCGILState_Release() to release the embedded Python - * interpreter from the current thread and to return the interpreter to the - * state it was in prior to the execution of this scoped lock's constructor. - */ - ~ScopedPythonLock() throw(); - - -private: - - /** - * Opaque handle to the bookkeeping information kept by Python about the - * thread taking a lock on the embedded Python interpreter. - */ - const PyGILState_STATE m_gstate; - -}; // class ScopedPythonLock - -} // namespace python -} // namespace tape -} // namespace castor - - -#endif // CASTOR_TAPE_PYTHON_SCOPEPYTHONLOCK_HPP diff --git a/castor/tape/python/SmartPyObjectPtr.cpp b/castor/tape/python/SmartPyObjectPtr.cpp deleted file mode 100644 index 47a90ae781d74c2cf5c11e4e1540a9c31f130438..0000000000000000000000000000000000000000 --- a/castor/tape/python/SmartPyObjectPtr.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/****************************************************************************** - * castor/tape/python/SmartPyObject.cpp - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * 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. - * - * - * - * @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch - *****************************************************************************/ - -// Include Python.h before any standard headers because Python.h may define -// some pre-processor definitions which affect the standard headers -#include <Python.h> - -#include "castor/tape/python/SmartPyObjectPtr.hpp" - - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::tape::python::SmartPyObjectPtr::SmartPyObjectPtr() throw() : - m_pyObject(NULL) { -} - - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::tape::python::SmartPyObjectPtr::SmartPyObjectPtr( - PyObject *const pyObject) throw() : m_pyObject(pyObject) { -} - - -//----------------------------------------------------------------------------- -// reset -//----------------------------------------------------------------------------- -void castor::tape::python::SmartPyObjectPtr::reset( - PyObject *const pyObject = NULL) throw() { - - // If the new pointer is not the one already owned - if(pyObject != m_pyObject) { - - // If this smart pointer still owns a pointer, then call Py_XDECREF() on it - if(m_pyObject != NULL) { - Py_XDECREF(m_pyObject); - } - - // Take ownership of the new pointer - m_pyObject = pyObject; - } -} - - -//----------------------------------------------------------------------------- -// SmartPyObjectPtr assignment operator -//----------------------------------------------------------------------------- -castor::tape::python::SmartPyObjectPtr - &castor::tape::python::SmartPyObjectPtr::operator=(SmartPyObjectPtr& obj) - throw() { - - reset(obj.release()); - - return *this; -} - - -//----------------------------------------------------------------------------- -// destructor -//----------------------------------------------------------------------------- -castor::tape::python::SmartPyObjectPtr::~SmartPyObjectPtr() { - - reset(); -} - - -//----------------------------------------------------------------------------- -// get -//----------------------------------------------------------------------------- -PyObject *castor::tape::python::SmartPyObjectPtr::get() const throw() { - - return m_pyObject; -} - - -//----------------------------------------------------------------------------- -// release -//----------------------------------------------------------------------------- -PyObject *castor::tape::python::SmartPyObjectPtr::release() - throw(castor::exception::Exception) { - - // If this smart pointer does not own a pointer - if(m_pyObject == NULL) { - castor::exception::Exception ex(EPERM); - - ex.getMessage() << - "Smart pointer does not own a PyObject pointer"; - - throw(ex); - } - - - PyObject *const tmp = m_pyObject; - - // A NULL value indicates this smart pointer does not own a pointer - m_pyObject = NULL; - - return tmp; -} diff --git a/castor/tape/python/SmartPyObjectPtr.hpp b/castor/tape/python/SmartPyObjectPtr.hpp deleted file mode 100644 index e5816974fec32c8b783327966f0abd7afabece4d..0000000000000000000000000000000000000000 --- a/castor/tape/python/SmartPyObjectPtr.hpp +++ /dev/null @@ -1,120 +0,0 @@ -/****************************************************************************** - * castor/rtcopy/mighunter/SmartPyObject.hpp - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * 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. - * - * - * - * @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch - *****************************************************************************/ - -#ifndef CASTOR_TAPE_PYTHON_SMARTPYOBJECTPTR_HPP -#define CASTOR_TAPE_PYTHON_SMARTPYOBJECTPTR_HPP 1 - -// Include Python.h before any standard headers because Python.h may define -// some pre-processor definitions which affect the standard headers -#include <Python.h> - -#include "castor/exception/Exception.hpp" - -namespace castor { -namespace tape { -namespace python { - -/** - * A smart PyObject pointer that owns a PyObject pointer. When the smart - * pointer goes out of scope, it will call Py_XDECREF() on the PyObject - * pointer. - */ -class SmartPyObjectPtr { -public: - - /** - * Constructor. - * - */ - SmartPyObjectPtr() throw(); - - /** - * Constructor. - * - * @param pyObject The PyObject pointer to be owned by the smart pointer. - */ - SmartPyObjectPtr(PyObject *const pyObject) throw(); - - /** - * Take ownership of the specified PyObject pointer, calling Py_XDECREF() on - * the previously owned pointer if there is one and it is not the same as the - * one specified. - * - * @param pyObject The PyObject pointer to be owned, defaults to NULL if not - * specified, where NULL means this SmartPyObjectPtr will not - * own a pointer after the reset() method returns. - */ - void reset(PyObject *const pyObject) throw(); - - /** - * SmartPyObjectPtr assignment operator. - * - * This function does the following: - * <ul> - * <li> Calls release on the previous owner (obj); - * <li> Calls Py_XDECREF() on the PyObject pointer of this object if it - * already owns one. - * <li> Makes this object the owner of the PyObject pointer released from the - * previous owner (obj). - * </ul> - */ - SmartPyObjectPtr &operator=(SmartPyObjectPtr& obj) throw(); - - /** - * Destructor. - * - * Calls Py_XDECREF() on the owned PyObject pointer if there is one. - */ - ~SmartPyObjectPtr(); - - /** - * Returns the owned pointer or NULL if this smart pointer does not own one. - * - * @return The owned FILE pointer. - */ - PyObject *get() const throw(); - - /** - * Releases the owned pointer. - * - * @return The released pointer. - */ - PyObject *release() throw(castor::exception::Exception); - -private: - - /** - * The owned pointer. A value of NULL means this smart pointer does not own - * a pointer. - */ - PyObject *m_pyObject; - -}; // class SmartPyObjectPtr - -} // namespace python -} // namespace tape -} // namespace castor - - -#endif // CASTOR_TAPE_PYTHON_SMARTPYOBJECTPTR_HPP diff --git a/castor/tape/python/python.cpp b/castor/tape/python/python.cpp deleted file mode 100644 index 688c130ae7200fb71643bfad253c0ca6c46b89fb..0000000000000000000000000000000000000000 --- a/castor/tape/python/python.cpp +++ /dev/null @@ -1,629 +0,0 @@ -/****************************************************************************** - * castor/tape/python/python.cpp - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * 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. - * - * - * @author Giulia Taurelli, Nicola Bessone and Steven Murray - *****************************************************************************/ - -// Include python.hpp before any standard headers because python.hpp includes -// Python.h which may define some pre-processor definitions which affect the -// standard headers -#include "castor/tape/python/python.hpp" - -#include "castor/tape/python/Constants.hpp" -#include "castor/tape/python/ScopedPythonLock.hpp" -#include "castor/tape/python/SmartPyObjectPtr.hpp" -#include "castor/tape/utils/utils.hpp" -#include "h/serrno.h" - -#include <errno.h> -#include <pthread.h> -#include <unistd.h> - - -//--------------------------------------------------------------------------- -// initializePython -//--------------------------------------------------------------------------- -void castor::tape::python::initializePython() - throw(castor::exception::Exception) { - - // Append the CASTOR policies directory to the end of the PYTHONPATH - // environment variable so the PyImport_ImportModule() function can find the - // stream and migration policy modules - { - const std::string envVarName("PYTHONPATH"); - const std::string pathToBeAppended(CASTOR_POLICIES_DIRECTORY); - utils::appendPathToEnvVar(envVarName, pathToBeAppended); - } - - // Initialize Python throwing an exception if a Python error occurs - Py_Initialize(); - if(PyErr_Occurred()) { - castor::exception::Exception ex(ECANCELED); - - ex.getMessage() << - "Py_Initialize() call failed" - ": A Python error occured"; - - throw ex; - } - - // Initialize thread support - // - // Please note that PyEval_InitThreads() takes a lock on the global Python - // interpreter - PyEval_InitThreads(); - if(PyErr_Occurred()) { - castor::exception::Exception ex(ECANCELED); - - ex.getMessage() << - "PyEval_InitThreads() call failed" - ": A Python error occured"; - - throw ex; - } - - // Release the lock on the Python global interpreter that was taken by the - // preceding PyEval_InitThreads() call - PyEval_ReleaseLock(); - if(PyErr_Occurred()) { - castor::exception::Exception ex(ECANCELED); - - ex.getMessage() << - "PyEval_ReleaseLock() call failed" - ": A Python error occured"; - - throw ex; - } -} - - -//--------------------------------------------------------------------------- -// finalizePython -//--------------------------------------------------------------------------- -void castor::tape::python::finalizePython() - throw() { - - // Get a lock on the global embedded Python interpreter using - // PyGILState_Ensure() so that the Py_Finalize() function which will be - // called next, can internally get a hold of the current thread's state via - // PyThreadState_Get(). A ScopedPythonLock object cannot be used because its - // destructor would call the PyGILState_Release() function which would fail - // because it would be called after the Py_Finalize() function. - PyGILState_Ensure(); - - // Finalize the embedded Python interpreter - Py_Finalize(); -} - - -//--------------------------------------------------------------------------- -// importPythonModule -//--------------------------------------------------------------------------- -PyObject * castor::tape::python::importPythonModule( - const char *const moduleName) - throw(castor::exception::Exception) { - - if(moduleName == NULL) { - TAPE_THROW_EX(castor::exception::InvalidArgument, - ": Failed to import python-module" - ": moduleName parameter is NULL"); - } - - castor::tape::python::SmartPyObjectPtr - module(PyImport_ImportModule((char *)moduleName)); - - if(module.get() == NULL) { - // Try to determine the Python exception if there was a Python error - PyObject *const pyEx = PyErr_Occurred(); - const char *pyExStr = python::stdPythonExceptionToStr(pyEx); - - // Clear the Python error if there was one - if(pyEx != NULL) { - PyErr_Clear(); - } - - castor::exception::Exception ex(ECANCELED); - - ex.getMessage() << - "Failed to import python-module" - ": PyImport_ImportModule() call failed" - ": moduleName=" << moduleName << - ", pythonException=" << pyExStr; - - throw(ex); - } - - PyObject *const dict = PyModule_GetDict(module.get()); - - if(dict == NULL) { - castor::exception::Exception ex(ECANCELED); - - ex.getMessage() << - "Failed to import python-module" - ": moduleName=" << moduleName << - "PyModule_GetDict() call failed"; - - throw(ex); - } - - return(dict); -} - - -//--------------------------------------------------------------------------- -// importPythonModuleWithLock -//--------------------------------------------------------------------------- -PyObject * castor::tape::python::importPythonModuleWithLock( - const char *const moduleName) - throw(castor::exception::Exception) { - // Get a lock on the embedded Python-interpreter - ScopedPythonLock scopedLock; - - return(importPythonModule(moduleName)); -} - - -//--------------------------------------------------------------------------- -// importPolicyPythonModule -//--------------------------------------------------------------------------- -PyObject * castor::tape::python::importPolicyPythonModule( - const char *const moduleName) - throw(castor::exception::Exception) { - - if(moduleName == NULL) { - TAPE_THROW_EX(castor::exception::InvalidArgument, - ": Failed to import policy python-module" - ": moduleName parameter is NULL"); - } - - // Check the module file exists in the CASTOR_POLICIES_DIRECTORY as it is - // difficult to obtain errors from the embedded Python interpreter - checkPolicyModuleIsInCastorPoliciesDirectory(moduleName); - - return importPythonModule(moduleName); -} - - -//--------------------------------------------------------------------------- -// checkPolicyModuleIsInCastorPoliciesDirectory -//--------------------------------------------------------------------------- -void castor::tape::python::checkPolicyModuleIsInCastorPoliciesDirectory( - const char *const moduleName) - throw(castor::exception::Exception) { - std::string fullPathname(CASTOR_POLICIES_DIRECTORY); - - fullPathname += "/"; - fullPathname += moduleName; - fullPathname += ".py"; - - struct stat buf; - try { - utils::statFile(fullPathname.c_str(), buf); - } catch(castor::exception::Exception &ex) { - castor::exception::Exception ex2(ex.code()); - - ex2.getMessage() << - "Failed to import policy python-module" - ": moduleName=" << moduleName << - ": Failed to get information about the CASTOR-policy Python-module file" - ": " << ex.getMessage().str(); - - throw(ex2); - } - - // Throw an exception if the module file is not a regular file - if(!S_ISREG(buf.st_mode)) { - castor::exception::Exception ex(ECANCELED); - - ex.getMessage() << - "Failed to import policy python-module" - ": moduleName=" << moduleName << - ": " << fullPathname << " is not a regular file"; - - throw(ex); - } -} - - -//--------------------------------------------------------------------------- -// importPolicyPythonModuleWithLock -//--------------------------------------------------------------------------- -PyObject * castor::tape::python::importPolicyPythonModuleWithLock( - const char *const moduleName) - throw(castor::exception::Exception) { - if(moduleName == NULL) { - TAPE_THROW_EX(castor::exception::InvalidArgument, - ": Failed to import policy python-module" - ": moduleName parameter is NULL"); - } - - // Check the module file exists in the CASTOR_POLICIES_DIRECTORY as it is - // difficult to obtain errors from the embedded Python interpreter - checkPolicyModuleIsInCastorPoliciesDirectory(moduleName); - - return importPythonModuleWithLock(moduleName); -} - - -//--------------------------------------------------------------------------- -// getPythonFunction -//--------------------------------------------------------------------------- -PyObject *castor::tape::python::getPythonFunction( - PyObject *const pyDict, - const char *const functionName) - throw(castor::exception::Exception) { - - if(pyDict == NULL) { - TAPE_THROW_EX(castor::exception::InvalidArgument, - ": pyDict parameter is NULL"); - } - - if(functionName == NULL) { - TAPE_THROW_EX(castor::exception::InvalidArgument, - ": functionName parameter is NULL"); - } - - // Get a pointer to the Python-function object - PyObject *pyFunc = PyDict_GetItemString(pyDict, functionName); - - // Throw an exception if the Python-function object was not found due to a - // Python error occurring as opposed to function simply not being in the - // dictionary - if(pyFunc == NULL && PyErr_Occurred()) { - castor::exception::Exception ex(ECANCELED); - - ex.getMessage() << - "PyDict_GetItemString() call failed" - ": functionName=" << functionName << - ": A Python error occured"; - - throw ex; - } - - // Throw an exception if a non-callable object was found with the same name - // as the function - if(pyFunc != NULL && !PyCallable_Check(pyFunc)) { - castor::exception::InvalidArgument ex; - - ex.getMessage() << - "Found non-callable Python object" - ": functionName=" << functionName; - - throw ex; - } - - return pyFunc; -} - - -//--------------------------------------------------------------------------- -// getPythonFunctionWithLock -//--------------------------------------------------------------------------- -PyObject *castor::tape::python::getPythonFunctionWithLock( - PyObject *const pyDict, - const char *const functionName) - throw(castor::exception::Exception) { - // Get a lock on the embedded Python-interpreter - ScopedPythonLock scopedLock; - - return(getPythonFunction(pyDict, functionName)); -} - - -//--------------------------------------------------------------------------- -// pythonExceptionToStr -//--------------------------------------------------------------------------- -const char *castor::tape::python::stdPythonExceptionToStr( - PyObject *const pyEx) - throw() { - - if(pyEx == NULL) { - return "NULL"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_AssertionError)) { - return "AssertionError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_AttributeError)) { - return "AttributeError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_EOFError)) { - return "EOFError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_FloatingPointError)) { - return "FloatingPointError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_IOError)) { - return "IOError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_ImportError)) { - return "ImportError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_IndexError)) { - return "IndexError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_KeyError)) { - return "KeyError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_KeyboardInterrupt)) { - return "KeyboardInterrupt"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_MemoryError)) { - return "MemoryError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_NameError)) { - return "NameError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_NotImplementedError)) { - return "NotImplementedError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_OSError)) { - return "OSError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_OverflowError)) { - return "OverflowError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_ReferenceError)) { - return "ReferenceError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_RuntimeError)) { - return "RuntimeError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_SyntaxError)) { - return "SyntaxError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_SystemError)) { - return "SystemError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_SystemExit)) { - return "SystemExit"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_TypeError)) { - return "TypeError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_ValueError)) { - return "ValueError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_ZeroDivisionError)) { - return "ZeroDivisionError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_StandardError)) { - return "StandardError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_ArithmeticError)) { - return "ArithmeticError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_LookupError)) { - return "LookupError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_EnvironmentError)) { - return "EnvironmentError"; - } else if(PyErr_GivenExceptionMatches(pyEx, PyExc_Exception)) { - return "Exception"; - } else { - return "UNKNOWN"; - } -} - - -//--------------------------------------------------------------------------- -// getPythonFunctionArgumentNames -//--------------------------------------------------------------------------- -void castor::tape::python::getPythonFunctionArgumentNames( - PyObject *const inspectGetargspecFunc, - PyObject *const pyFunc, - std::vector<std::string> &argumentNames) throw(castor::exception::Exception) { - - // Build the input Python-object for the inspect.getargspec Python-function - castor::tape::python::SmartPyObjectPtr inputObj( - Py_BuildValue((char *)"(O)", pyFunc)); - - // Throw an exception if the creation of the input Python-object failed - if(inputObj.get() == NULL) { - // Try to determine the Python exception if there was a Python error - PyObject *const pyEx = PyErr_Occurred(); - const char *pyExStr = python::stdPythonExceptionToStr(pyEx); - - // Clear the Python error if there was one - if(pyEx != NULL) { - PyErr_Clear(); - } - - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Failed to create input Python-object for inspect.getargspec" - ": Call to Py_BuildValue failed" - ": pythonException=" << pyExStr; - throw(ex); - } - - // Call the inspect.getmembers method on the stream-policy Python-module - SmartPyObjectPtr resultObj(PyObject_CallObject(inspectGetargspecFunc, - inputObj.get())); - - // Throw an exception if the invocation of the Python-function failed - if(resultObj.get() == NULL) { - // Try to determine the Python exception if there was a Python error - PyObject *const pyEx = PyErr_Occurred(); - const char *pyExStr = python::stdPythonExceptionToStr(pyEx); - - // Clear the Python error if there was one - if(pyEx != NULL) { - PyErr_Clear(); - } - - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Failed to get result from Python-function" - ": moduleName=inspect" - ", functionName=getargspec" - ", pythonException=" << pyExStr; - throw(ex); - } - - // Throw an exception if the result of inspect.getargsspec is not a - // Python-sequence - if(!PySequence_Check(resultObj.get())) { - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Python-function returned unexpected result-type" - ": moduleName=inspect" - ", functionName=getargspec" - ", expectedResultType=PySequence"; - throw(ex); - } - - // Get a handle on the array of function argument names - SmartPyObjectPtr - argumentNamesPySequence(PySequence_GetItem(resultObj.get(), 0)); - - // Throw an exception if the handle cound not be obtained - if(argumentNamesPySequence.get() == NULL) { - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Failed to get a handle on the array of function argument names" - ": moduleName=inspect" - ", functionName=getargspec"; - throw(ex); - } - - // Throw an exception if the function argument names are not a - // Python-sequence - if(!PySequence_Check(argumentNamesPySequence.get())) { - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Function argument names are not of the expected Python-type" - ": expectedResultType=PySequence"; - throw(ex); - } - - const int nbArgumentNames = PySequence_Size(argumentNamesPySequence.get()); - - // Throw an exception if the number of function argument names could not be - // determined - if(nbArgumentNames == -1) { - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Failed to determine the number of function argument names" - ": Call to PySequence_Size() failed"; - throw(ex); - } - - // Push each function argument name on onto the back of the output list of - // function argument names - for(int i=0; i<nbArgumentNames; i++) { - SmartPyObjectPtr - argumentNamePyObj(PySequence_GetItem(argumentNamesPySequence.get(),i)); - - // Throw an exception if the function argument name could not be retreived - if(argumentNamePyObj.get() == NULL) { - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Failed to retreive function argument name" - ": Call to PySequence_GetItem() failed"; - throw(ex); - } - - // Throw an exception if the function argument name is not a Python-string - if(!PyString_Check(argumentNamePyObj.get())) { - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Function argument name is not a Python-string"; - throw(ex); - } - - char *const argumentName = PyString_AsString(argumentNamePyObj.get()); - - // Throw an exception if the function argument name could not be converted - // to a C string - if(argumentName == NULL) { - // Try to determine the Python exception if there was a Python error - PyObject *const pyEx = PyErr_Occurred(); - const char *pyExStr = python::stdPythonExceptionToStr(pyEx); - - // Clear the Python error if there was one - if(pyEx != NULL) { - PyErr_Clear(); - } - - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Failed to convert function argument name to a C string" - ": Call to PyString_AsString() failed" - ": pythonException=" << pyExStr; - throw(ex); - } - - argumentNames.push_back(argumentName); - } -} - - -//--------------------------------------------------------------------------- -// getPythonFunctionArgumentNamesWithLock -//--------------------------------------------------------------------------- -void castor::tape::python::getPythonFunctionArgumentNamesWithLock( - PyObject *const inspectGetargspecFunc, - PyObject *const pyFunc, - std::vector<std::string> &argumentNames) - throw(castor::exception::Exception) { - // Get a lock on the embedded Python-interpreter - ScopedPythonLock scopedPythonLock; - - getPythonFunctionArgumentNames(inspectGetargspecFunc, pyFunc, argumentNames); -} - - -//--------------------------------------------------------------------------- -// checkFuncArgNames -//--------------------------------------------------------------------------- -void castor::tape::python::checkFuncArgNames( - const std::string &funcName, - const std::vector<std::string> &expectedArgNames, - PyObject *const inspectGetargspecFunc, - PyObject *const pyFunc) - throw(castor::exception::InvalidConfiguration) { - - // Get the names of the actual arguments of the migration-policy - // Python-function - std::vector<std::string> actualArgNames; - python::getPythonFunctionArgumentNamesWithLock(inspectGetargspecFunc, pyFunc, - actualArgNames); - - // Throw an InvalidConfiguration exception if the number of parameters is - // wrong - if(actualArgNames.size() != expectedArgNames.size()) { - castor::exception::InvalidConfiguration ex; - ex.getMessage() << - "Invalid configuration" - ": Python-function has the wrong number of arguments" - ": funcName=" << funcName << - ", expectedNbParams=" << expectedArgNames.size() << - ", actualNbParams=" << actualArgNames.size() << - ", expectedParams='" << utils::vectorOfStringToString(expectedArgNames) - << "'" << - ", actualParams='" << utils::vectorOfStringToString(actualArgNames) - << "'"; - throw(ex); - } - - // Throw an InvalidConfiguration exception if one of the function argument - // names does not match what is expected - for(std::vector<std::string>::size_type i=0; - i<expectedArgNames.size(); i++) { - if(expectedArgNames[i] != actualArgNames[i]) { - castor::exception::InvalidConfiguration ex; - ex.getMessage() << - "Invalid configuration" - ": Python-function has an unexpected argument name" - ": funcName=" << funcName << - ", argumentIndex=" << i << - ", expectedName=" << expectedArgNames[i] << - ", actualName=" << actualArgNames[i] << - ", expectedParams='" << utils::vectorOfStringToString(expectedArgNames) - << "'" << - ", actualParams='" << utils::vectorOfStringToString(actualArgNames) - << "'"; - throw(ex); - } - } -} diff --git a/castor/tape/python/python.hpp b/castor/tape/python/python.hpp deleted file mode 100644 index 268e052d3664c99e56b93ba795ade43ec48eebc5..0000000000000000000000000000000000000000 --- a/castor/tape/python/python.hpp +++ /dev/null @@ -1,297 +0,0 @@ -/****************************************************************************** - * castor/tape/python/python.hpp - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * 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. - * - * - * - * @author Giulia Taurelli, Nicola Bessone and Steven Murray - *****************************************************************************/ - -#ifndef CASTOR_TAPE_PYTHON_PYTHON_HPP -#define CASTOR_TAPE_PYTHON_PYTHON_HPP - -// Include Python.h before any standard headers because Python.h may define -// some pre-processor definitions which affect the standard headers -#include <Python.h> - -#include "castor/exception/Exception.hpp" -#include "castor/exception/InvalidConfiguration.hpp" - -#include <string> -#include <vector> - -namespace castor { -namespace tape { -namespace python { - -/** - * Initializes the embedded Python interpreter for multi-threaded use and - * append the CASTOR_POLICIES_DIRECTORY to the PYTHONPATH environment - * variable. - * - * This function should be once and only once for the entire duration of the - * calling program. - * - * When this function returns there will be no lock taken on the global Python - * interpeter. All threads, including the main thread must therefore take a - * lock using a ScopedPythonLock object before acsessing the API of the - * embedded Python interpreter. - */ -void initializePython() - throw(castor::exception::Exception); - -/** - * Finalizes the embedded Python interpreter. - * - * Please note that the calling thread must NOT have a lock on the global - * Python interpreter. - */ -void finalizePython() - throw(); - -/** - * Imports the Python-module with the specified name. - * - * Please note that initPython() must be called before this function is called. - * - * Please note that the calling thread MUST have a lock on the global Python - * interpreter through a call to PyGILState_Ensure() or through the strongly - * recommended use of a ScopedPythonLock object. - * - * @param moduleName The name of the Python-module. - * @return The Python dictionary object of the imported library. The - * documentation of the embedded Python-interpreter describes - * the return value as being a "borrowed reference". This - * means the caller does not need to call Py_XDECREF when the - * dictionary is no longer required. - */ -PyObject* importPythonModule( - const char *const moduleName) - throw(castor::exception::Exception); - -/** - * Convenient wrapper method around importPythonModule() that takes a - * lock on the global Python interpreter and then calls - * importPythonModule(). The lock is released before this method - * returns. - * - * For further information please see the documentation for the - * importPythonModule() method. - * - * @param moduleName The name of the Python-module. - * @return The Python dictionary object of the imported library. The - * documentation of the embedded Python-interpreter describes - * the return value as being a "borrowed reference". This - * means the caller does not need to call Py_XDECREF when the - * dictionary is no longer required. - */ -PyObject* importPythonModuleWithLock( - const char *const moduleName) - throw(castor::exception::Exception); - -/** - * Imports a CASTOR-policy implemented as a Python module from the - * Python-module search path which includes the - * castor::tape::python::CASTOR_POLICIES_DIRECTORY directory. - * - * The CASTOR-policy must be implemented by a '*.py' file in the - * castor::tape::python::CASTOR_POLICIES_DIRECTORY directory. A '*.pyc' by - * itself will be rejected. In this sense the importPolicyPythonModule() - * function is stricter than the underlying PyImport_ImportModule() method - * which would work if only a '*.pyc' file was present. The reason for this - * enforced strictness is that CASTOR operators should be able to see in a - * human-readbale form the logic implementing a CASTOR-policy. - * - * Please note that initPython() must be called before this function is called. - * - * Please note that the calling thread MUST have a lock on the global Python - * interpreter through a call to PyGILState_Ensure() or through the strongly - * recommended use of a ScopedPythonLock object. - * - * @param moduleName The name of the CASTOR-policy Python-module. - * @return The Python dictionary object of the imported library. The - * documentation of the embedded Python-interpreter describes - * the return value as being a "borrowed reference". This - * means the caller does not need to call Py_XDECREF when the - * dictionary is no longer required. - */ -PyObject* importPolicyPythonModule( - const char *const moduleName) - throw(castor::exception::Exception); - -/** - * Checks that the module file of the specified policy Python-module exists in - * the CASTOR_POLICIES_DIRECTORY as it is difficult to obtain errors from the - * embedded Python interpreter. - * - * This method raises a castor::exception::Exception if the check fails. - */ -void checkPolicyModuleIsInCastorPoliciesDirectory( - const char *const moduleName) - throw(castor::exception::Exception); - -/** - * The same functionality as importPolicyPythonModule but with the additional - * taking and releasing of the lock on the global Python interpreter. - * - * For further information please see the documentation for the - * importPolicyPythonModule() method. - * - * @param moduleName The name of the CASTOR-policy Python-module. - * @return The Python dictionary object of the imported library. The - * documentation of the embedded Python-interpreter describes - * the return value as being a "borrowed reference". This - * means the caller does not need to call Py_XDECREF when the - * dictionary is no longer required. - */ -PyObject* importPolicyPythonModuleWithLock( - const char *const moduleName) - throw(castor::exception::Exception); - -/** - * Get the Python function object for the specified function within the - * specified Python dictionary. - * - * Please note that initPython() must be called before this function is called. - * - * Please note that the calling thread MUST have a lock on the global Python - * interpreter through a call to PyGILState_Ensure() or through the strongly - * recommended use of a ScopedPythonLock object. - * - * @param pyDict The Python dictionary in which the specified function is - * to be found. - * @param functionName The name of the Python function. - * @return The Python function object representing the specified - * function or NULL if the named function is not in the - * specified dictionary. The documentation of the embedded - * Python-interpreter describes the return value as being a - * "borrowed reference". This means the caller does not - * need to call Py_XDECREF when the function is no longer - * required. - */ -PyObject* getPythonFunction( - PyObject *const pyDict, - const char *const functionName) - throw(castor::exception::Exception); - -/** - * Convenient wrapper method around getPythonFunction() that takes a - * lock on the global Python interpreter and then calls - * getPythonFunction(). The lock is released before this method - * returns. - * - * For further information please see the documentation for the - * getPythonFunction() method. - * - * @param pyDict The Python dictionary in which the specified function is - * to be found. - * @param functionName The name of the Python function. - * @return The Python function object representing the specified - * function or NULL if the named function is not in the - * specified dictionary. The documentation of the embedded - * Python-interpreter describes the return value as being a - * "borrowed reference". This means the caller does not - * need to call Py_XDECREF when the function is no longer - * required. - */ -PyObject* getPythonFunctionWithLock( - PyObject *const pyDict, - const char *const functionName) - throw(castor::exception::Exception); - -/** - * Returns a string representation of the specified Python exception. This - * function only knows the standard Python exceptions that were documented at - * the time the function was written. - * - * If a NULL pointer is passed as the Python exception, then this function will - * return a pointer the string literal "NULL". If the specified Python - * exception is unknown, then this function will return a pointer to the string - * literal "UNKNOWN"; - * - * The caller of this function must not try to free the memory used by a - * returned string. All of the values returned by this function are pointers - * to string literals. - * - * @param pyEx Python exception or NULL if there isn't one. - * @return String representation of the specified Python exception. - */ -const char *stdPythonExceptionToStr( - PyObject *const pyDict) - throw(); - -/** - * Returns the argument names of the specified Python-function. - * - * @param inspectGetargspecFunc The inspect.getargspec Python-function. - * @param pyFunc The Python-function whose argument names will - * be returned. - * @param argumentNames The list of argument names to be filled by this - * function. - */ -void getPythonFunctionArgumentNames( - PyObject *const inspectGetargspecFunc, - PyObject *const pyFunc, - std::vector<std::string> &argumentNames) - throw(castor::exception::Exception); - -/** - * Convenient wrapper method around getPythonFunctionArgumentNames that takes a - * lock on the global Python interpreter and then calls - * getPythonFunctionArgumentNames(). The lock is released before this method - * returns. - * - * For further information please see the documentation for the - * getPythonFunctionArgumentNames() method. - * - * @param inspectGetargspecFunc The inspect.getargspec Python-function. - * @param pyFunc The Python-function whose argument names will - * be returned. - * @param argumentNames The list of argument names to be filled by this - * function. - */ -void getPythonFunctionArgumentNamesWithLock( - PyObject *const inspectGetargspecFunc, - PyObject *const pyFunc, - std::vector<std::string> &argumentNames) - throw(castor::exception::Exception); - -/** - * Checks whether or not the specified Python-function has the specified - * argument names. - * - * This method raises an InvalidConfiguration exception if the specified - * Python-function does not have the correct argument-names. - * - * @param funcName Input: The name of the Python-function. - * @param expectedArgNames Input: The expected argument-names. - * @param inspectGetargspecFunc Input: The inspect.getargspec Python-function. - * @param pyFunc Input: The Python-function. - */ -void checkFuncArgNames( - const std::string &funcName, - const std::vector<std::string> &expectedArgNames, - PyObject *const inspectGetargspecFunc, - PyObject *const pyFunc) - throw(castor::exception::InvalidConfiguration); - -} // namespace python -} // namespace tape -} // namespace castor - -#endif // CASTOR_TAPE_PYTHON_PYTHON_HPP diff --git a/test/castor/tape/mt_embedded_python/migration.py b/test/castor/tape/mt_embedded_python/migration.py deleted file mode 100644 index e738a9e30b8f4fad5eef44bb89834e5716ac54e4..0000000000000000000000000000000000000000 --- a/test/castor/tape/mt_embedded_python/migration.py +++ /dev/null @@ -1,74 +0,0 @@ -########################################################################## -# # -# CASTOR POLICY SERVICE # -# Migration Policy File # -# # -########################################################################## - -# Modules -import sys -import os - -def steveMigrationPolicy (): - print "Entered steveMigrationPolicy" - return 1; - -def defaultMigrationPolicy (tapePool,castorfilename,copynb,fileId,fileSize,fileMode,uid,gid,aTime,mTime,cTime,fileClass): - return 1; - -def smallFiles(tapePool, fileSize,smallfilesTP): - if ((fileSize <= 30000000) and (tapePool == smallfilesTP)): - return 1 - elif ((fileSize > 30000000) and (tapePool != smallfilesTP)): - return 1 - else: - return 0 - -def migrationWithMC (tapePool,fileClass,fileSize,copynb,validcases,validcasesWithMC,smallfilesTP,rest): - if (tapePool, fileClass) in validcases: - if (smallfilesTP, fileClass) in validcases: - return smallFiles(tapePool,fileSize,smallfilesTP) - else: - return 1 - if (tapePool,fileClass,copynb) in validcasesWithMC: - return 1 - validall = validcases + validcasesWithMC - if tapePool in rest: - for validtuple in validall: - if fileClass == validtuple[1]: - return 0 - else: - return 1 - return 0 - -def atlasT0MigrPolicy(tapePool, castorfilename,copynb,fileId,fileSize,fileMode,uid,gid,aTime,mTime,cTime,fileClass): - validtapepoolfileclass = [ ("atlas_recycle1w",2006), ("atlas_raw_08",2001), ("atlas_prod_08",2002), ("atlas_prod_08",2003), ("atlas_prod_08",2004)] - validtapepoolfileclasscopynb = [] - smallfilestapepool = None - resttapepool = [ "atlas_m4_07" ] - myreturncode = migrationWithMC(tapePool,fileClass,fileSize,copynb,validtapepoolfileclass,validtapepoolfileclasscopynb,smallfilestapepool,resttapepool) - f = open('/tmp/atlasT0MigrPolicy','a') - f.writelines(str(tapePool)+' '+str(castorfilename)+' '+str(copynb)+' '+str(fileId)+' '+str(fileSize)+' '+str(fileMode)+' '+str(uid)+' '+str(gid)+' '+str(aTime)+' '+str(mTime)+' '+str(cTime)+' '+str(fileClass)+' '+str(myreturncode)+'\n') - return myreturncode - -def atlsprodMigrPolicy(tapePool, castorfilename,copynb,fileId,fileSize,fileMode,uid,gid,aTime,mTime,cTime,fileClass): - validtapepoolfileclass = [ ("atlas_new1",139), ("atlas_new2",139), ("atlas_small_07",139), ("atlas_new1",33), ("atlas_new2",33), ("atlas_small_07",33), ("atlas_new1",59), ("atlas_new2",59), ("atlas_small_07",59), ("atlas_stream_07",145)] - validtapepoolfileclasscopynb = [ ("atlas_new1",34,2), ("atlas_new2",34,1), ("atlas_new1",115,2), ("atlas_new2",115,1) ] - smallfilestapepool = "atlas_small_07" - resttapepool = [ "user_new" ] - myreturncode = migrationWithMC(tapePool,fileClass,fileSize,copynb,validtapepoolfileclass,validtapepoolfileclasscopynb,smallfilestapepool,resttapepool) - f = open('/tmp/atlsprodMigrPolicy','a') - f.writelines(str(tapePool)+' '+str(castorfilename)+' '+str(copynb)+' '+str(fileId)+' '+str(fileSize)+' '+str(fileMode)+' '+str(uid)+' '+str(gid)+' '+str(aTime)+' '+str(mTime)+' '+str(cTime)+' '+str(fileClass)+' '+str(myreturncode)+'\n') - return myreturncode - -#print atlasT0MigrPolicy("atlas_t0T_new","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",148) -#print atlasT0MigrPolicy("atlas_m4_07","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",2) -#print atlasT0MigrPolicy("user_new","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",2) -#print atlsprodMigrPolicy("atlas_new1","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_new1","castorfilename","copynb","fileId",1000000000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_new2","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_new2","castorfilename","copynb","fileId",1000000000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_small_07","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("user_new","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",2) -# End-of-File - diff --git a/test/castor/tape/mt_embedded_python/stream.py b/test/castor/tape/mt_embedded_python/stream.py deleted file mode 100644 index 584a962977d9460273dfb24af0baa56b11f12766..0000000000000000000000000000000000000000 --- a/test/castor/tape/mt_embedded_python/stream.py +++ /dev/null @@ -1,61 +0,0 @@ -########################################################################## -# # -# CASTOR POLICY SERVICE # -# Stream Policy for ATLAS # -# # -########################################################################## - -# Modules -import sys -import os -from time import time, localtime, strftime -from random import random - -def steveStreamPolicy(): - print "Entered steveStreamPolicy" - return 1 - -def defaultStreamPolicy(runningStreams,numFiles,dataVolume,maxNumStreams,age): - return 1 - -def giveZeroSometimesOne(period,numberOfDrives): - # To avoid indefinite postponenment, randomly, - # once each "period" hours say yes, assuming mighunter period - # to be 1 hour - probability = 1./(period*numberOfDrives) - uniform01pick = random() - if probability > uniform01pick: - return 1 - else: - return 0 - -def firststreamPolicy(runningStreams,numFiles,dataVolume,maxNumStreams,age): - - randomPolicy = 0 - # Correction of 300 Mbytes per file due to the around 6 seconds spent - # writing labels and tape marks - correctedDataVolume = dataVolume + (numFiles*300000000) - # Step function with 300 GB step - wantedRunningStreams = int(correctedDataVolume/300000000000) - # dont go above the number of drives - if wantedRunningStreams > maxNumStreams: - wantedRunningStreams = maxNumStreams - - if wantedRunningStreams > runningStreams: - myreturncode = 1 - else: - randomPolicy = 1 - myreturncode = giveZeroSometimesOne(4,maxNumStreams) - - f = open('/tmp/fileStream.dump','a') - f.writelines("StreamPolicy called "+strftime("%d %b %Y %H:%M:%S", localtime())+' '+"runningStreams "+str(runningStreams)+" numFiles "+str(numFiles)+" dataVolume "+str(dataVolume)+" nbDrives "+str(maxNumStreams)+" wantedRunningStreams "+str(wantedRunningStreams)+" returncode "+str(myreturncode)) - if randomPolicy == 1: - f.writelines(" random"); - else: - f.writelines(" determ"); - f.writelines('\n'); - f.close() - - return myreturncode - -# End-of-File diff --git a/test/castor/tape/mt_embedded_python/test_mt_embedded_python.cpp b/test/castor/tape/mt_embedded_python/test_mt_embedded_python.cpp deleted file mode 100644 index 6d16e13d2c28770b0aed441bbc4e7bf7866e3e0c..0000000000000000000000000000000000000000 --- a/test/castor/tape/mt_embedded_python/test_mt_embedded_python.cpp +++ /dev/null @@ -1,878 +0,0 @@ -/****************************************************************************** - * test_multithreaded_cpp_embedded_python_interpreter.cpp - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * 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. - * - * - * - * @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch - *****************************************************************************/ - - -// Include Python.h before any standard headers because Python.h may define -// some pre-processor definitions which affect the standard headers -#include <Python.h> - -#include <iostream> -#include <pthread.h> -#include <sstream> -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> - -#define SEBASEOFF 1000 /* Base offset for special err. */ -#define SEINTERNAL SEBASEOFF+15 /* Internal error */ - -namespace castor { - - namespace exception { - - /** - * class Exception - * A simple exception used for error handling in castor - */ - class Exception { - - public: - - /** - * Empty Constructor - * @param serrno the serrno code of the corresponding C error - */ - Exception(int se); - - /** - * Copy Constructor - */ - Exception(Exception& dbex); - - /** - * Empty Destructor - */ - virtual ~Exception(); - - /** - * Get the value of m_message - * A message explaining why this exception was raised - * @return the value of m_message - */ - std::ostringstream& getMessage() { - return m_message; - } - - /** - * gets the serrno code of the corresponding C error - */ - const int code() const { return m_serrno; } - - private: - /// A message explaining why this exception was raised - std::ostringstream m_message; - - /** - * The serrno code of the corresponding C error - */ - int m_serrno; - - }; // class Exception - - /** - * Invalid argument exception - */ - class Internal : public castor::exception::Exception { - - public: - - /** - * default constructor - */ - Internal(); - - }; // class Internal - - /** - * Invalid argument exception - */ - class InvalidArgument : public castor::exception::Exception { - - public: - - /** - * default constructor - */ - InvalidArgument(); - - }; // class InvalidArgument - - } // end of exception namespace - -} // end of castor namespace - -castor::exception::Exception::Exception(int se) : m_serrno(se) {} - -castor::exception::Exception::Exception(castor::exception::Exception& ex) { - m_serrno = ex.code(); - m_message << ex.getMessage().str(); -} - -castor::exception::Exception::~Exception() {} - -castor::exception::Internal::Internal() : - castor::exception::Exception(SEINTERNAL) {} - -castor::exception::InvalidArgument::InvalidArgument() : - castor::exception::Exception(EINVAL) {} - -namespace castor { -namespace rtcopy { -namespace mighunter { - -/** - * As scoped lock which calls PyCGILState_Ensure() and PyGILState_Release() - * in order to ensure the current thread is ready to call the Python C API - * regardless of the current state of the embedded Python interpreter, or the - * state of the global interpreter lock. - */ -class ScopedPythonLock { -public: - - /** - * Constructor that immediately calls PyCGILState_Ensure() to ensure the - * current thread is ready to call the Python C API regardless of the current - * state of the embedded Python interpreter, or the state of the global - * interpreter lock. - */ - ScopedPythonLock() throw() : m_gstate(PyGILState_Ensure()) { - } - - /** - * Destructor that calls PyCGILState_Release() to release the embedded Python - * interpreter from the current thread and to return the interpreter to the - * state it was in prior to the execution of this scoped lock's constructor. - */ - ~ScopedPythonLock() throw() { - PyGILState_Release(m_gstate); - } - -private: - - /** - * Opaque handle to the bookkeeping information kept by Python about the - * thread taking a lock on the embedded Python interpreter. - */ - const PyGILState_STATE m_gstate; - -}; // class ScopedPythonLock - - - /** - * A smart FILE pointer that owns a basic FILE pointer. When the smart FILE - * pointer goes out of scope, it will close the FILE pointer it owns. - */ - class SmartFILEPtr { - public: - - /** - * Constructor. - * - */ - SmartFILEPtr(); - - /** - * Constructor. - * - * @param file The FILE pointer to be owned by the smart FILE pointer. - */ - SmartFILEPtr(FILE *const file); - - /** - * Take ownership of the specified FILE pointer, closing the previously - * owned FILE pointer if there is one and it is not the same as the one - * specified. - * - * @param file The FILE pointer to be owned, defaults to NULL if not - * specified, where NULL means this SmartFILEPtr does not own - * anything. - */ - void reset(FILE *const file) throw(); - - /** - * SmartFILEPtr assignment operator. - * - * This function does the following: - * <ul> - * <li> Calls release on the previous owner (obj); - * <li> Closes the FILE pointer of this object if it already owns one. - * <li> Makes this object the owner of the FILE pointer released from the - * previous owner (obj). - * </ul> - */ - SmartFILEPtr &operator=(SmartFILEPtr& obj) throw(); - - /** - * Destructor. - * - * Closes the owned FILE pointer if there is one. - */ - ~SmartFILEPtr(); - - /** - * Returns the owned FILE pointer or NULL if this smartFILEPtr does not own - * FILE pointer. - * - * @return The owned FILE pointer. - */ - FILE *get() throw(); - - /** - * Releases the owned FILE pointer. - * - * @return The released FILE pointer. - */ - FILE *release() throw(castor::exception::Exception); - - - private: - - /** - * The owned FILE pointer. A value of NULL means this SmartFILEPtr does - * not own anything. - */ - FILE *m_file; - - }; // class SmartFILEPtr - - -/** - * A smart PyObject pointer that owns a PyObject pointer. When the smart - * pointer goes out of scope, it will call Py_XDECREF() on the PyObject - * pointer. - */ -class SmartPyObjectPtr { -public: - - /** - * Constructor. - * - */ - SmartPyObjectPtr() throw(); - - /** - * Constructor. - * - * @param pyObject The PyObject pointer to be owned by the smart pointer. - */ - SmartPyObjectPtr(PyObject *const pyObject) throw(); - - /** - * Take ownership of the specified PyObject pointer, calling Py_XDECREF() on - * the previously owned pointer if there is one and it is not the same as the - * one specified. - * - * @param pyObject The PyObject pointer to be owned, defaults to NULL if not - * specified, where NULL means this SmartPyObjectPtr will not - * own a pointer after the reset() method returns. - */ - void reset(PyObject *const pyObject) throw(); - - /** - * SmartPyObjectPtr assignment operator. - * - * This function does the following: - * <ul> - * <li> Calls release on the previous owner (obj); - * <li> Calls Py_XDECREF() on the PyObject pointer of this object if it - * already owns one. - * <li> Makes this object the owner of the PyObject pointer released from the - * previous owner (obj). - * </ul> - */ - SmartPyObjectPtr &operator=(SmartPyObjectPtr& obj) throw(); - - /** - * Destructor. - * - * Calls Py_XDECREF() on the owned PyObject pointer if there is one. - */ - ~SmartPyObjectPtr(); - - /** - * Returns the owned pointer or NULL if this smart pointer does not own one. - * - * @return The owned FILE pointer. - */ - PyObject *get() const throw(); - - /** - * Releases the owned pointer. - * - * @return The released pointer. - */ - PyObject *release() throw(castor::exception::Exception); - - -private: - - /** - * The owned pointer. A value of NULL means this smart pointer does not own - * a pointer. - */ - PyObject *m_pyObject; - -}; // class SmartPyObjectPtr - -} // namespace mighunter -} // namespace rtcopy -} // namespace castor - - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::rtcopy::mighunter::SmartFILEPtr::SmartFILEPtr() : - m_file(NULL) { -} - - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::rtcopy::mighunter::SmartFILEPtr::SmartFILEPtr(FILE *const file) : - m_file(file) { -} - - -//----------------------------------------------------------------------------- -// reset -//----------------------------------------------------------------------------- -void castor::rtcopy::mighunter::SmartFILEPtr::reset(FILE *const file = NULL) - throw() { - // If the new FILE pointer is not the one already owned - if(file != m_file) { - - // If this SmartFILEPtr still owns a FILE pointer, then close it - if(m_file != NULL) { - fclose(m_file); - } - - // Take ownership of the new FILE pointer - m_file = file; - } -} - - -//----------------------------------------------------------------------------- -// SmartFILEPtr assignment operator -//----------------------------------------------------------------------------- -castor::rtcopy::mighunter::SmartFILEPtr - &castor::rtcopy::mighunter::SmartFILEPtr::operator=(SmartFILEPtr& obj) - throw() { - - reset(obj.release()); - - return *this; -} - - -//----------------------------------------------------------------------------- -// destructor -//----------------------------------------------------------------------------- -castor::rtcopy::mighunter::SmartFILEPtr::~SmartFILEPtr() { - - reset(); -} - - -//----------------------------------------------------------------------------- -// get -//----------------------------------------------------------------------------- -FILE *castor::rtcopy::mighunter::SmartFILEPtr::get() throw() { - - return m_file; -} - - -//----------------------------------------------------------------------------- -// release -//----------------------------------------------------------------------------- -FILE *castor::rtcopy::mighunter::SmartFILEPtr::release() - throw(castor::exception::Exception) { - - // If this SmartFILEPtr does not own a FILE pointer - if(m_file == NULL) { - castor::exception::Exception ex(EPERM); - - ex.getMessage() << - "Smart FILE pointer does not own a FILE pointer"; - - throw(ex); - } - - - FILE *const tmpFile = m_file; - - // A NULL value indicates this SmartFILEPtr does not own a FILE pointer - m_file = NULL; - - return tmpFile; -} - - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::rtcopy::mighunter::SmartPyObjectPtr::SmartPyObjectPtr() throw() : - m_pyObject(NULL) { -} - - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::rtcopy::mighunter::SmartPyObjectPtr::SmartPyObjectPtr( - PyObject *const pyObject) throw() : m_pyObject(pyObject) { -} - - -//----------------------------------------------------------------------------- -// reset -//----------------------------------------------------------------------------- -void castor::rtcopy::mighunter::SmartPyObjectPtr::reset( - PyObject *const pyObject = NULL) throw() { - - // If the new pointer is not the one already owned - if(pyObject != m_pyObject) { - - // If this smart pointer still owns a pointer, then call Py_XDECREF() on it - if(m_pyObject != NULL) { - Py_XDECREF(m_pyObject); - } - - // Take ownership of the new pointer - m_pyObject = pyObject; - } -} - - -//----------------------------------------------------------------------------- -// SmartPyObjectPtr assignment operator -//----------------------------------------------------------------------------- -castor::rtcopy::mighunter::SmartPyObjectPtr - &castor::rtcopy::mighunter::SmartPyObjectPtr::operator=(SmartPyObjectPtr& obj) - throw() { - - reset(obj.release()); - - return *this; -} - - -//----------------------------------------------------------------------------- -// destructor -//----------------------------------------------------------------------------- -castor::rtcopy::mighunter::SmartPyObjectPtr::~SmartPyObjectPtr() { - - reset(); -} - - -//----------------------------------------------------------------------------- -// get -//----------------------------------------------------------------------------- -PyObject *castor::rtcopy::mighunter::SmartPyObjectPtr::get() const throw() { - - return m_pyObject; -} - - -//----------------------------------------------------------------------------- -// release -//----------------------------------------------------------------------------- -PyObject *castor::rtcopy::mighunter::SmartPyObjectPtr::release() - throw(castor::exception::Exception) { - - // If this smart pointer does not own a pointer - if(m_pyObject == NULL) { - castor::exception::Exception ex(EPERM); - - ex.getMessage() << - "Smart pointer does not own a PyObject pointer"; - - throw(ex); - } - - - PyObject *const tmp = m_pyObject; - - // A NULL value indicates this smart pointer does not own a pointer - m_pyObject = NULL; - - return tmp; -} - -/** - * Loads the specified Python module file into the embedded Python interpreter - * and returns a pointer to the asscoaited Python module dictionary. - */ -PyObject *loadPythonScript(const char *filename) - throw(castor::exception::Exception) { - using namespace castor::rtcopy::mighunter; - - SmartFILEPtr fp(fopen(filename, "r")); - if (fp.get() == NULL) { - castor::exception::Exception ex(errno); - ex.getMessage() << - "Failed to open python module-file" - ": filename= " << filename; - throw ex; - } - - // Open the python module - PyRun_SimpleFile(fp.get(), filename); - if(PyErr_Occurred()) { - castor::exception::Internal ex; - - ex.getMessage() << "Error in invoking call to PyRun_SimpleFile" - << std::endl; - throw ex; - } - fclose(fp.release()); - - // Import the pythons modules __main__ namespace - PyObject *pyModule = PyImport_AddModule((char*)"__main__"); - if (pyModule == NULL) { - castor::exception::Exception ex(SEINTERNAL); - ex.getMessage() << "Error importing python module with PyImport_AddModule" - << std::endl; - throw ex; - } - - // Get and return a pointer to the module's dictionary object - return PyModule_GetDict(pyModule); -} - - -PyObject *callPythonFunction(PyObject *const pyDict, const char *functionName, - PyObject *const inputObj) throw(castor::exception::Exception) { - - // Get a pointer to the Python function - PyObject *pyFunc = PyDict_GetItemString(pyDict, functionName); - - // Throw an exception if the Python function does not exist - if(pyFunc == NULL) { - castor::exception::InvalidArgument ex; - - ex.getMessage() << - "Python function does not exist" - ": functionName=" << functionName; - - throw ex; - } - - // Throw an exception if the Python function is not callable - if (!PyCallable_Check(pyFunc)) { - castor::exception::InvalidArgument ex; - - ex.getMessage() << - "Python function cannot be called" - ": functionName=" << functionName; - - throw ex; - } - - PyObject *result = PyObject_CallObject(pyFunc,inputObj); - if (result == NULL) { - castor::exception::Internal ex; - - ex.getMessage() << - "Failed to execute Python function" - ": functionName=" << functionName; - - throw ex; - } - - return result; -} - - -void *strThreadRoutine(void *arg) { - using namespace castor::rtcopy::mighunter; - - std::cout << "strThreadRoutine started" << std::endl; - - PyObject *pyDict = (PyObject *)arg; - // const char *functionName = "steveStreamPolicy"; - const char *functionName = "firststreamPolicy"; - - // SmartPyObjectPtr inputObj; - SmartPyObjectPtr inputObj(Py_BuildValue( - "(K,K,K,K,K)", - 1, // elem->runningStream(), - 1, // elem->numFiles(), - 1, // elem->numBytes(), - 1, // elem->maxNumStreams(), - 1 //elem->age()); - )); - - int i=1; - try { - for(i=1; i<=10000; i++) { - ScopedPythonLock scopedPythonLock; - - SmartPyObjectPtr result(callPythonFunction(pyDict, functionName, - inputObj.get())); - } - } catch(castor::exception::Exception &ex) { - std::cerr << - "strThreadRoutine iteration failed" - ": iteration=" << i << - ": code=" << ex.code() << - ": message=" << ex.getMessage().str(); - } - - std::cout << "strThreadRoutine ended" << std::endl; - return NULL; -} - - -void *migrThreadRoutine(void *arg) { - using namespace castor::rtcopy::mighunter; - - std::cout << "migrThreadRoutine started" << std::endl; - - PyObject *pyDict = (PyObject *)arg; - //const char *functionName = "steveMigrationPolicy"; - const char *functionName = "atlasT0MigrPolicy"; - - SmartPyObjectPtr inputObj(Py_BuildValue( - "(s,s,K,K,K,K,K,K,K,K,K,K)", - "nicolasPool", // (elem->tapePoolName()).c_str(), - "nicolasFile", // (elem->castorFileName()).c_str(), - 1, // elem->copyNb(), - 1, // elem->fileId(), - 1, // elem->fileSize(), - 1, // elem->fileMode(), - 1, // elem->uid(), - 1, // elem->gid(), - 1, // elem->aTime(), - 1, // elem->mTime(), - 1, // elem->cTime(), - 1 // elem->fileClass() - )); - - int i=1; - try { - for(i=1; i<=10000; i++) { - ScopedPythonLock scopedPythonLock; - - - SmartPyObjectPtr result(callPythonFunction(pyDict, functionName, - inputObj.get())); - } - } catch(castor::exception::Exception &ex) { - std::cerr << - "strThreadRoutine iteration failed" - ": iteration=" << i << - ": code=" << ex.code() << - ": message=" << ex.getMessage().str(); - } - - std::cout << "migrThreadRoutine ended" << std::endl; - - return NULL; -} - - -/** - * C++ wrapper function of the C pthread_create() function. This wrapper - * converts the return value indicating an error into the throw of a - * castor::exception::Exception. - */ -void pthreadCreate(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine)(void*), void *arg) - throw(castor::exception::Exception) { - - const int rc = pthread_create(thread, attr, start_routine, arg); - - if(rc != 0) { - castor::exception::Exception ex(rc); - - ex.getMessage() << - "Call to pthread_create() failed"; - - throw(ex); - } -} - - -/** - * C++ wrapper function of the C pthread_join() function. This wrapper - * converts the return value indicating an error into the throw of a - * castor::exception::Exception. - */ -void pthreadJoin(pthread_t thread, void **value_ptr) - throw(castor::exception::Exception) { - - const int rc = pthread_join(thread, value_ptr); - - if(rc != 0) { - castor::exception::Exception ex(rc); - - ex.getMessage() << - "Call to pthread_join() failed"; - - throw(ex); - } -} - - -PyObject *importPythonModule(char *const moduleName) - throw(castor::exception::Exception) { - - PyObject *const module = PyImport_ImportModule(moduleName); - - if(module == NULL) { - castor::exception::Exception ex(ECANCELED); - - ex.getMessage() << - "PyImport_ImportModule() call failed" - ": moduleName=" << moduleName; - - throw(ex); - } - - return module; -} - - -/** - * Append the specified directory to the value of the PYTHONPATH environment - * variable. - */ -void appendDirectoryToPYTHONPATH(const char *const directory) { - // Get the current value of PYTHONPATH (there may not be one) - const char *const currentPath = getenv("PYTHONPATH"); - - // Construct the new value of PYTHONPATH - std::string newPath; - if(currentPath == NULL) { - newPath = directory; - } else { - newPath = currentPath; - newPath += ":"; - newPath += directory; - } - - // Set PYTHONPATH to the new value - const int overwrite = 1; - setenv("PYTHONPATH", newPath.c_str(), overwrite); -} - - -int exceptionThrowingMain(int argc, char **argv) - throw(castor::exception::Exception) { - using namespace castor::rtcopy::mighunter; - - std::cout << - "\n" - "Testing the multi-thread API of embedded Python from C++\n" - "========================================================\n" << - std::endl; - - // Append /etc/castor/policies to the end of the PYTHONPATH environment - // variable so the PyImport_ImportModule() function can find the stream and - // migration policy modules - appendDirectoryToPYTHONPATH("."); - - // Display the result of modifying PYTHONPATH - { - const char *value = getenv("PYTHONPATH"); - - if(value == NULL) { - value = ""; - } - - std::cout << "PYTHONPATH=" << value << std::endl; - } - - // Initialize Python - Py_Initialize(); - - // Initialize thread support - // - // Please note that PyEval_InitThreads() takes a lock on the global Python - // interpreter - PyEval_InitThreads(); - - //std::cout << "Loading in the stream and migration policies" << std::endl; - SmartPyObjectPtr streamModule(importPythonModule("stream")); - PyObject *const strDict = PyModule_GetDict(streamModule.get()); - SmartPyObjectPtr migrationModule(importPythonModule("migration")); - PyObject *const migrDict = PyModule_GetDict(migrationModule.get()); - - // Load in the stream and migration policies - //std::cout << "Loading in the stream and migration policies" << std::endl; - //PyObject *const strDict = loadPythonScript("stream.py"); - //PyObject *const migrDict = loadPythonScript("migration.py"); - - // Release the lock on the Python global interpreter that was taken by the - // preceding PyEval_InitThreads() call - PyEval_ReleaseLock(); - - // Display the pointers to the module dictionaries to see if they are infact - // the same one - std::cout << std::hex << - "strDict =0x" << (uint64_t)strDict << "\n" - "migrDict=0x" << (uint64_t)migrDict << "\n" << - std::dec << std::endl; - - // Create the stream and migration threads - std::cout << "Creating the stream and migration threads" << std::endl; - pthread_t strThread; - pthread_t migrThread; - pthreadCreate(&strThread , NULL, strThreadRoutine , strDict ); - pthreadCreate(&migrThread, NULL, migrThreadRoutine, migrDict); - - // Join with the stream and migration threads - void *strThreadResult = NULL; - void *migrThreadResult = NULL; - std::cout << "Joining with the stream thread" << std::endl; - pthreadJoin(strThread , &strThreadResult); - std::cout << "Joining with the migration thread" << std::endl; - pthreadJoin(migrThread, &migrThreadResult); - - return 0; -} - - -int main(int argc, char **argv) { - try { - exceptionThrowingMain(argc, argv); - } catch(castor::exception::Exception &ex) { - std::cerr << - "Test failed" - ": Caught an exception" - ": code=" << ex.code() << - ": message=" << ex.getMessage().str() << std::endl; - - return 1; - } - - std::cout << "Test finished successfully\n" << std::endl; - - return 0; -} diff --git a/test/castor/tape/python/Makefile b/test/castor/tape/python/Makefile deleted file mode 100644 index 79ee4a4a2a51e3b641faf07e8c94f9b42b4a25a1..0000000000000000000000000000000000000000 --- a/test/castor/tape/python/Makefile +++ /dev/null @@ -1,60 +0,0 @@ -TO_ROOT=../../../.. - -PYTHONLIBS = $(shell python ${TO_ROOT}/config/pycompile.py --libs) -PYTHONINC = $(shell python ${TO_ROOT}/config/pycompile.py --inc) -PYTHONCFLAGS = $(shell python ${TO_ROOT}/config/pycompile.py --cflags) - -INCLUDE_OPTIONS=$(PYTHONINC) -I$(TO_ROOT) -I$(TO_ROOT)/h - -C_SRCS=$(TO_ROOT)/common/serror.c\ - $(TO_ROOT)/common/Cglobals.c\ - $(TO_ROOT)/common/getconfent.c - -CPP_SRCS=TestPythonMain.cpp\ - $(TO_ROOT)/castor/Constants.cpp\ - $(TO_ROOT)/castor/tape/python/python.cpp\ - $(TO_ROOT)/castor/exception/BadVersion.cpp\ - $(TO_ROOT)/castor/exception/Busy.cpp\ - $(TO_ROOT)/castor/exception/Communication.cpp\ - $(TO_ROOT)/castor/exception/Exception.cpp\ - $(TO_ROOT)/castor/exception/FailedToExecutePython.cpp\ - $(TO_ROOT)/castor/exception/Internal.cpp\ - $(TO_ROOT)/castor/exception/InvalidArgument.cpp\ - $(TO_ROOT)/castor/exception/InvalidConfigEntry.cpp\ - $(TO_ROOT)/castor/exception/InvalidConfiguration.cpp\ - $(TO_ROOT)/castor/exception/NoEntry.cpp\ - $(TO_ROOT)/castor/exception/NoPortInRange.cpp\ - $(TO_ROOT)/castor/exception/NoSegmentFound.cpp\ - $(TO_ROOT)/castor/exception/NotSupported.cpp\ - $(TO_ROOT)/castor/exception/NoValue.cpp\ - $(TO_ROOT)/castor/exception/OutOfMemory.cpp\ - $(TO_ROOT)/castor/exception/PermissionDenied.cpp\ - $(TO_ROOT)/castor/exception/RequestCanceled.cpp\ - $(TO_ROOT)/castor/exception/Security.cpp\ - $(TO_ROOT)/castor/exception/SegmentNotAccessible.cpp\ - $(TO_ROOT)/castor/exception/SQLError.cpp\ - $(TO_ROOT)/castor/exception/TapeCopyNotFound.cpp\ - $(TO_ROOT)/castor/exception/TapeNetAcceptInterrupted.cpp\ - $(TO_ROOT)/castor/exception/TapeOffline.cpp\ - $(TO_ROOT)/castor/exception/TimeOut.cpp\ - $(TO_ROOT)/castor/exception/TooBig.cpp\ - $(TO_ROOT)/castor/tape/python/python.cpp\ - $(TO_ROOT)/castor/tape/python/ScopedPythonLock.cpp\ - $(TO_ROOT)/castor/tape/python/SmartPyObjectPtr.cpp\ - $(TO_ROOT)/castor/tape/utils/ScopedLock.cpp\ - $(TO_ROOT)/castor/tape/utils/SmartFd.cpp\ - $(TO_ROOT)/castor/tape/utils/SmartFdList.cpp\ - $(TO_ROOT)/castor/tape/utils/SmartFILEPtr.cpp\ - $(TO_ROOT)/castor/tape/utils/utils.cpp - -OBJS=$(C_SRCS:.c=.o) $(CPP_SRCS:.cpp=.o) -PROGRAM=testpython - -$(PROGRAM): $(OBJS) - g++ -g -pthread -o $@ $^ $(PYTHONLIBS) - -clean: - rm -f $(PROGRAM) *.o - -%.o: %.cpp - g++ -g -pthread $(INCLUDE_OPTIONS) -c -o $@ $^ diff --git a/test/castor/tape/python/TestPythonMain.cpp b/test/castor/tape/python/TestPythonMain.cpp deleted file mode 100644 index e7ceba824b2c8685cfd339d765df868782b6d25f..0000000000000000000000000000000000000000 --- a/test/castor/tape/python/TestPythonMain.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/****************************************************************************** - * test/castor/tape/python/TestPythonMain.cpp - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * 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. - * - * - * - * @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch - *****************************************************************************/ - -// Include python.hpp before any standard headers because python.hpp includes -// Python.h which may define some pre-processor definitions which affect the -// standard headers -#include "castor/tape/python/python.hpp" - -#include "castor/tape/python/ScopedPythonLock.hpp" -#include "castor/tape/python/SmartPyObjectPtr.hpp" -#include "castor/tape/utils/utils.hpp" - -#include <iostream> -#include <pthread.h> -#include <string> -#include <vector> - -/** - * The arguments names a migration-policy Python-function must have in order - * to be considered valid. - */ -static std::vector<std::string> s_expectedMigrationPolicyArgNames; - -void *startRoutine(void *arg) { - using namespace castor::tape; - - std::cout << "Entered " << __PRETTY_FUNCTION__ << std::endl; - - PyObject *const pyFunc = (PyObject *)arg; - - { - python::ScopedPythonLock scopedPythonLock; - - python::SmartPyObjectPtr inputObj(Py_BuildValue( - "(s,s,K,K,K,K,K,K,K,K,K,K)", - "stevePool", // (elem->tapePoolName()).c_str(), - "steveFile", // (elem->castorFileName()).c_str(), - 1, // elem->copyNb(), - 1, // elem->fileId(), - 1, // elem->fileSize(), - 1, // elem->fileMode(), - 1, // elem->uid(), - 1, // elem->gid(), - 1, // elem->aTime(), - 1, // elem->mTime(), - 1, // elem->cTime(), - 1 // elem->fileClass() - )); - - python::SmartPyObjectPtr - result(PyObject_CallObject(pyFunc, inputObj.get())); - - if(result.get() != NULL) { - std::cout << - "Succeeded to execute Python function" << - std::endl; - } else { - std::cerr << - "Failed to execute Python function" << - std::endl; - } - } - - std::cout << "Leaving startRoutine()" << std::endl; - return NULL; -} - - -int exceptionThrowingMain() - throw(castor::exception::Exception) { - - using namespace castor::tape; - - python::initializePython(); - - // Import a valid module and get a valid function - const char *const functionName = "defaultMigrationPolicy"; - PyObject *pyFunc = NULL; - { - python::ScopedPythonLock scopedPythonLock; - - const char *const moduleName = "migration"; - PyObject *const pyDict = python::importPolicyPythonModule(moduleName); - pyFunc = python::getPythonFunction(pyDict, functionName); - - if(pyFunc != NULL) { - std::cout << "\"" << functionName << "\" found" << std::endl; - } else { - std::cout << "\"" << functionName << "\" NOT found" << std::endl; - - return 1; - } - } - - PyObject *const inspectDict = python::importPythonModuleWithLock("inspect"); - - // Get a handle on the inspect.getargspec Python-function - PyObject *const inspectGetargspecFunc = python::getPythonFunctionWithLock( - inspectDict, "getargspec"); - - // Set the argument names a migration-policy Python-function must have in - // order to be considered valid - std::vector<std::string> expectedArgumentNames; - expectedArgumentNames.push_back("tapepool"); - expectedArgumentNames.push_back("castorfilename"); - expectedArgumentNames.push_back("copynb"); - expectedArgumentNames.push_back("fileId"); - expectedArgumentNames.push_back("fileSize"); - expectedArgumentNames.push_back("fileMode"); - expectedArgumentNames.push_back("uid"); - expectedArgumentNames.push_back("gid"); - expectedArgumentNames.push_back("aTime"); - expectedArgumentNames.push_back("mTime"); - expectedArgumentNames.push_back("cTime"); - expectedArgumentNames.push_back("fileClass"); - - std::cout << "Getting the names of the arguments of " << functionName << - std::endl; - - std::vector<std::string> actualArgumentNames; - python::getPythonFunctionArgumentNamesWithLock(inspectGetargspecFunc, pyFunc, - actualArgumentNames); - - std::cout << "Argument names of " << functionName << ": " << - utils::vectorOfStringToString(actualArgumentNames) << std::endl; - - if(actualArgumentNames.size() != expectedArgumentNames.size()) { - std::cout << "Test failed " << functionName << - " has the wrong number of arguments" - ": expectedArgumentNames.size()=" << expectedArgumentNames.size() << - ", actualArgumentNames.size()=" << actualArgumentNames.size(); - - return 1; // Test failed - } else { - std::cout << functionName << " has the correct number of arguments: " << - expectedArgumentNames.size() << std::endl; - } - - for(std::vector<std::string>::size_type i=0; - i<expectedArgumentNames.size(); i++) { - if(expectedArgumentNames[i] != actualArgumentNames[i]) { - std::cout << functionName << " has an unexpected argument name" - ": argumentIndex=" << i << - ", expectedName=" << expectedArgumentNames[i] << - ", actualName=" << actualArgumentNames[i]; - return 1; // Test failed - } - } - std::cout << functionName << " has the correct argument names" << std::endl; - - // Try to import a non-existant module - try { - python::ScopedPythonLock scopedPythonLock; - - python::importPolicyPythonModule("doesnotexist"); - - std::cerr << - "Test failed because the importing of non-existant module apparently" - " worked" << - std::endl; - - return 1; - } catch(castor::exception::Exception &ex) { - - if(ex.code() == ENOENT) { - std::cout << - "Succeeded to detect non-existant module file" << - std::endl; - } else { - std::cerr << - "Test failed because importPolicyPythonModule() threw the wrong" - " exception" << - std::endl; - - return 1; - } - } - - { - python::ScopedPythonLock scopedPythonLock; - - std::cout << - "Inside a new scopedPythonLock" << - std::endl; - } - - std::cout << - "New scopedPythonLock released" << - std::endl; - - { - python::ScopedPythonLock scopedPythonLock; - - std::cout << - "Inside yet another new scopedPythonLock" << - std::endl; - } - - std::cout << - "Yet another new scopedPythonLock released" << - std::endl; - - pthread_t thread; - - utils::pthreadCreate(&thread , NULL, startRoutine, pyFunc); - - utils::pthreadJoin(thread, NULL); - - std::cout << - "main thread is sleeping for 1 second" << - std::endl; - sleep(1); - - { - python::ScopedPythonLock scopedPythonLock; - - std::cout << - "Inside new scopedPythonLock after utils::pthreadJoin() and sleep(1)" << - std::endl; - } - - std::cout << - "New scopedPythonLock after utils::pthreadJoin() and sleep(1) released" << - std::endl; - - python::finalizePython(); - - std::cout << - "After python::finalizePython()" << - std::endl; - - return 0; -} - - -int main() { - std::cout << - "\n" - "Testing castor::tape::python\n" - "============================\n" << - std::endl; - - int rc = 0; - - try { - rc = exceptionThrowingMain(); - } catch(castor::exception::Exception &ex) { - std::cerr << - "Test failed" - ": Caught an exception" - ": code=" << ex.code() << - ": message=" << ex.getMessage().str() << std::endl; - - return 1; - } - - if(rc == 0) { - std::cout << "Test finished successfully\n" << std::endl; - } else { - std::cout << "Test failed" << std::endl; - } - - return rc; -} diff --git a/test/castor/tape/python/migration.py b/test/castor/tape/python/migration.py deleted file mode 100644 index e738a9e30b8f4fad5eef44bb89834e5716ac54e4..0000000000000000000000000000000000000000 --- a/test/castor/tape/python/migration.py +++ /dev/null @@ -1,74 +0,0 @@ -########################################################################## -# # -# CASTOR POLICY SERVICE # -# Migration Policy File # -# # -########################################################################## - -# Modules -import sys -import os - -def steveMigrationPolicy (): - print "Entered steveMigrationPolicy" - return 1; - -def defaultMigrationPolicy (tapePool,castorfilename,copynb,fileId,fileSize,fileMode,uid,gid,aTime,mTime,cTime,fileClass): - return 1; - -def smallFiles(tapePool, fileSize,smallfilesTP): - if ((fileSize <= 30000000) and (tapePool == smallfilesTP)): - return 1 - elif ((fileSize > 30000000) and (tapePool != smallfilesTP)): - return 1 - else: - return 0 - -def migrationWithMC (tapePool,fileClass,fileSize,copynb,validcases,validcasesWithMC,smallfilesTP,rest): - if (tapePool, fileClass) in validcases: - if (smallfilesTP, fileClass) in validcases: - return smallFiles(tapePool,fileSize,smallfilesTP) - else: - return 1 - if (tapePool,fileClass,copynb) in validcasesWithMC: - return 1 - validall = validcases + validcasesWithMC - if tapePool in rest: - for validtuple in validall: - if fileClass == validtuple[1]: - return 0 - else: - return 1 - return 0 - -def atlasT0MigrPolicy(tapePool, castorfilename,copynb,fileId,fileSize,fileMode,uid,gid,aTime,mTime,cTime,fileClass): - validtapepoolfileclass = [ ("atlas_recycle1w",2006), ("atlas_raw_08",2001), ("atlas_prod_08",2002), ("atlas_prod_08",2003), ("atlas_prod_08",2004)] - validtapepoolfileclasscopynb = [] - smallfilestapepool = None - resttapepool = [ "atlas_m4_07" ] - myreturncode = migrationWithMC(tapePool,fileClass,fileSize,copynb,validtapepoolfileclass,validtapepoolfileclasscopynb,smallfilestapepool,resttapepool) - f = open('/tmp/atlasT0MigrPolicy','a') - f.writelines(str(tapePool)+' '+str(castorfilename)+' '+str(copynb)+' '+str(fileId)+' '+str(fileSize)+' '+str(fileMode)+' '+str(uid)+' '+str(gid)+' '+str(aTime)+' '+str(mTime)+' '+str(cTime)+' '+str(fileClass)+' '+str(myreturncode)+'\n') - return myreturncode - -def atlsprodMigrPolicy(tapePool, castorfilename,copynb,fileId,fileSize,fileMode,uid,gid,aTime,mTime,cTime,fileClass): - validtapepoolfileclass = [ ("atlas_new1",139), ("atlas_new2",139), ("atlas_small_07",139), ("atlas_new1",33), ("atlas_new2",33), ("atlas_small_07",33), ("atlas_new1",59), ("atlas_new2",59), ("atlas_small_07",59), ("atlas_stream_07",145)] - validtapepoolfileclasscopynb = [ ("atlas_new1",34,2), ("atlas_new2",34,1), ("atlas_new1",115,2), ("atlas_new2",115,1) ] - smallfilestapepool = "atlas_small_07" - resttapepool = [ "user_new" ] - myreturncode = migrationWithMC(tapePool,fileClass,fileSize,copynb,validtapepoolfileclass,validtapepoolfileclasscopynb,smallfilestapepool,resttapepool) - f = open('/tmp/atlsprodMigrPolicy','a') - f.writelines(str(tapePool)+' '+str(castorfilename)+' '+str(copynb)+' '+str(fileId)+' '+str(fileSize)+' '+str(fileMode)+' '+str(uid)+' '+str(gid)+' '+str(aTime)+' '+str(mTime)+' '+str(cTime)+' '+str(fileClass)+' '+str(myreturncode)+'\n') - return myreturncode - -#print atlasT0MigrPolicy("atlas_t0T_new","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",148) -#print atlasT0MigrPolicy("atlas_m4_07","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",2) -#print atlasT0MigrPolicy("user_new","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",2) -#print atlsprodMigrPolicy("atlas_new1","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_new1","castorfilename","copynb","fileId",1000000000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_new2","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_new2","castorfilename","copynb","fileId",1000000000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_small_07","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("user_new","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",2) -# End-of-File - diff --git a/test/castor/tape/python/testpython.sh b/test/castor/tape/python/testpython.sh deleted file mode 100755 index 942f703fbea9b9b75dc97c0975c34fce860f67d7..0000000000000000000000000000000000000000 --- a/test/castor/tape/python/testpython.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test "x$CASTOR_SRC" = x; then - echo "Error: The environment variable CASTOR_SRC is not set" - echo - echo "CASTOR_SRC should be the full path to the CASTOR source code, e.g." - echo - echo " export CASTOR_SRC=/usr/local/src/CASTOR_SVN_CO/trunk" - echo - exit -1 -fi - -LD_LIBRARY_PATH=`find $CASTOR_SRC -name '*.so*' | sed 's|/[^/]*$||' | sort | uniq` -LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | sed 's/ /:/g'` -PARAMS=$@ -CMD="export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; $CASTOR_SRC/test/castor/tape/python/testpython $PARAMS" - -if test $USER = root; then - sudo -u stage sh -c "$CMD" -else - sh -c "$CMD" -fi diff --git a/test/castor/tape/pythonmemory/TestPythonMemoryMain.cpp b/test/castor/tape/pythonmemory/TestPythonMemoryMain.cpp deleted file mode 100644 index 40dee26ee0350a47dbc69718a8e7c997e9b84e4a..0000000000000000000000000000000000000000 --- a/test/castor/tape/pythonmemory/TestPythonMemoryMain.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/****************************************************************************** - * test/castor/tape/python/TestPythonMemoryMain.cpp - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * 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. - * - * - * - * @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch - *****************************************************************************/ - -// Include python.hpp before any standard headers because python.hpp includes -// Python.h which may define some pre-processor definitions which affect the -// standard headers -#include "castor/tape/python/python.hpp" - -#include "castor/tape/python/ScopedPythonLock.hpp" -#include "castor/tape/python/SmartPyObjectPtr.hpp" -#include "castor/tape/utils/utils.hpp" - -#include <iostream> -#include <string> -#include <vector> - - -int exceptionThrowingMain() - throw(castor::exception::Exception) { - - using namespace castor::tape; - - python::initializePython(); - - PyObject *const migrationDict = - python::importPythonModuleWithLock("migration"); - PyObject *const migrationFunc = - python::getPythonFunctionWithLock(migrationDict, "defaultMigrationPolicy"); - - PyObject *const inspectDict = python::importPythonModuleWithLock("inspect"); - PyObject *const inspectGetargspecFunc = python::getPythonFunctionWithLock( - inspectDict, "getargspec"); - - std::vector<std::string> actualArgumentNames; - - for(;;) { // Forever - python::getPythonFunctionArgumentNamesWithLock(inspectGetargspecFunc, - migrationFunc, actualArgumentNames); -/* - castor::tape::python::SmartPyObjectPtr inputObj( - Py_BuildValue((char *)"(O)", inspectGetargspecFunc)); - - if(inputObj.get() == NULL) { - // Try to determine the Python exception if there was a Python error - PyObject *const pyEx = PyErr_Occurred(); - const char *pyExStr = python::stdPythonExceptionToStr(pyEx); - - // Clear the Python error if there was one - if(pyEx != NULL) { - PyErr_Clear(); - } - - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Failed to create input Python-object for inspect.getargspec" - ": Call to Py_BuildValue failed" - ": pythonException=" << pyExStr; - throw(ex); - } - - // Call the inspect.getmembers method on the stream-policy Python-module - python::SmartPyObjectPtr - resultObj(PyObject_CallObject(inspectGetargspecFunc, inputObj.get())); - - // Throw an exception if the invocation of the Python-function failed - if(resultObj.get() == NULL) { - // Try to determine the Python exception if there was a Python error - PyObject *const pyEx = PyErr_Occurred(); - const char *pyExStr = python::stdPythonExceptionToStr(pyEx); - - // Clear the Python error if there was one - if(pyEx != NULL) { - PyErr_Clear(); - } - - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Failed to get result from Python-function" - ": moduleName=inspect" - ", functionName=getargspec" - ", pythonException=" << pyExStr; - throw(ex); - } - - // Throw an exception if the result of inspect.getargsspec is not a - // Python-sequence - if(!PySequence_Check(resultObj.get())) { - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Python-function returned unexpected result-type" - ": moduleName=inspect" - ", functionName=getargspec" - ", expectedResultType=PySequence"; - throw(ex); - } - - // Get a handle on the array of function argument names - python::SmartPyObjectPtr - argumentNamesPySequence(PySequence_GetItem(resultObj.get(), 0)); - - // Throw an exception if the handle cound not be obtained - if(argumentNamesPySequence.get() == NULL) { - castor::exception::Exception ex(ECANCELED); - ex.getMessage() << - __FUNCTION__ << "() failed" - ": Failed to get a handle on the array of function argument names" - ": moduleName=inspect" - ", functionName=getargspec"; - throw(ex); - } -*/ - } // Forever - - return 0; -} - - -int main() { - std::cout << - "\n" - "Testing castor::tape::python\n" - "============================\n" << - std::endl; - - int rc = 0; - - try { - rc = exceptionThrowingMain(); - } catch(castor::exception::Exception &ex) { - std::cerr << - "Test failed" - ": Caught an exception" - ": code=" << ex.code() << - ": message=" << ex.getMessage().str() << std::endl; - - return 1; - } - - if(rc == 0) { - std::cout << "Test finished successfully\n" << std::endl; - } else { - std::cout << "Test failed" << std::endl; - } - - return rc; -} diff --git a/test/castor/tape/pythonmemory/migration.py b/test/castor/tape/pythonmemory/migration.py deleted file mode 100644 index e738a9e30b8f4fad5eef44bb89834e5716ac54e4..0000000000000000000000000000000000000000 --- a/test/castor/tape/pythonmemory/migration.py +++ /dev/null @@ -1,74 +0,0 @@ -########################################################################## -# # -# CASTOR POLICY SERVICE # -# Migration Policy File # -# # -########################################################################## - -# Modules -import sys -import os - -def steveMigrationPolicy (): - print "Entered steveMigrationPolicy" - return 1; - -def defaultMigrationPolicy (tapePool,castorfilename,copynb,fileId,fileSize,fileMode,uid,gid,aTime,mTime,cTime,fileClass): - return 1; - -def smallFiles(tapePool, fileSize,smallfilesTP): - if ((fileSize <= 30000000) and (tapePool == smallfilesTP)): - return 1 - elif ((fileSize > 30000000) and (tapePool != smallfilesTP)): - return 1 - else: - return 0 - -def migrationWithMC (tapePool,fileClass,fileSize,copynb,validcases,validcasesWithMC,smallfilesTP,rest): - if (tapePool, fileClass) in validcases: - if (smallfilesTP, fileClass) in validcases: - return smallFiles(tapePool,fileSize,smallfilesTP) - else: - return 1 - if (tapePool,fileClass,copynb) in validcasesWithMC: - return 1 - validall = validcases + validcasesWithMC - if tapePool in rest: - for validtuple in validall: - if fileClass == validtuple[1]: - return 0 - else: - return 1 - return 0 - -def atlasT0MigrPolicy(tapePool, castorfilename,copynb,fileId,fileSize,fileMode,uid,gid,aTime,mTime,cTime,fileClass): - validtapepoolfileclass = [ ("atlas_recycle1w",2006), ("atlas_raw_08",2001), ("atlas_prod_08",2002), ("atlas_prod_08",2003), ("atlas_prod_08",2004)] - validtapepoolfileclasscopynb = [] - smallfilestapepool = None - resttapepool = [ "atlas_m4_07" ] - myreturncode = migrationWithMC(tapePool,fileClass,fileSize,copynb,validtapepoolfileclass,validtapepoolfileclasscopynb,smallfilestapepool,resttapepool) - f = open('/tmp/atlasT0MigrPolicy','a') - f.writelines(str(tapePool)+' '+str(castorfilename)+' '+str(copynb)+' '+str(fileId)+' '+str(fileSize)+' '+str(fileMode)+' '+str(uid)+' '+str(gid)+' '+str(aTime)+' '+str(mTime)+' '+str(cTime)+' '+str(fileClass)+' '+str(myreturncode)+'\n') - return myreturncode - -def atlsprodMigrPolicy(tapePool, castorfilename,copynb,fileId,fileSize,fileMode,uid,gid,aTime,mTime,cTime,fileClass): - validtapepoolfileclass = [ ("atlas_new1",139), ("atlas_new2",139), ("atlas_small_07",139), ("atlas_new1",33), ("atlas_new2",33), ("atlas_small_07",33), ("atlas_new1",59), ("atlas_new2",59), ("atlas_small_07",59), ("atlas_stream_07",145)] - validtapepoolfileclasscopynb = [ ("atlas_new1",34,2), ("atlas_new2",34,1), ("atlas_new1",115,2), ("atlas_new2",115,1) ] - smallfilestapepool = "atlas_small_07" - resttapepool = [ "user_new" ] - myreturncode = migrationWithMC(tapePool,fileClass,fileSize,copynb,validtapepoolfileclass,validtapepoolfileclasscopynb,smallfilestapepool,resttapepool) - f = open('/tmp/atlsprodMigrPolicy','a') - f.writelines(str(tapePool)+' '+str(castorfilename)+' '+str(copynb)+' '+str(fileId)+' '+str(fileSize)+' '+str(fileMode)+' '+str(uid)+' '+str(gid)+' '+str(aTime)+' '+str(mTime)+' '+str(cTime)+' '+str(fileClass)+' '+str(myreturncode)+'\n') - return myreturncode - -#print atlasT0MigrPolicy("atlas_t0T_new","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",148) -#print atlasT0MigrPolicy("atlas_m4_07","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",2) -#print atlasT0MigrPolicy("user_new","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",2) -#print atlsprodMigrPolicy("atlas_new1","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_new1","castorfilename","copynb","fileId",1000000000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_new2","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_new2","castorfilename","copynb","fileId",1000000000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("atlas_small_07","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",139) -#print atlsprodMigrPolicy("user_new","castorfilename","copynb","fileId",1000,"fileMode","uid","gid","aTime","mTime","cTime",2) -# End-of-File - diff --git a/test/castor/tape/pythonmemory/testpythonmemory.sh b/test/castor/tape/pythonmemory/testpythonmemory.sh deleted file mode 100755 index 5d3e14a055538e813b02390f6fb592bbe6950d3e..0000000000000000000000000000000000000000 --- a/test/castor/tape/pythonmemory/testpythonmemory.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test "x$CASTOR_SRC" = x; then - echo "Error: The environment variable CASTOR_SRC is not set" - echo - echo "CASTOR_SRC should be the full path to the CASTOR source code, e.g." - echo - echo " export CASTOR_SRC=/usr/local/src/CASTOR_SVN_CO/trunk" - echo - exit -1 -fi - -LD_LIBRARY_PATH=`find $CASTOR_SRC -name '*.so*' | sed 's|/[^/]*$||' | sort | uniq` -LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | sed 's/ /:/g'` -PARAMS=$@ -CMD="export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; $CASTOR_SRC/test/castor/tape/pythonmemory/testpythonmemory $PARAMS" - -if test $USER = root; then - sudo -u stage sh -c "$CMD" -else - sh -c "$CMD" -fi