2
2
'angular' ,
3
3
'lodash' ,
4
4
'moment' ,
5
- './queryCtrl ' ,
5
+ './query_ctrl ' ,
6
6
'./directives' ,
7
7
] ,
8
8
function ( angular , _ ) {
@@ -278,37 +278,28 @@ function (angular, _) {
278
278
Period : query . period
279
279
} ;
280
280
281
- var d = $q . defer ( ) ;
282
- cloudwatch . getMetricStatistics ( params , function ( err , data ) {
283
- if ( err ) {
284
- return d . reject ( err ) ;
285
- }
286
- return d . resolve ( data ) ;
287
- } ) ;
288
-
289
- return d . promise ;
281
+ return cloudwatch . getMetricStatistics ( params ) ;
290
282
} ;
291
283
292
- CloudWatchDatasource . prototype . performSuggestRegion = function ( ) {
293
- return this . supportedRegion ;
284
+ CloudWatchDatasource . prototype . getRegions = function ( ) {
285
+ return $q . when ( this . supportedRegion ) ;
294
286
} ;
295
287
296
- CloudWatchDatasource . prototype . performSuggestNamespace = function ( ) {
297
- console . log ( this . supportMetrics ) ;
298
- return _ . keys ( this . supportedMetrics ) ;
288
+ CloudWatchDatasource . prototype . getNamespaces = function ( ) {
289
+ return $q . when ( _ . keys ( this . supportedMetrics ) ) ;
299
290
} ;
300
291
301
- CloudWatchDatasource . prototype . performSuggestMetrics = function ( namespace ) {
292
+ CloudWatchDatasource . prototype . getMetrics = function ( namespace ) {
302
293
namespace = templateSrv . replace ( namespace ) ;
303
- return this . supportedMetrics [ namespace ] || [ ] ;
294
+ return $q . when ( this . supportedMetrics [ namespace ] || [ ] ) ;
304
295
} ;
305
296
306
- CloudWatchDatasource . prototype . performSuggestDimensionKeys = function ( namespace ) {
297
+ CloudWatchDatasource . prototype . getDimensionKeys = function ( namespace ) {
307
298
namespace = templateSrv . replace ( namespace ) ;
308
- return this . supportedDimensions [ namespace ] || [ ] ;
299
+ return $q . when ( this . supportedDimensions [ namespace ] || [ ] ) ;
309
300
} ;
310
301
311
- CloudWatchDatasource . prototype . performSuggestDimensionValues = function ( region , namespace , metricName , dimensions ) {
302
+ CloudWatchDatasource . prototype . getDimensionValues = function ( region , namespace , metricName , dimensions ) {
312
303
region = templateSrv . replace ( region ) ;
313
304
namespace = templateSrv . replace ( namespace ) ;
314
305
metricName = templateSrv . replace ( metricName ) ;
@@ -323,26 +314,15 @@ function (angular, _) {
323
314
params . Dimensions = convertDimensionFormat ( dimensions ) ;
324
315
}
325
316
326
- var d = $q . defer ( ) ;
327
-
328
- cloudwatch . listMetrics ( params , function ( err , data ) {
329
- if ( err ) {
330
- return d . reject ( err ) ;
331
- }
332
-
333
- var suggestData = _ . chain ( data . Metrics )
334
- . map ( function ( metric ) {
317
+ return cloudwatch . listMetrics ( params ) . then ( function ( data ) {
318
+ var suggestData = _ . chain ( data . Metrics ) . map ( function ( metric ) {
335
319
return metric . Dimensions ;
336
- } )
337
- . reject ( function ( metric ) {
320
+ } ) . reject ( function ( metric ) {
338
321
return _ . isEmpty ( metric ) ;
339
- } )
340
- . value ( ) ;
322
+ } ) . value ( ) ;
341
323
342
- return d . resolve ( suggestData ) ;
324
+ return suggestData ;
343
325
} ) ;
344
-
345
- return d . promise ;
346
326
} ;
347
327
348
328
CloudWatchDatasource . prototype . performEC2DescribeInstances = function ( region , filters , instanceIds ) {
@@ -356,26 +336,7 @@ function (angular, _) {
356
336
params . InstanceIds = instanceIds ;
357
337
}
358
338
359
- var d = $q . defer ( ) ;
360
-
361
- ec2 . describeInstances ( params , function ( err , data ) {
362
- if ( err ) {
363
- return d . reject ( err ) ;
364
- }
365
-
366
- return d . resolve ( data ) ;
367
- } ) ;
368
-
369
- return d . promise ;
370
- } ;
371
-
372
- CloudWatchDatasource . prototype . getTemplateVariableNames = function ( ) {
373
- var variables = [ ] ;
374
- templateSrv . fillVariableValuesForUrl ( variables ) ;
375
-
376
- return _ . map ( _ . keys ( variables ) , function ( k ) {
377
- return k . replace ( / v a r - / , '$' ) ;
378
- } ) ;
339
+ return ec2 . describeInstances ( params ) ;
379
340
} ;
380
341
381
342
CloudWatchDatasource . prototype . metricFindQuery = function ( query ) {
@@ -389,32 +350,26 @@ function (angular, _) {
389
350
} ) ;
390
351
} ;
391
352
392
- var d = $q . defer ( ) ;
393
-
394
353
var regionQuery = query . match ( / ^ r e g i o n \( \) / ) ;
395
354
if ( regionQuery ) {
396
- d . resolve ( transformSuggestData ( this . performSuggestRegion ( ) ) ) ;
397
- return d . promise ;
355
+ return this . getRegions ( ) . then ( transformSuggestData ) ;
398
356
}
399
357
400
358
var namespaceQuery = query . match ( / ^ n a m e s p a c e \( \) / ) ;
401
359
if ( namespaceQuery ) {
402
- d . resolve ( transformSuggestData ( this . performSuggestNamespace ( ) ) ) ;
403
- return d . promise ;
360
+ return this . getNamespaces ( ) . then ( transformSuggestData ) ;
404
361
}
405
362
406
363
var metricNameQuery = query . match ( / ^ m e t r i c s \( ( [ ^ \) ] + ?) \) / ) ;
407
364
if ( metricNameQuery ) {
408
365
namespace = templateSrv . replace ( metricNameQuery [ 1 ] ) ;
409
- d . resolve ( transformSuggestData ( this . performSuggestMetrics ( namespace ) ) ) ;
410
- return d . promise ;
366
+ return this . getMetrics ( namespace ) . then ( transformSuggestData ) ;
411
367
}
412
368
413
369
var dimensionKeysQuery = query . match ( / ^ d i m e n s i o n _ k e y s \( ( [ ^ \) ] + ?) \) / ) ;
414
370
if ( dimensionKeysQuery ) {
415
371
namespace = templateSrv . replace ( dimensionKeysQuery [ 1 ] ) ;
416
- d . resolve ( transformSuggestData ( this . performSuggestDimensionKeys ( namespace ) ) ) ;
417
- return d . promise ;
372
+ return this . getDimensionKeys ( namespace ) . then ( transformSuggestData ) ;
418
373
}
419
374
420
375
var dimensionValuesQuery = query . match ( / ^ d i m e n s i o n _ v a l u e s \( ( [ ^ , ] + ?) , \s ? ( [ ^ , ] + ?) , \s ? ( [ ^ , ] + ?) ( , \s ? ( [ ^ ) ] * ) ) ? \) / ) ;
@@ -435,7 +390,7 @@ function (angular, _) {
435
390
} ) ;
436
391
}
437
392
438
- return this . performSuggestDimensionValues ( region , namespace , metricName , dimensions )
393
+ return this . getDimensionValues ( region , namespace , metricName , dimensions )
439
394
. then ( function ( suggestData ) {
440
395
return _ . map ( suggestData , function ( dimensions ) {
441
396
var result = _ . chain ( dimensions )
@@ -460,8 +415,7 @@ function (angular, _) {
460
415
instanceId
461
416
] ;
462
417
463
- return this . performEC2DescribeInstances ( region , [ ] , instanceIds )
464
- . then ( function ( result ) {
418
+ return this . performEC2DescribeInstances ( region , [ ] , instanceIds ) . then ( function ( result ) {
465
419
var volumeIds = _ . map ( result . Reservations [ 0 ] . Instances [ 0 ] . BlockDeviceMappings , function ( mapping ) {
466
420
return mapping . EBS . VolumeID ;
467
421
} ) ;
@@ -488,7 +442,7 @@ function (angular, _) {
488
442
CloudWatchDatasource . prototype . getAwsClient = function ( region , service ) {
489
443
var self = this ;
490
444
var generateRequestProxy = function ( service , action ) {
491
- return function ( params , callback ) {
445
+ return function ( params ) {
492
446
var data = {
493
447
region : region ,
494
448
service : service ,
@@ -502,11 +456,7 @@ function (angular, _) {
502
456
data : data
503
457
} ;
504
458
505
- $http ( options ) . then ( function ( response ) {
506
- callback ( null , response . data ) ;
507
- } , function ( err ) {
508
- callback ( err , [ ] ) ;
509
- } ) ;
459
+ return $http ( options ) ;
510
460
} ;
511
461
} ;
512
462
0 commit comments