Ejemplo n.º 1
0
    def __init__(self, parmIdentifier=None, dbId=None, level=None):
        self.parmName = None
        self.parmLevel = None
        self.dbId = None
        self.compositeName = None
        self.shortParmId = None
        self.parmId = None

        if (parmIdentifier is not None) and (dbId is not None):
            self.parmName = parmIdentifier

            if type(dbId) is DatabaseID:
                self.dbId = dbId
            elif type(dbId) is str:
                self.dbId = DatabaseID(dbId)
            else:
                raise TypeError("Invalid database ID specified.")

            if level is None:
                self.parmLevel = self.defaultLevel()
            else:
                self.parmLevel = level

            self.__encodeIdentifier()

        elif parmIdentifier is not None:
            self.__decodeIdentifier(parmIdentifier)
            self.__encodeIdentifier()
Ejemplo n.º 2
0
 def __decodeIdentifier(self, parmIdentifier):
     parts = parmIdentifier.split(":")
     nameLevel = parts[0].split("_")
     self.dbId = DatabaseID(parts[1])
     if (len(nameLevel) == 2):
         self.parmName = nameLevel[0]
         self.parmLevel = nameLevel[1]
     else:
         self.parmName = nameLevel[0]
         self.parmLevel = self.defaultLevel()
Ejemplo n.º 3
0
 def __call__(self, parser, namespace, values, option_string=None):
     did = DatabaseID(values)
     if did.isValid():
         if (hasattr(namespace, self.dest)) and \
            (getattr(namespace, self.dest) is not None):
             currentValues = getattr(namespace, self.dest)
             currentValues.append(did)
             setattr(namespace, self.dest, currentValues)
         else:
             setattr(namespace, self.dest, [did])
     else:
         parser.error("DatabaseID [" + values + "] not valid identifier")
Ejemplo n.º 4
0
 def __call__(self, parser, namespace, values, option_string=None):
     did = DatabaseID(values)
     if did.isValid():
         if (hasattr(namespace, self.dest)) and \
            (getattr(namespace, self.dest) is not None):
             currentValues = getattr(namespace, self.dest)
             currentValues.append(did)
             setattr(namespace, self.dest, currentValues)
         else:
             setattr(namespace, self.dest, [did])
     else:
         parser.error("DatabaseID [" + values + "] not valid identifier")
Ejemplo n.º 5
0
    def __init__(self, parmIdentifier=None, dbId=None, level=None):
        self.parmName = None
        self.parmLevel = None
        self.dbId = None
        self.compositeName = None
        self.shortParmId = None
        self.parmId = None

        if (parmIdentifier is not None) and (dbId is not None):
            self.parmName = parmIdentifier

            if type(dbId) is DatabaseID:
                self.dbId = dbId
            elif type(dbId) is str:
                self.dbId = DatabaseID(dbId)
            else:
                raise TypeError("Invalid database ID specified.")

            if level is None:
                self.parmLevel = self.defaultLevel()
            else:
                self.parmLevel = level

            self.__encodeIdentifier()

        elif parmIdentifier is not None:
            self.__decodeIdentifier(parmIdentifier)
            self.__encodeIdentifier()
Ejemplo n.º 6
0
 def __decodeIdentifier(self, parmIdentifier):
     parts = parmIdentifier.split(":")
     nameLevel = parts[0].split("_")
     self.dbId = DatabaseID(parts[1])
     if (len(nameLevel) == 2):
         self.parmName = nameLevel[0]
         self.parmLevel = nameLevel[1]
     else:
         self.parmName = nameLevel[0]
         self.parmLevel = self.defaultLevel()
Ejemplo n.º 7
0
def validateArgs():
    parser = UsageArgumentParser.UsageArgumentParser(prog='ifpBreakAllLocks', conflict_handler="resolve")
    parser.add_argument("-h", action="store", dest="host",
                      help="The host the ifpServer is running on", 
                      metavar="host")
    parser.add_argument("-p", action="store", type=int, dest="port", 
                      help="The port number the server is using",
                      metavar="port")
    parser.add_argument("-s", action="store", dest="siteID", 
                      help="Site ID",
                      metavar="siteID")
    parser.add_argument("-a", action="store_true", dest="allLocks",
                      help="Break locks on all databases")
    parser.add_argument("-d", action="append", dest="databaseIDs", default=[],
                        help="Break locks on specified database identifier",
                        metavar="databaseID")
    options = parser.parse_args()
        
    if options.host == None:
        if "CDSHOST" in os.environ:
            options.host = os.environ["CDSHOST"]
        else:
            parser.error("Error: host is not specified.")
    if options.port == None:
        if "CDSPORT" in os.environ:
            options.port = int(os.environ["CDSPORT"])
        else:
            parser.error("Error: port is not specified.")
    if options.allLocks == False and not options.databaseIDs:
        parser.error("Error: either -a or -d are required.")
    invalidDbIds = []
    if not options.allLocks:
        for db in options.databaseIDs:
            if not DatabaseID(dbIdentifier=db).isValid():
                invalidDbIds.append(db)
        if invalidDbIds:
            parser.error("Invalid DatabaseIDs specified: {}".format(invalidDbIds))

    return options
Ejemplo n.º 8
0
 def __call__(self, parser, namespace, values, option_string=None):
     (isValid, dateTime) = DatabaseID.decodeDtg(values)
     if isValid:
         setattr(namespace, self.dest, dateTime)
     else:
         parser.error(str(self.dest) + " not in yyyymmdd_hhmm format")
Ejemplo n.º 9
0
 def __call__(self, parser, namespace, values, option_string=None):
     did = DatabaseID(values)
     if did.isValid():
         setattr(namespace, self.dest, did)
     else:
         parser.error("DatabaseID [" + values + "] not a valid identifier")
Ejemplo n.º 10
0
def deserialize(context):
    result = DatabaseID(context.readString())
    return result
Ejemplo n.º 11
0
 def __call__(self, parser, namespace, values, option_string=None):
     (isValid, dateTime) = DatabaseID.decodeDtg(values)
     if isValid:
         setattr(namespace, self.dest, dateTime)
     else:
         parser.error("Argument for option " + option_string + " not in yyyymmdd_hhmm format")
Ejemplo n.º 12
0
class ParmID(object):
    def __init__(self, parmIdentifier=None, dbId=None, level=None):
        self.parmName = None
        self.parmLevel = None
        self.dbId = None
        self.compositeName = None
        self.shortParmId = None
        self.parmId = None

        if (parmIdentifier is not None) and (dbId is not None):
            self.parmName = parmIdentifier

            if type(dbId) is DatabaseID:
                self.dbId = dbId
            elif type(dbId) is str:
                self.dbId = DatabaseID(dbId)
            else:
                raise TypeError("Invalid database ID specified.")

            if level is None:
                self.parmLevel = self.defaultLevel()
            else:
                self.parmLevel = level

            self.__encodeIdentifier()

        elif parmIdentifier is not None:
            self.__decodeIdentifier(parmIdentifier)
            self.__encodeIdentifier()

    def getParmName(self):
        return self.parmName

    def getParmLevel(self):
        return self.parmLevel

    def getDbId(self):
        return self.dbId

    def getCompositeName(self):
        return self.compositeName

    def getShortParmId(self):
        return self.shortParmId

    def getParmId(self):
        return self.parmId

    def __decodeIdentifier(self, parmIdentifier):
        parts = parmIdentifier.split(":")
        nameLevel = parts[0].split("_")
        self.dbId = DatabaseID(parts[1])
        if (len(nameLevel) == 2):
            self.parmName = nameLevel[0]
            self.parmLevel = nameLevel[1]
        else:
            self.parmName = nameLevel[0]
            self.parmLevel = self.defaultLevel()

    def __encodeIdentifier(self):
        self.compositeName = self.parmName + "_" + self.parmLevel
        self.shortParmId = self.compositeName + ":" + self.dbId.getShortModelId(
        )
        self.parmId = self.compositeName + ":" + self.dbId.getModelId()

    def isValid(self):
        if len(self.parmName) is None or len(
                self.parmLevel) is None or self.dbId is None:
            return False
        if len(self.parmName) < 1 or len(
                self.parmLevel) < 1 or not self.dbId.isValid():
            return False

        if not self.parmName.isalnum():
            return False
        if not self.parmLevel.isalnum():
            return False

        return True

    @staticmethod
    def defaultLevel():
        return "SFC"

    @staticmethod
    def parmNameAndLevel(composite):
        pos = composite.find('_')
        if pos != -1:
            return (composite[:pos], composite[pos + 1:])
        else:
            return (composite, "SFC")

    def __str__(self):
        return self.__repr__()

    def __repr__(self):
        return self.parmName + '_' + self.parmLevel + ":" + str(self.dbId)

    def __hash__(self):
        return hash(self.parmId)

    def __cmp__(self, other):
        if isinstance(other, ParmID):
            nameComp = cmp(self.parmName, other.parmName)
            if nameComp != 0:
                return nameComp

            levelComp = cmp(self.parmLevel, other.parmLevel)
            if levelComp != 0:
                return levelComp

            return cmp(self.dbId, other.dbId)
        else:
            return NotImplemented

    def __eq__(self, other):
        if not isinstance(other, ParmID):
            return False
        if self.dbId != other.dbId:
            return False
        if self.parmLevel != other.parmLevel:
            return False
        if self.parmName != other.parmName:
            return False
        return True

    def __ne__(self, other):
        return (not self.__eq__(other))
Ejemplo n.º 13
0
class ParmID(object):

    def __init__(self, parmIdentifier=None, dbId=None, level=None):
        self.parmName = None
        self.parmLevel = None
        self.dbId = None
        self.compositeName = None
        self.shortParmId = None
        self.parmId = None

        if (parmIdentifier is not None) and (dbId is not None):
            self.parmName = parmIdentifier

            if type(dbId) is DatabaseID:
                self.dbId = dbId
            elif type(dbId) is str:
                self.dbId = DatabaseID(dbId)
            else:
                raise TypeError("Invalid database ID specified.")

            if level is None:
                self.parmLevel = self.defaultLevel()
            else:
                self.parmLevel = level

            self.__encodeIdentifier()

        elif parmIdentifier is not None:
            self.__decodeIdentifier(parmIdentifier)
            self.__encodeIdentifier()

    def getParmName(self):
        return self.parmName

    def getParmLevel(self):
        return self.parmLevel

    def getDbId(self):
        return self.dbId

    def getCompositeName(self):
        return self.compositeName

    def getShortParmId(self):
        return self.shortParmId

    def getParmId(self):
        return self.parmId

    def __decodeIdentifier(self, parmIdentifier):
        parts = parmIdentifier.split(":")
        nameLevel = parts[0].split("_")
        self.dbId = DatabaseID(parts[1])
        if (len(nameLevel) == 2):
            self.parmName = nameLevel[0]
            self.parmLevel = nameLevel[1]
        else:
            self.parmName = nameLevel[0]
            self.parmLevel = self.defaultLevel()

    def __encodeIdentifier(self):
        self.compositeName = self.parmName + "_" + self.parmLevel
        self.shortParmId = self.compositeName + ":" + self.dbId.getShortModelId()
        self.parmId = self.compositeName + ":" + self.dbId.getModelId()

    def isValid(self):
        if len(self.parmName) is None or len(self.parmLevel) is None or self.dbId is None:
            return False
        if len(self.parmName) < 1 or len(self.parmLevel) < 1 or not self.dbId.isValid():
            return False

        if not self.parmName.isalnum():
            return False
        if not self.parmLevel.isalnum():
            return False

        return True

    @staticmethod
    def defaultLevel():
        return "SFC"

    @staticmethod
    def parmNameAndLevel(composite):
        pos = composite.find('_')
        if pos != -1:
            return (composite[:pos], composite[pos+1:])
        else:
            return (composite, "SFC")

    def __str__(self):
        return self.__repr__()

    def __repr__(self):
        return self.parmName + '_' + self.parmLevel + ":" + str(self.dbId)

    def __hash__(self):
        return hash(self.parmId)

    def __cmp__(self, other):
        if isinstance(other, ParmID):
            nameComp = cmp(self.parmName, other.parmName)
            if nameComp != 0:
                return nameComp

            levelComp = cmp(self.parmLevel, other.parmLevel)
            if levelComp != 0:
                return levelComp

            return cmp(self.dbId, other.dbId)
        else:
            return NotImplemented

    def __eq__(self, other):
        if not isinstance(other, ParmID):
            return False
        if self.dbId != other.dbId:
            return False
        if self.parmLevel != other.parmLevel:
            return False
        if self.parmName != other.parmName:
            return False
        return True

    def __ne__(self, other):
        return (not self.__eq__(other))
Ejemplo n.º 14
0
 def __call__(self, parser, namespace, values, option_string=None):
     did = DatabaseID(values)
     if did.isValid():
         setattr(namespace, self.dest, did)
     else:
         parser.error("DatabaseID [" + values + "] not a valid identifier")
Ejemplo n.º 15
0
def main():
    __initLogger()
    logger.info("Publish Fcst Data to Official")
    
    args = validateArgs()
    logger.debug("Command-line arguments: " + str(args))
    
    # build IFPClient object
    db = IFPClient.IFPClient(args.host, args.port, args.user, args.site, "publishGFE")
    
    # get site id
    siteID = args.site
    if siteID is None or len(siteID) == 0:
        sr = db.getSiteID()
        if not sr.isOkay():
            logger.error("Unable to determine site id: " + sr.message())
            sys.exit(1)
        siteID = sr.getPayload()[0]
    
    # calculate list of parms
    dbid = DatabaseID(siteID + "_GRID__Fcst_00000000_0000")
    sr = db.getParmList(dbid)
    if not sr.isOkay():
        logger.error("Unable to determine parms: " + sr.message())
        sys.exit(1)
    parmsInDb = sr.getPayload()
    commitParmList = []
    if len(args.parmNamesAndLevels) == 0:
        commitParmList = parmsInDb
    else:
        for parm in args.parmNamesAndLevels:
            tx = ParmID.parmNameAndLevel(parm)
            found = False
            for dbParm in parmsInDb:
                if dbParm.getParmName() == tx[0] and dbParm.getParmLevel() == tx[1]:
                    commitParmList.append(dbParm)
                    found = True
            if not found:
                logger.warning("Unable to find parm [" + str(parm) + "] in database [" + str(dbid) + "]")
    
    # calculate time ranges
    tr = args.tr
    if len(args.definedTR) > 0:
        sr = db.getSelectTR(args.definedTR)
        if not sr.isOkay():
            logger.error("Unable to find select tr definition: " + sr.message())
            sys.exit(1)
        tr = sr.getPayload()        
    
    # CommitGridRequest(parmid, commitTime)
    requests = []
    for parm in commitParmList:
        inv = []
        sr = db.getGridInventory(parm)
        if not sr.isOkay():
            logger.error("Unable to get grid inventory: " + sr.message())
            sys.exit(1)
        inv = sr.getPayload()
        expandTR = expandToParmInv(inv, tr)
        req = CommitGridRequest()
        req.setParmId(parm)
        req.setTimeRange(expandTR)
        requests.append(req)
        logger.debug(parm.getParmName() + ' ' + str(tr))
    
    # commit grid
    sr = db.commitGrid(requests)
    if not sr.isOkay():
        logger.error("Unable to publish grids: " + sr.message())
        sys.exit(1)
    else:
        logger.info("Publish completed.")