From de366ba87d5ca6135da469443980a365c55e63be Mon Sep 17 00:00:00 2001 From: Klaudiusz Dembler Date: Mon, 16 Mar 2020 15:59:56 +0100 Subject: [PATCH] improve compute layout, add running raw algorithm --- package.json | 3 +- src/Compute.js | 118 +++++++++++++++++++------------ src/asset.js | 164 +++++++++++++------------------------------ src/compute-asset.js | 70 ++++++++++++++++++ src/index.js | 7 +- 5 files changed, 197 insertions(+), 165 deletions(-) create mode 100644 src/compute-asset.js diff --git a/package.json b/package.json index ff93285..2b4132d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "react": "^16.12.0", "react-dom": "^16.12.0", "react-scripts": "^3.3.0", - "web3": "^1.2.5" + "web3": "^1.2.5", + "prettier": "^1.19.1" }, "scripts": { "start": "react-scripts start", diff --git a/src/Compute.js b/src/Compute.js index 4292ec9..87ec5ac 100644 --- a/src/Compute.js +++ b/src/Compute.js @@ -1,12 +1,13 @@ import React, { useState } from 'react' -import * as Assets from './asset' +import { asset } from './asset' +import { algoAsset, createComputeService, rawAlgoMeta } from './compute-asset' export default function Compute({ ocean, web3 }) { - const [ddoAsset, setDdoAsset] = useState({ id: '' }) + const [ddoAssetId, setDdoAssetId] = useState('') const [jobStatus, setJobStatus] = useState('') const [jobId, setJobId] = useState('') const [agreementId, setAgreementId] = useState('') - const [ddoAlgorithm, setDdoAlgorithm] = useState({ id: '' }) + const [ddoAlgorithmId, setDdoAlgorithmId] = useState('') // publish a dataset and an algorithm async function publish() { @@ -14,22 +15,20 @@ export default function Compute({ ocean, web3 }) { const accounts = await ocean.accounts.list() console.log('Publishing asset.') - const service = await Assets.createComputeService( + const service = await createComputeService( ocean, accounts[0], '0', '2020-03-10T10:00:00Z' ) console.log(service) - const ddoAssetNew = await ocean.assets.create( - Assets.getAsset(), - accounts[0], - [service] - ) + const ddoAssetNew = await ocean.assets.create(asset, accounts[0], [ + service + ]) console.log('Asset successfully submitted.') console.log(ddoAssetNew) // keep track of this registered asset for consumption later on - setDdoAsset(ddoAssetNew) + setDdoAssetId(ddoAssetNew.id) alert('Asset successfully submitted.') } catch (error) { console.error(error.message) @@ -41,33 +40,30 @@ export default function Compute({ ocean, web3 }) { const accounts = await ocean.accounts.list() console.log('Publishing algo.') - const ddoAlgorithmNew = await ocean.assets.create( - Assets.getAlgoAsset(), - accounts[0] - ) + const ddoAlgorithmNew = await ocean.assets.create(algoAsset, accounts[0]) console.log(ddoAlgorithmNew) console.log('Algo asset successfully submitted.') // keep track of this registered asset for consumption later on - setDdoAlgorithm(ddoAlgorithmNew) + setDdoAlgorithmId(ddoAlgorithmNew.id) alert('Algorithm successfully submitted.') } catch (error) { console.error(error.message) } } - // order and start the compute service - async function start() { + async function startCompute(algorithmId, algorithmMeta) { try { const accounts = await ocean.accounts.list() // order the compute service - const agreement = await ocean.compute.order(accounts[0], ddoAsset.id) + const agreement = await ocean.compute.order(accounts[0], ddoAssetId) setAgreementId(agreement) // start a compute job const status = await ocean.compute.start( accounts[0], agreement, - ddoAlgorithm.id + algorithmId, + algorithmMeta ) setJobId(status.jobId) console.log(status) @@ -77,6 +73,15 @@ export default function Compute({ ocean, web3 }) { } } + // order and start the compute service + async function startWithPublishedAlgo() { + return startCompute(ddoAlgorithmId) + } + + async function startWithRawAlgo() { + return startCompute(undefined, rawAlgoMeta) + } + async function getStatus() { try { const accounts = await ocean.accounts.list() @@ -92,33 +97,60 @@ export default function Compute({ ocean, web3 }) { // get results + if (!web3) { + return null + } + return ( <>

Compute

- - - - -
- Asset DID: - -
- Algo DID: - -
- Job ID: - -
- Compute status: -