From 2c510ef5cb82a71da853de0cec213e88f911e3dc Mon Sep 17 00:00:00 2001 From: James Strachan Date: Tue, 25 Apr 2017 16:44:31 +0100 Subject: [PATCH 1/2] feat(apps-function): add an appsInfo function lets add a function to return all the environments and for each environment return the name and all the apps, their version and deployUrl so we can easily view summaries per environment or per app --- src/app/kubernetes/model/build.model.ts | 24 ++++-- src/app/kubernetes/model/buildconfig.model.ts | 80 ++++++++++++++++++- 2 files changed, 96 insertions(+), 8 deletions(-) diff --git a/src/app/kubernetes/model/build.model.ts b/src/app/kubernetes/model/build.model.ts index d16a98c..a332ed1 100644 --- a/src/app/kubernetes/model/build.model.ts +++ b/src/app/kubernetes/model/build.model.ts @@ -32,7 +32,7 @@ export class Build extends KubernetesSpecResource { private _pipelineStages: Array; private _serviceUrls: Array = new Array(); - private _serviceEnvironmentsMap: Map = new Map(); + private _serviceEnvironmentsMap: Map = new Map(); get serviceUrls(): Array { // lets force the lazy creation @@ -40,11 +40,11 @@ export class Build extends KubernetesSpecResource { return this._serviceUrls; } - get serviceEnvironmentMap(): Map { + get serviceEnvironmentMap(): Map { let annotations = this.annotations; if (annotations) { for (let key in annotations) { - if (key && key.startsWith(serviceEnvironmentsAnnotationPrefix)) { + if (key && key.indexOf(serviceEnvironmentsAnnotationPrefix) === 0) { let yamlText = annotations[key]; let envKey = key.substring(serviceEnvironmentsAnnotationPrefix.length); if (envKey) { @@ -52,8 +52,8 @@ export class Build extends KubernetesSpecResource { let config = jsyaml.safeLoad(yamlText); if (config) { let se = new ServiceEnvironments(config.environmentName as string, - config.serviceUrls as Map, - config.deploymentVersions as Map); + config.serviceUrls as Map, + config.deploymentVersions as Map); this._serviceEnvironmentsMap[envKey] = se; } } catch (e) { @@ -239,7 +239,19 @@ export class ServiceUrl { } export class ServiceEnvironments { - constructor(public environmentName: string, public serviceUrls: Map, public deploymentVersions: Map) {} + constructor(public environmentName: string, public serviceUrls: Map, public deploymentVersions: Map) {} + + toAppInfo(name: string): AppInfo { + let deployUrl = this.serviceUrls[name] || ""; + let version = this.deploymentVersions[name] || ""; + let environmentName = this.environmentName; + return new AppInfo(name, deployUrl, version, environmentName); + } +} + +export class AppInfo { + constructor(public name: string, public deployUrl: string, public version: string, public environmentName: string) { + } } export class Builds extends Array{ diff --git a/src/app/kubernetes/model/buildconfig.model.ts b/src/app/kubernetes/model/buildconfig.model.ts index 68b7387..aac5e8e 100644 --- a/src/app/kubernetes/model/buildconfig.model.ts +++ b/src/app/kubernetes/model/buildconfig.model.ts @@ -1,5 +1,5 @@ import {KubernetesSpecResource} from "./kuberentesspecresource.model"; -import {Build, Builds, ServiceUrl} from "./build.model"; +import {Build, Builds, ServiceUrl, ServiceEnvironments, AppInfo} from "./build.model"; import {Params} from "@angular/router"; export const defaultBuildIconStyle = "pficon-build"; @@ -105,10 +105,53 @@ export class BuildConfig extends KubernetesSpecResource { * Returns the Jenkins test report URL of the last build if it is available */ get jenkinsTestReportUrl(): string { - let build = this.lastBuild + let build = this.lastBuild; return build ? build.jenkinsTestReportUrl : ""; } + get serviceEnvironmentMap(): Map { + let build = this.lastBuild; + if (!build) { + return new Map(); + } + const answer = build.serviceEnvironmentMap; + let builds = this.builds; + if (builds.length && builds.length > 1) { + let previousBuild = builds[1]; + let map = previousBuild.serviceEnvironmentMap; + if (map) { + for (let key in map) { + let value = map[key]; + if (!answer[key]) { + answer[key] = value; + } + } + } + } + return answer; + } + + /** + * Returns a map indexed by the environment key of the app information + */ + get environmentApp(): Map { + let map = this.serviceEnvironmentMap; + let answer = new Map(); + let name = this.name; + if (map && name) { + for (let environmentKey in map) { + let value = map[environmentKey]; + let appInfo = value.toAppInfo(name); + if (appInfo) { + answer[environmentKey] = appInfo; + } + } + } + return answer; + } + + + updateValuesFromResource() { super.updateValuesFromResource(); @@ -217,3 +260,36 @@ export function filterPipelines(buildConfigs: BuildConfigs): BuildConfigs { }); return answer; } + +/** + * returns a map of all the environments with the apps in each environment + */ +export function appInfos(buildConfigs: BuildConfigs): Map { + let answer = new Map(); + buildConfigs.forEach(bc => { + let appEnv = bc.environmentApp; + for (let environmentKey in appEnv) { + let app = appEnv[environmentKey]; + let env = answer[environmentKey]; + if (!env) { + env = new EnvironmentApps(); + answer[environmentKey] = env; + } + if (!env.name) { + env.name = app.environmentName; + } + env.apps[app.name] = app; + } + }); + return answer; +} + +window['appInfos'] = appInfos; + +/** + * Keeps track of all the apps in each environment along with its name + */ +export class EnvironmentApps { + apps: Map = new Map(); + name: string; +} \ No newline at end of file From ce7907b091f4a16c0f42550eecfdb068c96563e7 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Tue, 25 Apr 2017 16:47:11 +0100 Subject: [PATCH 2/2] remove debug property --- src/app/kubernetes/model/buildconfig.model.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/kubernetes/model/buildconfig.model.ts b/src/app/kubernetes/model/buildconfig.model.ts index aac5e8e..af01cb4 100644 --- a/src/app/kubernetes/model/buildconfig.model.ts +++ b/src/app/kubernetes/model/buildconfig.model.ts @@ -284,8 +284,6 @@ export function appInfos(buildConfigs: BuildConfigs): Map