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

Commit

Permalink
HWKINVENT-45 Deleting the metrics from inventory before deleting the …
Browse files Browse the repository at this point in the history
…resource itself. If metrics stay in inventory and the URL is added again (after deletion) it'd fail.
  • Loading branch information
jkremser committed Jun 1, 2015
1 parent 94fde62 commit b36c36f
Showing 1 changed file with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,9 @@ module HawkularMetrics {
}, metricsIds).$promise;

/// For right now we will just Register a couple of metrics automatically
return createMetric(metrics[0])
.then(createMetric(metrics[1]), errMetric)
return this.$q.all([createMetric(metrics[0]), createMetric(metrics[1])])
.then(associateResourceWithMetrics, errMetric)
.catch('Error associating metrics with resource.');
// .catch(err('Error adding availability.'));
.catch((e) => err(e, 'Error associating metrics with resource.'));
})

// Find if a default email exists
Expand Down Expand Up @@ -248,18 +246,36 @@ module HawkularMetrics {

class DeleteResourceModalController {

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

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

deleteResource() {
this.HawkularInventory.Resource.delete({
tenantId: this.$rootScope.currentPersona.id,
environmentId: globalEnvironmentId,
resourceId: this.resource.id
}).$promise.then((res) => {
var metricsIds: string[] = [this.resource.id + '.status.duration', this.resource.id + '.status.code'];
var deleteMetric = (metricId: string) =>
this.HawkularInventory.Metric.delete({
tenantId: this.$rootScope.currentPersona.id,
environmentId: globalEnvironmentId,
metricId: metricId
}).$promise;

var removeResource = () =>
this.HawkularInventory.Resource.delete({
tenantId: this.$rootScope.currentPersona.id,
environmentId: globalEnvironmentId,
resourceId: this.resource.id
}).$promise;

this.$q.all([deleteMetric(metricsIds[0]), deleteMetric(metricsIds[1])])
.then(removeResource)
.then((res) => {
toastr.success('The site ' + this.resource.properties.url + ' is no longer being monitored.');
this.$modalInstance.close(res);
});
Expand Down

0 comments on commit b36c36f

Please sign in to comment.