Exemplo n.º 1
0
	void Loader::init(const brahms::Environment& environment)
	{
		//	The bindings are accessed via the INSTALL_PREFIX.
#if STANDALONE_INSTALL
                installPrefix = brahms::os::getenv("SYSTEMML_INSTALL_PATH", false);
                if (installPrefix.empty()) {
                    installPrefix = INSTALL_PREFIX;
                    installPrefix += brahms::os::PATH_SEPARATOR;
                }
#else
                installPrefix = INSTALL_PREFIX;
                installPrefix += brahms::os::PATH_SEPARATOR;
#endif
		//	get path from Execution Parameters
		string sNamespaceRoots = environment.gets("NamespaceRoots");

		//	break out separate paths
		VSTRING roots = brahms::text::explode(brahms::os::ENV_SEPARATOR, sNamespaceRoots);

		//	trim any whitespace from them
		for (UINT32 i=0; i<roots.size(); i++)
		{
			string root = roots[i];
			brahms::text::trim(root);
			if (root.length())
				namespaceRoots.push_back(root);
		}

		//	check we got some
		if (!namespaceRoots.size())
			ferr << E_EXECUTION_PARAMETERS << "malformed execution parameter NamespaceRoots (no entries)";
	}
Exemplo n.º 2
0
int cmd_remove_family(const VSTRING& param)
{
  int32_t flag = DELETE_FAMILY_IN_STORE | DELETE_FAMILY_IN_MEMORY;
  if (param.size() < 1)
  {
    fprintf(stderr, "invalid parameter, param.empty\n");
    return TFS_ERROR;
  }
  int64_t family_id = strtoull(param[0].c_str(), NULL, 10);
  if (family_id <= 0)
  {
    fprintf(stderr, "invalid familyid %s\n", param[0].c_str());
    return TFS_ERROR;
  }
  if (param.size() == 2)
    flag = atoi(param[1].c_str());

  ClientCmdMessage req_cc_msg;
  req_cc_msg.set_cmd(CLIENT_CMD_DELETE_FAMILY);
  req_cc_msg.set_value3(family_id);
  req_cc_msg.set_value4(flag);

  int32_t status = TFS_ERROR;
  send_msg_to_server(g_tfs_client->get_server_id(), &req_cc_msg, status);

  ToolUtil::print_info(status, "remove family %s, ret: %d", param[0].c_str(), status);
  return status;
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
0
int cmd_ls(const VSTRING& param)
{
    int32_t size = param.size();
    const char* path = (1 == size) ? param.at(0).c_str() : ".";
    char sys_cmd[MAX_CMD_SIZE];
    // just use system tool ls, maybe DIY
    snprintf(sys_cmd, MAX_CMD_SIZE, "ls -FCl %s", path);
    return system(sys_cmd);
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
int cmd_list_file_info(const VSTRING& param)
{
  uint64_t block_id = 0;
  uint64_t attach_block_id = 0;
  uint64_t server_id = 0;

  int32_t show_detail = 0;

  int ret = TFS_ERROR;
  if ((block_id = strtoull(param[0].c_str(), (char**)NULL, 10)) <= 0)
  {
    fprintf(stderr, "invalid blockid: %"PRI64_PREFIX"u\n", block_id);
    return ret;
  }

  if (param.size() > 3)
  {
    server_id = Func::get_host_ip(param[3].c_str());
  }
  else
  {
    VUINT64 ds_list;
    ret = ToolUtil::get_block_ds_list_v2(g_tfs_client->get_server_id(), block_id, ds_list);
    if (ret != TFS_SUCCESS)
    {
      fprintf(stderr, "get ds list failed. block_id: %"PRI64_PREFIX"u, ret: %d\n", block_id, ret);
      return ret;
    }
    server_id = ds_list[0];
  }

  if (0 != server_id)
  {
    if (param.size() > 2 && 0 == strcmp(param[2].c_str(), "detail"))
    {
      show_detail = 1;
    }

    if (param.size() > 1)
    {
      attach_block_id = strtoull(param[1].c_str(), (char**)NULL, 10);
    }
    else
    {
      attach_block_id = block_id;
    }

    DsTask ds_task(server_id, g_tfs_client->get_cluster_id());
    ds_task.block_id_ = block_id;
    ds_task.attach_block_id_ = attach_block_id;
    ds_task.mode_ = show_detail;
    ret = DsLib::list_file(ds_task);
  }

  return ret;
}
Exemplo n.º 7
0
int cmd_remove_block(const VSTRING& param)
{
  uint32_t flag = 0;
  uint32_t block_id = atoi(param[0].c_str());
  uint64_t server_id = 0;
  if (param.empty())
  {
    fprintf(stderr, "invalid parameter, param.empty\n");
    return TFS_ERROR;
  }
  if (param.size() == 1)
  {
    flag = 1;
  }
  else if (param.size() == 2 )
  {
    if (param[1].length() == 1)
      flag = atoi(param[1].c_str());
    else
    {
      server_id = Func::get_host_ip(param[1].c_str());
      if (0 == server_id)
      {
        fprintf(stderr, "invalid addr %s\n", param[1].c_str());
        return TFS_ERROR;
      }
    }
  }
  if (0 == block_id)
  {
    fprintf(stderr, "invalid blockid %s\n", param[0].c_str());
    return TFS_ERROR;
  }

  ClientCmdMessage req_cc_msg;
  req_cc_msg.set_cmd(CLIENT_CMD_EXPBLK);
  req_cc_msg.set_value1(server_id);
  req_cc_msg.set_value3(block_id);
  req_cc_msg.set_value4(flag);

  int32_t status = TFS_ERROR;

  send_msg_to_server(g_tfs_client->get_server_id(), &req_cc_msg, status);

  if (param.size() == 1)
    ToolUtil::print_info(status, "removeblock %s", param[0].c_str());
  else if (param.size() == 2)
    ToolUtil::print_info(status, "removeblock %s %s", param[0].c_str(), param[1].c_str());
  return status;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
int cmd_rm_dir_meta(const VSTRING& param)
{
    int ret = TFS_SUCCESS;
    const char* dir_path = expand_path(const_cast<string&>(param[0]));
    char appkey[257];
    int size = param.size();
    if (size > 1)
    {
        strncpy(appkey, param[1].c_str(), 256);
        appkey[256] = '\0';
    }
    else
    {
        strcpy(appkey, app_key);
    }

    if (size > 2)
    {
        uid = strtoll(param[2].c_str(), NULL, 10);
    }

    RcClientImpl impl;
    ret = impl.initialize(rc_addr, appkey, app_ip);

    if (TFS_SUCCESS != ret)
    {
        TBSYS_LOG(DEBUG, "meta client init failed, ret: %d", ret);
    }
    else
    {
        ret = impl.rm_dir(uid, dir_path);
    }

    return ret;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
int cmd_get_file_raw(const VSTRING& param)
{
    const char* tfs_name = canonical_param(param[0]);
    const char* local_file = expand_path(const_cast<string&>(param[1]));
    char appkey[257];
    int size = param.size();
    if (size > 2)
    {
        TBSYS_LOG(DEBUG, "appkey: %s", param[2].c_str());
        strncpy(appkey, param[2].c_str(), 256);
        appkey[256] = '\0';
    }
    else
    {
        strcpy(appkey, app_key);
    }
    int ret = TFS_SUCCESS;
    RcClientImpl impl;
    ret = impl.initialize(rc_addr, appkey, app_ip);

    if (TFS_SUCCESS != ret)
    {
        TBSYS_LOG(DEBUG, "rc client init failed, ret: %d", ret);
    }
    else
    {
        ret = impl.fetch_file(local_file, tfs_name, NULL);
    }

    ToolUtil::print_info(ret, "fetch %s => %s", tfs_name, local_file);

    return ret;
}
Exemplo n.º 12
0
int cmd_del_object(const VSTRING& param)
{
  const char* bucket_name = param[0].c_str();
  const char* object_name = param[1].c_str();
  char appkey[257];
  int size = param.size();
  if (size > 2)
  {
    strncpy(appkey, param[2].c_str(), 256);
    appkey[256] = '\0';
  }
  else
  {
    strcpy(appkey, app_key);
  }

  UserInfo user_info;

  RcClientImpl impl;
  impl.set_kv_rs_addr(krs_addr);
  int ret = impl.initialize(rc_addr, appkey, app_ip);

  if (TFS_SUCCESS != ret)
  {
    TBSYS_LOG(DEBUG, "rc client init failed, ret: %d", ret);
  }
  else
  {
    ret = impl.del_object(bucket_name, object_name, user_info);
  }
  ToolUtil::print_info(ret, "del bucket: %s, object: %s", bucket_name, object_name);

  return ret;
}
Exemplo n.º 13
0
int cmd_stat_blk(const VSTRING& param)
{
    int ret = TFS_ERROR;

    uint64_t server_id = 0;
    uint32_t block_id = 0;

    if ((block_id = atoi(param[0].c_str())) <= 0)
    {
        fprintf(stderr, "invalid blockid: %u\n", block_id);
    }

    if (param.size() > 2)
    {
        server_id = Func::get_host_ip(param[1].c_str());
    }
    else
    {
        VUINT64 ds_list;
        ret = ToolUtil::get_block_ds_list(g_tfs_client->get_server_id(), block_id, ds_list);
        if (ret != TFS_SUCCESS)
        {
            fprintf(stderr, "get ds list failed. block_id: %u, ret: %d\n", block_id, ret);
            return ret;
        }
        server_id = ds_list[0];
    }

    DsTask ds_task(server_id, g_tfs_client->get_cluster_id());
    ds_task.block_id_ = block_id;
    ret = DsLib::get_block_info(ds_task);

    return ret;
}
Exemplo n.º 14
0
int cmd_stat_file_meta(const VSTRING& param)
{
    int ret = TFS_SUCCESS;
    const char* file_path = expand_path(const_cast<string&>(param[0]));
    char rs_addr[257];
    FragInfo frag_info_;

    int size = param.size();
    if (size > 1)
    {
        strncpy(rs_addr, param[1].c_str(), 256);
        rs_addr[256] = '\0';
        printf("rs_addr: %s\n", rs_addr);
    }

    if (size > 2)
    {
        app_id = strtoll(param[2].c_str(), NULL, 10);
    }
    if (size > 3)
    {
        uid = strtoll(param[3].c_str(), NULL, 10);
    }

    NameMetaClientImpl impl;
    ret = impl.initialize(rs_addr);

    if (TFS_SUCCESS != ret)
    {
        TBSYS_LOG(DEBUG, "meta client login rs_addr: %s fail, ret: %d", rs_addr, ret);
    }
    else
    {
        ret = impl.read_frag_info(app_id, uid, file_path, frag_info_);
    }

    //stat the detail
    ToolUtil::print_info(ret, "stat %s", file_path);
    if (TFS_SUCCESS == ret)
    {
        int32_t cluster_id = frag_info_.cluster_id_;
        std::vector<FragMeta> vFragMeta = frag_info_.v_frag_meta_;
        std::vector<FragMeta>::iterator iter;
        fprintf(stdout, "  FILE_NAME\t  BLOCK_ID\t  FILE_ID\t  OFFSET\t  SIZE\n");
        for (iter = vFragMeta.begin(); iter < vFragMeta.end(); iter++)
        {
            FSName fsname(iter->block_id_, iter->file_id_, cluster_id);
            fprintf(stdout,
                    "  %s\t"
                    "  %u\t"
                    "  %" PRI64_PREFIX "u\t"
                    "  %"PRI64_PREFIX"d\t"
                    "  %d\n",
                    fsname.get_name(), iter->block_id_, iter->file_id_, iter->offset_, iter->size_);
        }
    }

    return ret;
}
Exemplo n.º 15
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;

}
Exemplo n.º 16
0
int cmd_ls_file_meta(const VSTRING& param)
{
    int ret = TFS_SUCCESS;
    char appkey[257];
    if (!g_use_meta)
    {
        TBSYS_LOG(WARN, "sorry, this commond is for name meta!!!");
    }
    else
    {
        const char* file_path = expand_path(const_cast<string&>(param[0]));
        int size = param.size();
        if (size > 1)
        {
            strncpy(appkey, param[1].c_str(), 256);
            appkey[256] = '\0';
        }
        else
        {
            strcpy(appkey, app_key);
        }

        if (size > 2)
        {
            app_id = strtoll(param[2].c_str(), NULL, 10);
        }
        if (size > 3)
        {
            uid = strtoll(param[3].c_str(), NULL, 10);
        }

        RcClientImpl impl;
        ret = impl.initialize(rc_addr, appkey, app_ip);

        if (TFS_SUCCESS != ret)
        {
            TBSYS_LOG(DEBUG, "meta client init failed, ret: %d", ret);
        }
        else
        {
            FileMetaInfo file_info;
            ret = impl.ls_file(app_id, uid, file_path, file_info);
            if (TFS_SUCCESS == ret)
            {
                if (file_info.name_.size() > 0)
                    fprintf(stdout, "name:%s\n", file_info.name_.data());
                fprintf(stdout, "pid %"PRI64_PREFIX"d id %"PRI64_PREFIX
                        "d create_time %s modify_time %s size %"PRI64_PREFIX"d ver_no %d\n",
                        file_info.pid_, file_info.id_, Func::time_to_str(file_info.create_time_).c_str(),
                        Func::time_to_str(file_info.modify_time_).c_str(), file_info.size_, file_info.ver_no_);
            }
        }
    }
    return ret;
}
Exemplo n.º 17
0
int cmd_ls_dir_meta(const VSTRING& param)
{
    int ret = TFS_SUCCESS;
    const char* dir_path = expand_path(const_cast<string&>(param[0]));
    int size = param.size();
    char appkey[257];
    TBSYS_LOG(DEBUG, "size: %d", size);
    if (size > 1)
    {
        TBSYS_LOG(DEBUG, "appkey: %s", param[1].c_str());
        strncpy(appkey, param[1].c_str(), 256);
        appkey[256] = '\0';
    }
    else
    {
        strcpy(appkey, app_key);
    }

    if (size > 2)
    {
        app_id = strtoll(param[2].c_str(), NULL, 10);
    }
    if (size > 3)
    {
        uid = strtoll(param[3].c_str(), NULL, 10);
    }

    RcClientImpl impl;
    ret = impl.initialize(rc_addr, appkey, app_ip);

    if (TFS_SUCCESS != ret)
    {
        TBSYS_LOG(DEBUG, "meta client init failed, ret: %d", ret);
    }
    else
    {
        std::vector<FileMetaInfo> meta_info;
        std::vector<FileMetaInfo>::const_iterator it;
        ret = impl.ls_dir(app_id, uid, dir_path, meta_info);
        if (TFS_SUCCESS == ret)
        {
            for (it = meta_info.begin(); it != meta_info.end(); it++)
            {
                if (it->name_.size() > 0)
                    fprintf(stdout, "name:%s\n", it->name_.data());
                fprintf(stdout, "pid %"PRI64_PREFIX"d id %"PRI64_PREFIX
                        "d create_time %d modify_time %d size %"PRI64_PREFIX"d ver_no %d\n",
                        it->pid_, it->id_, it->create_time_, it->modify_time_, it->size_, it->ver_no_);
            }
        }
    }
    return ret;
}
Exemplo n.º 18
0
int cmd_set_bpr(const VSTRING& param)
{
  int32_t size = param.size();
  int32_t iret = 2 != size ? EXIT_PARAMETER_ERROR : TFS_SUCCESS;
  if (TFS_SUCCESS != iret)
  {
    fprintf(stderr, "parameter size: %d is invalid, must be 2\n", size);
  }
  else
  {
    int32_t value3 = atoi(param[0].c_str());
    int32_t value4;
    iret = (value3 > 1 || value3 < 0 || param[1].length() > 6 || ((value4 = atoi(param[1].c_str())) != 0 && 1 == value3)) ? EXIT_PARAMETER_ERROR : TFS_SUCCESS;
    if (TFS_SUCCESS != iret)
    {
      fprintf(stderr, "parameter is invalid, value1: (0|1), value2.length should <= 6. but input value1: %d, value2: %s\n", value3, param[1].c_str());
    }
    else
    {
      ClientCmdMessage req_cc_msg;
      req_cc_msg.set_cmd(CLIENT_CMD_SET_BALANCE_PERCENT);
      req_cc_msg.set_value3(value3);
      req_cc_msg.set_value4(value4);

      tbnet::Packet* ret_message = NULL;
      NewClient* client = NewClientManager::get_instance().create_client();
      iret = send_msg_to_server(g_tfs_client->get_server_id(), client, &req_cc_msg, ret_message);
      string ret_value = "successful";
      if (TFS_SUCCESS != iret)
      {
        ret_value = "setbpr failed";
      }
      else
      {
        if (ret_message->getPCode() == STATUS_MESSAGE)
        {
          StatusMessage* s_msg = dynamic_cast<StatusMessage*> (ret_message);
          iret = s_msg->get_status();
          if (iret != STATUS_MESSAGE_OK)
          {
            ret_value = s_msg->get_error();
          }
        }
      }
      ToolUtil::print_info(iret, "%s", ret_value.c_str());

      NewClientManager::get_instance().destroy_client(client);
    }
  }
  return iret;
}
Exemplo n.º 19
0
int put_file_raw_ex(const VSTRING& param, const bool is_large)
{
    int32_t size = param.size();
    const char* local_file = expand_path(const_cast<string&>(param[0]));
    char* tfs_name = NULL;
    const char* suffix = NULL;
    char appkey[257];
    //int32_t flag = T_DEFAULT;
    int ret = TFS_SUCCESS;
    char ret_tfs_name[TFS_FILE_LEN];
    ret_tfs_name[0] = '\0';

    if (size > 1)
    {
        suffix = canonical_param(param[1]);
    }

    if (size > 2)
    {
        //TBSYS_LOG(DEBUG, "app_key: %s", param[2].c_str());
        strncpy(appkey, canonical_param(param[2]), 256);
        appkey[256] = '\0';
    }
    else
    {
        // default app_key = "tfscom"
        strcpy(appkey, app_key);
    }

    //login with rc and app_key
    RcClientImpl impl;
    ret = impl.initialize(rc_addr, appkey, app_ip);

    if (TFS_SUCCESS != ret)
    {
        TBSYS_LOG(DEBUG, "rc client init failed, ret: %d", ret);
    }
    else
    {
        ret = impl.save_file(local_file, ret_tfs_name, TFS_FILE_LEN, suffix, is_large) < 0 ? TFS_ERROR : TFS_SUCCESS;
    }

    //printf("tfs_name: %s, ret_tfs_name: %s\n", tfs_name, ret_tfs_name);

    ToolUtil::print_info(ret, "put %s => %s", local_file, tfs_name != NULL ? FSName(tfs_name, suffix).get_name() : ret_tfs_name);
    return ret;
}
Exemplo n.º 20
0
int cmd_hide_file(const VSTRING& param)
{
    const char* tfs_name = canonical_param(param[0]);

    TfsUnlinkType unlink_type = CONCEAL;
    if (param.size() > 1)
    {
        unlink_type = static_cast<TfsUnlinkType>(atoi(param[1].c_str()));
    }

    int64_t file_size = 0;
    int ret = g_tfs_client->unlink(file_size, tfs_name, NULL, unlink_type);

    ToolUtil::print_info(ret, "hide %s %d", tfs_name, unlink_type);

    return ret;
}
Exemplo n.º 21
0
int cmd_put_file(const VSTRING& param)
{
  int32_t size = param.size();
  const char* local_file = expand_path(const_cast<string&>(param[0]));
  const char* tfs_name = NULL;
  const char* suffix = NULL;
  int32_t flag = T_DEFAULT;
  int ret = TFS_SUCCESS;
  char ret_tfs_name[TFS_FILE_LEN_V2];
  ret_tfs_name[0] = '\0';

  if (size > 1)
  {
    tfs_name = canonical_param(param[1]);
  }

  if (size > 2)
  {
    suffix = canonical_param(param[2]);
  }

  if (size > 3 &&
      param[3] == "force")
  {
    flag |= T_NEWBLK;
  }

  if (NULL != tfs_name)  // update
  {
    ret = g_tfs_client->save_file_update(local_file, flag, tfs_name, suffix);
  }
  else
  {
    ret = g_tfs_client->save_file(ret_tfs_name, TFS_FILE_LEN_V2, local_file, flag, suffix);
  }

  if (ret >= 0)
  {
    TBSYS_LOG(DEBUG, "save %d bytes data to tfs", ret);
  }
  ret = (ret < 0) ? ret : TFS_SUCCESS;

  //printf("tfs_name: %s, ret_tfs_name: %s\n", tfs_name, ret_tfs_name);
  ToolUtil::print_info(ret, "put %s => %s", local_file, tfs_name != NULL ? FSName(tfs_name, suffix).get_name() : ret_tfs_name);
  return ret;
}
Exemplo n.º 22
0
int cmd_cd(const VSTRING& param)
{
    int ret = TFS_SUCCESS;
    int32_t size = param.size();
    const char* dest_dir = (1 == size) ? expand_path(const_cast<string&>(param[0])) : getenv("HOME");

    if (NULL == dest_dir)
    {
        fprintf(stderr, "no directory argument and HOME not found\n\n");
        ret = TFS_ERROR;
    }
    else if (chdir(dest_dir) == -1)
    {
        fprintf(stderr, "can't change directory %s: %s\n", dest_dir, strerror(errno));
        ret = TFS_ERROR;
    }
    cmd_pwd(param);
    return ret;
}
Exemplo n.º 23
0
int cmd_is_dir_exist_meta(const VSTRING& param)
{
    int ret = TFS_SUCCESS;
    const char* dir_path = expand_path(const_cast<string&>(param[0]));
    char appkey[257];
    int size = param.size();
    TBSYS_LOG(DEBUG, "size: %d", size);
    if (size > 1)
    {
        //TBSYS_LOG(DEBUG, "appkey: %s", param[1].c_str());
        strncpy(appkey, param[1].c_str(), 256);
        appkey[256] = '\0';
    }
    else
    {
        strcpy(appkey, app_key);
    }

    if (size > 2)
    {
        app_id = strtoll(param[2].c_str(), NULL, 10);
    }
    if (size > 3)
    {
        uid = strtoll(param[3].c_str(), NULL, 10);
    }

    RcClientImpl impl;
    ret = impl.initialize(rc_addr, appkey, app_ip);

    if (TFS_SUCCESS != ret)
    {
        TBSYS_LOG(DEBUG, "meta client init failed, ret: %d", ret);
    }
    else
    {
        std::vector<FileMetaInfo> meta_info;
        std::vector<FileMetaInfo>::const_iterator it;
        bool bRet = impl.is_dir_exist(app_id, uid, dir_path);
        fprintf(stdout, "dir: %s %s exist \n", dir_path, bRet ? "" : "not ");
    }
    return ret;
}
Exemplo n.º 24
0
int remove_file_raw_ex(const VSTRING& param, TfsUnlinkType type)
{
    const char* tfs_name = canonical_param(param[0]);
    char appkey[257];
    int ret = TFS_SUCCESS;


    int size = param.size();
    if (size > 1)
    {
        //TBSYS_LOG(DEBUG, "app_key: %s", param[1].c_str());
        strncpy(appkey, canonical_param(param[1]), 256);
        appkey[256] = '\0';
    }
    else
    {
        //default app_key = "tfscom"
        strcpy(appkey, app_key);
    }

    RcClientImpl impl;
    ret = impl.initialize(rc_addr, appkey, app_ip);
    if (TFS_SUCCESS != ret)
    {
        TBSYS_LOG(DEBUG, "rc client init fail, ret: %d", ret);
    }
    else
    {
        ret = impl.unlink(tfs_name, NULL, type);
    }

    if (type == DELETE)
    {
        ToolUtil::print_info(ret, "del %s", tfs_name);
    }
    else if (type == UNDELETE)
    {
        ToolUtil::print_info(ret, "undel %s", tfs_name);
    }

    return ret;
}
Exemplo n.º 25
0
int cmd_head_bucket(const VSTRING& param)
{
  const char* bucket_name = param[0].c_str();
  char appkey[257];
  int size = param.size();
  if (size > 1)
  {
    strncpy(appkey, param[1].c_str(), 256);
    appkey[256] = '\0';
  }
  else
  {
    strcpy(appkey, app_key);
  }

  BucketMetaInfo bucket_meta_info;
  UserInfo user_info;

  RcClientImpl impl;
  impl.set_kv_rs_addr(krs_addr);
  int ret = impl.initialize(rc_addr, appkey, app_ip);

  if (TFS_SUCCESS != ret)
  {
    TBSYS_LOG(DEBUG, "rc client init failed, ret: %d", ret);
  }
  else
  {
    ret = impl.head_bucket(bucket_name, &bucket_meta_info, user_info);
  }

  ToolUtil::print_info(ret, "head bucket %s", bucket_name);

  if (TFS_SUCCESS == ret)
  {
    printf("bucket: %s, create_time: %"PRI64_PREFIX"d, owner_id: %"PRI64_PREFIX"d\n",
        bucket_name, bucket_meta_info.create_time_, bucket_meta_info.owner_id_);
  }

  return ret;
}
Exemplo n.º 26
0
int cmd_put_object(const VSTRING& param)
{
  const char* bucket_name = param[0].c_str();
  const char* object_name = param[1].c_str();
  const char* local_file = expand_path(const_cast<string&>(param[2]));
  int64_t owner_id = strtoll(param[3].c_str(), NULL, 10);
  char appkey[257];
  int size = param.size();
  if (size > 4)
  {
    strncpy(appkey, param[4].c_str(), 256);
    appkey[256] = '\0';
  }
  else
  {
    strcpy(appkey, app_key);
  }

  UserInfo user_info;
  user_info.owner_id_ = owner_id;

  RcClientImpl impl;
  impl.set_kv_rs_addr(krs_addr);
  int ret = impl.initialize(rc_addr, appkey, app_ip);

  if (TFS_SUCCESS != ret)
  {
    TBSYS_LOG(DEBUG, "rc client init failed, ret: %d", ret);
  }
  else
  {
    ret = impl.put_object(bucket_name, object_name, local_file, user_info);
    ToolUtil::print_info(ret, "put object: %s, object: %s => %s owner_id: %"PRI64_PREFIX"d",
        bucket_name, object_name, local_file, owner_id);
  }
  return ret;
}
Exemplo n.º 27
0
int cmd_hide_file_raw(const VSTRING& param)
{
    const char* tfs_name = canonical_param(param[0]);
    char appkey[257];
    int size = param.size();

    TfsUnlinkType unlink_type = CONCEAL;
    if (size > 1)
    {
        unlink_type = static_cast<TfsUnlinkType>(atoi(param[1].c_str()));
    }

    if (size > 2)
    {
        strncpy(appkey, param[2].c_str(), 256);
        appkey[256] = '\0';
    }
    else
    {
        strcpy(appkey, app_key);
    }

    RcClientImpl impl;
    int ret = impl.initialize(rc_addr, appkey, app_ip);
    if (TFS_SUCCESS != ret)
    {
        TBSYS_LOG(DEBUG, "rc client login fail, ret: %d", ret);
    }
    else
    {
        ret = impl.unlink(tfs_name, NULL, unlink_type);
    }

    ToolUtil::print_info(ret, "hide %s %d", tfs_name, unlink_type);

    return ret;
}
Exemplo n.º 28
0
int cmd_put_bucket(const VSTRING& param)
{
  const char* bucket_name = param[0].c_str();
  int64_t owner_id = strtoll(param[1].c_str(), NULL, 10);
  char appkey[257];
  int size = param.size();
  if (size > 2)
  {
    strncpy(appkey, param[2].c_str(), 256);
    appkey[256] = '\0';
  }
  else
  {
    strcpy(appkey, app_key);
  }

  UserInfo user_info;
  user_info.owner_id_ = owner_id;

  RcClientImpl impl;
  impl.set_kv_rs_addr(krs_addr);
  int ret = impl.initialize(rc_addr, appkey, app_ip);
  if (TFS_SUCCESS != ret)
  {
    TBSYS_LOG(DEBUG, "rc client init failed, ret: %d", ret);
  }
  else
  {
    ret = impl.put_bucket(bucket_name, user_info);
  }
  if (TFS_SUCCESS == ret)
  {
    ToolUtil::print_info(ret, "put bucket %s owner_id : %ld", bucket_name, owner_id);
  }
  return ret;
}
Exemplo n.º 29
0
int cmd_access_control_flag(const VSTRING& param)//Discarded function
{
  int32_t size = param.size();
  uint64_t server_id = Func::get_host_ip(param[0].c_str());
  uint32_t op_type = atoi(param[1].c_str());
  if (op_type < 1 || op_type > 5)
  {
    fprintf(stderr, "error type %d must in [1,5]\n\n", op_type);
    return TFS_ERROR;
  }

  const char* value1 = NULL;
  const char* value2 = NULL;
  uint64_t v1 = 0;
  uint32_t v2 = 0;
  if (size > 2)
  {
    value1 = param[2].c_str();
  }

  if (size > 3)
  {
    value2 = param[3].c_str();
  }

  switch (op_type)
  {
  case 1:
    if (!value1)
    {
      fprintf(stderr, "setacl ip:port 1 flag\n");
      fprintf(stderr, "flag: 0 -- set mode, when you can set ip mask or ip port\n");
      fprintf(stderr, "      1 -- control mode, when those in ip list will be denied to do read or readV2 operation\n");
      fprintf(stderr, "      2 -- control mode, when those in ip list will be denied to do write or close operation\n");
      fprintf(stderr, "      4 -- control mode, when those in ip list will be denied to do unlink operation\n");
      return TFS_ERROR;
    }
    v1 = atoi(value1);
    v2 = 0;
    break;
  case 2:
    if (!value1 || !value2)
    {
      fprintf(stderr, "setacl ip:port 2 ip mask\n");
      return TFS_ERROR;
    }
    v1 = tbsys::CNetUtil::strToAddr(const_cast<char*> (value1), 0);
    v2 = static_cast<uint32_t> (tbsys::CNetUtil::strToAddr(const_cast<char*> (value2), 0));
    if (!v1 || !v2)
    {
      fprintf(stderr, "setacl ip:port 2 ip mask, not  a valid ip & mask\n");
      return TFS_ERROR;
    }
    break;
  case 3:
    if (!value1)
    {
      fprintf(stderr, "setacl ip:port 3 ipaddr\n");
      return TFS_ERROR;
    }
    v1 = tbsys::CNetUtil::strToAddr(const_cast<char*> (value1), 0);
    v2 = 0;
    break;
  case 4:
  case 5:
    v1 = 0;
    v2 = 0;
    break;
  default:
    fprintf(stderr, "error type %d must in [1,5]\n\n", op_type);
    return TFS_ERROR;
  }

  ClientCmdMessage req_cc_msg;
  req_cc_msg.set_cmd(CLIENT_CMD_SET_PARAM);
  req_cc_msg.set_value3(op_type); // param type == 1 as set acl flag.
  req_cc_msg.set_value1(v1); // ns_id as flag
  req_cc_msg.set_value4(v2);

  int32_t status = TFS_ERROR;
  send_msg_to_server(server_id, &req_cc_msg, status);
  ToolUtil::print_info(status, "set acl %s", param[0].c_str());
  return status;
}
Exemplo n.º 30
0
int cmd_access_stat_info(const VSTRING& param)//Discarded function
{
  int32_t size = param.size();
  uint64_t server_id = Func::get_host_ip(param[0].c_str());

  uint32_t start_row = 0;
  uint32_t return_row = 0;

  if (size > 1)
  {
    start_row = atoi(param[1].c_str());
  }
  if (size > 2)
  {
    return_row = atoi(param[2].c_str());
  }

  bool get_all = (start_row == 0 && return_row == 0);
  if (get_all)
  {
    return_row = 1000;
  }
  int32_t has_next = 0;

  GetServerStatusMessage req_gss_msg;

  fprintf(stdout,
          "ip addr           | read count  | read bytes  | write count  | write bytes\n"
          "------------------ -------------- ------------- -------------- ------------\n");

  int ret = TFS_SUCCESS;
  while (1)
  {
    req_gss_msg.set_status_type(GSS_CLIENT_ACCESS_INFO);
    req_gss_msg.set_from_row(start_row);
    req_gss_msg.set_return_row(return_row);

    tbnet::Packet* ret_message = NULL;
    NewClient* client = NewClientManager::get_instance().create_client();
    send_msg_to_server(server_id, client, &req_gss_msg, ret_message);

    if (ret_message == NULL)
    {
      ret = TFS_ERROR;
    }
    else if (ret_message->getPCode() == ACCESS_STAT_INFO_MESSAGE)
    {
      AccessStatInfoMessage* req_cb_msg = reinterpret_cast<AccessStatInfoMessage*> (ret_message);
      const AccessStatInfoMessage::COUNTER_TYPE & m = req_cb_msg->get();
      for (AccessStatInfoMessage::COUNTER_TYPE::const_iterator it = m.begin(); it != m.end(); ++it)
      {
        printf("%15s : %14" PRI64_PREFIX "u %14s %14" PRI64_PREFIX "u %14s\n",
               tbsys::CNetUtil::addrToString(it->first).c_str(),
               it->second.read_file_count_, Func::format_size(it->second.read_byte_).c_str(),
               it->second.write_file_count_, Func::format_size(it->second.write_byte_).c_str());
      }

      has_next = req_cb_msg->has_next();
    }
    else if (ret_message->getPCode() == STATUS_MESSAGE)
    {
      StatusMessage* s_msg = dynamic_cast<StatusMessage*> (ret_message);
      fprintf(stderr, "get status msg, ret: %d, error: %s\n", s_msg->get_status(), s_msg->get_error());
      ret = s_msg->get_status();
    }

    NewClientManager::get_instance().destroy_client(client);

    if (TFS_SUCCESS == ret)
    {
      if (get_all)
      {
        if (!has_next)
        {
          break;
        }
        else
        {
          start_row += return_row;
        }
      }
      else
      {
        break;
      }
    }
    else
    {
      break;
    }
  }
  return ret;
}