def run(self):
    """ Starts the main loop of the restore thread. """
    datastore_batch = appscale_datastore_batch.\
      DatastoreFactory.getDatastore(self.table)
    transaction_manager = TransactionManager(self.zoo_keeper.handle)
    self.ds_distributed = DatastoreDistributed(
      datastore_batch, transaction_manager, zookeeper=self.zoo_keeper)
    self.dynamic_put_sync = tornado_synchronous(
      self.ds_distributed.dynamic_put)

    while True:
      logging.debug("Trying to get restore lock.")
      if self.get_restore_lock():
        logging.info("Got the restore lock.")
        self.run_restore()
        try:
          self.zoo_keeper.release_lock_with_path(zk.DS_RESTORE_LOCK_PATH)
        except zk.ZKTransactionException, zk_exception:
          logging.error("Unable to release zk lock {0}.".\
            format(str(zk_exception)))
        break
      else:
        logging.info("Did not get the restore lock. Another instance may be "
          "running.")
        time.sleep(random.randint(1, self.LOCK_POLL_PERIOD))
Example #2
0
def main():
    """ Updates a composite index after prompting the user. """
    parser = argparse.ArgumentParser(description='Updates composite indexes')
    parser.add_argument('--type',
                        '-t',
                        default='cassandra',
                        help='The datastore backend type')
    parser.add_argument('--app_id', '-a', required=True, help='The project ID')
    parser.add_argument('--all',
                        action='store_true',
                        help='Updates all composite indexes')
    args = parser.parse_args()

    datastore_batch = appscale_datastore_batch.DatastoreFactory.\
      getDatastore(args.type)
    zookeeper_locations = appscale_info.get_zk_locations_string()
    zookeeper = zk.ZKTransaction(host=zookeeper_locations)
    transaction_manager = TransactionManager(zookeeper.handle)
    datastore_access = DatastoreDistributed(datastore_batch,
                                            transaction_manager,
                                            zookeeper=zookeeper)
    index_manager = IndexManager(zookeeper.handle, datastore_access)
    datastore_access.index_manager = index_manager

    indices = index_manager.projects[args.app_id].indexes_pb
    if len(indices) == 0:
        print('No composite indices found for app {}'.format(args.app_id))
        zookeeper.close()
        return

    update_composite_index_sync = tornado_synchronous(
        datastore_access.update_composite_index)

    if args.all:
        for index in indices:
            update_composite_index_sync(args.app_id, index)
        print('Successfully updated all composite indexes')
        return

    selection = -1
    selection_range = range(1, len(indices) + 1)
    while selection not in selection_range:
        for number, index in enumerate(indices, start=1):
            pretty_index = prettify_index(index.definition())
            print('{}) {}'.format(number, pretty_index))

        try:
            selection = int(
                raw_input(
                    'Select the index you want to update. (1-{}) '.format(
                        len(indices))))
        except KeyboardInterrupt:
            zookeeper.close()
            sys.exit()

    selected_index = indices[selection - 1]
    update_composite_index_sync(args.app_id, selected_index)

    zookeeper.close()
    print('Index successfully updated')
Example #3
0
def main():
  """ Updates a composite index after prompting the user. """
  parser = argparse.ArgumentParser(description='Updates composite indexes')
  parser.add_argument('--type', '-t', default='cassandra',
                      help='The datastore backend type')
  parser.add_argument('--app_id', '-a', required=True, help='The project ID')
  parser.add_argument('--all', action='store_true',
                      help='Updates all composite indexes')
  args = parser.parse_args()

  datastore_batch = appscale_datastore_batch.DatastoreFactory.\
    getDatastore(args.type)
  zookeeper_locations = appscale_info.get_zk_locations_string()
  zookeeper = zk.ZKTransaction(host=zookeeper_locations)
  transaction_manager = TransactionManager(zookeeper.handle)
  datastore_access = DatastoreDistributed(
    datastore_batch, transaction_manager, zookeeper=zookeeper)
  index_manager = IndexManager(zookeeper.handle, datastore_access)
  datastore_access.index_manager = index_manager

  indices = index_manager.projects[args.app_id].indexes_pb
  if len(indices) == 0:
    print('No composite indices found for app {}'.format(args.app_id))
    zookeeper.close()
    return

  update_composite_index_sync = tornado_synchronous(
    datastore_access.update_composite_index)

  if args.all:
    for index in indices:
      update_composite_index_sync(args.app_id, index)
    print('Successfully updated all composite indexes')
    return

  selection = -1
  selection_range = range(1, len(indices) + 1)
  while selection not in selection_range:
    for number, index in enumerate(indices, start=1):
      pretty_index = prettify_index(index.definition())
      print('{}) {}'.format(number, pretty_index))

    try:
      selection = int(raw_input('Select the index you want to update. (1-{}) '
        .format(len(indices))))
    except KeyboardInterrupt:
      zookeeper.close()
      sys.exit()

  selected_index = indices[selection - 1]
  update_composite_index_sync(args.app_id, selected_index)

  zookeeper.close()
  print('Index successfully updated')
    def __init__(self, log_level=logging.INFO, hosts=None):
        """
    Constructor.
    """
        class_name = self.__class__.__name__
        self.logger = logging.getLogger(class_name)
        self.logger.setLevel(log_level)
        self.logger.info('Starting {}'.format(class_name))

        if hosts is not None:
            self.hosts = hosts
        else:
            self.hosts = appscale_info.get_db_ips()

        remaining_retries = INITIAL_CONNECT_RETRIES
        while True:
            try:
                self.cluster = Cluster(self.hosts,
                                       default_retry_policy=BASIC_RETRIES,
                                       load_balancing_policy=LB_POLICY)
                self.session = self.cluster.connect(KEYSPACE)
                self.tornado_cassandra = TornadoCassandra(self.session)
                break
            except cassandra.cluster.NoHostAvailable as connection_error:
                remaining_retries -= 1
                if remaining_retries < 0:
                    raise connection_error
                time.sleep(3)

        self.session.default_consistency_level = ConsistencyLevel.QUORUM
        self.prepared_statements = {}

        # Provide synchronous version of some async methods
        self.batch_get_entity_sync = tornado_synchronous(self.batch_get_entity)
        self.batch_put_entity_sync = tornado_synchronous(self.batch_put_entity)
        self.batch_delete_sync = tornado_synchronous(self.batch_delete)
        self.valid_data_version_sync = tornado_synchronous(
            self.valid_data_version)
        self.range_query_sync = tornado_synchronous(self.range_query)
        self.get_metadata_sync = tornado_synchronous(self.get_metadata)
        self.set_metadata_sync = tornado_synchronous(self.set_metadata)
        self.get_indices_sync = tornado_synchronous(self.get_indices)
        self.delete_table_sync = tornado_synchronous(self.delete_table)
  def __init__(self, log_level=logging.INFO, hosts=None):
    """
    Constructor.
    """
    class_name = self.__class__.__name__
    self.logger = logging.getLogger(class_name)
    self.logger.setLevel(log_level)
    self.logger.info('Starting {}'.format(class_name))

    if hosts is not None:
      self.hosts = hosts
    else:
      self.hosts = appscale_info.get_db_ips()

    remaining_retries = INITIAL_CONNECT_RETRIES
    while True:
      try:
        self.cluster = Cluster(self.hosts, default_retry_policy=BASIC_RETRIES,
                               load_balancing_policy=LB_POLICY)
        self.session = self.cluster.connect(KEYSPACE)
        self.tornado_cassandra = TornadoCassandra(self.session)
        break
      except cassandra.cluster.NoHostAvailable as connection_error:
        remaining_retries -= 1
        if remaining_retries < 0:
          raise connection_error
        time.sleep(3)

    self.session.default_consistency_level = ConsistencyLevel.QUORUM
    self.prepared_statements = {}

    # Provide synchronous version of some async methods
    self.batch_get_entity_sync = tornado_synchronous(self.batch_get_entity)
    self.batch_put_entity_sync = tornado_synchronous(self.batch_put_entity)
    self.batch_delete_sync = tornado_synchronous(self.batch_delete)
    self.valid_data_version_sync = tornado_synchronous(self.valid_data_version)
    self.range_query_sync = tornado_synchronous(self.range_query)
    self.get_metadata_sync = tornado_synchronous(self.get_metadata)
    self.set_metadata_sync = tornado_synchronous(self.set_metadata)
    self.get_indices_sync = tornado_synchronous(self.get_indices)
    self.delete_table_sync = tornado_synchronous(self.delete_table)
Example #6
0
    def __init__(self):
        hosts = appscale_info.get_db_ips()

        remaining_retries = INITIAL_CONNECT_RETRIES
        while True:
            try:
                cluster = Cluster(hosts, load_balancing_policy=LB_POLICY)
                self.session = cluster.connect(keyspace=KEYSPACE)
                self.tornado_cassandra = TornadoCassandra(self.session)
                break
            except cassandra.cluster.NoHostAvailable as connection_error:
                remaining_retries -= 1
                if remaining_retries < 0:
                    raise connection_error
                time.sleep(3)

        self.session.default_consistency_level = ConsistencyLevel.QUORUM

        # Provide synchronous version of get_schema method
        self.get_schema_sync = tornado_synchronous(self.get_schema)
Example #7
0
  def __init__(self):
    hosts = appscale_info.get_db_ips()

    remaining_retries = INITIAL_CONNECT_RETRIES
    while True:
      try:
        cluster = Cluster(hosts, load_balancing_policy=LB_POLICY)
        self.session = cluster.connect(keyspace=KEYSPACE)
        self.tornado_cassandra = TornadoCassandra(self.session)
        break
      except cassandra.cluster.NoHostAvailable as connection_error:
        remaining_retries -= 1
        if remaining_retries < 0:
          raise connection_error
        time.sleep(3)

    self.session.default_consistency_level = ConsistencyLevel.QUORUM

    # Provide synchronous version of get_schema method
    self.get_schema_sync = tornado_synchronous(self.get_schema)