// dataset_property_t.cxx #include #include #include #include "dataset_util/ssystem.h" #include "dataset_util/getcwd.h" #include "dataset_util/mkdir.h" #include "dataset_util/FileName.h" #include "dataset_util/FileStatus.h" #include "dataset_sql/SqlResultTable.h" #include "dataset_id/SimpleUniqueIdGenerator.h" #include "dataset_xml/XmlParser.h" #include "dataset_catalog/ConnectionResolver.h" #include "dataset_catalog/DatasetSelectionCatalog.h" #include "dataset_credential/CredentialSelectionCatalog.h" #include "dataset_credential/GssCredentialManager.h" #include "dataset_base/Location.h" #include "dataset_base/Dataset.h" #include "dataset_base/DatasetRepository.h" #include "dataset_base/SimpleCompoundDataset.h" #include "dataset_base/Dataset_t.h" using std::string; using std::cout; using std::endl; using std::ostringstream; using dset::SqlResult; using dset::SqlResultTable; using dset::ConnectionResolver; using dset::Url; using dset::DatasetSelectionCatalog; using dset::CredentialSelectionCatalog; using dset::GssCredentialManager; using dset::Content; using dset::Location; using dset::Dataset; using dset::DatasetList; using dset::DatasetRepository; using dset::SimpleCompoundDataset; typedef DatasetSelectionCatalog::Attributes Attributes; void msg(string txt) { cout << "----- "; cout << txt; cout << " -----" << endl; } int dataset_property_t() { system("rm resolver.dat dr.dat"); system("rm -f dataset.dtd mydst1.xml mydst2.xml mydst3.xml"); system("rm -rf a.dat b.dat out.dat mydb"); system("rm -rf UniqueId"); SimpleUniqueIdGenerator::create_collection("Dataset", 123, 1001); SimpleUniqueIdGenerator::set_as_default(); msg("Create default DR and DSC"); DatasetRepository::create_default_instance(); DatasetSelectionCatalog::create_default_instance(); DatasetRepository& rep = DatasetRepository::default_instance(); assert( rep.is_valid() ); DatasetSelectionCatalog& dsc = DatasetSelectionCatalog::default_instance(); assert( dsc.is_valid() ); msg("Fetch default instance of CSC."); assert( CredentialSelectionCatalog::create_default_instance() == 0 ); CredentialSelectionCatalog& sc = CredentialSelectionCatalog::default_instance(); cout << sc << endl; assert( sc.is_valid() ); string owner = "me"; assert( GssCredentialManager::set_default() == 0 ); assert( GssCredentialManager::set_owner("me") == 0 ); msg("Create FMS SE"); string sedir = getcwd() + "/sedir"; mkdir(sedir); msg("Show help"); int stat = system("dataset_property -h"); assert( stat == 0 ); msg("Try with nonexistent file"); stat = system("dataset_property mydst.xml"); assert( stat != 0 ); msg("Create test files"); Text a0("a.dat"); a0.append("This is file a"); a0.append("A is for apple"); a0.write(); Text b0("b.dat"); b0.append("This is file b"); b0.append("B is for bumblebee"); b0.write(); msg("Create test dataset"); Location loc; string dir = getcwd(); loc.files().push_back(Url("file:" + dir + "/a.dat")); loc.files().push_back(Url("file:" + dir + "/b.dat")); Content con; TestDataset dst1(con, loc); dst1.lock(); cout << dst1 << endl; msg("Create 2nd test dataset"); TestDataset dst2; dst2.lock(); cout << dst2 << endl; msg("Create Compound dataset"); DatasetList cons; SimpleCompoundDataset dst3; dst3.merge(dst1); dst3.merge(dst2); dst3.lock(); cout << dst3 << endl; msg("Write XML description of dataset 1"); XmlParser xparser; assert( ! FileStatus("mydst1.xml").exists() ); { const XmlElement* pele = dst1.xml(); assert( pele != 0 ); stat = xparser.write("mydst1.xml", *pele); delete pele; if ( stat != 0 ) { cout << "Parser returned status " << stat << endl; } assert( stat == 0 ); } assert( FileStatus("mydst1.xml").exists() ); msg("Write XML description of dataset 2"); assert( ! FileStatus("mydst2.xml").exists() ); { const XmlElement* pele = dst2.xml(); assert( pele != 0 ); stat = xparser.write("mydst2.xml", *pele); delete pele; if ( stat != 0 ) { cout << "Parser returned status " << stat << endl; } assert( stat == 0 ); } assert( FileStatus("mydst2.xml").exists() ); msg("Write XML description of dataset 3"); assert( ! FileStatus("mydst3.xml").exists() ); { const XmlElement* pele = dst3.xml(); assert( pele != 0 ); stat = xparser.write("mydst3.xml", *pele); delete pele; if ( stat != 0 ) { cout << "Parser returned status " << stat << endl; } assert( stat == 0 ); } assert( FileStatus("mydst1.xml").exists() ); string com0 = "export DIAL_DATASET_DB=./mydb; "; com0 += "export DIAL_CATALOG_CONF=resolver.dat; "; com0 += "export DIAL_FMS_PROTOCOLS=file; "; com0 += "export DIAL_FMS_PROTOCOL_ORDER=file; "; com0 += "export DIAL_FMS_SE=" + sedir + "; "; com0 += "dataset_property "; msg("Check exists"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat exists"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "1" ); } msg("Check is_valid"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat is_valid"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "1" ); } msg("Check is_empty"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat is_empty"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "1" ); } msg("Check is_locked"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat is_locked"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "1" ); } msg("Check is_virtual"); { stat = ssystem(com0 + "-f mydst1.xml -o out.dat is_virtual"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "0" ); } msg("Check not is_compound"); { stat = ssystem(com0 + "-f mydst1.xml -o out.dat is_compound"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "0" ); } msg("Check is_compound"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat is_compound"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "1" ); } msg("Check is_event"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat is_event"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "0" ); } msg("Check ID"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat id"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == dst3.id().to_string() ); } msg("Check list of logical files"); { stat = ssystem(com0 + "-f mydst1.xml -o out.dat logical_file_names"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 2 ); msg("...first file"); Url url1(tout.line(0)); string file1 = url1.fullpath(); cout << file1 << endl; assert( file1 == FileName(a0.name()).fullpath_name() ); msg("... second file"); Url url2(tout.line(1)); string file2 = url2.fullpath(); cout << file2 << endl; assert( file2 == FileName(b0.name()).fullpath_name() ); } msg("Check list of interface logical files"); { stat = ssystem(com0 + "-f mydst1.xml -o out.dat interface_logical_file_names"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 2 ); msg("...first file"); Url url1(tout.line(0)); string file1 = url1.fullpath(); cout << file1 << endl; assert( file1 == FileName(a0.name()).fullpath_name() ); Url url2(tout.line(1)); string file2 = url2.fullpath(); cout << file2 << endl; assert( file2 == FileName(b0.name()).fullpath_name() ); msg("... second file"); } msg("Check replica extraction"); { stat = ssystem(com0 + "-f mydst1.xml -o out.dat extract_files"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 5 ); Text all_lfns("all_lfns"); Text all_pfns("all_pfns"); Text int_lfns("interface_lfns"); Text int_pfns("interface_pfns"); msg("...All LFN's"); cout << all_lfns << endl; assert( all_lfns.size() == 2 ); msg("...All PFN's"); cout << all_pfns << endl; assert( all_pfns.size() == 2 ); msg("...Interface LFN's"); cout << int_lfns << endl; assert( int_lfns.size() == 2 ); msg("...Interface LFN's"); cout << int_pfns << endl; assert( int_pfns.size() == 2 ); } msg("Check file count"); { stat = ssystem(com0 + "-f mydst1.xml -o out.dat file_count"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "2" ); } msg("Check sub-datasets"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat sub_datasets"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 2 ); msg("...first dataset"); cout << tout.line(0) << endl; assert( tout.line(0) == dst1.id().to_string() ); msg("... second dataset"); cout << tout.line(1) << endl; assert( tout.line(1) == dst2.id().to_string() ); } msg("Check sub-dataset count"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat sub_dataset_count"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "2" ); } msg("Check event count"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat event_count"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "0" ); } msg("Check has event ID's"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat has_event_ids"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "0" ); } msg("Check event ID list"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat event_ids"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() <= 1 ); if ( tout.size() == 1 ) { assert( tout.line(0) == "" ); } } msg("Check print"); { stat = ssystem(com0 + "-f mydst3.xml -o out.dat print"); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() > 0 ); assert( tout.line(0).size() > 0 ); } msg("Check print to stdout"); { stat = ssystem(com0 + "-f mydst3.xml print"); assert( stat == 0 ); } msg("Check retrieval from DB"); { assert( rep.insert(&dst3).is_valid() ); stat = ssystem(com0 + "-i " + dst3.id().to_string() + " -o out.dat id"); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == dst3.id().to_string() ); } msg("Check retrieval by DSC name"); { msg("fill selection catalog"); Attributes atts; atts["uid"] = dst3.id().to_string(); assert( dsc.insert("testname", atts) == 0 ); assert( dsc.id("testname") == dst3.id() ); msg("...check retrieval"); string com; com+= "DIAL_CATALOG_CONF=resolver.dat; export DIAL_CATALOG_CONF; "; com += com0; com += "-n testname -o out.dat is_valid"; stat = ssystem(com); assert( stat == 0 ); Text tout("out.dat"); cout << tout << endl; assert( tout.size() == 1 ); assert( tout.line(0) == "1" ); } return 0; } #ifdef CTEST_MAIN int main() { return dataset_property_t(); } #endif