Skip to content

Commit d75c6f1

Browse files
Add SST api
Signed-off-by: Andrei Stepanov <[email protected]>
1 parent 1f4383e commit d75c6f1

File tree

5 files changed

+124
-7
lines changed

5 files changed

+124
-7
lines changed

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ RUN ["bash","-c", "--", "npm run build"]
1212
FROM registry.access.redhat.com/ubi8/nodejs-14
1313
ARG ADDPKGS=""
1414
ARG NPMLOCATION="open"
15+
ARG ANCHORS=""
1516
USER root
1617
RUN yum install -y "krb5-workstation" $ADDPKGS && \
1718
yum clean all -y
19+
COPY Dockerfile $ANCHORS "$HOME/"
20+
RUN if [ -n "${ANCHORS}" ]; then echo "Add anchors ${ANCHORS}"; trust anchor --store "${HOME}/${ANCHORS}"; fi
1821
USER 1001
1922
COPY "src" "$HOME/src/"
2023
COPY "assets" "$HOME/assets/"

assets/config-default.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ waiverdb:
2828
datagrepper:
2929
url: ~
3030
sst:
31-
url: ~
31+
url: 'https://sst.osci.redhat.com'
32+
results: 'results/sstlist.json'
3233
db:
3334
# http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html
3435
url: ~
@@ -91,6 +92,7 @@ env_to_config_map:
9192
url: SRV_DATAGREPPER_URL
9293
sst:
9394
url: SRV_SST_URL
95+
results: SRV_SST_RESULTS
9496
db:
9597
url: SRV_DB_URL
9698
limit_default: SRV_DB_LIMIT_DEFAULT

src/cfg.ts

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export interface Cfg {
205205
};
206206
sst: {
207207
url: string;
208+
results: string;
208209
};
209210
db: {
210211
/**

src/schema/root_query_type.ts

+71-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of ciboard-server
33
4-
* Copyright (c) 2021 Andrei Stepanov <[email protected]>
4+
* Copyright (c) 2021, 2022 Andrei Stepanov <[email protected]>
55
*
66
* This program is free software; you can redistribute it and/or
77
* modify it under the terms of the GNU Lesser General Public
@@ -67,6 +67,8 @@ import {
6767
GreenwaveSubjectTypesType,
6868
} from './greenwave_types';
6969

70+
import { SSTInfoType, SSTListType, SSTResultsType } from './sst_types';
71+
7072
import { ArtifactsType } from './db_types';
7173

7274
import {
@@ -158,6 +160,73 @@ const RootQuery = new GraphQLObjectType({
158160
return 'pong';
159161
},
160162
},
163+
/**
164+
* Subsystem teams (SST)
165+
*/
166+
sst_list: {
167+
type: SSTListType,
168+
resolve() {
169+
const url = new URL(cfg.sst.results, cfg.sst.url);
170+
return axios.get(url.toString()).then((response) =>
171+
response.data.map((sst: SSTInfoType) => {
172+
const releases = (sst.releases || []).map((rel) => rel.name);
173+
const { name, display_name } = sst;
174+
return { name, display_name, releases };
175+
})
176+
);
177+
},
178+
},
179+
sst_results: {
180+
type: SSTResultsType,
181+
args: {
182+
sst_name: { type: new GraphQLNonNull(GraphQLString) },
183+
release: { type: new GraphQLNonNull(GraphQLString) },
184+
},
185+
resolve(_parentValue, { sst_name, release }) {
186+
const results_json_url = new URL(
187+
`/results/${sst_name}.${release}.json`,
188+
cfg.sst.url
189+
).toString();
190+
return axios.get(results_json_url).then((response) => {
191+
const results = response.data.data;
192+
const reply = _.map(results, (result) => {
193+
const transformed: { [key: string]: any } = {
194+
nvr: result.nvr,
195+
assignee: result.assignee,
196+
artifact: {
197+
id: result.aid,
198+
url: result.aid_link,
199+
},
200+
testcase: {
201+
namespace: result.namespace,
202+
type: result.type,
203+
category: result.category,
204+
},
205+
tag: result.tag,
206+
time: result.time,
207+
status: result.status,
208+
metadata_url: result.nvr_link,
209+
};
210+
if (result.rebuild_link && result.rebuild_link !== 'X')
211+
transformed.rebuild_url = result.rebuild_link;
212+
if (result.log_link && result.log_link !== 'X') {
213+
if (Array.isArray(result.log_link))
214+
transformed.log_urls = result.log_link;
215+
else transformed.log_urls = [result.log_link];
216+
}
217+
if (result.el8_gating_bug && result.el8_gating_bug !== 'X')
218+
transformed.gating_bug = {
219+
text: result.el8_gating_bug,
220+
url: result.el8_gating_bug_link,
221+
};
222+
if (result.yaml && result.yaml !== 'missing')
223+
transformed.gating_yaml_url = result.yaml_link;
224+
return transformed;
225+
});
226+
return reply as SSTResultsType;
227+
});
228+
},
229+
},
161230
/**
162231
* WaiverDB
163232
*/
@@ -656,7 +725,7 @@ const RootQuery = new GraphQLObjectType({
656725
};
657726
},
658727
},
659-
sst_list: {
728+
db_sst_list: {
660729
args: {
661730
product_id: {
662731
type: GraphQLInt,

src/services/db.ts

+46-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,45 @@ const options: MongoClientOptions = _.pickBy(
4141

4242
log(' [i] mongo client options: %O', options);
4343

44-
export const client_promise = new MongoClient(cfg.db.url, options).connect();
44+
async function attemptAsync<T>(
45+
func: (...args: any[]) => Promise<T>,
46+
...args: any[]
47+
): Promise<Error | T> {
48+
try {
49+
return await func(...args);
50+
} catch (e) {
51+
if (_.isError(e)) {
52+
return e;
53+
}
54+
throw e;
55+
}
56+
}
57+
58+
const mkClient = (): Promise<MongoClient> => {
59+
var mongoClient;
60+
try {
61+
mongoClient = new MongoClient(cfg.db.url, options);
62+
} catch (e) {
63+
console.log('Failed to create mongo configuration. Check options.');
64+
console.dir(e);
65+
process.exit(1);
66+
}
67+
return mongoClient.connect();
68+
};
69+
70+
const clientPromise: Promise<Error | MongoClient> =
71+
attemptAsync<MongoClient>(mkClient);
72+
73+
const getClient = async (
74+
clientPromise: Promise<Error | MongoClient>
75+
): Promise<MongoClient> => {
76+
const client = await clientPromise;
77+
if (_.isError(client)) {
78+
console.dir(clientPromise);
79+
process.exit(1);
80+
}
81+
return client;
82+
};
4583

4684
/** For reduced query */
4785
const project = {
@@ -78,7 +116,7 @@ const mk_filter = (
78116
};
79117

80118
(async function test() {
81-
const client = await client_promise;
119+
const client = await getClient(clientPromise);
82120
const database = client.db('ci-messages');
83121
const collection = database.collection('artifacts');
84122
const cursor = collection.find().sort({ _id: -1 }).limit(1);
@@ -155,7 +193,11 @@ export const mk_cursor = async (args: QueryOptions) => {
155193
dbFieldValues3,
156194
dbFieldValuesComponentMapping1,
157195
} = args;
158-
const client = await client_promise;
196+
if (_.isError(clientPromise)) {
197+
console.dir(clientPromise);
198+
process.exit(1);
199+
}
200+
const client = await getClient(clientPromise);
159201
const database = client.db(cfg.db.db_name);
160202
const collection = database.collection(cfg.db.collection_name);
161203
/** look-up by name -> nvr, nsvc, ... */
@@ -254,7 +296,7 @@ export const mk_cursor = async (args: QueryOptions) => {
254296
};
255297

256298
export const db_list_sst = async (product_id: number) => {
257-
const client = await client_promise;
299+
const client = await getClient(clientPromise);
258300
const database = client.db(cfg.db.db_name);
259301
const collection = database.collection(cfg.db.collection_name_components);
260302
log('List SST names');

0 commit comments

Comments
 (0)