示例#1
0
def construct(json):
    if (not isinstance(json, dict) or
            'type' not in json or 'args' not in json):
        raise Exceptions.SubscribableWebObjectsException("Invalid ObjectDefinition: %s", json)

    if json['type'] not in classMap:
        raise Exceptions.SubscribableWebObjectsException("Unknown class type: %s", json['type'])

    return json['type'](json['args'])
示例#2
0
    def writeToS3(self, bucketname, keyname):
        """Trigger a task writing this dataset to amazon S3.

        Returns a WriteToS3Task object.
        """
        if not isinstance(bucketname, str):
            raise Exceptions.SubscribableWebObjectsException("Expected bucketname to be a string")
        if not isinstance(keyname, str):
            raise Exceptions.SubscribableWebObjectsException("Expected keyname to be a string")

        if self.valueIVC is None:
            return None

        task = WriteToS3Task.WriteToS3Task(computedValue=self, bucketname=bucketname, keyname=keyname)

        task.trigger()

        return task
示例#3
0
    def convert(self, objectId, serializedBinaryObjectDefinition):
        import pyfora.Exceptions as PyforaExceptions
        import pyfora.BinaryObjectRegistryDeserializer as BinaryObjectRegistryDeserializer


        result = [None]
        def onConverted(r):
            result[0] = r

        t0 = time.time()

        BinaryObjectRegistryDeserializer.deserializeFromString(
            base64.b64decode(serializedBinaryObjectDefinition), 
            objectRegistry_[0],
            convertJsonToObject
            )

        logging.info("Updated object registry in %s seconds.", time.time() - t0)
        t0 = time.time()

        try:
            converter_[0].convert(objectId, objectRegistry_[0], onConverted)
        except Exception as e:
            logging.error("Converter raised an exception: %s", traceback.format_exc())
            raise Exceptions.InternalError("Unable to convert objectId %s" % objectId)

        logging.info("Converted to fora in %s seconds", time.time() - t0)

        assert result[0] is not None

        if isinstance(result[0], PyforaExceptions.PythonToForaConversionError):
            return {'isException': True, 'message': result[0].message, 'trace': result[0].trace}

        if isinstance(result[0], Exception):
            raise Exceptions.SubscribableWebObjectsException(result[0].message)

        objectIdToIvc_[objectId] = result[0]
        return {'objectId': objectId}
示例#4
0
    def convert(self, objectId, objectIdToObjectDefinition):
        import pyfora.TypeDescription as TypeDescription
        import pyfora.Exceptions as PyforaExceptions

        result = [None]
        def onConverted(r):
            result[0] = r

        t0 = time.time()

        objectRegistry_[0].objectIdToObjectDefinition.update({
            int(k): TypeDescription.deserialize(v)
            for k, v in objectIdToObjectDefinition.iteritems()
            })

        logging.info("Updated object registry in %s seconds.", time.time() - t0)
        t0 = time.time()

        try:
            converter_[0].convert(objectId, objectRegistry_[0], onConverted)
        except Exception as e:
            logging.error("Converter raised an exception: %s", traceback.format_exc())
            raise Exceptions.InternalError("Unable to convert objectId %s" % objectId)

        logging.info("Converted to fora in %s seconds", time.time() - t0)

        assert result[0] is not None

        if isinstance(result[0], PyforaExceptions.PythonToForaConversionError):
            return {'isException': True, 'message': result[0].message, 'trace': result[0].trace}

        if isinstance(result[0], Exception):
            raise Exceptions.SubscribableWebObjectsException(result[0].message)

        objectIdToIvc_[objectId] = result[0]
        return {'objectId': objectId}
示例#5
0
文件: Test.py 项目: vishnur/ufora
 def aFunctionThrowingASpecificException(self, jsonArgs):
     raise Exceptions.SubscribableWebObjectsException(
         "swo exception: function call")
示例#6
0
文件: Test.py 项目: vishnur/ufora
 def aValueThrowingASpecificException(self):
     raise Exceptions.SubscribableWebObjectsException(
         "swo exception: getter")
示例#7
0
文件: Test.py 项目: vishnur/ufora
 def setAValueThrowingASpecificException(self, value):
     raise Exceptions.SubscribableWebObjectsException(
         "swo exception: setter")
示例#8
0
            def raiseException():
                guid = uuid.uuid4()

                logging.error("%s of type %s is not valid json. guid = %s", jsonCandidate, type(jsonCandidate), guid)
                raise Exceptions.SubscribableWebObjectsException("result was not valid json. Guid = %s" % guid)