Skip to content

Commit

Permalink
Change addUrl (Resource, metrics) functionality to send data to Inven…
Browse files Browse the repository at this point in the history
…tory module not metrics.
  • Loading branch information
mtho11 committed Feb 20, 2015
1 parent 9d48b8f commit 02474ce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 71 deletions.
35 changes: 8 additions & 27 deletions dist/hawkular-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,25 @@ var HawkularMetrics;
var HawkularMetrics;
(function (HawkularMetrics) {
var AddUrlController = (function () {
function AddUrlController($location, $scope, $log, HawkularMetric, resourceUrl) {
function AddUrlController($location, $scope, $log, HawkularInventory, resourceUrl) {
this.$location = $location;
this.$scope = $scope;
this.$log = $log;
this.HawkularMetric = HawkularMetric;
this.HawkularInventory = HawkularInventory;
this.resourceUrl = resourceUrl;
this.tenantId = 'test';
$scope.vm = this;
this.resourceUrl = '';
}
AddUrlController.prototype.addUrl = function (url) {
this.$log.debug("Adding Url to backend: " + url);
this.registerFixedMetrics(this.tenantId);
AddUrlController.prototype.addUrl = function (resourceId) {
this.$log.debug("Adding Url to backend: " + resourceId);
this.HawkularInventory.Resource.save({ tenantId: this.tenantId }, resourceId);
this.HawkularInventory.Metric.save({ tenantId: this.tenantId, resourceId: resourceId }, 'status.time');
this.HawkularInventory.Metric.save({ tenantId: this.tenantId, resourceId: resourceId }, 'status.code');
this.$log.debug("Current url: " + this.$location.url());
this.$location.url("/metrics/metricsView");
};
AddUrlController.prototype.registerFixedMetrics = function (tenantId) {
var result;
var webResponseTimeMetric = {
"name": "web.responseTime",
"tags": {
"attribute1": "web",
"attribute2": "value2"
}
};
var cpuUsageMetric = {
"name": "cpu.usage",
"tags": {
"attribute1": "cpu",
"attribute2": "value2"
}
};
result = this.HawkularMetric.NumericMetric.save({ tenantId: tenantId }, webResponseTimeMetric);
this.$log.info("Created Metric: " + result);
result = this.HawkularMetric.NumericMetric.save({ tenantId: tenantId }, cpuUsageMetric);
this.$log.info("Created Metric: " + result);
};
AddUrlController.$inject = ['$location', '$scope', '$log', 'HawkularMetric'];
AddUrlController.$inject = ['$location', '$scope', '$log', 'HawkularInventory'];
return AddUrlController;
})();
HawkularMetrics.AddUrlController = AddUrlController;
Expand Down
9 changes: 4 additions & 5 deletions plugins/metrics/d.ts/metrics/ts/addUrlPage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ declare module HawkularMetrics {
private $location;
private $scope;
private $log;
private HawkularMetric;
private HawkularInventory;
resourceUrl: string;
static $inject: string[];
private tenantId;
constructor($location: ng.ILocationService, $scope: any, $log: ng.ILogService, HawkularMetric: any, resourceUrl: string);
addUrl(url: string): void;
registerFixedMetrics(tenantId: string): void;
tenantId: string;
constructor($location: ng.ILocationService, $scope: any, $log: ng.ILogService, HawkularInventory: any, resourceUrl: string);
addUrl(resourceId: string): void;
}
}
57 changes: 18 additions & 39 deletions plugins/metrics/plugins/metrics/ts/addUrlPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,43 @@
module HawkularMetrics {

export class AddUrlController {
public static $inject = ['$location', '$scope', '$log', 'HawkularMetric' ];
public static $inject = ['$location', '$scope', '$log', 'HawkularInventory' ];

///@todo: fixed tenant until we get it from KeyCloak
private tenantId = 'test';
tenantId = 'test';


constructor(private $location:ng.ILocationService,
private $scope:any,
private $log:ng.ILogService,
private HawkularMetric:any,
private HawkularInventory:any,
public resourceUrl:string) {
$scope.vm = this;
this.resourceUrl = '';

}

addUrl(url:string):void {
this.$log.debug("Adding Url to backend: " + url);
this.registerFixedMetrics(this.tenantId);
addUrl(resourceId:string):void {
this.$log.debug("Adding Url to backend: " + resourceId);
/// Add the Resource
this.HawkularInventory.Resource.save({tenantId: this.tenantId},resourceId);

this.$log.debug("Current url: " + this.$location.url());

/// Hop on over to the metricsView page for charting
this.$location.url("/metrics/metricsView");
/// Add our fixed metrics
/// @todo: this will become the 'Metrics Selection' screen once we get that
/// For right now we will just Register a couple of metrics automatically
/// Later, this will become the metrics selection screen and the user can
/// select metrics for the resource url
this.HawkularInventory.Metric.save({tenantId: this.tenantId, resourceId:resourceId }, 'status.time');
this.HawkularInventory.Metric.save({tenantId: this.tenantId, resourceId:resourceId }, 'status.code');

}

this.$log.debug("Current url: " + this.$location.url());

/// @todo: this will become the 'Metrics Selection' screen once we get that
/// For right now we will just Register a couple of metrics automatically
/// Later, this will become the metrics selection screen and the user can
/// select metrics for the resource url
registerFixedMetrics(tenantId:string):void {
/// for now just register the two metrics

var result:any;
var webResponseTimeMetric = {
"name": "web.responseTime",
"tags": {
"attribute1": "web",
"attribute2": "value2"
}
};
var cpuUsageMetric = {
"name": "cpu.usage",
"tags": {
"attribute1": "cpu",
"attribute2": "value2"
}
};

//@todo: ignoring error handling for now
result = this.HawkularMetric.NumericMetric.save({tenantId: tenantId}, webResponseTimeMetric);
this.$log.info("Created Metric: " + result);
result = this.HawkularMetric.NumericMetric.save({tenantId: tenantId}, cpuUsageMetric);
this.$log.info("Created Metric: " + result);
/// Hop on over to the metricsView page for charting
this.$location.url("/metrics/metricsView");

}

}

_module.controller('HawkularMetrics.AddUrlController', AddUrlController);
Expand Down

0 comments on commit 02474ce

Please sign in to comment.