forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement create space, drop space, add hosts, show hosts , remove ho…
…sts via MetaClient (vesoft-inc#223) close vesoft-inc#200
- Loading branch information
Showing
30 changed files
with
1,079 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved | ||
* | ||
* This source code is licensed under Apache 2.0 License | ||
* (found in the LICENSE.Apache file in the root directory) | ||
*/ | ||
|
||
#include "graph/AddHostsExecutor.h" | ||
|
||
namespace nebula { | ||
namespace graph { | ||
|
||
AddHostsExecutor::AddHostsExecutor(Sentence *sentence, | ||
ExecutionContext *ectx) : Executor(ectx) { | ||
sentence_ = static_cast<AddHostsSentence*>(sentence); | ||
} | ||
|
||
|
||
Status AddHostsExecutor::prepare() { | ||
hosts_ = sentence_->hosts(); | ||
if (hosts_.size() == 0) { | ||
return Status::Error("Host address illegal"); | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
|
||
void AddHostsExecutor::execute() { | ||
auto future = ectx()->getMetaClient()->addHosts(hosts_); | ||
auto *runner = ectx()->rctx()->runner(); | ||
|
||
auto cb = [this] (auto &&resp) { | ||
if (!resp.ok()) { | ||
DCHECK(onError_); | ||
onError_(resp.status()); | ||
return; | ||
} | ||
auto ret = resp.value(); | ||
if (!ret) { | ||
DCHECK(onError_); | ||
onError_(Status::Error("Add hosts failed")); | ||
return; | ||
} | ||
DCHECK(onFinish_); | ||
onFinish_(); | ||
}; | ||
|
||
auto error = [this] (auto &&e) { | ||
LOG(ERROR) << "Exception caught: " << e.what(); | ||
DCHECK(onError_); | ||
onError_(Status::Error("Internal error")); | ||
return; | ||
}; | ||
|
||
std::move(future).via(runner).thenValue(cb).thenError(error); | ||
} | ||
|
||
} // namespace graph | ||
} // namespace nebula |
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,36 @@ | ||
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved | ||
* | ||
* This source code is licensed under Apache 2.0 License | ||
* (found in the LICENSE.Apache file in the root directory) | ||
*/ | ||
|
||
#ifndef GRAPH_ADDHOSTSEXECUTOR_H_ | ||
#define GRAPH_ADDHOSTSEXECUTOR_H_ | ||
|
||
#include "base/Base.h" | ||
#include "graph/Executor.h" | ||
|
||
namespace nebula { | ||
namespace graph { | ||
|
||
class AddHostsExecutor final : public Executor { | ||
public: | ||
AddHostsExecutor(Sentence *sentence, ExecutionContext *ectx); | ||
|
||
const char* name() const override { | ||
return "AddHostsExecutor"; | ||
} | ||
|
||
Status MUST_USE_RESULT prepare() override; | ||
|
||
void execute() override; | ||
|
||
private: | ||
AddHostsSentence *sentence_{nullptr}; | ||
std::vector<HostAddr> hosts_; | ||
}; | ||
|
||
} // namespace graph | ||
} // namespace nebula | ||
|
||
#endif // GRAPH_ADDHOSTSEXECUTOR_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved | ||
* | ||
* This source code is licensed under Apache 2.0 License | ||
* (found in the LICENSE.Apache file in the root directory) | ||
*/ | ||
|
||
#include "graph/CreateSpaceExecutor.h" | ||
|
||
namespace nebula { | ||
namespace graph { | ||
|
||
CreateSpaceExecutor::CreateSpaceExecutor(Sentence *sentence, | ||
ExecutionContext *ectx) : Executor(ectx) { | ||
sentence_ = static_cast<CreateSpaceSentence*>(sentence); | ||
} | ||
|
||
|
||
Status CreateSpaceExecutor::prepare() { | ||
spaceName_ = sentence_->spaceName(); | ||
for (auto &item : sentence_->getOpts()) { | ||
switch (item->getOptType()) { | ||
case SpaceOptItem::PARTITION_NUM: | ||
partNum_ = item->get_partition_num(); | ||
break; | ||
case SpaceOptItem::REPLICA_FACTOR: | ||
replicaFactor_ = item->get_replica_factor(); | ||
break; | ||
} | ||
} | ||
if (partNum_ == 0) { | ||
return Status::Error("Partition_num value illegal"); | ||
} | ||
if (replicaFactor_ == 0) { | ||
return Status::Error("Replica_factor value illegal"); | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
|
||
void CreateSpaceExecutor::execute() { | ||
auto future = ectx()->getMetaClient()->createSpace(*spaceName_, partNum_, replicaFactor_); | ||
auto *runner = ectx()->rctx()->runner(); | ||
|
||
auto cb = [this] (auto &&resp) { | ||
if (!resp.ok()) { | ||
DCHECK(onError_); | ||
onError_(resp.status()); | ||
return; | ||
} | ||
auto spaceId = resp.value(); | ||
if (spaceId <= 0) { | ||
DCHECK(onError_); | ||
onError_(Status::Error("Create space failed")); | ||
return; | ||
} | ||
DCHECK(onFinish_); | ||
onFinish_(); | ||
}; | ||
|
||
auto error = [this] (auto &&e) { | ||
LOG(ERROR) << "Exception caught: " << e.what(); | ||
DCHECK(onError_); | ||
onError_(Status::Error("Internal error")); | ||
return; | ||
}; | ||
|
||
std::move(future).via(runner).thenValue(cb).thenError(error); | ||
} | ||
|
||
} // namespace graph | ||
} // namespace nebula |
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,38 @@ | ||
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved | ||
* | ||
* This source code is licensed under Apache 2.0 License | ||
* (found in the LICENSE.Apache file in the root directory) | ||
*/ | ||
|
||
#ifndef GRAPH_CREATESPACEEXECUTOR_H_ | ||
#define GRAPH_CREATESPACEEXECUTOR_H_ | ||
|
||
#include "base/Base.h" | ||
#include "graph/Executor.h" | ||
|
||
namespace nebula { | ||
namespace graph { | ||
|
||
class CreateSpaceExecutor final : public Executor { | ||
public: | ||
CreateSpaceExecutor(Sentence *sentence, ExecutionContext *ectx); | ||
|
||
const char* name() const override { | ||
return "CreateSpaceExecutor"; | ||
} | ||
|
||
Status MUST_USE_RESULT prepare() override; | ||
|
||
void execute() override; | ||
|
||
private: | ||
CreateSpaceSentence *sentence_{nullptr}; | ||
std::string *spaceName_{nullptr}; | ||
int32_t partNum_{0}; | ||
int32_t replicaFactor_{0}; | ||
}; | ||
|
||
} // namespace graph | ||
} // namespace nebula | ||
|
||
#endif // GRAPH_CREATESPACEEXECUTOR_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved | ||
* | ||
* This source code is licensed under Apache 2.0 License | ||
* (found in the LICENSE.Apache file in the root directory) | ||
*/ | ||
|
||
#include "graph/DropSpaceExecutor.h" | ||
|
||
namespace nebula { | ||
namespace graph { | ||
|
||
DropSpaceExecutor::DropSpaceExecutor(Sentence *sentence, | ||
ExecutionContext *ectx) : Executor(ectx) { | ||
sentence_ = static_cast<DropSpaceSentence*>(sentence); | ||
} | ||
|
||
|
||
Status DropSpaceExecutor::prepare() { | ||
spaceName_ = sentence_->spaceName(); | ||
return Status::OK(); | ||
} | ||
|
||
|
||
void DropSpaceExecutor::execute() { | ||
auto future = ectx()->getMetaClient()->dropSpace(*spaceName_); | ||
auto *runner = ectx()->rctx()->runner(); | ||
|
||
auto cb = [this] (auto &&resp) { | ||
if (!resp.ok()) { | ||
DCHECK(onError_); | ||
onError_(resp.status()); | ||
return; | ||
} | ||
auto ret = resp.value(); | ||
if (!ret) { | ||
DCHECK(onError_); | ||
onError_(Status::Error("Drop space failed")); | ||
return; | ||
} | ||
DCHECK(onFinish_); | ||
onFinish_(); | ||
}; | ||
|
||
auto error = [this] (auto &&e) { | ||
LOG(ERROR) << "Exception caught: " << e.what(); | ||
DCHECK(onError_); | ||
onError_(Status::Error("Internal error")); | ||
return; | ||
}; | ||
|
||
std::move(future).via(runner).thenValue(cb).thenError(error); | ||
} | ||
|
||
} // namespace graph | ||
} // namespace nebula |
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,36 @@ | ||
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved | ||
* | ||
* This source code is licensed under Apache 2.0 License | ||
* (found in the LICENSE.Apache file in the root directory) | ||
*/ | ||
|
||
#ifndef GRAPH_DROPSPACEEXECUTOR_H_ | ||
#define GRAPH_DROPSPACEEXECUTOR_H_ | ||
|
||
#include "base/Base.h" | ||
#include "graph/Executor.h" | ||
|
||
namespace nebula { | ||
namespace graph { | ||
|
||
class DropSpaceExecutor final : public Executor { | ||
public: | ||
DropSpaceExecutor(Sentence *sentence, ExecutionContext *ectx); | ||
|
||
const char* name() const override { | ||
return "DropSpaceExecutor"; | ||
} | ||
|
||
Status MUST_USE_RESULT prepare() override; | ||
|
||
void execute() override; | ||
|
||
private: | ||
DropSpaceSentence *sentence_{nullptr}; | ||
std::string *spaceName_{nullptr}; | ||
}; | ||
|
||
} // namespace graph | ||
} // namespace nebula | ||
|
||
#endif // GRAPH_DROPSPACEEXECUTOR_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
Oops, something went wrong.