Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add space client to AppContext #836

Merged
merged 7 commits into from
Jul 7, 2023
Merged

Add space client to AppContext #836

merged 7 commits into from
Jul 7, 2023

Conversation

patuwwy
Copy link
Member

@patuwwy patuwwy commented Apr 4, 2023

What?

this.space: ManagerClient

Usage:

  • Get information about Hubs connected to Space.
  • List entities on all Hosts connected to Space.
  • Send Sequences, Start Instances on the other Hubs connected to Space.
  • Disconnect Hubs from Space.
  • And more, please refer to ManagerClient

Sample Sequence printing Space version and the list of connected Hubs to stdout:

// sequence.ts
/* eslint-disable no-console */
import { InertApp } from "@scramjet/types";
import { Readable } from "stream";

module.exports = async function(_stream: Readable) {
    const spaceClient = this.space;

    const version = await spaceClient.getVersion();
    const hosts = await spaceClient.getHosts();

    console.log("Instance output start");
    console.log("Manager", spaceClient);
    console.log("Manager version", version);
    console.log("Hubs connected to space", hosts);
    console.log("Instance output end");
} as InertApp;

Review checks:

These aspects need to be checked by the reviewer:

  • Verify and confirm operation (please post a screenshot)
  • All STH tests pass
  • All Scramjet Cloud Platform tests pass
  • Documentation is updated or no changes

when host is not connected all ManagerClient requests return 404

Copy link
Member

@alicja-gruzdz alicja-gruzdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a really clever idea, thanks for your help with this.

@patuwwy patuwwy marked this pull request as ready for review April 4, 2023 21:54
@patuwwy patuwwy requested review from MichalCz and ErykSol April 4, 2023 21:54
@patuwwy
Copy link
Member Author

patuwwy commented Apr 4, 2023

image

@patuwwy patuwwy marked this pull request as draft April 6, 2023 00:01
@patuwwy patuwwy marked this pull request as ready for review April 6, 2023 01:08
@patuwwy patuwwy added the PoC Proof of Concept label Apr 6, 2023
@patuwwy patuwwy force-pushed the feature/space-client branch 3 times, most recently from 7838f4b to c709b10 Compare June 6, 2023 10:44
@patuwwy patuwwy changed the title Add getSpaceClient to HostClient Add space client to AppContext Jun 19, 2023
@patuwwy patuwwy added ready to review and removed PoC Proof of Concept labels Jun 20, 2023
Copy link
Contributor

@a-tylenda a-tylenda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on the stage environment:
image

@a-tylenda
Copy link
Contributor

a-tylenda commented Jul 7, 2023

verified after rebase:

~/shared/transform-hub/bdd/data/sequences/seq [feature/space-client|…1⚑ 1] 
11:21 $ si inst stdout -
Instance output start
Manager ManagerClient { apiBase: 'http://scramjet-host/api/v1/cpm/api/v1' }
Manager version {
  service: '@scramjet/manager',
  apiVersion: 'v1',
  version: '0.32.4',
  build: '30f6943'
}
Hubs connected to space [
  {
    id: 'sth-0',
    info: {
      created: '2023-06-30T11:29:22.850Z',
      lastConnected: '2023-06-30T11:29:23.141Z'
    },
    healthy: true,
    isConnectionActive: true,
    selfHosted: false,
    description: '',
    tags: []
  },
  {
    id: 'SELF_HOSTED_STH-1',
    info: {
      created: '2023-07-04T09:08:02.331Z',
      lastConnected: '2023-07-04T09:08:04.449Z',
      lastDisconnected: '2023-07-04T09:09:33.469Z'
    },
    healthy: false,
    isConnectionActive: false,
    selfHosted: true,
    description: 'Some description',
    tags: [ 'tag1', ' tag2' ]
  },
  {
    id: 'SHH-1',
    info: {
      created: '2023-07-03T09:11:39.747Z',
      lastConnected: '2023-07-03T09:11:41.080Z',
      lastDisconnected: '2023-07-03T09:18:32.273Z'
    },
    healthy: false,
    isConnectionActive: false,
    selfHosted: true,
    description: 'My awesome Self-Hosted Hub <3',
    tags: [ 'scramjet', ' samples' ]
  },
  {
    id: 'shh-1',
    info: {
      created: '2023-07-07T11:21:14.523Z',
      lastConnected: '2023-07-07T11:21:14.798Z'
    },
    healthy: true,
    isConnectionActive: true,
    selfHosted: true,
    description: 'My awesome Self-Hosted Hub <3',
    tags: [ 'scramjet', ' samples' ]
  }
]
Instance output end

and logs from sth:

2023-07-07T11:21:24.801Z TRACE CSIController [b118d163] Instance started 
2023-07-07T11:21:24.801Z TRACE Host [shh-1] CSIController started [ 'b118d163-db38-474a-908f-ff7c4777f019' ]
2023-07-07T11:21:24.801Z TRACE CPMConnector [shh-1] Send instance status update [ 0 ]
2023-07-07T11:21:24.801Z TRACE CPMConnector [shh-1] Instance status update sent [ 0 ]
2023-07-07T11:21:24.802Z DEBUG Host [shh-1] Instance limits [ { memory: 512 } ]
2023-07-07T11:21:24.802Z DEBUG LokiAdapter [shh-1] Pushing log entry [ '["Instance started",{"version":"0.34.4","environment":"vm","hostSize":"m","ip":"51.444.13.111","adapter":"process","id":"b118d163-db38-474a-908f-ff7c4777f019","language":"js","seqId":"e1d46f5b-b7c0-4007-b0f1-ec572722e361"}]' ]
2023-07-07T11:21:24.804Z DEBUG Host [shh-1] Request [ 'date: 2023-07-07T11:21:22.278Z, method: POST, url: /api/v1/sequence/e1d46f5b-b7c0-4007-b0f1-ec572722e361/start, status: 200' ]
2023-07-07T11:21:24.811Z INFO  Host [shh-1] SPACE REQUEST [ '/api/v1/cpm/api/v1/version', 'version' ]
2023-07-07T11:21:24.811Z INFO  CPMConnector [shh-1] make HTTP Req to CPM [ 'https://api-hybrid.scp.ovh/api/v1/cpm/org-f8d19d60-0dc6-446b-9794-c701f5c3a584-manager/api/v1/version' ]
2023-07-07T11:21:24.812Z INFO  VerserClient Creating muxed channel in verser connection 
2023-07-07T11:21:24.887Z DEBUG Host [shh-1] Request [ 'date: 2023-07-07T11:21:24.812Z, method: GET, url: /api/v1/cpm/api/v1/version, status: 200' ]
2023-07-07T11:21:24.893Z INFO  Host [shh-1] SPACE REQUEST [ '/api/v1/cpm/api/v1/list', 'list' ]
2023-07-07T11:21:24.893Z INFO  CPMConnector [shh-1] make HTTP Req to CPM [ 'https://api-hybrid.scp.ovh/api/v1/cpm/org-f8d19d60-0dc6-446b-9794-c701f5c3a584-manager/api/v1/list' ]
2023-07-07T11:21:24.893Z INFO  VerserClient Creating muxed channel in verser connection 
2023-07-07T11:21:24.926Z DEBUG Host [shh-1] Request [ 'date: 2023-07-07T11:21:24.893Z, method: GET, url: /api/v1/cpm/api/v1/list, status: 200' ]
2023-07-07T11:21:24.929Z TRACE Host [shh-1] PANG received [ { provides: '', requires: undefined, contentType: '' } ]
2023-07-07T11:21:24.929Z TRACE CSIController [b118d163] Got message: SEQUENCE_COMPLETED. 

@patuwwy patuwwy merged commit 1caf5e3 into devel Jul 7, 2023
57 checks passed
@patuwwy patuwwy deleted the feature/space-client branch July 7, 2023 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants