예제 #1
0
def delete(user_name):
    """
    delete user

    user_name : user name of the new user
    """

    hbase_op.delete_row("Users", user_name)
    return True
예제 #2
0
def delete(user_name):
    """
    delete user

    user_name : user name of the new user
    """

    hbase_op.delete_row("Users", user_name)
    return True
예제 #3
0
def updateLocation(id_, posX, posY, posZ, delta, author):
    """
    update existing object location at the database

    id_ : complete identifier (primary key) of the data

    posX, posY, posZ : coordiantes which describes the exact location

    delta : impreciseness of position data

    author: author of the description
    """

    transport = roboearth.openDBTransport()
    client = transport['client']
    try:
        oldLocation = getLocation(id_)
        object_ = oldLocation[0]['object']
        environment = oldLocation[0]['environment']
        room_number = oldLocation[0]['room_number']
        newID = environment + '.' + room_number + '.' + posX + '.' + posY + '.' + posZ + '.' + delta

        client.mutateRow("ObjectLocations", newID, [
            Mutation(column="object:id", value=object_),
            Mutation(column="info:author", value=author),
            Mutation(column="environment:id", value=environment),
            Mutation(column="environment:room", value=room_number),
            Mutation(column="position:x", value=posX),
            Mutation(column="position:y", value=posY),
            Mutation(column="position:z", value=posZ),
            Mutation(column="position:delta", value=delta)
        ])

        roboearth.closeDBTransport(transport)

        hbase_op.delete_row("ObjectLocations", id_)

        return {
            'id': id_,
            'posX': posX,
            'posY': posY,
            'posZ': posZ,
            'delta': delta,
            'object': object_,
            'environment': environment,
            'room_number': room_number
        }
    except (IOError, IllegalArgument), err:
        raise roboearth.DBWriteErrorException(
            "Can't write data to Robots table: " + err.__str__())
예제 #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__())
예제 #5
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__())
예제 #6
0
def updateLocation(id_, posX, posY, posZ, delta, author):
    """
    update existing object location at the database

    id_ : complete identifier (primary key) of the data

    posX, posY, posZ : coordiantes which describes the exact location

    delta : impreciseness of position data

    author: author of the description
    """

    transport = roboearth.openDBTransport()
    client = transport['client']
    try:
        oldLocation = getLocation(id_)
        object_ = oldLocation[0]['object']
        environment = oldLocation[0]['environment']
        room_number = oldLocation[0]['room_number']
        newID = environment + '.' + room_number + '.' + posX + '.' + posY + '.' + posZ + '.' + delta
        
        client.mutateRow("ObjectLocations", newID,
                         [Mutation(column="object:id", value=object_),
                          Mutation(column="info:author", value=author),
                          Mutation(column="environment:id", value=environment),
                          Mutation(column="environment:room", value=room_number),
                          Mutation(column="position:x", value=posX),
                          Mutation(column="position:y", value=posY),
                          Mutation(column="position:z", value=posZ),
                          Mutation(column="position:delta", value=delta)])

        roboearth.closeDBTransport(transport)

        hbase_op.delete_row("ObjectLocations", id_)
        
        return {'id' : id_, 'posX' : posX, 'posY' : posY, 'posZ' : posZ, 'delta' : delta, 'object' : object_, 'environment' : environment, 'room_number' : room_number}
    except (IOError, IllegalArgument), err:
        raise roboearth.DBWriteErrorException("Can't write data to Robots table: " + err.__str__())
예제 #7
0
            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):
    """
    update an existing recipe at the database
예제 #8
0
                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:
예제 #9
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__())
예제 #10
0
def unsubscribe(username, table, uid):
    hbase_op.delete_row(table="Subscriptions",
                        rowKey=username + "#" + table + "#" + uid)
    hbase_op.delete_column(table='Elements',
                           rowKey=uid,
                           column="subscriber:" + username)
예제 #11
0
          'http://roboearth.informatik.uni-stuttgart.de/api/0.1/recipe/<recipe_id>/<api_key>',
          Content-Type: application/json which contains:

          'api_key' : identifies the user

          'recipe_id' : the complete UID of the environment
      """

        try:
            api_key = api_keys.objects.get(key__exact=api_key)
            if not User.objects.get(
                    username__exact=api_key.username).is_active:
                raise
        except Exception, e:
            return rc.BAD_REQUEST

        data = transaction.get(query=recipe_id, exact=True)
        if not data:
            return rc.NOT_HERE
        if User.objects.get(username__exact=api_key.username
                            ).username != data[0]['author']:
            return rc.BAD_REQUEST

        try:
            hbase_op.delete_row("Recipes", recipe_id)

        except Exception, e:
            return rc.NOT_HERE

        return rc.DELETED
예제 #12
0
def unsubscribe(username, table, uid):
    hbase_op.delete_row(table="Subscriptions", rowKey=username+"#"+table+"#"+uid)
    hbase_op.delete_column(table='Elements', rowKey=uid, column="subscriber:"+username)
예제 #13
0
          'http://roboearth.informatik.uni-stuttgart.de/api/0.1/recipe/<recipe_id>/<api_key>',
          Content-Type: application/json which contains:

          'api_key' : identifies the user

          'recipe_id' : the complete UID of the environment
      """

      try:
         api_key = api_keys.objects.get(key__exact=api_key)
         if not User.objects.get(username__exact=api_key.username).is_active:
            raise
      except Exception, e:
         return rc.BAD_REQUEST

      data = transaction.get(query=recipe_id, exact=True)
      if not data:
         return rc.NOT_HERE 
      if User.objects.get(username__exact=api_key.username).username != data[0]['author']:
         return rc.BAD_REQUEST

      try:
         hbase_op.delete_row("Recipes", recipe_id)

      except Exception, e:
         return rc.NOT_HERE

      return rc.DELETED


예제 #14
0
          object_id: the complete UID of the environment (deletes the complete data set)

          data: file identifier to delete only the corresponding file
      """

      try:
         api_key = api_keys.objects.get(key__exact=api_key)
         if not User.objects.get(username__exact=api_key.username).is_active:
            raise         
      except Exception, e:
         return rc.BAD_REQUEST


      object_ = transaction.get(query=object_id, format="json", exact=True)
      if not object_:
         return rc.NOT_HERE
      if User.objects.get(username__exact=api_key.username).username != object_[0]['author']:
         return rc.BAD_REQUEST

      try:
         if data:
            file_type = data
            hdfs_op.rm_file(object_[0]["files"][file_type]["url"].replace(roboearth.BINARY_ROOT, roboearth.UPLOAD_DIR))
            hbase_op.delete_column("Elements", object_id, 'file:'+file_type)
         else:
            hbase_op.delete_row("Elements", object_id)
      except Exception, e:
         return rc.NOT_HERE

      return rc.DELETED
예제 #15
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__())
예제 #16
0
                                  environment=environment,
                                  room_number=room_number)
         if result:
            return result
         else:
            return rc.DUPLICATE_ENTRY
         
      except Exception, e:
         return rc.NOT_HERE
      
   def delete(self, request, robot_id, api_key):
      try:
         api_key = api_keys.objects.get(key__exact=api_key)
         if not User.objects.get(username__exact=api_key.username).is_active:
            raise
      except Exception, e:
         return rc.BAD_REQUEST

      data = transaction.get(robot_id, exact=True)
      if not data:
         return rc.NOT_HERE
      if User.objects.get(username__exact=api_key.username).username != data[0]['author']:
         return rc.BAD_REQUEST

      try:
         hbase_op.delete_row("Robots", robot_id)
      except Exception, e:
         return rc.NOT_HERE

      return rc.DELETED
예제 #17
0
      
   def delete(self, request, env_id, api_key):
      """ handle DELETE request to
          'http://roboearth.informatik.uni-stuttgart.de/api/0.1/environment/<env_id>/<api_key>',
          Content-Type: application/json which contains:

          api_key: identifies the user

          env_id: the complete UID of the environment
      """

      try:
         api_key = api_keys.objects.get(key__exact=api_key)
         if not User.objects.get(username__exact=api_key.username).is_active:
            raise
      except Exception, e:
         return rc.BAD_REQUEST

      data = transaction.get(query=env_id, exact=True)
      if not data:
         return rc.NOT_HERE
      if User.objects.get(username__exact=api_key.username).username != data[0]['author']:
         return rc.BAD_REQUEST    

      try:
         hbase_op.delete_row("Environments", env_id)
      except Exception, e:
         return rc.NOT_HERE

      return rc.DELETED