def compute(self, pid): cert_file = None key_file = None cn_url = get_cn_url(self) mn_url = get_mn_url(self) if self.hasInputFromPort("authentication"): auth = self.getInputFromPort("authentication") cert_file = auth.cert_file key_file = auth.key_file self.annotate({"cn_url": cn_url, "mn_url": mn_url}) mn_client = utils.get_d1_mn_client(mn_url=mn_url, cert_file=cert_file, key_file=key_file) cn_client = utils.get_d1_cn_client(cn_url=cn_url) # if it already exists if utils.get_sysmeta_by_pid(pid, True, cn_client, mn_client): if not self.forceGetInputFromPort("updateIfExists", False): raise ModuleError(self, 'Cannot add data: ' \ 'identifer "%s" already exists.') else: self.update_object(pid, mn_client, cn_client) self.create_object(pid, mn_client, cn_client)
def compute(self, get_method): """compute dumps to object (either science data or metadata) to a file object, get_method is the unbound method (e.g. MemberNodeClient.get)""" pid = self.getInputFromPort("identifier") cn_url = get_cn_url(self) mn_url = get_mn_url(self) cn_client = utils.get_d1_cn_client(cn_url=cn_url) mn_client = utils.get_d1_mn_client(mn_url=mn_url) self.annotate({'cn_url': cn_url, 'mn_url': used_mn_url}) output_file = self.interpreter.filePool.create_file() # FIXME would be nice to know which member node the data was # downloaded from res = get_method(pid, mn_client, cn_client, True, output_file.name) if res is None: raise ModuleError(self, "Object could not be retrieved") # do something with identifier.pid and output_file.name self.setResult("file", output_file)