예제 #1
0
class FileCatalogProxyClient(object):
    """File catalog client for the File Catalog proxy service"""
    def __init__(self, fcName, **kwargs):
        """Constructor of the LCGFileCatalogProxy client class"""
        self.method = None
        self.fcName = fcName
        self.rpc = Client(url="DataManagement/FileCatalogProxy", timeout=120)
        self.valid = False
        self.valid = self.rpc.ping()["OK"]
        self.interfaceMethods = None

    def isOK(self):
        """Is the Catalog available?"""
        return self.valid

    def getName(self):
        """Get the file catalog name"""
        return self.fcName

    def setInterfaceMethods(self, methodTuple):
        self.interfaceMethods = methodTuple

    def getInterfaceMethods(self):
        return self.interfaceMethods

    def __getattr__(self, name):
        self.method = name
        return self.execute

    def execute(self, *parms, **kws):
        """Magic method dispatcher"""
        return self.rpc.callProxyMethod(self.fcName, self.method, parms, kws)
예제 #2
0
    def putFile(self, path, sourceSize=0):

        client = Client(url=self.url)

        if sourceSize:
            gLogger.debug(
                "ProxyStorage.putFile: The client has provided the source file size implying\
         a replication is requested.")
            return client.callProxyMethod(self.name, "putFile", [path],
                                          {"sourceSize": sourceSize})

        gLogger.debug(
            "ProxyStorage.putFile: No source size was provided therefore a simple put will be performed."
        )
        res = checkArgumentFormat(path)
        if not res["OK"]:
            return res
        urls = res["Value"]
        failed = {}
        successful = {}
        # make sure transferClient uses the same ProxyStorage instance we uploaded the file to
        transferClient = TransferClient(client.serviceURL)
        for dest_url, src_file in urls.items():
            fileName = os.path.basename(dest_url)
            res = transferClient.sendFile(src_file, "putFile/%s" % fileName)
            if not res["OK"]:
                gLogger.error(
                    "ProxyStorage.putFile: Failed to send file to proxy server.",
                    res["Message"])
                failed[dest_url] = res["Message"]
            else:
                res = client.uploadFile(self.name, dest_url)
                if not res["OK"]:
                    gLogger.error(
                        "ProxyStorage.putFile: Failed to upload file to storage element from proxy server.",
                        res["Message"],
                    )
                    failed[dest_url] = res["Message"]
                else:
                    res = self.__executeOperation(dest_url, "getFileSize")
                    if not res["OK"]:
                        gLogger.error(
                            "ProxyStorage.putFile: Failed to determine destination file size.",
                            res["Message"])
                        failed[dest_url] = res["Message"]
                    else:
                        successful[dest_url] = res["Value"]
        resDict = {"Failed": failed, "Successful": successful}
        return S_OK(resDict)
예제 #3
0
 def removeDirectory(self, path, recursive=False):
     client = Client(url=self.url)
     return client.callProxyMethod(self.name, "removeDirectory", [path], {"recursive": recursive})
예제 #4
0
 def createDirectory(self, path):
     client = Client(url=self.url)
     return client.callProxyMethod(self.name, "createDirectory", [path], {})
예제 #5
0
 def getDirectorySize(self, path):
     client = Client(url=self.url)
     return client.callProxyMethod(self.name, "getDirectorySize", [path], {})
예제 #6
0
 def releaseFile(self, path):
     client = Client(url=self.url)
     return client.callProxyMethod(self.name, "releaseFile", [path], {})
예제 #7
0
 def pinFile(self, path, lifetime=60 * 60 * 24):
     client = Client(url=self.url)
     return client.callProxyMethod(self.name, "pinFile", [path], {"lifetime": lifetime})
예제 #8
0
 def prestageFileStatus(self, path):
     client = Client(url=self.url)
     return client.callProxyMethod(self.name, "prestageFileStatus", [path], {})
예제 #9
0
 def getFileMetadata(self, path):
     client = Client(url=self.url)
     return client.callProxyMethod(self.name, "getFileMetadata", [path], {})
예제 #10
0
 def exists(self, path):
     client = Client(url=self.url)
     return client.callProxyMethod(self.name, "exists", [path], {})