Commit 73cb1310 authored by Robert Maynard's avatar Robert Maynard
Browse files

MeshOperator now deletes any temporary mesh files that the worker generates.

When a Mesh Worker has finished it currently generates a temporary file
to store the mesh results. This file is now deleted by the MeshOperator, so
that we don't leave around bad mesh files.

In the future all this logic should be handled by remus, once it has
support for remote FileHandles, and remus::JobResult can list multiple files
generated by the worker.
parent 17a1e4e2
......@@ -26,6 +26,12 @@
#include "smtk/io/ExportJSON.txx"
#include "smtk/io/ImportJSON.h"
//todo: remove this once remus supports automatic transfer of FileHandles
// and Destructive Read of FileHandles
//force to use filesystem version 3
#define BOOST_FILESYSTEM_VERSION 3
#include <boost/filesystem.hpp>
//todo: remove this once remus Issue #183 has been resolved.
// #include <boost/date_time/posix_time/posix_time.hpp>
// #include <boost/thread/thread.hpp>
......@@ -148,15 +154,46 @@ OperatorResult MeshOperator::operateInternal()
if(haveResultFromWorker)
{
//now fetch the latest results from the server
remus::proto::JobResult updatedModel = client.retrieveResults(job);
remus::proto::JobResult meshMetaData = client.retrieveResults(job);
//parse the job result as a json string
smtk::io::ImportJSON::intoModelManager(updatedModel.data(), this->manager());
//determine all existing collection
typedef std::map< smtk::common::UUID, smtk::mesh::CollectionPtr > CollectionStorage;
CollectionStorage existingCollections(this->manager()->collectionBegin(),
this->manager()->collectionEnd());
cJSON* root = cJSON_Parse(updatedModel.data());
//parse the job result as json mesh data
cJSON* root = cJSON_Parse(meshMetaData.data());
smtk::io::ImportJSON::ofMeshesOfModel(root, this->manager());
cJSON_Delete(root);
//
//iterate over all collections looking for new collections. When we find
//a new mesh collection, we will delete the file that was used to generate
//that collection, as that file is meant to be temporary and only exist
//for data transfer back from the worker.
//
//This all should be removed, and instead remus should handle all this logic
//
//
//
for(smtk::mesh::Manager::const_iterator i = this->manager()->collectionBegin();
i != this->manager()->collectionEnd();
++i)
{
smtk::mesh::CollectionPtr collection = i->second;
smtk::mesh::UUID collectionUUID = i->first;
if( existingCollections.find(collectionUUID) == existingCollections.end())
{ //found a new collection
std::string location = collection->readLocation();
if(!location.empty())
{ //delete the file if it exists
::boost::filesystem::path cpath( location );
::boost::filesystem::remove( cpath );
}
collection->clearReadWriteLocations();
}
}
//mark all models and submodels as modified
smtk::model::Models allModels = models;
for(smtk::model::Models::const_iterator m = models.begin();
......
......@@ -181,6 +181,14 @@ void Collection::writeLocation(const std::string& n)
this->m_writeLocation = n;
}
//----------------------------------------------------------------------------
void Collection::clearReadWriteLocations()
{
this->m_readLocation.clear();
this->m_writeLocation.clear();
}
//----------------------------------------------------------------------------
std::string Collection::interfaceName() const
{
......
......@@ -82,6 +82,11 @@ public:
void writeLocation(const std::string& path);
const std::string& writeLocation() const;
//clear both the read and write locations for the collection. This
//is generally done when de-serializing a collection and the read and write
//locations are going to be deleted by the calling code.
void clearReadWriteLocations();
//get a string the identifies the interface type of the collection
// valid types are:
// "moab"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment