From cf7d003d569b9189dbfc0e7391ab958d96b20828 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 10 Mar 2020 13:26:45 +0200 Subject: [PATCH 01/10] added create_compute_service_attributes --- src/ocean/OceanCompute.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ocean/OceanCompute.ts b/src/ocean/OceanCompute.ts index 7a0f171..3bdb72a 100644 --- a/src/ocean/OceanCompute.ts +++ b/src/ocean/OceanCompute.ts @@ -261,4 +261,25 @@ export class OceanCompute extends Instantiable { return computeJobsList[0] as ComputeJob } + + public async create_compute_service_attributes(consumerAccount: Account,price: string,datePublished: string){ + const { templates } = this.ocean.keeper + const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate() + const name = 'dataAssetComputingServiceAgreement' + const service = { + type: 'compute', + serviceEndpoint: this.ocean.brizo.getComputeEndpoint(), + templateId: templates.escrowComputeExecutionTemplate.getId(), + attributes: { + main: { + creator: consumerAccount.getId(), + datePublished, + price, + timeout: 3600, + name + }, + serviceAgreementTemplate + } + } + return(service) } From bd831c2c61ac1352a39ba382f3e333951c1118ea Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 10 Mar 2020 13:30:06 +0200 Subject: [PATCH 02/10] Update Compute.test.ts --- test/integration/ocean/Compute.test.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/test/integration/ocean/Compute.test.ts b/test/integration/ocean/Compute.test.ts index 893129e..47b690b 100644 --- a/test/integration/ocean/Compute.test.ts +++ b/test/integration/ocean/Compute.test.ts @@ -3,7 +3,7 @@ import { assert } from 'chai' import { config } from '../config' import { Ocean, Account, DDO, MetaData, ComputeJobStatus, Config } from '../../../src' import { getMetadata, createComputeService } from '../utils' -import { ServiceCompute } from '../../../src/ddo/Service' + const metadataAsset = getMetadata() const metadataAlgorithm = getMetadata(0, 'algorithm') @@ -29,12 +29,7 @@ describe('Compute', () => { before(async () => { ocean = await Ocean.getInstance(customConfig) ;[account] = await ocean.accounts.list() - computeService = await createComputeService( - ocean, - account, - '1000', - metadataAsset.main.datePublished - ) + }) it('should authenticate the consumer account', async () => { @@ -43,7 +38,7 @@ describe('Compute', () => { it('should publish a dataset with a compute service object', async () => { const stepsAsset = [] - + const computeService= await ocean.compute.create_compute_service_attributes(account,"1000",metadataAsset.main.datePublished) dataset = await ocean.assets .create(metadataAsset as MetaData, account, [computeService]) .next(step => stepsAsset.push(step)) From 8cfbd4024c1298defc3deb1830b73e94b4488496 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 10 Mar 2020 13:57:17 +0200 Subject: [PATCH 03/10] fixes --- src/ocean/OceanCompute.ts | 14 ++++++++++---- test/integration/ocean/Compute.test.ts | 5 +++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ocean/OceanCompute.ts b/src/ocean/OceanCompute.ts index 3bdb72a..e096715 100644 --- a/src/ocean/OceanCompute.ts +++ b/src/ocean/OceanCompute.ts @@ -5,6 +5,7 @@ import { DDO } from '../ddo/DDO' import { SubscribablePromise } from '../utils' import { OrderProgressStep } from './utils/ServiceUtils' import { DID } from '../squid' +import {ServiceCompute} from '../ddo/Service' export const ComputeJobStatus = Object.freeze({ Started: 10, @@ -262,12 +263,17 @@ export class OceanCompute extends Instantiable { return computeJobsList[0] as ComputeJob } - public async create_compute_service_attributes(consumerAccount: Account,price: string,datePublished: string){ + public async create_compute_service_attributes( + consumerAccount: Account, + price: string, + datePublished: string + ): Promise { const { templates } = this.ocean.keeper const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate() const name = 'dataAssetComputingServiceAgreement' - const service = { + return { type: 'compute', + index: 3, serviceEndpoint: this.ocean.brizo.getComputeEndpoint(), templateId: templates.escrowComputeExecutionTemplate.getId(), attributes: { @@ -280,6 +286,6 @@ export class OceanCompute extends Instantiable { }, serviceAgreementTemplate } - } - return(service) + } + } } diff --git a/test/integration/ocean/Compute.test.ts b/test/integration/ocean/Compute.test.ts index 47b690b..d920778 100644 --- a/test/integration/ocean/Compute.test.ts +++ b/test/integration/ocean/Compute.test.ts @@ -2,7 +2,8 @@ import { assert } from 'chai' import { config } from '../config' import { Ocean, Account, DDO, MetaData, ComputeJobStatus, Config } from '../../../src' -import { getMetadata, createComputeService } from '../utils' +import { getMetadata} from '../utils' +import { ServiceCompute } from '../../../src/ddo/Service' const metadataAsset = getMetadata() @@ -38,7 +39,7 @@ describe('Compute', () => { it('should publish a dataset with a compute service object', async () => { const stepsAsset = [] - const computeService= await ocean.compute.create_compute_service_attributes(account,"1000",metadataAsset.main.datePublished) + computeService= await ocean.compute.create_compute_service_attributes(account,"1000",metadataAsset.main.datePublished) dataset = await ocean.assets .create(metadataAsset as MetaData, account, [computeService]) .next(step => stepsAsset.push(step)) From e7872666faf6e1b0c9868613823bb843d8609756 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 17 Mar 2020 12:57:36 +0200 Subject: [PATCH 04/10] fix compute & added createAccessServiceAttributes --- src/ocean/OceanAssets.ts | 54 ++++++++++++++++++-------- src/ocean/OceanCompute.ts | 44 ++++++++++----------- test/integration/ocean/Compute.test.ts | 10 +++-- 3 files changed, 66 insertions(+), 42 deletions(-) diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index dd94884..11f9e62 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -2,12 +2,13 @@ import { TransactionReceipt } from 'web3-core' import { SearchQuery } from '../aquarius/Aquarius' import { DDO } from '../ddo/DDO' import { MetaData } from '../ddo/MetaData' -import { Service } from '../ddo/Service' +import { Service, ServiceAccess } from '../ddo/Service' import Account from './Account' import DID from './DID' import { fillConditionsWithDDO, SubscribablePromise } from '../utils' import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' import { OrderProgressStep } from './utils/ServiceUtils' +import { access } from 'fs' export enum CreateProgressStep { EncryptingFiles, @@ -76,6 +77,16 @@ export class OceanAssets extends Instantiable { this.logger.log('Files encrypted') observer.next(CreateProgressStep.FilesEncrypted) + // makr sure that access service is defined if services is empty + if (services.length === 0) { + const accessService = await this.createAccessServiceAttributes( + publisher, + metadata.main.price, + metadata.main.datePublished + ) + services.push(accessService) + } + const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate() const serviceEndpoint = this.ocean.aquarius.getServiceEndpoint(did) @@ -98,21 +109,6 @@ export class OceanAssets extends Instantiable { } ], service: [ - { - type: 'access', - serviceEndpoint: this.ocean.brizo.getConsumeEndpoint(), - templateId: templates.escrowAccessSecretStoreTemplate.getId(), - attributes: { - main: { - creator: publisher.getId(), - datePublished: metadata.main.datePublished, - name: 'dataAssetAccessServiceAgreement', - price: metadata.main.price, - timeout: 3600 - }, - serviceAgreementTemplate - } - }, { type: 'authorization', service: 'SecretStore', @@ -396,4 +392,30 @@ export class OceanAssets extends Instantiable { } } as SearchQuery) } + + public async createAccessServiceAttributes( + consumerAccount: Account, + price: string, + datePublished: string + ): Promise { + const { templates } = this.ocean.keeper + const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate() + const name = 'dataAssetComputingServiceAgreement' + return { + type: 'access', + index: 2, + serviceEndpoint: this.ocean.brizo.getConsumeEndpoint(), + templateId: templates.escrowAccessSecretStoreTemplate.getId(), + attributes: { + main: { + creator: consumerAccount.getId(), + datePublished, + price, + timeout: 3600, + name: 'dataAssetAccessServiceAgreement' + }, + serviceAgreementTemplate + } + } + } } diff --git a/src/ocean/OceanCompute.ts b/src/ocean/OceanCompute.ts index e096715..262fabb 100644 --- a/src/ocean/OceanCompute.ts +++ b/src/ocean/OceanCompute.ts @@ -5,7 +5,7 @@ import { DDO } from '../ddo/DDO' import { SubscribablePromise } from '../utils' import { OrderProgressStep } from './utils/ServiceUtils' import { DID } from '../squid' -import {ServiceCompute} from '../ddo/Service' +import { ServiceCompute } from '../ddo/Service' export const ComputeJobStatus = Object.freeze({ Started: 10, @@ -262,30 +262,30 @@ export class OceanCompute extends Instantiable { return computeJobsList[0] as ComputeJob } - - public async create_compute_service_attributes( + + public async createComputeServiceAttributes( consumerAccount: Account, price: string, datePublished: string ): Promise { - const { templates } = this.ocean.keeper - const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate() - const name = 'dataAssetComputingServiceAgreement' - return { - type: 'compute', - index: 3, - serviceEndpoint: this.ocean.brizo.getComputeEndpoint(), - templateId: templates.escrowComputeExecutionTemplate.getId(), - attributes: { - main: { - creator: consumerAccount.getId(), - datePublished, - price, - timeout: 3600, - name - }, - serviceAgreementTemplate - } - } + const { templates } = this.ocean.keeper + const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate() + const name = 'dataAssetComputingServiceAgreement' + return { + type: 'compute', + index: 3, + serviceEndpoint: this.ocean.brizo.getComputeEndpoint(), + templateId: templates.escrowComputeExecutionTemplate.getId(), + attributes: { + main: { + creator: consumerAccount.getId(), + datePublished, + price, + timeout: 3600, + name + }, + serviceAgreementTemplate + } + } } } diff --git a/test/integration/ocean/Compute.test.ts b/test/integration/ocean/Compute.test.ts index d920778..cdb561c 100644 --- a/test/integration/ocean/Compute.test.ts +++ b/test/integration/ocean/Compute.test.ts @@ -2,10 +2,9 @@ import { assert } from 'chai' import { config } from '../config' import { Ocean, Account, DDO, MetaData, ComputeJobStatus, Config } from '../../../src' -import { getMetadata} from '../utils' +import { getMetadata } from '../utils' import { ServiceCompute } from '../../../src/ddo/Service' - const metadataAsset = getMetadata() const metadataAlgorithm = getMetadata(0, 'algorithm') @@ -30,7 +29,6 @@ describe('Compute', () => { before(async () => { ocean = await Ocean.getInstance(customConfig) ;[account] = await ocean.accounts.list() - }) it('should authenticate the consumer account', async () => { @@ -39,7 +37,11 @@ describe('Compute', () => { it('should publish a dataset with a compute service object', async () => { const stepsAsset = [] - computeService= await ocean.compute.create_compute_service_attributes(account,"1000",metadataAsset.main.datePublished) + computeService = await ocean.compute.createComputeServiceAttributes( + account, + '1000', + metadataAsset.main.datePublished + ) dataset = await ocean.assets .create(metadataAsset as MetaData, account, [computeService]) .next(step => stepsAsset.push(step)) From 6c43a72474bf9c40be8b053de1baa1e12f8e6d07 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 17 Mar 2020 13:07:54 +0200 Subject: [PATCH 05/10] fix conflict --- test/integration/ocean/Compute.test.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/integration/ocean/Compute.test.ts b/test/integration/ocean/Compute.test.ts index cdb561c..9111381 100644 --- a/test/integration/ocean/Compute.test.ts +++ b/test/integration/ocean/Compute.test.ts @@ -1,8 +1,16 @@ import { assert } from 'chai' import { config } from '../config' -import { Ocean, Account, DDO, MetaData, ComputeJobStatus, Config } from '../../../src' -import { getMetadata } from '../utils' +import { + Ocean, + Account, + DDO, + MetaData, + ComputeJobStatus, + Config, + MetaDataAlgorithm +} from '../../../src' +import { getMetadata, createComputeService } from '../utils' import { ServiceCompute } from '../../../src/ddo/Service' const metadataAsset = getMetadata() From 3130d6b9fd0996a1771ced6d6172646a7fc7baa2 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 17 Mar 2020 13:17:35 +0200 Subject: [PATCH 06/10] fix typo --- src/ocean/OceanAssets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index 11f9e62..7ca0194 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -77,7 +77,7 @@ export class OceanAssets extends Instantiable { this.logger.log('Files encrypted') observer.next(CreateProgressStep.FilesEncrypted) - // makr sure that access service is defined if services is empty + // make sure that access service is defined if services is empty if (services.length === 0) { const accessService = await this.createAccessServiceAttributes( publisher, From cd04d1b1ba9159967f38adf578cd4394e4a8632d Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 17 Mar 2020 13:23:23 +0200 Subject: [PATCH 07/10] Update src/ocean/OceanAssets.ts Co-Authored-By: Matthias Kretschmann --- src/ocean/OceanAssets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index 7ca0194..b174122 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -400,7 +400,7 @@ export class OceanAssets extends Instantiable { ): Promise { const { templates } = this.ocean.keeper const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate() - const name = 'dataAssetComputingServiceAgreement' + const name = 'dataAssetAccessServiceAgreement' return { type: 'access', index: 2, From 14a0c5dcc3f48ec722b5c3a9041a35370755a982 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 17 Mar 2020 13:41:49 +0200 Subject: [PATCH 08/10] remove unused code --- test/integration/ocean/Compute.test.ts | 2 +- .../utils/ddo-metadata-generator.ts | 27 ------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/test/integration/ocean/Compute.test.ts b/test/integration/ocean/Compute.test.ts index 9111381..88f0d9f 100644 --- a/test/integration/ocean/Compute.test.ts +++ b/test/integration/ocean/Compute.test.ts @@ -10,7 +10,7 @@ import { Config, MetaDataAlgorithm } from '../../../src' -import { getMetadata, createComputeService } from '../utils' +import { getMetadata } from '../utils' import { ServiceCompute } from '../../../src/ddo/Service' const metadataAsset = getMetadata() diff --git a/test/integration/utils/ddo-metadata-generator.ts b/test/integration/utils/ddo-metadata-generator.ts index d79a4dd..a809ef1 100644 --- a/test/integration/utils/ddo-metadata-generator.ts +++ b/test/integration/utils/ddo-metadata-generator.ts @@ -78,30 +78,3 @@ export const generateMetadata = ( export const getMetadata = (price?: number, type?: 'dataset' | 'algorithm') => generateMetadata('TestAsset', type, price) -export const createComputeService = async ( - ocean: Ocean, - publisher: Account, - price: string, - datePublished: string -): Promise => { - const { templates } = ocean.keeper - const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate() - - const name = 'dataAssetComputingServiceAgreement' - return { - type: 'compute', - index: 3, - serviceEndpoint: ocean.brizo.getComputeEndpoint(), - templateId: templates.escrowComputeExecutionTemplate.getId(), - attributes: { - main: { - creator: publisher.getId(), - datePublished, - price, - timeout: 3600, - name - }, - serviceAgreementTemplate - } - } -} From 00b518aa224ccc4162618235b14f959a78519a74 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Wed, 18 Mar 2020 09:40:22 +0200 Subject: [PATCH 09/10] removed name & access fs --- src/ocean/OceanAssets.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index b174122..b171ca0 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -8,7 +8,6 @@ import DID from './DID' import { fillConditionsWithDDO, SubscribablePromise } from '../utils' import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' import { OrderProgressStep } from './utils/ServiceUtils' -import { access } from 'fs' export enum CreateProgressStep { EncryptingFiles, @@ -400,7 +399,6 @@ export class OceanAssets extends Instantiable { ): Promise { const { templates } = this.ocean.keeper const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate() - const name = 'dataAssetAccessServiceAgreement' return { type: 'access', index: 2, From 8e82885036545fc5460f579ee1a058c95ec04409 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Wed, 18 Mar 2020 10:29:51 +0200 Subject: [PATCH 10/10] some lint --- test/integration/utils/ddo-metadata-generator.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/utils/ddo-metadata-generator.ts b/test/integration/utils/ddo-metadata-generator.ts index a809ef1..5bfe952 100644 --- a/test/integration/utils/ddo-metadata-generator.ts +++ b/test/integration/utils/ddo-metadata-generator.ts @@ -77,4 +77,3 @@ export const generateMetadata = ( export const getMetadata = (price?: number, type?: 'dataset' | 'algorithm') => generateMetadata('TestAsset', type, price) -