Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/compute-interface #130

Merged
merged 26 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ before_script:
- git clone https://github.com/oceanprotocol/barge
- cd barge
- git checkout v3
- export PROVIDER_VERSION=alex
- export PROVIDER_VERSION=phase2
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
- cd ..
- sleep 300
Expand All @@ -39,4 +39,4 @@ deploy:
api_key: ${NPM_TOKEN}
skip_cleanup: true
on:
tags: true
tags: true
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"changelog": "auto-changelog -p",
"prepublishOnly": "npm run build",
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit test/unit/**/*.ts",
"test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit test/integration/**/*.ts",
"test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit test/integration/*.ts",
"test:cover": "nyc --report-dir coverage/unit npm run test:unit"
},
"repository": {
Expand Down
6 changes: 2 additions & 4 deletions src/ddo/interfaces/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ServiceComputeAttributes extends ServiceCommonAttributes {
main: {
creator: string
datePublished: string
price: string
cost: string
timeout: number
provider?: ServiceComputeProvider
name: string
Expand All @@ -57,7 +57,7 @@ export interface ServiceComputeProvider {
supportedServers: {
serverId: string
serverType: string
price: string
cost: string
cpu: string
gpu: string
memory: string
Expand All @@ -74,13 +74,11 @@ export interface ServiceMetadata extends ServiceCommon {

export interface ServiceAccess extends ServiceCommon {
type: 'access'
templateId?: string
attributes: ServiceAccessAttributes
}

export interface ServiceCompute extends ServiceCommon {
type: 'compute'
templateId?: string
attributes: ServiceComputeAttributes
}

Expand Down
6 changes: 6 additions & 0 deletions src/models/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export class Config {
*/
public nodeUri?: string

/**
* Address of Provider.
* @type {string}
*/
public providerAddress?: string

/**
* Metadata Store URL.
* @type {string}
Expand Down
48 changes: 31 additions & 17 deletions src/ocean/Assets.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { SearchQuery } from '../metadatastore/MetadataStore'
import { DDO } from '../ddo/DDO'
import { Metadata } from '../ddo/interfaces/Metadata'
import { MetadataAlgorithm } from '../ddo/interfaces/MetadataAlgorithm'
import {
Service,
ServiceAccess,
ServiceComputePrivacy,
ServiceCommon
ServiceCommon,
ServiceCompute
} from '../ddo/interfaces/Service'

import { EditableMetadata } from '../ddo/interfaces/EditableMetadata'
import Account from './Account'
import DID from './DID'
import { SubscribablePromise } from '../utils'
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
import { WebServiceConnector } from './utils/WebServiceConnector'
import { Output } from './interfaces/ComputeOutput'
import { ComputeJob } from './interfaces/ComputeJob'

export enum CreateProgressStep {
CreatingDataToken,
Expand Down Expand Up @@ -44,18 +49,6 @@ export class Assets extends Instantiable {
return instance
}

/**
* Creates a simple asset and a datatoken
* @param {Account} publisher Publisher account.
* @return {Promise<String>}
*/
public createSimpleAsset(publisher: Account): Promise<string> {
const publisherURI = this.ocean.provider.getURI()
const jsonBlob = { t: 0, url: publisherURI }
const { datatokens } = this.ocean
return datatokens.create(JSON.stringify(jsonBlob), publisher)
}

/**
* Creates a new DDO and publishes it
* @param {Metadata} metadata DDO metadata.
Expand Down Expand Up @@ -354,6 +347,20 @@ export class Assets extends Instantiable {
return service
}

public async getServiceByIndex(
did: string,
serviceIndex: number
): Promise<ServiceCommon> {
const services: ServiceCommon[] = (await this.resolve(did)).service
let service
services.forEach((serv) => {
if (serv.index === serviceIndex) {
service = serv
}
})
return service
}

public async createAccessServiceAttributes(
creator: Account,
dtCost: number,
Expand All @@ -370,7 +377,7 @@ export class Assets extends Instantiable {
datePublished,
cost: dtCost,
timeout: timeout,
name: 'dataAssetAccessServiceAgreement'
name: 'dataAssetAccess'
}
}
}
Expand All @@ -379,12 +386,19 @@ export class Assets extends Instantiable {
public async order(
did: string,
serviceType: string,
consumerAddress: string
consumerAddress: string,
serviceIndex: number = -1
): Promise<string> {
const service = await this.getServiceByType(did, serviceType)
if (serviceIndex === -1) {
const service = await this.getServiceByType(did, serviceType)
serviceIndex = service.index
} else {
const service = await this.getServiceByIndex(did, serviceIndex)
serviceType = service.type
}
return await this.ocean.provider.initialize(
did,
service.index,
serviceIndex,
serviceType,
consumerAddress
)
Expand Down
Loading