Load config from DB
This commit is contained in:
1 parent
4530967b6b
commit
819e8a52a3
4 files changed
+203
-65
No files matched your search
+58
-23
@@ -30,10 +30,6 @@ const InstanceSet = require("./instance-set");
|
||||
const defaultProvisions = require("./default-provisions");
|
||||
const gpnHeuristic = require("./gpn-heuristic");
|
||||
|
||||
// Multiply by two because every iteration is two
|
||||
// phases: read and update
|
||||
const MAX_ITERATIONS = config.get("MAX_COMMIT_ITERATIONS") * 2;
|
||||
|
||||
function initDeviceData() {
|
||||
return {
|
||||
paths: new PathSet(),
|
||||
@@ -64,11 +60,7 @@ function init(deviceId, cwmpVersion, timeout, callback) {
|
||||
declarations: []
|
||||
};
|
||||
|
||||
localCache.getCurrentSnapshot((err, cacheSnapshot) => {
|
||||
if (err) return void callback(err);
|
||||
sessionContext.cacheSnapshot = cacheSnapshot;
|
||||
callback(null, sessionContext);
|
||||
});
|
||||
callback(null, sessionContext);
|
||||
}
|
||||
|
||||
function loadParameters(sessionContext, callback) {
|
||||
@@ -435,7 +427,11 @@ function timeoutOperations(sessionContext, callback) {
|
||||
}
|
||||
|
||||
const DOWNLOAD_TIMEOUT =
|
||||
config.get("DOWNLOAD_TIMEOUT", sessionContext.deviceId) * 1000;
|
||||
localCache.getConfig(
|
||||
sessionContext.cacheSnapshot,
|
||||
"cwmp.downloadTimeout",
|
||||
sessionContext.configContext
|
||||
) * 1000;
|
||||
|
||||
if (sessionContext.timestamp > operation.timestamp + DOWNLOAD_TIMEOUT) {
|
||||
delete sessionContext.operations[commandKey];
|
||||
@@ -465,6 +461,15 @@ function timeoutOperations(sessionContext, callback) {
|
||||
}
|
||||
|
||||
function addProvisions(sessionContext, channel, provisions) {
|
||||
// Multiply by two because every iteration is two
|
||||
// phases: read and update
|
||||
const MAX_ITERATIONS =
|
||||
localCache.getConfig(
|
||||
sessionContext.cacheSnapshot,
|
||||
"cwmp.maxCommitIterations",
|
||||
sessionContext.configContext
|
||||
) * 2;
|
||||
|
||||
delete sessionContext.syncState;
|
||||
delete sessionContext.rpcRequest;
|
||||
sessionContext.declarations = [];
|
||||
@@ -509,6 +514,15 @@ function addProvisions(sessionContext, channel, provisions) {
|
||||
}
|
||||
|
||||
function clearProvisions(sessionContext) {
|
||||
// Multiply by two because every iteration is two
|
||||
// phases: read and update
|
||||
const MAX_ITERATIONS =
|
||||
localCache.getConfig(
|
||||
sessionContext.cacheSnapshot,
|
||||
"cwmp.maxCommitIterations",
|
||||
sessionContext.configContext
|
||||
) * 2;
|
||||
|
||||
if (sessionContext.revisions[sessionContext.revisions.length - 1] > 0) {
|
||||
sessionContext.deviceData.timestamps.collapse(1);
|
||||
sessionContext.deviceData.attributes.collapse(1);
|
||||
@@ -1080,6 +1094,15 @@ function rpcRequest(sessionContext, _declarations, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
// Multiply by two because every iteration is two
|
||||
// phases: read and update
|
||||
const MAX_ITERATIONS =
|
||||
localCache.getConfig(
|
||||
sessionContext.cacheSnapshot,
|
||||
"cwmp.maxCommitIterations",
|
||||
sessionContext.configContext
|
||||
) * 2;
|
||||
|
||||
if (sessionContext.iteration >= MAX_ITERATIONS * (sessionContext.cycle + 1)) {
|
||||
return void callback(null, {
|
||||
code: "too_many_commits",
|
||||
@@ -1504,10 +1527,12 @@ function generateGetRpcRequest(sessionContext) {
|
||||
syncState.refreshAttributes.writable.clear();
|
||||
|
||||
if (syncState.gpn.size) {
|
||||
const GPN_NEXT_LEVEL = config.get(
|
||||
"GPN_NEXT_LEVEL",
|
||||
sessionContext.deviceId
|
||||
const GPN_NEXT_LEVEL = localCache.getConfig(
|
||||
sessionContext.cacheSnapshot,
|
||||
"cwmp.gpnNextLevel",
|
||||
sessionContext.configContext
|
||||
);
|
||||
|
||||
const paths = Array.from(syncState.gpn.keys()).sort(
|
||||
(a, b) => b.length - a.length
|
||||
);
|
||||
@@ -1561,10 +1586,12 @@ function generateGetRpcRequest(sessionContext) {
|
||||
}
|
||||
|
||||
if (syncState.refreshAttributes.value.size) {
|
||||
const GPV_BATCH_SIZE = config.get(
|
||||
"GPV_BATCH_SIZE",
|
||||
sessionContext.deviceId
|
||||
const GPV_BATCH_SIZE = localCache.getConfig(
|
||||
sessionContext.cacheSnapshot,
|
||||
"cwmp.gpvBatchSize",
|
||||
sessionContext.configContext
|
||||
);
|
||||
|
||||
const parameterNames = [];
|
||||
for (const path of syncState.refreshAttributes.value) {
|
||||
syncState.refreshAttributes.value.delete(path);
|
||||
@@ -1620,14 +1647,22 @@ function generateSetRpcRequest(sessionContext) {
|
||||
}
|
||||
|
||||
// Set values
|
||||
const GPV_BATCH_SIZE = config.get("GPV_BATCH_SIZE", sessionContext.deviceId);
|
||||
const DATETIME_MILLISECONDS = config.get(
|
||||
"DATETIME_MILLISECONDS",
|
||||
sessionContext.deviceId
|
||||
const GPV_BATCH_SIZE = localCache.getConfig(
|
||||
sessionContext.cacheSnapshot,
|
||||
"cwmp.gpvBatchSize",
|
||||
sessionContext.configContext
|
||||
);
|
||||
const BOOLEAN_LITERAL = config.get(
|
||||
"BOOLEAN_LITERAL",
|
||||
sessionContext.deviceId
|
||||
|
||||
const DATETIME_MILLISECONDS = localCache.getConfig(
|
||||
sessionContext.cacheSnapshot,
|
||||
"cwmp.datetimeMilliseconds",
|
||||
sessionContext.configContext
|
||||
);
|
||||
|
||||
const BOOLEAN_LITERAL = localCache.getConfig(
|
||||
sessionContext.cacheSnapshot,
|
||||
"cwmp.booleanLiteral",
|
||||
sessionContext.configContext
|
||||
);
|
||||
|
||||
const parameterValues = [];
|
||||
|
||||
Reference in new issue
Block a user