Skip to content

Commit

Permalink
commit build instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Nov 28, 2023
1 parent 8f718ea commit e805a65
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 54 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -82,6 +83,23 @@ The provided block is an example of the adding the two inputs.
</p>
<br/> -->

## 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.
Expand Down
48 changes: 10 additions & 38 deletions analytics-service/cumulocity.json
Original file line number Diff line number Diff line change
@@ -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"
]

"apiVersion": "2",
"version": "{VERSION}",
"provider": {
"name": "Software AG"
},
"isolation": "PER_TENANT",
"requiredRoles": [
],
"roles": []
}
2 changes: 1 addition & 1 deletion analytics-ui/src/analytics/list/block.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
</c8y-form-group>
Expand Down
4 changes: 3 additions & 1 deletion analytics-ui/src/sample/list/sample.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class SampleGridComponent implements OnInit {
header: "Name",
path: "name",
dataType: ColumnDataType.TextLong,
filterable:true,
gridTrackSize: "15%",
visible: true,
},
Expand All @@ -72,6 +73,7 @@ export class SampleGridComponent implements OnInit {
header: "URL",
path: "url",
dataType: ColumnDataType.TextLong,
filterable:true,
visible: true,
},
];
Expand Down Expand Up @@ -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() {}
Expand Down
3 changes: 2 additions & 1 deletion analytics-ui/src/shared/analytics.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
63 changes: 50 additions & 13 deletions analytics-ui/src/shared/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import {
AlertService,
gettext,
ManagedObjectRealtimeService,
ModalService,
Status,
} from "@c8y/ngx-components";
Expand All @@ -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" })
Expand All @@ -49,6 +50,7 @@ export class AnalyticsService {
private restart: BehaviorSubject<string> = new BehaviorSubject<string>(null);
protected baseUrl: string;
private _cepId: Promise<string>;
private _repositories: Promise<Repository[]> | Repository[];
private realtime: Realtime;
private subscription: Subscription;

Expand Down Expand Up @@ -84,7 +86,14 @@ export class AnalyticsService {
}

async getRepositories(): Promise<Repository[]> {
let result = [];
if (!this._repositories) {
this._repositories = this.getUncachedRepositories();
}
return this._repositories;
}

async getUncachedRepositories(): Promise<Repository[]> {
let result = [] as Repository[];
const filter: object = {
pageSize: 100,
withTotalPages: true,
Expand All @@ -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<IManagedObject> = {
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;
}

Expand All @@ -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<any> {
Expand Down Expand Up @@ -164,7 +182,7 @@ export class AnalyticsService {
this.appDeleted.emit(app);
}

async getCEP_Blocks(): Promise<CEP_Block[]> {
async getLoadedCEP_Blocks(): Promise<CEP_Block[]> {
const result: CEP_Block[] = [];
const meta: CEP_Metadata = await this.getCEP_Metadata();
if (meta && meta.metadatas) {
Expand All @@ -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");
Expand All @@ -190,10 +206,31 @@ export class AnalyticsService {
return result;
}

async getBlock_Samples(): Promise<Partial<CEP_Block>[]> {
const sampleUrl = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/${REPO_SAMPLES_NAME}/contents/${REPO_SAMPLES_PATH}`;
async getCEP_BlockSamplesFromRepositories(): Promise<CEP_Block[]> {
const promises: Promise<CEP_Block[]>[] = [];
const reps: Repository[] = await this.getRepositories();

for (let i = 0; i < reps.length; i++) {
const url = reps[i].url;
const promise: Promise<CEP_Block[]> =
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<CEP_Block[]> {
const result: any = this.githubFetchClient
.get(sampleUrl, {
.get(url, {
headers: {
"content-type": "application/json",
},
Expand Down Expand Up @@ -259,12 +296,12 @@ export class AnalyticsService {

async getCEPId(): Promise<string> {
if (!this._cepId) {
this._cepId = this.getUncachedCEPId();
this._cepId = this.getUncachedCEP_Id();
}
return this._cepId;
}

async getUncachedCEPId(): Promise<string> {
async getUncachedCEP_Id(): Promise<string> {
// get name of microservice from cep endpoint
const response: IFetchResponse = await this.fetchClient.fetch(
`${PATH_CEP_STATUS}`,
Expand Down

0 comments on commit e805a65

Please sign in to comment.