示例#1
0
  def test_stop(self):
    YAML_INFO="""--- 
:keyname: appscale
:replication: "1"
:table: cassandra
"""
    flexmock(file_io).should_receive('read').and_return(YAML_INFO)
    self.assertEqual('cassandra', appscale_info.get_db_info()[':table'])
    self.assertEqual( '1', appscale_info.get_db_info()[':replication'])
    self.assertEqual( 'appscale', appscale_info.get_db_info()[':keyname'])
    self.assertEqual(True, isinstance(appscale_info.get_db_info(), dict))
示例#2
0
    def test_stop(self):
        YAML_INFO = """--- 
:keyname: appscale
:replication: "1"
:table: cassandra
"""
        flexmock(file_io).should_receive('read').and_return(YAML_INFO)
        self.assertEqual('cassandra', appscale_info.get_db_info()[':table'])
        self.assertEqual('1', appscale_info.get_db_info()[':replication'])
        self.assertEqual('appscale', appscale_info.get_db_info()[':keyname'])
        self.assertEqual(True, isinstance(appscale_info.get_db_info(), dict))
示例#3
0
def main():
  """ This main function allows you to run the backup manually. """

  parser = init_parser()
  args = parser.parse_args()

  # Set up logging.
  level = logging.INFO
  if args.debug:
    level = logging.DEBUG
  logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:' \
    '%(lineno)s %(message)s ', level=level)
  logging.info("Logging started")

  message = "Backing up "
  if args.source_code:
    message += "source and "
  message += "data for: {0}".format(args.app_id)
  logging.info(message)

  zk_connection_locations = appscale_info.get_zk_locations_string()
  zookeeper = zk.ZKTransaction(host=zk_connection_locations)
  db_info = appscale_info.get_db_info()
  table = db_info[':table']

  skip_list = args.skip
  if not skip_list:
    skip_list = []
  logging.info("Will skip the following kinds: {0}".format(sorted(skip_list)))
  ds_backup = DatastoreBackup(args.app_id, zookeeper, table,
    source_code=args.source_code, skip_list=sorted(skip_list))
  try:
    ds_backup.run()
  finally:
    zookeeper.close()
示例#4
0
def main():
    """ This main function allows you to run the restore manually. """

    # Parse CLI arguments.
    parser = init_parser()
    args = parser.parse_args()

    # Set up logging.
    level = logging.INFO
    if args.debug:
        level = logging.DEBUG
    logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:' \
      '%(lineno)s %(message)s ', level=level)
    logger.info("Logging started")

    logger.info(args)

    zk_connection_locations = appscale_info.get_zk_locations_string()
    zookeeper = zk.ZKTransaction(host=zk_connection_locations)

    # Verify app is deployed.
    if not app_is_deployed(args.app_id, zookeeper.handle):
        return

    # Verify backup dir exists.
    if not backup_dir_exists(args.backup_dir):
        return

    if args.clear_datastore:
        message = "Deleting \"{0}\" data...".\
          format(args.app_id, args.backup_dir)
        logger.info(message)
        try:
            tables_to_clear = {
                APP_ENTITY_TABLE: APP_ENTITY_SCHEMA,
                ASC_PROPERTY_TABLE: PROPERTY_SCHEMA,
                DSC_PROPERTY_TABLE: PROPERTY_SCHEMA,
                COMPOSITE_TABLE: COMPOSITE_SCHEMA,
                APP_KIND_TABLE: APP_KIND_SCHEMA
            }
            for table, schema in tables_to_clear.items():
                fetch_and_delete_entities('cassandra', table, schema,
                                          args.app_id, False)
        except Exception as exception:
            logger.error("Unhandled exception while deleting \"{0}\" data: {1} " \
              "Exiting...".format(args.app_id, exception.message))
            return

    # Initialize connection to Zookeeper and database related variables.
    db_info = appscale_info.get_db_info()
    table = db_info[':table']

    # Start restore process.
    ds_restore = DatastoreRestore(args.app_id.strip('/'), args.backup_dir,
                                  zookeeper, table)
    try:
        ds_restore.run()
    finally:
        zookeeper.close()
示例#5
0
def main():
  """ This main function allows you to run the restore manually. """

  # Parse CLI arguments.
  parser = init_parser()
  args = parser.parse_args()

  # Set up logging.
  level = logging.INFO
  if args.debug:
    level = logging.DEBUG
  logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:' \
    '%(lineno)s %(message)s ', level=level)
  logger.info("Logging started")

  logger.info(args)

  zk_connection_locations = appscale_info.get_zk_locations_string()
  zookeeper = zk.ZKTransaction(host=zk_connection_locations)

  # Verify app is deployed.
  if not app_is_deployed(args.app_id, zookeeper.handle):
    return

  # Verify backup dir exists.
  if not backup_dir_exists(args.backup_dir):
    return

  if args.clear_datastore:
    message = "Deleting \"{0}\" data...".\
      format(args.app_id, args.backup_dir)
    logger.info(message)
    try:
      tables_to_clear = {
        APP_ENTITY_TABLE: APP_ENTITY_SCHEMA,
        ASC_PROPERTY_TABLE: PROPERTY_SCHEMA,
        DSC_PROPERTY_TABLE: PROPERTY_SCHEMA,
        COMPOSITE_TABLE: COMPOSITE_SCHEMA,
        APP_KIND_TABLE: APP_KIND_SCHEMA
      }
      for table, schema in tables_to_clear.items():
        fetch_and_delete_entities('cassandra', table, schema, args.app_id, False)
    except Exception as exception:
      logger.error("Unhandled exception while deleting \"{0}\" data: {1} " \
        "Exiting...".format(args.app_id, exception.message))
      return

  # Initialize connection to Zookeeper and database related variables.
  db_info = appscale_info.get_db_info()
  table = db_info[':table']

  # Start restore process.
  ds_restore = DatastoreRestore(args.app_id.strip('/'), args.backup_dir,
    zookeeper, table)
  try:
    ds_restore.run()
  finally:
    zookeeper.close()
示例#6
0
def get_datastore():
    """ Returns a reference to the batch datastore interface. Validates where
  the <database>_interface.py is and adds that path to the system path.
  """
    db_info = appscale_info.get_db_info()
    db_type = db_info[':table']
    datastore_batch = appscale_datastore_batch.DatastoreFactory.getDatastore(
        db_type)
    return datastore_batch
示例#7
0
  def test_get_db_info(self, read_mock):
    read_mock.return_value = '''---
:keyname: appscale
:replication: '1'
:table: cassandra
'''
    db_info = appscale_info.get_db_info()
    self.assertIsInstance(db_info, dict)
    self.assertEqual(db_info[':table'], 'cassandra')
    self.assertEqual(db_info[':replication'], '1')
    self.assertEqual(db_info[':keyname'], 'appscale')
    read_mock.assert_called_once_with('/etc/appscale/database_info.yaml')
示例#8
0
    def test_get_db_info(self, read_mock):
        read_mock.return_value = '''---
:keyname: appscale
:replication: '1'
:table: cassandra
'''
        db_info = appscale_info.get_db_info()
        self.assertIsInstance(db_info, dict)
        self.assertEqual(db_info[':table'], 'cassandra')
        self.assertEqual(db_info[':replication'], '1')
        self.assertEqual(db_info[':keyname'], 'appscale')
        read_mock.assert_called_once_with('/etc/appscale/database_info.yaml')
示例#9
0
def main():
    """ This main function allows you to run the backup manually. """

    parser = init_parser()
    args = parser.parse_args()

    # Set up logging.
    level = logging.INFO
    if args.debug:
        level = logging.DEBUG
    logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:' \
      '%(lineno)s %(message)s ', level=level)
    logging.info("Logging started")

    message = "Backing up "
    if args.source_code:
        message += "source and "
    message += "data for: {0}".format(args.app_id)
    logging.info(message)

    zk_connection_locations = appscale_info.get_zk_locations_string()
    zookeeper = zk.ZKTransaction(host=zk_connection_locations)
    db_info = appscale_info.get_db_info()
    table = db_info[':table']

    skip_list = args.skip
    if not skip_list:
        skip_list = []
    logging.info("Will skip the following kinds: {0}".format(
        sorted(skip_list)))
    ds_backup = DatastoreBackup(args.app_id,
                                zookeeper,
                                table,
                                source_code=args.source_code,
                                skip_list=sorted(skip_list))
    try:
        ds_backup.run()
    finally:
        zookeeper.close()