Quellcode durchsuchen

storage-node-v2: Add `version` endpoint

Shamil Gadelshin vor 3 Jahren
Ursprung
Commit
645777ec1b

+ 34 - 18
storage-node-v2/README.md

@@ -30,7 +30,7 @@ USAGE
 <!-- commands -->
 * [`storage-node dev:init`](#storage-node-devinit)
 * [`storage-node dev:multihash`](#storage-node-devmultihash)
-* [`storage-node dev:sync [FILE]`](#storage-node-devsync-file)
+* [`storage-node dev:sync`](#storage-node-devsync)
 * [`storage-node dev:upload`](#storage-node-devupload)
 * [`storage-node dev:verify-bag-id`](#storage-node-devverify-bag-id)
 * [`storage-node help [COMMAND]`](#storage-node-help-command)
@@ -50,7 +50,7 @@ USAGE
 * [`storage-node operator:set-bucket-limits`](#storage-node-operatorset-bucket-limits)
 * [`storage-node operator:set-metadata`](#storage-node-operatorset-metadata)
 * [`storage-node operator:update-bucket-status`](#storage-node-operatorupdate-bucket-status)
-* [`storage-node server [FILE]`](#storage-node-server-file)
+* [`storage-node server`](#storage-node-server)
 
 ## `storage-node dev:init`
 
@@ -85,18 +85,26 @@ OPTIONS
 
 _See code: [src/commands/dev/multihash.ts](https://github.com/Joystream/joystream/blob/v0.1.0/src/commands/dev/multihash.ts)_
 
-## `storage-node dev:sync [FILE]`
+## `storage-node dev:sync`
 
-describe the command here
+Synchronizes data - it fixes the differences between local data folder and worker ID obligations from the runtime.
 
 ```
 USAGE
-  $ storage-node dev:sync [FILE]
+  $ storage-node dev:sync
 
 OPTIONS
-  -f, --force
-  -h, --help       show CLI help
-  -n, --name=name  name to print
+  -d, --uploads=uploads                                (required) Data uploading directory (absolute path).
+  -h, --help                                           show CLI help
+
+  -o, --dataSourceOperatorHost=dataSourceOperatorHost  Storage node host and port (e.g.: some.com:8081) to get data
+                                                       from.
+
+  -p, --syncWorkersNumber=syncWorkersNumber            Sync workers number (max async operations in progress).
+
+  -q, --queryNodeHost=queryNodeHost                    Query node host and port (e.g.: some.com:8081)
+
+  -w, --workerId=workerId                              (required) Storage node operator worker ID.
 ```
 
 _See code: [src/commands/dev/sync.ts](https://github.com/Joystream/joystream/blob/v0.1.0/src/commands/dev/sync.ts)_
@@ -529,24 +537,32 @@ OPTIONS
 
 _See code: [src/commands/operator/update-bucket-status.ts](https://github.com/Joystream/joystream/blob/v0.1.0/src/commands/operator/update-bucket-status.ts)_
 
-## `storage-node server [FILE]`
+## `storage-node server`
 
 Starts the storage node server.
 
 ```
 USAGE
-  $ storage-node server [FILE]
+  $ storage-node server
 
 OPTIONS
-  -d, --uploads=uploads    (required) Data uploading directory (absolute path).
-  -h, --help               show CLI help
-  -k, --keyfile=keyfile    Key file for the account. Mandatory in non-dev environment.
-  -m, --dev                Use development mode
-  -o, --port=port          (required) Server port.
-  -p, --password=password  Key file password (optional).
-  -u, --apiUrl=apiUrl      Runtime API URL. Mandatory in non-dev environment. Default is ws://localhost:9944
-  -w, --worker=worker      (required) Storage provider worker ID
+  -d, --uploads=uploads                      (required) Data uploading directory (absolute path).
+  -h, --help                                 show CLI help
+  -i, --syncInterval=syncInterval            [default: 1] Interval between syncronizations (in minutes)
+  -k, --keyfile=keyfile                      Key file for the account. Mandatory in non-dev environment.
+  -m, --dev                                  Use development mode
+  -o, --port=port                            (required) Server port.
+  -p, --password=password                    Key file password (optional).
+  -q, --queryNodeHost=queryNodeHost          Query node host and port (e.g.: some.com:8081)
+  -r, --syncWorkersNumber=syncWorkersNumber  [default: 20] Sync workers number (max async operations in progress).
+  -s, --sync                                 Enable data synchronization.
+
+  -u, --apiUrl=apiUrl                        Runtime API URL. Mandatory in non-dev environment. Default is
+                                             ws://localhost:9944
+
+  -w, --worker=worker                        (required) Storage provider worker ID
 ```
 
 _See code: [src/commands/server.ts](https://github.com/Joystream/joystream/blob/v0.1.0/src/commands/server.ts)_
+
 <!-- commandsstop -->

+ 2 - 2
storage-node-v2/scripts/generate-test-data.ts

@@ -8,9 +8,9 @@ import { exit } from 'process'
 
 async function doJob(): Promise<void> {
   const uploadDirectory = '/Users/shamix/uploads2'
-  const fileSize = 100
+  const fileSize = 100000000
 
-  const objectNumber = 3000
+  const objectNumber = 100
   const bagNumber = 10
   const bucketNumber = 10
 

+ 24 - 1
storage-node-v2/src/api-spec/openapi.yaml

@@ -186,7 +186,7 @@ paths:
       operationId: publicApi.getAllLocalDataObjects
       description: Returns all local data objects.
       tags:
-        - public
+        - state
       responses:
         200:
           description: Ok
@@ -197,6 +197,20 @@ paths:
                 items:
                   type: string
 
+  /version:
+    get:
+      operationId: publicApi.getVersion
+      description: Returns server version.
+      tags:
+        - state
+      responses:
+        200:
+          description: Ok
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/VersionResponse'
+
 components:
   securitySchemes:
     UploadAuth:
@@ -242,4 +256,13 @@ components:
         type:
           type: string
         message:
+          type: string    
+    VersionResponse:
+      type: object
+      required:
+        - version
+      properties:
+        version:
+          type: string
+        userAgent:
           type: string

+ 6 - 1
storage-node-v2/src/services/webApi/app.ts

@@ -26,7 +26,11 @@ export async function createApp(
   account: KeyringPair,
   workerId: number,
   uploadsDir: string,
-  maxFileSize: number
+  maxFileSize: number,
+  config: {
+    version: string,
+    userAgent: string
+  }
 ): Promise<Express> {
   const spec = path.join(__dirname, './../../api-spec/openapi.yaml')
 
@@ -43,6 +47,7 @@ export async function createApp(
       res.locals.storageProviderAccount = account
       res.locals.workerId = workerId
       res.locals.api = api
+      res.locals.config = config
       next()
     },
     // Setup OpenAPiValidator

+ 44 - 6
storage-node-v2/src/services/webApi/controllers/publicApi.ts

@@ -179,7 +179,7 @@ export async function authTokenForUploading(req: express.Request, res: express.R
  *
  * @remarks
  * This is a helper function. It parses the request object for a variable and
- * throws an error on failier.
+ * throws an error on failure.
  */
 function getFileObject(req: express.Request): Express.Multer.File {
   if (req.file) {
@@ -214,7 +214,7 @@ function getWorkerId(res: express.Response): number {
  *
  * @remarks
  * This is a helper function. It parses the response object for a variable and
- * throws an error on failier.
+ * throws an error on failure.
  */
 function getUploadsDir(res: express.Response): string {
   if (res.locals.uploadsDir) {
@@ -229,7 +229,7 @@ function getUploadsDir(res: express.Response): string {
  *
  * @remarks
  * This is a helper function. It parses the response object for a variable and
- * throws an error on failier.
+ * throws an error on failure.
  */
 function getAccount(res: express.Response): KeyringPair {
   if (res.locals.storageProviderAccount) {
@@ -244,7 +244,7 @@ function getAccount(res: express.Response): KeyringPair {
  *
  * @remarks
  * This is a helper function. It parses the response object for a variable and
- * throws an error on failier.
+ * throws an error on failure.
  */
 function getApi(res: express.Response): ApiPromise {
   if (res.locals.api) {
@@ -259,7 +259,7 @@ function getApi(res: express.Response): ApiPromise {
  *
  * @remarks
  * This is a helper function. It parses the request object for a variable and
- * throws an error on failier.
+ * throws an error on failure.
  */
 function getCid(req: express.Request): string {
   const cid = req.params.cid || ''
@@ -275,7 +275,7 @@ function getCid(req: express.Request): string {
  *
  * @remarks
  * This is a helper function. It parses the request object for a variable and
- * throws an error on failier.
+ * throws an error on failure.
  */
 function getTokenRequest(req: express.Request): UploadTokenRequest {
   const tokenRequest = req.body as UploadTokenRequest
@@ -452,4 +452,42 @@ export async function getAllLocalDataObjects(
       message: err.toString(),
     })
   }
+}
+
+/**
+ * A public endpoint: return the server version.
+ */
+export async function getVersion(
+  req: express.Request,
+  res: express.Response
+): Promise<void> {
+  try {
+    const config = getCommandConfig(res)
+
+    // Copy from an object, because the actual object could contain more data.
+    res.status(200).json({
+      version: config.version,
+      userAgent: config.userAgent,
+    })
+  } catch (err) {
+    res.status(500).json({
+      type: 'version',
+      message: err.toString(),
+    })
+  }
+}
+
+/**
+ * Returns a command config.
+ *
+ * @remarks
+ * This is a helper function. It parses the response object for a variable and
+ * throws an error on failure.
+ */
+ function getCommandConfig(res: express.Response): {version: string, userAgent: string} {
+  if (res.locals.config) {
+    return res.locals.config
+  }
+
+  throw new Error('No upload directory path loaded.')
 }

+ 0 - 17
storage-node-v2/test/commands/dev/sync.test.ts

@@ -1,17 +0,0 @@
-import {expect, test} from '@oclif/test'
-
-describe('dev:sync', () => {
-  test
-  .stdout()
-  .command(['dev:sync'])
-  .it('runs hello', ctx => {
-    expect(ctx.stdout).to.contain('hello world')
-  })
-
-  test
-  .stdout()
-  .command(['dev:sync', '--name', 'jeff'])
-  .it('runs hello --name jeff', ctx => {
-    expect(ctx.stdout).to.contain('hello jeff')
-  })
-})