From 02474ceb1d8748f792a6466e121f37971ed2790c Mon Sep 17 00:00:00 2001 From: Mike Thompson Date: Fri, 20 Feb 2015 10:04:02 -0800 Subject: [PATCH] Change addUrl (Resource, metrics) functionality to send data to Inventory module not metrics. --- dist/hawkular-metrics.js | 35 +++--------- .../metrics/d.ts/metrics/ts/addUrlPage.d.ts | 9 ++- .../metrics/plugins/metrics/ts/addUrlPage.ts | 57 ++++++------------- 3 files changed, 30 insertions(+), 71 deletions(-) diff --git a/dist/hawkular-metrics.js b/dist/hawkular-metrics.js index 1d1da30..4ec261f 100644 --- a/dist/hawkular-metrics.js +++ b/dist/hawkular-metrics.js @@ -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; diff --git a/plugins/metrics/d.ts/metrics/ts/addUrlPage.d.ts b/plugins/metrics/d.ts/metrics/ts/addUrlPage.d.ts index 927c9d8..15631a1 100644 --- a/plugins/metrics/d.ts/metrics/ts/addUrlPage.d.ts +++ b/plugins/metrics/d.ts/metrics/ts/addUrlPage.d.ts @@ -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; } } diff --git a/plugins/metrics/plugins/metrics/ts/addUrlPage.ts b/plugins/metrics/plugins/metrics/ts/addUrlPage.ts index fddcf74..218f167 100755 --- a/plugins/metrics/plugins/metrics/ts/addUrlPage.ts +++ b/plugins/metrics/plugins/metrics/ts/addUrlPage.ts @@ -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);