From cdec8be7ae0eedfeb9b52ffe9f55f24a891ec7f8 Mon Sep 17 00:00:00 2001 From: boneyard93501 <4523011+boneyard93501@users.noreply.github.com> Date: Sun, 23 Apr 2023 14:17:21 -0500 Subject: [PATCH] update url-downloader to fluence cli (#442) * update to fluence cli * update aqua * add config toml, update aqua script --- .../url-downloader/.fluence/aqua/workers.aqua | 21 ++++-- .../.fluence/schemas/fluence.yaml.json | 32 +++------ .../.fluence/schemas/module.yaml.json | 11 +-- .../.fluence/schemas/service.yaml.json | 22 +----- .../.fluence/schemas/workers.yaml.json | 40 +++-------- .../url-downloader/.fluence/tmp/Config.toml | 7 +- .../url-downloader/.fluence/workers.yaml | 20 ++++-- .../url-downloader/.fluence/workers.yaml.bsk | 16 ----- .../url-downloader/fluence-lock.yaml | 12 ---- marine-examples/url-downloader/fluence.yaml | 12 +--- .../url-downloader/src/aqua/main.aqua | 67 ++++++++++--------- 11 files changed, 95 insertions(+), 165 deletions(-) delete mode 100644 marine-examples/url-downloader/.fluence/workers.yaml.bsk delete mode 100644 marine-examples/url-downloader/fluence-lock.yaml diff --git a/marine-examples/url-downloader/.fluence/aqua/workers.aqua b/marine-examples/url-downloader/.fluence/aqua/workers.aqua index 942fa4c..ab6b940 100644 --- a/marine-examples/url-downloader/.fluence/aqua/workers.aqua +++ b/marine-examples/url-downloader/.fluence/aqua/workers.aqua @@ -1,18 +1,31 @@ data GetWorkersInfoDealsDefaultWorker: - installationSpells: ?u8 definition: string timestamp: string dealIdOriginal: string dealId: string chainNetwork: string - chainNetworkId: f64 + chainNetworkId: u64 data GetWorkersInfoDeals: defaultWorker: GetWorkersInfoDealsDefaultWorker +data GetWorkersInfoHostsDefaultWorkerInstallationSpells: + hostId: string + spellId: string + workerId: string + +data GetWorkersInfoHostsDefaultWorker: + definition: string + installationSpells: []GetWorkersInfoHostsDefaultWorkerInstallationSpells + timestamp: string + relayId: string + +data GetWorkersInfoHosts: + defaultWorker: GetWorkersInfoHostsDefaultWorker + data GetWorkersInfo: deals: GetWorkersInfoDeals - hosts: ?u8 + hosts: GetWorkersInfoHosts func getWorkersInfo() -> GetWorkersInfo: - <- GetWorkersInfo(deals=GetWorkersInfoDeals(defaultWorker=GetWorkersInfoDealsDefaultWorker(installationSpells=nil,definition="bafkreihndikxxxvl6r2alrfzh7awwywiolyklkwxzmzoyfcolvlxho2zuy",timestamp="2023-04-04T00:29:31.854Z",dealIdOriginal="0xd0c75aEEA62bc0ABf16F5f01361277CC8287AB0E",dealId="d0c75aeea62bc0abf16f5f01361277cc8287ab0e",chainNetwork="testnet",chainNetworkId=80001.0)),hosts=nil) + <- GetWorkersInfo(deals=GetWorkersInfoDeals(defaultWorker=GetWorkersInfoDealsDefaultWorker(definition="bafkreicdordcic2qmd2pnacl5adffsuhwg4eleu4prcgaldjvzr6ds2f2m",timestamp="2023-04-23T07:01:18.682Z",dealIdOriginal="0x9d7503E13Bc2d3430536e3d5D635D8172141d884",dealId="9d7503e13bc2d3430536e3d5d635d8172141d884",chainNetwork="testnet",chainNetworkId=1313161555)),hosts=GetWorkersInfoHosts(defaultWorker=GetWorkersInfoHostsDefaultWorker(definition="bafkreicdordcic2qmd2pnacl5adffsuhwg4eleu4prcgaldjvzr6ds2f2m",installationSpells=[GetWorkersInfoHostsDefaultWorkerInstallationSpells(hostId="12D3KooWJ4bTHirdTFNZpCS72TAzwtdmavTBkkEXtzo6wHL25CtE",spellId="039f4e06-923e-4a21-8814-8164fa9b137c",workerId="12D3KooWKsxVXgnpL4wrTts9d49jiNSEN1auaxotdMYa4HpFS66g")],timestamp="2023-04-23T07:00:05.549Z",relayId="12D3KooWAKNos2KogexTXhrkMZzFYpLHuWJ4PgoAhurSAv7o5CWA"))) diff --git a/marine-examples/url-downloader/.fluence/schemas/fluence.yaml.json b/marine-examples/url-downloader/.fluence/schemas/fluence.yaml.json index ad9c9b2..b7d5437 100644 --- a/marine-examples/url-downloader/.fluence/schemas/fluence.yaml.json +++ b/marine-examples/url-downloader/.fluence/schemas/fluence.yaml.json @@ -48,16 +48,7 @@ "nullable": true, "required": [], "title": "Volumes", - "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)" - }, - "preopenedFiles": { - "type": "array", - "title": "Preopened files", - "description": "A list of files and directories that this module could access with WASI", - "items": { - "type": "string" - }, - "nullable": true + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file" }, "envs": { "type": "object", @@ -153,16 +144,7 @@ "nullable": true, "required": [], "title": "Volumes", - "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)" - }, - "preopenedFiles": { - "type": "array", - "title": "Preopened files", - "description": "A list of files and directories that this module could access with WASI", - "items": { - "type": "string" - }, - "nullable": true + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file" }, "envs": { "type": "object", @@ -257,7 +239,7 @@ "type": "object", "title": "Dependencies", "nullable": true, - "description": "A map of dependency versions", + "description": "(For advanced users) Overrides for the project dependencies", "properties": { "npm": { "type": "object", @@ -463,6 +445,14 @@ ] }, "required": [] + }, + "aquaImports": { + "type": "array", + "description": "A list of path to be considered by aqua compiler to be used as imports. First dependency in the list has the highest priority. Priority of imports is considered in the following order: imports from --import flags, imports from aquaImports property in fluence.yaml, project's .fluence/aqua dir, npm dependencies from fluence.yaml, npm dependencies from user's .fluence/config.yaml, npm dependencies recommended by fluence", + "items": { + "type": "string" + }, + "nullable": true } }, "required": [ diff --git a/marine-examples/url-downloader/.fluence/schemas/module.yaml.json b/marine-examples/url-downloader/.fluence/schemas/module.yaml.json index 910e6e2..1ac8895 100644 --- a/marine-examples/url-downloader/.fluence/schemas/module.yaml.json +++ b/marine-examples/url-downloader/.fluence/schemas/module.yaml.json @@ -38,16 +38,7 @@ "nullable": true, "required": [], "title": "Volumes", - "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)" - }, - "preopenedFiles": { - "type": "array", - "title": "Preopened files", - "description": "A list of files and directories that this module could access with WASI", - "items": { - "type": "string" - }, - "nullable": true + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file" }, "envs": { "type": "object", diff --git a/marine-examples/url-downloader/.fluence/schemas/service.yaml.json b/marine-examples/url-downloader/.fluence/schemas/service.yaml.json index dc51e68..7f24ba2 100644 --- a/marine-examples/url-downloader/.fluence/schemas/service.yaml.json +++ b/marine-examples/url-downloader/.fluence/schemas/service.yaml.json @@ -40,16 +40,7 @@ "nullable": true, "required": [], "title": "Volumes", - "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)" - }, - "preopenedFiles": { - "type": "array", - "title": "Preopened files", - "description": "A list of files and directories that this module could access with WASI", - "items": { - "type": "string" - }, - "nullable": true + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file" }, "envs": { "type": "object", @@ -99,16 +90,7 @@ "nullable": true, "required": [], "title": "Volumes", - "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file. (This property replaces the legacy \"mapped_dirs\" property so there is no need to duplicate the same paths in \"preopenedFiles\" dir)" - }, - "preopenedFiles": { - "type": "array", - "title": "Preopened files", - "description": "A list of files and directories that this module could access with WASI", - "items": { - "type": "string" - }, - "nullable": true + "description": "A map of accessible files and their aliases. Aliases should be used in Marine module development because it's hard to know the full path to a file" }, "envs": { "type": "object", diff --git a/marine-examples/url-downloader/.fluence/schemas/workers.yaml.json b/marine-examples/url-downloader/.fluence/schemas/workers.yaml.json index eb35275..5451c70 100644 --- a/marine-examples/url-downloader/.fluence/schemas/workers.yaml.json +++ b/marine-examples/url-downloader/.fluence/schemas/workers.yaml.json @@ -14,29 +14,6 @@ "additionalProperties": { "type": "object", "properties": { - "installation_spells": { - "type": "array", - "description": "A list of installation spells", - "items": { - "type": "object", - "properties": { - "host_id": { - "type": "string" - }, - "spell_id": { - "type": "string" - }, - "worker_id": { - "type": "string" - } - }, - "required": [ - "host_id", - "spell_id", - "worker_id" - ] - } - }, "definition": { "type": "string" }, @@ -62,7 +39,6 @@ } }, "required": [ - "installation_spells", "timestamp", "definition", "dealId", @@ -80,6 +56,13 @@ "additionalProperties": { "type": "object", "properties": { + "definition": { + "type": "string" + }, + "timestamp": { + "type": "string", + "description": "ISO timestamp of the time when the worker was deployed" + }, "installation_spells": { "type": "array", "description": "A list of installation spells", @@ -103,21 +86,14 @@ ] } }, - "definition": { - "type": "string" - }, - "timestamp": { - "type": "string", - "description": "ISO timestamp of the time when the worker was deployed" - }, "relayId": { "type": "string" } }, "required": [ - "installation_spells", "timestamp", "definition", + "installation_spells", "relayId" ] }, diff --git a/marine-examples/url-downloader/.fluence/tmp/Config.toml b/marine-examples/url-downloader/.fluence/tmp/Config.toml index 3f0eb62..cb38309 100644 --- a/marine-examples/url-downloader/.fluence/tmp/Config.toml +++ b/marine-examples/url-downloader/.fluence/tmp/Config.toml @@ -3,11 +3,8 @@ name = "local_storage" load_from = "/Users/bebo/localdev/examples/marine-examples/url-downloader/target/wasm32-wasi/release/local_storage.wasm" logger_enabled = true - [module.wasi] - preopened_files = [ "./tmp" ] - - [module.wasi.mapped_dirs] - sites = "./tmp" +[module.wasi.mapped_dirs] +sites = "./tmp" [[module]] name = "curl_adapter" diff --git a/marine-examples/url-downloader/.fluence/workers.yaml b/marine-examples/url-downloader/.fluence/workers.yaml index bffc3f5..603a239 100644 --- a/marine-examples/url-downloader/.fluence/workers.yaml +++ b/marine-examples/url-downloader/.fluence/workers.yaml @@ -5,12 +5,20 @@ # Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/workers.md version: 0 +hosts: + defaultWorker: + definition: bafkreicdordcic2qmd2pnacl5adffsuhwg4eleu4prcgaldjvzr6ds2f2m + installation_spells: + - host_id: 12D3KooWJ4bTHirdTFNZpCS72TAzwtdmavTBkkEXtzo6wHL25CtE + spell_id: 039f4e06-923e-4a21-8814-8164fa9b137c + worker_id: 12D3KooWKsxVXgnpL4wrTts9d49jiNSEN1auaxotdMYa4HpFS66g + timestamp: 2023-04-23T07:00:05.549Z + relayId: 12D3KooWAKNos2KogexTXhrkMZzFYpLHuWJ4PgoAhurSAv7o5CWA deals: defaultWorker: - installation_spells: [] - definition: bafkreihndikxxxvl6r2alrfzh7awwywiolyklkwxzmzoyfcolvlxho2zuy - timestamp: 2023-04-04T00:29:31.854Z - dealIdOriginal: "0xd0c75aEEA62bc0ABf16F5f01361277CC8287AB0E" - dealId: d0c75aeea62bc0abf16f5f01361277cc8287ab0e + definition: bafkreicdordcic2qmd2pnacl5adffsuhwg4eleu4prcgaldjvzr6ds2f2m + timestamp: 2023-04-23T07:01:18.682Z + dealIdOriginal: "0x9d7503E13Bc2d3430536e3d5D635D8172141d884" + dealId: 9d7503e13bc2d3430536e3d5d635d8172141d884 chainNetwork: testnet - chainNetworkId: 80001 + chainNetworkId: 1313161555 diff --git a/marine-examples/url-downloader/.fluence/workers.yaml.bsk b/marine-examples/url-downloader/.fluence/workers.yaml.bsk deleted file mode 100644 index a2288b9..0000000 --- a/marine-examples/url-downloader/.fluence/workers.yaml.bsk +++ /dev/null @@ -1,16 +0,0 @@ -# yaml-language-server: $schema=schemas/workers.yaml.json - -# A result of app deployment. This file is created automatically after successful deployment using `fluence workers deploy` command - -# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/workers.md - -version: 0 -deals: - defaultWorker: - installation_spells: [] - definition: bafkreigvh7cxlf5nkisqqxq6alpoj32l44ttxkfxafa6agp2u344kl3k4m - timestamp: 2023-04-03T22:37:49.594Z - dealIdOriginal: "0xEA6f3D3177c40123C7B8B1d89440F1DdcfA6014B" - dealId: ea6f3d3177c40123c7b8b1d89440f1ddcfa6014b - chainNetwork: testnet - chainNetworkId: 80001 diff --git a/marine-examples/url-downloader/fluence-lock.yaml b/marine-examples/url-downloader/fluence-lock.yaml deleted file mode 100644 index 69232f2..0000000 --- a/marine-examples/url-downloader/fluence-lock.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# yaml-language-server: $schema=.fluence/schemas/fluence-lock.yaml.json - -# Defines a lock file for Fluence Project dependencies. When dependencies are installed - their exact versions are saved here. - -# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/fluence-lock.md - -version: 0 -npm: - "@fluencelabs/aqua": 0.10.3 - "@fluencelabs/aqua-lib": 0.6.0 - "@fluencelabs/spell": 0.5.7 - "@fluencelabs/registry": 0.8.2 diff --git a/marine-examples/url-downloader/fluence.yaml b/marine-examples/url-downloader/fluence.yaml index 877e387..90cc013 100644 --- a/marine-examples/url-downloader/fluence.yaml +++ b/marine-examples/url-downloader/fluence.yaml @@ -7,14 +7,8 @@ version: 2 aquaInputPath: src/aqua/main.aqua dependencies: - npm: - "@fluencelabs/aqua": 0.10.3 - "@fluencelabs/aqua-lib": 0.6.0 - "@fluencelabs/spell": 0.5.7 - "@fluencelabs/registry": 0.8.2 cargo: - marine: 0.14.0 - mrepl: 0.21.2 + mrepl: 0.21.3 workers: defaultWorker: services: [ url_downloader ] @@ -25,8 +19,8 @@ deals: hosts: defaultWorker: peerIds: - - 12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr -relays: kras + - 12D3KooWJ4bTHirdTFNZpCS72TAzwtdmavTBkkEXtzo6wHL25CtE #stage +relays: stage services: url_downloader: get: service diff --git a/marine-examples/url-downloader/src/aqua/main.aqua b/marine-examples/url-downloader/src/aqua/main.aqua index 4a5551d..093352f 100644 --- a/marine-examples/url-downloader/src/aqua/main.aqua +++ b/marine-examples/url-downloader/src/aqua/main.aqua @@ -1,52 +1,59 @@ -import "workers.aqua" -import "services.aqua" import "@fluencelabs/aqua-lib/builtin.aqua" import "@fluencelabs/registry/subnetwork.aqua" import Registry, Record from "@fluencelabs/registry/registry-service.aqua" import "@fluencelabs/spell/spell_service.aqua" -export get_and_save, put, put_all, get, worker_n +import "workers.aqua" +import "services.aqua" +export put, get +export put_workers, get_workers, get_and_save_workers func getWorkers() -> []Record: workersInfo <- getWorkersInfo() dealId = workersInfo.deals.defaultWorker.dealId - on HOST_PEER_ID: - workersOp <- resolveSubnetwork(dealId) + workersOp <- resolveSubnetwork(dealId) <- workersOp! -func worker_n() -> u32: - workers <- getWorkers() - <- workers.length - -func get_and_save(url: string, fname: string) -> string: - workers <- getWorkers() - w = workers[8] - on w.metadata.peer_id via w.metadata.relay_id: - res = UrlDownloader.get_n_save(url, fname) - <- res - -func put_all(file_name: string, file_content: []u8) -> []string: - res: *string - workers <- getWorkers() - for w <- workers: - on w.metadata.peer_id via w.metadata.relay_id: - try: - res <- UrlDownloader.put(file_name, file_content) - catch e: - res <<- "failed to execute" - <- res - func put(file_name: string, file_content: []u8) -> string: workers <- getWorkers() - w = workers[1] + w = workers[0] on w.metadata.peer_id via w.metadata.relay_id: res <- UrlDownloader.put(file_name, file_content) <- res + func get(file_name: string) -> []u8: workers <- getWorkers() - w = workers[5] - on w.metadata.peer_id via w.metadata.relay_id: + w = workers[0] + on w.metadata.peer_id via w.metadata.relay_id: res <- UrlDownloader.get(file_name) + <- res + +func get_and_save(url: string, fname: string) -> string: + workers <- getWorkers() + w = workers[0] + on w.metadata.peer_id via w.metadata.relay_id: + res = UrlDownloader.get_n_save(url, fname) + <- res + +func put_workers(file_name: string, file_content: []u8) -> string: + info <- getWorkersInfo() + spell = info.hosts.defaultWorker.installationSpells[0] + on spell.workerId via spell.hostId: + res <- UrlDownloader.put(file_name, file_content) + <- res + +func get_workers(file_name: string) -> []u8: + info <- getWorkersInfo() + spell = info.hosts.defaultWorker.installationSpells[0] + on spell.workerId via spell.hostId: + res <- UrlDownloader.get(file_name) + <- res + +func get_and_save_workers(url: string, fname: string) -> string: + info <- getWorkersInfo() + spell = info.hosts.defaultWorker.installationSpells[0] + on spell.workerId via spell.hostId: + res = UrlDownloader.get_n_save(url, fname) <- res \ No newline at end of file