"by RFN" calls. master
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 8 Dec 2013 23:34:15 +0000 (00:34 +0100)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 8 Dec 2013 23:34:15 +0000 (00:34 +0100)
run.cpp

diff --git a/run.cpp b/run.cpp
index 89129c6..3d30984 100644 (file)
--- a/run.cpp
+++ b/run.cpp
@@ -22,6 +22,22 @@ static void outstat(dmlite::ExtendedStat& xStat) {
 }
 
 
+static void outreplica(const dmlite::Replica replica) {
+       std::vector<std::string> keys;
+
+       printf("  %lu: inode %lu, server '%s', rfn '%s'\n", replica.replicaid, replica.fileid, replica.server.c_str(), replica.rfn.c_str());
+       if (replica.size()) {
+               keys = replica.getKeys();
+               printf("\t");
+               for (size_t j = 0; j < keys.size(); j++) {
+                       if (j) printf(", ");
+                       printf("%s = '%s'", keys[j].c_str(), replica.getString(keys[j]).c_str());
+               }
+               printf("\n");
+       }
+}
+
+
 static void usage(const std::string name) {
        std::cout << "Usage: " << name << " [ DMLITE_CONFIGFILE [ s | d | h | (r|w|c) [PATH] | z [PATH [SIZE]] | m PATH mode ] ]" << std::endl;
        std::cout << "  s ... stat" << std::endl;
@@ -38,6 +54,8 @@ static void usage(const std::string name) {
        std::cout << "    p add FILE URL" << std::endl;
        std::cout << "    p delete FILE REPLICAID" << std::endl;
        std::cout << "    p update FILE REPLICAID URL" << std::endl;
+       std::cout << "    p search RFN" << std::endl;
+       std::cout << "    p stat RFN" << std::endl;
 }
 
 
@@ -264,7 +282,6 @@ int main(int argc, char *argv[]) {
                        dmlite::ExtendedStat xstat;
                        dmlite::Replica replica;
                        std::vector<dmlite::Replica> replicas;
-                       std::vector<std::string> keys;
                        char *cmd, *path, *rfn;
                        size_t i;
                        int64_t replicaid;
@@ -284,6 +301,7 @@ int main(int argc, char *argv[]) {
                                xstat = catalog->extendedStat(path);
                                replica.fileid = xstat.stat.st_ino;
                                replica.rfn = rfn;
+                               replica["application"] = std::string("clients");
                                catalog->addReplica(replica);
                        } else if (strcasecmp(cmd, "list") == 0 && argc >= 5) {
                                operation = "list replicas";
@@ -291,18 +309,8 @@ int main(int argc, char *argv[]) {
 
                                replicas = catalog->getReplicas(path);
                                printf("Replicas of '%s':\n", path);
-                               for (i = 0; i < replicas.size(); i++) {
-                                       printf("  %lu: inode %lu, server '%s', rfn '%s'\n", replicas[i].replicaid, replicas[i].fileid, replicas[i].server.c_str(), replicas[i].rfn.c_str());
-                                       if (replicas[i].size()) {
-                                               keys = replicas[i].getKeys();
-                                               printf("\t");
-                                               for (size_t j = 0; j < keys.size(); j++) {
-                                                       if (j) printf(", ");
-                                                       printf("%s = '%s'", keys[j].c_str(), replicas[i].getString(keys[j]).c_str());
-                                               }
-                                               printf("\n");
-                                       }
-                               }
+                               for (i = 0; i < replicas.size(); i++)
+                                       outreplica(replicas[i]);
                        } else if (strcasecmp(cmd, "delete") == 0 && argc >= 6) {
                                operation = "delete replica";
                                path = argv[4];
@@ -322,7 +330,21 @@ int main(int argc, char *argv[]) {
                                replica.fileid = xstat.stat.st_ino;
                                replica.replicaid = replicaid;
                                replica.rfn = rfn;
+                               replica["application"] = std::string("clients");
                                catalog->updateReplica(replica);
+                       } else if (strcasecmp(cmd, "search") == 0 && argc >= 5) {
+                               operation = "search replica";
+                               std::string rfn = argv[4];
+
+                               replica = catalog->getReplicaByRFN(rfn);
+                               outreplica(replica);
+                       } else if (strcasecmp(cmd, "stat") == 0 && argc >= 5) {
+                               operation = "stat replica";
+                               std::string rfn = argv[4];
+
+                               xstat = catalog->extendedStatByRFN(rfn);
+                               outheader();
+                               outstat(xstat);
                        } else {
                                std::cerr << "Bad aruments for 'p'" << std::endl;
                                usage(argv[0]);