Skip to content

Commit

Permalink
fix(clusters/loadBalancers): fix false positive change detections
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed May 4, 2017
1 parent 9dc3381 commit d2e3bff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports = angular
function diffServerGroups(oldGroup, newGroup) {
var toRemove = [];
oldGroup.serverGroups.forEach(function(serverGroup, idx) {
serverGroup.stringVal = angular.toJson(serverGroup);
serverGroup.stringVal = serverGroup.stringVal || angular.toJson(serverGroup);
var newServerGroup = _.find(newGroup.serverGroups, { name: serverGroup.name, account: serverGroup.account, region: serverGroup.region });
if (!newServerGroup) {
$log.debug('server group no longer found, removing:', serverGroup.name, serverGroup.account, serverGroup.region);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@ import {APPLICATION_DATA_SOURCE_REGISTRY} from '../application/service/applicati
import {ENTITY_TAGS_READ_SERVICE} from '../entityTag/entityTags.read.service';
import {SETTINGS} from 'core/config/settings';
import {CLUSTER_SERVICE} from 'core/cluster/cluster.service';
import {JSON_UTILITY_SERVICE} from 'core/utils/json/json.utility.service';

module.exports = angular
.module('spinnaker.core.serverGroup.dataSource', [
APPLICATION_DATA_SOURCE_REGISTRY,
ENTITY_TAGS_READ_SERVICE,
CLUSTER_SERVICE,
JSON_UTILITY_SERVICE,
])
.run(function($q, applicationDataSourceRegistry, clusterService, entityTagsReader, serverGroupTransformer) {
.run(function($q, applicationDataSourceRegistry, clusterService, entityTagsReader, serverGroupTransformer, jsonUtilityService) {

let loadServerGroups = (application) => {
return clusterService.loadServerGroups(application);
};

let addServerGroups = (application, serverGroups) => {
return addTags(serverGroups).then(() => {
serverGroups.forEach(serverGroup => serverGroup.stringVal = JSON.stringify(serverGroup, serverGroupTransformer.jsonReplacer));
serverGroups.forEach(serverGroup => serverGroup.stringVal =
jsonUtilityService.makeSortedStringFromAngularObject(serverGroup, ['executions', 'runningTasks']));
application.clusters = clusterService.createServerGroupClusters(serverGroups);
let data = clusterService.addServerGroupsToApplication(application, serverGroups);
clusterService.addTasksToServerGroups(application);
Expand Down
14 changes: 14 additions & 0 deletions app/scripts/modules/core/utils/json/json.utility.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ export class JsonUtilityService {
return JSON.stringify(obj, null, 2);
}

public makeSortedStringFromAngularObject(obj: any, omit: string[] = []): string {
const replacer = (key: string, value: string) => {
let val = value;
if (typeof key === 'string' && key.charAt(0) === '$' && key.charAt(1) === '$') {
val = undefined;
}
if (omit.includes(key)) {
val = undefined;
}
return val;
};
return JSON.stringify(this.sortObject(obj), replacer);
}

public diff(left: any, right: any, sortKeys = false): IJsonDiff {
if (sortKeys) {
left = this.makeSortedString(left);
Expand Down

0 comments on commit d2e3bff

Please sign in to comment.