Esempio n. 1
0
    def execute(self):
        logger.info('Checking if filespace is same as current filespace')

        try:
            if self.file_type == FileType.TRANSACTION_FILES:
                filename = GP_TRANSACTION_FILES_FILESPACE
            else:
                filename = GP_TEMPORARY_FILES_FILESPACE

            pg_system_filespace_entries = GetFilespaceEntries(
                self.gparray, PG_SYSTEM_FILESPACE).run()

            file_path = os.path.join(pg_system_filespace_entries[0][2],
                                     filename)

            if self.filespace_name == 'pg_system' and not CheckFile(
                    file_path).run():
                return True

            if CheckFile(file_path).run():
                with open(file_path) as file:
                    oid = int(file.readline().strip())
                    if self.gparray.getFileSpaceName(
                            oid) == self.filespace_name:
                        return True
        except Exception, e:
            raise MoveFilespaceError('Failed to check if filespace is same.')
Esempio n. 2
0
 def execute(self):
     if "HOME" not in os.environ or "GPHOME" not in os.environ:
         logger.warn(
             "Could not find mail_contacts file. Set $HOME and $GPHOME.")
         return
     mail_file = os.path.join(os.environ["GPHOME"], "bin", "mail_contacts")
     home_mail_file = os.path.join(os.environ["HOME"], "mail_contacts")
     contacts_file = None
     if CheckFile(home_mail_file).run():
         contacts_file = home_mail_file
     elif CheckFile(mail_file).run():
         contacts_file = mail_file
     else:
         logger.warn("Found neither %s nor %s" %
                     (mail_file, home_mail_file))
         logger.warn("Unable to send dump email notification")
         logger.info(
             "To enable email notification, create %s or %s containing required email addresses"
             % (mail_file, home_mail_file))
         return
     to_addrs = None
     with open(contacts_file, 'r') as f:
         to_addrs = [line.strip() for line in f]
     MailEvent(subject=self.subject,
               message=self.message,
               to_addrs=to_addrs).run()
Esempio n. 3
0
def impl(context):
    if "HOME" in os.environ:
        home_mail_file = os.path.join(os.environ["HOME"], "mail_contacts")
        if CheckFile(home_mail_file).run():
            os.remove(home_mail_file)
    if "GPHOME" in os.environ:
        mail_file = os.path.join(os.environ["GPHOME"], "bin", "mail_contacts")
        if CheckFile(mail_file).run():
            os.remove(mail_file)
Esempio n. 4
0
    def execute(self):
        path = os.path.join(self.master_datadir, DUMP_DIR, self.candidate_timestamp[0:8])
        createdb_file = os.path.join(path, "%s%s" % (CREATEDB_PREFIX, self.candidate_timestamp))
        if not CheckFile(createdb_file).run():
            raise ExceptionNoStackTraceNeeded("Dump file %s%s does not exist on Master" % (CREATEDB_PREFIX, self.candidate_timestamp))
        restore_db = GetDbName(createdb_file).run()

        compressed_file = os.path.join(path, "%s%s.gz" % (MASTER_DBDUMP_PREFIX, self.candidate_timestamp))
        compress = CheckFile(compressed_file).run()

        return (self.candidate_timestamp, restore_db, compress)
Esempio n. 5
0
 def check_install(self, gppkg_filename):
     cmd = "gppkg -q %s" % gppkg_filename
     results = run_command(cmd)
     results = results[1:]
     test_str = ''.join(gppkg_filename.split('-')[:1]) + " is installed"
     is_installed = test_str in results
     return is_installed and CheckFile(os.path.join(ARCHIVE_PATH, gppkg_filename)).run()
Esempio n. 6
0
    def execute(self):
        logger.info('Obtaining current filespace entries used by %s' %
                    FileType.lookup[self.file_type])
        filespace_entries = []
        default_filespace_entries = GetFilespaceEntries(
            self.gparray, PG_SYSTEM_FILESPACE).run()
        flat_files_dir = default_filespace_entries[0][2]
        flat_file = None

        if self.file_type == FileType.TRANSACTION_FILES:
            flat_file = GP_TRANSACTION_FILES_FILESPACE
        elif self.file_type == FileType.TEMPORARY_FILES:
            flat_file = GP_TEMPORARY_FILES_FILESPACE

        gp_filespace_path = os.path.join(flat_files_dir, flat_file)

        try:
            if CheckFile(gp_filespace_path).run():
                with open(gp_filespace_path) as file:
                    fs_oid = file.readline().strip()
                filespace_name = self.gparray.getFileSpaceName(int(fs_oid))
                filespace_entries = GetFilespaceEntries(
                    self.gparray, filespace_name).run()
        except TypeError, e:
            raise MoveFilespaceError('Invalid oid in flat file. %s' % str(e))
Esempio n. 7
0
 def _restore_global(self, restore_timestamp, master_datadir): 
     logger.info('Commencing restore of global objects')
     global_file = os.path.join(master_datadir, DUMP_DIR, restore_timestamp[0:8], "%s%s" % (GLOBAL_PREFIX, restore_timestamp))
     if not CheckFile(global_file).run():
         logger.warn('Unable to locate %s%s file in dump set' % (GLOBAL_PREFIX, restore_timestamp))
         return
     Psql('Invoking global dump', filename=global_file).run(validateAfter=True)
Esempio n. 8
0
    def execute(self):
        logger.info('flat file location = %s' % self.flat_file_location)
        if not CheckFile(self.flat_file_location).run():
            return -1

        with open(self.flat_file_location, 'r') as file:
            oid = file.readline().strip()
        return oid
Esempio n. 9
0
 def execute(self):
     for fake_time in range(0, 1000000):
         fake_timestamp = "%s%06d" % (self.restore_timestamp[0:8], fake_time)
         path = os.path.join(self.master_datadir, DUMP_DIR, fake_timestamp[0:8], "%s%s" % (MASTER_DBDUMP_PREFIX, fake_timestamp))
         if self.compress:
             path += '.gz'
         if not CheckFile(path).run():
             break
     else:   
         raise ExceptionNoStackTraceNeeded("Could not construct table dump")
     return fake_timestamp
Esempio n. 10
0
 def execute(self):
     # Ensure that status file exists
     if not CheckFile(self.status_file).run():
         logger.error('Could not locate status file: %s' % self.status_file)
         raise NoStatusFile()
     # Ensure that status file indicates successful dump
     with open(self.status_file, 'r') as f:
         for line in f:
             if line.find("Finished successfully") != -1:
                 break
         else:
             logger.error("Status report file indicates errors: %s" %
                          self.status_file)
             for line in f:
                 logger.info(line)
             logger.error("Status file contents dumped to log file")
             raise StatusFileError()
     # Ensure that dump file exists
     if not CheckFile(self.dump_file).run():
         logger.error("Could not locate dump file: %s" % self.dump_file)
         raise NoDumpFile()
Esempio n. 11
0
 def check_install(self, gppkg_filename):
     """
     Checks if a gppkg was installed successfully.
     
     @param gppkg_filename: The name of the gppkg file
     @type gppkg_filename: str
     @return: True if the gppkg was installed successfully
              False otherwise
     @rtype: bool
     """
     cmd = "gppkg -q %s" % gppkg_filename
     results = run_command(cmd)
     test_str = ''.join(gppkg_filename.split('-')[:1]) + " is installed" 
     is_installed = test_str in results 
     return is_installed and CheckFile(os.path.join(ARCHIVE_PATH, gppkg_filename)).run()
Esempio n. 12
0
    def execute(self):

        if not CheckDir(self.current_filespace_entry[2]).run():
            return

        tmp_file = os.path.join(self.new_filespace_entry[2], 'tmp_file')
        if not CheckFilespacePermissions(tmp_file).run():
            raise MoveFilespaceError('Invalid permissions for %s' % tmp_file)

        stats = os.statvfs(os.path.dirname(self.new_filespace_entry[2]))
        free_bytes = stats.f_bfree * stats.f_frsize
        logger.info('free_bytes for %s = %s' %
                    (self.new_filespace_entry[2], free_bytes))
        if not free_bytes:
            raise MoveFilespaceError('Insufficient diskspace for %s' %
                                     self.new_filespace_entry[2])

        # 1. Drop the directories from old filespace location
        # If the filespace is being moved from pg_system filespace
        # for temp files will be slightly different as they will be stored under
        # <filespace_dir>/base/<database_oid>/
        gp_temporary_files_filespace_path = os.path.join(
            self.pg_system_filespace_entry[2], GP_TEMPORARY_FILES_FILESPACE)

        if not CheckFile(gp_temporary_files_filespace_path).run():
            base_dir = os.path.join(self.current_filespace_entry[2], 'base')

            directories = []
            try:
                directories = ListFiles(base_dir).run()
            except Exception, e:
                if self.rollback:
                    pass
                else:
                    raise

            for directory in directories:
                try:
                    dst_dir = os.path.join(base_dir, directory,
                                           self.TEMPORARY_FILES_DIR)
                    if CheckDir(dst_dir).run():
                        logger.info('Dropping dir %s' % dst_dir)
                        shutil.rmtree(dst_dir)
                except (IOError, OSError), e:
                    logger.error('Failed to delete temporary files')
                    raise
Esempio n. 13
0
            src_dir = os.path.join(self.current_filespace_entry[2], directory)
            try:
                if CheckDir(src_dir).run():
                    logger.info('Dropping dir %s' % src_dir)
                    shutil.rmtree(src_dir)
            except (IOError, OSError), e:
                logger.error(
                    'Failed to drop transaction files directories from current filespace.'
                )
                raise

        gp_transaction_files_filespace_path = os.path.join(
            self.pg_system_filespace_entry[2], GP_TRANSACTION_FILES_FILESPACE)
        # If we are moving to default Filespace, then we need to delete the flat file
        if self.new_filespace_name == PG_SYSTEM_FILESPACE:
            if CheckFile(gp_transaction_files_filespace_path).run():
                os.remove(gp_transaction_files_filespace_path)
            return

        # 3. Write the dbid and directories into tmp directory
        temp_gp_transaction_files_filespace_path = gp_transaction_files_filespace_path + '.tmp'

        logger.info('Writing filespace information into flat file')
        with open(temp_gp_transaction_files_filespace_path, 'w') as file:
            lines_to_write = str(self.new_filespace_entry[0]) + '\n' + \
                             str(self.new_filespace_entry[1]) + ' ' + self.new_filespace_entry[2] + '\n'
            # In case of system without mirrors
            if self.peer_filespace_entry is not None:
                lines_to_write += str(
                    self.peer_filespace_entry[1]
                ) + ' ' + self.peer_filespace_entry[2] + '\n'