Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Use HawkularAlertsManager as main API instead of HawkularAlert
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasponce committed Sep 16, 2015
1 parent 4dd2074 commit d58ac7e
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module HawkularMetrics {
export class AppServerDeploymentsDetailsController {
/// this is for minification purposes
public static $inject = ['$location', '$scope', '$rootScope', '$interval', '$log', '$filter', '$routeParams',
'$modal', 'HawkularInventory', 'HawkularMetric', 'HawkularAlert', 'HawkularOps', 'HawkularAlertsManager',
'$modal', 'HawkularInventory', 'HawkularMetric', 'HawkularOps', 'HawkularAlertsManager',
'ErrorsManager', '$q', 'NotificationsService'];

private autoRefreshPromise:ng.IPromise<number>;
Expand All @@ -46,7 +46,6 @@ module HawkularMetrics {
private $modal:any,
private HawkularInventory:any,
private HawkularMetric:any,
private HawkularAlert:any,
private HawkularOps:any,
private HawkularAlertsManager:IHawkularAlertsManager,
private ErrorsManager:IErrorsManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
module HawkularMetrics {

export class JvmAlertController {
public static $inject = ['$scope', 'HawkularAlert', 'HawkularAlertsManager', 'ErrorsManager', '$log', '$q',
public static $inject = ['$scope', 'HawkularAlertsManager', 'ErrorsManager', '$log', '$q',
'$rootScope', '$routeParams', '$modal', '$interval', 'HkHeaderParser'];

private resourceId: string;
Expand All @@ -41,7 +41,6 @@ module HawkularMetrics {
public headerLinks: any;

constructor(private $scope:any,
private HawkularAlert:any,
private HawkularAlertsManager: IHawkularAlertsManager,
private ErrorsManager: IErrorsManager,
private $log: ng.ILogService,
Expand Down Expand Up @@ -253,7 +252,13 @@ module HawkularMetrics {
}
alertIdList = alertIdList.slice(0, - 1);

this.HawkularAlert.Alert.resolve({alertIds: alertIdList}, {}).$promise.then( () => {
let resolvedAlerts = {
alertIds: alertIdList,
resolvedBy: 'user', // FIXME update with current user
resolvedNotes: 'Manually resolved'
};

this.HawkularAlertsManager.resolveAlerts(resolvedAlerts).then( () => {
this.alertList.length = 0;
this.isResolvingAll = false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module HawkularMetrics {
export class AppServerJvmDetailsController {
/// this is for minification purposes
public static $inject = ['$location', '$scope', '$rootScope', '$interval', '$log', '$filter', '$routeParams',
'$modal', '$window', 'HawkularInventory', 'HawkularMetric', 'HawkularAlert', 'HawkularAlertsManager',
'$modal', '$window', 'HawkularInventory', 'HawkularMetric', 'HawkularAlertsManager',
'ErrorsManager', '$q', 'md5'];

public static USED_COLOR = '#1884c7'; /// blue
Expand Down Expand Up @@ -58,7 +58,6 @@ module HawkularMetrics {
private $window: any,
private HawkularInventory: any,
private HawkularMetric: any,
private HawkularAlert: any,
private HawkularAlertsManager: HawkularMetrics.IHawkularAlertsManager,
private ErrorsManager: HawkularMetrics.IErrorsManager,
private $q: ng.IQService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module HawkularMetrics {

/// this is for minification purposes
public static $inject = ['$location', '$scope', '$rootScope', '$interval', '$log', '$filter', '$routeParams',
'$modal', 'HawkularInventory', 'HawkularMetric', 'HawkularAlert', 'HawkularAlertsManager', 'ErrorsManager',
'$modal', 'HawkularInventory', 'HawkularMetric', 'HawkularAlertsManager', 'ErrorsManager',
'$q', '$window', 'md5'];

public static MAX_ACTIVE_COLOR = '#1884c7'; /// blue
Expand All @@ -51,7 +51,6 @@ module HawkularMetrics {
private $modal: any,
private HawkularInventory: any,
private HawkularMetric: any,
private HawkularAlert: any,
private HawkularAlertsManager: IHawkularAlertsManager,
private ErrorsManager: IErrorsManager,
private $q: ng.IQService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,27 @@ module HawkularMetrics {
public templateUrl = 'plugins/metrics/html/directives/alert.html';


constructor(private HawkularAlert) {
constructor(private HawkularAlertsManager) {
this.link = (scope:any, element:ng.IAugmentedJQuery, attrs:ng.IAttributes) => {
scope.alertResolve = ():void => {
this.HawkularAlert.Alert.resolve({alertIds: scope.alert.id}, {}, () => {
let resolvedAlerts = {
alertIds: scope.alert.id,
resolvedBy: 'user', // FIXME update with current user
resolvedNotes: 'Manually resolved'
};
this.HawkularAlertsManager.resolveAlerts(resolvedAlerts).then( () => {
scope.refresh({hkAlert: scope.alert});
});
};
};
}

public static Factory() {
let directive = (HawkularAlert:any) => {
return new HkAlertPanel(HawkularAlert);
let directive = (HawkularAlertsManager:any) => {
return new HkAlertPanel(HawkularAlertsManager);
};

directive['$inject'] = ['HawkularAlert'];
directive['$inject'] = ['HawkularAlertsManager'];

return directive;
}
Expand Down
11 changes: 8 additions & 3 deletions console/src/main/scripts/plugins/metrics/ts/metricsAlerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module HawkularMetrics {


export class MetricsAlertController {
public static $inject = ['$scope', 'HawkularAlert', 'HawkularAlertsManager', 'ErrorsManager', '$log', '$q',
public static $inject = ['$scope', 'HawkularAlertsManager', 'ErrorsManager', '$log', '$q',
'$rootScope', '$routeParams', '$modal', '$interval', 'HkHeaderParser'];

private metricId: string; /// @todo: use MetricId
Expand All @@ -127,7 +127,6 @@ module HawkularMetrics {
public headerLinks: any;

constructor(private $scope:any,
private HawkularAlert:any,
private HawkularAlertsManager: HawkularMetrics.IHawkularAlertsManager,
private ErrorsManager: HawkularMetrics.IErrorsManager,
private $log: ng.ILogService,
Expand Down Expand Up @@ -214,7 +213,13 @@ module HawkularMetrics {
}
alertIdList = alertIdList.slice(0, - 1);

this.HawkularAlert.Alert.resolve({alertIds: alertIdList}, {}).$promise.then( () => {
let resolvedAlerts = {
alertIds: alertIdList,
resolvedBy: 'user', // FIXME update with current user
resolvedNotes: 'Manually resolved'
};

this.HawkularAlertsManager.resolveAlerts(resolvedAlerts).then( () => {
this.alertList.length = 0;
this.isResolvingAll = false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module HawkularMetrics {
export class AppServerListController {
/// this is for minification purposes
public static $inject = ['$location', '$scope', '$rootScope', '$interval', '$log', '$filter', '$modal',
'HawkularInventory', 'HawkularMetric', 'HawkularAlert', 'HawkularAlertsManager', 'ErrorsManager', '$q',
'HawkularInventory', 'HawkularMetric', 'HawkularAlertsManager', 'ErrorsManager', '$q',
'md5', 'HkHeaderParser'];

private resourceList;
Expand All @@ -43,7 +43,6 @@ module HawkularMetrics {
private $modal: any,
private HawkularInventory: any,
private HawkularMetric: any,
private HawkularAlert: any,
private HawkularAlertsManager: HawkularMetrics.IHawkularAlertsManager,
private ErrorsManager: HawkularMetrics.IErrorsManager,
private $q: ng.IQService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module HawkularMetrics {
export class MetricsAvailabilityController {
/// for minification only
public static $inject = ['$scope', '$rootScope', '$interval', '$window', '$log', 'HawkularMetric',
'HawkularAlert', '$routeParams', '$filter', '$moment', 'HawkularAlertsManager',
'$routeParams', '$filter', '$moment', 'HawkularAlertsManager',
'ErrorsManager', 'NotificationsService', '$modal'];

private availabilityDataPoints:IChartDataPoint[] = [];
Expand All @@ -61,7 +61,6 @@ module HawkularMetrics {
private $window:any,
private $log:ng.ILogService,
private HawkularMetric:any,
private HawkularAlert:any,
private $routeParams:any,
private $filter:ng.IFilterService,
private $moment:any,
Expand Down
14 changes: 6 additions & 8 deletions console/src/main/scripts/plugins/metrics/ts/metricsResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module HawkularMetrics {

export class MetricsViewController {
/// for minification only
public static $inject = ['$scope', '$rootScope', '$interval', '$log', 'HawkularAlert',
public static $inject = ['$scope', '$rootScope', '$interval', '$log',
'$routeParams', 'HawkularAlertsManager', 'ErrorsManager', 'NotificationsService', 'MetricsService'];

private bucketedDataPoints:IChartDataPoint[] = [];
Expand All @@ -45,7 +45,6 @@ module HawkularMetrics {
private $rootScope:IHawkularRootScope,
private $interval:ng.IIntervalService,
private $log:ng.ILogService,
private HawkularAlert:any,
private $routeParams:any,
private HawkularAlertsManager:IHawkularAlertsManager,
private ErrorsManager:IErrorsManager,
Expand Down Expand Up @@ -164,13 +163,12 @@ module HawkularMetrics {
}

private retrieveThreshold() {
this.HawkularAlert.Condition.query({triggerId: this.$routeParams.resourceId + '_trigger_thres'}).$promise
.then((response) => {

if (response[0]) {
this.threshold = response[0].threshold;
let triggerId = this.$routeParams.resourceId + '_trigger_thres';
this.HawkularAlertsManager.getTriggerConditions(triggerId)
.then((conditions) => {
if (conditions[0]) {
this.threshold = conditions[0].threshold;
}

}, (error) => {
this.$log.error('Error Loading Threshold data');
toastr.error('Error Loading Threshold Data: ' + error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ module HawkularMetrics {
queryAlerts(metricId: MetricId, startTime?:TimestampInMillis,
endTime?:TimestampInMillis, currentPage?:number, perPage?:number): any;

// Alerts

/**
* @name queryAllAlerts
* @desc Fetch all Alerts with status OPEN
* @returns {ng.IPromise} with a list of Alerts
*/
queryAllAlerts(): ng.IPromise<any>;

/**
* @name resolveAlerts
* @desc Mark as resolved a list of alerts*
* @param resolvedAlerts - An object with the description of the resolution of the alerts, in the form
*
* resolvedAlerts = {
* alertIds: A string with a comma separated list of Alert ids,
* resolvedBy: The user responsible of the resolution of the alerts,
* resolvedNotes: Additional notes to add in the resolved state
* }
*
* @returns {ng.IPromise}
*/
resolveAlerts(resolvedAlerts: any): ng.IPromise<any>;

// Triggers

/**
Expand All @@ -62,6 +86,14 @@ module HawkularMetrics {
*/
getTrigger(triggerId: TriggerId): any;

/**
* @name getTriggerConditions
* @desc Fetch only Conditions for a specified trigger
* @param {TriggerId} triggerId - The id of the trigger to fetch Conditions
* @returns {ng.IPromise} with a list of conditions as a value
*/
getTriggerConditions(triggerId: TriggerId): ng.IPromise<any>;

/**
* @name createTrigger
* @desc Create a Trigger with Dampenings and Conditions
Expand Down Expand Up @@ -106,6 +138,8 @@ module HawkularMetrics {
* }
*/
updateTrigger(fullTrigger: any, errorCallback: any, backupTrigger?: any): ng.IPromise<any>;


}

export class HawkularAlertsManager implements IHawkularAlertsManager{
Expand All @@ -120,6 +154,14 @@ module HawkularMetrics {
private ErrorsManager: HawkularMetrics.IErrorsManager) {
}

queryAllAlerts(): ng.IPromise<any> {
return this.HawkularAlert.Alert.query({statuses: 'OPEN'}).$promise;
}

public resolveAlerts(resolvedAlerts: any): ng.IPromise<any> {
return this.HawkularAlert.Alert.resolve(resolvedAlerts, {}).$promise;
}

public existTrigger(triggerId: TriggerId): any {
return this.HawkularAlert.Trigger.get({triggerId: triggerId}).$promise;
}
Expand All @@ -142,6 +184,10 @@ module HawkularMetrics {
return deffered.promise;
}

public getTriggerConditions(triggerId: TriggerId): ng.IPromise<any> {
return this.HawkularAlert.Condition.query({triggerId: triggerId}).$promise;
}

public createTrigger(fullTrigger: any, errorCallback: any): ng.IPromise<void> {

let triggerDefaults = {
Expand Down
7 changes: 3 additions & 4 deletions console/src/main/scripts/plugins/metrics/ts/urlList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module HawkularMetrics {
export class UrlListController {
/// this is for minification purposes
public static $inject = ['$location', '$scope', '$rootScope', '$interval', '$log', '$filter', '$modal',
'HawkularInventory', 'HawkularMetric', 'HawkularAlert', 'HawkularAlertsManager', 'ErrorsManager', '$q',
'HawkularInventory', 'HawkularMetric', 'HawkularAlertsManager', 'ErrorsManager', '$q',
'md5', 'HkHeaderParser', 'NotificationsService'];

private autoRefreshPromise:ng.IPromise<number>;
Expand All @@ -73,7 +73,6 @@ module HawkularMetrics {
private $modal:any,
private HawkularInventory:any,
private HawkularMetric:any,
private HawkularAlert:any,
private HawkularAlertsManager:IHawkularAlertsManager,
private ErrorsManager:IErrorsManager,
private $q:ng.IQService,
Expand Down Expand Up @@ -318,9 +317,9 @@ module HawkularMetrics {
this.headerLinks = this.HkHeaderParser.parse(getResponseHeaders());

aResourceList.expanded = this.resourceList ? this.resourceList.expanded : [];
this.HawkularAlert.Alert.query({statuses: 'OPEN'}, (anAlertList) => {
this.HawkularAlertsManager.queryAllAlerts().then((anAlertList) => {
this.alertList = anAlertList;
}, this);
});
var promises = [];
angular.forEach(aResourceList, function (res) {
var traitsArray:string[] = [];
Expand Down

0 comments on commit d58ac7e

Please sign in to comment.