Skip to content

Commit b97ca23

Browse files
Fixes to unit tests
1 parent a8811f9 commit b97ca23

File tree

21 files changed

+382
-145
lines changed

21 files changed

+382
-145
lines changed

lib/OpenCloud/CloudMonitoring/Resource/AbstractResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function updateJson($params = array())
4343
foreach (static::$requiredKeys as $requiredKey) {
4444
if (!$this->getProperty($requiredKey)) {
4545
throw new Exceptions\UpdateError(sprintf(
46-
"%s is required to update a %s", $requiredKey, get_class()
46+
"%s is required to update a %s", $requiredKey, get_class($this)
4747
));
4848
}
4949
}

lib/OpenCloud/CloudMonitoring/Resource/Agent.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,54 @@
1717
*/
1818
class Agent extends ReadOnlyResource
1919
{
20-
private $id;
21-
private $last_connected;
20+
/**
21+
* Agent IDs are user specified strings that are a maximum of 255 characters and can contain letters, numbers,
22+
* dashes and dots.
23+
*
24+
* @var string
25+
*/
26+
private $id;
27+
28+
/**
29+
* @var int UTC timestamp of last connection.
30+
*/
31+
private $last_connected;
2232

2333
protected static $json_name = false;
2434
protected static $json_collection_name = 'values';
2535
protected static $url_resource = 'agents';
2636

27-
public function getConnections()
37+
/**
38+
* @return mixed
39+
* @throws \OpenCloud\CloudMonitoring\Exception\AgentException
40+
*/
41+
public function getConnections()
2842
{
2943
if (!$this->getId()) {
3044
throw new Exception\AgentException(
3145
'Please specify an "ID" value'
3246
);
3347
}
34-
35-
$url = $this->url('connections');
36-
return $this->getService()->resourceList('AgentConnection', $url);
48+
49+
return $this->getService()->resourceList('AgentConnection', $this->getUrl('connections'));
3750
}
38-
39-
public function getConnection($connectionId)
51+
52+
/**
53+
* @param $connectionId
54+
* @return mixed
55+
* @throws \OpenCloud\CloudMonitoring\Exception\AgentException
56+
*/
57+
public function getConnection($connectionId)
4058
{
4159
if (!$this->getId()) {
4260
throw new Exception\AgentException(
4361
'Please specify an "ID" value'
4462
);
4563
}
4664

47-
$url = $this->url('connections/' . $connectionId);
65+
$url = clone $this->getUrl();
66+
$url->addPath('connections')->addPath($connectionId);
67+
4868
$response = $this->getClient()->get($url)->send()->getDecodedBody();
4969
return $this->getService()->resource('AgentConnection', $response);
5070
}

lib/OpenCloud/CloudMonitoring/Resource/AgentToken.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
*
55
* @copyright 2013 Rackspace Hosting, Inc. See LICENSE for information.
66
* @license https://www.apache.org/licenses/LICENSE-2.0
7-
* @author Glen Campbell <[email protected]>
87
* @author Jamie Hannaford <[email protected]>
98
*/
109

1110
namespace OpenCloud\CloudMonitoring\Resource;
1211

1312
/**
1413
* Agent class.
15-
*
16-
* @extends ReadOnlyResource
17-
* @implements ResourceInterface
1814
*/
1915
class AgentToken extends AbstractResource
2016
{

lib/OpenCloud/CloudMonitoring/Resource/Alarm.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,35 @@
1717
*/
1818
class Alarm extends AbstractResource
1919
{
20+
/**
21+
* @var string
22+
*/
2023
private $id;
21-
private $check_id;
22-
private $notification_plan_id;
23-
private $criteria;
24-
private $disabled;
25-
private $label;
26-
protected $metadata;
24+
25+
/**
26+
* @var string The ID of the check to alert on.
27+
*/
28+
private $check_id;
29+
30+
/**
31+
* @var string The id of the notification plan to execute when the state changes.
32+
*/
33+
private $notification_plan_id;
34+
35+
/**
36+
* @var string The alarm DSL for describing alerting conditions and their output states.
37+
*/
38+
private $criteria;
39+
40+
/**
41+
* @var bool Disable processing and alerts on this alarm.
42+
*/
43+
private $disabled;
44+
45+
/**
46+
* @var string A friendly label for an alarm.
47+
*/
48+
private $label;
2749

2850
protected static $json_name = false;
2951
protected static $json_collection_name = 'values';

lib/OpenCloud/CloudMonitoring/Resource/Check.php

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,69 @@
1717
*/
1818
class Check extends AbstractResource
1919
{
20+
/**
21+
* @var string
22+
*/
2023
private $id;
21-
private $type;
22-
private $details;
23-
private $disabled;
24-
private $label;
25-
protected $metadata;
26-
private $period;
27-
private $timeout;
28-
private $monitoring_zones_poll;
29-
private $target_alias;
30-
private $target_hostname;
31-
private $target_resolver;
24+
25+
/**
26+
* @var string|CheckType The type of check.
27+
*/
28+
private $type;
29+
30+
/**
31+
* @var array Details specific to the check type.
32+
*/
33+
private $details;
34+
35+
/**
36+
* @var bool Disables the check.
37+
*/
38+
private $disabled;
39+
40+
/**
41+
* @var string A friendly label for a check.
42+
*/
43+
private $label;
44+
45+
/**
46+
* @var int The period in seconds for a check. The value must be greater than the minimum period set on your account.
47+
*/
48+
private $period;
49+
50+
/**
51+
* @var int The timeout in seconds for a check. This has to be less than the period.
52+
*/
53+
private $timeout;
54+
55+
/**
56+
* For remote checks only. List of monitoring zones to poll from. Note: This argument is only required for remote
57+
* (non-agent) checks.
58+
*
59+
* @var array
60+
*/
61+
private $monitoring_zones_poll;
62+
63+
/**
64+
* For remote checks only. A key in the entity's 'ip_addresses' hash used to resolve this check to an IP address.
65+
* This parameter is mutually exclusive with target_hostname.
66+
*
67+
* @var string
68+
*/
69+
private $target_alias;
70+
71+
/**
72+
* For remote checks only. The hostname this check should target. This parameter is mutually exclusive with target_alias.
73+
*
74+
* @var string
75+
*/
76+
private $target_hostname;
77+
78+
/**
79+
* For remote checks only. Determines how to resolve the check target.
80+
* @var string
81+
*/
82+
private $target_resolver;
3283

3384
protected static $json_name = false;
3485
protected static $json_collection_name = 'values';
@@ -39,7 +90,6 @@ class Check extends AbstractResource
3990
'details',
4091
'disabled',
4192
'label',
42-
//'metadata',
4393
'period',
4494
'timeout',
4595
'monitoring_zones_poll',
@@ -48,13 +98,9 @@ class Check extends AbstractResource
4898
'target_resolver'
4999
);
50100

51-
protected static $requiredKeys = array(
52-
'type'
53-
);
101+
protected static $requiredKeys = array('type');
54102

55-
protected $associatedResources = array(
56-
'CheckType' => 'CheckType'
57-
);
103+
protected $associatedResources = array('CheckType' => 'CheckType');
58104

59105
protected $dataPointParams = array(
60106
'from',
@@ -83,6 +129,14 @@ public function getMetrics()
83129
return $this->getService()->resourceList('Metric', null, $this);
84130
}
85131

132+
/**
133+
* Fetch particular data points.
134+
*
135+
* @param string $metricName
136+
* @param array $options
137+
* @return mixed
138+
* @throws \OpenCloud\CloudMonitoring\Exception\MetricException
139+
*/
86140
public function fetchDataPoints($metricName, array $options = array())
87141
{
88142
$metric = $this->getService()->resource('Metric', null, $this);

lib/OpenCloud/CloudMonitoring/Resource/CheckType.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,28 @@
1515
*/
1616
class CheckType extends ReadOnlyResource
1717
{
18-
19-
private $id;
20-
private $type;
21-
private $fields;
22-
private $supported_platforms;
18+
/**
19+
* @var string
20+
*/
21+
private $id;
22+
23+
/**
24+
* @var string The name of the supported check type.
25+
*/
26+
private $type;
27+
28+
/**
29+
* @var array Check type fields.
30+
*/
31+
private $fields;
32+
33+
/**
34+
* Platforms on which an agent check type is supported. This is advisory information only - the check may still work
35+
* on other platforms, or report that check execution failed at runtime.
36+
*
37+
* @var array
38+
*/
39+
private $supported_platforms;
2340

2441
protected static $json_name = false;
2542
protected static $url_resource = 'check_types';

lib/OpenCloud/CloudMonitoring/Resource/Entity.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@
1515
*/
1616
class Entity extends AbstractResource
1717
{
18-
19-
private $id;
20-
private $label;
21-
private $agent_id;
22-
private $ip_addresses;
23-
protected $metadata;
18+
/**
19+
* @var string
20+
*/
21+
private $id;
22+
23+
/**
24+
* @var string Defines a name for the entity.
25+
*/
26+
private $label;
27+
28+
/**
29+
* @var string Agent to which this entity is bound to.
30+
*/
31+
private $agent_id;
32+
33+
/**
34+
* @var array Hash of IP addresses that can be referenced by checks on this entity.
35+
*/
36+
private $ip_addresses;
2437

2538
protected static $json_name = false;
2639
protected static $url_resource = 'entities';
@@ -47,6 +60,11 @@ public function getCheck($id = null)
4760
return $this->getService()->resource('Check', $id, $this);
4861
}
4962

63+
public function createCheck(array $params)
64+
{
65+
return $this->getCheck()->create($params);
66+
}
67+
5068
public function testNewCheckParams(array $params, $debug = false)
5169
{
5270
return $this->getCheck()->testParams($params, $debug);

lib/OpenCloud/CloudMonitoring/Resource/Metric.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
*/
1616
class Metric extends ReadOnlyResource
1717
{
18-
1918
protected static $json_name = 'metrics';
2019
protected static $json_collection_name = 'values';
2120
protected static $url_resource = 'metrics';
22-
2321
}

lib/OpenCloud/CloudMonitoring/Resource/Notification.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,24 @@
1515
*/
1616
class Notification extends AbstractResource
1717
{
18+
/**
19+
* @var string
20+
*/
1821
private $id;
22+
23+
/**
24+
* @var string Friendly name for the notification.
25+
*/
1926
private $label;
27+
28+
/**
29+
* @var string|NotificationType The notification type to send.
30+
*/
2031
private $type;
32+
33+
/**
34+
* @var array A hash of notification specific details based on the notification type.
35+
*/
2136
private $details;
2237

2338
protected static $json_name = false;
@@ -41,10 +56,10 @@ class Notification extends AbstractResource
4156

4257
public function testUrl($debug = false)
4358
{
44-
return $this->getService()->url('test-notification');
59+
return $this->getService()->getUrl('test-notification');
4560
}
4661

47-
public function testExisting($debug = false)
62+
public function test($debug = false)
4863
{
4964
return $this->getService()
5065
->getClient()

0 commit comments

Comments
 (0)