diff --git a/src/mirage/factories.ts b/src/mirage/factories.ts index be61e62817..91cacefc57 100644 --- a/src/mirage/factories.ts +++ b/src/mirage/factories.ts @@ -23,7 +23,7 @@ export const targetFactory: FactoryDefinition = Factory.extend({ jvmId: '1234', annotations: { platform: { 'io.cryostat.demo': 'this-is-not-real' }, - cryostat: { hello: 'world' }, + cryostat: { hello: 'world', REALM: 'KubernetesApi' }, }, }); diff --git a/src/mirage/index.ts b/src/mirage/index.ts index faad96aadc..58f8d56859 100644 --- a/src/mirage/index.ts +++ b/src/mirage/index.ts @@ -99,14 +99,16 @@ export const startMirage = ({ environment = 'development' } = {}) => { () => new Response(400, {}, 'Resource downloads are not supported in this demo') ); this.post('api/v2/targets', (schema, request) => { - const attrs = JSON.parse(request.requestBody); + const attrs = request.requestBody as any; const target = schema.create(Resource.TARGET, { - jvmId: `${Math.floor(1000 * Math.random())}`, + jvmId: `${Date.now().toString(16)}`, alias: attrs.get('alias'), connectUrl: attrs.get('connectUrl'), annotations: { platform: {}, - cryostat: {}, + cryostat: { + REALM: 'Custom Targets', + }, }, }); websocket.send( @@ -126,31 +128,50 @@ export const startMirage = ({ environment = 'development' } = {}) => { }; }); this.get('api/v1/targets', (schema) => schema.all(Resource.TARGET).models); - this.get('api/v2.1/discovery', (schema) => ({ - meta: { - status: 'OK', - type: 'application/json', - }, - data: { - result: { - name: 'Universe', - nodeType: 'Universe', - labels: {}, - children: [ - { - name: 'KubernetesApi', - nodeType: 'Realm', - labels: {}, - children: schema.all(Resource.TARGET).models.map((t) => ({ - name: t.alias, - nodeType: 'JVM', - target: t, - })), - }, - ], + this.get('api/v2.1/discovery', (schema) => { + const models = schema.all(Resource.TARGET).models; + const ct = models.filter((t) => t.annotations.cryostat['REALM'] === 'Custom Targets'); + const k8s = models.filter((t) => t.annotations.cryostat['REALM'] === 'KubernetesApi'); + return { + meta: { + status: 'OK', + type: 'application/json', }, - }, - })); + data: { + result: { + name: 'Universe', + nodeType: 'Universe', + labels: {}, + children: [ + { + name: 'KubernetesApi', + nodeType: 'Realm', + labels: {}, + id: 'KubernetesApi', + children: k8s.map((t) => ({ + id: t.alias, + name: t.alias, + nodeType: 'JVM', + target: t, + })), + }, + { + name: 'Custom Targets', + nodeType: 'Realm', + labels: {}, + id: 'Custom Targets', + children: ct.map((t) => ({ + id: t.alias, + name: t.alias, + nodeType: 'CustomTarget', + target: t, + })), + }, + ], + }, + }, + }; + }); this.get('api/v1/recordings', (schema) => schema.all(Resource.ARCHIVE).models); this.get('api/beta/fs/recordings', (schema) => { const target = schema.first(Resource.TARGET); @@ -186,7 +207,9 @@ export const startMirage = ({ environment = 'development' } = {}) => { return new Response(200); }); this.post('api/v1/targets/:targetId/recordings', (schema, request) => { - const attrs = JSON.parse(request.requestBody); + // Note: MirageJS will fake serialize FormData (i.e. FormData object is returned when accessing request.requestBody) + const attrs = request.requestBody as any; + const recording = schema.create(Resource.RECORDING, { // id will generated by Mirage (i.e. increment intergers) downloadUrl: '',