From 2d012ad1b9e0f92980ea59a4fd4b7bf70932c83b Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 28 Nov 2023 14:32:11 +0100 Subject: [PATCH] add cluster health --- .openapi-generator/FILES | 3 + README.md | 6 +- docs/GetHealth200Response.md | 16 +++ docs/NodesApi.md | 53 ++++++++- src/api/NodesApi.js | 50 ++++++++- src/index.js | 7 ++ src/model/GetHealth200Response.js | 143 ++++++++++++++++++++++++ test/model/GetHealth200Response.spec.js | 107 ++++++++++++++++++ 8 files changed, 375 insertions(+), 10 deletions(-) create mode 100644 docs/GetHealth200Response.md create mode 100644 src/model/GetHealth200Response.js create mode 100644 test/model/GetHealth200Response.spec.js diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index 621e0d9..c549c53 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -16,6 +16,7 @@ docs/ClusterLayout.md docs/CreateBucketRequest.md docs/CreateBucketRequestLocalAlias.md docs/CreateBucketRequestLocalAliasAllow.md +docs/GetHealth200Response.md docs/GetNodes200Response.md docs/ImportKeyRequest.md docs/KeyApi.md @@ -62,6 +63,7 @@ src/model/ClusterLayout.js src/model/CreateBucketRequest.js src/model/CreateBucketRequestLocalAlias.js src/model/CreateBucketRequestLocalAliasAllow.js +src/model/GetHealth200Response.js src/model/GetNodes200Response.js src/model/ImportKeyRequest.js src/model/KeyInfo.js @@ -83,3 +85,4 @@ src/model/UpdateBucketRequestWebsiteAccess.js src/model/UpdateKeyRequest.js src/model/UpdateKeyRequestAllow.js src/model/UpdateKeyRequestDeny.js +test/model/GetHealth200Response.spec.js diff --git a/README.md b/README.md index 819a743..42b0393 100644 --- a/README.md +++ b/README.md @@ -146,8 +146,9 @@ Class | Method | HTTP request | Description *garage.LayoutApi* | [**applyLayout**](docs/LayoutApi.md#applyLayout) | **POST** /layout/apply | Apply staged layout *garage.LayoutApi* | [**getLayout**](docs/LayoutApi.md#getLayout) | **GET** /layout | Details on the current and staged layout *garage.LayoutApi* | [**revertLayout**](docs/LayoutApi.md#revertLayout) | **POST** /layout/revert | Clear staged layout -*garage.NodesApi* | [**addNode**](docs/NodesApi.md#addNode) | **POST** /connect | Connect target node to other Garage nodes -*garage.NodesApi* | [**getNodes**](docs/NodesApi.md#getNodes) | **GET** /status | Status of this node and other nodes in the cluster +*garage.NodesApi* | [**addNode**](docs/NodesApi.md#addNode) | **POST** /connect | Connect a new node +*garage.NodesApi* | [**getHealth**](docs/NodesApi.md#getHealth) | **GET** /health | Cluster health report +*garage.NodesApi* | [**getNodes**](docs/NodesApi.md#getNodes) | **GET** /status | Describe cluster ## Documentation for Models @@ -165,6 +166,7 @@ Class | Method | HTTP request | Description - [garage.CreateBucketRequest](docs/CreateBucketRequest.md) - [garage.CreateBucketRequestLocalAlias](docs/CreateBucketRequestLocalAlias.md) - [garage.CreateBucketRequestLocalAliasAllow](docs/CreateBucketRequestLocalAliasAllow.md) + - [garage.GetHealth200Response](docs/GetHealth200Response.md) - [garage.GetNodes200Response](docs/GetNodes200Response.md) - [garage.ImportKeyRequest](docs/ImportKeyRequest.md) - [garage.KeyInfo](docs/KeyInfo.md) diff --git a/docs/GetHealth200Response.md b/docs/GetHealth200Response.md new file mode 100644 index 0000000..b8dc1fd --- /dev/null +++ b/docs/GetHealth200Response.md @@ -0,0 +1,16 @@ +# garage.GetHealth200Response + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**status** | **String** | | +**knownNodes** | **Number** | | +**connectedNodes** | **Number** | | +**storageNodes** | **Number** | | +**storageNodesOk** | **Number** | | +**partitions** | **Number** | | +**partitionsQuorum** | **Number** | | +**partitionsAllOk** | **Number** | | + + diff --git a/docs/NodesApi.md b/docs/NodesApi.md index 78cf6bb..d4a2764 100644 --- a/docs/NodesApi.md +++ b/docs/NodesApi.md @@ -4,8 +4,9 @@ All URIs are relative to *http://localhost:3903/v1* Method | HTTP request | Description ------------- | ------------- | ------------- -[**addNode**](NodesApi.md#addNode) | **POST** /connect | Connect target node to other Garage nodes -[**getNodes**](NodesApi.md#getNodes) | **GET** /status | Status of this node and other nodes in the cluster +[**addNode**](NodesApi.md#addNode) | **POST** /connect | Connect a new node +[**getHealth**](NodesApi.md#getHealth) | **GET** /health | Cluster health report +[**getNodes**](NodesApi.md#getNodes) | **GET** /status | Describe cluster @@ -13,7 +14,7 @@ Method | HTTP request | Description > [AddNode200ResponseInner] addNode(requestBody) -Connect target node to other Garage nodes +Connect a new node Instructs this Garage node to connect to other Garage nodes at specified `<node_id>@<net_address>`. `node_id` is generated automatically on node start. @@ -57,11 +58,55 @@ Name | Type | Description | Notes - **Accept**: application/json +## getHealth + +> GetHealth200Response getHealth() + +Cluster health report + +Returns the global status of the cluster, the number of connected nodes (over the number of known ones), the number of healthy storage nodes (over the declared ones), and the number of healthy partitions (over the total). + +### Example + +```javascript +import garage from 'garage_administration_api_v0garage_v0_9_0'; +let defaultClient = garage.ApiClient.instance; +// Configure Bearer access token for authorization: bearerAuth +let bearerAuth = defaultClient.authentications['bearerAuth']; +bearerAuth.accessToken = "YOUR ACCESS TOKEN" + +let apiInstance = new garage.NodesApi(); +apiInstance.getHealth().then((data) => { + console.log('API called successfully. Returned data: ' + data); +}, (error) => { + console.error(error); +}); + +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**GetHealth200Response**](GetHealth200Response.md) + +### Authorization + +[bearerAuth](../README.md#bearerAuth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + + ## getNodes > GetNodes200Response getNodes() -Status of this node and other nodes in the cluster +Describe cluster Returns the cluster's current status, including: - ID of the node being queried and its version of the Garage daemon - Live nodes - Currently configured cluster layout - Staged changes to the cluster layout *Capacity is given in bytes* diff --git a/src/api/NodesApi.js b/src/api/NodesApi.js index 66f9756..ce94ef8 100644 --- a/src/api/NodesApi.js +++ b/src/api/NodesApi.js @@ -14,6 +14,7 @@ import ApiClient from "../ApiClient"; import AddNode200ResponseInner from '../model/AddNode200ResponseInner'; +import GetHealth200Response from '../model/GetHealth200Response'; import GetNodes200Response from '../model/GetNodes200Response'; /** @@ -37,7 +38,7 @@ export default class NodesApi { /** - * Connect target node to other Garage nodes + * Connect a new node * Instructs this Garage node to connect to other Garage nodes at specified `@`. `node_id` is generated automatically on node start. * @param {Array.} requestBody * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link Array.} and HTTP response @@ -70,7 +71,7 @@ export default class NodesApi { } /** - * Connect target node to other Garage nodes + * Connect a new node * Instructs this Garage node to connect to other Garage nodes at specified `@`. `node_id` is generated automatically on node start. * @param {Array.} requestBody * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link Array.} @@ -84,7 +85,48 @@ export default class NodesApi { /** - * Status of this node and other nodes in the cluster + * Cluster health report + * Returns the global status of the cluster, the number of connected nodes (over the number of known ones), the number of healthy storage nodes (over the declared ones), and the number of healthy partitions (over the total). + * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/GetHealth200Response} and HTTP response + */ + getHealthWithHttpInfo() { + let postBody = null; + + let pathParams = { + }; + let queryParams = { + }; + let headerParams = { + }; + let formParams = { + }; + + let authNames = ['bearerAuth']; + let contentTypes = []; + let accepts = ['application/json']; + let returnType = GetHealth200Response; + return this.apiClient.callApi( + '/health', 'GET', + pathParams, queryParams, headerParams, formParams, postBody, + authNames, contentTypes, accepts, returnType, null + ); + } + + /** + * Cluster health report + * Returns the global status of the cluster, the number of connected nodes (over the number of known ones), the number of healthy storage nodes (over the declared ones), and the number of healthy partitions (over the total). + * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/GetHealth200Response} + */ + getHealth() { + return this.getHealthWithHttpInfo() + .then(function(response_and_data) { + return response_and_data.data; + }); + } + + + /** + * Describe cluster * Returns the cluster's current status, including: - ID of the node being queried and its version of the Garage daemon - Live nodes - Currently configured cluster layout - Staged changes to the cluster layout *Capacity is given in bytes* * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/GetNodes200Response} and HTTP response */ @@ -112,7 +154,7 @@ export default class NodesApi { } /** - * Status of this node and other nodes in the cluster + * Describe cluster * Returns the cluster's current status, including: - ID of the node being queried and its version of the Garage daemon - Live nodes - Currently configured cluster layout - Staged changes to the cluster layout *Capacity is given in bytes* * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/GetNodes200Response} */ diff --git a/src/index.js b/src/index.js index ee07b9c..5c4a58c 100644 --- a/src/index.js +++ b/src/index.js @@ -26,6 +26,7 @@ import ClusterLayout from './model/ClusterLayout'; import CreateBucketRequest from './model/CreateBucketRequest'; import CreateBucketRequestLocalAlias from './model/CreateBucketRequestLocalAlias'; import CreateBucketRequestLocalAliasAllow from './model/CreateBucketRequestLocalAliasAllow'; +import GetHealth200Response from './model/GetHealth200Response'; import GetNodes200Response from './model/GetNodes200Response'; import ImportKeyRequest from './model/ImportKeyRequest'; import KeyInfo from './model/KeyInfo'; @@ -169,6 +170,12 @@ export { */ CreateBucketRequestLocalAliasAllow, + /** + * The GetHealth200Response model constructor. + * @property {module:model/GetHealth200Response} + */ + GetHealth200Response, + /** * The GetNodes200Response model constructor. * @property {module:model/GetNodes200Response} diff --git a/src/model/GetHealth200Response.js b/src/model/GetHealth200Response.js new file mode 100644 index 0000000..e626cc8 --- /dev/null +++ b/src/model/GetHealth200Response.js @@ -0,0 +1,143 @@ +/** + * Garage Administration API v0+garage-v0.9.0 + * Administrate your Garage cluster programatically, including status, layout, keys, buckets, and maintainance tasks. *Disclaimer: The API is not stable yet, hence its v0 tag. The API can change at any time, and changes can include breaking backward compatibility. Read the changelog and upgrade your scripts before upgrading. Additionnaly, this specification is very early stage and can contain bugs, especially on error return codes/types that are not tested yet. Do not expect a well finished and polished product!* + * + * The version of the OpenAPI document: v0.9.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + * + */ + +import ApiClient from '../ApiClient'; + +/** + * The GetHealth200Response model module. + * @module model/GetHealth200Response + * @version v0.9.0 + */ +class GetHealth200Response { + /** + * Constructs a new GetHealth200Response. + * @alias module:model/GetHealth200Response + * @param status {String} + * @param knownNodes {Number} + * @param connectedNodes {Number} + * @param storageNodes {Number} + * @param storageNodesOk {Number} + * @param partitions {Number} + * @param partitionsQuorum {Number} + * @param partitionsAllOk {Number} + */ + constructor(status, knownNodes, connectedNodes, storageNodes, storageNodesOk, partitions, partitionsQuorum, partitionsAllOk) { + + GetHealth200Response.initialize(this, status, knownNodes, connectedNodes, storageNodes, storageNodesOk, partitions, partitionsQuorum, partitionsAllOk); + } + + /** + * Initializes the fields of this object. + * This method is used by the constructors of any subclasses, in order to implement multiple inheritance (mix-ins). + * Only for internal use. + */ + static initialize(obj, status, knownNodes, connectedNodes, storageNodes, storageNodesOk, partitions, partitionsQuorum, partitionsAllOk) { + obj['status'] = status; + obj['knownNodes'] = knownNodes; + obj['connectedNodes'] = connectedNodes; + obj['storageNodes'] = storageNodes; + obj['storageNodesOk'] = storageNodesOk; + obj['partitions'] = partitions; + obj['partitionsQuorum'] = partitionsQuorum; + obj['partitionsAllOk'] = partitionsAllOk; + } + + /** + * Constructs a GetHealth200Response from a plain JavaScript object, optionally creating a new instance. + * Copies all relevant properties from data to obj if supplied or a new instance if not. + * @param {Object} data The plain JavaScript object bearing properties of interest. + * @param {module:model/GetHealth200Response} obj Optional instance to populate. + * @return {module:model/GetHealth200Response} The populated GetHealth200Response instance. + */ + static constructFromObject(data, obj) { + if (data) { + obj = obj || new GetHealth200Response(); + + if (data.hasOwnProperty('status')) { + obj['status'] = ApiClient.convertToType(data['status'], 'String'); + } + if (data.hasOwnProperty('knownNodes')) { + obj['knownNodes'] = ApiClient.convertToType(data['knownNodes'], 'Number'); + } + if (data.hasOwnProperty('connectedNodes')) { + obj['connectedNodes'] = ApiClient.convertToType(data['connectedNodes'], 'Number'); + } + if (data.hasOwnProperty('storageNodes')) { + obj['storageNodes'] = ApiClient.convertToType(data['storageNodes'], 'Number'); + } + if (data.hasOwnProperty('storageNodesOk')) { + obj['storageNodesOk'] = ApiClient.convertToType(data['storageNodesOk'], 'Number'); + } + if (data.hasOwnProperty('partitions')) { + obj['partitions'] = ApiClient.convertToType(data['partitions'], 'Number'); + } + if (data.hasOwnProperty('partitionsQuorum')) { + obj['partitionsQuorum'] = ApiClient.convertToType(data['partitionsQuorum'], 'Number'); + } + if (data.hasOwnProperty('partitionsAllOk')) { + obj['partitionsAllOk'] = ApiClient.convertToType(data['partitionsAllOk'], 'Number'); + } + } + return obj; + } + + +} + +/** + * @member {String} status + */ +GetHealth200Response.prototype['status'] = undefined; + +/** + * @member {Number} knownNodes + */ +GetHealth200Response.prototype['knownNodes'] = undefined; + +/** + * @member {Number} connectedNodes + */ +GetHealth200Response.prototype['connectedNodes'] = undefined; + +/** + * @member {Number} storageNodes + */ +GetHealth200Response.prototype['storageNodes'] = undefined; + +/** + * @member {Number} storageNodesOk + */ +GetHealth200Response.prototype['storageNodesOk'] = undefined; + +/** + * @member {Number} partitions + */ +GetHealth200Response.prototype['partitions'] = undefined; + +/** + * @member {Number} partitionsQuorum + */ +GetHealth200Response.prototype['partitionsQuorum'] = undefined; + +/** + * @member {Number} partitionsAllOk + */ +GetHealth200Response.prototype['partitionsAllOk'] = undefined; + + + + + + +export default GetHealth200Response; + diff --git a/test/model/GetHealth200Response.spec.js b/test/model/GetHealth200Response.spec.js new file mode 100644 index 0000000..2a643a1 --- /dev/null +++ b/test/model/GetHealth200Response.spec.js @@ -0,0 +1,107 @@ +/** + * Garage Administration API v0+garage-v0.9.0 + * Administrate your Garage cluster programatically, including status, layout, keys, buckets, and maintainance tasks. *Disclaimer: The API is not stable yet, hence its v0 tag. The API can change at any time, and changes can include breaking backward compatibility. Read the changelog and upgrade your scripts before upgrading. Additionnaly, this specification is very early stage and can contain bugs, especially on error return codes/types that are not tested yet. Do not expect a well finished and polished product!* + * + * The version of the OpenAPI document: v0.9.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + * + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', process.cwd()+'/src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require(process.cwd()+'/src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.garage); + } +}(this, function(expect, garage) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new garage.GetHealth200Response(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('GetHealth200Response', function() { + it('should create an instance of GetHealth200Response', function() { + // uncomment below and update the code to test GetHealth200Response + //var instance = new garage.GetHealth200Response(); + //expect(instance).to.be.a(garage.GetHealth200Response); + }); + + it('should have the property status (base name: "status")', function() { + // uncomment below and update the code to test the property status + //var instance = new garage.GetHealth200Response(); + //expect(instance).to.be(); + }); + + it('should have the property knownNodes (base name: "knownNodes")', function() { + // uncomment below and update the code to test the property knownNodes + //var instance = new garage.GetHealth200Response(); + //expect(instance).to.be(); + }); + + it('should have the property connectedNodes (base name: "connectedNodes")', function() { + // uncomment below and update the code to test the property connectedNodes + //var instance = new garage.GetHealth200Response(); + //expect(instance).to.be(); + }); + + it('should have the property storageNodes (base name: "storageNodes")', function() { + // uncomment below and update the code to test the property storageNodes + //var instance = new garage.GetHealth200Response(); + //expect(instance).to.be(); + }); + + it('should have the property storageNodesOk (base name: "storageNodesOk")', function() { + // uncomment below and update the code to test the property storageNodesOk + //var instance = new garage.GetHealth200Response(); + //expect(instance).to.be(); + }); + + it('should have the property partitions (base name: "partitions")', function() { + // uncomment below and update the code to test the property partitions + //var instance = new garage.GetHealth200Response(); + //expect(instance).to.be(); + }); + + it('should have the property partitionsQuorum (base name: "partitionsQuorum")', function() { + // uncomment below and update the code to test the property partitionsQuorum + //var instance = new garage.GetHealth200Response(); + //expect(instance).to.be(); + }); + + it('should have the property partitionsAllOk (base name: "partitionsAllOk")', function() { + // uncomment below and update the code to test the property partitionsAllOk + //var instance = new garage.GetHealth200Response(); + //expect(instance).to.be(); + }); + + }); + +}));