1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

new OceanCompute submodule

This commit is contained in:
Matthias Kretschmann 2020-01-10 20:25:14 +01:00
parent ae7768253e
commit 619cd42db7
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 76 additions and 46 deletions

View File

@ -95,7 +95,7 @@ export class Brizo extends Instantiable {
return destination
}
public async executeService(
public async computeService(
agreementId: string,
serviceEndpoint: string,
account: Account,
@ -105,16 +105,16 @@ export class Brizo extends Instantiable {
): Promise<string> {
const signature = await this.createSignature(account, agreementId)
let executeUrl = serviceEndpoint
executeUrl += `&signature=${signature}`
executeUrl += `&serviceAgreementId=${noZeroX(agreementId)}`
executeUrl += `&consumerAddress=${account.getId()}`
executeUrl += `&algorithmDID=${algorithmDid}`
executeUrl += `&algorithm=${algorithm}`
executeUrl += `&algorithmMeta=${algorithmMeta}`
let url = serviceEndpoint
url += `&signature=${signature}`
url += `&serviceAgreementId=${noZeroX(agreementId)}`
url += `&consumerAddress=${account.getId()}`
url += `&algorithmDID=${algorithmDid}`
url += `&algorithm=${algorithm}`
url += `&algorithmMeta=${algorithmMeta}`
const result: { workflowId: string } = await this.ocean.utils.fetch
.post(executeUrl, '')
const result: { jobId: string } = await this.ocean.utils.fetch
.post(url, '')
.then((response: any) => {
if (response.ok) {
return response.json()
@ -134,7 +134,7 @@ export class Brizo extends Instantiable {
throw error
})
return result.workflowId
return result.jobId
}
public async createSignature(account: Account, agreementId: string): Promise<string> {

View File

@ -145,12 +145,11 @@ export interface MetaDataMain {
name: string
/**
* Type of the Asset. Helps to filter by the type of asset,
* initially ("dataset", "algorithm", "container", "workflow", "other").
* Type of the Asset. Helps to filter by the type of asset ("dataset" or "algorithm").
* @type {string}
* @example "dataset"
*/
type: 'dataset' | 'algorithm' | 'container' | 'workflow' | 'other'
type: 'dataset' | 'algorithm'
/**
* The date on which the asset was created by the originator in

View File

@ -2,6 +2,7 @@ import { OceanAccounts } from './OceanAccounts'
import { OceanAgreements } from './OceanAgreements'
import { OceanAssets } from './OceanAssets'
import { OceanAuth } from './OceanAuth'
import { OceanCompute } from './OceanCompute'
import { OceanSecretStore } from './OceanSecretStore'
import { OceanTokens } from './OceanTokens'
import { OceanVersions } from './OceanVersions'
@ -45,6 +46,7 @@ export class Ocean extends Instantiable {
instance.accounts = await OceanAccounts.getInstance(instanceConfig)
instance.auth = await OceanAuth.getInstance(instanceConfig)
instance.assets = await OceanAssets.getInstance(instanceConfig)
instance.compute = await OceanCompute.getInstance(instanceConfig)
instance.agreements = await OceanAgreements.getInstance(instanceConfig)
instance.secretStore = await OceanSecretStore.getInstance(instanceConfig)
instance.tokens = await OceanTokens.getInstance(instanceConfig)
@ -97,6 +99,12 @@ export class Ocean extends Instantiable {
*/
public agreements: OceanAgreements
/**
* Ocean compute submodule
* @type {OceanCompute}
*/
public compute: OceanCompute
/**
* Ocean secretStore submodule
* @type {OceanSecretStore}

View File

@ -364,38 +364,6 @@ export class OceanAssets extends Instantiable {
})
}
/**
* Start the execution of a compute job.
* @param {string} agreementId ID of the agreement.
* @param {DDO} computeDdo DDO of the compute asset.
* @param {Account} consumerAccount Consumer account.
* @param {string} algorithmDid The asset DID (of type `algorithm`) which consist of `did:op:` and the `assetId` hex str (without `0x` prefix).
* @param {string} algorithm The text of the algorithm to run in the compute job (e.g. a jupyter notebook)
* @param {MetaData} algorithmMeta Metadata about the algorithm being run if `algorithm` is being used. This is ignored when `algorithmDID` is specified.
* @return {Promise<string>} Returns Workflow ID
*/
public async execute(
agreementId: string,
computeDdo: DDO,
consumerAccount: Account,
algorithmDid: string,
algorithm: string,
algorithmMeta?: MetaData
): Promise<string> {
const { serviceEndpoint } = computeDdo.findServiceByType('compute')
const workflowId = await this.ocean.brizo.executeService(
agreementId,
serviceEndpoint,
consumerAccount,
algorithmDid,
algorithm,
algorithmMeta
)
return workflowId
}
/**
* Returns the owner of a asset.
* @param {string} did Decentralized ID.

55
src/ocean/OceanCompute.ts Normal file
View File

@ -0,0 +1,55 @@
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
import { MetaData } from '../ddo/MetaData'
import Account from './Account'
import { DDO } from '../ddo/DDO'
/**
* Compute submodule of Ocean Protocol.
*/
export class OceanCompute extends Instantiable {
/**
* Returns the instance of OceanCompute.
* @return {Promise<OceanCompute>}
*/
public static async getInstance(config: InstantiableConfig): Promise<OceanCompute> {
const instance = new OceanCompute()
instance.setInstanceConfig(config)
return instance
}
/**
* Start the execution of a compute job.
* @param {string} agreementId The service agreement ID.
* @param {string} datasetDid The DID of the dataset asset (of type `dataset`) to run the algorithm on.
* @param {number} serviceIndex ID of the compute service within the dataset DDO.
* @param {Account} consumerAccount The account of the consumer ordering the service.
* @param {string} algorithmDid The DID of the algorithm asset (of type `algorithm`) to run on the asset.
* @param {string} algorithmRaw The raw text of the algorithm to run in the compute job (e.g. a jupyter notebook) or a valid URL to fetch the algorithm.
* @param {MetaData} algorithmMeta Metadata about the algorithm being run if `algorithm` is being used. This is ignored when `algorithmDid` is specified.
* @return {Promise<string>} Returns compute job ID
*/
public async run(
agreementId: string,
datasetDid: string,
serviceIndex: number,
consumerAccount: Account,
algorithmDid: string,
algorithmRaw?: string,
algorithmMeta?: MetaData
): Promise<string> {
const ddo: DDO = await this.ocean.assets.resolve(datasetDid)
const { serviceEndpoint } = ddo.findServiceById(serviceIndex)
const jobId = await this.ocean.brizo.computeService(
agreementId,
serviceEndpoint,
consumerAccount,
algorithmDid,
algorithmRaw,
algorithmMeta
)
return jobId
}
}