From e805a656e701530a9a8353581fb34c5490a906da Mon Sep 17 00:00:00 2001 From: sagIoTPower Date: Tue, 28 Nov 2023 12:09:47 +0100 Subject: [PATCH] commit build instructions --- README.md | 18 ++++++ analytics-service/cumulocity.json | 48 +++----------- .../src/analytics/list/block.component.ts | 2 +- .../editor/repositories-modal.component.ts | 1 + .../src/sample/list/sample.component.ts | 4 +- analytics-ui/src/shared/analytics.model.ts | 3 +- analytics-ui/src/shared/analytics.service.ts | 63 +++++++++++++++---- 7 files changed, 85 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index e62458f..a87b496 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ - [Installation](#installation-of-plugin-as-community-plugin) - [Build Instructions](#build-instructions) - [Analytics Builder Block SDK](#analytics-builder-block-sdk) +- [Analytics Builder Extension Backend](#analytics-builder-extension-backend) ## Overview @@ -82,6 +83,23 @@ The provided block is an example of the adding the two inputs.


--> +## Analytics Builder Extension Backend + +To build the backend as a microservice follow these steps: +* run script: +``` +# cd analytics-service +# ./build.sh analytics-ext-service XXXX +``` +* upload created image: +``` +# c8y microservices list --name analytics-ext-service | c8y microservices createBinary --file dist/analytics-ext-service.zip --timeout 360 +``` +> **NOTE** +FOr the first deployment you have to use: +``` +# c8y microservices create --file dist/analytics-ext-service.zip --name analytics-ext-service --timeout 360 +``` ------------------------------ These tools are provided as-is and without warranty or support. They do not constitute part of the Software AG product suite. Users are free to use, fork and modify them, subject to the license agreement. While Software AG welcomes contributions, we cannot guarantee to include every contribution in the master project. diff --git a/analytics-service/cumulocity.json b/analytics-service/cumulocity.json index 4c94cbb..c58af82 100644 --- a/analytics-service/cumulocity.json +++ b/analytics-service/cumulocity.json @@ -1,39 +1,11 @@ { - "apiVersion": "2", - "version": "{VERSION}", - "provider": { - "name": "Software AG" - }, - "isolation": "PER_TENANT", - "requiredRoles": [ - "ROLE_INVENTORY_READ", - "ROLE_INVENTORY_ADMIN", - "ROLE_OPTION_MANAGEMENT_READ", - "ROLE_OPTION_MANAGEMENT_ADMIN", - "ROLE_USER_MANAGEMENT_ADMIN", - "ROLE_USER_MANAGEMENT_READ" - ], - "roles":[ - "ROLE_ANALYTICSBUILDER_ADMIN", - "ROLE_ANALYTICSBUILDER_CREATE" - ] - { - "apiVersion": "2", - "version": "{VERSION}", - "provider": { - "name": "Software AG" - }, - "isolation": "PER_TENANT", - "requiredRoles": [ - "ROLE_INVENTORY_READ", - "ROLE_INVENTORY_ADMIN", - "ROLE_OPTION_MANAGEMENT_READ", - "ROLE_OPTION_MANAGEMENT_ADMIN", - "ROLE_USER_MANAGEMENT_ADMIN", - "ROLE_USER_MANAGEMENT_READ" - ], - "roles":[ - "ROLE_TWINMAKER_ADMIN", - "ROLE_TWINMAKER_CREATE" - ] - \ No newline at end of file + "apiVersion": "2", + "version": "{VERSION}", + "provider": { + "name": "Software AG" + }, + "isolation": "PER_TENANT", + "requiredRoles": [ + ], + "roles": [] +} diff --git a/analytics-ui/src/analytics/list/block.component.ts b/analytics-ui/src/analytics/list/block.component.ts index e76b783..647a7f6 100644 --- a/analytics-ui/src/analytics/list/block.component.ts +++ b/analytics-ui/src/analytics/list/block.component.ts @@ -112,7 +112,7 @@ export class BlockGridComponent implements OnInit { } async loadBlocks() { - this.blocks = await this.analyticsService.getCEP_Blocks(); + this.blocks = await this.analyticsService.getLoadedCEP_Blocks(); } ngOnDestroy() {} diff --git a/analytics-ui/src/sample/editor/repositories-modal.component.ts b/analytics-ui/src/sample/editor/repositories-modal.component.ts index f487e02..3a136b0 100644 --- a/analytics-ui/src/sample/editor/repositories-modal.component.ts +++ b/analytics-ui/src/sample/editor/repositories-modal.component.ts @@ -75,6 +75,7 @@ import { RepositoryService } from "./repository.service"; type="text" id="url" formControlName="url" + placeholder="enter in the form: https://api.github.com/repos/{REPO_SAMPLES_OWNER}/{REPO_SAMPLES_NAME}/contents/{REPO_SAMPLES_PATH}" class="form-control" /> diff --git a/analytics-ui/src/sample/list/sample.component.ts b/analytics-ui/src/sample/list/sample.component.ts index d9447d4..af16ec6 100644 --- a/analytics-ui/src/sample/list/sample.component.ts +++ b/analytics-ui/src/sample/list/sample.component.ts @@ -64,6 +64,7 @@ export class SampleGridComponent implements OnInit { header: "Name", path: "name", dataType: ColumnDataType.TextLong, + filterable:true, gridTrackSize: "15%", visible: true, }, @@ -72,6 +73,7 @@ export class SampleGridComponent implements OnInit { header: "URL", path: "url", dataType: ColumnDataType.TextLong, + filterable:true, visible: true, }, ]; @@ -175,7 +177,7 @@ export class SampleGridComponent implements OnInit { } async loadSamples() { - this.samples = await this.analyticsService.getBlock_Samples(); + this.samples = await this.analyticsService.getCEP_BlockSamplesFromRepositories(); } ngOnDestroy() {} diff --git a/analytics-ui/src/shared/analytics.model.ts b/analytics-ui/src/shared/analytics.model.ts index 6bae726..abcde90 100644 --- a/analytics-ui/src/shared/analytics.model.ts +++ b/analytics-ui/src/shared/analytics.model.ts @@ -88,10 +88,11 @@ export const GITHUB_BASE = "https://api.github.com"; export const REPO_SAMPLES_NAME = "apama-analytics-builder-block-sdk"; export const REPO_SAMPLES_OWNER = "SoftwareAG"; export const REPO_SAMPLES_PATH = "samples/blocks"; +export const REPO_SAMPLES_BLOCKSDK = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/${REPO_SAMPLES_NAME}/contents/${REPO_SAMPLES_PATH}` export const BASE_URL = "service/analytics-ext-service"; export const ENDPOINT_EXTENSION = "extension"; -export const ANALYTICS_REPOSITORIES_TYPE = "extension"; +export const ANALYTICS_REPOSITORIES_TYPE = "c8y_CEP_repository"; export function uuidCustom(): string { let id = Math.random().toString(36).slice(-6); diff --git a/analytics-ui/src/shared/analytics.service.ts b/analytics-ui/src/shared/analytics.service.ts index 09a4c7c..d29fa90 100644 --- a/analytics-ui/src/shared/analytics.service.ts +++ b/analytics-ui/src/shared/analytics.service.ts @@ -14,7 +14,6 @@ import { import { AlertService, gettext, - ManagedObjectRealtimeService, ModalService, Status, } from "@c8y/ngx-components"; @@ -38,8 +37,10 @@ import { ENDPOINT_EXTENSION, ANALYTICS_REPOSITORIES_TYPE, Repository, + uuidCustom, + REPO_SAMPLES_BLOCKSDK, } from "./analytics.model"; -import { filter, map, pairwise, tap } from "rxjs/operators"; +import { filter, map, pairwise } from "rxjs/operators"; import { HttpClient } from "@angular/common/http"; @Injectable({ providedIn: "root" }) @@ -49,6 +50,7 @@ export class AnalyticsService { private restart: BehaviorSubject = new BehaviorSubject(null); protected baseUrl: string; private _cepId: Promise; + private _repositories: Promise | Repository[]; private realtime: Realtime; private subscription: Subscription; @@ -84,7 +86,14 @@ export class AnalyticsService { } async getRepositories(): Promise { - let result = []; + if (!this._repositories) { + this._repositories = this.getUncachedRepositories(); + } + return this._repositories; + } + + async getUncachedRepositories(): Promise { + let result = [] as Repository[]; const filter: object = { pageSize: 100, withTotalPages: true, @@ -93,16 +102,24 @@ export class AnalyticsService { type: ANALYTICS_REPOSITORIES_TYPE, }; let { data } = await this.inventoryService.listQuery(query, filter); - if (!data) { + if (!data || data.length == 0) { const reposMO: Partial = { name: "AnalyticsRepositories", type: ANALYTICS_REPOSITORIES_TYPE, }; - reposMO[ANALYTICS_REPOSITORIES_TYPE] = []; + reposMO[ANALYTICS_REPOSITORIES_TYPE] = [ + { + id: uuidCustom(), + name: "Block SDK Samples", + url: REPO_SAMPLES_BLOCKSDK, + }, + ] as Repository[]; this.inventoryService.create(reposMO); + result = reposMO[ANALYTICS_REPOSITORIES_TYPE]; } else if (data.length > 0) { result = data[0][ANALYTICS_REPOSITORIES_TYPE]; } + this._repositories = result; return result; } @@ -126,6 +143,7 @@ export class AnalyticsService { data[0][ANALYTICS_REPOSITORIES_TYPE] = repositories; this.inventoryService.update(data[0]); } + this._repositories = repositories; } async createExtensionsZIP(name: string, monitors: string[]): Promise { @@ -164,7 +182,7 @@ export class AnalyticsService { this.appDeleted.emit(app); } - async getCEP_Blocks(): Promise { + async getLoadedCEP_Blocks(): Promise { const result: CEP_Block[] = []; const meta: CEP_Metadata = await this.getCEP_Metadata(); if (meta && meta.metadatas) { @@ -176,9 +194,7 @@ export class AnalyticsService { const extensionNameAbbreviated = extensionName.match(/(.+?)(\.[^.]*$|$)/)[1]; extension.analytics.forEach((block) => { - //result.push({ name: block.name, category: block.category }); const cepBlock = block as CEP_Block; - //console.log(block.id); cepBlock.custom = !block.id.startsWith("apama.analyticsbuilder.blocks") && !block.id.startsWith("apama.analyticskit.blocks.core"); @@ -190,10 +206,31 @@ export class AnalyticsService { return result; } - async getBlock_Samples(): Promise[]> { - const sampleUrl = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/${REPO_SAMPLES_NAME}/contents/${REPO_SAMPLES_PATH}`; + async getCEP_BlockSamplesFromRepositories(): Promise { + const promises: Promise[] = []; + const reps: Repository[] = await this.getRepositories(); + + for (let i = 0; i < reps.length; i++) { + const url = reps[i].url; + const promise: Promise = + this.getCEP_BlockSamplesFromRepository(url); + promises.push(promise); + } + // return Promise.all(promises); + return promises[0]; + // return promises.reduce( + // (acc, promise) => + // acc.then((data) => { + // const r = data.concat(promise.); + // return r; + // }), + // Promise.resolve([]) + // ); + } + + async getCEP_BlockSamplesFromRepository(url: string): Promise { const result: any = this.githubFetchClient - .get(sampleUrl, { + .get(url, { headers: { "content-type": "application/json", }, @@ -259,12 +296,12 @@ export class AnalyticsService { async getCEPId(): Promise { if (!this._cepId) { - this._cepId = this.getUncachedCEPId(); + this._cepId = this.getUncachedCEP_Id(); } return this._cepId; } - async getUncachedCEPId(): Promise { + async getUncachedCEP_Id(): Promise { // get name of microservice from cep endpoint const response: IFetchResponse = await this.fetchClient.fetch( `${PATH_CEP_STATUS}`,