-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. curvefs_tool add create-fs command whitch send create-fs rpc to mds/topology 2. rename buildtopo directory
- Loading branch information
1 parent
df55c9a
commit 81ef9ff
Showing
14 changed files
with
409 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* Copyright (c) 2021 NetEase Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/* | ||
* Project: curve | ||
* Created Date: 2021-12-23 | ||
* Author: chengyi01 | ||
*/ | ||
|
||
#include "curvefs/src/tools/create/curvefs_create_fs.h" | ||
|
||
#include "curvefs/proto/common.pb.h" | ||
#include "curvefs/src/tools/curvefs_tool_define.h" | ||
#include "src/common/string_util.h" | ||
|
||
DECLARE_string(fsName); | ||
DECLARE_string(confPath); | ||
DECLARE_string(mdsAddr); | ||
DECLARE_uint64(blockSize); | ||
DECLARE_string(fsType); | ||
DECLARE_uint64(volumeSize); | ||
DECLARE_uint64(volumeBlockSize); | ||
DECLARE_string(volumeName); | ||
DECLARE_string(volumeUser); | ||
DECLARE_string(volumePassword); | ||
DECLARE_string(s3_ak); | ||
DECLARE_string(s3_sk); | ||
DECLARE_string(s3_endpoint); | ||
DECLARE_string(s3_bucket_name); | ||
DECLARE_uint64(s3_blocksize); | ||
DECLARE_uint64(s3_chunksize); | ||
|
||
namespace curvefs { | ||
namespace tools { | ||
namespace create { | ||
|
||
void CreateFsTool::PrintHelp() { | ||
CurvefsToolRpc::PrintHelp(); | ||
std::cout << " -fsName=" << FLAGS_fsName | ||
<< "[-blockSize=" << FLAGS_blockSize | ||
<< "] [-fsType=volume -volumeSize=" << FLAGS_volumeSize | ||
<< " -volumeBlockSize=" << FLAGS_volumeBlockSize | ||
<< " -volumeName=" << FLAGS_volumeName | ||
<< " -volumeUser=" << FLAGS_volumeUser | ||
<< " -volumePassword=" << FLAGS_volumePassword | ||
<< "]|[-fsType=s3 -s3_ak=" << FLAGS_s3_ak | ||
<< " -s3_sk=" << FLAGS_s3_sk | ||
<< " -s3_endpoint=" << FLAGS_s3_endpoint | ||
<< " -s3_bucket_name=" << FLAGS_s3_bucket_name | ||
<< " -s3_blocksize=" << FLAGS_s3_blocksize | ||
<< " -s3_chunkSize=" << FLAGS_s3_chunksize | ||
<< "] [-mdsAddr=" << FLAGS_mdsAddr << "]" << std::endl; | ||
} | ||
|
||
void CreateFsTool::AddUpdateFlags() { | ||
AddUpdateFlagsFunc(curvefs::tools::SetMdsAddr); | ||
AddUpdateFlagsFunc(curvefs::tools::SetBlockSize); | ||
AddUpdateFlagsFunc(curvefs::tools::SetFsType); | ||
AddUpdateFlagsFunc(curvefs::tools::SetVolumeSize); | ||
AddUpdateFlagsFunc(curvefs::tools::SetVolumeBlockSize); | ||
AddUpdateFlagsFunc(curvefs::tools::SetVolumeName); | ||
AddUpdateFlagsFunc(curvefs::tools::SetVolumeUser); | ||
AddUpdateFlagsFunc(curvefs::tools::SetVolumePassword); | ||
AddUpdateFlagsFunc(curvefs::tools::SetS3_sk); | ||
AddUpdateFlagsFunc(curvefs::tools::SetS3_sk); | ||
AddUpdateFlagsFunc(curvefs::tools::SetS3_endpoint); | ||
AddUpdateFlagsFunc(curvefs::tools::SetS3_bucket_name); | ||
AddUpdateFlagsFunc(curvefs::tools::SetS3_blocksize); | ||
AddUpdateFlagsFunc(curvefs::tools::SetS3_chunksize); | ||
} | ||
|
||
int CreateFsTool::Init() { | ||
google::CommandLineFlagInfo info; | ||
if (CheckFsNameDefault(&info)) { | ||
std::cerr << "no -fsName=***, please check it!" << std::endl; | ||
return -1; | ||
} | ||
int ret = CurvefsToolRpc::Init(); | ||
|
||
curve::common::SplitString(FLAGS_mdsAddr, ",", &hostsAddr_); | ||
service_stub_func_ = | ||
std::bind(&mds::MdsService_Stub::CreateFs, service_stub_.get(), | ||
std::placeholders::_1, std::placeholders::_2, | ||
std::placeholders::_3, nullptr); | ||
|
||
mds::CreateFsRequest request; | ||
request.set_fsname(FLAGS_fsName); | ||
request.set_blocksize(FLAGS_blockSize); | ||
if (FLAGS_fsType == "s3") { | ||
// s3 | ||
request.set_fstype(common::FSType::TYPE_S3); | ||
auto s3 = new common::S3Info(); | ||
s3->set_ak(FLAGS_s3_ak); | ||
s3->set_sk(FLAGS_s3_sk); | ||
s3->set_endpoint(FLAGS_s3_endpoint); | ||
s3->set_bucketname(FLAGS_s3_bucket_name); | ||
s3->set_blocksize(FLAGS_s3_blocksize); | ||
s3->set_chunksize(FLAGS_s3_chunksize); | ||
request.mutable_fsdetail()->set_allocated_s3info(s3); | ||
} else if (FLAGS_fsType == "volume") { | ||
// volume | ||
request.set_fstype(common::FSType::TYPE_S3); | ||
auto volume = new common::Volume(); | ||
volume->set_volumesize(FLAGS_volumeSize); | ||
volume->set_blocksize(FLAGS_volumeBlockSize); | ||
volume->set_volumename(FLAGS_volumeName); | ||
volume->set_user(FLAGS_volumeUser); | ||
volume->set_password(FLAGS_volumePassword); | ||
request.mutable_fsdetail()->set_allocated_volume(volume); | ||
} else { | ||
std::cerr << "-fsType should be s3 or volume." << std::endl; | ||
ret = -1; | ||
} | ||
|
||
AddRequest(request); | ||
return ret; | ||
} | ||
|
||
bool CreateFsTool::AfterSendRequestToHost(const std::string& host) { | ||
bool ret = true; | ||
if (controller_->Failed()) { | ||
errorOutput_ << "send create fs request to mds: " << host | ||
<< " failed, errorcode= " << controller_->ErrorCode() | ||
<< ", error text: " << controller_->ErrorText() | ||
<< std::endl; | ||
ret = false; | ||
} else if (response_->statuscode() == mds::FSStatusCode::OK) { | ||
// create success | ||
std::cout << "create fs success." << std::endl; | ||
if (response_->has_fsinfo()) { | ||
auto const& fsInfo = response_->fsinfo(); | ||
std::cout << "the create fs info is:\n" | ||
<< fsInfo.ShortDebugString() << std::endl; | ||
} | ||
} else { | ||
// create fail | ||
std::cerr << "create fs failed, errorcode= " << response_->statuscode() | ||
<< ", error name: " | ||
<< mds::FSStatusCode_Name(response_->statuscode()) | ||
<< std::endl; | ||
ret = false; | ||
} | ||
return ret; | ||
} | ||
|
||
} // namespace create | ||
} // namespace tools | ||
} // namespace curvefs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2021 NetEase Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/* | ||
* Project: curve | ||
* Created Date: 2021-12-23 | ||
* Author: chengyi01 | ||
*/ | ||
|
||
#ifndef CURVEFS_SRC_TOOLS_CREATE_CURVEFS_CREATE_FS_H_ | ||
#define CURVEFS_SRC_TOOLS_CREATE_CURVEFS_CREATE_FS_H_ | ||
|
||
#include <string> | ||
|
||
#include "curvefs/proto/mds.pb.h" | ||
#include "curvefs/src/tools/curvefs_tool.h" | ||
#include "curvefs/src/tools/curvefs_tool_define.h" | ||
|
||
namespace curvefs { | ||
namespace tools { | ||
namespace create { | ||
|
||
class CreateFsTool : public CurvefsToolRpc<curvefs::mds::CreateFsRequest, | ||
curvefs::mds::CreateFsResponse, | ||
curvefs::mds::MdsService_Stub> { | ||
public: | ||
explicit CreateFsTool(const std::string& cmd = kCreateFsCmd, | ||
bool show = true) | ||
: CurvefsToolRpc(cmd) { | ||
show_ = show; | ||
} | ||
void PrintHelp() override; | ||
|
||
int Init() override; | ||
|
||
protected: | ||
void AddUpdateFlags() override; | ||
bool AfterSendRequestToHost(const std::string& host) override; | ||
}; | ||
|
||
} // namespace create | ||
} // namespace tools | ||
} // namespace curvefs | ||
|
||
#endif // CURVEFS_SRC_TOOLS_CREATE_CURVEFS_CREATE_FS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.