Skip to content

Commit

Permalink
HWKINVENT-38 Initialize inventory with new persona.id if the user get…
Browse files Browse the repository at this point in the history
…s logged in or switched from different persona.
  • Loading branch information
jkremser committed May 14, 2015
1 parent 15acbe4 commit 05fb051
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 39 deletions.
46 changes: 41 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.

4 changes: 2 additions & 2 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.

33 changes: 18 additions & 15 deletions dist/hawkular-ui-components-metrics.js

Large diffs are not rendered by default.

53 changes: 52 additions & 1 deletion plugins/accounts/plugins/accounts/ts/accountsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/// <reference path="accountsGlobals.ts"/>
module HawkularAccounts {
export var _module = angular.module(HawkularAccounts.pluginName, ['ui.bootstrap']);
export var userDetails:any = undefined;
var accountsTab:any = undefined;
var currentPersona:any = undefined;

Expand All @@ -35,9 +36,10 @@ 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;
HawkularAccounts.userDetails = userDetails;

$rootScope.$on('IdleStart', () => {
$('#idle').slideDown();
Expand All @@ -56,12 +58,61 @@ 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 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'))
.catch((e) => err(e, 'Error initializing the inventory.'));
};

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

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

Expand Down
27 changes: 15 additions & 12 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', 'HawkularAccounts', '$q', 'md5'];

private httpUriPart = 'http://';
public addProgress: boolean = false;
Expand All @@ -43,6 +43,7 @@ module HawkularMetrics {
private HawkularAlert:any,
private HawkularAlertsManager: HawkularMetrics.IHawkularAlertsManager,
private HawkularErrorManager: HawkularMetrics.IHawkularErrorManager,
private HawkularAccounts: any,
private $q: ng.IQService,
private md5: any,
public resourceUrl:string) {
Expand All @@ -52,6 +53,8 @@ module HawkularMetrics {
this.autoRefresh(20);
}

private currentTenantId = this.HawkularAccounts.currentPersona.id;

private autoRefreshPromise:ng.IPromise<number>;

cancelAutoRefresh():void {
Expand Down Expand Up @@ -84,11 +87,11 @@ 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.HawkularAccounts.userDetails.email || 'myemail@company.com';
var err = (error: any, msg: string): void => this.HawkularErrorManager.errorHandler(error, msg);

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

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

getResourceList():any {
this.HawkularInventory.Resource.query({tenantId: globalTenantId, environmentId: globalEnvironmentId, per_page: this.resPerPage, page: this.resCurPage}, (aResourceList, getResponseHeaders) => {
this.HawkularInventory.Resource.query({tenantId: this.currentTenantId, 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 +175,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: this.currentTenantId, 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: this.currentTenantId, 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: this.currentTenantId,
availabilityId: res.id,
start: moment().subtract(24, 'hours').valueOf(),
end: moment().valueOf(),
Expand Down Expand Up @@ -231,15 +234,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

0 comments on commit 05fb051

Please sign in to comment.