Skip to content

Commit

Permalink
Merge pull request #109 from Jiri-Kremser/HWKINVENT-38
Browse files Browse the repository at this point in the history
HWKINVENT-38 + HAWKULAR-100
  • Loading branch information
mtho11 committed May 14, 2015
2 parents 15acbe4 + 8741f8f commit 758c0c6
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 113 deletions.
53 changes: 48 additions & 5 deletions dist/hawkular-ui-components-accounts.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/hawkular-ui-components-alerts.js

Large diffs are not rendered by default.

56 changes: 33 additions & 23 deletions dist/hawkular-ui-components-directives.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/hawkular-ui-components-inventory.js

Large diffs are not rendered by default.

61 changes: 36 additions & 25 deletions dist/hawkular-ui-components-metrics.js

Large diffs are not rendered by default.

65 changes: 64 additions & 1 deletion plugins/accounts/plugins/accounts/ts/accountsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module HawkularAccounts {
$httpProvider.interceptors.push(PersonaInterceptorService.Factory);
}]);

_module.run(['$rootScope', '$log', '$modal', '$document', 'userDetails', 'HawtioNav', ($rootScope, $log, $modal, $document, userDetails, HawtioNav:HawtioMainNav.Registry) => {
_module.run(['$rootScope', '$log', '$modal', '$document', 'userDetails', 'HawtioNav', 'HawkularInventory', ($rootScope, $log, $modal, $document, userDetails, HawtioNav:HawtioMainNav.Registry, hawkularInventory) => {
//HawtioNav.add(accountsTab);
$rootScope.userDetails = userDetails;

Expand All @@ -56,12 +56,75 @@ module HawkularAccounts {
});
});

var initializeInventory = (tenantId: string) => {

var addTenant = () => {
var tenant = {
id: tenantId
};
return hawkularInventory.Tenant.save(tenant).$promise;
};

var addEnvironment = () => {
// todo: environment is hard-coded here
var environment = {
id: 'test'
};
return hawkularInventory.Environment.save({tenantId: tenantId}, environment).$promise;
};

var addResourceType = () => {
var resourceType = {
id: 'URL',
version: '1.0'
};
return hawkularInventory.ResourceType.save({tenantId: tenantId}, resourceType).$promise;
};

var addMetricType = (id: string, units: string) => {
var metricType = {
id: id,
unit: units
};
return hawkularInventory.MetricType.save({tenantId: tenantId}, metricType).$promise;
};

var notify = () => $rootScope.$emit("UserInitialized", tenantId);

var err = (error: any, msg: string): void => {
toastr.error(msg);
// todo: use HawkularErrorManager once it is available in shared services
// this.HawkularErrorManager.errorHandler(error, msg);
};

addTenant()
.then(() => addEnvironment()
.then(addResourceType)
.then(addMetricType('status.duration.type', 'MILLI_SECOND'))
.then(addMetricType('status.code.type', 'NONE'))
.then(notify)
.catch((e) => {
err(e, 'Error initializing the data for user.');
notify();
})
,() => {
// this is called if the very first call in chain fails
// (tenant has been created so we assume the rest is there as well)
console.log('Inventory has already beed initialized.');
notify();
});
};

$rootScope.$on('CurrentPersonaLoaded', (e, persona) => {
currentPersona = persona;
$rootScope.currentPersona = currentPersona;
initializeInventory(currentPersona.id);
});

$rootScope.$on('SwitchedPersona', (e, persona) => {
currentPersona = persona;
$rootScope.currentPersona = currentPersona;
initializeInventory(currentPersona.id);
});
}]);

Expand Down
2 changes: 1 addition & 1 deletion plugins/directives/plugins/sidebar/ts/sidebarDirective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module Sidebar {

$scope.getUrlFromId = function(id) {
if(!$scope.resource) {
$scope.resource = HawkularInventory.Resource.get({tenantId: globalTenantId, environmentId: globalEnvironmentId, resourceId: id}, function(data) {
$scope.resource = HawkularInventory.Resource.get({tenantId: $rootScope.currentPersona.id, environmentId: globalEnvironmentId, resourceId: id}, function(data) {
$scope.resourceName = data.properties.url;
});
}
Expand Down
2 changes: 0 additions & 2 deletions plugins/directives/plugins/sidebar/ts/sidebarGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ module Sidebar {

export var templatePath = "plugins/sidebar/html/sidebar.html";

export var globalTenantId = "test";

export var globalEnvironmentId = "test";
}
2 changes: 0 additions & 2 deletions plugins/directives/plugins/topbar/ts/topbarGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ module Topbar {

export var templatePath = "plugins/topbar/html/topbar.html";

export var globalTenantId = "test";

export var globalEnvironmentId = "test";

}
55 changes: 33 additions & 22 deletions plugins/directives/plugins/topbar/ts/topbarServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,47 @@ module Topbar {
// default time period set to 24 hours
var defaultOffset = 1 * 60 * 60 * 1000;

HawkularInventory.Resource.query({tenantId: globalTenantId, environmentId: globalEnvironmentId}, (resourceList) => {
$rootScope.hkResources = resourceList;
for (var i = 0; i < resourceList.length; i++) {
if(resourceList[i].id === $rootScope.hkParams.resourceId) {
$rootScope.selectedResource = resourceList[i];
var init = (tenantId: string) => {
HawkularInventory.Resource.query({tenantId: tenantId, environmentId: globalEnvironmentId}, (resourceList) => {
$rootScope.hkResources = resourceList;
for (var i = 0; i < resourceList.length; i++) {
if(resourceList[i].id === $rootScope.hkParams.resourceId) {
$rootScope.selectedResource = resourceList[i];
}
}
}
});

$rootScope.hkParams.timeOffset = $routeParams.timeOffset || defaultOffset;
$rootScope.hkEndTimestamp = $routeParams.endTimestamp || moment().valueOf();
$rootScope.hkStartTimestamp = moment().subtract($rootScope.hkParams.timeOffset, 'milliseconds').valueOf();

$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
$rootScope.hkParams = current.params;
});

$rootScope.hkParams.timeOffset = $routeParams.timeOffset || defaultOffset;
$rootScope.hkEndTimestamp = $routeParams.endTimestamp || moment().valueOf();
$rootScope.hkStartTimestamp = moment().subtract($rootScope.hkParams.timeOffset, 'milliseconds').valueOf();

HawkularInventory.Resource.query({tenantId: globalTenantId, environmentId: globalEnvironmentId}, (resourceList) => {
$rootScope.hkResources = resourceList;
for (var i = 0; i < resourceList.length; i++) {
if(resourceList[i].id === $rootScope.hkParams.resourceId) {
$rootScope.selectedResource = resourceList[i];
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
$rootScope.hkParams = current.params;

$rootScope.hkParams.timeOffset = $routeParams.timeOffset || defaultOffset;
$rootScope.hkEndTimestamp = $routeParams.endTimestamp || moment().valueOf();
$rootScope.hkStartTimestamp = moment().subtract($rootScope.hkParams.timeOffset, 'milliseconds').valueOf();

HawkularInventory.Resource.query({tenantId: tenantId, environmentId: globalEnvironmentId}, (resourceList) => {
$rootScope.hkResources = resourceList;
for (var i = 0; i < resourceList.length; i++) {
if(resourceList[i].id === $rootScope.hkParams.resourceId) {
$rootScope.selectedResource = resourceList[i];
}
}
}
});
});

}, this);
}, this);
};
var tenantId = this.$rootScope.currentPersona && this.$rootScope.currentPersona.id;
if (tenantId) {
init(tenantId);
} else {
// currentPersona hasn't been injected to the rootScope yet, wait for it..
$rootScope.$on('UserInitialized', (tenantId) => {
init(tenantId);
});
}
}

public setTimestamp(offset, end) {
Expand Down
44 changes: 27 additions & 17 deletions plugins/metrics/plugins/metrics/ts/addUrlPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module HawkularMetrics {

export class AddUrlController {
/// this is for minification purposes
public static $inject = ['$location', '$scope', '$rootScope', '$interval', '$log', '$filter', '$modal', 'HawkularInventory', 'HawkularMetric', 'HawkularAlert', 'HawkularAlertsManager','HawkularErrorManager','$q', 'md5'];
public static $inject = ['$location', '$scope', '$rootScope', '$interval', '$log', '$filter', '$modal', 'HawkularInventory', 'HawkularMetric', 'HawkularAlert', 'HawkularAlertsManager','HawkularErrorManager', '$q', 'md5'];

private httpUriPart = 'http://';
public addProgress: boolean = false;
Expand All @@ -33,7 +33,7 @@ module HawkularMetrics {

constructor(private $location:ng.ILocationService,
private $scope:any,
private $rootScope:ng.IRootScopeService,
private $rootScope:any,
private $interval:ng.IIntervalService,
private $log:ng.ILogService,
private $filter:ng.IFilterService,
Expand All @@ -48,10 +48,18 @@ module HawkularMetrics {
public resourceUrl:string) {
$scope.vm = this;
this.resourceUrl = this.httpUriPart;
this.getResourceList();

if (this.$rootScope.currentPersona) {
this.getResourceList(this.$rootScope.currentPersona.id);
} else {
// currentPersona hasn't been injected to the rootScope yet, wait for it..
$rootScope.$on('UserInitialized', (tenantId) => {
this.getResourceList(tenantId);
});
}

this.autoRefresh(20);
}

private autoRefreshPromise:ng.IPromise<number>;

cancelAutoRefresh():void {
Expand Down Expand Up @@ -84,13 +92,14 @@ module HawkularMetrics {
this.$log.info('Adding new Resource Url to Hawkular-inventory: ' + url);

var metricId: string;
var defaultEmail = this.$rootScope['user_email'] ? this.$rootScope['user_email'] : 'myemail@company.com';
var defaultEmail = this.$rootScope.userDetails.email || 'myemail@company.com';
var err = (error: any, msg: string): void => this.HawkularErrorManager.errorHandler(error, msg);
var currentTenantId = this.$rootScope.currentPersona.id;

/// Add the Resource and its metrics
this.HawkularInventory.Resource.save({tenantId: globalTenantId, environmentId: globalEnvironmentId}, resource).$promise
this.HawkularInventory.Resource.save({tenantId: currentTenantId, environmentId: globalEnvironmentId}, resource).$promise
.then((newResource) => {
this.getResourceList();
this.getResourceList(currentTenantId);
metricId = resourceId;
console.dir(newResource);
this.$log.info('New Resource ID: ' + metricId + ' created.');
Expand All @@ -113,13 +122,13 @@ module HawkularMetrics {
var errMetric = (error: any) => err(error, 'Error saving metric.');
var createMetric = (metric: any) =>
this.HawkularInventory.Metric.save({
tenantId: globalTenantId,
tenantId: currentTenantId,
environmentId: globalEnvironmentId
}, metric).$promise;

var associateResourceWithMetrics = () =>
this.HawkularInventory.ResourceMetric.save({
tenantId: globalTenantId,
tenantId: currentTenantId,
environmentId: globalEnvironmentId,
resourceId: resourceId
}, metricsIds).$promise;
Expand Down Expand Up @@ -155,8 +164,9 @@ module HawkularMetrics {
});
}

getResourceList():any {
this.HawkularInventory.Resource.query({tenantId: globalTenantId, environmentId: globalEnvironmentId, per_page: this.resPerPage, page: this.resCurPage}, (aResourceList, getResponseHeaders) => {
getResourceList(currentTenantId?: string):any {
var tenantId:string = currentTenantId || this.$rootScope.currentPersona.id;
this.HawkularInventory.Resource.query({tenantId: tenantId, environmentId: globalEnvironmentId, per_page: this.resPerPage, page: this.resCurPage}, (aResourceList, getResponseHeaders) => {
// FIXME: hack.. make expanded out of list
var pages = getResponseHeaders().link ? getResponseHeaders().link.split(', ') : [];
for (var p = 0; p < pages.length; p++) {
Expand All @@ -172,19 +182,19 @@ module HawkularMetrics {
var promises = [];
angular.forEach(aResourceList, function(res, idx) {
promises.push(this.HawkularMetric.NumericMetricData.queryMetrics({
tenantId: globalTenantId, resourceId: res.id, numericId: (res.id + '.status.duration'),
tenantId: tenantId, resourceId: res.id, numericId: (res.id + '.status.duration'),
start: moment().subtract(24, 'hours').valueOf(), end: moment().valueOf()}, (resource) => {
// FIXME: Work data so it works for chart ?
res['responseTime'] = resource;
}).$promise);
promises.push(this.HawkularMetric.NumericMetricData.queryMetrics({
tenantId: globalTenantId, resourceId: res.id, numericId: (res.id + '.status.code'),
tenantId: tenantId, resourceId: res.id, numericId: (res.id + '.status.code'),
start: moment().subtract(24, 'hours').valueOf(), end: moment().valueOf()}, (resource) => {
// FIXME: Use availability instead..
res['isUp'] = (resource[0] && resource[0].value >= 200 && resource[0].value < 300);
}).$promise);
promises.push(this.HawkularMetric.AvailabilityMetricData.query({
tenantId: globalTenantId,
tenantId: tenantId,
availabilityId: res.id,
start: moment().subtract(24, 'hours').valueOf(),
end: moment().valueOf(),
Expand Down Expand Up @@ -231,15 +241,15 @@ module HawkularMetrics {

class DeleteResourceModalController {

static $inject = ['$scope', '$modalInstance', 'HawkularInventory', 'resource'];
static $inject = ['$scope', '$rootScope', '$modalInstance', 'HawkularInventory', 'resource'];

constructor(private $scope, private $modalInstance: any, private HawkularInventory, public resource) {
constructor(private $scope, private $rootScope, private $modalInstance: any, private HawkularInventory, public resource) {
$scope.vm = this;
}

deleteResource() {
this.HawkularInventory.Resource.delete({
tenantId: globalTenantId,
tenantId: this.$rootScope.currentPersona.id,
environmentId: globalEnvironmentId,
resourceId: this.resource.id
}).$promise.then((res) => {
Expand Down
7 changes: 4 additions & 3 deletions plugins/metrics/plugins/metrics/ts/metricsAvailabilityPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ module HawkularMetrics {

export class MetricsAvailabilityController {
/// for minification only
public static $inject = ['$scope', '$interval', '$log', 'HawkularMetric', 'HawkularAlert', '$routeParams'];
public static $inject = ['$scope', '$rootScope', '$interval', '$log', 'HawkularMetric', 'HawkularAlert', '$routeParams'];

public math;

constructor(private $scope:any,
private $rootScope:any,
private $interval:ng.IIntervalService,
private $log:ng.ILogService,
private HawkularMetric:any,
Expand Down Expand Up @@ -125,7 +126,7 @@ module HawkularMetrics {

if (metricId) {
this.HawkularMetric.AvailabilityMetricData.query({
tenantId: globalTenantId,
tenantId: this.$rootScope.currentPersona.id,
availabilityId: metricId,
start: startTime,
end: endTime,
Expand Down Expand Up @@ -162,7 +163,7 @@ module HawkularMetrics {

if (metricId) {
this.HawkularMetric.AvailabilityMetricData.query({
tenantId: globalTenantId,
tenantId: this.$rootScope.currentPersona.id,
availabilityId: metricId,
start: startTime,
end: endTime,
Expand Down
3 changes: 0 additions & 3 deletions plugins/metrics/plugins/metrics/ts/metricsGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ module HawkularMetrics {

/// These are plugin globals used across several screens (think session vars from server side programming)

/// @todo: this will go away once we have KeyCloak integration
export var globalTenantId = "test";

export var globalEnvironmentId = "test";

}
4 changes: 2 additions & 2 deletions plugins/metrics/plugins/metrics/ts/metricsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ module HawkularMetrics {
when('/hawkular/:resourceId/:timeOffset?/:endTime?', {templateUrl: 'plugins/metrics/html/single-page.html'}).
when('/metrics/response-time', {templateUrl: 'plugins/metrics/html/response-time.html',
resolve: {
hkResourceList : function($filter, $location, $q, HawkularInventory) {
var resPromise = HawkularInventory.Resource.query({tenantId: globalTenantId, environmentId: globalEnvironmentId}).$promise;
hkResourceList : function($filter, $location, $rootScope, $q, HawkularInventory) {
var resPromise = HawkularInventory.Resource.query({tenantId: $rootScope.currentPersona.id, environmentId: globalEnvironmentId}).$promise;
resPromise.then(function(hkResourceList){
$location.path('/metrics/response-time/' + hkResourceList[0].id);
}, function(){
Expand Down
6 changes: 3 additions & 3 deletions plugins/metrics/plugins/metrics/ts/metricsResponsePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module HawkularMetrics {
public math;

constructor(private $scope:any,
private $rootScope:ng.IRootScopeService,
private $rootScope:any,
private $interval:ng.IIntervalService,
private $log:ng.ILogService,
private HawkularMetric:any,
Expand Down Expand Up @@ -185,7 +185,7 @@ module HawkularMetrics {

if (metricId) {
this.HawkularMetric.NumericMetricData.queryMetrics({
tenantId: globalTenantId,
tenantId: this.$rootScope.currentPersona.id,
numericId: metricId,
start: startTime,
end: endTime,
Expand Down Expand Up @@ -221,7 +221,7 @@ module HawkularMetrics {

if (metricId) {
this.HawkularMetric.NumericMetricData.queryMetrics({
tenantId: globalTenantId,
tenantId: this.$rootScope.currentPersona.id,
numericId: metricId,
start: startTime,
end: endTime,
Expand Down

0 comments on commit 758c0c6

Please sign in to comment.