Beispiel #1
0
 def _executeInternal(self):
     start = time.time()
     cursor = mongo.traffic().find({
         "$and": [{
             "_id": {
                 "$gte": self.fromDate
             }
         }, {
             "_id": {
                 "$lt": self.toDate
             }
         }]
     })
     allFlows = dict((countryName, {})
                     for countryName in MediationConfig.getCountries())
     currentConfig = dict(
         (countryName, MediationConfig.getLobs(countryName))
         for countryName in MediationConfig.getCountries())
     newFlows = {}
     newLobs = dict((countryName, {})
                    for countryName in MediationConfig.getCountries())
     for doc in cursor:
         for countryName, country in doc["data"].items():
             for lobName, lob in country.items():
                 if lobName == "FOX":
                     continue
                 if currentConfig[countryName].get(lobName, None) == None:
                     newLobs[countryName][lobName] = True
                 for flowName, flow in lob.get("inputs", {}).items():
                     if flowName == "updatesCnt" or flowName == "sum":
                         continue
                     if flowName not in currentConfig[countryName].get(
                             lobName, {}).get("inputs", {}):
                         newFlows[createGlobalName(countryName, lobName,
                                                   flowName,
                                                   "inputs")] = True
                 for flowName, flow in lob.get("forwards", {}).items():
                     if flowName == "updatesCnt" or flowName == "sum":
                         continue
                     if flowName not in currentConfig[countryName].get(
                             lobName, {}).get("forwards", {}):
                         newFlows[createGlobalName(countryName, lobName,
                                                   flowName,
                                                   "forwards")] = True
                         # print(flowName)
     insertedLobs = 0
     for countryName, lobs in newLobs.items():
         for lobName in lobs.keys():
             insertedLobs += 1
             MediationConfig.addLob(countryName, lobName)
     for globalFlowName in newFlows.keys():
         flow = globalNameToFlow(globalFlowName)
         MediationConfig.addFlow(flow)
     if insertedLobs > 0 or len(newFlows) > 0:
         logging.info("inserted " + str(insertedLobs) + " lobs and " +
                      str(len(newFlows)) + " flows in " +
                      str(int(time.time() - start)) + " seconds")
Beispiel #2
0
def addLob():
    """put under /lobs"""
    addLobRequest = request.get_json()
    country = addLobRequest["country"]
    lobName = addLobRequest["lobName"]
    if MediationConfig.getLobWithCountry(country, lobName) is not None:
        raise StatusException("Lob already exists", 400)
    MediationConfig.addLob(country, lobName)
    return getCountry(country)