Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #378 from jstrachan/malarkey
Browse files Browse the repository at this point in the history
feat(apps-function): add an appsInfo function
  • Loading branch information
jstrachan authored Apr 25, 2017
2 parents 7d882ad + ce7907b commit 035247c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 8 deletions.
24 changes: 18 additions & 6 deletions src/app/kubernetes/model/build.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,28 @@ export class Build extends KubernetesSpecResource {

private _pipelineStages: Array<PipelineStage>;
private _serviceUrls: Array<ServiceUrl> = new Array<ServiceUrl>();
private _serviceEnvironmentsMap: Map<String,ServiceEnvironments> = new Map<String,ServiceEnvironments>();
private _serviceEnvironmentsMap: Map<string,ServiceEnvironments> = new Map<string,ServiceEnvironments>();

get serviceUrls(): Array<ServiceUrl> {
// lets force the lazy creation
let foo = this.serviceEnvironmentMap;
return this._serviceUrls;
}

get serviceEnvironmentMap(): Map<String,ServiceEnvironments> {
get serviceEnvironmentMap(): Map<string,ServiceEnvironments> {
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) {
try {
let config = jsyaml.safeLoad(yamlText);
if (config) {
let se = new ServiceEnvironments(config.environmentName as string,
config.serviceUrls as Map<String,String>,
config.deploymentVersions as Map<String,String>);
config.serviceUrls as Map<string,string>,
config.deploymentVersions as Map<string,string>);
this._serviceEnvironmentsMap[envKey] = se;
}
} catch (e) {
Expand Down Expand Up @@ -239,7 +239,19 @@ export class ServiceUrl {
}

export class ServiceEnvironments {
constructor(public environmentName: string, public serviceUrls: Map<String,String>, public deploymentVersions: Map<String,String>) {}
constructor(public environmentName: string, public serviceUrls: Map<string,string>, public deploymentVersions: Map<string,string>) {}

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<Build>{
Expand Down
78 changes: 76 additions & 2 deletions src/app/kubernetes/model/buildconfig.model.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<string,ServiceEnvironments> {
let build = this.lastBuild;
if (!build) {
return new Map<string,ServiceEnvironments>();
}
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<string,AppInfo> {
let map = this.serviceEnvironmentMap;
let answer = new Map<string,AppInfo>();
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();

Expand Down Expand Up @@ -217,3 +260,34 @@ 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<string,EnvironmentApps> {
let answer = new Map<string,EnvironmentApps>();
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;
}

/**
* Keeps track of all the apps in each environment along with its name
*/
export class EnvironmentApps {
apps: Map<string, AppInfo> = new Map<string, AppInfo>();
name: string;
}

0 comments on commit 035247c

Please sign in to comment.