Skip to content

Commit

Permalink
Merge pull request #3484 from icfantv/commit_diffs
Browse files Browse the repository at this point in the history
feat(aws/netflix): add diff view to ASG details
  • Loading branch information
icfantv committed Apr 6, 2017
2 parents 7da3ea4 + be89bd4 commit cabcb50
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 73 deletions.
@@ -1,6 +1,6 @@
'use strict';

import _ from 'lodash';
import {chain, filter, find, get, isEmpty} from 'lodash';
let angular = require('angular');

import {ACCOUNT_SERVICE} from 'core/account/account.service';
Expand Down Expand Up @@ -61,7 +61,7 @@ module.exports = angular.module('spinnaker.serverGroup.details.aws.controller',
return app
.ready()
.then(() => {
var summary = _.find(app.serverGroups.data, (toCheck) => {
var summary = find(app.serverGroups.data, (toCheck) => {
return toCheck.name === serverGroup.name && toCheck.account === serverGroup.accountId && toCheck.region === serverGroup.region;
});
if (!summary) {
Expand Down Expand Up @@ -107,7 +107,7 @@ module.exports = angular.module('spinnaker.serverGroup.details.aws.controller',
this.serverGroup = plainDetails;
this.applyAccountDetails(this.serverGroup);

if (!_.isEmpty(this.serverGroup)) {
if (!isEmpty(this.serverGroup)) {

this.image = details.image ? details.image : undefined;

Expand All @@ -116,7 +116,7 @@ module.exports = angular.module('spinnaker.serverGroup.details.aws.controller',
if (vpc !== '') {
var subnetId = vpc.split(',')[0];
subnetReader.listSubnets().then((subnets) => {
var subnet = _.chain(subnets).find({'id': subnetId}).value();
var subnet = chain(subnets).find({'id': subnetId}).value();
this.serverGroup.subnetType = subnet.purpose;
});
}
Expand All @@ -139,9 +139,9 @@ module.exports = angular.module('spinnaker.serverGroup.details.aws.controller',
}

if (details.launchConfig && details.launchConfig.securityGroups) {
this.securityGroups = _.chain(details.launchConfig.securityGroups).map((id) => {
return _.find(app.securityGroups.data, { 'accountName': serverGroup.accountId, 'region': serverGroup.region, 'id': id }) ||
_.find(app.securityGroups.data, { 'accountName': serverGroup.accountId, 'region': serverGroup.region, 'name': id });
this.securityGroups = chain(details.launchConfig.securityGroups).map((id) => {
return find(app.securityGroups.data, { 'accountName': serverGroup.accountId, 'region': serverGroup.region, 'id': id }) ||
find(app.securityGroups.data, { 'accountName': serverGroup.accountId, 'region': serverGroup.region, 'name': id });
}).compact().value();
}

Expand All @@ -156,6 +156,10 @@ module.exports = angular.module('spinnaker.serverGroup.details.aws.controller',
.filter(p => !p.enabled)
.some(p => ['Launch','Terminate','ScheduledAction'].includes(p.name));
configureEntityTagTargets();

this.changeConfig = {
metadata: this.serverGroup.entityTags.creationMetadata
};
} else {
autoClose();
}
Expand All @@ -180,7 +184,7 @@ module.exports = angular.module('spinnaker.serverGroup.details.aws.controller',
this.isEnableLocked = () => {
if (this.serverGroup.isDisabled) {
let resizeTasks = (this.serverGroup.runningTasks || [])
.filter(task => _.get(task, 'execution.stages', []).some(
.filter(task => get(task, 'execution.stages', []).some(
stage => stage.type === 'resizeServerGroup'));
if (resizeTasks.length) {
return true;
Expand Down Expand Up @@ -301,8 +305,8 @@ module.exports = angular.module('spinnaker.serverGroup.details.aws.controller',
resolve: {
serverGroup: () => this.serverGroup,
disabledServerGroups: () => {
var cluster = _.find(app.clusters, {name: this.serverGroup.cluster, account: this.serverGroup.account});
return _.filter(cluster.serverGroups, {isDisabled: true, region: this.serverGroup.region});
var cluster = find(app.clusters, {name: this.serverGroup.cluster, account: this.serverGroup.account});
return filter(cluster.serverGroups, {isDisabled: true, region: this.serverGroup.region});
},
allServerGroups: () => app.getDataSource('serverGroups').data.filter(g =>
g.cluster === this.serverGroup.cluster &&
Expand Down
Expand Up @@ -88,6 +88,10 @@ <h3 select-on-dbl-click>
<dd>{{ctrl.serverGroup.createdTime | timestamp}}</dd>
<render-if-feature feature="entityTags">
<entity-source metadata="ctrl.serverGroup.entityTags.creationMetadata"></entity-source>
<view-changes-link commits="ctrl.commits"
jar-diffs="ctrl.jarDiffs"
link-text="view changes"
name-item="ctrl.serverGroup"></view-changes-link>
</render-if-feature>
<dt>In</dt>
<dd>
Expand All @@ -105,7 +109,6 @@ <h3 select-on-dbl-click>
<li ng-repeat="zone in ctrl.serverGroup.asg.availabilityZones">{{zone}}</li>
</ul>
</dd>

</dl>
</collapsible-section>
<collapsible-section heading="Capacity" expanded="true">
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/modules/core/core.module.js
Expand Up @@ -6,6 +6,7 @@ let angular = require('angular');
import {AUTHENTICATION} from './authentication/authentication.module';
import {API_SERVICE} from './api/api.service';
import {CLOUD_PROVIDER_LOGO} from './cloudProvider/cloudProviderLogo.component';
import {CORE_DIFF_MODULE} from './diffs';
import {HELP_FIELD_COMPONENT} from './help/helpField.component';
import {STATE_CONFIG_PROVIDER} from './navigation/state.provider';
import {APPLICATIONS_STATE_PROVIDER} from './application/applications.state.provider';
Expand Down Expand Up @@ -59,6 +60,7 @@ module.exports = angular

require('./cache/caches.module.js'),
CLOUD_PROVIDER_LOGO,
CORE_DIFF_MODULE,
require('./cloudProvider/cloudProviderLabel.directive.js'),
require('./cloudProvider/serviceDelegate.service.js'),
require('./cluster/cluster.module.js'),
Expand Down
27 changes: 27 additions & 0 deletions app/scripts/modules/core/diffs/changes.html
@@ -0,0 +1,27 @@
<div modal-page>
<modal-close (dismiss)="$ctrl.close()"></modal-close>
<div class="modal-header has-sticky-headers">
<h3>Changes to {{$ctrl.nameItem.name}}</h3>
</div>
<div class="modal-body" style="max-height: 800px; overflow-y: scroll;" sticky-headers>
<div ng-if="$ctrl.commits.length">
<div class="component-heading" sticky-header>
<h4>Commits</h4>
</div>
<div class="component-body">
<commit-history commits="$ctrl.commits"></commit-history>
</div>
</div>
<div ng-if="$ctrl.hasJarChanges">
<div class="component-heading" sticky-header>
<h4>JAR Changes</h4>
</div>
<div class="component-body">
<jar-diff jar-diffs="$ctrl.jarDiffs"></jar-diff>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="$ctrl.close()">Close</button>
</div>
</div>
34 changes: 34 additions & 0 deletions app/scripts/modules/core/diffs/commitHistory.component.ts
@@ -0,0 +1,34 @@
import {module} from 'angular';

import {IComponentOptions} from 'angular';

export interface ICommit {
authorDisplayName: string;
commitUrl: string;
displayId: string;
id: string;
message: string;
timestamp: number;
}

class CommitHistoryComponent implements IComponentOptions {
public bindings: any = {
commits: '<'
};
public template = `
<div ng-if="$ctrl.commits && $ctrl.commits.length">
<table class="table table-condensed">
<tr><th>Date</th><th>Commit</th><th>Message</th><th>Author</th></tr>
<tr ng-repeat="commit in $ctrl.commits">
<td>{{commit.timestamp | date:'MM/dd'}}</td>
<td><a target="_blank" href="{{commit.commitUrl}}">{{commit.displayId}}</a></td>
<td>{{commit.message | limitTo: 50}}</td>
<td>{{commit.authorDisplayName || 'N/A'}}</td>
</tr>
</table>
</div>
`;
}

export const COMMIT_HISTORY_COMPONENT = 'spinnaker.diffs.commit.history.component';
module(COMMIT_HISTORY_COMPONENT, []).component('commitHistory', new CommitHistoryComponent());
6 changes: 6 additions & 0 deletions app/scripts/modules/core/diffs/index.ts
@@ -0,0 +1,6 @@
import {module} from 'angular';

import {VIEW_CHANGES_LINK} from './viewChangesLink.component';

export const CORE_DIFF_MODULE = 'spinnaker.diff.module';
module(CORE_DIFF_MODULE, [VIEW_CHANGES_LINK]);
80 changes: 80 additions & 0 deletions app/scripts/modules/core/diffs/jarDiff.component.ts
@@ -0,0 +1,80 @@
import {IComponentController, IComponentOptions, module} from 'angular';

export interface IJarDiffItem {
displayDiff: string;
}

export interface IJarDiff {
[key: string]: IJarDiffItem[];
added: IJarDiffItem[];
downgraded: IJarDiffItem[];
duplicates: IJarDiffItem[];
removed: IJarDiffItem[];
unchanged: IJarDiffItem[];
unknown: IJarDiffItem[];
upgraded: IJarDiffItem[];
}

class JarDiffComponentController implements IComponentController {

public jarDiffs: IJarDiff;
public hasJarDiffs = false;

public $onInit() {
this.hasJarDiffs = Object.keys(this.jarDiffs).some((key: string) => this.jarDiffs[key].length > 0);
}

public $onChanges() {
this.$onInit();
}
}

class JarDiffComponent implements IComponentOptions {
public bindings: any = {
jarDiffs: '<'
};
public controller: any = JarDiffComponentController;
public template = `
<div ng-if="$ctrl.hasJarDiffs">
<table class="table table-condensed no-lines" ng-if="$ctrl.jarDiffs.added && $ctrl.jarDiffs.added.length">
<tr><th>Added</th></tr>
<tr ng-repeat="jar in $ctrl.jarDiffs.added">
<td>{{jar.displayDiff}}</td>
</tr>
</table>
<table class="table table-condensed no-lines" ng-if="$ctrl.jarDiffs.removed && $ctrl.jarDiffs.removed.length">
<tr><th>Removed</th></tr>
<tr ng-repeat="jar in $ctrl.jarDiffs.removed">
<td>{{jar.displayDiff}}</td>
</tr>
</table>
<table class="table table-condensed no-lines" ng-if="$ctrl.jarDiffs.upgraded && $ctrl.jarDiffs.upgraded.length">
<tr><th>Upgraded</th></tr>
<tr ng-repeat="jar in $ctrl.jarDiffs.upgraded">
<td>{{jar.displayDiff}}</td>
</tr>
</table>
<table class="table table-condensed no-lines" ng-if="$ctrl.jarDiffs.downgraded && $ctrl.jarDiffs.downgraded.length">
<tr><th>Downgraded</th></tr>
<tr ng-repeat="jar in $ctrl.jarDiffs.downgraded">
<td>{{jar.displayDiff}}</td>
</tr>
</table>
<table class="table table-condensed no-lines" ng-if="$ctrl.jarDiffs.duplicates && $ctrl.jarDiffs.duplicates.length">
<tr><th>Duplicates</th></tr>
<tr ng-repeat="jar in $ctrl.jarDiffs.duplicates">
<td>{{jar.displayDiff}}</td>
</tr>
</table>
<table class="table table-condensed no-lines" ng-if="$ctrl.jarDiffs.unknown && $ctrl.jarDiffs.unknown.length">
<tr><th>Unknown</th></tr>
<tr ng-repeat="jar in $ctrl.jarDiffs.unknown">
<td>{{jar.displayDiff}}</td>
</tr>
</table>
</div>
`;
}

export const JAR_DIFF_COMPONENT = 'spinnaker.diffs.jar.diff.component';
module(JAR_DIFF_COMPONENT, []).component('jarDiff', new JarDiffComponent());

0 comments on commit cabcb50

Please sign in to comment.