From 304b1ed1b992ca817dfcd57091c9d9623bb17ea7 Mon Sep 17 00:00:00 2001 From: tradke Date: Fri, 1 Feb 2008 16:25:43 +0000 Subject: send metadata updates as a transaction of individual remove/add statements git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@147 83718e91-0e4f-0410-abf4-91180603181f --- src/rdf.cc | 187 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 108 insertions(+), 79 deletions(-) diff --git a/src/rdf.cc b/src/rdf.cc index 49d2ab3..9377e05 100644 --- a/src/rdf.cc +++ b/src/rdf.cc @@ -107,17 +107,20 @@ namespace Formaline char* rundatebuf = Util_CurrentDateTime (); const string started_at (clean (rundatebuf)); free (rundatebuf); - char cwdbuf[512]; - getcwd (cwdbuf, sizeof (cwdbuf)); - const string cwd (clean (cwdbuf)); - + char buf[512] = ""; + getcwd (buf, sizeof (buf)); + const string cwd (clean (buf)); + buf[0] = 0; + CCTK_RunTitle (sizeof (buf) - 1, buf); + const string title (clean (buf)); msgbuf << "" << endl << "\t" << nprocs << "" << endl @@ -154,8 +159,8 @@ namespace Formaline << compiled_at << "" << endl << "\t" << started_at << "" << endl - << "\t" - << started_at << "" << endl; + << "\t" + << started_at << "" << endl; // // metadata as references to other nodes @@ -317,6 +322,24 @@ namespace Formaline } + static string AppendToTransaction(const string operation, + const string& subject, + const string& predicate, + const string& object) + { + ostringstream buf; + buf << "<" << operation << ">\n" + " &simID;" << subject << "\n" + " &cctk;" << predicate << "\n" + " " << object << "\n" + " \n" + " &context;\n" + " \n" + "\n\n"; + return buf.str(); + } + + void rdf::Update (cGH const * const cctkGH) { DECLARE_CCTK_PARAMETERS; @@ -348,56 +371,68 @@ namespace Formaline char* rundatebuf = Util_CurrentDateTime (); const string started_at (clean (rundatebuf)); + free (rundatebuf); static int publishedItems = 0; - msgbuf << "" << endl - << "\t" - << started_at << "" << endl; for (size_t i = 0; i < rdfPublishList.size(); i++) { - msgbuf << "\t" << endl; + ostringstream object; + object << "&simID;Publish/" << (publishedItems + i) << ""; + msgbuf << AppendToTransaction("add", jobID, "publish", object.str()); } - msgbuf << "" << endl << endl; for (size_t i = 0; i < rdfPublishList.size(); i++, publishedItems++) { const rdfPublishItem& item = rdfPublishList[i]; - msgbuf << "" << endl - << "\t" - << item.datetime << "" << endl - << "\t" << item.key << "" << endl; + ostringstream subject, object; + subject << "Publish/" << publishedItems; + object << "" << item.datetime << ""; + msgbuf << AppendToTransaction("add", subject.str(), "datetime", object.str()); + object.str(""); + object << "" << item.key << ""; + msgbuf << AppendToTransaction("add", subject.str(), "key", object.str()); if (not item.name.empty()) { - msgbuf << "\t" << item.name << "" << endl; + object.str(""); + object << "" << item.name << ""; + msgbuf << AppendToTransaction("add", subject.str(), "name", object.str()); } if (item.hasCCTKinfo) { - msgbuf << "\t" << item.cctk_time << "" << endl; - msgbuf << "\t" << item.cctk_iteration - << "" << endl; + object.str(""); + object << "" << item.cctk_time << ""; + msgbuf << AppendToTransaction("add", subject.str(), "time", object.str()); + object.str(""); + object << "" << item.cctk_iteration << ""; + msgbuf << AppendToTransaction("add", subject.str(), "iteration", object.str()); } + ostringstream tablebuf; if (item.isTable) { for (size_t j = 0; j < item.table.size(); j++) { const rdfTableEntry& entry = item.table[j]; - msgbuf << "\t" << endl; - tablebuf << "" << endl - << "\t" << entry.key << "" << endl - << "\t&simID;Publish/" << publishedItems << "/" << j << ""; + msgbuf << AppendToTransaction("add", subject.str(), "tableEntry", object.str()); + subject.str(""); + subject << "Publish/" << publishedItems << "/" << j; + object.str(""); + object << "" << entry.key << ""; + msgbuf << AppendToTransaction("add", subject.str(), "key", object.str()); + object.str(""); + object << "" << entry.value.value << "" << endl - << "" << endl; + object << ">" << entry.value.value << ""; + msgbuf << AppendToTransaction("add", subject.str(), "value", object.str()); } } else { - msgbuf << "\t" << item.scalar.value << "" << endl; + object << ">" << item.scalar.value << ""; + msgbuf << AppendToTransaction("add", subject.str(), "value", object.str()); } - msgbuf << "" << endl; - msgbuf << tablebuf.str(); } rdfPublishList.clear(); @@ -412,51 +447,42 @@ namespace Formaline // check if anything needs to be done if (msgbuf.str().empty()) return; + // this simulation's RDF context + const string context = "CactusSimulations:" + jobID; + const string contextURI = cleanURI("<" + context + ">"); + // RDF/XML document header with some namespace definitions - const string header = + string header = "\n" "\n" -"\t\n" -"\t\n" - -#if 0 - << "\t" << endl - << "\t" << endl - << "" << endl -#endif -"]>\n" -"\n" -#if 0 - << "" << endl - << "" << endl - << "" << endl -#endif -"\n\n"; +"\t\n" +"\t\n" +"\t\n" +"\t\n" +"\t\n" +"]>\n\n"; + if (get_state() == initial) { + header += "\n\n"; + } else { + header += "\n\n"; + } // RDF/XML document footer - const string footer = "\n\n"; + const string footer = get_state() == initial ? + "\n\n" : "\n\n"; + + if (get_state() != initial) { + char* dateBuffer = Util_CurrentDateTime(); + const string lastUpdated = "" + + clean(dateBuffer) + ""; + free(dateBuffer); + + msgbuf << AppendToTransaction("remove", jobID, "lastUpdated", ""); + msgbuf << AppendToTransaction("add", jobID, "lastUpdated", lastUpdated); + } const int len = header.length() + msgbuf.str().length() + footer.length(); @@ -470,13 +496,16 @@ namespace Formaline ostringstream databuf; databuf << (get_state() == initial ? "PUT" : "POST") -<< " /context/CactusSimulations/" << jobID; +<< " /openrdf-sesame/repositories/Simulations/statements" + "?context=" << contextURI << "&baseURI=" << contextURI; +//<< " /context/CactusSimulations/" << jobID; // set a metadata lifetime if requested by the user // (Formaline::time_to_live is hours but the RDF service wants seconds) - if (metadata_lifetime) databuf << "?ttl=" << (metadata_lifetime * 3600); + // if (metadata_lifetime) databuf << "?ttl=" << (metadata_lifetime * 3600); databuf << " HTTP/1.0\r\n" << "Host: " << rdf_hostname[i] << "\r\n" -<< "Content-Type: application/rdf+xml\r\n" +<< "Content-Type: application/" +<< (get_state() == initial ? "rdf+xml" : "x-rdftransaction") << "\r\n" << "Content-Length: " << len << "\r\n\r\n" << header << msgbuf.str() << footer << "\r\n\r\n"; -- cgit v1.2.3