From b037d4a6ad33f51c1133501561f1e239e08d7ea5 Mon Sep 17 00:00:00 2001 From: prascle Date: Thu, 20 Apr 2006 19:11:33 +0000 Subject: [PATCH] PR: add service for large file transfer via CORBA --- idl/SALOME_Component.idl | 69 ++++-- src/Container/Container_i.cxx | 59 ++++++ src/Container/Makefile.am | 4 + src/Container/SALOME_Container_i.hxx | 9 +- src/Container/SALOME_FileRef_i.cxx | 180 ++++++++++++++++ src/Container/SALOME_FileRef_i.hxx | 63 ++++++ src/Container/SALOME_FileTransfer_i.cxx | 129 +++++++++++ src/Container/SALOME_FileTransfer_i.hxx | 55 +++++ src/LifeCycleCORBA/Makefile.am | 10 +- .../SALOME_FileTransferCORBA.cxx | 200 ++++++++++++++++++ .../SALOME_FileTransferCORBA.hxx | 57 +++++ src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 15 +- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx | 2 + .../Test/LifeCycleCORBATest.cxx | 41 +++- .../Test/LifeCycleCORBATest.hxx | 5 +- src/LifeCycleCORBA/Test_LifeCycleCORBA.cxx | 67 +++--- 16 files changed, 913 insertions(+), 52 deletions(-) create mode 100644 src/Container/SALOME_FileRef_i.cxx create mode 100644 src/Container/SALOME_FileRef_i.hxx create mode 100644 src/Container/SALOME_FileTransfer_i.cxx create mode 100644 src/Container/SALOME_FileTransfer_i.hxx create mode 100644 src/LifeCycleCORBA/SALOME_FileTransferCORBA.cxx create mode 100644 src/LifeCycleCORBA/SALOME_FileTransferCORBA.hxx diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index bb0990030..7e0ad5c80 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -25,6 +25,7 @@ #ifndef _SALOME_COMPONENT_IDL_ #define _SALOME_COMPONENT_IDL_ + /*! This is a package of interfaces used for connecting new components to %SALOME application. It also contains a set of interfaces used for management of %MED @@ -50,6 +51,8 @@ module Engines typedef sequence FieldsDict; interface Component ; + interface fileRef ; + interface fileTransfer ; /*! \brief Interface of the %Container This interface defines the process of loading and registration @@ -148,25 +151,20 @@ module Engines */ boolean Kill_impl() ; - // -------------------------- removed ------------------------------- - /*! - Loads into the container a new component, registers it and starts it's - CORBA servant. - \param nameToRegister Name used to register in Naming Service, - the component instance - \param componentName Name of the %component - \return a new instance of the component or the registered component - if already registered or Nil if not possible + returns a fileRef object if origFileName exists and is readable + else returns null object. Only one fileRef is created for a given + file name, so, several calls with the same file name returns the + same object. */ - // Component instance(in string nameToRegister, in string componentName); - + fileRef createFileRef(in string origFileName); /*! - Name of the machine containing this container (location of the container). + returns a fileTransfer object used to copy files from the container + machine to the clients machines. Only one fileTransfer instance is + created in a container. */ - // readonly attribute string machineName ; - + fileTransfer getFileTransfer(); }; @@ -280,6 +278,49 @@ module Engines out boolean isValidScript); } ; + + typedef sequence fileBlock; + + /*! + file transfer object. open method returns a key (fileId) that identifies + the structure (ex: C FILE) on the server, created for transfer. + */ + interface fileTransfer + { + long open(in string fileName); + + void close(in long fileId); + + fileBlock getBlock(in long fileId); + }; + + /*! + A fileRef object is associated to an original file (origFileName) on a + machine (refMachine). + It is created by a container (factoryServer) on refMachine, + with createFileRef(in string origFileName) method. + fileRef object maintains a list of (machine,filename) for copies. + If a copy exists on myMachine, getRef(myMachine) returns the file name + of the copy on myMachine, else returns empy string. + If there is no copy on myMachine, method getFileTransfer() from container + factoryServer on refMachine provides a fileTransfer object dedicated to + CORBA file copy. + After the copy, addRef(myMachine, localFileNameOnMyMachine) registers + the file name of the copy on myMachine. + */ + interface fileRef + { + readonly attribute string origFileName; + readonly attribute string refMachine; + + Container getContainer(); + + boolean addRef(in string machine, + in string fileName); + + string getRef(in string machine); + }; + } ; #endif diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 0af3362a3..7c3063295 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -51,6 +51,8 @@ int SIGUSR1 = 1000; #include // must be before Python.h ! #include "SALOME_Container_i.hxx" #include "SALOME_Component_i.hxx" +#include "SALOME_FileRef_i.hxx" +#include "SALOME_FileTransfer_i.hxx" #include "SALOME_NamingService.hxx" #include "OpUtil.hxx" @@ -189,6 +191,9 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, PyRun_SimpleString((char*)myCommand.c_str()); Py_RELEASE_NEW_THREAD; } + + fileTransfer_i* aFileTransfer = new fileTransfer_i(); + _fileTransfer = Engines::fileTransfer::_narrow(aFileTransfer->_this()); } } @@ -578,6 +583,60 @@ bool Engines_Container_i::Kill_impl() return false; } +//============================================================================= +/*! + * CORBA method: get or create a fileRef object associated to a local file + * (a file on the computer on which runs the container server), which stores + * a list of (machine, localFileName) corresponding to copies already done. + * + * \param origFileName absolute path for a local file to copy on other + * computers + * \return a fileRef object associated to the file. + */ +//============================================================================= + +Engines::fileRef_ptr +Engines_Container_i::createFileRef(const char* origFileName) +{ + string origName(origFileName); + Engines::fileRef_var theFileRef = Engines::fileRef::_nil(); + + if (origName[0] != '/') + { + INFOS("path of file to copy must be an absolute path begining with '/'"); + return Engines::fileRef::_nil(); + } + + if (CORBA::is_nil(_fileRef_map[origName])) + { + CORBA::Object_var obj=_poa->id_to_reference(*_id); + Engines::Container_var pCont = Engines::Container::_narrow(obj); + fileRef_i* aFileRef = new fileRef_i(pCont, origFileName); + theFileRef = Engines::fileRef::_narrow(aFileRef->_this()); + _fileRef_map[origName] = theFileRef; + } + + theFileRef = Engines::fileRef::_duplicate(_fileRef_map[origName]); + ASSERT(! CORBA::is_nil(theFileRef)); + return theFileRef._retn(); +} + +//============================================================================= +/*! + * CORBA method: + * \return a reference to the fileTransfer object + */ +//============================================================================= + +Engines::fileTransfer_ptr +Engines_Container_i::getFileTransfer() +{ + Engines::fileTransfer_var aFileTransfer + = Engines::fileTransfer::_duplicate(_fileTransfer); + return aFileTransfer._retn(); +} + + //============================================================================= /*! * C++ method: Finds an already existing servant instance of a component, or diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index df8f5b8f2..f160095b7 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -38,6 +38,8 @@ include $(top_srcdir)/salome_adm/unix/make_common_starter.am salomeinclude_HEADERS = \ SALOME_Component_i.hxx \ SALOME_Container_i.hxx \ + SALOME_FileTransfer_i.hxx \ + SALOME_FileRef_i.hxx \ SALOME_ContainerManager.hxx \ Container_init_python.hxx @@ -96,6 +98,8 @@ lib_LTLIBRARIES = libSalomeContainer.la libSalomeContainer_la_SOURCES=\ Component_i.cxx \ Container_i.cxx \ + SALOME_FileTransfer_i.cxx \ + SALOME_FileRef_i.cxx \ SALOME_ContainerManager.cxx \ Container_init_python.cxx diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index b3b6db4f3..6b1e96c38 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -100,10 +100,11 @@ public: char* getHostName(); CORBA::Long getPID(); //! Kill current container - bool Kill_impl() ; + bool Kill_impl(); + + Engines::fileRef_ptr createFileRef(const char* origFileName); + Engines::fileTransfer_ptr getFileTransfer(); - //Engines::Component_ptr instance(const char* nameToRegister, - // const char* componentName); // --- local C++ methods @@ -142,6 +143,8 @@ protected: PortableServer::ObjectId * _id ; int _numInstance ; std::map _listInstances_map; + std::map _fileRef_map; + Engines::fileTransfer_var _fileTransfer; int _argc ; char** _argv ; diff --git a/src/Container/SALOME_FileRef_i.cxx b/src/Container/SALOME_FileRef_i.cxx new file mode 100644 index 000000000..87d65d992 --- /dev/null +++ b/src/Container/SALOME_FileRef_i.cxx @@ -0,0 +1,180 @@ +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_FileRef_i.cxx +// Author : Paul RASCLE, EDF +// Module : SALOME +// $Header$ + +#include "SALOME_FileRef_i.hxx" +#include "utilities.h" +#include "OpUtil.hxx" +#include + +using namespace std; + +//============================================================================= +/*! + * Default constructor, not for use + */ +//============================================================================= + +fileRef_i::fileRef_i() +{ + ASSERT(0); +} +//============================================================================= +/*! + * Constructor to use + */ +//============================================================================= + +fileRef_i::fileRef_i(Engines::Container_ptr container, + const char* origFileName) +{ + MESSAGE("fileRef_i::fileRef_i "<< origFileName); + _container = Engines::Container::_duplicate(container); + _origFileName = origFileName; + _machine = GetHostname(); + int OK = addRef(_machine.c_str(), _origFileName.c_str()); + SCRUTE(OK); +} + + +//============================================================================= +/*! + * Destructor + */ +//============================================================================= + +fileRef_i::~fileRef_i() +{ + MESSAGE("fileRef_i::~fileRef_i"); +} + +//============================================================================= +/*! + * CORBA method: + * \return the file name (absolute path) on the computer which runs the + * container server + */ +//============================================================================= + +char* fileRef_i::origFileName() +{ + MESSAGE("fileRef_i::origFileName " << _origFileName); + return CORBA::string_dup(_origFileName.c_str()); +} + +//============================================================================= +/*! + * CORBA method: + * \return the hostname of the computer which runs the container server + */ +//============================================================================= + +char* fileRef_i::refMachine() +{ + MESSAGE("fileRef_i::refMachine " << _machine); + return CORBA::string_dup(_machine.c_str()); +} + +//============================================================================= +/*! + * CORBA method: + * \return the container reference + */ +//============================================================================= + +Engines::Container_ptr fileRef_i::getContainer() +{ + MESSAGE("fileRef_i::getContainer"); + Engines::Container_var theContainer = + Engines::Container::_duplicate(_container); + return theContainer._retn(); +} + +//============================================================================= +/*! + * CORBA method: after a file transfer on a client computer, registers + * hostname of client and file path of the copied file. + * \param machine client hostname + * \param fileName asolute path of the transfered file on client computer + */ +//============================================================================= + +CORBA::Boolean fileRef_i::addRef(const char* machine, + const char* fileName) +{ + MESSAGE("fileRef_i::addRef " << machine << " " << fileName); + string theMachine = machine; + string theFileName = fileName; + + if (theFileName[0] != '/') + { + INFOS("destination file path must be absolute, begining with '/'"); + return 0; + } + + if (theMachine.empty()) + { + INFOS("provide a hostname for the copy destination"); + return 0; + } + + if (! _copies[theMachine].empty()) + { + INFOS("there is already a copy on " << theMachine << " under the path " + << _copies[theMachine] << " new ref not added! "); + return 0; + } + + _copies[theMachine] = theFileName; + return 1; +} + +//============================================================================= +/*! + * CORBA method: check if a copy of the file referenced by fileRef is + * available on the client computer. + * \param machine hostname of the client computer + * \return path of the copy on the client computer, if the copy exists, + * else empty string + */ +//============================================================================= + +char* fileRef_i::getRef(const char* machine) +{ + MESSAGE("fileRef_i::getRef "<< machine); + string theMachine = machine; + string theFileName = _copies[theMachine]; + if (_copies[theMachine].empty()) + { + MESSAGE("no copy of " << _machine << _origFileName << " available on " + << theMachine); + } + else + { + MESSAGE("a copy of " << _machine << _origFileName << "is available on " + << theMachine << _copies[theMachine]); + } + return CORBA::string_dup(_copies[theMachine].c_str()); +} + diff --git a/src/Container/SALOME_FileRef_i.hxx b/src/Container/SALOME_FileRef_i.hxx new file mode 100644 index 000000000..b2fc11f0a --- /dev/null +++ b/src/Container/SALOME_FileRef_i.hxx @@ -0,0 +1,63 @@ +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_FileRef_i.hxx +// Author : Paul RASCLE, EDF +// Module : SALOME +// $Header$ + +#ifndef _SALOME_FILEREF_I_HXX_ +#define _SALOME_FILEREF_I_HXX_ + +#include +#include CORBA_SERVER_HEADER(SALOME_Component) + +#include +#include + +class fileRef_i: + public virtual POA_Engines::fileRef, + public virtual PortableServer::RefCountServantBase +{ +public: + fileRef_i(); + fileRef_i(Engines::Container_ptr container, + const char* origFileName); + virtual ~fileRef_i(); + + char* origFileName(); + + char* refMachine(); + + Engines::Container_ptr getContainer(); + + CORBA::Boolean addRef(const char* machine, + const char* fileName); + + char* getRef(const char* machine); + +protected: + Engines::Container_var _container; + std::string _origFileName; + std::string _machine; + std::map _copies; +}; + +#endif diff --git a/src/Container/SALOME_FileTransfer_i.cxx b/src/Container/SALOME_FileTransfer_i.cxx new file mode 100644 index 000000000..d487a8c01 --- /dev/null +++ b/src/Container/SALOME_FileTransfer_i.cxx @@ -0,0 +1,129 @@ + +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_FileTransfer_i.cxx +// Author : Paul RASCLE, EDF +// Module : SALOME +// $Header$ + +#include "SALOME_FileTransfer_i.hxx" +#include "utilities.h" + +//============================================================================= +/*! + * Default constructor, + */ +//============================================================================= + +fileTransfer_i::fileTransfer_i() +{ + MESSAGE("fileTransfer_i::fileTransfer_i"); + _fileKey=1; +} + +//============================================================================= +/*! + * Destructor + */ +//============================================================================= + +fileTransfer_i::~fileTransfer_i() +{ + MESSAGE("fileTransfer_i::~fileTransfer_i"); +} + + +//============================================================================= +/*! + * CORBA method: try to open the file given. If the file is readable, return + * a positive integer else return 0; + * \param fileName path to the file to be transfered + * \return fileId = positive integer > 0 if open OK. + */ +//============================================================================= + +CORBA::Long fileTransfer_i::open(const char* fileName) +{ + MESSAGE(" fileTransfer_i::open " << fileName); + int aKey = _fileKey++; + _ctr=0; + FILE* fp; + if ((fp = fopen(fileName,"rb")) == NULL) + { + INFOS("file " << fileName << " is not readable"); + return 0; + } + _fileAccess[aKey] = fp; + return aKey; +} + +//============================================================================= +/*! + * CORBA method: close the file associated to the fileId given at open. + * \param fileId got in return from open method + */ +//============================================================================= + +void fileTransfer_i::close(CORBA::Long fileId) +{ + MESSAGE("fileTransfer_i::close"); + FILE* fp; + if (! (fp = _fileAccess[fileId]) ) + { + INFOS(" no FILE structure associated to fileId " <replace(nbRed, nbRed, buf, 1); // 1 means give ownership + return aBlock; +} + diff --git a/src/Container/SALOME_FileTransfer_i.hxx b/src/Container/SALOME_FileTransfer_i.hxx new file mode 100644 index 000000000..7b0947089 --- /dev/null +++ b/src/Container/SALOME_FileTransfer_i.hxx @@ -0,0 +1,55 @@ +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_FileTransfer_i.hxx +// Author : Paul RASCLE, EDF +// Module : SALOME +// $Header$ + + +#ifndef _SALOME_FILETRANSFER_I_HXX_ +#define _SALOME_FILETRANSFER_I_HXX_ + +#include +#include CORBA_SERVER_HEADER(SALOME_Component) +#include +#include + +class fileTransfer_i: + public virtual POA_Engines::fileTransfer, + public virtual PortableServer::RefCountServantBase +{ +public: + fileTransfer_i(); + virtual ~fileTransfer_i(); + + CORBA::Long open(const char* fileName); + + void close(CORBA::Long fileId); + + Engines::fileBlock* getBlock(CORBA::Long fileId); + +protected: + int _fileKey; + std::map _fileAccess; + int _ctr; +}; + +#endif diff --git a/src/LifeCycleCORBA/Makefile.am b/src/LifeCycleCORBA/Makefile.am index 2b48a6be2..2eca53f10 100644 --- a/src/LifeCycleCORBA/Makefile.am +++ b/src/LifeCycleCORBA/Makefile.am @@ -35,11 +35,12 @@ include $(top_srcdir)/salome_adm/unix/make_common_starter.am # # header files salomeinclude_HEADERS = \ - SALOME_LifeCycleCORBA.hxx + SALOME_LifeCycleCORBA.hxx \ + SALOME_FileTransferCORBA.hxx # Scripts to be installed -dist_salomescript_DATA =\ - Launchers.py +#dist_salomescript_DATA =\ +# Launchers.py # # =============================================================== @@ -77,8 +78,7 @@ COMMON_LIBS =\ lib_LTLIBRARIES = libSalomeLifeCycleCORBA.la libSalomeLifeCycleCORBA_la_SOURCES = \ SALOME_LifeCycleCORBA.cxx \ - Launchers.cxx \ - Launchers.hxx + SALOME_FileTransferCORBA.cxx libSalomeLifeCycleCORBA_la_CPPFLAGS = \ $(COMMON_CPPFLAGS) \ @PYTHON_INCLUDES@ \ diff --git a/src/LifeCycleCORBA/SALOME_FileTransferCORBA.cxx b/src/LifeCycleCORBA/SALOME_FileTransferCORBA.cxx new file mode 100644 index 000000000..522ed88ca --- /dev/null +++ b/src/LifeCycleCORBA/SALOME_FileTransferCORBA.cxx @@ -0,0 +1,200 @@ +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_FileTransferCORBA.cxx +// Author : Paul RASCLE, EDF +// Module : SALOME +// $Header$ + +#include "SALOME_FileTransferCORBA.hxx" +#include "SALOME_LifeCycleCORBA.hxx" +#include "utilities.h" +#include "OpUtil.hxx" + +using namespace std; + +//============================================================================= +/*! + * Default constructor, not for use + */ +//============================================================================= + +SALOME_FileTransferCORBA::SALOME_FileTransferCORBA() +{ + ASSERT(0); +} + +//============================================================================= +/*! + * Constructor to use when we get a fileRef CORBA object from a component + * \param aFileRef file reference CORBA object + */ +//============================================================================= + +SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(Engines::fileRef_ptr + aFileRef) +{ + MESSAGE("SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(aFileRef)"); + _theFileRef = aFileRef; +} + +//============================================================================= +/*! + * Constructor to use we the file name and machine from which to copy, plus + * an optional Container name on the machine + * \param refMachine the machine on which is the file to transfer + * \param origFileName abolute file path on refMachine + * \param containerName default container name used (FactoryServer) if empty + */ +//============================================================================= + +SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(string refMachine, + string origFileName, + string containerName) +{ + MESSAGE("SALOME_FileTransferCORBA::SALOME_FileTransferCORBA" + << refMachine << " " << origFileName << " " << containerName); + _refMachine = refMachine; + _origFileName = origFileName; + _containerName = containerName; + if (_refMachine.empty() or _origFileName.empty()) + { + INFOS("bad parameters: machine and file name must be given"); + } +} + +//============================================================================= +/*! + * Destructor + */ +//============================================================================= + +SALOME_FileTransferCORBA::~SALOME_FileTransferCORBA() +{ + MESSAGE("SALOME_FileTransferCORBA::~SALOME_FileTransferCORBA"); +} + +//============================================================================= +/*! + * CORBA method: get a local copy of the reference file + * \param localFile optional absolute path to store the copt + * \return the file name (absolute path) of the copy, may be different from + * localFile parameter if the copy was already done before the call + */ +//============================================================================= + +string SALOME_FileTransferCORBA::getLocalFile(string localFile) +{ + MESSAGE("SALOME_FileTransferCORBA::getLocalFile"); + + Engines::Container_var container; + + if (CORBA::is_nil(_theFileRef)) + { + if (_refMachine.empty() or _origFileName.empty()) + { + INFOS("not enough parameters: machine and file name must be given"); + return ""; + } + + SALOME_LifeCycleCORBA LCC; + Engines::ContainerManager_var contManager = LCC.getContainerManager(); + + Engines::MachineParameters params; + LCC.preSet(params); + params.container_name = _containerName.c_str(); + params.hostname = _refMachine.c_str(); + + Engines::MachineList_var listOfMachines = + contManager->GetFittingResources(params, ""); + + container = contManager->FindOrStartContainer(params, + listOfMachines); + if (CORBA::is_nil(container)) + { + INFOS("machine " << _refMachine << " unreachable"); + return ""; + } + + _theFileRef = container->createFileRef(_origFileName.c_str()); + if (CORBA::is_nil(_theFileRef)) + { + INFOS("imposssible to create fileRef on " << _refMachine); + return ""; + } + } + + container = _theFileRef->getContainer(); + ASSERT(! CORBA::is_nil(container)); + + string myMachine = GetHostname(); + string localCopy = _theFileRef->getRef(myMachine.c_str()); + + if (localCopy.empty()) + { + if (localFile.empty()) + { + char bufName[256]; + localCopy = tmpnam(bufName); + localFile = bufName; + SCRUTE(localFile); + } + + FILE* fp; + if ((fp = fopen(localFile.c_str(),"wb")) == NULL) + { + INFOS("file " << localFile << " cannot be open for writing"); + return ""; + } + + Engines::fileTransfer_var fileTransfer = container->getFileTransfer(); + ASSERT(! CORBA::is_nil(fileTransfer)); + + CORBA::Long fileId = fileTransfer->open(_origFileName.c_str()); + if (fileId > 0) + { + Engines::fileBlock* aBlock; + int toFollow = 1; + int ctr=0; + while (toFollow) + { + ctr++; + SCRUTE(ctr); + aBlock = fileTransfer->getBlock(fileId); + toFollow = aBlock->length(); + SCRUTE(toFollow); + CORBA::Octet *buf = aBlock->get_buffer(); + int nbWri = fwrite(buf, sizeof(CORBA::Octet), toFollow, fp); + ASSERT(nbWri == toFollow); + } + MESSAGE("end of transfer"); + fileTransfer->close(fileId); + _theFileRef->addRef(myMachine.c_str(), localFile.c_str()); + } + else + { + INFOS("open reference file for copy impossible"); + return ""; + } + + } + SCRUTE(localCopy); + return localCopy; +} diff --git a/src/LifeCycleCORBA/SALOME_FileTransferCORBA.hxx b/src/LifeCycleCORBA/SALOME_FileTransferCORBA.hxx new file mode 100644 index 000000000..8fc0589dd --- /dev/null +++ b/src/LifeCycleCORBA/SALOME_FileTransferCORBA.hxx @@ -0,0 +1,57 @@ +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_FileTransferCORBA.hxx +// Author : Paul RASCLE, EDF +// Module : SALOME +// $Header$ + +#ifndef _SALOME_FILETRANSFERCORBA_HXX_ +#define _SALOME_FILETRANSFERCORBA_HXX_ + + +#include +#include + +#include CORBA_CLIENT_HEADER(SALOME_Component) + +#include + +class SALOME_FileTransferCORBA +{ +public: + SALOME_FileTransferCORBA(); + SALOME_FileTransferCORBA(Engines::fileRef_ptr aFileRef); + SALOME_FileTransferCORBA(std::string refMachine, + std::string origFileName, + std::string containerName=""); + + virtual ~SALOME_FileTransferCORBA(); + + std::string getLocalFile(std::string localFile = ""); + +protected: + Engines::fileRef_var _theFileRef; + std::string _refMachine; + std::string _origFileName; + std::string _containerName; +}; + +#endif diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 60e22e909..648dde7b1 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -48,7 +48,6 @@ #include "SALOME_ContainerManager.hxx" #include "SALOME_Component_i.hxx" #include "SALOME_NamingService.hxx" -#include "Launchers.hxx" using namespace std; @@ -360,6 +359,20 @@ int SALOME_LifeCycleCORBA::NbProc(const Engines::MachineParameters& params) return params.nb_node * params.nb_proc_per_node; } +//============================================================================= +/*! Public - + * \return the container Manager + */ +//============================================================================= + +Engines::ContainerManager_ptr SALOME_LifeCycleCORBA::getContainerManager() +{ + Engines::ContainerManager_var contManager = + Engines::ContainerManager::_duplicate(_ContManager); + return contManager._retn(); +} + + //============================================================================= /*! Protected - * Find and aready existing and registered component instance. diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx index dea15255f..27e614103 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx @@ -98,6 +98,8 @@ public: void preSet(Engines::MachineParameters& params); + Engines::ContainerManager_ptr getContainerManager(); + protected: /*! Establish if a component called "componentName" in a container called diff --git a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx index fed326885..8da9f84ae 100644 --- a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx +++ b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx @@ -20,6 +20,7 @@ #include "LifeCycleCORBATest.hxx" #include "SALOME_LifeCycleCORBA.hxx" +#include "SALOME_FileTransferCORBA.hxx" #include "Utils_ORB_INIT.hxx" #include "Utils_SINGLETON.hxx" #include "OpUtil.hxx" @@ -609,7 +610,43 @@ LifeCycleCORBATest::testFindOrLoad_Component_ParamsRemoteComputer2() CPPUNIT_ASSERT_EQUAL(hostname1, remoteHost); } +// ============================================================================ +/*! + * Check SALOME_FileTransferCORBA on local machine + */ +// ============================================================================ + +void LifeCycleCORBATest::testgetLocalFile_localComputer() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + string origFileName = getenv("KERNEL_ROOT_DIR"); + origFileName += "/lib/salome/libSalomeLifeCycleCORBA.so.0.0.0"; + SALOME_FileTransferCORBA transfer( GetHostname(), + origFileName); + string local = transfer.getLocalFile(); + CPPUNIT_ASSERT(!local.empty()); + CPPUNIT_ASSERT_EQUAL(local, origFileName); +} + +// ============================================================================ +/*! + * Check SALOME_FileTransferCORBA on remote machine + */ +// ============================================================================ +void LifeCycleCORBATest::testgetLocalFile_remoteComputer() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + string origFileName = getenv("KERNEL_ROOT_DIR"); + origFileName += "/lib/salome/libSalomeContainer.so.0.0.0"; + SALOME_FileTransferCORBA transfer( GetRemoteHost(), + origFileName); + string local = transfer.getLocalFile(); + CPPUNIT_ASSERT(!local.empty()); + string local2 = transfer.getLocalFile(); + CPPUNIT_ASSERT(!local2.empty()); + CPPUNIT_ASSERT_EQUAL(local, local2); +} // ============================================================================ /*! @@ -625,10 +662,6 @@ LifeCycleCORBATest::testFindOrLoad_Component_ParamsRemoteComputer2() - - - - // ============================================================================ /*! * Get a remote HostName in the Resource Catalog diff --git a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx index 401a03978..c11dd24ec 100644 --- a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx +++ b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx @@ -45,7 +45,8 @@ class LifeCycleCORBATest : public CppUnit::TestFixture CPPUNIT_TEST( testFindOrLoad_Component_RemoteComputer ); CPPUNIT_TEST( testFindOrLoad_Component_ParamsRemoteComputer ); CPPUNIT_TEST( testFindOrLoad_Component_ParamsRemoteComputer2 ); -// CPPUNIT_TEST( testFindOrLoad_Component_ ); + CPPUNIT_TEST( testgetLocalFile_localComputer ); + CPPUNIT_TEST( testgetLocalFile_remoteComputer ); // CPPUNIT_TEST( testFindOrLoad_Component_ ); // CPPUNIT_TEST( ); // CPPUNIT_TEST( ); @@ -70,6 +71,8 @@ public: void testFindOrLoad_Component_RemoteComputer(); void testFindOrLoad_Component_ParamsRemoteComputer(); void testFindOrLoad_Component_ParamsRemoteComputer2(); + void testgetLocalFile_localComputer(); + void testgetLocalFile_remoteComputer(); // void testFindOrLoad_Component_(); // void testFindOrLoad_Component_(); diff --git a/src/LifeCycleCORBA/Test_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/Test_LifeCycleCORBA.cxx index d4247492d..8c88a63a2 100644 --- a/src/LifeCycleCORBA/Test_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/Test_LifeCycleCORBA.cxx @@ -40,6 +40,7 @@ #endif #include "SALOME_NamingService.hxx" #include "SALOME_LifeCycleCORBA.hxx" +#include "SALOME_FileTransferCORBA.hxx" #include "utilities.h" #include @@ -50,72 +51,90 @@ int main (int argc, char * argv[]) try { - // Initializing omniORB + // --- Initialize omniORB + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); - // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); - // Obtain a reference to the root POA + // --- Obtain a reference to the root POA + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ; PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ; + + // --- Naming Service and LifeCycleCORBA interfaces SALOME_NamingService _NS(orb) ; - SALOME_LifeCycleCORBA _LCC(&_NS) ; - // get a local container (with a name based on local hostname), - // load an engine, and invoque methods on that engine - - string containerName = GetHostname(); + // --- get a local container, + // load an engine, and invoque methods on that engine - cout << containerName << endl; - cout << "FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" << endl; + string containerName = "myServer"; MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" ); Engines::Component_var mycompo = _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); - ASSERT(!CORBA::is_nil(mycompo)); - Engines::TestComponent_var m1; m1 = Engines::TestComponent::_narrow(mycompo); - ASSERT(!CORBA::is_nil(m1)); - SCRUTE(m1->instanceName()); MESSAGE("Coucou " << m1->Coucou(1L)); - // get another container (with a fixed name), - // load an engine, and invoque methods on that engine + // --- get another container, + // load an engine, and invoque methods on that engine - string containerName2 = "FactoryServerPy"; + string containerName2 = "otherServer"; Engines::Component_var mycompo2 = _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy"); - ASSERT(!CORBA::is_nil(mycompo2)); - Engines::TestComponent_var m2; m2 = Engines::TestComponent::_narrow(mycompo2); - ASSERT(!CORBA::is_nil(m2)); - SCRUTE(m2->instanceName()); cout << m2->instanceName() << endl; MESSAGE("Coucou " << m2->Coucou(1L)); - Engines::Component_var mycompo3 = _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy"); + // --- get a third container, + // load an engine, and invoque methods on that engine + + Engines::Component_var mycompo3 = + _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy"); ASSERT(!CORBA::is_nil(mycompo3)); Engines::TestComponent_var m3 = Engines::TestComponent::_narrow(mycompo3); ASSERT(!CORBA::is_nil(m3)); cout << m3->instanceName() << endl; - string containerName4 = containerName + "/titiPy"; - Engines::Component_var mycompo4 = _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy"); + // --- yet another container, with hostname, + // load an engine, and invoque methods on that engine + + string containerName4 = GetHostname(); + containerName4 += "/titiPy"; + Engines::Component_var mycompo4 = + _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy"); ASSERT(!CORBA::is_nil(mycompo4)); Engines::TestComponent_var m4 = Engines::TestComponent::_narrow(mycompo4); ASSERT(!CORBA::is_nil(m4)); cout << m4->instanceName() << endl; + // --- try a local file transfer + + string origFileName = "/home/prascle/petitfichier"; + SALOME_FileTransferCORBA transfer( GetHostname(), + origFileName); + string local = transfer.getLocalFile(); + SCRUTE(local); + + // --- try a file transfer from another computer + + origFileName = "/home/prascle/occ60.tgz"; + SALOME_FileTransferCORBA transfer2( "cli76ce", + origFileName); + local = transfer2.getLocalFile(); + SCRUTE(local); + local = transfer2.getLocalFile(); + SCRUTE(local); + } catch(CORBA::SystemException& ex) { -- 2.39.2