2 Created on Mar 17, 2015 6 @link: http://hierarchical-cluster-engine.com/ 7 @copyright: Copyright © 2014-2016 IOIX Ukraine 8 @license: http://hierarchical-cluster-engine.com/license/ 25 JSON_EXTENSION =
".json" 41 jsonStr = json.dumps(element, indent=4)
42 if jsonStr
is not None and jsonStr !=
"":
43 if os.path.isdir(storageDir):
45 if localDir[-1] !=
"/":
48 if not os.path.isdir(localDir):
53 localFileName = localDir
55 localFileName += str(siteId)
58 fd = open(localFileName,
"w")
62 logger.debug(
">>> LFSDataStorage.saveElement can't open file to write, file=" + localFileName)
64 logger.debug(
">>> LFSDataStorage.saveElement can't find root dir, dir=" + storageDir)
75 def loadElement(self, storageDir, host, siteId, externalElement=None, readFromFS=False):
80 if not os.path.isdir(storageDir):
81 os.makedirs(storageDir)
83 if os.path.isdir(storageDir):
85 if localDir[-1] !=
"/":
88 if os.path.isdir(localDir):
89 localFileName = localDir
91 localFileName += str(siteId)
94 fd = open(localFileName,
"r") 96 if fileBuf
is not None and fileBuf !=
"":
97 nodeElem = json.loads(fileBuf)
100 logger.debug(
">>> LFSDataStorage.loadElement can't open file to read, file=" + str(localFileName))
101 except Exception
as exp:
102 logger.debug(
">>> LFSDataStorage.loadElement some exception, = " + str(exp))
104 logger.debug(
">>> LFSDataStorage.loadElement can't find storage dir, dir=" + str(localDir))
106 logger.debug(
">>> LFSDataStorage.loadElement can't find root dir, dir=" + str(storageDir))
108 if nodeElem
is not None:
112 if externalElement
is not None:
115 for headerKey
in externalElement:
116 if headerKey
not in nodeElem:
117 nodeElem[headerKey] = {}
118 for valueKey
in externalElement[headerKey]:
119 if valueKey
not in nodeElem[headerKey]:
120 nodeElem[headerKey][valueKey] = 0
134 if isinstance(fileStorageElements, dict):
135 for headerKey
in fileStorageElements:
138 for valueKey
in fileStorageElements[headerKey]:
139 if (minValue
is None or minValue > fileStorageElements[headerKey][valueKey])
and \
142 siteStorageElements
is not None and 143 (headerKey
in siteStorageElements
and isinstance(siteStorageElements[headerKey], list)
and \
144 valueKey
in siteStorageElements[headerKey])):
145 minValue = fileStorageElements[headerKey][valueKey]
146 t = tuple([headerKey, valueKey])
147 elif (minValue
is None or minValue > fileStorageElements[headerKey][valueKey])
and fileCacheOnly
is True:
148 t = tuple([headerKey, valueKey])
162 ret = json.loads(jsonBuf)
163 except Exception
as exp:
164 logger.debug(
">>> LFSDataStorage.extractSiteStorageElement can't load data from incoming jsonBuf " +
165 "(may be not json format...) exception=" + str(exp))
def fetchLowFreqHeaders(self, fileStorageElements, siteStorageElements=None, fileCacheOnly=False)
def extractSiteStorageElement(self, jsonBuf)
def saveElement(self, storageDir, domain, siteId, element)
def loadElement(self, storageDir, host, siteId, externalElement=None, readFromFS=False)