s3_file_uploader.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #include <array>
16 #include <vector>
17 
18 #include <aws/core/utils/logging/LogMacros.h>
20 #include <file_uploader_msgs/UploadFilesAction.h>
23 #include <s3_common/utils.h>
24 
26 #include <actionlib_msgs/GoalID.h>
27 #include <ros/ros.h>
28 
31 
32 
33 constexpr char kBucketNameParameter[] = "s3_bucket";
34 constexpr char kEnableEncryptionParameter[] = "enable_encryption";
35 constexpr char kSpinnerThreadCountOverrideParameter[] = "spinner_thread_count";
36 
41 constexpr uint32_t kDefaultNumberOfSpinnerThreads = 2;
42 
43 namespace Aws
44 {
45 namespace S3
46 {
47 
48 
49 S3FileUploader::S3FileUploader(std::unique_ptr<S3UploadManager> upload_manager) :
50  node_handle_("~"),
51  action_server_(node_handle_, "UploadFiles", false)
52 {
53  parameter_reader_ = std::make_shared<Aws::Client::Ros1NodeParameterReader>();
54 
55  if (upload_manager) {
56  upload_manager_ = move(upload_manager);
57  } else {
58  bool enable_encryption = false;
59  if (Aws::AwsError::AWS_ERR_OK != parameter_reader_->ReadParam(Aws::Client::ParameterPath(kEnableEncryptionParameter), enable_encryption)) {
60  AWS_LOG_INFO(__func__, "No user setting for data encryption provided, defaulting to no data encryption");
61  }
62 
64  Aws::Client::ClientConfiguration aws_sdk_config = configuration_provider.GetClientConfiguration();
65 
66  upload_manager_ = std::make_unique<S3UploadManager>(enable_encryption, aws_sdk_config);
67  }
68 
70  [this](UploadFilesActionServer::GoalHandle goal_handle) {
72  }
73  );
74 
76  [this](UploadFilesActionServer::GoalHandle /*goal_handle*/) {
78  }
79  );
80 
82 }
83 
85 {
86  if (Aws::AwsError::AWS_ERR_OK != parameter_reader_->ReadParam(Aws::Client::ParameterPath(kBucketNameParameter), bucket_)) {
87  AWS_LOG_ERROR(__func__, "Failed to load s3 bucket name, aborting. Check the configuration file for parameter s3_bucket");
88  return;
89  }
90 
91  uint32_t spinner_thread_count = kDefaultNumberOfSpinnerThreads;
92  int spinner_thread_count_input;
93  if (Aws::AwsError::AWS_ERR_OK ==
95  spinner_thread_count_input)) {
96  if (spinner_thread_count_input < 0) {
97  spinner_thread_count = 0;
98  } else {
99  spinner_thread_count = static_cast<uint32_t>(spinner_thread_count_input);
100  }
101  }
102 
103  AWS_LOG_INFO(__func__, "Starting S3FileUploader spinner with bucket %s and thread count %d\n", bucket_.c_str(), spinner_thread_count);
104  ros::MultiThreadedSpinner executor(spinner_thread_count);
105  executor.spin();
106 }
107 
108 } // namespace S3
109 } // namespace Aws
UploadFilesActionServer action_server_
constexpr char kSpinnerThreadCountOverrideParameter[]
constexpr uint32_t kDefaultNumberOfSpinnerThreads
void registerGoalCallback(boost::function< void(GoalHandle)> cb)
std::unique_ptr< S3UploadManager > upload_manager_
static void UploadToS3(S3UploadManager &upload_manager, const std::string &bucket, T &goal_handle)
static void CancelUploadToS3(S3UploadManager &upload_manager)
void registerCancelCallback(boost::function< void(GoalHandle)> cb)
ClientConfiguration GetClientConfiguration(const std::string &ros_version_override="")
std::shared_ptr< Aws::Client::Ros1NodeParameterReader > parameter_reader_
S3FileUploader(std::unique_ptr< S3UploadManager > upload_manager=nullptr)
constexpr char kEnableEncryptionParameter[]
constexpr char kBucketNameParameter[]


s3_file_uploader
Author(s): AWS RoboMaker
autogenerated on Tue Jun 1 2021 02:51:30