XRootD
XrdMapCluster.cc File Reference
#include <cerrno>
#include <getopt.h>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <strings.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/types.h>
#include "XProtocol/XProtocol.hh"
#include "XrdCl/XrdClEnv.hh"
#include "XrdCl/XrdClFileSystem.hh"
#include "XrdCl/XrdClDefaultEnv.hh"
#include "XrdNet/XrdNetAddr.hh"
#include "XrdOuc/XrdOucHash.hh"
#include "XrdSys/XrdSysHeaders.hh"
+ Include dependency graph for XrdMapCluster.cc:

Go to the source code of this file.

Macros

#define EMSG(x)   std::cerr <<"xrdmapc: " <<x <<std::endl
 
#define OPT_TYPE
 

Functions

int main (int argc, char *argv[])
 

Variables

int optind
 
int optopt
 

Macro Definition Documentation

◆ EMSG

#define EMSG (   x)    std::cerr <<"xrdmapc: " <<x <<std::endl

Definition at line 63 of file XrdMapCluster.cc.

◆ OPT_TYPE

#define OPT_TYPE

Definition at line 70 of file XrdMapCluster.cc.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 552 of file XrdMapCluster.cc.

553 {
554  const char *opLetters = ":f:hl:rv";
555  struct option opVec[] = // For getopt_long()
556  {
557  {OPT_TYPE "format", 1, 0, (int)'f'},
558  {OPT_TYPE "help", 0, 0, (int)'h'},
559  {OPT_TYPE "list", 1, 0, (int)'l'},
560  {OPT_TYPE "quiet", 0, 0, (int)'q'},
561  {OPT_TYPE "refresh", 0, 0, (int)'r'},
562  {OPT_TYPE "verify", 0, 0, (int)'v'},
563  {0, 0, 0, 0}
564  };
565  extern int optind, opterr;
566  extern char *optarg;
567  XrdNetAddr sPoint;
568  clMap *baseNode, *clNow;
569  const char *eMsg;
570  char opC;
571  int i;
572  bool doRefresh = false;
573 
574 // Process options
575 //
576  opterr = 0;
577  optind = 1;
578  while((opC = getopt_long(argc, argv, opLetters, opVec, &i)) != (char)-1)
579  switch(opC)
580  // We implicity silence the errors for the json output since we store
581  // the error state for the site in the state field of the json output
582  {case 'f': if (!strcmp("json",optarg))
583  {doJson = true; doHush = true;}
584  else if (!strcmp("text",optarg))
585  doJson = false;
586  else Usage("Invalid format argument.");
587  break;
588  case 'h': Usage(0);
589  break;
590  case 'l': if (!strcmp("all",optarg))
591  {listMan = true; listSrv = true;}
592  else if (!strcmp("m", optarg))
593  {listMan = true; listSrv = false;}
594  else if (!strcmp("s", optarg))
595  {listMan = false; listSrv = true;}
596  else Usage("Invalid list argument.");
597  break;
598  case 'q': doHush = true;
599  break;
600  case 'r': doRefresh = true;
601  break;
602  case 'v': doVerify = true;
603  break;
604  case ':': EMSG("'" <<OpName(argv) <<"' argument missing.");
605  exit(2); break;
606  case '?': EMSG("Invalid option, '" <<OpName(argv) <<"'.");
607  exit(2); break;
608  default: EMSG("Internal error processing '" <<OpName(argv) <<"'.");
609  exit(2); break;
610  }
611 
612 // Make sure we have a starting point
613 //
614  if (optind >= argc) Usage("Initial node not specified.");
615 
616 // Establish starting point
617 //
618  if ((eMsg = sPoint.Set(argv[optind])))
619  {EMSG("Unable to validate initial node; " <<eMsg);
620  exit(2);
621  }
622 
623 // Make sure it's resolvable
624 //
625  if (!sPoint.Name(0, &eMsg))
626  {EMSG("Unable to resolve " <<argv[optind] <<"; " <<eMsg);
627  exit(2);
628  }
629 
630 // Establish the base node
631 //
632  baseNode = new clMap(argv[optind]);
633 
634 // Check if we will be checking a path
635 //
636  if (optind+1 < argc) Path = argv[optind+1];
637  else doVerify = false;
638 
639 // Set default client values
640 //
641  SetEnv();
642 
643 // Map the cluster
644 //
645  MapCluster(baseNode, baseNode);
646 
647 // Check if we need to do a locate on a file and possibly verify results
648 //
649  if (Path)
650  {MapPath(baseNode, Path, doRefresh);
651  eMsg = (doVerify ? "0*rv* " : "0*r** ");
652  } else eMsg = "0**** ";
653 
654 // Print the output in the selected format
655 //
656  if (doJson)
657  {PrintJson(baseNode);
658  putchar('\n');
659  }
660  else
661  {std::cout <<eMsg <<baseNode->name <<baseNode->state <<std::endl;
662  PrintMap(baseNode, 1);
663  }
664 
665 // Check if we have any phantom nodes
666 //
667  if (Path && clLost)
668  {std::cerr <<"Warning! " <<baseNode->name
669  <<" referred to the following unconnected node:" <<std::endl;
670  clNow = clLost;
671  while(clNow)
672  {std::cerr <<"????? " <<clNow->name <<std::endl;
673  clNow = clNow->nextSrv;
674  }
675  }
676 
677 // All done
678 //
679  exit(0);
680 }
void Usage(const char *msg)
Definition: XrdAccTest.cc:105
#define OPT_TYPE
int optind
#define EMSG(x)
XrdOucString Path
#define eMsg(x)
const char * Name(const char *eName=0, const char **eText=0)
const char * Set(const char *hSpec, int pNum=PortInSpec)
Definition: XrdNetAddr.cc:216

References EMSG, eMsg, XrdNetAddrInfo::Name(), OPT_TYPE, optind, Path, XrdNetAddr::Set(), and Usage().

+ Here is the call graph for this function:

Variable Documentation

◆ optind

◆ optopt

int optopt