Example #1
0
int TestCommonUtils::readFilelist(char *filelist, VUINT32& crcSet, VSTRING& filenameSet)
{

  FILE *fp = NULL;
  if((fp = fopen(filelist,"r")) == NULL)
  {
    TBSYS_LOG(DEBUG,"open file_list failed.");
    return -1;
  }
  uint32_t crc = 0;
  char filename[64];
  while(fgets(filename,sizeof(filename),fp))
  {
    if(filename[strlen(filename)-1] == '\n')
    {
      filename[strlen(filename)-1] = '\0';
    } else {
      filename[strlen(filename)] = '\0';
    }
#if 0
    TBSYS_LOG(ERROR,"line = %d, filename = %s, filelist = %s!!!",__LINE__,filename, filelist);
#endif
    char *p = strchr(filename,' ');
    *p++ = '\0';
    sscanf(p,"%u",&crc);

    filenameSet.push_back(filename);
    crcSet.push_back(crc);

  }

  return 0;
}
Example #2
0
int32_t do_cmd(char* key)
{
  key = strip_line(key);
  if (!key[0])
  {
    return TFS_SUCCESS;
  }

#ifdef _WITH_READ_LINE
  // not blank line, add to history
  add_history(key);
#endif

  char* token = strchr(key, ' ');
  if (token != NULL)
  {
    *token = '\0';
  }

  STR_FUNC_MAP_ITER it = g_cmd_map.find(Func::str_to_lower(key));

  if (it == g_cmd_map.end())
  {
    fprintf(stderr, "unknown command. \n");
    return TFS_ERROR;
  }
  // ok this is current command
  g_cur_cmd = key;

  if (token != NULL)
  {
    token++;
    key = token;
  }
  else
  {
    key = NULL;
  }

  VSTRING param;
  param.clear();
  while ((token = strsep(&key, " ")) != NULL)
  {
    if ('\0' == token[0])
    {
      continue;
    }
    param.push_back(token);
  }

  // check param count
  int32_t param_cnt = param.size();
  if (param_cnt < it->second.min_param_cnt_ || param_cnt > it->second.max_param_cnt_)
  {
    fprintf(stderr, "%s\t\t%s\n\n", it->second.syntax_, it->second.info_);
    return TFS_ERROR;
  }

  return it->second.func_(param);
}
Example #3
0
//get the command
int parse_cmd(char* key, VSTRING & param)
{
  int cmd = CMD_NOP;
  char* token;
  //remove the space
  while (*key == ' ')
    key++;
  token = key + strlen(key);
  while (*(token - 1) == ' ' || *(token - 1) == '\n' || *(token - 1) == '\r')
    token--;
  *token = '\0';
  if (key[0] == '\0')
  {
    return cmd;
  }

#ifdef _WITH_READ_LINE
  // not blank line, add to history
  add_history(key);
#endif

  token = strchr(key, ' ');
  if (token != NULL)
  {
    *token = '\0';
  }
  //find the command
  STR_INT_MAP_ITER it = cmd_map.find(Func::str_to_lower(key));
  if (it == cmd_map.end())
  {
    return CMD_UNKNOWN;
  }
  else
  {
    cmd = it->second;
  }
  if (token != NULL)
  {
    token++;
    key = token;
  }
  else
  {
    key = NULL;
  }
  //get the parameters
  param.clear();
  while ((token = strsep(&key, " ")) != NULL)
  {
    if (token[0] == '\0')
    {
      continue;
    }
    param.push_back(token);
  }
  return cmd;
}
Example #4
0
int TestCommonUtils::getFilelist(int partNo, int partSize, VUINT32& crcSet, 
      VUINT32& crcSetPerThread, VSTRING& filenameSet, VSTRING& filenameSetPerThread)
{
  // total size less than thread count
  if (partSize == 0)
  {
    partSize = 1; 
  }
  
  int offset = partNo * partSize;
  int end = (offset + partSize) > (int)crcSet.size()? crcSet.size():(offset + partSize); 
  for (; offset < end; offset++)
  {
    crcSetPerThread.push_back(crcSet[offset]);
    filenameSetPerThread.push_back( filenameSet.at(offset).c_str() );
  }

  // the last thread eat the left
  if (partNo == (TestGFactory::_threadCount - 1) )
  {
    for (; offset < (int)crcSet.size(); offset++)
    {
      crcSetPerThread.push_back(crcSet[offset]);
      filenameSetPerThread.push_back( filenameSet.at(offset).c_str() );
    }
  }

  //debug
  /*
  char fileListPerThread[20] = {0};
  sprintf(fileListPerThread, "./read_file_list_%d.txt", partNo);
  FILE *fp = fopen(fileListPerThread, "w");
  VSTRING::iterator it = filenameSetPerThread.begin();
  for (; it != filenameSetPerThread.end(); it++)
  {
     fprintf(fp, "%s\n", it->c_str());
  } 
  fflush(fp);
  fclose(fp);
  */
  return 0;

}
Example #5
0
int cmd_check_all(const VSTRING&)
{
  print_head();
  // for uniformity, a little time waste
  MSTR_VSTR::iterator it;
  VSTRING param;
  for (it = g_server_map.begin(); it != g_server_map.end(); it++)
  {
    param.clear();
    param.push_back(it->first);
    do_monitor(param, ADMIN_CMD_CHECK);
  }
  return TFS_SUCCESS;
}
Example #6
0
int main(int argc, char* argv[])
{
    int32_t i;
    int ret = TFS_SUCCESS;
    bool directly = false;
    bool set_log_level = false;

    // analyze arguments
    while ((i = getopt(argc, argv, "s:r:nih")) != EOF)
    {
        switch (i)
        {
        case 'n':
            set_log_level = true;
            break;
        case 's':
            nsip = optarg;
            break;
        case 'r':
            rc_addr = optarg;
            break;
        case 'i':
            directly = true;
            break;
        case 'h':
        default:
            usage(argv[0]);
            return TFS_ERROR;
        }
    }

    if (set_log_level)
    {
        TBSYS_LOGGER.setLogLevel("ERROR");
    }

    if (NULL == nsip && NULL == rc_addr)
    {
        usage(argv[0]);
        return TFS_ERROR;
    }

    gstreamer.set_packet_factory(&gfactory);
    NewClientManager::get_instance().initialize(&gfactory, &gstreamer);

    if (nsip != NULL)
    {
        g_tfs_client = TfsClientImpl::Instance();
        ret = g_tfs_client->initialize(nsip, DEFAULT_BLOCK_CACHE_TIME, 1000, false);
        if (ret != TFS_SUCCESS)
        {
            fprintf(stderr, "init tfs client fail, ret: %d\n", ret);
            return ret;
        }
        g_use_meta = false;
    }
    else if (rc_addr != NULL)
    {
        strcpy(app_key, default_app_key);
        g_use_meta = true;
    }


    init();

    if (optind >= argc)
    {
        signal(SIGINT, sign_handler);
        signal(SIGTERM, sign_handler);
        main_loop();
    }
    else // has other params
    {
        int32_t i = 0;
        if (directly)
        {
            for (i = optind; i < argc; i++)
            {
                do_cmd(argv[i]);
            }
        }
        else
        {
            VSTRING param;
            for (i = optind; i < argc; i++)
            {
                param.clear();
                param.push_back(argv[i]);
                cmd_batch_file(param);
            }
        }
    }
    if (g_tfs_client != NULL)
    {
        g_tfs_client->destroy();
    }
    return TFS_SUCCESS;
}
Example #7
0
File: main.cpp Project: alimy/tfs
int32_t do_cmd(char* key)
{
  key = strip_line(key);
  if (!key[0])
  {
    return TFS_SUCCESS;
  }
#ifdef _WITH_READ_LINE
  // not blank line, add to history
  add_history(key);
#endif

  char* token = strchr(key, ' ');
  if (token != NULL)
  {
    *token = '\0';
  }

  MSTR_FUNC_ITER it = g_cmd_map.find(Func::str_to_lower(key));

  if (it == g_cmd_map.end())
  {
    fprintf(stderr, "unknown command. \n");
    return TFS_ERROR;
  }
  // ok this is current command
  g_cur_cmd = key;

  if (token != NULL)
  {
    token++;
    key = token;
  }
  else
  {
    key = NULL;
  }

  VSTRING param;
  param.clear();
  while ((token = strsep(&key, " ")) != NULL)
  {
    if ('\0' == token[0])
    {
      break;
    }
    param.push_back(token);
  }

  //check param count
  int32_t min_param_count = g_cmd_map[g_cur_cmd].min_param_count_;
  int32_t max_param_count = g_cmd_map[g_cur_cmd].max_param_count_;
  int32_t param_size = static_cast<int32_t>(param.size());
  if ((param_size < min_param_count) || param_size > max_param_count)
  {
    //fprintf(stderr, "%s\n\n", g_cmd_map[g_cur_cmd].info_);
    fprintf(stderr, "bad param...");
    print_help();
    return TFS_ERROR;
  }

  return it->second.func_(param);
}
Example #8
0
File: main.cpp Project: alimy/tfs
int main(int argc,char** argv)
{
  //TODO readline
  int32_t i;
  string ns_ip_port_1;
  string ns_ip_port_2;
  bool directly = false;
  while ((i = getopt(argc, argv, "s:m:ihv")) != EOF)
  {
    switch (i)
    {
      case 's':
        ns_ip_port_2 = optarg;
        break;
      case 'm':
        ns_ip_port_1 = optarg;
        g_need_cmp = true;
        break;
      case 'i':
        directly = true;
        break;
      case 'v':
        version(argv[0]);
        break;
      case 'h':
      default:
        usage(argv[0]);
    }
  }

  if (ns_ip_port_2.empty() || (g_need_cmp && ns_ip_port_1.empty()))
  {
    fprintf(stderr, "please input nameserver ip and port.\n");
    usage(argv[0]);
  }

  TBSYS_LOGGER.setLogLevel("error");

  init();

  gstreamer.set_packet_factory(&gfactory);
  NewClientManager::get_instance().initialize(&gfactory, &gstreamer);

  if (!g_need_cmp)
  {
    g_show_info.set_ns_ip(ns_ip_port_2);
  }
  else
  {
    g_cmp_info.set_ns_ip(ns_ip_port_1, ns_ip_port_2);
  }

  signal(SIGINT, sign_handler);
  signal(SIGTERM, sign_handler);
  if (optind >= argc)
  {
    main_loop();
  }
  else
  {
    if (directly) // ssm ... -i "cmd"
    {
      for (i = optind; i < argc; i++)
      {
        do_cmd(argv[i]);
      }
      g_show_info.clean_last_file();
    }
    else// exec filename
    {
      VSTRING param;
      for (i = optind; i < argc; i++)
      {
        param.clear();
        param.push_back(argv[i]);
        cmd_batch(param);
      }
    }
  }
  NewClientManager::get_instance().destroy();
}
Example #9
0
int main(int argc, char* argv[])
{
  int32_t i;
  bool directly = false;
  bool set_log_level = false;

  // analyze arguments
  while ((i = getopt(argc, argv, "s:k:ih")) != EOF)
  {
    switch (i)
    {
      case 'n':
        set_log_level = true;
        break;
      case 'k':
        krs_addr = optarg;
        break;
      case 'i':
        directly = true;
        break;
      case 'h':
      default:
        usage(argv[0]);
        return TFS_ERROR;
    }
  }

  if (set_log_level)
  {
    TBSYS_LOGGER.setLogLevel("ERROR");
  }

  if (NULL == krs_addr)
  {
    usage(argv[0]);
    return TFS_ERROR;
  }

  gstreamer.set_packet_factory(&gfactory);
  NewClientManager::get_instance().initialize(&gfactory, &gstreamer);

  if (krs_addr != NULL)
  {
    new_server_id = Func::get_host_ip(krs_addr);
  }

  init();

  if (optind >= argc)
  {
    signal(SIGINT, sign_handler);
    signal(SIGTERM, sign_handler);
    main_loop();
  }
  else // has other params
  {
    int32_t i = 0;
    if (directly)
    {
      for (i = optind; i < argc; i++)
      {
        do_cmd(argv[i]);
      }
    }
    else
    {
      VSTRING param;
      for (i = optind; i < argc; i++)
      {
        param.clear();
        param.push_back(argv[i]);
        cmd_batch_file(param);
      }
    }
  }
  return TFS_SUCCESS;
}
Example #10
0
int main(int argc, char* argv[])
{
  int i = 0;
  int iex = 0;

  // input option
  if (argc == 1)
  {
    usage(argv[0]);
    return TFS_ERROR;
  }
  while ((i = getopt(argc, argv, "d:i::")) != -1)
  {
    switch (i)
    {
    case 'i':
      iex = 1;
      break;
    case 'd':
      ds_ip = Func::get_host_ip(optarg);
      if (ds_ip == 0)
      {
        printf("ip or port is invalid, please try again.\n");
        return TFS_ERROR;
      }
      break;
    case ':':
      printf("missing -d");
      usage(argv[0]);
      break;
    default:
      usage(argv[0]);
      return TFS_ERROR;
    }
  }
  static tfs::message::MessageFactory factory;
  static tfs::common::BasePacketStreamer streamer;
  streamer.set_packet_factory(&factory);
  NewClientManager::get_instance().initialize(&factory, &streamer);

  init();

  if (optind >= argc)
  {
    signal(SIGINT, signal_handler);
    main_loop();
  }
  else
  {
    VSTRING param;
    int i = optind;
    if (iex)
    {
      printf("with i\n");
      for (i = optind; i < argc; i++)
      {
        param.clear();
        int cmd = parse_cmd(argv[i], param);
        switch_cmd(cmd, param);
      }
    }
    else
    {
      printf("without i\n");
      for (i = optind; i < argc; i++)
      {
        param.clear();
        param.push_back(argv[i]);
      }
    }
  }
  return TFS_SUCCESS;
}