Example #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()
Example #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()
Example #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")
Example #4
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
Example #5
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")
Example #6
0
def deserialize(context):
    result = DatabaseID(context.readString())
    return result
Example #7
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.")