Exemplo n.º 1
0
    def stat(self, path):
        """
            Returns the stats of a file.

            :param path: path to file

            :raises ServiceUnavailable: if some generic error occured in the library.

            :returns: a dict with two keys, filesize and adler32 of the file provided in path.
        """
        ret = {}
        ctx = self.__ctx

        try:
            stat_str = str(ctx.stat(str(path)))
        except Exception as error:
            msg = 'Error while processing gfal stat call. Error: %s'
            raise exception.ServiceUnavailable(msg % str(error))

        stats = stat_str.split()
        if len(stats) < 8:
            msg = 'gfal stat call result has unknown format. Result: %s'
            raise exception.ServiceUnavailable(msg % stat_str)

        ret['filesize'] = stat_str.split()[7]

        try:
            ret['adler32'] = ctx.checksum(str(path), str('ADLER32'))
        except Exception as error:
            msg = 'Error while processing gfal checksum call. Error: %s'
            raise exception.RSEChecksumUnavailable(msg % str(error))

        return ret
Exemplo n.º 2
0
    def stat(self, path):
        """
            Returns the stats of a file.

            :param path: path to file

            :raises ServiceUnavailable: if some generic error occured in the library.

            :returns: a dict with two keys, filesize and an element of GLOBALLY_SUPPORTED_CHECKSUMS.
        """
        self.logger(logging.DEBUG, 'getting stats of file {}'.format(path))

        ret = {}
        ctx = self.__ctx

        path = str(path)

        try:
            stat_str = str(ctx.stat(path))
        except Exception as error:
            msg = 'Error while processing gfal stat call. Error: %s'
            raise exception.ServiceUnavailable(msg % str(error))

        stats = stat_str.split()
        if len(stats) < 8:
            msg = 'gfal stat call result has unknown format. Result: %s'
            raise exception.ServiceUnavailable(msg % stat_str)

        ret['filesize'] = stats[7]

        message = "\n"
        try:
            ret[PREFERRED_CHECKSUM] = ctx.checksum(
                path, str(PREFERRED_CHECKSUM.upper()))
            return ret
        except Exception as error:
            message += 'Error while processing gfal checksum call (%s). Error: %s \n' % (
                PREFERRED_CHECKSUM, str(error))

        for checksum_name in GLOBALLY_SUPPORTED_CHECKSUMS:
            if checksum_name == PREFERRED_CHECKSUM:
                continue
            try:
                ret[checksum_name] = ctx.checksum(path,
                                                  str(checksum_name.upper()))
                return ret
            except Exception as error:
                message += 'Error while processing gfal checksum call (%s). Error: %s \n' % (
                    checksum_name, str(error))

        raise exception.RSEChecksumUnavailable(message)
Exemplo n.º 3
0
    def stat(self, path):
        """
        Returns the stats of a file.

        :param path: path to file

        :raises ServiceUnavailable: if some generic error occured in the library.

        :returns: a dict with two keys, filesize and an element of GLOBALLY_SUPPORTED_CHECKSUMS.
        """
        self.logger(logging.DEBUG, 'xrootd.stat: path: {}'.format(path))
        ret = {}
        chsum = None
        if path.startswith('root:'):
            path = self.pfn2path(path)

        try:
            # xrdfs stat for getting filesize
            cmd = 'XrdSecPROTOCOL=gsi xrdfs %s:%s stat %s' % (self.hostname,
                                                              self.port, path)
            self.logger(logging.INFO,
                        'xrootd.stat: filesize cmd: {}'.format(cmd))
            status_stat, out, err = execute(cmd)
            if status_stat == 0:
                ret['filesize'] = out.split(b'\n')[2].split()[-1].decode()

            # xrdfs query checksum for getting checksum
            cmd = 'XrdSecPROTOCOL=gsi xrdfs %s:%s query checksum %s' % (
                self.hostname, self.port, path)
            self.logger(logging.INFO,
                        'xrootd.stat: checksum cmd: {}'.format(cmd))
            status_query, out, err = execute(cmd)
            if status_query == 0:
                chsum, value = out.strip(b'\n').split()
                chsum = chsum.decode()
                value = value.decode()
                ret[chsum] = value

        except Exception as e:
            raise exception.ServiceUnavailable(e)

        if 'filesize' not in ret:
            raise exception.ServiceUnavailable(
                'Filesize could not be retrieved.')
        if PREFERRED_CHECKSUM != chsum or not chsum:
            msg = '{} does not match with {}'.format(chsum, PREFERRED_CHECKSUM)
            raise exception.RSEChecksumUnavailable(msg)

        return ret
Exemplo n.º 4
0
    def stat(self, path):
        """
        Returns the stats of a file.

        :param path: path to file

        :raises ServiceUnavailable: if some generic error occured in the library.

        :returns: a dict with two keys, filesize and an element of GLOBALLY_SUPPORTED_CHECKSUMS.
        """
        self.logger(logging.DEBUG, 'rsync.stat: path: {}'.format(path))
        ret = {}
        chsum = None
        path = self.pfn2path(path)

        try:
            # rsync stat for getting filesize
            cmd = "rsync -an --size-only -e 'ssh -p {0}' --remove-source-files  {1}{2}:{3}".format(
                self.port, self.sshuser, self.hostname, path)
            self.logger(logging.DEBUG,
                        'rsync.stat: filesize cmd: {}'.format(cmd))
            status_stat, out, err = execute(cmd)
            if status_stat == 0:
                sizestr = out.split(" ")[-4]
                ret['filesize'] = sizestr.replace(',', '')

            # rsync query checksum for getting md5 checksum
            cmd = 'ssh -p %s %s%s md5sum %s' % (self.port, self.sshuser,
                                                self.hostname, path)
            self.logger(logging.DEBUG,
                        'rsync.stat: checksum cmd: {}'.format(cmd))
            status_query, out, err = execute(cmd)

            if status_query == 0:
                chsum = 'md5'
                val = out.strip('  ').split()
                ret[chsum] = val[0]

        except Exception as e:
            raise exception.ServiceUnavailable(e)

        if 'filesize' not in ret:
            raise exception.ServiceUnavailable(
                'Filesize could not be retrieved.')
        if PREFERRED_CHECKSUM != chsum or not chsum:
            msg = '{} does not match with {}'.format(chsum, PREFERRED_CHECKSUM)
            raise exception.RSEChecksumUnavailable(msg)

        return ret
Exemplo n.º 5
0
    def stat(self, path):
        """
        Returns the stats of a file.

        :param path: path to file

        :raises ServiceUnavailable: if some generic error occured in the library.

        :returns: a dict with two keys, filesize and an element of GLOBALLY_SUPPORTED_CHECKSUMS.
        """
        self.logger(logging.DEBUG, 'rclone.stat: path: {}'.format(path))
        ret = {}
        chsum = None
        if path.startswith('rclone://'):
            path = self.pfn2path(path)

        try:
            # rclone stat for getting filesize
            cmd = 'rclone size {0}:{1}'.format(self.hostname, path)
            self.logger(logging.DEBUG,
                        'rclone.stat: filesize cmd: {}'.format(cmd))
            status_stat, out, err = execute(cmd)
            if status_stat == 0:
                fsize = (out.split('\n')[1]).split(' ')[4][1:]
                ret['filesize'] = fsize

            # rclone query checksum for getting md5 checksum
            cmd = 'rclone md5sum %s:%s' % (self.hostname, path)
            self.logger(logging.DEBUG,
                        'rclone.stat: checksum cmd: {}'.format(cmd))
            status_query, out, err = execute(cmd)

            if status_query == 0:
                chsum = 'md5'
                val = out.strip('  ').split()
                ret[chsum] = val[0]

        except Exception as e:
            raise exception.ServiceUnavailable(e)

        if 'filesize' not in ret:
            raise exception.ServiceUnavailable(
                'Filesize could not be retrieved.')
        if PREFERRED_CHECKSUM != chsum or not chsum:
            msg = '{} does not match with {}'.format(chsum, PREFERRED_CHECKSUM)
            raise exception.RSEChecksumUnavailable(msg)

        return ret
Exemplo n.º 6
0
Arquivo: gfal.py Projeto: yhshin/rucio
    def stat(self, path):
        """
            Returns the stats of a file.

            :param path: path to file

            :raises ServiceUnavailable: if some generic error occured in the library.

            :returns: a dict with two keys, filesize and adler32 of the file provided in path.
        """
        ret = {}
        ctx = self.__ctx

        try:
            stat_str = str(ctx.stat(str(path)))
        except Exception as error:
            msg = 'Error while processing gfal stat call. Error: %s'
            raise exception.ServiceUnavailable(msg % str(error))

        stats = stat_str.split()
        if len(stats) < 8:
            msg = 'gfal stat call result has unknown format. Result: %s'
            raise exception.ServiceUnavailable(msg % stat_str)

        ret['filesize'] = stat_str.split()[7]

        verified = False
        message = "\n"

        for checksum_name in GLOBALLY_SUPPORTED_CHECKSUMS:
            try:
                ret[checksum_name] = ctx.checksum(
                    str(path), str(checksum_name.capitalize()))
                verified = True
            except Exception as error:
                message += 'Error while processing gfal checksum call (%s). Error: %s \n' % (
                    checksum_name, str(error))

        if not verified:
            raise exception.RSEChecksumUnavailable(message)

        return ret