Page MenuHomePhabricator

D5165.diff
No OneTemporary

D5165.diff

diff --git a/services/tunnelbroker/src/Database/DatabaseManager.h b/services/tunnelbroker/src/Database/DatabaseManager.h
--- a/services/tunnelbroker/src/Database/DatabaseManager.h
+++ b/services/tunnelbroker/src/Database/DatabaseManager.h
@@ -19,6 +19,8 @@
#include <aws/dynamodb/model/GetItemRequest.h>
#include <aws/dynamodb/model/PutItemRequest.h>
#include <aws/dynamodb/model/QueryRequest.h>
+#include <aws/dynamodb/model/UpdateItemRequest.h>
+#include <aws/dynamodb/model/UpdateItemResult.h>
#include <memory>
#include <string>
@@ -40,6 +42,7 @@
std::shared_ptr<DeviceSessionItem>
findSessionItem(const std::string &deviceID);
void removeSessionItem(const std::string &sessionID);
+ void updateSessionItemIsOnline(const std::string &sessionID, bool isOnline);
void putSessionSignItem(const SessionSignItem &item);
std::shared_ptr<SessionSignItem>
diff --git a/services/tunnelbroker/src/Database/DatabaseManager.cpp b/services/tunnelbroker/src/Database/DatabaseManager.cpp
--- a/services/tunnelbroker/src/Database/DatabaseManager.cpp
+++ b/services/tunnelbroker/src/Database/DatabaseManager.cpp
@@ -2,6 +2,8 @@
#include "DynamoDBTools.h"
#include "GlobalTools.h"
+#include <glog/logging.h>
+
namespace comm {
namespace network {
namespace database {
@@ -76,6 +78,43 @@
this->innerRemoveItem(*item);
}
+void DatabaseManager::updateSessionItemIsOnline(
+ const std::string &sessionID,
+ bool isOnline) {
+ std::shared_ptr<DeviceSessionItem> item = this->findSessionItem(sessionID);
+ if (item == nullptr) {
+ LOG(ERROR) << "Can't find for update sessionItem for sessionID: "
+ << sessionID;
+ return;
+ }
+ Aws::DynamoDB::Model::UpdateItemRequest request;
+ request.SetTableName(item->getTableName());
+
+ Aws::DynamoDB::Model::AttributeValue attributeKeyValue;
+ attributeKeyValue.SetS(sessionID);
+ request.AddKey(DeviceSessionItem::FIELD_SESSION_ID, attributeKeyValue);
+ Aws::String update_expression("SET #a = :valueA");
+ request.SetUpdateExpression(update_expression);
+ Aws::Map<Aws::String, Aws::String> expressionAttributeNames;
+ expressionAttributeNames["#a"] = DeviceSessionItem::FIELD_IS_ONLINE;
+ request.SetExpressionAttributeNames(expressionAttributeNames);
+
+ Aws::DynamoDB::Model::AttributeValue attributeUpdatedValue;
+ attributeUpdatedValue.SetBool(isOnline);
+ Aws::Map<Aws::String, Aws::DynamoDB::Model::AttributeValue>
+ expressionAttributeValue;
+ expressionAttributeValue[":valueA"] = attributeUpdatedValue;
+ request.SetExpressionAttributeValues(expressionAttributeValue);
+
+ const Aws::DynamoDB::Model::UpdateItemOutcome &result =
+ getDynamoDBClient()->UpdateItem(request);
+ if (!result.IsSuccess()) {
+ LOG(ERROR) << "Error updating device online status at "
+ "`updateSessionItemIsOnline`: "
+ << result.GetError().GetMessage();
+ }
+}
+
void DatabaseManager::putSessionSignItem(const SessionSignItem &item) {
Aws::DynamoDB::Model::PutItemRequest request;
request.SetTableName(item.getTableName());

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 11:39 PM (21 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577662
Default Alt Text
D5165.diff (3 KB)

Event Timeline