def main(): log.info("Starting ifpnetCDF") options = get_and_check_args() log.debug("Command-line args: " + repr(options)) netCdfRequest = create_request(**vars(options)) log.debug("Sending request: " + str(netCdfRequest)) for i in range(1, RETRY_ATTEMPTS + 1): log.info("Attempt number: %d", i) try: thriftClient = ThriftClient.ThriftClient(options.host, options.port, "/services") serverResponse = thriftClient.sendRequest(netCdfRequest) except: log.exception( "Unhandled exception thrown during ifpnetCDF processing:") sys.exit(1) if serverResponse: break else: log.error("Errors occurred during ifpnetCDF processing: " + serverResponse.message()) if (i == RETRY_ATTEMPTS): log.error("Final attempt failed - exiting") sys.exit(1)
def __init__(self, server, pluginName, modelId, arrayLen): self.pluginName = pluginName self.modelId = modelId self.arrayLen = arrayLen self.host = os.getenv("DEFAULT_HOST", server) self.port = os.getenv("DEFAULT_PORT", "9581") self.client = ThriftClient.ThriftClient(self.host, self.port)
def importModule(name, localizationHost, localizationPort, localizedSite=None, localizationUser=None, loctype='COMMON_STATIC', level=None): ''' @param name: the name of the localization file @param localizationHost: the EDEX server that the localization should be retrieved from @param localizationPort: the port that will be used to connect to the EDEX server @param localizedSite: the site that localization information should be retrieved for (if applicable) @param localizationUser: the user that localization information should be retrieved for (if applicable) @param loctype: the type of localization files to retrieve @param level: the minimum level that localization files should be retrieved for @return: the merged module @summary: this is the pure python (no jep dependencies) version of the python overrider ''' # determine which localization levels files need to be retrieved for levels = PythonOverriderCore._buildLocalizationLevelsList(availableLevels, level) # create a thrift instance thrift = ThriftClient.ThriftClient(localizationHost, localizationPort, '/services') # retrieve a list of the localization files that will need to be merged serverResponse = \ _executeLocalizationFileListRetrieval(name, levels, localizedSite, localizationUser, loctype, thrift) # download the localization files lfiles = _downloadLocalizationFiles(serverResponse, thrift, name) # complete the module merge return _executeModuleMerge(lfiles)
def decode(self): """ Sends the file to EDEX practice decoder """ thriftClient = ThriftClient.ThriftClient(self._host, self._port, '/services') request = SendPracticeProductRequest() request.setProductText(self._getProduct()) request.setDrtString(self._offtimeStr) request.setNotifyGFE(self._notifyGFE) processed = False try: thriftClient.sendRequest(request) log.info('Practice product %s sent to %s:%d.', self._incomingFilename, self._host, self._port) processed = True except: log.warn("Error sending practice product %s to server:", self._incomingFilename, exc_info=True) if self._deleteAfterProcessing and processed: os.unlink(self._incomingFilename) log.info("%s deleted", self._incomingFilename) return
def __init__(self, server, pluginName, timeField): self.pluginName = pluginName self.timeField = timeField self.outdir = os.getcwd() self.host = os.getenv("DEFAULT_HOST", server) self.port = os.getenv("DEFAULT_PORT", "9581") self.client = ThriftClient.ThriftClient(self.host, self.port)
def main(): options = decodeArguments() __initLogger() logEvent("ifpAG Starting") if hasattr(options, "outputFile"): logVerbose("outputFile=" + str(options.outputFile)) if hasattr(options, "inputFile"): logVerbose("inputFile=" + str(options.inputFile)) logVerbose("hostname=" + str(options.hostname)) logVerbose("portNumber=" + str(options.portNumber)) logVerbose("databaseIds=" + str(options.databaseIds)) logVerbose("parmIds=" + str(options.parmIds)) logVerbose("startTime=" + str(options.startTime)) logVerbose("endTime=" + str(options.endTime)) logVerbose("userName="******"coordConversionString=" + str(options.coordConversionString)) # access the database db = ThriftClient.ThriftClient(options.hostname, options.portNumber) statusCode = 0 if hasattr(options, "outputFile") and options.outputFile not in ["", None]: statusCode = outputAG(db, options.databaseIds, options.parmIds, options.startTime,\ options.endTime, options.outputFile, options.coordConversionString, options.userName) elif hasattr(options, "inputFile") and options.inputFile not in ["", None]: statusCode = inputAG(db, options.inputFile, options.userName) logEvent("ifpAG Finished") sys.exit(statusCode)
def main(self): """System entry point. Executes this script from the command line. @type args: list @param args: contains the commands used to launch the script """ # get the command line options (option, arg) = self.__parseOptions() request = ConfigureTextProductsRequest() request.mode = option.mode.lower() request.template = option.template request.site = arg[0] if (len(arg) > 1): request.destinationDir = arg[1] else: request.destinationDir = None response = None try: thriftClient = ThriftClient.ThriftClient(option.host) response = thriftClient.sendRequest(request) except Exception, e: self.__error(e, 2)
def main(): log.info('Break All Locks starting') options = validateArgs() log.info('allLocks= {}, Ids= {}'.format(options.allLocks, options.databaseIDs)) thriftClient = ThriftClient.ThriftClient(options.host, options.port, "/services") activeSites = [] try: activeSites = getActiveSites(thriftClient) except: log.exception("Could not retrieve current active sites:") sys.exit(1) if options.siteID and options.siteID in activeSites: siteID = options.siteID elif not options.siteID and len(activeSites) == 1: siteID = activeSites[0] else: if options.siteID and options.siteID not in activeSites: log.error("Invalid site ID {} specified, only sites {} are valid".format(options.siteID, activeSites)) else: log.error("Must use the -s option to specify one of the following sites {}".format(activeSites)) sys.exit(1) try: officialDbNamesRequest = getOfficialDbNamesRequest(siteID) officialDbNameResponse = thriftClient.sendRequest(officialDbNamesRequest) except: log.exception("Unable to retrieve official databases:") sys.exit(1) if not officialDbNameResponse.isOkay(): log.error("Unable to retrieve official databases: ", officialDbNameResponse.message()) sys.exit(1) officialDBs = officialDbNameResponse.getPayload() try: lockTablesRequest = getLockTablesRequest(siteID) lockTableResponse = thriftClient.sendRequest(lockTablesRequest) except: log.exception("Unable to retrieve lock table:") sys.exit(1) if (not lockTableResponse.isOkay()): log.error("Unable to retrieve lock table: ", lockTableResponse.message()) sys.exit(1) lockTables = lockTableResponse.getPayload() breakRequest = breakAllLocksGRIDRequest(officialDBs, lockTables, options.databaseIDs, options.allLocks) if breakRequest: try: breakResponse = thriftClient.sendRequest(breakRequest) except: log.exception("Unhandled exception thrown during break all locks:") sys.exit(1) if not breakResponse.isOkay(): log.error('Unable to break all locks.') sys.exit(1) log.info('Break All Locks Finished')
def __init__(self, server, pluginName, modelId, cycle=None, forecast=None): self.pluginName = pluginName self.modelId = modelId self.cycle = cycle self.forecast = forecast self.host = os.getenv("DEFAULT_HOST", server) self.port = os.getenv("DEFAULT_PORT", "9581") self.client = ThriftClient.ThriftClient(self.host, self.port)
def __submitRequestMessage(self, msg): # send the request to the server host = os.getenv("DEFAULT_HOST", "localhost") port = os.getenv("DEFAULT_PORT", "9581") tClient = ThriftClient.ThriftClient(host, port) req = TextDBRequest() req.setMessage(msg) return tClient.sendRequest(req)
def download(site: str): # %% SITE site = site.lower() DataAccessLayer.changeEDEXHost('edex-cloud.unidata.ucar.edu') request = DataAccessLayer.newDataRequest() request.setDatatype('radar') request.setLocationNames(site) # %% TIME times = DataAccessLayer.getAvailableTimes(request) times = [parse(str(t)) for t in times] timerange = TimeRange(times[0], times[-1]) # %% REQUEST client = ThriftClient.ThriftClient('edex-cloud.unidata.ucar.edu') request = GetRadarDataRecordRequest() request.setTimeRange(timerange) request.setRadarId(site) code = 'N0Q' request.setProductCode(nexrad[code]['id']) request.setPrimaryElevationAngle(nexrad[code]['elev']) response = client.sendRequest(request) records = response.getData() print(f'found {len(records)} records at {site}') if not response.getData(): raise OSError(f'data not available {timerange}') for rec in records: idra = rec.getHdf5Data() rdat, azdat, depVals, threshVals = RadarCommon.get_hdf5_data(idra) # dim = rdat.getDimension() lat, lon = float(rec.getLatitude()), float(rec.getLongitude()) radials, rangeGates = rdat.getSizes() # Convert raw byte to pixel value array = np.array(rdat.getByteData()) array[array < 0] = array[array < 0] + 256 if azdat: azVals = azdat.getFloatData() az = np.array(RadarCommon.encode_radial(azVals)) # dattyp = RadarCommon.get_data_type(azdat) az = np.append(az, az[-1]) # header = RadarCommon.get_header(rec, format, rangeGates, radials, azdat, 'description') rng = np.linspace(0, rangeGates, rangeGates + 1) * nexrad[code]['res'] lats = np.empty((rng.size, az.size)) lons = np.empty_like(lats) for i, a in enumerate(az): lats, lons, _ = vreckon(lat, lon, rng, a)
def __init__(self, host, port, user, site=None, progName=None): self.__thrift = ThriftClient.ThriftClient(host, port) self.__wsId = WsId(userName=user, progName=progName) # retrieve default site if site is None: sr = self.getSiteID() if len(sr.getPayload()) > 0: site = sr.getPayload()[0] self.__siteId = site
def _getSiteFromServer(host): try: from awips import ThriftClient from dynamicserialize.dstypes.com.raytheon.uf.common.site.requests import GetPrimarySiteRequest client = ThriftClient.ThriftClient(host) return client.sendRequest(GetPrimarySiteRequest()) except: # Servers that don't have GFE installed will not return a site pass
def __processRequest(self): msg = self.__createMessage() host = os.getenv("DEFAULT_HOST", "localhost") port = os.getenv("DEFAULT_PORT", "9581") tClient = ThriftClient.ThriftClient(host, port) req = SubscriptionRequest() req.setMessage(msg) resp = tClient.sendRequest(req) retVal = self.__processResponse(resp) return retVal
def __init__(self, server, pluginName, stationId, refTime, parmList, partNumber): self.pluginName = pluginName self.stationId = stationId self.refTime = refTime self.parmList = parmList self.partNumber = partNumber self.host = os.getenv("DEFAULT_HOST", server) self.port = os.getenv("DEFAULT_PORT", "9581") self.client = ThriftClient.ThriftClient(self.host, self.port)
def main(): args = validateArgs() request = createRequest(args.site) thriftClient = ThriftClient.ThriftClient(args.host, args.port, "/services") try: thriftClient.sendRequest(request) except Exception, ex: print "Caught exception submitting RsyncGridsToCWFRequest: ", str(ex) return 1
def main(): args = validateArgs() purgeRequest = createRequest(args.Model, args.site, args.modelTime, args.all) thriftClient = ThriftClient.ThriftClient(args.host, args.port, "/services") try: serverResponse = thriftClient.sendRequest(purgeRequest) except Exception, ex: print "Caught exception submitting SmartInitRequest: ", str(ex) sys.exit(1)
def main(): connectionParams = getConnectionParams() try: receiveGridsRequest = createRequest() thriftClient = ThriftClient.ThriftClient(connectionParams[0], connectionParams[1], "/services") serverResponse = thriftClient.sendRequest(receiveGridsRequest) except Exception, e: print "Unhandled exception thrown during receive_grids processing: \n", str( e) sys.exit(1)
def send(self, site, host, port): thriftClient = ThriftClient.ThriftClient(host, port) ndfdRequest = ExportGridsRequest() ndfdRequest.setSite(site) ndfdRequest.setMode("GRIB2") status = str(thriftClient.sendRequest(ndfdRequest)) if (status == "SUCCESS"): return 0 else: print "sendGridsToNDFD returned status:", status,"\n See edex-request logs for details." return 1
def main(args): # if no args other than script add --help so usage is displayed if len(args) < 2: args.extend(["--help"]) # if --help in args add dummy --site arg so we can display # full script usage, not just the gfeClient.py usage if "--help" in args: args.extend(["--site", "XXX"]) parser, gfeClientArgs, scriptArgs = validateArgs(args) # add config and user option to scriptArgs scriptArgs.extend(["-c", gfeClientArgs.configFile, "-u", gfeClientArgs.userName]) # add drt option if specified if gfeClientArgs.drt: timeString = time.strftime(TIME_FORMAT, gfeClientArgs.drt) scriptArgs.extend(["-z", timeString]) # add startTime option if specified if gfeClientArgs.startTime: scriptArgs.extend(["-s", gfeClientArgs.startTime]) # shutdown isn't a real script and has no gfeClientArgs to validate if gfeClientArgs.script.lower() != "shutdown": # call the validateArgs() method in the target script scriptGlobals = {} scriptLocals = {} execfile(gfeClientArgs.script, scriptGlobals, scriptLocals) scriptLocals["validateArgs"](args, [parser]) elif "--help" in args: # Don't do shutdown if --help specified # this is only for ifpIMAGE since it's calling shutdown until # PngWriter can be fixed to run more than once in a session sys.exit(0) request = GfeClientRequest(gfeClientArgs.script, gfeClientArgs.site, gfeClientArgs.configFile, gfeClientArgs.userName, scriptArgs) if gfeClientArgs.drt: import calendar timeInMillis = calendar.timegm(gfeClientArgs.drt) * 1000 request.setTime(Date(timeInMillis)) thriftClient = ThriftClient.ThriftClient(gfeClientArgs.host, gfeClientArgs.port, "/services") thriftClient.sendRequest(request)
def __init__(self, serverHost, serverPort, site, removeRemote, remoteATName, atName, inputIsGZIP, drt=0, makeBackups=True, xmlIncoming=None, fromIngestAT=False): # serverHost - host name to send merge request to # serverPort - port EDEX is running on # site - site to perform merge operation as # removeRemote (False, True) to remove remote table file upon completion # remoteATName - name of remote active table file # atName (OPERATIONAL, PRACTICE) - name of active table name # inputIsGZIP (False, True) - remote input file is gzipped # drt mode - None, or number of seconds +/- current time # makeBackups (False, True) - make backups of table changes # xmlIncoming - None, or XML data from MHS, only used in ingestAT mode # fromIngestAT (False, True) - run in ingestAT mode, only affects logging self._thriftClient = ThriftClient.ThriftClient(serverHost, serverPort, '/services') self._site = site self._deleteAfterProcessing = removeRemote self._remoteTableFilename = remoteATName self._activeTableFilename = atName drt = 0 if drt is None else drt self._drtInfo = float(drt) self._makeBackups = makeBackups self._xmlIncoming = xmlIncoming self._fromIngestAT = fromIngestAT log.info("MergeVTEC Starting") log.info("remoteFN= " + self._remoteTableFilename + " localFN= " + self._activeTableFilename + " siteID= " + self._site) # read table to merge otherTable = self._readActiveTable(self._remoteTableFilename, inputIsGZIP) log.info("Remote Table size: %d", len(otherTable)) self._mergeTable(otherTable) # delete remote file, if desired if self._deleteAfterProcessing: os.remove(self._remoteTableFilename) log.info("MergeVTEC Finished")
def __init__(self, server, pluginName, modelId, cycle, forecast, level1, level2, vcoord, param, nnx, nny): self.pluginName = pluginName self.modelId = modelId self.cycle = cycle self.forecast = forecast self.level1 = level1 self.level2 = level2 self.vcoord = vcoord self.param = param self.nx = nnx self.ny = nny self.host = os.getenv("DEFAULT_HOST", server) self.port = os.getenv("DEFAULT_PORT", "9581") self.client = ThriftClient.ThriftClient(self.host, self.port)
def send_request(user_args): slop = user_args.slop dateTimeStr = user_args.datetime if not dateTimeStr: print >> sys.stderr, "DateTime not provided" return dateTime = datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") beginRange = dateTime - timedelta(0, slop) endRange = dateTime + timedelta(0, slop) timerange = TimeRange(beginRange, endRange) radar = user_args.radar if not radar: print >> sys.stderr, "Radar code not provided" return code = user_args.code if not code: print >> sys.stderr, "Product code not provided" return angle = user_args.angle slop = int(user_args.slop) host = user_args.host if not host: host = get_default_host() client = ThriftClient.ThriftClient(host) # Perform a GetRadarHDF5Request req = GetRadarDataRecordRequest() req.setRadarId(radar) req.setPrimaryElevationAngle(float(angle)) req.setTimeRange(timerange) req.setProductCode(int(code)) response = client.sendRequest(req) if response is None: # print "Data not available" return records = response.getData() return records
def main(): options = validateArgs() log.debug("Command-line args: " + repr(options)) try: purgeRequest = createRequest(options.databaseID) log.debug("Sending request: " + str(purgeRequest)) thriftClient = ThriftClient.ThriftClient(options.host, options.port, "/services") serverResponse = thriftClient.sendRequest(purgeRequest) except Exception as e: log.error("Unhandled exception thrown during grid purge: \n" + str(e)) sys.exit(1) if not serverResponse: log.error("Errors occurred during grid purge: " + serverResponse.message()) sys.exit(1)
def main(): __initLogger() logger.info("Starting purgeAllModelData.") options = __parseCommandLine() client = ThriftClient.ThriftClient(options.host, options.port) for model in options.models: logger.info("Deleting all data for model [" + model + "]...") try: req = DeleteAllGridDataRequest(model) client.sendRequest(req) logger.info("Data for model [" + model + "] successfully deleted...") except Exception: logger.exception("Could not purge data for model [" + model + "]:") logger.info("purgeAllModelData is complete.")
def main(): options = process_command_line() log.debug("Command-line options: " + repr(options)) req = build_request(options) log.debug("Request: " + repr(req)) thriftClient = ThriftClient.ThriftClient(host=options.serverHost) try: response = thriftClient.sendRequest(req) except: log.exception("Error posting request.") sys.exit(1) if not response.getTaskSuccess(): log.error("Error executing requestAT: " + response.getErrorMessage()) sys.exit(1)
def main(): args = validate_args() request = ValidateConfigRequest(args.site, "gfe") thriftClient = ThriftClient.ThriftClient(args.host, args.port, "/services") print("Validating configuration for site {}.".format(request.getSiteID())) try: response = thriftClient.sendRequest(request) print("Response received from server:", str(response)) except ThriftRequestException: print("Failed to process {} for site {}".format( type(request).__name__, request.getSiteID()), file=sys.stderr) traceback.print_exc() return -1
def main(): connectionParams = getConnectionParams() try: iscDataRequest = createRequest() thriftClient = ThriftClient.ThriftClient(connectionParams[0], connectionParams[1], "/services") serverResponse = thriftClient.sendRequest(iscDataRequest) except Exception as e: print "Unhandled exception thrown during iscDataRec processing: \n", str( e) sys.exit(1) if (not serverResponse.isOkay()): print "Errors occurred during iscDataRec processing: ", serverResponse.message( ) sys.exit(1)
def __init__(self): self.__host = None self.__port = None self.__siteID = None self.__user = None self.__mode = None self.__name = None self.__filename = None self.__classType = None self.__textCategory = None self.__metaInfo = None self.__osUser = pwd.getpwuid(os.getuid()).pw_name self.__cmdLine() self.__thrift = ThriftClient.ThriftClient(self.__host, self.__port, "/services") # build inventory: if self.__textCategory is not None: self.__db = self.__buildInventory()
def main(): log.info("Starting iscMosaic") options = get_args() log.debug("Command-line args: " + repr(options)) iscRequest = create_request(**vars(options)) log.debug("Sending request: " + str(iscRequest)) try: thriftClient = ThriftClient.ThriftClient(options.host, options.port, "/services") serverResponse = thriftClient.sendRequest(iscRequest) except: log.exception( "Unhandled exception thrown during iscMosaic processing:") sys.exit(1) if not serverResponse: log.error("Errors occurred during iscMosaic processing: " + str(serverResponse.message())) sys.exit(1)