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'])
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
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}
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}
def aFunctionThrowingASpecificException(self, jsonArgs): raise Exceptions.SubscribableWebObjectsException( "swo exception: function call")
def aValueThrowingASpecificException(self): raise Exceptions.SubscribableWebObjectsException( "swo exception: getter")
def setAValueThrowingASpecificException(self, value): raise Exceptions.SubscribableWebObjectsException( "swo exception: setter")
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)