Beispiel #1
0
class Interface(object):

  def __init__(self, dataset_name, project_name, host_name=HOST_NAME):
    # self.resource_interface = ResourceInterface(dataset_name, project_name, host_name)
    self.cuboid_bucket = CuboidBucket(project_name)
    self.cuboidindex_db = CuboidIndexDB(project_name)

  # def deleteToken(self):
    # """Delete the Token"""
    # self.resource_interface.deleteToken()
    # print 'Delete successful for token {}'.format(self.token)

  def deleteProject(self):
    """Delete the project"""
    return NotImplemented 
    # delete the project from s3 and dynamo
    # self.s3_projdb.deleteNDProject()
    # deleting the meta-data via resource interface
    # self.resource_interface.deleteToken()
    # self.resource_interface.deleteProject()
    # print 'Delete successful for project {}'.format(self.project_name)
  
  
  def deleteChannel(self, channel_name):
    """Delete the channel"""
    
    try:
      for item in self.cuboidindex_db.queryChannelItems(channel_name):
        self.cuboid_bucket.deleteObject(item['supercuboid_key'])
        self.cuboidindex_db.deleteItem(item['supercuboid_key'])
    except Exception as e:
      print (e)
      
    # delete the channel from s3 and dynamo
    # self.s3_projdb.deleteNDChannel(channel_name)
    # deleting the meta-data via resource interface
    # self.resource_interface.deleteChannel(channel_name)
    # print 'Delete successful for channel {}'.format(channel_name)


  def deleteResolution(self, channel_name, resolution):
    """Delete an existing resolution"""
    
    try:
      for item in self.cuboidindex_db.queryResolutionItems(channel_name, resolution):
        print(item['supercuboid_key'])
        self.cuboid_bucket.deleteObject(item['supercuboid_key'])
        self.cuboidindex_db.deleteItem(item['supercuboid_key'])
    except Exception as e:
      print (e)
Beispiel #2
0
class S3ProjectDB:
    """Database for the projects"""
    def __init__(self, pr):
        """Create the database connection"""
        self.pr = pr
        # create connections for cuboid bucket and cuboid dyanmo table
        self.cuboid_bucket = CuboidBucket(
            self.pr.project_name, endpoint_url=ndingest_settings.S3_ENDPOINT)
        self.cuboidindex_db = CuboidIndexDB(
            self.pr.project_name,
            endpoint_url=ndingest_settings.DYNAMO_ENDPOINT)

    def __del__(self):
        """Close the database connection"""
        self.close()

    def close(self):
        """Close the database connection"""
        pass

    def newNDProject(self):
        """Create the database for a project."""
        pass

    def newNDChannel(self, channel_name):
        """Create the tables for a channel."""
        pass

    def deleteNDProject(self):
        """Delete a project in s3 and dyanmo"""

        try:
            for item in self.cuboidindex_db.queryProjectItems():
                self.cuboid_bucket.deleteObject(item['supercuboid_key'])
                self.cuboidindex_db.deleteItem(item['supercuboid_key'])
        except botocore.exceptions.ClientError as e:
            if e.response['Error']['Code'] == 'ResourceNotFoundException':
                logger.warning("Resource was not accessible {}".format(e))
                pass
            else:
                raise e
        except Exception as e:
            logger.error("Error in deleting S3 project {}. {}".format(
                self.pr.project_name, e))
            raise NDWSError("Error in deleting S3 project {}. {}".format(
                self.pr.project_name, e))

    def deleteNDChannel(self, channel_name):
        """Delete a channel in s3 and dynamo"""

        try:
            for item in self.cuboidindex_db.queryChannelItems(channel_name):
                self.cuboid_bucket.deleteObject(item['supercuboid_key'])
                self.cuboidindex_db.deleteItem(item['supercuboid_key'])
        except botocore.exceptions.ClientError as e:
            if e.response['Error']['Code'] == 'ResourceNotFoundException':
                logger.warning("Resource was not accessible {}".format(e))
                pass
            else:
                raise e
        except Exception as e:
            logger.error("Error in deleting S3 channel {}. {}".format(
                channel_name, e))
            raise NDWSError("Error in deleting S3 channel {}. {}".format(
                channel_name, e))

    def deleteNDResolution(self, channel_name, resolution):
        """Delete the resolution in s3 and dynamo"""

        try:
            for item in self.cuboidindex_db.queryResolutionItems(
                    channel_name, resolution):
                self.cuboid_bucket.deleteObject(item['supercuboid_key'])
                self.cuboidindex_db.deleteItem(item['supercuboid_key'])
        except botocore.exceptions.ClientError as e:
            if e.response['Error']['Code'] == 'ResourceNotFoundException':
                logger.warning("Resource was not accessible {}".format(e))
                pass
            else:
                raise e
        except Exception as e:
            logger.error(
                "Error in deleting S3 channel resolution {},{}. {}".format(
                    channel_name, resolution, e))
            raise NDWSError(
                "Error in deleting S3 channel resolution {},{}. {}".format(
                    channel_name, resolution, e))
Beispiel #3
0
class S3ProjectDB:
  """Database for the projects"""

  def __init__(self, pr):
    """Create the database connection"""
    self.pr = pr
    # create connections for cuboid bucket and cuboid dyanmo table
    self.cuboid_bucket = CuboidBucket(self.pr.project_name, endpoint_url=ndingest_settings.S3_ENDPOINT)
    self.cuboidindex_db = CuboidIndexDB(self.pr.project_name, endpoint_url=ndingest_settings.DYNAMO_ENDPOINT)

  def __del__(self):
    """Close the database connection"""
    self.close()

  def close (self):
    """Close the database connection"""
    pass


  def newNDProject(self):
    """Create the database for a project."""
    pass
  

  def newNDChannel(self, channel_name):
    """Create the tables for a channel."""
    pass


  def deleteNDProject(self):
    """Delete a project in s3 and dyanmo"""
    
    try:
      for item in self.cuboidindex_db.queryProjectItems():
        self.cuboid_bucket.deleteObject(item['supercuboid_key'])
        self.cuboidindex_db.deleteItem(item['supercuboid_key'])
    except botocore.exceptions.ClientError as e:
      if e.response['Error']['Code'] == 'ResourceNotFoundException':
        logger.warning("Resource was not accessible {}".format(e))
        pass
      else:
        raise e
    except Exception as e:
      logger.error("Error in deleting S3 project {}. {}".format(self.pr.project_name, e))
      raise NDWSError("Error in deleting S3 project {}. {}".format(self.pr.project_name, e))


  def deleteNDChannel(self, channel_name):
    """Delete a channel in s3 and dynamo"""
    
    try:
      for item in self.cuboidindex_db.queryChannelItems(channel_name):
        self.cuboid_bucket.deleteObject(item['supercuboid_key'])
        self.cuboidindex_db.deleteItem(item['supercuboid_key'])
    except botocore.exceptions.ClientError as e:
      if e.response['Error']['Code'] == 'ResourceNotFoundException':
        logger.warning("Resource was not accessible {}".format(e))
        pass
      else:
        raise e
    except Exception as e:
      logger.error("Error in deleting S3 channel {}. {}".format(channel_name, e))
      raise NDWSError("Error in deleting S3 channel {}. {}".format(channel_name, e))

  def deleteNDResolution(self, channel_name, resolution):
    """Delete the resolution in s3 and dynamo"""

    try:
      for item in self.cuboidindex_db.queryResolutionItems(channel_name, resolution):
        self.cuboid_bucket.deleteObject(item['supercuboid_key'])
        self.cuboidindex_db.deleteItem(item['supercuboid_key'])
    except botocore.exceptions.ClientError as e:
      if e.response['Error']['Code'] == 'ResourceNotFoundException':
        logger.warning("Resource was not accessible {}".format(e))
        pass
      else:
        raise e
    except Exception as e:
      logger.error("Error in deleting S3 channel resolution {},{}. {}".format(channel_name, resolution, e))
      raise NDWSError("Error in deleting S3 channel resolution {},{}. {}".format(channel_name, resolution, e))