示例#1
0
 def __init__(self, project_name):
     """Create the database connection"""
     self.pr = NDProject(project_name)
     # connect to Riak
     self.rcli = riak.RiakClient(host=self.pr.getKVServer(),
                                 pb_port=8087,
                                 protocol='pbc')
示例#2
0
  def __init__(self, project_name):
    """Create the database connection"""

    self.project_name = project_name
    self.pr = NDProject(project_name)
    server_address = ND_servermap[self.pr.getKVServer()]
    cluster = cassandra.Cluster([server_address])
    self.session = cluster.connect()
示例#3
0
 def __init__(self, ch):
   """Constructor for a channel. It is a project and then some."""
   from ndproject import NDProject
   self.ch = ch
   self.pr = NDProject.fromName(self.project_name)
   with closing (NDProjectsDB.getProjDB(self.pr)) as db:
     self.db = db
示例#4
0
    def __init__(self, project, channel):
        try:
            self.pr = Project.objects.get(project_name=project)
        except Project.DoesNotExist:
            raise

        self.ch = Channel.objects.get(channel_name=channel, project=self.pr)

        # pr and ch are django objects. proj and chan are NDStore objects
        self.proj = NDProject(self.pr.project_name)
        self.chan = NDChannel(self.proj, self.ch.channel_name)

        self.annodb = mysqlramondb.MySQLRamonDB(self.proj)
        self.ramondb = ramondb.RamonDB(self.proj)

        self.getAllAnnoIDs()
示例#5
0
class ConvertRamon:
    """ Converts an annotation project from the old RAMON format (spread across many tables) to the new RAMON format (consolidated in a single table) """
    def __init__(self, project, channel):
        try:
            self.pr = Project.objects.get(project_name=project)
        except Project.DoesNotExist:
            raise

        self.ch = Channel.objects.get(channel_name=channel, project=self.pr)

        # pr and ch are django objects. proj and chan are NDStore objects
        self.proj = NDProject(self.pr.project_name)
        self.chan = NDChannel(self.proj, self.ch.channel_name)

        self.annodb = mysqlramondb.MySQLRamonDB(self.proj)
        self.ramondb = ramondb.RamonDB(self.proj)

        self.getAllAnnoIDs()

    def createRAMONTables(self):

        with closing(
                MySQLdb.connect(
                    host=self.proj.getDBHost(),
                    user=settings.DATABASES['default']['USER'],
                    passwd=settings.DATABASES['default']['PASSWORD'],
                    db=self.proj.getDBName(),
                    connect_timeout=1)) as conn:
            with closing(conn.cursor()) as cursor:

                try:

                    ramonTableName = '{}_ramon'.format(self.ch.channel_name)

                    cursor.execute(
                        "CREATE TABLE {} ( annoid BIGINT, kv_key VARCHAR(255), kv_value VARCHAR(20000), INDEX ( annoid, kv_key ) USING BTREE)"
                        .format(ramonTableName))

                    # Commiting at the end
                    conn.commit()

                except MySQLdb.Error, e:
                    print "Error: Failed to create new RAMON table: {}".format(
                        e)
                    sys.exit(1)
示例#6
0
class CassProjectDB:
  """Database for the projects"""

  def __init__(self, project_name):
    """Create the database connection"""

    self.project_name = project_name
    self.pr = NDProject(project_name)
    server_address = ND_servermap[self.pr.getKVServer()]
    cluster = cassandra.Cluster([server_address])
    self.session = cluster.connect()

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

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

  
  def newNDProject(self, project_name):
    """Create the database for a project"""
      
    try:
      if self.server_address == 'localhost':  
        self.session.execute ("CREATE KEYSPACE {} WITH REPLICATION = {{ 'class' : 'SimpleStrategy', 'replication_factor' : 0 }}".format(self.pr.getProjectName()), timeout=30)
      else:
        self.session.execute ("CREATE KEYSPACE {} WITH REPLICATION = {{ 'class' : 'SimpleStrategy', 'replication_factor' : 1 }}".format(self.pr.getProjectName()), timeout=30)
    
    except Exception, e:
      self.pr.deleteProject()
      logger.error("Failed to create namespace for new project {}".format(self.project_name))
      raise NDWSError("Failed to create namespace for new project {}".format(self.project_name))
    
    finally:
示例#7
0
    def __init__(self, project, channel):
        try:
            self.pr = Project.objects.get( project_name = project )
        except Project.DoesNotExist:
            raise

        self.ch = Channel.objects.get( channel_name = channel, project = self.pr )

        # pr and ch are django objects. proj and chan are NDStore objects
        self.proj = NDProject(self.pr.project_name)
        self.chan = NDChannel(self.proj, self.ch.channel_name)

        self.annodb = mysqlramondb.MySQLRamonDB(self.proj)
        self.ramondb = ramondb.RamonDB(self.proj)

        self.getAllAnnoIDs()
示例#8
0
class RiakProjDB:
    def __init__(self, project_name):
        """Create the database connection"""
        self.pr = NDProject(project_name)
        # connect to Riak
        self.rcli = riak.RiakClient(host=self.pr.getKVServer(),
                                    pb_port=8087,
                                    protocol='pbc')

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

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

        ch = NDChannel.fromName(self.pr, channel_name)
        pass
        # TODO KL figure out new schema for Riak
        # bucket = rcli.bucket_type("nd{}".format(proj.getProjectType())).bucket(proj.getDBName())
        # bucket.set_property('allow_mult',False)

    def deleteNDProject(self, project_name):
        """Delete the database for a project"""

        pass
        # TODO KL figure out the new schema
        # bucket = rcli.bucket_type("nd{}".format(proj.getProjectType())).bucket(proj.getDBName())

        # key_list = rcli.get_keys(bucket)

        # for key_name in key_list:
        # bucket.delete(key_name)

    def deleteNDChannel(self, project_name, channel_name):
        """Delete the tables for a channel"""

        ch = NDChannel.fromName(self.pr, channel_name)
        # table_list = []
        # TODO KL
        pass
示例#9
0
class ConvertRamon:
    """ Converts an annotation project from the old RAMON format (spread across many tables) to the new RAMON format (consolidated in a single table) """

    def __init__(self, project, channel):
        try:
            self.pr = Project.objects.get( project_name = project )
        except Project.DoesNotExist:
            raise

        self.ch = Channel.objects.get( channel_name = channel, project = self.pr )

        # pr and ch are django objects. proj and chan are NDStore objects
        self.proj = NDProject(self.pr.project_name)
        self.chan = NDChannel(self.proj, self.ch.channel_name)

        self.annodb = mysqlramondb.MySQLRamonDB(self.proj)
        self.ramondb = ramondb.RamonDB(self.proj)

        self.getAllAnnoIDs()

    def createRAMONTables(self):

        with closing(MySQLdb.connect(host = self.proj.getDBHost(), user = settings.DATABASES['default']['USER'], passwd = settings.DATABASES['default']['PASSWORD'], db = self.proj.getDBName(), connect_timeout=1)) as conn:
            with closing(conn.cursor()) as cursor:

                try:

                    ramonTableName = '{}_ramon'.format(self.ch.channel_name)

                    cursor.execute("CREATE TABLE {} ( annoid BIGINT, kv_key VARCHAR(255), kv_value VARCHAR(20000), INDEX ( annoid, kv_key ) USING BTREE)".format(ramonTableName))

                    # Commiting at the end
                    conn.commit()

                except MySQLdb.Error, e:
                    print "Error: Failed to create new RAMON table: {}".format(e)
                    sys.exit(1)
示例#10
0
 def __init__(self, project_name):
   """Create the database connection"""
   self.pr = NDProject(project_name)
   self.dynamodb = boto3.resource('dynamodb')
示例#11
0
 def loadToken(token_name):
   """Query django configuration for a token to bind to a project"""
   from ndproject import NDProject
   return NDProject.fromTokenName(token_name)
示例#12
0
 def loadToken(token_name):
     """Query django configuration for a token to bind to a project"""
     from ndproject import NDProject
     return NDProject.fromTokenName(token_name)