Skip to content

Commit e8cb676

Browse files
mykola-kobets-epamal1img
authored andcommitted
cm: database: persist disableRebalance flag for launcher instance info
Signed-off-by: Mykola Kobets <mykola_kobets@epam.com> Reviewed-by: Mykhailo Lohvynenko <mykhailo_lohvynenko@epam.com> Reviewed-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com> Reviewed-by: Mykola Solianko <mykola_solianko@epam.com>
1 parent 35713c1 commit e8cb676

3 files changed

Lines changed: 22 additions & 16 deletions

File tree

src/cm/database/database.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ Error Database::AddInstance(const launcher::InstanceInfo& info)
593593
FromAos(info, row);
594594
*mSession << "INSERT INTO launcher_instances (itemID, subjectID, instance, type, preinstalled, manifestDigest, "
595595
"nodeID, prevNodeID, runtimeID, uid, gid, timestamp, state, isUnitSubject, version, ownerID, "
596-
"subjectType, labels, priority) "
597-
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
596+
"subjectType, labels, priority, disableRebalancing) "
597+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
598598
bind(row), now;
599599
} catch (const std::exception& e) {
600600
return AOS_ERROR_WRAP(common::utils::ToAosError(e));
@@ -613,16 +613,17 @@ Error Database::UpdateInstance(const launcher::InstanceInfo& info)
613613
statement
614614
<< "UPDATE launcher_instances SET manifestDigest = ?, nodeID = ?, prevNodeID = ?, runtimeID = ?, uid = ?, "
615615
"gid = ?, timestamp = ?, state = ?, isUnitSubject = ?, ownerID = ?, subjectType = ?, labels = ?, "
616-
"priority = ? "
616+
"priority = ?, disableRebalancing = ? "
617617
"WHERE itemID = ? AND subjectID = ? AND instance = ? "
618618
"AND type = ? AND preinstalled = ? AND version = ?;",
619619
bind(info.mManifestDigest.CStr()), bind(info.mNodeID.CStr()), bind(info.mPrevNodeID.CStr()),
620620
bind(info.mRuntimeID.CStr()), bind(info.mUID), bind(info.mGID), bind(info.mTimestamp.UnixNano()),
621621
bind(info.mState.ToString().CStr()), bind(info.mIsUnitSubject), bind(info.mOwnerID.CStr()),
622622
bind(info.mSubjectType.ToString().CStr()), bind(SerializeLabels(info.mLabels)), bind(info.mPriority),
623-
bind(info.mInstanceIdent.mItemID.CStr()), bind(info.mInstanceIdent.mSubjectID.CStr()),
624-
bind(info.mInstanceIdent.mInstance), bind(info.mInstanceIdent.mType.ToString().CStr()),
625-
bind(info.mInstanceIdent.mPreinstalled), bind(info.mVersion.CStr());
623+
bind(info.mDisableRebalancing), bind(info.mInstanceIdent.mItemID.CStr()),
624+
bind(info.mInstanceIdent.mSubjectID.CStr()), bind(info.mInstanceIdent.mInstance),
625+
bind(info.mInstanceIdent.mType.ToString().CStr()), bind(info.mInstanceIdent.mPreinstalled),
626+
bind(info.mVersion.CStr());
626627

627628
if (statement.execute() != 1) {
628629
return ErrorEnum::eNotFound;
@@ -643,7 +644,7 @@ Error Database::LoadActiveInstances(Array<launcher::InstanceInfo>& instances) co
643644

644645
*mSession << "SELECT itemID, subjectID, instance, type, preinstalled, manifestDigest, nodeID, prevNodeID, "
645646
"runtimeID, uid, gid, timestamp, state, isUnitSubject, version, ownerID, subjectType, labels, "
646-
"priority "
647+
"priority, disableRebalancing "
647648
"FROM launcher_instances;",
648649
into(rows), now;
649650

@@ -1089,6 +1090,7 @@ void Database::CreateTables()
10891090
"subjectType TEXT,"
10901091
"labels TEXT,"
10911092
"priority INTEGER,"
1093+
"disableRebalancing INTEGER,"
10921094
"PRIMARY KEY(itemID,subjectID,instance,type,preinstalled,version)"
10931095
");",
10941096
now;
@@ -1223,6 +1225,7 @@ void Database::FromAos(const launcher::InstanceInfo& src, LauncherInstanceInfoRo
12231225
dst.set<ToInt(LauncherInstanceInfoColumns::eSubjectType)>(src.mSubjectType.ToString().CStr());
12241226
dst.set<ToInt(LauncherInstanceInfoColumns::eLabels)>(SerializeLabels(src.mLabels));
12251227
dst.set<ToInt(LauncherInstanceInfoColumns::ePriority)>(src.mPriority);
1228+
dst.set<ToInt(LauncherInstanceInfoColumns::eDisableRebalancing)>(src.mDisableRebalancing);
12261229
}
12271230

12281231
void Database::ToAos(const LauncherInstanceInfoRow& src, launcher::InstanceInfo& dst)
@@ -1260,7 +1263,8 @@ void Database::ToAos(const LauncherInstanceInfoRow& src, launcher::InstanceInfo&
12601263
AOS_ERROR_CHECK_AND_THROW(AOS_ERROR_WRAP(err), "failed to parse subject type");
12611264

12621265
DeserializeLabels(src.get<ToInt(LauncherInstanceInfoColumns::eLabels)>(), dst.mLabels);
1263-
dst.mPriority = src.get<ToInt(LauncherInstanceInfoColumns::ePriority)>();
1266+
dst.mPriority = src.get<ToInt(LauncherInstanceInfoColumns::ePriority)>();
1267+
dst.mDisableRebalancing = src.get<ToInt(LauncherInstanceInfoColumns::eDisableRebalancing)>();
12641268
}
12651269

12661270
void Database::FromAos(const imagemanager::ItemInfo& src, ImageManagerItemInfoRow& dst)

src/cm/database/database.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,12 @@ class Database : public DatabaseItf, public networkmanager::StorageItf {
383383
eOwnerID,
384384
eSubjectType,
385385
eLabels,
386-
ePriority
386+
ePriority,
387+
eDisableRebalancing
387388
};
388389
using LauncherInstanceInfoRow = Poco::Tuple<std::string, std::string, uint64_t, std::string, bool, std::string,
389390
std::string, std::string, std::string, uint32_t, uint32_t, uint64_t, std::string, bool, std::string,
390-
std::string, std::string, std::string, size_t>;
391+
std::string, std::string, std::string, size_t, bool>;
391392

392393
enum class ImageManagerItemInfoColumns : int {
393394
eItemID = 0,

src/cm/database/tests/database.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ launcher::InstanceInfo CreateLauncherInstanceInfo(const char* itemID, const char
109109
const char* manifestDigest, const char* nodeID, UpdateItemType itemType = UpdateItemTypeEnum::eService,
110110
launcher::InstanceStateEnum state = launcher::InstanceStateEnum::eCached, bool isUnitSubject = false,
111111
const char* version = "1.0.0", const char* ownerID = "owner1", SubjectTypeEnum subjectType = SubjectTypeEnum::eUser,
112-
size_t priority = 0, std::vector<const char*> labels = {})
112+
size_t priority = 0, std::vector<const char*> labels = {}, bool disableRebalancing = false)
113113
{
114114
launcher::InstanceInfo info;
115115

@@ -130,7 +130,8 @@ launcher::InstanceInfo CreateLauncherInstanceInfo(const char* itemID, const char
130130
for (const char* label : labels) {
131131
AOS_ERROR_CHECK_AND_THROW(info.mLabels.EmplaceBack(label), "can't add label");
132132
}
133-
info.mPriority = priority;
133+
info.mPriority = priority;
134+
info.mDisableRebalancing = disableRebalancing;
134135

135136
return info;
136137
}
@@ -661,12 +662,12 @@ TEST_F(CMDatabaseTest, LauncherGetActiveInstances)
661662
ASSERT_TRUE(mDB.LoadActiveInstances(*emptyInstances).IsNone());
662663
EXPECT_EQ(emptyInstances->Size(), 0);
663664

664-
auto instance1
665-
= CreateLauncherInstanceInfo("service1", "subject1", 0, "image1", "node1", UpdateItemTypeEnum::eService,
666-
launcher::InstanceStateEnum::eActive, false, "1.0.0", "owner1", SubjectTypeEnum::eUser, 80, {"label4"});
665+
auto instance1 = CreateLauncherInstanceInfo("service1", "subject1", 0, "image1", "node1",
666+
UpdateItemTypeEnum::eService, launcher::InstanceStateEnum::eActive, false, "1.0.0", "owner1",
667+
SubjectTypeEnum::eUser, 80, {"label4"}, true);
667668
auto instance2 = CreateLauncherInstanceInfo("service2", "subject2", 0, "image2", "node2",
668669
UpdateItemTypeEnum::eService, launcher::InstanceStateEnum::eDisabled, true, "2.0.0", "owner2",
669-
SubjectTypeEnum::eUser, 200, {"label5", "label6", "label7"});
670+
SubjectTypeEnum::eUser, 200, {"label5", "label6", "label7"}, false);
670671

671672
// Add instances
672673
ASSERT_TRUE(mDB.AddInstance(instance1).IsNone());

0 commit comments

Comments
 (0)