Skip to content

Commit

Permalink
fix(clusters): convert on-demand params to filter params for small apps
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed Apr 10, 2017
1 parent cd357c8 commit 5091894
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/scripts/modules/core/cluster/cluster.service.spec.ts
Expand Up @@ -14,6 +14,7 @@ describe('Service: Cluster', function () {
);

let clusterService: ClusterService;
let ClusterFilterModel: any;
let $http: IHttpBackendService;
let API: Api;
let application: Application;
Expand All @@ -27,11 +28,12 @@ describe('Service: Cluster', function () {
};
}

beforeEach(mock.inject(($httpBackend: IHttpBackendService, _API_: Api,
beforeEach(mock.inject(($httpBackend: IHttpBackendService, _API_: Api, _ClusterFilterModel_: any,
_clusterService_: ClusterService, applicationModelBuilder: ApplicationModelBuilder) => {
$http = $httpBackend;
API = _API_;
clusterService = _clusterService_;
ClusterFilterModel = _ClusterFilterModel_;

application = applicationModelBuilder.createApplication(
{key: 'serverGroups'},
Expand Down Expand Up @@ -69,6 +71,19 @@ describe('Service: Cluster', function () {
expect(application.serverGroups.fetchOnDemand).toBe(false);
expect(serverGroups).toEqual([]);
});

it('converts clusters parameter to q and account params when there are fewer than 251 clusters', () => {
let clusters = Array(250);
ClusterFilterModel.sortFilter.clusters = {'test:myapp': true};
$http.expectGET(API.baseUrl + '/applications/app/clusters').respond(200, {test: clusters});
$http.expectGET(API.baseUrl + '/applications/app/serverGroups').respond(200, []);
let serverGroups: ServerGroup[] = null;
clusterService.loadServerGroups(application).then((result: ServerGroup[]) => serverGroups = result);
$http.flush();
expect(application.serverGroups.fetchOnDemand).toBe(false);
expect(ClusterFilterModel.sortFilter.filter).toEqual('clusters:myapp');
expect(ClusterFilterModel.sortFilter.account.test).toBe(true);
});
});

describe('health count rollups', () => {
Expand Down
25 changes: 25 additions & 0 deletions app/scripts/modules/core/cluster/cluster.service.ts
Expand Up @@ -30,6 +30,8 @@ export class ClusterService {
serverGroupLoader.withParams({
clusters: this.filterModelService.getCheckValues(this.ClusterFilterModel.sortFilter.clusters).join()
});
} else {
this.reconcileClusterDeepLink();
}
return serverGroupLoader.getList().then((serverGroups: ServerGroup[]) => {
serverGroups.forEach(sg => this.addHealthStatusCheck(sg));
Expand All @@ -39,6 +41,29 @@ export class ClusterService {
});
}

// if the application is deep linked via "clusters:", but the app is not "fetchOnDemand" sized, convert the parameters
// to the normal, filterable structure
private reconcileClusterDeepLink() {
const selectedClusters: string[] = this.filterModelService.getCheckValues(this.ClusterFilterModel.sortFilter.clusters);
if (selectedClusters && selectedClusters.length) {
const clusterNames: string[] = [];
const accountNames: string[] = [];
selectedClusters.forEach(clusterKey => {
const [account, cluster] = clusterKey.split(':');
accountNames.push(account);
if (cluster) {
clusterNames.push(cluster);
}
});
if (clusterNames.length) {
accountNames.forEach(account => this.ClusterFilterModel.sortFilter.account[account] = true);
this.ClusterFilterModel.sortFilter.filter = `clusters:${clusterNames.join()}`;
this.ClusterFilterModel.sortFilter.clusters = {};
this.ClusterFilterModel.applyParamsToUrl();
}
}
}

public addServerGroupsToApplication(application: Application, serverGroups: ServerGroup[] = []): ServerGroup[] {
if (application.serverGroups.data) {
let data = application.serverGroups.data;
Expand Down

0 comments on commit 5091894

Please sign in to comment.