class FileCatalogProxyClient: """ 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 = RPCClient( 'DataManagement/FileCatalogProxy', timeout=120 ) self.valid = False self.valid = self.rpc.ping()['OK'] def isOK( self ): """ Is the Catalog available? """ return self.valid def getName( self ): """ Get the file catalog name """ return self.fcName 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 )
def putFile( self, path, sourceSize = 0 ): client = RPCClient( 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 = self.__checkArgumentFormatDict( path ) if not res['OK']: return res urls = res['Value'] failed = {} successful = {} client = RPCClient( self.url ) transferClient = TransferClient( self.url ) 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, src_file ) 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 )
def putFile(self, path, sourceSize=0): client = RPCClient(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)
def removeDirectory(self, path, recursive=False): client = RPCClient(self.url) return client.callProxyMethod(self.name, 'removeDirectory', path, {'recursive': recursive})
def getDirectorySize(self, path): client = RPCClient(self.url) return client.callProxyMethod(self.name, 'getDirectorySize', path)
def pinFile(self, path, lifetime=60 * 60 * 24): client = RPCClient(self.url) return client.callProxyMethod(self.name, 'pinFile', path, {'lifetime': lifetime})
def getTransportURL(self, path, protocols=False): client = RPCClient(self.url) return client.callProxyMethod(self.name, 'getTransportURL', path, {'protocols': protocols})
def exists(self, path): client = RPCClient(self.url) return client.callProxyMethod(self.name, 'exists', path)
def removeDirectory( self, path, recursive = False ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'removeDirectory', [path], {'recursive':recursive} )
def listDirectory( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'listDirectory', [path], {} )
def getFileSize( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'getFileSize', [path], {} )
def exists( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'exists', [path], {} )
def listDirectory( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'listDirectory', path )
def getDirectoryMetadata( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'getDirectoryMetadata', path )
def prestageFile( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'prestageFile', path )
def getFileMetadata( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'getFileMetadata', [path], {} )
def getDirectorySize( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'getDirectorySize', [path], {} )
def getTransportURL( self, path, protocols = False ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'getTransportURL', [path], {'protocols':protocols} )
def createDirectory( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'createDirectory', [path], {} )
def removeFile( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'removeFile', [path], {} )
def getPFNBase( self ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'getPFNBase', [], {} )
def prestageFile( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'prestageFile', [path], {} )
def getFileMetadata(self, path): client = RPCClient(self.url) return client.callProxyMethod(self.name, 'getFileMetadata', path)
def prestageFileStatus( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'prestageFileStatus', [path], {} )
def prestageFileStatus(self, path): client = RPCClient(self.url) return client.callProxyMethod(self.name, 'prestageFileStatus', path)
def pinFile( self, path, lifetime = 60 * 60 * 24 ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'pinFile', [path], {'lifetime':lifetime} )
def releaseFile(self, path): client = RPCClient(self.url) return client.callProxyMethod(self.name, 'releaseFile', path)
def getFileSize( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'getFileSize', path )
def createDirectory(self, path): client = RPCClient(self.url) return client.callProxyMethod(self.name, 'createDirectory', path)
def getDirectoryMetadata( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'getDirectoryMetadata', [path], {} )
def releaseFile( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'releaseFile', [path], {} )
def removeFile( self, path ): client = RPCClient( self.url ) return client.callProxyMethod( self.name, 'removeFile', path )