XRootD
XrdMapCluster.cc File Reference
#include <algorithm>
#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 <vector>
#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 65 of file XrdMapCluster.cc.

◆ OPT_TYPE

#define OPT_TYPE

Definition at line 72 of file XrdMapCluster.cc.

Function Documentation

◆ main()

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

Definition at line 569 of file XrdMapCluster.cc.

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