def __init__(self): super(IRService, self).__init__() #Config in IRUtil self._backend = IRUtil.getBackend() self._address = IRUtil.getAddress() self._fgirimgstore = IRUtil.getFgirimgstore() self._fgserverdir = IRUtil.getFgserverdir() #Setup log self._log = fgLog.fgLog(IRUtil.getLogFile(), IRUtil.getLogLevel(), "Img Repo Server", True) if (self._backend == "mongodb"): self.metaStore = ImgMetaStoreMongo(self._address, self._fgserverdir, self._log) self.imgStore = ImgStoreMongo(self._address, self._fgserverdir, self._log) self.userStore = IRUserStoreMongo(self._address, self._fgserverdir, self._log) elif(self._backend == "mysql"): self.metaStore = ImgMetaStoreMysql(self._address, self._fgserverdir, self._log) self.imgStore = ImgStoreMysql(self._address, self._fgserverdir, self._log) self.userStore = IRUserStoreMysql(self._address, self._fgserverdir, self._log) elif(self._backend == "swiftmysql"): self.metaStore = ImgMetaStoreSwiftMysql(self._address, self._fgserverdir, self._log) self.imgStore = ImgStoreSwiftMysql(self._address, IRUtil.getAddressS(), self._fgserverdir, self._log) self.userStore = IRUserStoreSwiftMysql(self._address, self._fgserverdir, self._log) elif(self._backend == "swiftmongo"): self.metaStore = ImgMetaStoreSwiftMongo(self._address, self._fgserverdir, self._log) self.imgStore = ImgStoreSwiftMongo(self._address, IRUtil.getAddressS(), self._fgserverdir, self._log) self.userStore = IRUserStoreSwiftMongo(self._address, self._fgserverdir, self._log) elif(self._backend == "cumulusmysql"): self.metaStore = ImgMetaStoreCumulusMysql(self._address, self._fgserverdir, self._log) self.imgStore = ImgStoreCumulusMysql(self._address, IRUtil.getAddressS(), self._fgserverdir, self._log) self.userStore = IRUserStoreCumulusMysql(self._address, self._fgserverdir, self._log) elif(self._backend == "cumulusmongo"): self.metaStore = ImgMetaStoreCumulusMongo(self._address, self._fgserverdir, self._log) self.imgStore = ImgStoreCumulusMongo(self._address, IRUtil.getAddressS(), self._fgserverdir, self._log) self.userStore = IRUserStoreCumulusMongo(self._address, self._fgserverdir, self._log) else: self.metaStore = ImgMetaStoreFS() self.imgStore = ImgStoreFS() self.userStore = IRUserStoreFS()
def put(self, userId, imgId, fileName, attributeString, size): if (str(size) == 0) : print("Error size is 0 ") else : print("Logging log info for put action- user " + userId + " len(size) " + str(size)) self._log.info("user:"******" command:put args={imgId:" + imgId + ", metadata:" + attributeString + ",\ size:" + str(size) + "}") """ Register the file in the database return imgId or 0 if something fails """ status = False if type(fileName) == cherrypy._cpreqbody.Part : if (size > 0): aMeta = self._createImgMeta(userId, imgId, attributeString, False) aImg = ImgEntry(imgId, aMeta, fileName.filename, size) statusImg = self.imgStore.addRequestItem(aImg, fileName) if(statusImg): #put metadata into the image meta store #with MongoDB I put the metadata with the ImgEntry, so it skips meta add if(re.search("mongo", IRUtil.getBackend()) == None): statusMeta = self.metaStore.addItem(aMeta) else: statusMeta = True if(statusMeta): #Add size and #imgs to user statusAcc = self.userStore.updateAccounting(userId, size, 1) if (statusAcc): status = True else: self._log.error("File size must be higher than 0") else: fileName = self._fgirimgstore + imgId if (os.path.isfile(fileName)): if (size > 0): #parse attribute string and construct image metadata aMeta = self._createImgMeta(userId, imgId, attributeString, False) aImg = ImgEntry(imgId, aMeta, fileName, size) statusImg = self.imgStore.addItem(aImg) if(statusImg): #put metadata into the image meta store #with MongoDB I put the metadata with the ImgEntry, so it skips meta add if(re.search("mongo", IRUtil.getBackend()) == None): statusMeta = self.metaStore.addItem(aMeta) else: statusMeta = True if(statusMeta): #Add size and #imgs to user statusAcc = self.userStore.updateAccounting(userId, size, 1) if (statusAcc): status = True else: self._log.error("File size must be higher than 0") if(status): return aImg._imgId else: return 0
import logging from getopt import gnu_getopt, GetoptError from datetime import datetime from IRTypes import ImgMeta from IRTypes import ImgEntry from IRTypes import IRUser from IRTypes import IRCredential from cherrypy.lib import cptools import IRUtil import re from IRDataAccess import AbstractImgStore from IRDataAccess import AbstractImgMetaStore from IRDataAccess import AbstractIRUserStore if(IRUtil.getBackend() == "mongodb"): from IRDataAccessMongo import ImgStoreMongo from IRDataAccessMongo import ImgMetaStoreMongo from IRDataAccessMongo import IRUserStoreMongo elif(IRUtil.getBackend() == "mysql"): from IRDataAccessMysql import ImgStoreMysql from IRDataAccessMysql import ImgMetaStoreMysql from IRDataAccessMysql import IRUserStoreMysql elif(IRUtil.getBackend() == "swiftmysql"): from IRDataAccessMysql import ImgStoreMysql from IRDataAccessMysql import ImgMetaStoreMysql from IRDataAccessMysql import IRUserStoreMysql from IRDataAccessSwiftMysql import ImgStoreSwiftMysql from IRDataAccessSwiftMysql import ImgMetaStoreSwiftMysql from IRDataAccessSwiftMysql import IRUserStoreSwiftMysql elif(IRUtil.getBackend() == "swiftmongo"):