Skip to content

Commit 3c08f3a

Browse files
authored
Merge pull request redhat-developer#2 from johnmcollier/entityproviderusebridge
RHDHPAI-505: Switch the entity provider to the model catalog bridge
2 parents 1f7bd84 + 67ffab5 commit 3c08f3a

File tree

10 files changed

+62
-44
lines changed

10 files changed

+62
-44
lines changed

workspaces/rhdh-ai/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ yarn backstage-repo-tools knip-reports
1919

2020
To run the rhdh-ai backend module in development mode:
2121

22-
1. Run `yarn install` to install dependencies
22+
1. Ensure the following environment variables are set:
2323

24-
2. Run `yarn dev` to launch the module
24+
- `RHDH_AI_BRIDGE_SERVER`: Set to the server hosting the RHDH AI Bridge
25+
- `RHDH_BRIDGE_HOST`: Similar as above, but without the protocol
26+
- `RHDH_TOKEN`: Any 8 character password to use for authentication with RHDH
27+
28+
2. Run `yarn install` to install dependencies
29+
30+
3. Run `yarn dev` to launch the module

workspaces/rhdh-ai/app-config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,5 @@ catalog:
9191
providers:
9292
modelCatalog:
9393
ollama:
94-
baseUrl: '${RHDH_AI_MODEL_SERVER}'
95-
authorization: '${RHDH_AI_AUTH_TOKEN}'
94+
baseUrl: '${RHDH_AI_BRIDGE_SERVER}'
9695
name: 'Ollama Model Service'

workspaces/rhdh-ai/plugins/catalog-backend-module-rhdh-ai/config.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export interface Config {
2424
* ModelCatalogConfig
2525
*/
2626
baseUrl: string;
27-
/** @visibility secret */
28-
authorization: string;
2927
name?: string;
3028
system?: string;
3129
owner?: string;

workspaces/rhdh-ai/plugins/catalog-backend-module-rhdh-ai/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"@backstage/catalog-model": "^1.7.2",
2929
"@backstage/errors": "^1.2.7",
3030
"@backstage/plugin-catalog-common": "^1.1.3",
31-
"@backstage/plugin-catalog-node": "^1.15.1"
31+
"@backstage/plugin-catalog-node": "^1.15.1",
32+
"yaml": "^2.7.0"
3233
},
3334
"devDependencies": {
3435
"@backstage/backend-test-utils": "^1.2.1",

workspaces/rhdh-ai/plugins/catalog-backend-module-rhdh-ai/src/clients/OpenAIResourceConnector.ts renamed to workspaces/rhdh-ai/plugins/catalog-backend-module-rhdh-ai/src/clients/BridgeResourceConnector.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { ModelList } from './types';
16+
import { Entity } from '@backstage/catalog-model';
1717

18+
import YAML from 'yaml';
19+
20+
// listModels will list the models from an OpenAI compatible endpoint
21+
/*
1822
export async function listModels(
1923
baseUrl: string,
2024
access_token: string,
@@ -33,4 +37,23 @@ export async function listModels(
3337
3438
const data = await res.json();
3539
return data;
40+
}*/
41+
42+
export async function fetchCatalogEntities(baseUrl: string): Promise<Entity[]> {
43+
// ToDo: Discover catalog-info endpoint?
44+
const res = await fetch(`${baseUrl}/mnist/v1/catalog-info.yaml`, {
45+
method: 'GET',
46+
});
47+
48+
if (!res.ok) {
49+
throw new Error(res.statusText);
50+
}
51+
52+
// ToDo: Look at seeing if we can use the parser provided by the CatalogProcessorProvider package
53+
const data = await res
54+
.blob()
55+
.then(blob => blob.text())
56+
.then(yamlStr => YAML.parseAllDocuments(yamlStr))
57+
.then(yamlData => yamlData.map(item => item.toJS()));
58+
return data;
3659
}

workspaces/rhdh-ai/plugins/catalog-backend-module-rhdh-ai/src/clients/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
export * from './OpenAIResourceConnector';
16+
export * from './BridgeResourceConnector';

workspaces/rhdh-ai/plugins/catalog-backend-module-rhdh-ai/src/providers/ModelCatalogResourceEntityProvider.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@ import type {
1818
SchedulerService,
1919
SchedulerServiceTaskRunner,
2020
} from '@backstage/backend-plugin-api';
21-
import {
22-
ANNOTATION_LOCATION,
23-
ANNOTATION_ORIGIN_LOCATION,
24-
ComponentEntity,
25-
Entity,
26-
ResourceEntity,
27-
} from '@backstage/catalog-model';
2821
import {
2922
EntityProvider,
3023
EntityProviderConnection,
3124
} from '@backstage/plugin-catalog-node';
32-
import { listModels } from '../clients/OpenAIResourceConnector';
33-
import type { ModelList } from '../clients/types';
25+
import {
26+
ANNOTATION_LOCATION,
27+
ANNOTATION_ORIGIN_LOCATION,
28+
} from '@backstage/catalog-model';
29+
import { fetchCatalogEntities } from '../clients/BridgeResourceConnector';
3430
import { ModelCatalogConfig } from './types';
3531
import { readModelCatalogApiEntityConfigs } from './config';
3632
import type { Config } from '@backstage/config';
@@ -41,10 +37,6 @@ import { InputError, isError } from '@backstage/errors';
4137
export class ModelCatalogResourceEntityProvider implements EntityProvider {
4238
private readonly env: string;
4339
private readonly baseUrl: string;
44-
private readonly authorization: string;
45-
private readonly name: string;
46-
private readonly owner: string;
47-
private readonly system: string;
4840
private readonly logger: LoggerService;
4941
private readonly scheduleFn: () => Promise<void>;
5042
private connection?: EntityProviderConnection;
@@ -91,10 +83,6 @@ export class ModelCatalogResourceEntityProvider implements EntityProvider {
9183
) {
9284
this.env = config.id;
9385
this.baseUrl = config.baseUrl;
94-
this.authorization = config.authorization;
95-
this.name = config.name;
96-
this.owner = config.owner;
97-
this.system = config.system ?? '';
9886
this.logger = logger.child({
9987
target: this.getProviderName(),
10088
});
@@ -152,10 +140,24 @@ export class ModelCatalogResourceEntityProvider implements EntityProvider {
152140
this.logger.info(
153141
`Discovering ResourceEntities from Model Server ${this.baseUrl}`,
154142
);
155-
const modelList = await listModels(this.baseUrl, this.authorization);
156143

157144
/** [5]: Convert the fetched model and model server data into RHDH catalog entities */
158-
const modelServerName: string = this.convertModeServerName(this.name);
145+
const entityList = await fetchCatalogEntities(this.baseUrl);
146+
entityList.forEach(entity => {
147+
if (entity.metadata.annotations === undefined) {
148+
entity.metadata.annotations = {
149+
[ANNOTATION_LOCATION]: this.getProviderName(),
150+
[ANNOTATION_ORIGIN_LOCATION]: this.getProviderName(),
151+
};
152+
} else {
153+
entity.metadata.annotations[ANNOTATION_LOCATION] =
154+
this.getProviderName();
155+
entity.metadata.annotations[ANNOTATION_ORIGIN_LOCATION] =
156+
this.getProviderName();
157+
}
158+
});
159+
160+
/* const modelServerName: string = this.convertModeServerName(this.name);
159161
let entities: Entity[] = [];
160162
const modelServerEntity: ComponentEntity =
161163
this.buildComponentEntityFromModelEndpoint(modelServerName);
@@ -166,14 +168,14 @@ export class ModelCatalogResourceEntityProvider implements EntityProvider {
166168
/** [6]: Add/update the catalog entities that correspond to the models */
167169
await this.connection.applyMutation({
168170
type: 'full',
169-
entities: entities.map(entity => ({
171+
entities: entityList.map(entity => ({
170172
entity,
171173
locationKey: this.getProviderName(),
172174
})),
173175
});
174176
}
175177

176-
private convertModelNameToEntityName(modelName: string): string {
178+
/* private convertModelNameToEntityName(modelName: string): string {
177179
return modelName.replaceAll(/\:/g, '-');
178180
}
179181
@@ -245,5 +247,5 @@ export class ModelCatalogResourceEntityProvider implements EntityProvider {
245247
};
246248
247249
return modelServerComponent;
248-
}
250+
}*/
249251
}

workspaces/rhdh-ai/plugins/catalog-backend-module-rhdh-ai/src/providers/config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ function readModelCatalogApiEntityConfig(
3939
config: Config,
4040
): ModelCatalogConfig {
4141
const baseUrl = config.getString('baseUrl');
42-
const authorization = config.getString('authorization');
43-
const name = config.getString('name');
44-
const system = config.getOptionalString('system');
45-
const owner = config.getOptionalString('owner') ?? 'unknown';
4642

4743
const schedule = config.has('schedule')
4844
? readSchedulerServiceTaskScheduleDefinitionFromConfig(
@@ -53,10 +49,6 @@ function readModelCatalogApiEntityConfig(
5349
return {
5450
id,
5551
baseUrl,
56-
authorization,
57-
name,
58-
system,
59-
owner,
6052
schedule,
6153
};
6254
}

workspaces/rhdh-ai/plugins/catalog-backend-module-rhdh-ai/src/providers/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,5 @@ import type { SchedulerServiceTaskScheduleDefinition } from '@backstage/backend-
1818
export type ModelCatalogConfig = {
1919
id: string;
2020
baseUrl: string;
21-
authorization: string;
22-
name: string;
23-
owner: string;
24-
system?: string;
2521
schedule?: SchedulerServiceTaskScheduleDefinition;
2622
};

workspaces/rhdh-ai/yarn.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10177,6 +10177,7 @@ __metadata:
1017710177
"@backstage/errors": ^1.2.7
1017810178
"@backstage/plugin-catalog-common": ^1.1.3
1017910179
"@backstage/plugin-catalog-node": ^1.15.1
10180+
yaml: ^2.7.0
1018010181
languageName: unknown
1018110182
linkType: soft
1018210183

@@ -34105,7 +34106,7 @@ __metadata:
3410534106
languageName: node
3410634107
linkType: hard
3410734108

34108-
"yaml@npm:^2.0.0, yaml@npm:^2.0.0-10, yaml@npm:^2.2.1, yaml@npm:^2.2.2":
34109+
"yaml@npm:^2.0.0, yaml@npm:^2.0.0-10, yaml@npm:^2.2.1, yaml@npm:^2.2.2, yaml@npm:^2.7.0":
3410934110
version: 2.7.0
3411034111
resolution: "yaml@npm:2.7.0"
3411134112
bin:

0 commit comments

Comments
 (0)