From a60e4159255aadeba00bec2e72cf0fbb4b71489c Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Sat, 1 Feb 2020 15:25:24 +0200 Subject: [PATCH] add Output Object passed to brizo --- src/brizo/Brizo.ts | 4 ++- src/ocean/OceanCompute.ts | 62 ++++++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index a6a3000..4bfd8a6 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -116,7 +116,8 @@ export class Brizo extends Instantiable { consumerAccount: Account, algorithmDid?: string, algorithmMeta?: MetaData, - jobId?: string + jobId?: string, + output?: Object ): Promise { const signature = await this.createSignature(consumerAccount, serviceAgreementId) const address = consumerAccount.getId() @@ -138,6 +139,7 @@ export class Brizo extends Instantiable { url += `&serviceAgreementId=${noZeroX(serviceAgreementId)}` url += algorithmDid && `&algorithmDid=${algorithmDid}` url += algorithmMeta && `&algorithmMeta=${algorithmMeta}` + url += output && `&output=${output}` url += jobId && `&jobId=${jobId}` // switch fetch method diff --git a/src/ocean/OceanCompute.ts b/src/ocean/OceanCompute.ts index 46958cb..e0853df 100644 --- a/src/ocean/OceanCompute.ts +++ b/src/ocean/OceanCompute.ts @@ -16,18 +16,6 @@ export enum ComputeJobStatus { Stopped, Deleted } -export interface Output { - publishAlgorithmLog?: boolean - publishOutput?: boolean - brizoAddress?: string - brizoUrl?: string - metadata?: Object - metadataUrl?: string - nodeUri?: string - owner?: string - secretStoreUrl?: string - whitelist?: Array -} export interface ComputeJob { owner: string @@ -86,26 +74,72 @@ export class OceanCompute extends Instantiable { }) } + /** + * return minimal output object + * @return {Promise} Returns output object + */ + public async minimal_output_object():Promise { + var minimal_output=Object() + minimal_output["publishAlgorithmLog"]=false + minimal_output["publishOutput"]=false + return(minimal_output) + } + /** + * Check the output object and add default properties if needed + * @param {Account} consumerAccount The account of the consumer ordering the service. + * @param {Object} output Output section used for publishing the result. + * @return {Promise} Returns output object + */ + public async check_output_dict( + consumerAccount:Account, + output?:Object + ): Promise { + if (!output){ + //build a minimal object and return it + return (await this.minimal_output_object()) + } + if((!output["publishAlgorithmLog"] || output["publishAlgorithmLog"]==false) && (!output["publishOutput"] || output["publishOutput"]==false)){ + return (await this.minimal_output_object()) + } + if(!output["brizoAddress"]) + output["brizoAddress"]=this.config.brizoAddress + if(!output["brizoUrl"]) + output["brizoUrl"]=this.config.brizoUri + if(!output["metadataUrl"]) + output["metadataUrl"]=this.config.aquariusUri + if(!output["nodeUri"]) + output["nodeUri"]=this.config.nodeUri + if(!output["owner"]) + output["owner"]=consumerAccount.getId() + if(!output["secretStoreUrl"]) + output["secretStoreUrl"]=this.config.secretStoreUri + return output + } /** * Start the execution of a compute job. * @param {Account} consumerAccount The account of the consumer ordering the service. * @param {string} agreementId The service agreement ID. * @param {string} algorithmDid The DID of the algorithm asset (of type `algorithm`) to run on the asset. * @param {MetaData} algorithmMeta Metadata about the algorithm being run if `algorithm` is being used. This is ignored when `algorithmDid` is specified. + * @param {Object} output Output section used for publishing the result. * @return {Promise} Returns compute job ID under status.jobId */ public async start( consumerAccount: Account, agreementId: string, algorithmDid?: string, - algorithmMeta?: MetaData + algorithmMeta?: MetaData, + output?:Object ): Promise { + output=await this.check_output_dict(consumerAccount,output) const status = await this.ocean.brizo.compute( 'post', agreementId, consumerAccount, algorithmDid, - algorithmMeta + algorithmMeta, + null, + output ) return status as ComputeJob