# pip-clients-clusters-node

> Node.js client sdk for clusters microservice

Latest version **1.0.0** (published 2020-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install pip-clients-clusters-node
pnpm add pip-clients-clusters-node
yarn add pip-clients-clusters-node
bun add pip-clients-clusters-node
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-01-07 |
| First published | 2020-01-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=0.6.14 |
| Dependencies | 4 |
| Unpacked size | 165.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Conceptual Vision Consulting LLC |
| Maintainers | pipdeveloper |
| Keywords | clusters, microservice, client, sdk |

## Links

- npm: https://www.npmjs.com/package/pip-clients-clusters-node
- Repository: https://github.com/pip-services-infrastructure/pip-clients-clusters-node
- Homepage: https://github.com/pip-services-infrastructure/pip-clients-clusters-node#readme
- Issues: https://github.com/pip-services-infrastructure/pip-clients-clusters-node/issues
- npm.io page: https://npm.io/package/pip-clients-clusters-node

## Dependencies (4)

- [pip-services3-aws-node](https://npm.io/package/pip-services3-aws-node.md) ^3.0.0
- [pip-services3-rpc-node](https://npm.io/package/pip-services3-rpc-node.md) ^3.0.0
- [pip-services3-commons-node](https://npm.io/package/pip-services3-commons-node.md) ^3.0.0
- [pip-services3-components-node](https://npm.io/package/pip-services3-components-node.md) ^3.0.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-01-07

## README

# <img src="https://github.com/pip-services/pip-services/raw/master/design/Logo.png" alt="Pip.Services Logo" style="max-width:30%"> <br/> Clusters Microservice Client SDK for Node.js

<a name="links"></a> Quick Links:

* [Download Links](doc/Downloads.md)
* [Development Guide](doc/Development.md)
* Service
  - [Clusters service](https://github.com/pip-services-infrastructure/pip-service-clusters-node)

This is a Node.js client SDK for [pip-services-clusters](https://github.com/pip-services-infrastructure/pip-services-clusters-node) microservice.

 It provides an easy to use abstraction over communication protocols:

- Direct client for monolythic deployments
- Http client
- Lambda client for AWS
- Memory client
- Proxy http client
- Null client to be used in testing

## Install

Add dependency to the client SDK into **package.json** file of your project
```typescript
{
    ...
    "dependencies": {
        ....
        "pip-clients-clusters-node": "^1.0.*",
        ...
    }
}
```

Then install the dependency using **npm** tool
```bash
# Install new dependencies
npm install

# Update already installed dependencies
npm update
```

## Use

Inside your code get the reference to the client SDK
```typescript
 import { ClustersHttpClientV1 } from 'pip-clients-clusters-node';
```

Define client configuration parameters.

```typescript
// Client configuration
var httpConfig = ConfigParams.fromTuples(
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 3000
);
client.configure(httpConfig);
```

Instantiate the client and open connection to the microservice
```typescript
// Create the client instance
client = new ClustersHttpClientV1();

// Connect to the microservice
client.open(null, function(err) {
    if (err) {
        console.error('Connection to the microservice failed');
        console.error(err);
        return;
    }
    
    // Work with the microservice
    ...
});
```
Now the client is ready to perform operations:

Create new cluster:
```typescript 
let CLUSTER1: ClusterV1 = {
    id: '1',
    name: 'Cluster #1',
    type: 'root',
    active: true,
    api_host: 'api.mycluster1.com',
    service_ports: { myservice1: 30001, myservice2: 30002 },
    max_tenant_count: 1,
    tenants_count: 1,
    active_tenants: ['1']
};   

    client.createCluster("123", CLUSTER1, (err, cluster){
        if (err != null) {
            console.error('Can\'t create cluster!');
            console.error(err);
        } else {
            console.dir('Cluster was created successfull');
        }
    });
```
Update exists cluster:
```typescript
    CLUSTER1.name = "Cluster #2";
    client.updateCluster("123", CLUSTER1, (err, cluster){
        if (err != null) {
            console.error('Can\'t update cluster!');
            console.error(err);
        } else {
            console.dir('Cluster was updated successfull');
        }
    });
```
Delete existing cluster by cluster_id
```typescript    
    client.deleteClusterById("123", 1, (err, cluster){
        if (err != null) {
            console.error('Can\'t delete cluster!');
            console.error(err);
        } else {
            console.dir('Cluster was delete successfull');
            console.dir('Deleted cluster:');
            console.dir(cluster.toString());
        }
    });
```
Add new tenant into active cluster
```typescript
    client.addTenant("123", "5", (err, cluster) {
        if (err != null) {
            console.error('Can\'t add tenant to cluster!');
            console.error(err);
        } else {
            console.dir('Tenant was added successfull');
            console.dir('Cluster:');
            console.dir(cluster.toString());
        }
    });
```
Remove existing tenant by tenantId
```typescript
    client.removeTenant("123", "5", (err, cluster) {
        if (err != null) {
            console.error('Can\'t delete tenant from cluster!');
            console.error(err);
        } else {
            console.dir('Tenant was deleted successfull');
            console.dir('Cluster:');
            console.dir(cluster.toString());
        }
    });
```
Get list of all clusters:
```typescript
    let filter = FilterParams.fromTuples(
        'active', true,
        'open', true
    );
    client.getClusters("123", filter, new PagingParams(), (err, clusters){
        if (err != null) {
            console.error('Can\'t find cluster by filter!');
            console.error(err);
        } else {
            console.dir("Cluster list length:");
            console.dir(clusters.data.length);
        }
    });
```
Get cluster by cluster_id:
```typescript
    client.getClusterById("123", "1", (err, cluster){
         if (err != null) {
            console.error('Can\'t find cluster by cluster id!');
            console.error(err);
        } else {
            console.dir('Cluster was finded successfull');
            console.dir('Cluster:');
            console.dir(cluster.toString());
        }
    });
```
Get cluster by tenant:
```typescript
    client.getClusterByTenant("123", "5", (err, cluster){
        if (err != null) {
            console.error('Can\'t find cluster by tenant id!');
            console.error(err);
        } else {
            console.dir('Cluster was finded successfull');
            console.dir('Cluster:');
            console.dir(cluster.toString());
        }
    });
```

## Acknowledgements

This client SDK was created and currently maintained by *Sergey Seroukhov*.

---
_Source: https://npm.io/package/pip-clients-clusters-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
