Exemple #1
0
def update(id_, data, author):
    """
    update an existing object description at the database

    id_ : complete identifier (primary key) of the object

    data: dictionary with the updated data ('description' (human readable) and
    'object_description' (OWL))

    author: author of the description
    """

    transport = roboearth.openDBTransport()
    client = transport['client']
    try:
        mutation_list = []
        if data.has_key('description'):
            mutation_list.append(
                Mutation(column="info:description", value=data['description']))
        if data.has_key('object_description'):
            mutation_list.append(
                Mutation(column="owl:description",
                         value=data['object_description']))

        client.mutateRow("Elements", id_,
                         [Mutation(column="info:modified_by", value=author)] +
                         mutation_list)

        if data.has_key('object_description'):
            sesame.rm(id_, "Elements")
            sesame.set(data['object_description'], id_, "Elements")

        # push update to subscribers
        scanner = client.scannerOpenWithPrefix("Elements", id_, [])
        res = client.scannerGet(scanner)
        for r in res[0].columns:
            if r.startswith("subscriber:"):
                client.mutateRow(
                    "Users", res[0].columns[r].value,
                    [Mutation(column="news:", value="Objects#" + id_)])

        client.scannerClose(scanner)
        roboearth.closeDBTransport(transport)

        return True
    except (IOError, IllegalArgument), err:
        raise roboearth.DBWriteErrorException(
            "Can't write data to Elements table: " + err.__str__())
Exemple #2
0
def update(id_, data, author):
    """
    update an existing object description at the database

    id_ : complete identifier (primary key) of the object

    data: dictionary with the updated data ('description' (human readable) and
    'object_description' (OWL))

    author: author of the description
    """

    transport = roboearth.openDBTransport()
    client = transport['client']
    try:
        mutation_list = [ ]
        if data.has_key('description'):
            mutation_list.append(Mutation(column="info:description", value=data['description']))            
        if data.has_key('object_description'):
            mutation_list.append(Mutation(column="owl:description", value=data['object_description']))            
        
        client.mutateRow("Elements", id_,
                         [Mutation(column="info:modified_by", value=author)] +
                         mutation_list)

        if data.has_key('object_description'):
            sesame.rm(id_, "Elements")
            sesame.set(data['object_description'], id_, "Elements")

        # push update to subscribers
        scanner = client.scannerOpenWithPrefix("Elements", id_, [ ])
        res = client.scannerGet(scanner)
        for r in res[0].columns:
            if r.startswith("subscriber:"):
                client.mutateRow("Users", res[0].columns[r].value,
                                 [Mutation(column="news:", value="Objects#"+id_)])

        client.scannerClose(scanner)
        roboearth.closeDBTransport(transport)

        return True
    except (IOError, IllegalArgument), err:
        raise roboearth.DBWriteErrorException("Can't write data to Elements table: " + err.__str__())
Exemple #3
0
def set(id_, class_, description, recipe, author):
    """
    write recipe to the database

    id_ : recipe identifier

    class_: recipe class

    description: human readable description

    recipe: owl description

    author: author of the description
    """

    transport = roboearth.openDBTransport()
    client = transport['client']
    recipeName = class_.replace(' ',
                                '').lower().strip('.') + '.' + id_.replace(
                                    ' ', '').lower().strip('.')
    try:
        # recipe already exist
        if get(query=recipeName, exact=True):
            return None

        #write data to hbase
        client.mutateRow("Elements", recipeName, [
            Mutation(column="info:description", value=description),
            Mutation(column="info:author", value=author),
            Mutation(column="info:rating", value="1"),
            Mutation(column="info:type", value="recipe"),
            Mutation(column="owl:description", value=recipe)
        ])

        #write data to sesame
        sesame_ret = sesame.set(recipe, recipeName, "elements")
        if sesame_ret != "0":
            hbase_op.delete_row("Elements", recipeName)
            raise IllegalArgument(sesame_ret)

        client.mutateRow("Users", author,
                         [Mutation(column="element:" + recipeName, value="")])

        roboearth.closeDBTransport(transport)

        return {'id': recipeName, 'description': description, 'recipe': recipe}
    except (IOError, IllegalArgument), err:
        raise roboearth.DBWriteErrorException(
            "Can't write data to Action Recipe table: " + err.__str__())
Exemple #4
0
def set(id_, class_, description, recipe, author):
    """
    write recipe to the database

    id_ : recipe identifier

    class_: recipe class

    description: human readable description

    recipe: owl description

    author: author of the description
    """

    transport = roboearth.openDBTransport()
    client = transport['client']
    recipeName = class_.replace(' ', '').lower().strip('.') + '.' + id_.replace(' ', '').lower().strip('.')
    try:
        # recipe already exist
        if get(query=recipeName, exact=True):
            return None

        #write data to hbase
        client.mutateRow("Elements", recipeName,
                         [Mutation(column="info:description", value=description),
                          Mutation(column="info:author", value=author),
                          Mutation(column="info:rating", value="1"),
                          Mutation(column="info:type", value="recipe"),
                          Mutation(column="owl:description", value=recipe)])

        #write data to sesame
        sesame_ret = sesame.set(recipe, recipeName, "elements")
        if sesame_ret != "0":
            hbase_op.delete_row("Elements", recipeName)
            raise IllegalArgument(sesame_ret)
            
        client.mutateRow("Users", author,
                         [Mutation(column="element:"+recipeName, value="")])

        roboearth.closeDBTransport(transport)      

        return {'id' : recipeName, 'description' : description, 'recipe' : recipe}
    except (IOError, IllegalArgument), err:
        raise roboearth.DBWriteErrorException("Can't write data to Action Recipe table: " + err.__str__())
            hdfs.upload_file(file_, path)
            file_mutation_list.append(
                Mutation(column="file:" + file_ID,
                         value=wwwPath + "/" + file_.name))

    try:
        client.mutateRow("Elements", envName, [
            Mutation(column="info:description", value=description),
            Mutation(column="info:author", value=author),
            Mutation(column="info:rating", value="1"),
            Mutation(column="info:type", value="environment"),
            Mutation(column="owl:description", value=environment)
        ] + mutation_list + file_mutation_list)

        #write data to sesame
        sesame_ret = sesame.set(environment, envName, "elements")
        if sesame_ret != "0":
            hbase_op.delete_row("Elements", envName)
            raise IllegalArgument(sesame_ret + 'bug' + envName + ' ' +
                                  environment)

        client.mutateRow("Users", author,
                         [Mutation(column="element:" + envName, value="")])

        roboearth.closeDBTransport(transport)

        return {
            'id': envName,
            'description': description,
            'environment': environment
        }
Exemple #6
0
    if files:
        for file_ID, file_ in files.items():
            hdfs.upload_file(file_, path)
            file_mutation_list.append(Mutation(column="file:"+file_ID, value=wwwPath+"/"+file_.name))
              
    try:
        client.mutateRow("Elements", envName,
                         [Mutation(column="info:description", value=description),
                          Mutation(column="info:author", value=author),
                          Mutation(column="info:rating", value="1"),
                          Mutation(column="info:type", value="environment"),
                          Mutation(column="owl:description", value=environment)] +
                         mutation_list + file_mutation_list)

        #write data to sesame
        sesame_ret = sesame.set(environment, envName, "elements")
        if  sesame_ret != "0":
            hbase_op.delete_row("Elements", envName)
            raise IllegalArgument(sesame_ret+'bug'+envName+' ' +environment)

        client.mutateRow("Users", author,
                         [Mutation(column="element:"+envName, value="")])

        roboearth.closeDBTransport(transport)            

        return {'id' : envName, 'description' : description, 'environment' : environment}

    except (IOError, IllegalArgument), err:
        raise roboearth.DBWriteErrorException("Can't write data to Environment table: " + err.__str__())

def update(id_, data, author):
Exemple #7
0
def set(id_, class_, description, object_description, author, files=None):
    """
    write a object description to the database

    id_ : object identifier

    class_: object class

    description: human readable description

    object_description: owl description

    author: author of the description

    files: dictionary of binary files (file identifier : file)
    """
    logging.basicConfig(filename='example.log', level=logging.DEBUG)
    transport = roboearth.openDBTransport()
    client = transport['client']

    identifier = class_.replace(' ',
                                '').lower().strip('.') + '.' + id_.replace(
                                    ' ', '').lower().strip('.')

    #create paths
    path = class_.replace(' ', '').lower().strip('.') + '.' + id_.replace(
        ' ', '').lower().strip('.')
    wwwPath = roboearth.DOMAIN + os.path.join("data/", 'elements/',
                                              path.replace('.', '/'))
    path = os.path.join(roboearth.UPLOAD_DIR, 'elements/',
                        path.replace('.', '/'))

    try:
        # object already exists
        if get(query=identifier, exact=True):
            return None

        # upload files and build file mutation list for hbase operation
        file_mutation_list = []
        if files:
            for file_ID, file_ in files.items():
                hdfs.upload_file(file_, path)
                file_mutation_list.append(
                    Mutation(column="file:" + file_ID,
                             value=wwwPath + "/" + file_.name))

        # now write to hbase
        client.mutateRow("Elements", identifier, [
            Mutation(column="info:description", value=description),
            Mutation(column="info:author", value=author),
            Mutation(column="info:rating", value="1"),
            Mutation(column="info:type", value="object"),
            Mutation(column="owl:description", value=object_description)
        ] + file_mutation_list)

        #write data to sesame
        sesame_ret = sesame.set(object_description, identifier, "elements")
        if sesame_ret != "0":
            hbase_op.delete_row("Elements", identifier)
            print 'raising shit'
            raise IllegalArgument(sesame_ret)

        client.mutateRow("Users", author,
                         [Mutation(column="element:" + identifier, value="")])

        roboearth.closeDBTransport(transport)

        #if not roboearth.local_installation:
        #    roboearth.send_twitter_message("upload", "Object", identifier, author)

        return {
            'id': identifier,
            'description': description,
            'object_description': object_description
        }

    except (IOError, IllegalArgument), err:
        try:  # try clean up
            hdfs.rm_dir(path)
            hbase_op.delete_row("Elements", identifier)
            sesame.rm(identifier, "Elements")
        except:
            sys.exc_clear()
        import traceback
        logging.info(traceback.format_exc())
        raise roboearth.DBWriteErrorException(
            "Can't write data to Object table: HEREEEEE " + err.__str__())
Exemple #8
0
def set(id_, class_, description, object_description, author, files=None):
    """
    write a object description to the database

    id_ : object identifier

    class_: object class

    description: human readable description

    object_description: owl description

    author: author of the description

    files: dictionary of binary files (file identifier : file)
    """
    logging.basicConfig(filename='example.log',level=logging.DEBUG)
    transport = roboearth.openDBTransport()
    client = transport['client']

    identifier = class_.replace(' ', '').lower().strip('.') + '.' + id_.replace(' ', '').lower().strip('.')

    #create paths
    path = class_.replace(' ', '').lower().strip('.') +  '.' +id_.replace(' ', '').lower().strip('.')
    wwwPath = roboearth.DOMAIN + os.path.join("data/", 'elements/', path.replace('.', '/'))
    path = os.path.join(roboearth.UPLOAD_DIR, 'elements/', path.replace('.', '/'))

    try:
        # object already exists
        if get(query=identifier, exact=True):
            return None
        
        # upload files and build file mutation list for hbase operation
        file_mutation_list = [ ]
        if files:
            for file_ID, file_ in files.items():
                hdfs.upload_file(file_, path)
                file_mutation_list.append(Mutation(column="file:"+file_ID, value=wwwPath+"/"+file_.name))

        # now write to hbase
        client.mutateRow("Elements", identifier,
                         [Mutation(column="info:description", value=description),
                          Mutation(column="info:author", value=author),
                          Mutation(column="info:rating", value="1"),
                          Mutation(column="info:type", value="object"),
                          Mutation(column="owl:description", value=object_description)]+
                         file_mutation_list)
        
        #write data to sesame
        sesame_ret = sesame.set(object_description, identifier, "elements")
        if sesame_ret != "0":
            hbase_op.delete_row("Elements", identifier)
            print 'raising shit'
            raise IllegalArgument(sesame_ret)

        client.mutateRow("Users", author,
                         [Mutation(column="element:"+identifier, value="")])

        roboearth.closeDBTransport(transport)

        #if not roboearth.local_installation:
        #    roboearth.send_twitter_message("upload", "Object", identifier, author)

        return {'id' : identifier, 'description' : description, 'object_description' : object_description}

    except (IOError, IllegalArgument), err:
        try: # try clean up
            hdfs.rm_dir(path)
            hbase_op.delete_row("Elements", identifier)
            sesame.rm(identifier, "Elements")
        except:
            sys.exc_clear()
        import traceback
        logging.info(traceback.format_exc())
        raise roboearth.DBWriteErrorException("Can't write data to Object table: HEREEEEE " + err.__str__())