Page MenuHomePhabricator

D3248.id10021.diff
No OneTemporary

D3248.id10021.diff

diff --git a/services/backup/docker-server/contents/server/src/BackupServiceImpl.h b/services/backup/docker-server/contents/server/src/BackupServiceImpl.h
--- a/services/backup/docker-server/contents/server/src/BackupServiceImpl.h
+++ b/services/backup/docker-server/contents/server/src/BackupServiceImpl.h
@@ -8,31 +8,28 @@
namespace comm {
namespace network {
-class BackupServiceImpl final : public backup::BackupService::Service {
+class BackupServiceImpl final : public backup::BackupService::CallbackService {
public:
BackupServiceImpl();
virtual ~BackupServiceImpl();
- grpc::Status CreateNewBackup(
- grpc::ServerContext *context,
- grpc::ServerReaderWriter<
- backup::CreateNewBackupResponse,
- backup::CreateNewBackupRequest> *stream) override;
- grpc::Status SendLog(
- grpc::ServerContext *context,
- grpc::ServerReader<backup::SendLogRequest> *reader,
+ grpc::ServerBidiReactor<
+ backup::CreateNewBackupRequest,
+ backup::CreateNewBackupResponse> *
+ CreateNewBackup(grpc::CallbackServerContext *context) override;
+
+ grpc::ServerReadReactor<backup::SendLogRequest> *SendLog(
+ grpc::CallbackServerContext *context,
google::protobuf::Empty *response) override;
- grpc::Status RecoverBackupKey(
- grpc::ServerContext *context,
- grpc::ServerReaderWriter<
- backup::RecoverBackupKeyResponse,
- backup::RecoverBackupKeyRequest> *stream) override;
- grpc::Status PullBackup(
- grpc::ServerContext *context,
- grpc::ServerReaderWriter<
- backup::PullBackupResponse,
- backup::PullBackupRequest> *stream) override;
+
+ grpc::ServerBidiReactor<
+ backup::RecoverBackupKeyRequest,
+ backup::RecoverBackupKeyResponse> *
+ RecoverBackupKey(grpc::CallbackServerContext *context) override;
+
+ grpc::ServerBidiReactor<backup::PullBackupRequest, backup::PullBackupResponse>
+ *PullBackup(grpc::CallbackServerContext *context) override;
};
} // namespace network
diff --git a/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp b/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp
--- a/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp
+++ b/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp
@@ -1,5 +1,9 @@
#include "BackupServiceImpl.h"
+#include "AuthenticationManager.h"
+#include "BidiReactorBase.h"
+#include "ReadReactorBase.h"
+
#include <aws/core/Aws.h>
namespace comm {
@@ -13,35 +17,106 @@
Aws::ShutdownAPI({});
}
-grpc::Status BackupServiceImpl::CreateNewBackup(
- grpc::ServerContext *context,
- grpc::ServerReaderWriter<
- backup::CreateNewBackupResponse,
- backup::CreateNewBackupRequest> *stream) {
- return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet");
+grpc::ServerBidiReactor<
+ backup::CreateNewBackupRequest,
+ backup::CreateNewBackupResponse> *
+BackupServiceImpl::CreateNewBackup(grpc::CallbackServerContext *context) {
+ class CreateNewBackupReactor : public BidiReactorBase<
+ backup::CreateNewBackupRequest,
+ backup::CreateNewBackupResponse> {
+ auth::AuthenticationManager authenticationManager;
+
+ public:
+ std::unique_ptr<grpc::Status> handleRequest(
+ backup::CreateNewBackupRequest request,
+ backup::CreateNewBackupResponse *response) override {
+ if (this->authenticationManager.getState() !=
+ auth::AuthenticationState::SUCCESS &&
+ !request.has_authenticationrequestdata()) {
+ return std::make_unique<grpc::Status>(
+ grpc::StatusCode::INTERNAL,
+ "authentication has not been finished properly");
+ }
+ if (this->authenticationManager.getState() ==
+ auth::AuthenticationState::FAIL) {
+ return std::make_unique<grpc::Status>(
+ grpc::StatusCode::INTERNAL, "authentication failure");
+ }
+ if (this->authenticationManager.getState() !=
+ auth::AuthenticationState::SUCCESS) {
+ backup::FullAuthenticationResponseData authResponse =
+ this->authenticationManager.processRequest(
+ request.authenticationrequestdata());
+ // warning: core dumps possible, in such a case, try making the response
+ // a member of CreateNewBackupReactor class
+ response->set_allocated_authenticationresponsedata(&authResponse);
+ return nullptr;
+ }
+ // TODO handle request
+ return std::make_unique<grpc::Status>(
+ grpc::StatusCode::UNIMPLEMENTED, "unimplemented");
+ }
+ };
+
+ return new CreateNewBackupReactor();
}
-grpc::Status BackupServiceImpl::SendLog(
- grpc::ServerContext *context,
- grpc::ServerReader<backup::SendLogRequest> *reader,
+grpc::ServerReadReactor<backup::SendLogRequest> *BackupServiceImpl::SendLog(
+ grpc::CallbackServerContext *context,
google::protobuf::Empty *response) {
- return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet");
+ class SendLogReactor : public ReadReactorBase<
+ backup::SendLogRequest,
+ google::protobuf::Empty> {
+ public:
+ using ReadReactorBase<backup::SendLogRequest, google::protobuf::Empty>::
+ ReadReactorBase;
+ std::unique_ptr<grpc::Status>
+ readRequest(backup::SendLogRequest request) override {
+ // TODO handle request
+ return std::make_unique<grpc::Status>(
+ grpc::StatusCode::UNIMPLEMENTED, "unimplemented");
+ }
+ };
+
+ return new SendLogReactor(response);
}
-grpc::Status BackupServiceImpl::RecoverBackupKey(
- grpc::ServerContext *context,
- grpc::ServerReaderWriter<
- backup::RecoverBackupKeyResponse,
- backup::RecoverBackupKeyRequest> *stream) {
- return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet");
+grpc::ServerBidiReactor<
+ backup::RecoverBackupKeyRequest,
+ backup::RecoverBackupKeyResponse> *
+BackupServiceImpl::RecoverBackupKey(grpc::CallbackServerContext *context) {
+ class RecoverBackupKeyReactor : public BidiReactorBase<
+ backup::RecoverBackupKeyRequest,
+ backup::RecoverBackupKeyResponse> {
+ public:
+ std::unique_ptr<grpc::Status> handleRequest(
+ backup::RecoverBackupKeyRequest request,
+ backup::RecoverBackupKeyResponse *response) override {
+ // TODO handle request
+ return std::make_unique<grpc::Status>(
+ grpc::StatusCode::UNIMPLEMENTED, "unimplemented");
+ }
+ };
+
+ return new RecoverBackupKeyReactor();
}
-grpc::Status BackupServiceImpl::PullBackup(
- grpc::ServerContext *context,
- grpc::ServerReaderWriter<
- backup::PullBackupResponse,
- backup::PullBackupRequest> *stream) {
- return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet");
+grpc::ServerBidiReactor<backup::PullBackupRequest, backup::PullBackupResponse> *
+BackupServiceImpl::PullBackup(grpc::CallbackServerContext *context) {
+ class PullBackupReactor : public BidiReactorBase<
+ backup::PullBackupRequest,
+ backup::PullBackupResponse> {
+ public:
+ std::unique_ptr<grpc::Status> handleRequest(
+ backup::PullBackupRequest request,
+ backup::PullBackupResponse *response) override {
+ // TODO handle request
+ return std::make_unique<grpc::Status>(
+ grpc::StatusCode::UNIMPLEMENTED, "unimplemented");
+ }
+ };
+
+ return new PullBackupReactor();
}
} // namespace network

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 25, 5:52 PM (1 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2702858
Default Alt Text
D3248.id10021.diff (7 KB)

Event Timeline