Skip to content

Commit

Permalink
LogRemote upgrade configuration protocol (#12833)
Browse files Browse the repository at this point in the history
* update config

* Update LogRemote.cpp
  • Loading branch information
PatriceJiang committed Sep 22, 2022
1 parent f341032 commit 19fe1db
Showing 1 changed file with 57 additions and 17 deletions.
74 changes: 57 additions & 17 deletions native/cocos/base/LogRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,21 @@

namespace {

#define AUTO_TEST_CONFIG_FILE "auto-test-config.json"
#define ATC_KEY_CONFIG "ServerConfig"
#define ATC_KEY_IP "IP"
#define ATC_KEY_PORT "PORT"
#define ATC_KEY_PLANID "planId"
#define ATC_KEY_FLAGID "flagId"
// #define AUTO_TEST_CONFIG_FILE "auto-test-config.json" // v1
#define AUTO_TEST_CONFIG_FILE "testConfig.json" // v2

#define OLD_ATC_KEY_CONFIG "ServerConfig"
#define OLD_ATC_KEY_IP "IP"
#define OLD_ATC_KEY_PORT "PORT"
#define OLD_ATC_KEY_PLANID "planId"
#define OLD_ATC_KEY_FLAGID "flagId"

#define ATC_KEY_CONFIG "localServer"
#define ATC_KEY_IP "ip"
#define ATC_KEY_PORT "port"
#define ATC_KEY_JOBID "jobId"
#define ATC_KEY_PLATFORMS "platforms"
#define ATC_KEY_PLATFORM_INDEX "platformIndex"

enum class UdpLogClientState {
UNINITIALIZED,
Expand Down Expand Up @@ -155,26 +164,53 @@ class UdpLogClient {
return;
}

if (!doc.HasMember(ATC_KEY_CONFIG)) {
_status = UdpLogClientState::DONE;
return;
}
{
if (doc.HasMember(OLD_ATC_KEY_CONFIG)) {
// parse clientID & testID
if (doc.HasMember(ATC_KEY_FLAGID)) {
_clientID = doc[ATC_KEY_FLAGID].GetString();
if (doc.HasMember(OLD_ATC_KEY_FLAGID)) {
_clientID = doc[OLD_ATC_KEY_FLAGID].GetString();
} else {
_clientID = "flagId is not set!";
}

if (doc.HasMember(ATC_KEY_PLANID)) {
_testID = doc[ATC_KEY_PLANID].GetString();
if (doc.HasMember(OLD_ATC_KEY_PLANID)) {
_testID = doc[OLD_ATC_KEY_PLANID].GetString();
} else {
_testID = "planId is not set!";
}
}

{
// parse ip & port
rapidjson::Value &cfg = doc[OLD_ATC_KEY_CONFIG];
if (!cfg.HasMember(OLD_ATC_KEY_IP) || !cfg.HasMember(OLD_ATC_KEY_PORT)) {
_status = UdpLogClientState::DONE;
return;
}
const char *remoteIp = cfg[OLD_ATC_KEY_IP].GetString();
// The `PORT` property is used by other service and the next port is for log collection.
int remotePort = cfg[OLD_ATC_KEY_PORT].GetInt() + 1;
setServerAddr(remoteIp, remotePort);
} else if (doc.HasMember(ATC_KEY_CONFIG)) {
if (doc.HasMember(ATC_KEY_JOBID)) {
_testID = doc[ATC_KEY_JOBID].GetString();
} else {
_testID = "jobId is not set!";
}
if (doc.HasMember(ATC_KEY_PLATFORMS)) {
rapidjson::Value &platforms = doc[ATC_KEY_PLATFORMS];
if (!platforms.IsArray() || platforms.Size() < 1) {
_clientID = "array platforms is empty";
} else {
rapidjson::Value &plt = platforms[0];
if (!plt.HasMember(ATC_KEY_PLATFORM_INDEX)) {
_clientID = "platforms[0] not key platformIndex";
} else {
rapidjson::Value &index = plt[ATC_KEY_PLATFORM_INDEX];
_clientID = index.IsInt() ? std::to_string(index.GetInt()) : index.GetString();
}
}
} else {
_clientID = "platforms not set!";
}

// parse ip & port
rapidjson::Value &cfg = doc[ATC_KEY_CONFIG];
if (!cfg.HasMember(ATC_KEY_IP) || !cfg.HasMember(ATC_KEY_PORT)) {
Expand All @@ -185,7 +221,11 @@ class UdpLogClient {
// The `PORT` property is used by other service and the next port is for log collection.
int remotePort = cfg[ATC_KEY_PORT].GetInt() + 1;
setServerAddr(remoteIp, remotePort);
} else {
_status = UdpLogClientState::DONE;
return;
}

_bootID = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
Expand Down

0 comments on commit 19fe1db

Please sign in to comment.