Skip to content

Commit a35cca9

Browse files
committed
feat: Release version 2.3.0.
Add documentation Readme.md
1 parent 530c771 commit a35cca9

3 files changed

Lines changed: 2257 additions & 2111 deletions

File tree

README.md

Lines changed: 147 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,153 @@
11
# Javascript client for OSCAR
22

3-
This project uses Node.js as the runtime environment, Express as the web application framework and TypeScript to add static typing to the code. This client connects to an OSCAR cluster (https://oscar.grycap.net) to interact with the cluster and its services.
3+
This project has been developed using version 18.12 of Node.js and typed with the Typescript language, oscar-js can be used with a module by adding it as a dependency in the package.json file or by using the command `npm install @grycap/oscar-js`. This package exports a client class which creates a new instance of the oscar-js-client. Once the class is initialized, passing the correct parameters will make it possible to interact with an OSCAR cluster and its services (https://oscar.grycap.net). It is available on GitHub packages wit the name [oscar-js](https://github.com/grycap/oscar-js/pkgs/npm/oscar-js)
44

5-
## Client methods
5+
## Client
66

7-
### Cluster methods
7+
To construct an instance of this class, you must pass an object as an argument. Depending on the fields sent, Basic Auth or OIDC Auth will be used.
88

9-
### Services methods
9+
### Basic auth
1010

11-
### Logs methods
11+
For this type of authentication, you will need to send the object with values in the fields **oscar_endpoint, username, password**.
12+
13+
```typescript
14+
const basic_auth = {
15+
clusterId: "cluster-id",
16+
oscar_endpoint: "https://my-oscar-cluster",
17+
username: "oscar",
18+
password: "secret",
19+
};
20+
21+
const oscar_client: Client = new Client(basic_auth);
22+
```
23+
24+
### OIDC authentication
25+
26+
For this type of authentication, you should send the object with values in the fields **oscar_endpoint, oidc_token**.
27+
28+
```typescript
29+
const oidc_auth = {
30+
clusterId: "cluster-id",
31+
oscar_endpoint: "https://my-oscar-cluster",
32+
oidc_token: "Bearer token",
33+
};
34+
35+
const oscar_client: Client = new Client(oidc_auth);
36+
```
37+
38+
## Sample usage
39+
40+
- Basic sample using client to obtain information of the cluster you want to interact with.
41+
Remember you must put the correct url of your oscar_endpoint. Response is type Info. You may view all the types used in the class [types.ts](src/types.ts)
42+
43+
```typescript
44+
const basic_auth = {
45+
clusterId: "cluster-id",
46+
oscar_endpoint: "https://my-oscar-cluster",
47+
username: "oscar",
48+
password: "secret",
49+
};
50+
51+
const oscar_client: Client = new Client(basic_auth);
52+
53+
// Get infomation about your oscar cluster
54+
let response = oscar_client.getClusterInfo();
55+
console.log("Cluster Info", response);
56+
```
57+
58+
- Basic sample using client to create a new service in oscar cluster. This example has the minimum attributes for the creation of a new service. You can see the complete structure of the service in [types.ts](src/types.ts)
59+
60+
```typescript
61+
const basic_auth = {
62+
clusterId: "cluster-id",
63+
oscar_endpoint: "https://my-oscar-cluster",
64+
username: "oscar",
65+
password: "secret",
66+
};
67+
68+
const oscar_client: Client = new Client(basic_auth);
69+
70+
// Create service object
71+
const service: Service = {
72+
name: "bird-audio-test",
73+
memory: "2Gi",
74+
cpu: "2.0",
75+
total_memory: "2Gi",
76+
total_cpu: "2.0",
77+
enable_gpu: false,
78+
enable_sgx: false,
79+
log_level: "CRITICAL",
80+
image: "deephdc/deep-oc-birds-audio-classification-tf",
81+
script: "<service-script>",
82+
};
83+
84+
// Show created service info in console.
85+
let response = await oscar_client.createService(service);
86+
console.log("Created service", response);
87+
```
88+
89+
## Services methods
90+
91+
Available methods for interacting with the cluster's services.
92+
93+
**Get Services**
94+
95+
```typescript
96+
// Returns a promise, when resolved contains a list of services
97+
const services = await oscar_client.getServices();
98+
```
99+
100+
**Get Service by name**
101+
102+
```typescript
103+
// Returns a promise, when resolved contains a single service if exists
104+
const service = await oscar_client.getServiceByName("my-service");
105+
```
106+
107+
**Create Service**
108+
109+
```typescript
110+
// Returns a promise, when resolved contains the created service.
111+
const service = { ... };
112+
const createdService = await oscar_client.createService(service);
113+
```
114+
115+
**Update Service**
116+
117+
```typescript
118+
// Returns a promise, when resolved contains the updated service.
119+
const service = { ... };
120+
const updatedService = await oscar_client.updateService(service);
121+
```
122+
123+
**Delete Service**
124+
125+
```typescript
126+
// Returns a promise, when resolved contains name of the deleted service.
127+
const deletedService = await oscar_client.deleteService("my-service");
128+
```
129+
130+
## Cluster methods
131+
132+
Available methods to interact directly with the OSCAR cluster.
133+
134+
**Get cluster info**
135+
136+
```typescript
137+
// Get cluster information
138+
const info = await oscar_client.getClusterInfo();
139+
```
140+
141+
**Get cluster config**
142+
143+
```typescript
144+
// Get cluster information
145+
const config = await oscar_client.getClusterConfig();
146+
```
147+
148+
**Get cluster health status**
149+
150+
```typescript
151+
// Get cluster information
152+
const health = await oscar_client.getHealthStatus();
153+
```

0 commit comments

Comments
 (0)