Skip to content

Commit

Permalink
Merge pull request #6 from vrockai/HAWKULAR-13
Browse files Browse the repository at this point in the history
Create NgResource Services Layer for Hawkular REST API
  • Loading branch information
mtho11 committed Feb 10, 2015
2 parents 4b419d9 + 2acf707 commit 6db5643
Show file tree
Hide file tree
Showing 20 changed files with 222 additions and 114 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
/// <reference path="../bower_components/dt-angular/angular.d.ts" />
var hawkularRest;
(function (hawkularRest) {
hawkularRest._module = angular.module('hawkular.rest', ['ngResource']);
})(hawkularRest || (hawkularRest = {}));

/**
* @ngdoc provider
* @name hawkular.rest.HawkularInventory
* @description
* # HawkularInventory
* Provider in the hawkular.rest.
*/
var hawkularRest;
(function (hawkularRest) {
hawkularRest._module.provider('HawkularInventory', function () {
// time (in ms) the notifications are shown
this.host = 'localhost';
this.port = 8080;
this.setHost = function (host) {
this.host = host;
return this;
};
this.setPort = function (port) {
this.port = port;
return this;
};
this.$get = ['$resource', function ($resource) {
var prefix = 'http://' + this.host + ':' + this.port;
var factory = {};
factory['Resource'] = $resource(prefix + '/hawkular/inventory/:tenantId/resources/:resourceId', {
tenantId: '@tenantId',
resourceId: '@resourceId'
});
factory['Metric'] = $resource(prefix + '/hawkular/inventory/:tenantId/resources/:resourceId/metric/:metricId', {
tenantId: '@tenantId',
resourceId: '@resourceId',
metricId: '@metricId'
});
return factory;
}];
});
})(hawkularRest || (hawkularRest = {}));

/**
* @ngdoc provider
* @name hawkular.rest.HawkularRest
* @name hawkular.rest.HawkularMetric
* @description
* # HawkularRest
* Provider in the hawkular.rest.
*/
var hawkularRest;
(function (hawkularRest) {
hawkularRest.hawkMetric = angular.module('hawkular.rest', ['ngResource']);
hawkularRest.hawkMetric.provider('HawkularRest', function () {
hawkularRest._module.provider('HawkularMetric', function () {
// time (in ms) the notifications are shown
this.host = 'localhost';
this.port = 8080;
Expand All @@ -24,8 +66,8 @@ var hawkularRest;
this.$get = ['$resource', function ($resource) {
var prefix = 'http://' + this.host + ':' + this.port;
var factory = {};
factory['Tenant'] = $resource(prefix + '/rhq-metrics/tenants', {});
factory['Metric'] = $resource(prefix + '/rhq-metrics/:tenantId/metrics', {
factory['Tenant'] = $resource(prefix + '/hawkular-metrics/tenants', {});
factory['Metric'] = $resource(prefix + '/hawkular-metrics/:tenantId/metrics', {
tenantId: '@tenantId'
}, {
queryNum: {
Expand All @@ -44,31 +86,31 @@ var hawkularRest;
params: { type: 'log' }
}
});
factory['NumericMetric'] = $resource(prefix + '/rhq-metrics/:tenantId/metrics/numeric', {
factory['NumericMetric'] = $resource(prefix + '/hawkular-metrics/:tenantId/metrics/numeric', {
tenantId: '@tenantId'
});
factory['NumericMetricData'] = $resource(prefix + '/rhq-metrics/:tenantId/metrics/numeric/:numericId/data', {
factory['NumericMetricData'] = $resource(prefix + '/hawkular-metrics/:tenantId/metrics/numeric/:numericId/data', {
tenantId: '@tenantId',
numericId: '@numericId'
});
factory['NumericMetricMeta'] = $resource(prefix + '/rhq-metrics/:tenantId/metrics/numeric/:numericId/meta', {
factory['NumericMetricMeta'] = $resource(prefix + '/hawkular-metrics/:tenantId/metrics/numeric/:numericId/meta', {
tenantId: '@tenantId',
numericId: '@numericId'
}, {
update: 'PUT'
});
factory['NumericMetricMultiple'] = $resource(prefix + '/rhq-metrics/:tenantId/metrics/numeric/data', {
factory['NumericMetricMultiple'] = $resource(prefix + '/hawkular-metrics/:tenantId/metrics/numeric/data', {
tenantId: '@tenantId',
numericId: '@numericId'
});
factory['AvailabilityMetric'] = $resource(prefix + '/rhq-metrics/:tenantId/metrics/availability', {
factory['AvailabilityMetric'] = $resource(prefix + '/hawkular-metrics/:tenantId/metrics/availability', {
tenantId: '@tenantId'
});
factory['AvailabilityMetricData'] = $resource(prefix + '/rhq-metrics/:tenantId/metrics/availability/:availabilityId/data', {
factory['AvailabilityMetricData'] = $resource(prefix + '/hawkular-metrics/:tenantId/metrics/availability/:availabilityId/data', {
tenantId: '@tenantId',
availabilityId: '@availabilityId'
});
factory['AvailabilityMetricMultiple'] = $resource(prefix + '/rhq-metrics/:tenantId/metrics/availability/data', {
factory['AvailabilityMetricMultiple'] = $resource(prefix + '/hawkular-metrics/:tenantId/metrics/availability/data', {
tenantId: '@tenantId'
});
return factory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var $ = require('gulp-load-plugins')({
});

gulp.task('scripts', function () {
return gulp.src(paths.src + '/*.ts')
return gulp.src([paths.src + '/hawkRest.ts', paths.src + '/hawkRest-*.ts'])
.pipe($.typescript())
.on('error', function handleError(err) {
console.error(err.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function runTests (singleRun) {
});
}

function runTestsRest (singleRun) {
function runTestsRest (singleRun, service) {
var bowerDeps = wiredep({
directory: 'bower_components',
exclude: ['bootstrap-sass-official'],
Expand All @@ -42,7 +42,8 @@ function runTestsRest (singleRun) {
});

var testFiles = bowerDeps.js.concat([
paths.src + '/*.spec.rest.js',
paths.src + '/hawkRest.spec.rest.js',
paths.src + '/hawkRest-' + service + '*.spec.rest.js',
paths.dist + '/*.js'
]);

Expand All @@ -61,4 +62,5 @@ function runTestsRest (singleRun) {
gulp.task('test', ['scripts'], function (done) { runTests(true /* singleRun */, done) });
gulp.task('test:auto', ['scripts'], function (done) { runTests(false /* singleRun */, done) });

gulp.task('rest', ['scripts'], function (done) { runTestsRest(true /* singleRun */, done) });
gulp.task('rest:metric', ['scripts'], function (done) { runTestsRest(true, 'metric', done) });
gulp.task('rest:inventory', ['scripts'], function (done) { runTestsRest(true, 'inventory', done) });
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe('Provider: Hawkular live REST', function() {

var HawkularInventory;
var res;
var httpReal;
var $http;

beforeEach(module('hawkular.rest', 'httpReal'));

beforeEach(inject(function(_HawkularInventory_, _$resource_, _httpReal_, _$http_) {
HawkularInventory = _HawkularInventory_;
res = _$resource_;
httpReal = _httpReal_;
$http = _$http_;
}));

describe('Resources: ', function() {

describe('creating a resource', function() {
var result;
jasmine.DEFAULT_TIMEOUT_INTERVAL = TIMEOUT;

beforeEach(function(done) {
var resource = {
type: 'URL',
id: 'x1422733176502',
parameters: {
url: 'http://hawkular.org'
}
};

result = HawkularInventory.Resource.save(resource);
httpReal.submit();

result.$promise.then(function(){
}, function(error){
fail(errorFn(error));
}).finally(function(){
done();
});
});

it('should resolve', function() {
expect(result.$resolved).toEqual(true);
});
});
});
});
47 changes: 47 additions & 0 deletions services/hawkular-rest-service/src/hawkRest-inventory-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @ngdoc provider
* @name hawkular.rest.HawkularInventory
* @description
* # HawkularInventory
* Provider in the hawkular.rest.
*/

module hawkularRest {

_module.provider('HawkularInventory', function() {
// time (in ms) the notifications are shown

this.host = 'localhost';
this.port = 8080;

this.setHost = function(host){
this.host = host;
return this;
};

this.setPort = function(port){
this.port = port;
return this;
};

this.$get = ['$resource', function($resource) {

var prefix = 'http://' + this.host + ':' + this.port;
var factory = {};

factory['Resource'] = $resource(prefix + '/hawkular/inventory/:tenantId/resources/:resourceId', {
tenantId : '@tenantId',
resourceId : '@resourceId'
});

factory['Metric'] = $resource(prefix + '/hawkular/inventory/:tenantId/resources/:resourceId/metric/:metricId', {
tenantId : '@tenantId',
resourceId: '@resourceId',
metricId: '@metricId'
});

return factory;
}];

});
}
Loading

0 comments on commit 6db5643

Please sign in to comment.