|
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\Fetch; |
|
15
|
|
|
use Chapi\Entity\Marathon\AppEntity\HealthCheck; |
|
16
|
|
|
use Chapi\Entity\Marathon\AppEntity\IpAddress; |
|
17
|
|
|
use Chapi\Entity\Marathon\AppEntity\Network; |
|
18
|
|
|
use Chapi\Entity\Marathon\AppEntity\PortDefinition; |
|
19
|
|
|
use Chapi\Entity\Marathon\AppEntity\UpgradeStrategy; |
|
20
|
|
|
|
|
21
|
|
|
class MarathonAppEntity implements JobEntityInterface |
|
22
|
|
|
{ |
|
23
|
|
|
public $id = ''; |
|
24
|
|
|
|
|
25
|
|
|
public $cmd = null; |
|
26
|
|
|
|
|
27
|
|
|
public $cpus = 0; |
|
28
|
|
|
|
|
29
|
|
|
public $mem = 0; |
|
30
|
|
|
|
|
31
|
|
|
public $args = null; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var PortDefinition[] |
|
35
|
|
|
*/ |
|
36
|
|
|
public $portDefinitions = null; |
|
37
|
|
|
|
|
38
|
|
|
public $requirePorts = false; |
|
39
|
|
|
|
|
40
|
|
|
public $instances = 0; |
|
41
|
|
|
|
|
42
|
|
|
public $executor = ''; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var Container |
|
46
|
|
|
*/ |
|
47
|
|
|
public $container = null; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var Network[] |
|
51
|
|
|
*/ |
|
52
|
|
|
public $networks = []; |
|
53
|
|
|
|
|
54
|
|
|
public $env = null; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var array |
|
58
|
|
|
*/ |
|
59
|
|
|
public $constraints = []; |
|
60
|
|
|
|
|
61
|
|
|
public $acceptedResourceRoles = null; |
|
62
|
|
|
|
|
63
|
|
|
public $labels = null; |
|
64
|
|
|
|
|
65
|
|
|
public $uris = []; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var Fetch[] |
|
69
|
|
|
*/ |
|
70
|
|
|
public $fetch = []; |
|
71
|
|
|
|
|
72
|
|
|
public $dependencies = []; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var HealthCheck[] |
|
76
|
|
|
*/ |
|
77
|
|
|
public $healthChecks = null; |
|
78
|
|
|
|
|
79
|
|
|
public $backoffSeconds = 1; |
|
80
|
|
|
|
|
81
|
|
|
public $backoffFactor = 1.15; |
|
82
|
|
|
|
|
83
|
|
|
public $maxLaunchDelaySeconds = 3600; |
|
84
|
|
|
|
|
85
|
|
|
public $taskKillGracePeriodSeconds = 0; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @var UpgradeStrategy |
|
89
|
|
|
*/ |
|
90
|
|
|
public $upgradeStrategy = null; |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @var IpAddress |
|
95
|
|
|
*/ |
|
96
|
|
|
public $ipAddress = null; |
|
97
|
|
|
|
|
98
|
52 |
|
public function __construct($data = null) |
|
99
|
|
|
{ |
|
100
|
52 |
|
if (!$data) { |
|
101
|
|
|
// initialized with default values |
|
102
|
37 |
|
return; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
// make sure data is array |
|
106
|
21 |
|
$dataArray = (array) $data; |
|
107
|
|
|
|
|
108
|
21 |
|
MarathonEntityUtils::setAllPossibleProperties( |
|
109
|
21 |
|
$dataArray, |
|
110
|
21 |
|
$this, |
|
111
|
|
|
array( |
|
112
|
21 |
|
'portDefinitions' => MarathonEntityUtils::convArrayOfClass(PortDefinition::class), |
|
113
|
21 |
|
'container' => MarathonEntityUtils::convClass(Container::class), |
|
114
|
21 |
|
'networks' => MarathonEntityUtils::convArrayOfClass(Network::class), |
|
115
|
21 |
|
'fetch' => MarathonEntityUtils::convArrayOfClass(Fetch::class), |
|
116
|
21 |
|
'healthChecks' => MarathonEntityUtils::convArrayOfClass(HealthCheck::class), |
|
117
|
21 |
|
'upgradeStrategy' => MarathonEntityUtils::convClass(UpgradeStrategy::class), |
|
118
|
21 |
|
'ipAddress' => MarathonEntityUtils::convClass(IpAddress::class), |
|
119
|
21 |
|
'env' => MarathonEntityUtils::convSortedObject(), |
|
120
|
21 |
|
'labels' => MarathonEntityUtils::convSortedObject(), |
|
121
|
|
|
|
|
122
|
|
|
# don't skip assigning these just because they are arrays or objects in $dataArray |
|
123
|
21 |
|
'constraints' => MarathonEntityUtils::noConv(), |
|
124
|
21 |
|
'args' => MarathonEntityUtils::noConv(), |
|
125
|
21 |
|
'uris' => MarathonEntityUtils::noConv(), |
|
126
|
21 |
|
'acceptedResourceRoles' => MarathonEntityUtils::noConv(), |
|
127
|
21 |
|
'dependencies' => MarathonEntityUtils::noConv() |
|
128
|
|
|
) |
|
129
|
|
|
); |
|
130
|
|
|
|
|
131
|
21 |
|
if (!isset($dataArray['upgradeStrategy'])) { |
|
132
|
21 |
|
$this->upgradeStrategy = new UpgradeStrategy(); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
21 |
|
if (!isset($dataArray['labels'])) { |
|
136
|
16 |
|
$this->upgradeStrategy = (object) []; |
|
137
|
|
|
} |
|
138
|
21 |
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @inheritdoc |
|
142
|
|
|
* @return array |
|
143
|
|
|
*/ |
|
144
|
4 |
|
public function jsonSerialize() |
|
145
|
|
|
{ |
|
146
|
4 |
|
$return = (array) $this; |
|
147
|
|
|
|
|
148
|
|
|
// delete empty fields |
|
149
|
4 |
|
$return = array_filter( |
|
150
|
4 |
|
$return, |
|
151
|
4 |
|
function($value) { |
|
152
|
4 |
|
return !is_null($value) || empty($value); |
|
153
|
4 |
|
} |
|
154
|
|
|
); |
|
155
|
|
|
|
|
156
|
4 |
|
if (isset($return['networks']) |
|
157
|
4 |
|
&& count($return['networks']) == 1 // you can only have one bridge or host network |
|
158
|
4 |
|
&& $return['networks'][0]->mode != 'container') |
|
159
|
|
|
{ |
|
160
|
|
|
$return['networks'][0] = (array) $return['networks'][0]; |
|
161
|
|
|
unset($return['networks'][0]['name']); // only "container" networks can have names |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
4 |
|
return $return; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @inheritdoc |
|
169
|
|
|
* @return \ArrayIterator |
|
170
|
|
|
*/ |
|
171
|
5 |
|
public function getIterator() |
|
172
|
|
|
{ |
|
173
|
5 |
|
return new \ArrayIterator($this); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @inheritdoc |
|
178
|
|
|
* @return array |
|
179
|
|
|
*/ |
|
180
|
5 |
|
public function getSimpleArrayCopy() |
|
181
|
|
|
{ |
|
182
|
5 |
|
$_aReturn = []; |
|
183
|
|
|
|
|
184
|
5 |
|
foreach ($this as $_sProperty => $mValue) { |
|
185
|
5 |
|
$_aReturn[$_sProperty] = (is_array($mValue) || is_object($mValue)) ? json_encode($mValue) : $mValue; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
5 |
|
return $_aReturn; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @inheritdoc |
|
193
|
|
|
* @return bool |
|
194
|
|
|
*/ |
|
195
|
|
|
public function isSchedulingJob() |
|
196
|
|
|
{ |
|
197
|
|
|
return false; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @inheritdoc |
|
202
|
|
|
* @return bool |
|
203
|
|
|
*/ |
|
204
|
5 |
|
public function isDependencyJob() |
|
205
|
|
|
{ |
|
206
|
5 |
|
return count($this->dependencies) ? true : false; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @return string |
|
211
|
|
|
*/ |
|
212
|
5 |
|
public function getEntityType() |
|
213
|
|
|
{ |
|
214
|
5 |
|
return JobEntityInterface::MARATHON_TYPE; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @return string |
|
219
|
|
|
*/ |
|
220
|
28 |
|
public function getKey() |
|
221
|
|
|
{ |
|
222
|
28 |
|
return $this->id; |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
|