Example #1
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;
}
Example #2
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;
}
Example #3
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;
}
Example #4
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)";
	}
Example #5
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;
}
Example #6
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;
}
Example #7
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;
}
Example #8
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;
}
Example #9
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 #10
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;
}
Example #11
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);
}
Example #12
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;
}
Example #13
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;
}
Example #14
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;
}
Example #15
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;
}
Example #16
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;
}
Example #17
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;
}
Example #18
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;
}
Example #19
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;
}
Example #20
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;
}
Example #21
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;
}
Example #22
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;
}
Example #23
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;
}
Example #24
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;
}
Example #25
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;
}
Example #26
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;
}
Example #27
0
int cmd_replicate_block(const VSTRING& param)
{
  uint64_t block_id = strtoull(param[0].c_str(), NULL, 10);
  int32_t op_type = atoi(param[1].c_str());
  if (0 == block_id || op_type > 7 || op_type < 1)
  {
    fprintf(stderr, "invalid param. blockid: %"PRI64_PREFIX"u, typeid: %d, blockid > 0, typeid in [1, 7]\n", block_id, op_type);
    return TFS_ERROR;
  }

  ReplicateBlockMoveFlag flag = REPLICATE_BLOCK_MOVE_FLAG_NO;
  uint64_t src_id = 0;
  uint64_t dest_id = 0;
  string action = "no";

  int32_t size = param.size();
  switch (op_type)
  {
  case 1:
    if (size != 3 || (param[2] != "yes" && param[2] != "no") )
    {
      fprintf(stderr, "replblk blockid 1 action\n");
      fprintf(stderr, "action: yes -- move block\n");
      fprintf(stderr, "        no -- replicate block\n");
      return TFS_ERROR;
    }
    action = param[2];
    break;
  case 2:
    if (size != 3)
    {
      fprintf(stderr, "replblk blockid 2 src\n");
      return TFS_ERROR;
    }
    src_id = Func::get_host_ip(param[2].c_str());
    if (src_id == 0)
    {
      fprintf(stderr, "src addr is not correct, please check it\n");
      return TFS_ERROR;
    }
    break;
  case 3:
    if (size != 3)
    {
      fprintf(stderr, "replblk blockid 3 dest\n");
      return TFS_ERROR;
    }
    dest_id = Func::get_host_ip(param[2].c_str());
    if (dest_id == 0)
    {
      fprintf(stderr, "src addr is not correct, please check it\n");
      return TFS_ERROR;
    }
    break;
  case 4:
    if (size != 4 || (param[2] != "yes" && param[2] != "no") )
    {
      fprintf(stderr, "replblk blockid 4 action src\n");
      fprintf(stderr, "action: yes -- move block\n");
      fprintf(stderr, "        no -- replicate block\n");
      return TFS_ERROR;
    }
    action = param[2];
    src_id = Func::get_host_ip(param[3].c_str());
    if (src_id == 0)
    {
      fprintf(stderr, "src addr is not correct, please check it\n");
      return TFS_ERROR;
    }
    break;
  case 5:
    if (size != 4 || (param[2] != "yes" && param[2] != "no") )
    {
      fprintf(stderr, "replblk blockid 5 action dest\n");
      fprintf(stderr, "action: yes -- move block\n");
      fprintf(stderr, "        no -- replicate block\n");
      return TFS_ERROR;
    }
    action = param[2];
    dest_id = Func::get_host_ip(param[3].c_str());
    if (dest_id == 0)
    {
      fprintf(stderr, "dest addr is not correct, please check it\n");
      return TFS_ERROR;
    }
    break;
  case 6:
    if (size != 4)
    {
      fprintf(stderr, "replblk blockid 6 src dest\n");
      return TFS_ERROR;
    }
    src_id = Func::get_host_ip(param[2].c_str());
    dest_id = Func::get_host_ip(param[3].c_str());
    if (src_id == 0 || dest_id == 0)
    {
      fprintf(stderr, "src or dest addr is not correct, please check it\n");
      return TFS_ERROR;
    }
    break;
  case 7:
    if (size != 5 || (param[2] != "yes" && param[2] != "no") )
    {
      fprintf(stderr, "replblk blockid 7 action src dest\n");
      fprintf(stderr, "action: yes -- move block\n");
      fprintf(stderr, "        no -- replicate block\n");
      return TFS_ERROR;
    }
    action = param[2];
    src_id = Func::get_host_ip(param[3].c_str());
    dest_id = Func::get_host_ip(param[4].c_str());
    if (src_id == 0 || dest_id == 0)
    {
      fprintf(stderr, "src or dest addr is not correct, please check it\n");
      return TFS_ERROR;
    }
    break;
  default:
    fprintf(stderr, "error type %d must in [1,7]\n\n", op_type);
    return TFS_ERROR;
  }

  if (action == "yes")
  {
    flag = REPLICATE_BLOCK_MOVE_FLAG_YES;
  }

  ClientCmdMessage req_cc_msg;
  req_cc_msg.set_cmd(CLIENT_CMD_IMMEDIATELY_REPL);
  req_cc_msg.set_value1(src_id);
  req_cc_msg.set_value2(dest_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);
  ToolUtil::print_info(status, "replicate block %"PRI64_PREFIX"u %"PRI64_PREFIX"u %"PRI64_PREFIX"u", block_id, src_id, dest_id);

  return status;
}
Example #28
0
int cmd_batch_compact_file(const VSTRING& param)
{
  if(param.size() != 3)
  {
    fprintf(stderr, "invalid param number, command should like 'batch_compact file num interval'\n");
    return TFS_ERROR;
  }
  const char* batch_file = expand_path(const_cast<string&>(param[0]));
  g_num = (atoi(param[1].c_str()));
  g_sleep_seconds = (atoi(param[2].c_str()));

  if(g_num <= 0 || g_sleep_seconds < 0)
  {
    fprintf(stderr, "invalid num: %d or interval: %d, they should > 0\n", g_num, g_sleep_seconds);
    return TFS_ERROR;
  }
  FILE* fp = fopen(batch_file, "rb");
  int ret = TFS_SUCCESS;
  if (fp == NULL)
  {
    fprintf(stderr, "open file error: %s\n\n", batch_file);
    ret = TFS_ERROR;
  }
  else
  {
    signal(SIGUSR1, sign_handler);
    signal(SIGUSR2, sign_handler);
    signal(SIGHUP, sign_handler);

    int32_t error_count = 0;
    int32_t count = 0;
    char buffer[MAX_CMD_SIZE];
    VSTRING sub_param(1);
    while (fgets(buffer, MAX_CMD_SIZE, fp))
    {
      sub_param[0] = string(buffer);
      if ((ret = cmd_compact_block(sub_param)) != TFS_SUCCESS)
      {
        error_count++;
      }
      if (++count % 100 == 0)
      {
        fprintf(stdout, "total: %d, %d errors.\n", count, error_count);
        fflush(stdout);
      }
      if (TFS_CLIENT_QUIT == ret)
      {
        break;
      }
      do
      {
        if (g_suspend_compact || 0 == count % g_num)// suspend when signal SIGHUP set g_suspend_compact
        {
          fprintf(stdout, "sleep %ds, num: %d, current line no: %d, be suspended: %s\n",
              g_sleep_seconds, g_num, count, g_suspend_compact ? "true" : "false");
          fflush(stdout);
          sleep((unsigned int)g_sleep_seconds);
        }
      }while (g_suspend_compact);
    }
    fprintf(stdout, "total: %d, %d errors.\n\n", count, error_count);
    fclose(fp);
  }
  return TFS_SUCCESS;
}
Example #29
0
int cmd_remove_block(const VSTRING& param)
{
  uint32_t flag = 0;
  if (param.empty())
  {
    fprintf(stderr, "invalid parameter, param.empty\n");
    return TFS_ERROR;
  }
  uint64_t block_id = strtoull(param[0].c_str(), NULL, 10);
  if (0 == block_id)
  {
    fprintf(stderr, "invalid blockid %s\n", param[0].c_str());
    return TFS_ERROR;
  }
  uint64_t server_id = 0;
  if (param.size() == 1)
  {
    flag = 1;//default
  }
  else if (param.size() == 2)
  {
    if (param[1].length() == 1)
    {
      flag = atoi(param[1].c_str());
      if (1 != flag && 2 != flag && 4 != flag)
      {
        fprintf(stderr, "removeblock's flag parameter invalid\n");
        return TFS_ERROR;
      }
    }
    else//ds_ip:port
    {
      //flag = 8;//HANDLE_DELETE_BLOCK_FLAG_ONLY_ONE_RELATION
      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;
      }
    }
  }
  else
  {
    fprintf(stderr, "removeblock's parameter invalid\n");
    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 (STATUS_MESSAGE_OK == status)
    status = TFS_SUCCESS;
  else
    status = TFS_ERROR;

  if (1 == flag || 2 == flag || 4 == flag)
    ToolUtil::print_info(status, "removeblock: %s", param[0].c_str());
  else//flag=8,ds_ip:port
    ToolUtil::print_info(status, "removeblock: %s from ds:%s", param[0].c_str(), param[1].c_str());
  return status;
}
Example #30
0
int cmd_set_run_param(const VSTRING& param)
{
  /*const static char* param_str[] = {
      "min_replication",
      "max_replication",
      "max_write_file_count",
      "max_use_capacity_ratio",
      "heart_interval",
      "replicate_wait_time",
      "compact_delete_ratio",
      "compact_max_load",
      "plan_run_flag",
      "run_plan_expire_interval",
      "run_plan_ratio",
      "object_dead_max_time",
      "balance_max_diff_block_num",
      "log_level",
      "add_primary_block_count",
      "build_plan_interval",
      "replicate_ratio",
      "max_wait_write_lease",
      "dispatch_oplog",
      "cluster_index",
      "build_plan_default_wait_time",
      "group_count",
      "group_seq",
      "discard_newblk_safe_mode_time",
      "discard_max_count",
      "strategy_write_capacity_weigth",
      "strategy_write_elect_num_weigth",
      "strategy_replicate_capactiy_weigth",
      "strategy_replicate_load_weigth",
      "strategy_replicate_elect_num_weigth"
      ""
  };*/
  static int32_t param_strlen = sizeof(dynamic_parameter_str) / sizeof(char*);

  int32_t size = param.size();
  if (size != 1 && size != 3)
  {
    fprintf(stderr, "param param_name\n\n");
    for (int32_t i = 0; i < param_strlen; i++)
    {
      fprintf(stderr, "%s\n", dynamic_parameter_str[i]);
    }
    return TFS_ERROR;
  }

  const char* param_name = param[0].c_str();
  uint32_t index = 0;
  for (int32_t i = 0; i < param_strlen; i++)
  {
    if (strcmp(param_name, dynamic_parameter_str[i]) == 0)
    {
      index = i + 1;
      break;
    }
  }

  if (0 == index)
  {
    fprintf(stderr, "param %s not valid\n", param_name);
    return TFS_ERROR;
  }

  int32_t value = 0;
  bool is_set = false;

  if (3 == size)
  {
    if (strcmp("set", param[1].c_str()))
    {
      fprintf(stderr, "param %s set value\n\n", param_name);
      return TFS_ERROR;
    }
    index |= 0x10000000;//index的高16位表示set/get
    is_set = true;
    value = atoi(param[2].c_str());
  }

  ClientCmdMessage req_cc_msg;
  req_cc_msg.set_cmd(CLIENT_CMD_SET_PARAM);
  req_cc_msg.set_value3(index);
  req_cc_msg.set_value4(value);

  tbnet::Packet* ret_message = NULL;
  NewClient* client = NewClientManager::get_instance().create_client();
  send_msg_to_server(g_tfs_client->get_server_id(), client, &req_cc_msg, ret_message);

  int ret = TFS_SUCCESS;
  string ret_value = "";
  if (ret_message == NULL)
  {
    ret = TFS_ERROR;
  }
  else if (ret_message->getPCode() == STATUS_MESSAGE)
  {
    StatusMessage* s_msg = dynamic_cast<StatusMessage*> (ret_message);
    ret = s_msg->get_status();
    if (ret == STATUS_MESSAGE_OK && !is_set)
    {
      ret_value = s_msg->get_error();
    }
  }

  string ret_str = "param " +
    (is_set ? (string(param_name) + " set " + param[2]) :
     string(param_name) + " " + ret_value);

  ToolUtil::print_info(ret, "%s", ret_str.c_str());

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

  return ret;
}