1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package: chapi |
4
|
|
|
* |
5
|
|
|
* @author: bthapaliya |
6
|
|
|
* @since: 2016-10-16 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Chapi\Entity\Marathon; |
11
|
|
|
|
12
|
|
|
use Chapi\Entity\JobEntityInterface; |
13
|
|
|
use Chapi\Entity\Marathon\AppEntity\Container; |
14
|
|
|
use Chapi\Entity\Marathon\AppEntity\HealthCheck; |
15
|
|
|
use Chapi\Entity\Marathon\AppEntity\IpAddress; |
16
|
|
|
use Chapi\Entity\Marathon\AppEntity\PortDefinition; |
17
|
|
|
use Chapi\Entity\Marathon\AppEntity\UpgradeStrategy; |
18
|
|
|
|
19
|
|
|
class MarathonAppEntity implements JobEntityInterface |
20
|
|
|
{ |
21
|
|
|
public $id = ''; |
22
|
|
|
|
23
|
|
|
public $cmd = null; |
24
|
|
|
|
25
|
|
|
public $cpus = 0; |
26
|
|
|
|
27
|
|
|
public $mem = 0; |
28
|
|
|
|
29
|
|
|
public $args = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var PortDefinition[] |
33
|
|
|
*/ |
34
|
|
|
public $portDefinitions = null; |
35
|
|
|
|
36
|
|
|
public $requirePorts = false; |
37
|
|
|
|
38
|
|
|
public $instances = 0; |
39
|
|
|
|
40
|
|
|
public $executor = ''; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Container |
44
|
|
|
*/ |
45
|
|
|
public $container = null; |
46
|
|
|
|
47
|
|
|
public $env = null; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
public $constraints = []; |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public $acceptedResourceRoles = null; |
56
|
|
|
|
57
|
|
|
public $labels = null; |
58
|
|
|
|
59
|
|
|
public $uris = []; |
60
|
|
|
|
61
|
|
|
public $dependencies = []; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var HealthCheck[] |
65
|
|
|
*/ |
66
|
|
|
public $healthChecks = null; |
67
|
|
|
|
68
|
|
|
public $backoffSeconds = 1; |
69
|
|
|
|
70
|
|
|
public $backoffFactor = 1.15; |
71
|
|
|
|
72
|
|
|
public $maxLaunchDelaySeconds = 3600; |
73
|
|
|
|
74
|
|
|
public $taskKillGracePeriodSeconds = 0; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var UpgradeStrategy |
78
|
|
|
*/ |
79
|
|
|
public $upgradeStrategy = null; |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var IpAddress |
84
|
|
|
*/ |
85
|
|
|
public $ipAddress = null; |
86
|
|
|
|
87
|
50 |
|
public function __construct($data = null) |
88
|
|
|
{ |
89
|
50 |
|
if (!$data) { |
90
|
|
|
// initialized with default values |
91
|
36 |
|
return; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// make sure data is array |
95
|
20 |
|
$dataArray = (array) $data; |
96
|
|
|
|
97
|
20 |
|
MarathonEntityUtils::setAllPossibleProperties($dataArray, $this); |
98
|
|
|
|
99
|
20 |
|
if (isset($dataArray['portDefinitions'])) { |
100
|
|
|
foreach ($dataArray['portDefinitions'] as $portDefinition) { |
101
|
|
|
$this->portDefinitions[] = new PortDefinition((array) $portDefinition); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
20 |
|
if (isset($dataArray['container'])) { |
106
|
|
|
$this->container = new Container((array) $dataArray['container']); |
107
|
|
|
} |
108
|
|
|
|
109
|
20 |
|
if (isset($dataArray['healthChecks'])) { |
110
|
|
|
foreach ($dataArray['healthChecks'] as $healthCheck) { |
111
|
|
|
$this->healthChecks[] = new HealthCheck((array) $healthCheck); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
20 |
|
if (isset($dataArray['upgradeStrategy'])) { |
116
|
1 |
|
$this->upgradeStrategy = new UpgradeStrategy((array) $dataArray['upgradeStrategy']); |
117
|
|
|
} else { |
118
|
20 |
|
$this->upgradeStrategy = new UpgradeStrategy(); |
119
|
|
|
} |
120
|
|
|
|
121
|
20 |
|
if (isset($dataArray['ipAddress'])) { |
122
|
|
|
$this->ipAddress = new IpAddress((array) $dataArray['ipAddress']); |
123
|
|
|
} |
124
|
|
|
|
125
|
20 |
|
if (isset($dataArray['env'])) { |
126
|
3 |
|
$env = (array) $dataArray['env']; |
127
|
|
|
|
128
|
|
|
// sorting this makes the diff output a whole lot more readable |
129
|
3 |
|
ksort($env); |
130
|
|
|
|
131
|
3 |
|
$this->env = (object) $env; |
132
|
|
|
} else { |
133
|
18 |
|
$this->env = (object) []; |
134
|
|
|
} |
135
|
|
|
|
136
|
20 |
|
if (isset($dataArray['labels'])) { |
137
|
6 |
|
$this->labels = (object) $dataArray['labels']; |
138
|
|
|
} else { |
139
|
15 |
|
$this->labels = (object) []; |
140
|
|
|
} |
141
|
20 |
|
MarathonEntityUtils::setPropertyIfExist($dataArray, $this, 'constraints'); |
142
|
20 |
|
MarathonEntityUtils::setPropertyIfExist($dataArray, $this, 'args'); |
143
|
20 |
|
MarathonEntityUtils::setPropertyIfExist($dataArray, $this, 'uris'); |
144
|
20 |
|
MarathonEntityUtils::setPropertyIfExist($dataArray, $this, 'acceptedResourceRoles'); |
145
|
20 |
|
MarathonEntityUtils::setPropertyIfExist($dataArray, $this, 'dependencies'); |
146
|
20 |
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @inheritdoc |
150
|
|
|
* @return array |
151
|
|
|
*/ |
152
|
4 |
View Code Duplication |
public function jsonSerialize() |
153
|
|
|
{ |
154
|
4 |
|
$return = (array) $this; |
155
|
4 |
|
$return = array_filter( |
156
|
|
|
$return, |
157
|
4 |
|
function ($value, $key) { |
|
|
|
|
158
|
4 |
|
return !is_null($value) || empty($value); |
159
|
4 |
|
}, |
160
|
4 |
|
ARRAY_FILTER_USE_BOTH |
161
|
|
|
); |
162
|
4 |
|
return $return; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @inheritdoc |
167
|
|
|
* @return \ArrayIterator |
168
|
|
|
*/ |
169
|
4 |
|
public function getIterator() |
170
|
|
|
{ |
171
|
4 |
|
return new \ArrayIterator($this); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @inheritdoc |
176
|
|
|
* @return array |
177
|
|
|
*/ |
178
|
4 |
|
public function getSimpleArrayCopy() |
179
|
|
|
{ |
180
|
4 |
|
$_aReturn = []; |
181
|
|
|
|
182
|
4 |
|
foreach ($this as $_sProperty => $mValue) { |
183
|
4 |
|
$_aReturn[$_sProperty] = (is_array($mValue) || is_object($mValue)) ? json_encode($mValue) : $mValue; |
184
|
|
|
} |
185
|
|
|
|
186
|
4 |
|
return $_aReturn; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @inheritdoc |
191
|
|
|
* @return bool |
192
|
|
|
*/ |
193
|
|
|
public function isSchedulingJob() |
194
|
|
|
{ |
195
|
|
|
return false; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @inheritdoc |
200
|
|
|
* @return bool |
201
|
|
|
*/ |
202
|
5 |
|
public function isDependencyJob() |
203
|
|
|
{ |
204
|
5 |
|
return count($this->dependencies) ? true : false; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return string |
209
|
|
|
*/ |
210
|
5 |
|
public function getEntityType() |
211
|
|
|
{ |
212
|
5 |
|
return JobEntityInterface::MARATHON_TYPE; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return string |
217
|
|
|
*/ |
218
|
27 |
|
public function getKey() |
219
|
|
|
{ |
220
|
27 |
|
return $this->id; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.