diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index a6a3000..77aa4cb 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -4,7 +4,7 @@ import { noZeroX } from '../utils' import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' import { DDO } from '../ddo/DDO' import { ServiceType } from '../ddo/Service' -import { ComputeJob } from '../ocean/OceanCompute' +import { ComputeJob, Output } from '../ocean/OceanCompute' const apiPath = '/api/v1/brizo/services' @@ -116,7 +116,8 @@ export class Brizo extends Instantiable { consumerAccount: Account, algorithmDid?: string, algorithmMeta?: MetaData, - jobId?: string + jobId?: string, + output?: Output ): 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 06e0dc0..ea8fc33 100644 --- a/src/ocean/OceanCompute.ts +++ b/src/ocean/OceanCompute.ts @@ -17,6 +17,19 @@ export enum ComputeJobStatus { Deleted } +export interface Output { + publishAlgorithmLog?: boolean + publishOutput?: boolean + brizoAddress?: string + brizoUri?: string + metadata?: MetaData + metadataUri?: string + nodeUri?: string + owner?: string + secretStoreUri?: string + whitelist?: string[] +} + export interface ComputeJob { owner: string agreementId: string @@ -74,26 +87,60 @@ export class OceanCompute extends Instantiable { }) } + /** + * Check the output object and add default properties if needed + * @param {Account} consumerAccount The account of the consumer ordering the service. + * @param {Output} output Output section used for publishing the result. + * @return {Promise} Returns output object + */ + private checkOutput(consumerAccount: Account, output?: Output): Output { + const isDefault = + !output || (!output.publishAlgorithmLog && !output.publishOutput) + + if (isDefault) { + return { + publishAlgorithmLog: false, + publishOutput: false + } + } + + return { + publishAlgorithmLog: output.publishAlgorithmLog, + publishOutput: output.publishOutput, + brizoAddress: output.brizoAddress || this.config.brizoAddress, + brizoUri: output.brizoUri || this.config.brizoUri, + metadataUri: output.metadataUri || this.config.aquariusUri, + nodeUri: output.nodeUri || this.config.nodeUri, + owner: output.owner || consumerAccount.getId(), + secretStoreUri: output.secretStoreUri || this.config.secretStoreUri + } + } + /** * 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 {Output} output Define algorithm output publishing. Publishing the result of a compute job is turned off by default. * @return {Promise} Returns compute job ID under status.jobId */ public async start( consumerAccount: Account, agreementId: string, algorithmDid?: string, - algorithmMeta?: MetaData + algorithmMeta?: MetaData, + output?: Output ): Promise { + output = this.checkOutput(consumerAccount, output) const status = await this.ocean.brizo.compute( 'post', agreementId, consumerAccount, algorithmDid, - algorithmMeta + algorithmMeta, + null, + output ) return status as ComputeJob