Skip to content

Commit

Permalink
ISPN-7328 Cache statuses in cache container page behave randomly
Browse files Browse the repository at this point in the history
  • Loading branch information
vblagoje authored and ryanemerson committed Jan 18, 2017
1 parent 02c5f6f commit 45ce387
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 17 deletions.
59 changes: 51 additions & 8 deletions src/module/cache-container/caches/CachesCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {ICacheContainer} from "../../../services/container/ICacheContainer";
import {ITemplate} from "../../../services/container-config/ITemplate";
import {CacheService} from "../../../services/cache/CacheService";
import {IMap} from "../../../common/utils/IMap";
import {isNullOrUndefined} from "../../../common/utils/Utils";
import {isNullOrUndefined, isNotNullOrUndefined} from "../../../common/utils/Utils";
import {ContainerService} from "../../../services/container/ContainerService";

export class CachesCtrl {
static $inject: string[] = ["$uibModal", "container", "caches", "templates", "cacheService"];
static $inject: string[] = ["$uibModal", "container", "caches", "templates", "cacheService", "containerService"];

traitCheckboxes: TraitCheckboxes = new TraitCheckboxes();
typeCheckboxes: TypeCheckboxes = new TypeCheckboxes();
Expand All @@ -27,14 +28,47 @@ export class CachesCtrl {
public container: ICacheContainer,
public caches: ICache[],
public templates: ITemplate[],
public cacheService: CacheService) {
for (let c of caches) {
this.cacheService.isAvailable(this.container, c)
.then(result => this.cacheAvailability[c.name] = result);
public cacheService: CacheService,
private containerService: ContainerService) {

this.cacheService.isEnabled(this.container.profile, c)
.then(result => this.cacheEnablement[c.name] = !result[c.name]);
// query only distributed and replicated caches (local and invalidation don't have availability attribute)
let cacheToQuery: ICache [] = [];
for (let cache of caches) {
if (cache.isLocal() || cache.isInvalidation()) {
this.cacheAvailability[cache.name] = true;
} else {
cacheToQuery.push(cache);
}
}

this.containerService.cachesAvailability(this.container, cacheToQuery).then(result => {
let cacheCounter: number = 0;
for (let resultField in result) {
let cacheResponse: any = result[resultField];
let validResponse: boolean = cacheResponse.outcome === "success" ? true : false;
let cacheName: string = cacheToQuery[cacheCounter].name;
if (validResponse) {
this.cacheAvailability[cacheName] = cacheResponse.result === "AVAILABLE" ? true : false;
} else {
this.cacheAvailability[cacheName] = false;
}
cacheCounter += 1;
}
});

this.containerService.cachesEnablement(this.container, caches).then(result => {
for (let resultField in result) {
let cacheResponse: any = result[resultField];
let validResponse: boolean = cacheResponse.outcome === "success" ? true : false;
if (validResponse) {
let cacheEnablementResponse: any = cacheResponse.result;
for (let cacheName in cacheEnablementResponse) {
this.cacheEnablement[cacheName] = !cacheEnablementResponse[cacheName];
}
}
}
}
);
}

createCache(): void {
Expand Down Expand Up @@ -66,4 +100,13 @@ export class CachesCtrl {
return result;
}
}

isStatusAvailable(cache: ICache): boolean {
return isNotNullOrUndefined(this.cacheAvailability[cache.name]) &&
isNotNullOrUndefined(this.cacheEnablement[cache.name]);
}

isAvailableAndEnabled(cache: ICache): boolean {
return this.isEnabled(cache) && this.isAvailable(cache);
}
}
6 changes: 5 additions & 1 deletion src/module/cache-container/caches/view/caches.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ <h2 class="card-pf-title">Add Cache
title="View Cache Details">
<div class="card-pf card-pf-accented card-pf-aggregate-status card-pf-with-action" vertilize>
<h2 class="card-pf-title">
<span class="pficon" ng-class="cachesCtrl.isAvailable(cache) && cachesCtrl.isEnabled(cache)? 'pficon-ok' : 'pficon-warning-triangle-o'"></span>{{cache.name}}
<span class="pficon"
ng-class="{'pficon-help':!cachesCtrl.isStatusAvailable(cache),
'pficon-ok':cachesCtrl.isAvailableAndEnabled(cache),
'pficon-warning-triangle-o':cachesCtrl.isStatusAvailable(cache) && !cachesCtrl.isAvailableAndEnabled(cache)}">
</span>{{cache.name}}
</h2>

<div class="card-pf-body">
Expand Down
8 changes: 0 additions & 8 deletions src/services/cache/CacheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,6 @@ export class CacheService {
return this.dmrService.readAttribute(request);
}

isAvailable(container: ICacheContainer, cache: ICache): ng.IPromise<boolean> {
let deferred: ng.IDeferred<boolean> = this.$q.defer<boolean>();
this.availability(container, cache).then((response: string) => {
deferred.resolve(response === "AVAILABLE");
}, () => deferred.resolve(false));
return deferred.promise;
}

setRebalance(container: ICacheContainer, cache: ICache, rebalance: boolean): ng.IPromise<any> {
return this.jgroupsService.getServerGroupCoordinator(container.serverGroup).then((coord: IServerAddress) => {
return this.dmrService.executePost({
Expand Down
37 changes: 37 additions & 0 deletions src/services/container/ContainerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {CacheService} from "../cache/CacheService";
import IQService = angular.IQService;
import {SecurityService} from "../security/SecurityService";
import {LaunchTypeService} from "../launchtype/LaunchTypeService";
import {ICache} from "../cache/ICache";
import {CompositeOpBuilder} from "../dmr/CompositeOpBuilder";

const module: ng.IModule = App.module("managementConsole.services.container", []);

Expand Down Expand Up @@ -170,6 +172,35 @@ export class ContainerService {
return deferred.promise;
}

cachesAvailability(container: ICacheContainer, caches: ICache[]): ng.IPromise<any> {
let firstServer: IServerAddress = container.serverGroup.members[0];
let address: string [] = this.getContainerAddress(container, firstServer);

let builder: CompositeOpBuilder = new CompositeOpBuilder();
for (let cache of caches) {
let op: IDmrRequest = {
address: address.concat(cache.type, cache.name),
name: "cache-availability",
operation: "read-attribute"
};
builder.add(op);
}
return this.dmrService.executePost(builder.build());
}

cachesEnablement(container: ICacheContainer, caches: ICache[]): ng.IPromise<any> {
let builder: CompositeOpBuilder = new CompositeOpBuilder();
for (let cache of caches) {
let op: IDmrRequest = {
operation: "is-ignored-all-endpoints",
address: this.generateEndpointAddress(container.profile),
"cache-names": [cache.name]
};
builder.add(op);
}
return this.dmrService.executePost(builder.build());
}

getSiteArrays(container: ICacheContainer): ng.IPromise<{[id: string]: string[]}> {
let deferred: ng.IDeferred<{[id: string]: string[]}> = this.$q.defer<{[id: string]: string[]}>();
this.jGroupsService.getServerGroupCoordinator(container.serverGroup)
Expand Down Expand Up @@ -252,6 +283,12 @@ export class ContainerService {
let containerPath: string[] = ["subsystem", "datagrid-infinispan"];
return this.launchType.getProfilePath(profile).concat(containerPath);
}

private generateEndpointAddress(profile?: string): string[] {
let path: string[] = ["subsystem", "datagrid-infinispan-endpoint"];
return this.launchType.getProfilePath(profile).concat(path);
}

}

module.service("containerService", ContainerService);

0 comments on commit 45ce387

Please sign in to comment.