예제 #1
0
def SetupServer(app=None, socketio=None, host='localhost', port=5000, debug=True):
    # Initial Setup
    global FLASK_CORE_APP, SOCKET_IO_CORE, DB_CONNECTION, MESSAGING_GATEWAY
    if app is None: app = FLASK_CORE_APP
    if socketio is None: socketio = SOCKET_IO_CORE
    aPort = int(os.getenv('PORT', port))
    if (aPort != port or host != 'localhost') and debug:
        host = '0.0.0.0'
        debug = False
        logWarning("Going to host 0")
    app.debug = bool(debug)

    #Allow some env specification of helpful test services
    services = [
        CSVLoggingService("logfile.csv"),
    ]
    if os.getenv('TESTSERVICE', ''):
        logWarning('SKO_Architecture.MessagingGateway.TestService will be run')
        from SKO_Architecture.MessagingGateway import TestService
        services.append(TestService())

    MESSAGING_GATEWAY = HTTPMessagingGateway(
        None,
        SOCKET_IO_CORE,
        flask.ext.socketio,
        services
    )

    return socketio
예제 #2
0
 def eval(self, num_string, parseAll=True):
     #logWarning('here it is ', num_string)
     if isinstance(num_string, unicode):
         num_string = num_string.encode('ascii', 'ignore')
     if len(num_string) == 0:
         return ''
     poses = [m.start() for m in re.finditer('\(', num_string)]
     #logWarning(poses)
     newstring = ''
     n = 0
     while n < len(num_string):
         if n not in poses:
             newstring = newstring + num_string[n]
         else:
             if n == 0:
                 newstring = newstring + num_string[n]
             elif (num_string[n - 1].isdigit()) or (num_string[n - 1]
                                                    == ')'):
                 newstring = newstring + "*("
             else:
                 newstring = newstring + num_string[n]
         n = n + 1
     num_string = newstring
     #logWarning('string after = ' , num_string)
     self.exprStack = []
     try:
         results = self.bnf.parseString(num_string, parseAll)
         val = self.evaluateStack(self.exprStack[:])
     except ParseException, err:
         logWarning(err.line, '\n', num_string, '\n',
                    " " * (err.column - 1) + "^", '\n', err)
         val = num_string
예제 #3
0
    def _createValue(self, key, value, name="", description="", tags=None, storageType=DATA_TYPE_DB, dataType=""):
        # Force Valid Default values
        if name is None:
            name = ""
        if description is None:
            description = ""
        if tags is None:
            tags = []
        if dataType is None:
            dataType = ""
        if storageType is None:
            storageType = DATA_TYPE_DB

        # Must be a valid storage type
        if (
            key is not None
            and isinstance(key, basestring)
            and isinstance(storageType, int)
            and storageType in VALID_STORAGE_TYPES
        ):
            storageData = {"key": key, "value": value, "name": name, "data_type": dataType, "description": description}
            storageClass = self.STORAGE_ADAPTORS[storageType]
            data = storageClass(**storageData)
            if name != "":
                self.name_map[name] = key
            self.adaptor_map[key] = storageType
            for tag in tags:
                self.addTagKey(tag, key, delaySave=True)
            data.save()
            self.save()
            self.reload()
            return True
        else:
            logWarning("Couldn't create :" + str(key))
            return False
예제 #4
0
 def _updateValue(self, key, value=None, name=None, description=None, tags=None, storageType=None, dataType=None):
     key = self.resolveRef(key, name)
     currentName = self.getName(key)
     data = self._getData(key)
     if key is not None and data is not None:
         if name is not None and currentName != name:
             isChanged, data = self._changeName(name, data)
             if not isChanged:
                 # Failed on change name attempt
                 logWarning("Failed to update, rename failed: ", name)
                 return False
         if value is not None:
             data.value = value
         if dataType is not None:
             data.data_type = dataType
         if description is not None:
             data.description = description
         if storageType is not None:
             # @TODO: Fix this so it works appropriately
             # (e.g., changes the stored object type)
             # For now, no-op
             # self.adaptor_map[key] = storageType
             pass
         if tags is not None:
             self.changeTags(tags, key, delaySave=True)
         data.save()
         self.save()
         self.reload()
         return True
     else:
         logWarning("Error in updateValue. Couldn't get rename for: " + str(key))
         return False
 def eval(self, num_string, parseAll=True):
     #logWarning('here it is ', num_string)
     if isinstance(num_string, unicode):
         num_string = num_string.encode('ascii', 'ignore')
     if len(num_string) == 0:
         return ''
     poses = [m.start() for m in re.finditer('\(',num_string )]
     #logWarning(poses)
     newstring = ''
     n=0
     while n < len(num_string):
         if n not in poses:
             newstring = newstring+num_string[n]
         else:
             if n == 0:
                 newstring = newstring+num_string[n]
             elif (num_string[n-1].isdigit()) or (num_string[n-1] == ')'):
                 newstring = newstring + "*("
             else:
                 newstring = newstring + num_string[n]
         n = n+1
     num_string = newstring
     #logWarning('string after = ' , num_string)
     self.exprStack=[]
     try:
         results=self.bnf.parseString(num_string, parseAll)
         val=self.evaluateStack( self.exprStack[:] )
     except ParseException, err:
         logWarning(err.line, '\n', num_string, '\n', " "*(err.column-1) + "^", '\n', err)
         val = num_string
예제 #6
0
def StartServer(app=None, socketio=None, host='localhost', port=5000, debug=True):
    socketio = SetupServer(app, socketio, host, port, debug)
    Thread(target=background_thread).start()
    logWarning("Starting Socket App")
    try:
        socketio.run(app, host=host, port=port)
    except Exception, err:
        DB_CONNECTION.close()
예제 #7
0
    def sendMessage(self, msg):
        print("%s sending %s" % (self.__class__.__name__, msg))
        if self._gateway is not None:
            print("Actually sent it.")
            self._gateway.dispatchMessage(msg, self.getId())

        self.distributeMessage(msg,
                               msg.getContextValue(ORIGINATING_SERVICE_ID_KEY))
        logWarning("Message DISTRIBUTED: %s" % (msg, ))
예제 #8
0
 def template_imports(path):
     if path[-5:] in ('.html',):
         try:
             path = path.split('//')[-1]
             logWarning(path)
             return render_template(path)
         except Exception:
             abort(404)
     else:
         return abort(404)
예제 #9
0
 def handleConvertMsg(self, msg):
     text = msg.getActor()
     if text is None:
         text = ''
     try:
         text = self.translateToSpeech(text)
     except Exception, err:
         text = None
         logWarning("COULD NOT TRANSLATE: ", msg.getActor())
         raise err
예제 #10
0
 def _getData(self, key):
     if key is None:
         return None
     storage = self.getStorageAdaptor(key)
     if storage is not None:
         data = storage.objects(key=key).first()
         if data is None: logWarning("No data for: ", key)
         return data
     logWarning("No data for: ", key)
     return None
 def _getData(self, key):
     if key is None:
         return None
     storage = self.getStorageAdaptor(key)
     if storage is not None:
         data = storage.objects(key=key).first()
         if data is None: logWarning("No data for: ", key)
         return data
     logWarning("No data for: ", key)
     return None       
 def createCalendarData(self, ownerId=None, ownerType=None, permissions=None, data=None):
     if ownerId is None:
         logWarning("NO OWNER ID WAS GIVEN WHEN ATTEMPTING TO LOOK UP CALENDAR")
         return None
     if data is None:
         data = Calendar().to_ical()
     result = self.DB_BRIDGE.getCalendarFromOwnerId(ownerId)
     if result is None:
         result = DBCalendarData()
     result.setCalendarData(ownerId, ownerType, permissions, data)
     result.saveToDB()
     return result
예제 #13
0
 def stringToMessage(self, msg):
     if (CATCH_BAD_MESSAGES):
         try:
             msg = nativizeObject(msg)
         except:
             logWarning(
                 "ERROR: Could not process message data received.  Received:"
                 + str(msg))
             msg = None
     else:
         msg = nativizeObject(msg)
     return msg
예제 #14
0
 def logfile_imports(path):
     if path[-4:] in ('.log', '.csv'):
         try:
             path = path.split('//')
             path.insert(0, 'Services')
             path = '//'.join(path)
             logWarning(path)
             return FLASK_CORE_APP.send_static_file(path)
         except Exception:
             abort(404)
     else:
         return abort(404)
예제 #15
0
 def processStorageInform(self,
                          bucket,
                          verb,
                          key=None,
                          value=None,
                          tags=None,
                          aType=None,
                          allowCreate=None,
                          name=None,
                          description=None,
                          dataType=None):
     if verb == self.VALUE_VERB:
         logWarning("IS SETTING", value)
         if isinstance(value, SuperGlu_Serializable):
             logWarning("IS SERIALIZABLE")
             dataType = SERIALIZABLE_DATA_TYPE
             if key is None:
                 key = value.getId()
             elif key != value.getId():
                 logWarning('BAD KEY for Storage (%s != %s)' %
                            (key, value.getId()))
                 return False
             if isinstance(value, NamedSerializable):
                 if name is None:
                     name = value.getName()
                 elif name != value.getName():
                     logWarning('BAD NAME for Storage(%s != %s)' %
                                (name, value.getName()))
                     return False
             value = serializeObject(value, JSON_FORMAT)
         return bucket.setValue(key, value, name, description, tags, aType,
                                dataType, True, allowCreate)
     elif verb == self.VOID_VERB:
         return bucket.delValue(key, name)
 def processStorageInform(
     self,
     bucket,
     verb,
     key=None,
     value=None,
     tags=None,
     aType=None,
     allowCreate=None,
     name=None,
     description=None,
     dataType=None,
 ):
     if verb == self.VALUE_VERB:
         logWarning("IS SETTING", value)
         if isinstance(value, Serializable):
             logWarning("IS SERIALIZABLE")
             dataType = SERIALIZABLE_DATA_TYPE
             if key is None:
                 key = value.getId()
             elif key != value.getId():
                 logWarning("BAD KEY for Storage (%s != %s)" % (key, value.getId()))
                 return False
             if isinstance(value, NamedSerializable):
                 if name is None:
                     name = value.getName()
                 elif name != value.getName():
                     logWarning("BAD NAME for Storage(%s != %s)" % (name, value.getName()))
                     return False
             value = serializeObject(value, JSON_FORMAT)
         return bucket.setValue(key, value, name, description, tags, aType, dataType, True, allowCreate)
     elif verb == self.VOID_VERB:
         return bucket.delValue(key, name)
예제 #17
0
 def onReceiveAJAXMessage(self, msg, sid):
     """ Take message from client and send parent gateway and any child serices """
     if self.DATA_KEY in msg:
         sessionId = msg.get(SESSION_KEY, None)
         #if sessionId is not None and len(self._socketioModule.rooms()) == 0:
         self._socketio.server.enter_room(sid, sessionId,
                                          self.MESSAGES_NAMESPACE)
         # Wrap in a try/except
         msg = self.stringToMessage(msg[self.DATA_KEY])
         msg.setContextValue("sid", sid)
         if isinstance(msg, Message):
             if self._gateway is not None:
                 self._gateway.dispatchMessage(msg, self.getId())
             self.distributeMessage(msg)
     else:
         logWarning("GATEWAY DID NOT UNDERSTAND: ", msg)
예제 #18
0
 def createCalendarData(self,
                        ownerId=None,
                        ownerType=None,
                        permissions=None,
                        data=None):
     if ownerId is None:
         logWarning(
             "NO OWNER ID WAS GIVEN WHEN ATTEMPTING TO LOOK UP CALENDAR")
         return None
     if data is None: data = Calendar().to_ical()
     result = self.DB_BRIDGE.getCalendarFromOwnerId(ownerId)
     if result is None:
         result = DBCalendarData()
     result.setCalendarData(ownerId, ownerType, permissions, data)
     result.saveToDB()
     return result
예제 #19
0
 def addTagKey(self, tag, key=None, name=None, delaySave=False):
     if not delaySave:
         self.reload()
     key = self.resolveRef(key, name)
     try:
         tag = str(tag)
     except Exception:
         logWarning("ERROR: Invalid tag couldn't convert from unicode")
         tag = None
     if key is not None and isinstance(tag, str) and not self.hasTagKey(tag, key):
         if self.hasTag(tag):
             self.tag_maps[tag].append(key)
         else:
             self.tag_maps[tag] = [key]
         if not delaySave:
             self.save()
             self.reload()
예제 #20
0
 def dispatchMessage(self, msg, senderId=None):
     """ Send a message from a child node to parent and sibling nodes """
     self.addContextDataToMsg(msg)
     msg.setContextValue(ORIGINATING_SERVICE_ID_KEY, senderId)
     logWarning("Message DISPATCH")
     logWarning(msg)
     self.sendMessage(msg)
     logWarning("Message DISPATCH SENT: %s" % (msg, ))
     self._distributeMessage(self._nodes, msg, senderId)
     logWarning("Message DISTRIBUTED: %s" % (msg, ))
예제 #21
0
 def addTagKey(self, tag, key=None, name=None, delaySave=False):
     if not delaySave:
         self.reload()
     key = self.resolveRef(key, name)
     try:
         tag = str(tag)
     except Exception:
         logWarning("ERROR: Invalid tag couldn't convert from unicode")
         tag = None
     if key is not None and isinstance(
             tag, str) and not self.hasTagKey(tag, key):
         if self.hasTag(tag):
             self.tag_maps[tag].append(key)
         else:
             self.tag_maps[tag] = [key]
         if not delaySave:
             self.save()
             self.reload()
예제 #22
0
 def processQueuedMessages(self, wait=0.001):
     socketio = self._socketio
     msgKey = self.MESSAGES_KEY
     dataKey = self.DATA_KEY
     sessionKey = SESSION_KEY
     messagesNS = self.MESSAGES_NAMESPACE
     while True:
         time.sleep(wait)
         if not self._messages.empty():
             sid, sessionId, msg = self.dequeueAJAXMessage()
             #if sessionId and len(self._socketio.server.rooms(sessionId)) > 0:
             if sessionId:
                 self._socketio.emit(msgKey, {
                     dataKey: msg,
                     sessionKey: sessionId
                 },
                                     namespace=messagesNS,
                                     room=sessionId)
             else:
                 logWarning("Could not find room %s (Message was: %s)" %
                            (sessionId, msg))
예제 #23
0
    def _createValue(self,
                     key,
                     value,
                     name='',
                     description='',
                     tags=None,
                     storageType=DATA_TYPE_DB,
                     dataType=''):
        # Force Valid Default values
        if name is None: name = ''
        if description is None: description = ''
        if tags is None: tags = []
        if dataType is None: dataType = ''
        if storageType is None: storageType = DATA_TYPE_DB

        # Must be a valid storage type
        if (key is not None and isinstance(key, basestring)
                and isinstance(storageType, int)
                and storageType in VALID_STORAGE_TYPES):
            storageData = {
                'key': key,
                'value': value,
                'name': name,
                'data_type': dataType,
                'description': description
            }
            storageClass = self.STORAGE_ADAPTORS[storageType]
            data = storageClass(**storageData)
            if name != '':
                self.name_map[name] = key
            self.adaptor_map[key] = storageType
            for tag in tags:
                self.addTagKey(tag, key, delaySave=True)
            data.save()
            self.save()
            self.reload()
            return True
        else:
            logWarning("Couldn't create :" + str(key))
            return False
예제 #24
0
 def setValue(
     self,
     key=None,
     value=None,
     name=None,
     description=None,
     tags=None,
     storageType=None,
     dataType=None,
     allowOverwrite=False,
     allowCreate=True,
 ):
     self.reload()
     logWarning("SETTING VALUE")
     hasKey = self.hasKey(key)
     hasName = self.hasName(name)
     ref = self.resolveRef(key, name)
     # Make sure reference is valid, if any given
     if (ref is None) and ((hasKey and hasName) or (hasName and key is not None)):
         logWarning("INVALID: Mismatched unique keys in set value: (key=%s, name=%s)" % (key, name))
         return False
     # Overwrite existing data
     # This is aborted if another entry uses has the new 'name'
     elif (ref is not None) and allowOverwrite:
         return self._updateValue(key, value, name, description, tags, storageType, dataType)
     # Create a new entry
     # The key must not already exist and a non-None value must be given
     elif (ref is None) and allowCreate:
         return self._createValue(key, value, name, description, tags, storageType, dataType)
     else:
         logWarning("INVALID CONDITION")
         return False
예제 #25
0
 def setValue(self,
              key=None,
              value=None,
              name=None,
              description=None,
              tags=None,
              storageType=None,
              dataType=None,
              allowOverwrite=False,
              allowCreate=True):
     self.reload()
     logWarning("SETTING VALUE")
     hasKey = self.hasKey(key)
     hasName = self.hasName(name)
     ref = self.resolveRef(key, name)
     # Make sure reference is valid, if any given
     if (ref is None) and ((hasKey and hasName) or
                           (hasName and key is not None)):
         logWarning(
             "INVALID: Mismatched unique keys in set value: (key=%s, name=%s)"
             % (key, name))
         return False
     # Overwrite existing data
     # This is aborted if another entry uses has the new 'name'
     elif (ref is not None) and allowOverwrite:
         return self._updateValue(key, value, name, description, tags,
                                  storageType, dataType)
     # Create a new entry
     # The key must not already exist and a non-None value must be given
     elif (ref is None) and allowCreate:
         return self._createValue(key, value, name, description, tags,
                                  storageType, dataType)
     else:
         logWarning('INVALID CONDITION')
         return False
예제 #26
0
 def _updateValue(self,
                  key,
                  value=None,
                  name=None,
                  description=None,
                  tags=None,
                  storageType=None,
                  dataType=None):
     key = self.resolveRef(key, name)
     currentName = self.getName(key)
     data = self._getData(key)
     if key is not None and data is not None:
         if name is not None and currentName != name:
             isChanged, data = self._changeName(name, data)
             if not isChanged:
                 # Failed on change name attempt
                 logWarning("Failed to update, rename failed: ", name)
                 return False
         if value is not None:
             data.value = value
         if dataType is not None:
             data.data_type = dataType
         if description is not None:
             data.description = description
         if storageType is not None:
             # @TODO: Fix this so it works appropriately
             # (e.g., changes the stored object type)
             # For now, no-op
             # self.adaptor_map[key] = storageType
             pass
         if tags is not None:
             self.changeTags(tags, key, delaySave=True)
         data.save()
         self.save()
         self.reload()
         return True
     else:
         logWarning("Error in updateValue. Couldn't get rename for: " +
                    str(key))
         return False
예제 #27
0
    def findAssignmentNumber(self, task, sessions):
        possibleTaskNumber = -1
        for session in sessions:
            #sessionTask = session.getTask()
            #logInfo("task id is {0}, and session id is {1}".format(task._taskId, session.task), 1)

            if task._taskId == session.task:
                logInfo("found session with previous task", 1)
                if session.assignmentNumber is not None:
                    logInfo(
                        "session.assignmentNumber = {0}".format(
                            session.assignmentNumber), 5)
                    try:
                        possibleTaskNumber = int(session.assignmentNumber)
                    except:
                        logWarning(
                            "Failed to Find session.assignmentNumber for | {0}"
                            .format(session.task))
                        possibleTaskNumber = 0
                else:
                    possibleTaskNumber = 0
        return possibleTaskNumber + 1
예제 #28
0
 def receiveMessage(self, msg):
     """ Get message from a child and process/distribute it """
     super(HTTPMessagingGateway, self).receiveMessage(msg)
     logWarning("Message Received")
     self.queueAJAXMessage(msg)
     logWarning("Message Distributing %s" % msg.getId())
     self.distributeMessage(msg)
     logWarning("Message Distributed %s" % msg.getId())
예제 #29
0
 def getCalendarFromOwnerId(self, ownerId=None, useCache=True):
     if ownerId is None:
         logWarning("NO OWNER ID WAS GIVEN WHEN ATTEMPTING TO LOOK UP CALENDAR")
         return None
     
     if useCache:
         result = self.calendarCache.get(ownerId, None)
         if result is not None:
             return result;
     
     foundCalendars = DBCalendarData.find_by_index("ownerIdIndex", [])
     calendarData = None
     if len(foundCalendars) == 0:
         logInfo("No calendar found, creating a new calendar for owner:{0}".format(ownerId), 1)
         calendarData = DBCalendarData()
         calendarData.setCalendarData(ownerId)
     elif len(foundCalendars) == 1:
         calendarData = foundCalendars[0]
     elif len(foundCalendars) > 1:
         logWarning("{0} owns more than a single calendar.  Database may be corrupted.  Defaulting to the first value".format(ownerId))
         calendarData = foundCalendars[0]
     self.calendarCache[ownerId] = calendarData
     return calendarData
예제 #30
0
def staticImports(path):
    if path[-3:] not in ('.git'):
        try:
            return BASIC_BLUEPRINT.send_static_file(path)
        except Exception as e:
            logWarning('exception=')
            logWarning(e)
            logWarning(path)
            abort(404)
    else:
        return abort(404)
예제 #31
0
def cssImports(path):
    if path[-3:] == '.css':
        try:
            return BASIC_BLUEPRINT.send_static_file(path)
        except Exception as e:
            logWarning('exception=')
            logWarning(e)
            logWarning(path)
            abort(404)
    else:
        return abort(404)
def before_first():
    logWarning('Handling database init')
    if application.debug:
        # Debug/local dev
        logWarning('Debug Mode: MongoDB')
        default_database(Database( 'mongodb', mongo_url='mongodb://localhost:27017/TestDB'))
    else:
        # Production!
        logWarning('Production Mode: DynamoDB')
        default_database(Database('dynamodb'))
    set_db_application_prefix(APPLICATION_NAME)

    # Make sure we have our tables
    #IncomingMessage.ensure_table()
    initDerivedDataTables()
예제 #33
0
def before_first():
    logWarning('Handling database init')
    if application.debug:
        # Debug/local dev
        logWarning('Debug Mode: MongoDB')
        default_database(Database( 'mongodb', mongo_url='mongodb://localhost:27017/TestDB'))
    else:
        # Production!
       logWarning('Production Mode: MongoDB')
       default_database(Database( 'mongodb', mongo_url='mongodb://localhost:27017/TestDB'))
    set_db_application_prefix(APPLICATION_NAME)

    # Make sure we have our tables
    #IncomingMessage.ensure_table()
    initDerivedDataTables()
예제 #34
0
def StartServer(app=None, socketio=None, host=None, port=DEFAULT_PORT, debug=True):
    if socketio is None: socketio = SOCKET_IO_CORE
    if host is None:
        if debug:
            host = '0.0.0.0'
        else:
            host = '127.0.0.1'
    Thread(target=background_thread).start()
    logWarning("Starting Socket App1")
    try:
        logWarning(host)
        logWarning(port)
        socketio.run(app, host=host, port=port)
    except Exception as err:
        logError("Error: Could not start socketio.")
        DB_CONNECTION.close()
def StartServer(app=None, socketio=None, host=None, port=DEFAULT_PORT, debug=True):
    if socketio is None: socketio = SOCKET_IO_CORE
    if host is None:
        if debug:
            host = '0.0.0.0'
        else:
            host = '127.0.0.1'
    Thread(target=background_thread).start()
    logWarning("Starting Socket App1")
    try:
        logWarning(host)
        logWarning(port)
        socketio.run(app, host=host, port=port)
    except Exception as err:
        logError("Error: Could not start socketio.")
        DB_CONNECTION.close()
예제 #36
0
 def processStorageInform(self, bucket, verb, key=None, value=None,
                          tags=None, aType=None, allowCreate=None,
                          name=None, description=None, dataType=None):
     if verb == self.VALUE_VERB:
         logWarning("IS SETTING", value)
         if isinstance(value, Serializable):
             logWarning("IS SERIALIZABLE")
             if key is None:
                 key = value.getId()
             elif key != value.getId():
                 logWarning('BAD KEY for Storage (%s != %s)'%(key, value.getId()))
                 return False
             if isinstance(value, NamedSerializable):
                 if name is None:
                     name = value.getName()
                 elif name != value.getName():
                     logWarning('BAD NAME for Storage(%s != %s)'%(name, value.getName()))
                     return False
             #NOTE we are assuming that the value class and dbValue class have the toDB and saveToDB functions respectively.
             #If they do not have them they must be implemented or the system will not save the data.
         try:
             
             if isinstance(value, list):
                 for valueObject in value:
                     logInfo("saving task {0} to database".format(valueObject._name), 4)
                     dbValue = DBSerializable.convert(valueObject) 
                     dbValue.saveToDB()
                                     
         except NotImplementedError:
             logInfo('failed to serialize object', 1)
             dbValue = JSONtoDBSerializable(value)
             dbValue.saveToDB()
         return True
     
     #GLUDB does not currently allow for deletion of items so this should always return false
     elif verb == self.VOID_VERB:
         return False
예제 #37
0
    def receiveMessage(self, msg):
        logWarning("TEST SERVICE GOT: \n", self.messageToString(msg))

        default = "{{missing}}"

        authKey = msg.getContextValue(Message.AUTHENTICATION_KEY, default)
        logWarning(" ===> authN:[%s], authZ:[%s], ShouldBeBlank:[%s] <=== " % (
            authKey,
            msg.getContextValue(Message.AUTHORIZATION_KEY, default),
            msg.getContextValue('BE-BLANK', default),
        ))

        if authKey:
            try:
                from AWS_Core_Services.Authentication.UserData import UserData
                user = UserData.read(authKey)
                if user:
                    logWarning("USER IN MESSAGE: %s" % str(user))
                else:
                    logWarning("USER IN MESSAGE: {{{NONE}}}")
            except:
                pass

        super(TestService, self).receiveMessage(msg)
예제 #38
0
 def receiveMessage(self, msg):
     # TODO: Restore bucket management
     #if ((msg.getActor() == STORAGE_SERVICE_NAME) and
     #    (msg.getContextValue(self.BUCKET_KEY, None) is not None) and
     #    (self.hasBucket(msg.getContextValue(self.BUCKET_KEY)))):
     print("STORAGE RECEIVED MESSAGE: %s" % (msg, ))
     if (msg.getActor() == STORAGE_SERVICE_NAME):
         bucket = self.getBucket(msg.getContextValue(self.BUCKET_KEY))
         # Inform: Set some value(s)
         if (msg.getSpeechAct() == INFORM_ACT):
             try:
                 logWarning("INFORMING")
                 value = self.processStorageInform(
                     bucket, msg.getVerb(), msg.getObject(),
                     msg.getResult(),
                     msg.getContextValue(self.TAGS_KEY, None),
                     msg.getContextValue(self.TYPE_KEY, None),
                     msg.getContextValue(self.ALLOW_CREATE_KEY, True),
                     msg.getContextValue(self.NAME_KEY, None),
                     msg.getContextValue(self.DESCRIPTION_KEY, None),
                     msg.getContextValue(self.DATA_TYPE_KEY, None))
                 if (value == True):
                     response = self.makeConfirmMessage(msg)
                 else:
                     response = self.makeDisconfirmMessage(msg)
             except Exception:
                 self.sendMessage(self.makeDisconfirmMessage(msg))
                 raise
             self.sendMessage(response)
         # Request: get some value(s)
         elif (msg.getSpeechAct() == REQUEST_ACT):
             try:
                 value = self.processStorageRequest(
                     bucket, msg.getVerb(), msg.getObject(),
                     msg.getContextValue(self.TAGS_KEY, None),
                     msg.getContextValue(self.TYPE_KEY, None),
                     msg.getContextValue(self.NAME_KEY, None))
                 if msg.getVerb() == self.CONTAINS_VERB:
                     response = self.makeReplyToContainsMessage(
                         msg, value[0], value[1])
                 elif msg.getVerb() != INFORM_REF_ACT or value is None:
                     response = self.makeRequestAnswerMessage(msg, value)
                 else:
                     response = self.makeReplyToInformRefMessage(
                         msg, value[0], value[1])
             except Exception:
                 self.sendMessage(self.makeDisconfirmMessage(msg))
                 raise
             self.sendMessage(response)
         # Inform about the name of a value (rename)
         elif (msg.getSpeechAct() == INFORM_REF_ACT):
             try:
                 value = self.processStorageRename(
                     bucket, msg.getVerb(), msg.getObject(),
                     msg.getResult(),
                     msg.getContextValue(self.NAME_KEY, None))
                 if (value == True):
                     response = self.makeConfirmMessage(msg)
                 else:
                     response = self.makeDisconfirmMessage(msg)
             except Exception:
                 self.sendMessage(self.makeDisconfirmMessage(msg))
                 raise
             self.sendMessage(response)
         else:
             logWarning("COULD NOT PROCESS (%s): %s" %
                        (self.getId(), serializeObject(msg)))
예제 #39
0
def onDisconnect():
    logWarning('Client disconnected')
예제 #40
0
 def sendTestString(self, aStr):
     logWarning("Test Service is Sending: ", aStr)
     self.sendMessage(Message("TestService", "Sent Test", "To Server",
                              aStr))
예제 #41
0
 def onConnect():
     logWarning("Connected")
예제 #42
0
    def onConnect():
        logWarning("Connected")
        #flask.ext.socketio.emit('my response', {'data': 'Connected', 'count': 0})

    @SOCKET_IO_CORE.on('disconnect', namespace='/messaging')
    def onDisconnect():
        logWarning('Client disconnected')


    #First check to see if HOST and PORT were specified in the
    #environment - if so, we use those values directly and skip
    #the "usual" logic below
    envHost, envPort = None, None
    try:
        envHost = os.getenv('HOST', None)
        envPort = int(os.getenv('PORT', 0))
    except:
        pass

    if envHost and envPort:
        logWarning("Using Host/Port from environment: %s:%d" % (envHost, envPort))
        StartServer(FLASK_CORE_APP, SOCKET_IO_CORE, envHost, envPort, DEBUG_MODE)
    elif DEBUG_MODE:
        StartDebugServer(FLASK_CORE_APP, SOCKET_IO_CORE)
    elif DEBUG_ON_VM:
        StartVMDebugServer(FLASK_CORE_APP, SOCKET_IO_CORE)
    elif False:
        StartDirectServer(FLASK_CORE_APP, SOCKET_IO_CORE)
    else:
        StartProductionServer(FLASK_CORE_APP, SOCKET_IO_CORE)
 def logOnly(self, strg, loc, toks):
     logWarning("LOG: ", toks)
예제 #44
0
                self.name_map[name] = key
                self._changeName(name, data)
        self.save()
        return StorageObject.objects, self.adaptor_map, self.name_map


if __name__ == "__main__":
    # Backup to files
    if False:
        outDataFile = "StorageServiceBackup.log"
        conn = connect("StorageService_DB")
        try:
            storageService = MongoStorageService(conn)
            outData = storageService.exportBucket("ONR")
        except Exception, exc:
            logWarning(exc)
        finally:
            conn.close()
        outStr = serializeObject(outData)
        with open(outDataFile, "wb") as aFile:
            aFile.write(outStr)
    if False:
        conn = connect("StorageService_DB")
        try:
            storageService = MongoStorageService(conn)
            bucket = storageService.getBucket("ONR")
            bucket.resolveInconsistencies()
        # except Exception as exc:
        #    logWarning("EXCEPT: ", exc)
        finally:
            conn.close()
 def receiveMessage(self, msg):
     if (
         (msg.getActor() == STORAGE_SERVICE_NAME)
         and (msg.getContextValue(self.BUCKET_KEY, None) is not None)
         and (self.hasBucket(msg.getContextValue(self.BUCKET_KEY)))
     ):
         bucket = self.getBucket(msg.getContextValue(self.BUCKET_KEY))
         # Inform: Set some value(s)
         if msg.getSpeechAct() == INFORM_ACT:
             try:
                 logWarning("INFORMING")
                 value = self.processStorageInform(
                     bucket,
                     msg.getVerb(),
                     msg.getObject(),
                     msg.getResult(),
                     msg.getContextValue(self.TAGS_KEY, None),
                     msg.getContextValue(self.TYPE_KEY, None),
                     msg.getContextValue(self.ALLOW_CREATE_KEY, True),
                     msg.getContextValue(self.NAME_KEY, None),
                     msg.getContextValue(self.DESCRIPTION_KEY, None),
                     msg.getContextValue(self.DATA_TYPE_KEY, None),
                 )
                 if value == True:
                     response = self.makeConfirmMessage(msg)
                 else:
                     response = self.makeDisconfirmMessage(msg)
             except Exception:
                 self.sendMessage(self.makeDisconfirmMessage(msg))
                 raise
             self.sendMessage(response)
         # Request: get some value(s)
         elif msg.getSpeechAct() == REQUEST_ACT:
             try:
                 value = self.processStorageRequest(
                     bucket,
                     msg.getVerb(),
                     msg.getObject(),
                     msg.getContextValue(self.TAGS_KEY, None),
                     msg.getContextValue(self.TYPE_KEY, None),
                     msg.getContextValue(self.NAME_KEY, None),
                 )
                 if msg.getVerb() == self.CONTAINS_VERB:
                     response = self.makeReplyToContainsMessage(msg, value[0], value[1])
                 elif msg.getVerb() != INFORM_REF_ACT or value is None:
                     response = self.makeRequestAnswerMessage(msg, value)
                 else:
                     response = self.makeReplyToInformRefMessage(msg, value[0], value[1])
             except Exception:
                 self.sendMessage(self.makeDisconfirmMessage(msg))
                 raise
             self.sendMessage(response)
         # Inform about the name of a value (rename)
         elif msg.getSpeechAct() == INFORM_REF_ACT:
             try:
                 value = self.processStorageRename(
                     bucket,
                     msg.getVerb(),
                     msg.getObject(),
                     msg.getResult(),
                     msg.getContextValue(self.NAME_KEY, None),
                 )
                 if value == True:
                     response = self.makeConfirmMessage(msg)
                 else:
                     response = self.makeDisconfirmMessage(msg)
             except Exception:
                 self.sendMessage(self.makeDisconfirmMessage(msg))
                 raise
             self.sendMessage(response)
         else:
             logWarning("COULD NOT PROCESS (%s): %s" % (self.getId(), serializeObject(msg)))
예제 #46
0
 def logOnly(self, strg, loc, toks):
     logWarning("LOG: ", toks)
예제 #47
0
 def delBucket(self, name):
     if name is not None:
         buckets = Bucket.objects(bucket_name=name)
         buckets.delete()
     else:
         logWarning("Could not remove missing bucket: %s"(name))
예제 #48
0
 def _renameBucket(self, oldName, newName):
     bucket = self.getBucket(oldName)
     if bucket:
         bucket.setBucketName(newName)
     else:
         logWarning("Could not rename missing bucket: %s"(oldName))
예제 #49
0
if application.config.get('DEBUG', None):
    # Debug mode - running on a workstation
    application.debug = True
    logging.basicConfig(level=logging.DEBUG)
else:
    # We are running on AWS Elastic Beanstalk (or something like it)
    application.debug = False
    # See .ebextensions/01logging.config
    logging.basicConfig(
        filename='log/Re.log',
        level=logging.INFO
    )

APPLICATION_NAME = application.config.get('APPLICATION_NAME', 'noName')
    
logWarning('Application debug is %s'%(application.debug,))

# Register our blueprints
application.register_blueprint(BASIC_BLUEPRINT)

# Start up the messaging system
SOCKET_IO_CORE = flask_socketio.SocketIO(application)

#Allow some env specification of helpful test services
services = [DBLoggingService(), StudentModelMessaging(), GLUDBStorageService(),
            CSVReader(), RecommenderMessaging(), ICalReader()]

MESSAGING_GATEWAY = HTTPMessagingGateway(
        None,
        SOCKET_IO_CORE,
        flask_socketio,
if application.config.get('DEBUG', None):
    # Debug mode - running on a workstation
    application.debug = True
    logging.basicConfig(level=logging.DEBUG)
else:
    # We are running on AWS Elastic Beanstalk (or something like it)
    application.debug = False
    # See .ebextensions/01logging.config
    logging.basicConfig(
        filename='log/Re.log',
        level=logging.INFO
    )

APPLICATION_NAME = application.config.get('APPLICATION_NAME', 'noName')
    
logWarning('Application debug is %s'%(application.debug,))

# Register our blueprints
application.register_blueprint(BASIC_BLUEPRINT)

# Start up the messaging system
SOCKET_IO_CORE = flask.ext.socketio.SocketIO(application)

#Allow some env specification of helpful test services
services = [DBLoggingService(), StudentModelMessaging(), GLUDBStorageService(),
            CSVReader(), RecommenderMessaging(), ICalReader()]

MESSAGING_GATEWAY = HTTPMessagingGateway(
        None,
        SOCKET_IO_CORE,
        flask.ext.socketio,
예제 #51
0
 def delBucket(self, name):
     if name is not None:
         buckets = Bucket.objects(bucket_name=name)
         buckets.delete()
     else:
         logWarning("Could not remove missing bucket: %s" (name, ))
예제 #52
0
def onConnect():
    logWarning("Connected")
예제 #53
0
 def onDisconnect():
     logWarning('Client disconnected')