-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handling global attributes per cluster
- Loading branch information
Showing
9 changed files
with
198 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* | ||
* Copyright (c) 2020 Silicon Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const dbApi = require('../db/db-api.js') | ||
const queryPackage = require('../db/query-package.js') | ||
const queryCluster = require('../db/query-cluster.js') | ||
const dbEnum = require('../../src-shared/db-enum.js') | ||
const fs = require('fs') | ||
const fsp = fs.promises | ||
|
||
/** | ||
* This file implements upgrade rules which are used to upgrade .zap files and xml files | ||
* to be in sync with the spec | ||
*/ | ||
|
||
/** | ||
* Returns an array of objects containing global attributes that should be forced external. | ||
* | ||
* @export | ||
* @param {*} db | ||
* @param {*} attributeId | ||
* @returns An array of objects | ||
*/ | ||
|
||
async function getForcedExternalStorage(db, attributeId) { | ||
let pkgs = await queryPackage.getPackageRefByAttributeId(db, attributeId) | ||
let zcl = await queryPackage.getPackageByPackageId(db, pkgs) | ||
zcl = zcl.path | ||
let obj = await fsp.readFile(zcl) | ||
let data = JSON.parse(obj) | ||
let byName = data?.attributeAccessInterfaceAttributes | ||
let lists = data?.listsUseAttributeAccessInterface | ||
let forcedExternal = { byName, lists } | ||
return forcedExternal | ||
} | ||
|
||
/** | ||
* Returns a flag stating which type of storage option the attribute is categorized to be. | ||
* | ||
* @export | ||
* @param {*} db | ||
* @param {*} clusterName | ||
* @param {*} clusterRef | ||
* @param {*} storagePolicy | ||
* @param {*} forcedExternal | ||
* @param {*} attributeId | ||
* @returns Storage Option | ||
*/ | ||
|
||
async function computeStorageNewConfig( | ||
db, | ||
clusterRef, | ||
storagePolicy, | ||
forcedExternal, | ||
attributeName | ||
) { | ||
let storageOption | ||
let clusterName | ||
clusterName = await queryCluster.selectClusterName(db, clusterRef) | ||
if (storagePolicy == dbEnum.storagePolicy.attributeAccessInterface) { | ||
storageOption = dbEnum.storageOption.external | ||
} else if (storagePolicy == dbEnum.storagePolicy.any) { | ||
storageOption = dbEnum.storageOption.ram | ||
} else { | ||
throw 'check storage policy' | ||
} | ||
if ( | ||
forcedExternal.byName && | ||
forcedExternal.byName[clusterName] && | ||
forcedExternal.byName[clusterName].includes(attributeName) | ||
) { | ||
storageOption = dbEnum.storageOption.external | ||
} | ||
return storageOption | ||
} | ||
|
||
/** | ||
* Returns a flag stating which type of storage option the attribute is categorized to be. | ||
* | ||
* @export | ||
* @param {*} db | ||
* @param {*} clusterName | ||
* @param {*} forcedExternal | ||
* @param {*} attributeId | ||
* @returns Storage Policy | ||
*/ | ||
|
||
async function computeStorageImport( | ||
db, | ||
clusterName, | ||
storagePolicy, | ||
forcedExternal, | ||
attributeName | ||
) { | ||
if ( | ||
forcedExternal.byName && | ||
forcedExternal.byName[clusterName] && | ||
forcedExternal.byName[clusterName].includes(attributeName) | ||
) { | ||
storagePolicy = dbEnum.storagePolicy.attributeAccessInterface | ||
} | ||
return storagePolicy | ||
} | ||
|
||
exports.getForcedExternalStorage = getForcedExternalStorage | ||
exports.computeStorageImport = computeStorageImport | ||
exports.computeStorageNewConfig = computeStorageNewConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters