Skip to content

Commit

Permalink
Merge pull request #157 from XavierGeerinck/api-shutdown
Browse files Browse the repository at this point in the history
feat: Add shutdown API
  • Loading branch information
XavierGeerinck authored Jan 17, 2022
2 parents d21261c + e0fce66 commit 57f4675
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Version 2.0.0 brings a lot of changes to the Dapr JS SDK that were long due. Bel
* The HTTP Connection is now being reused to reduce the CONNRESET errors when intensively using the JS SDK
* The [Metadata API](https://docs.dapr.io/reference/api/metadata_api/) is supported
* The [Health API](https://docs.dapr.io/reference/api/health_api/) is supported
* The `/v1.0/shutdown` [API endpoint](https://docs.dapr.io/operations/hosting/kubernetes/kubernetes-job/) is now supported by calling `await client.sidecar.shutdown()`

#### Breaking Changes

Expand All @@ -23,5 +24,6 @@ Version 2.0.0 brings a lot of changes to the Dapr JS SDK that were long due. Bel
* `healthz` endpoint was implemented as `client.health.isHealthy()` for gRPC this checks the `getMetadata` function since it does not have a Health PROTO.
* Server startup now ensures the Dapr Sidecar is healthy before starting
* Add metadata API for gRPC and HTTP
* Add the SDK implementation for gRPC and HTTP for shutting down the Sidecar through the SDK

## 1.x release
6 changes: 6 additions & 0 deletions src/implementation/Client/DaprClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import IClientInvoker from '../../interfaces/Client/IClientInvoker';
import IClientSecret from '../../interfaces/Client/IClientSecret';
import IClientHealth from '../../interfaces/Client/IClientHealth';
import IClientMetadata from '../../interfaces/Client/IClientMetadata';
import IClientSidecar from '../../interfaces/Client/IClientSidecar';
import IClient from '../../interfaces/Client/IClient';

import GRPCClientBinding from './GRPCClient/binding';
Expand All @@ -14,6 +15,7 @@ import GRPCClientInvoker from './GRPCClient/invoker';
import GRPCClientSecret from './GRPCClient/secret';
import GRPCClientHealth from './GRPCClient/health';
import GRPCClientMetadata from './GRPCClient/metadata';
import GRPCClientSidecar from './GRPCClient/sidecar';
import GRPCClient from './GRPCClient/GRPCClient';

import HTTPClientBinding from './HTTPClient/binding';
Expand All @@ -23,6 +25,7 @@ import HTTPClientInvoker from './HTTPClient/invoker';
import HTTPClientSecret from './HTTPClient/secret';
import HTTPClientHealth from './HTTPClient/health';
import HTTPClientMetadata from './HTTPClient/metadata';
import HTTPClientSidecar from './HTTPClient/sidecar';
import HTTPClient from './HTTPClient/HTTPClient';

import CommunicationProtocolEnum from '../../enum/CommunicationProtocol.enum';
Expand All @@ -42,6 +45,7 @@ export default class DaprClient {
readonly secret: IClientSecret;
readonly health: IClientHealth;
readonly metadata: IClientMetadata;
readonly sidecar: IClientSidecar;

constructor(
daprHost: string
Expand Down Expand Up @@ -74,6 +78,7 @@ export default class DaprClient {
this.secret = new GRPCClientSecret(client);
this.health = new GRPCClientHealth(client);
this.metadata = new GRPCClientMetadata(client);
this.sidecar = new GRPCClientSidecar(client);
break;
}
case CommunicationProtocolEnum.HTTP:
Expand All @@ -88,6 +93,7 @@ export default class DaprClient {
this.secret = new HTTPClientSecret(client);
this.health = new HTTPClientHealth(client);
this.metadata = new HTTPClientMetadata(client);
this.sidecar = new HTTPClientSidecar(client);
break;
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/implementation/Client/GRPCClient/sidecar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import GRPCClient from './GRPCClient';
import IClientSidecar from "../../../interfaces/Client/IClientSidecar";
import { Empty } from "google-protobuf/google/protobuf/empty_pb";

// https://docs.dapr.io/reference/api/secrets_api/
export default class GRPCClientSidecar implements IClientSidecar {
client: GRPCClient;

constructor(client: GRPCClient) {
this.client = client;
}

async shutdown(): Promise<void> {
return new Promise((resolve, reject) => {
const client = this.client.getClient();
client.shutdown(new Empty(), (err, res: Empty) => {
if (err) {
return reject(err);
}

return resolve();
});
});
}
}
17 changes: 17 additions & 0 deletions src/implementation/Client/HTTPClient/sidecar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import HTTPClient from './HTTPClient';
import IClientSidecar from '../../../interfaces/Client/IClientSidecar';

// https://docs.dapr.io/reference/api/bindings_api/
export default class HTTPClientSidecar implements IClientSidecar {
client: HTTPClient;

constructor(client: HTTPClient) {
this.client = client;
}

async shutdown(): Promise<void> {
await this.client.execute(`/shutdown`, {
method: 'POST'
});
}
}
3 changes: 3 additions & 0 deletions src/interfaces/Client/IClientSidecar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default interface IClientSidecar {
shutdown(): Promise<void>;
}

0 comments on commit 57f4675

Please sign in to comment.