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\DockerPortMapping; |
15
|
|
|
use Chapi\Entity\Marathon\AppEntity\HealthCheck; |
16
|
|
|
use Chapi\Entity\Marathon\AppEntity\IpAddress; |
17
|
|
|
use Chapi\Entity\Marathon\AppEntity\PortDefinition; |
18
|
|
|
use Chapi\Entity\Marathon\AppEntity\UpgradeStrategy; |
19
|
|
|
use Symfony\Component\Config\Definition\Exception\Exception; |
20
|
|
|
|
21
|
|
|
class MarathonAppEntity implements JobEntityInterface |
22
|
|
|
{ |
23
|
|
|
public $id = ''; |
24
|
|
|
|
25
|
|
|
public $cmd = ''; |
26
|
|
|
|
27
|
|
|
public $cpus = 0; |
28
|
|
|
|
29
|
|
|
public $mem = 0; |
30
|
|
|
|
31
|
|
|
public $args = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var PortDefinition[] |
35
|
|
|
*/ |
36
|
|
|
public $portDefinitions =[]; |
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
|
|
|
public $env = null; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
public $constraints = []; |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public $acceptedResourceRoles = []; |
58
|
|
|
|
59
|
|
|
public $labels = null; |
60
|
|
|
|
61
|
|
|
public $uris = []; |
62
|
|
|
|
63
|
|
|
public $dependencies = []; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var HealthCheck[] |
67
|
|
|
*/ |
68
|
|
|
public $healthChecks = []; |
69
|
|
|
|
70
|
|
|
public $backoffSeconds = 1; |
71
|
|
|
|
72
|
|
|
public $backoffFactor = 1.15; |
73
|
|
|
|
74
|
|
|
public $maxLaunchDelaySeconds = 3600; |
75
|
|
|
|
76
|
|
|
public $taskKillGracePeriodSeconds = 0; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var UpgradeStrategy |
80
|
|
|
*/ |
81
|
|
|
public $upgradeStrategy = null; |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var IpAddress |
86
|
|
|
*/ |
87
|
|
|
public $ipAddress = null; |
88
|
|
|
|
89
|
45 |
|
public function __construct($mData = null) |
90
|
|
|
{ |
91
|
45 |
|
if (!$mData) |
92
|
45 |
|
{ |
93
|
|
|
// initialized with default values |
94
|
33 |
|
return; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// make sure data is array |
98
|
18 |
|
$aData = (array) $mData; |
99
|
|
|
|
100
|
18 |
|
MarathonEntityUtils::setAllPossibleProperties($aData, $this); |
101
|
|
|
|
102
|
18 |
|
if (isset($aData['portDefinitions'])) |
103
|
18 |
|
{ |
104
|
4 |
|
foreach ($aData['portDefinitions'] as $portDefinition) |
105
|
|
|
{ |
106
|
|
|
$this->portDefinitions[] = new PortDefinition((array)$portDefinition); |
107
|
4 |
|
} |
108
|
4 |
|
} |
109
|
|
|
|
110
|
18 |
|
if (isset($aData['container'])) |
111
|
18 |
|
{ |
112
|
|
|
$this->container = new Container((array)$aData['container']); |
113
|
|
|
} |
114
|
|
|
|
115
|
18 |
|
if (isset($aData['healthChecks'])) |
116
|
18 |
|
{ |
117
|
4 |
|
foreach($aData['healthChecks'] as $healthCheck) |
118
|
|
|
{ |
119
|
|
|
$this->healthChecks[] = new HealthCheck((array)$healthCheck); |
120
|
4 |
|
} |
121
|
4 |
|
} |
122
|
|
|
|
123
|
18 |
|
if (isset($aData['upgradeStrategy'])) |
124
|
18 |
|
{ |
125
|
1 |
|
$this->upgradeStrategy = new UpgradeStrategy((array)$aData['upgradeStrategy']); |
126
|
1 |
|
} else { |
127
|
18 |
|
$this->upgradeStrategy = new UpgradeStrategy(); |
128
|
|
|
} |
129
|
|
|
|
130
|
18 |
|
if (isset($aData['ipAddress'])) |
131
|
18 |
|
{ |
132
|
|
|
$this->ipAddress = new IpAddress((array)$aData['ipAddress']); |
133
|
|
|
} |
134
|
|
|
|
135
|
18 |
View Code Duplication |
if (isset($aData['env'])) |
|
|
|
|
136
|
18 |
|
{ |
137
|
1 |
|
$this->env = (object) $aData['env']; |
138
|
1 |
|
} else { |
139
|
18 |
|
$this->env = (object)[]; |
140
|
|
|
} |
141
|
|
|
|
142
|
18 |
|
if (isset($aData['labels'])) |
143
|
18 |
|
{ |
144
|
5 |
|
$this->labels = (object) $aData['labels']; |
145
|
5 |
|
} |
146
|
18 |
|
MarathonEntityUtils::setPropertyIfExist($aData, $this, 'constraints'); |
147
|
18 |
|
MarathonEntityUtils::setPropertyIfExist($aData, $this, 'args'); |
148
|
18 |
|
MarathonEntityUtils::setPropertyIfExist($aData, $this, 'uris'); |
149
|
18 |
|
MarathonEntityUtils::setPropertyIfExist($aData, $this, 'acceptedResourceRoles'); |
150
|
18 |
|
MarathonEntityUtils::setPropertyIfExist($aData, $this, 'dependencies'); |
151
|
18 |
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @inheritdoc |
155
|
|
|
* @return array |
156
|
|
|
*/ |
157
|
4 |
|
public function jsonSerialize() |
158
|
|
|
{ |
159
|
4 |
|
$_aRet = (array) $this; |
160
|
4 |
|
return $_aRet; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @inheritdoc |
165
|
|
|
* @return \ArrayIterator |
166
|
|
|
*/ |
167
|
2 |
|
public function getIterator() |
168
|
|
|
{ |
169
|
2 |
|
return new \ArrayIterator($this); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @inheritdoc |
174
|
|
|
* @return array |
175
|
|
|
*/ |
176
|
2 |
View Code Duplication |
public function getSimpleArrayCopy() |
|
|
|
|
177
|
|
|
{ |
178
|
2 |
|
$_aReturn = []; |
179
|
|
|
|
180
|
2 |
|
foreach ($this as $_sProperty => $mValue) |
181
|
|
|
{ |
182
|
2 |
|
$_aReturn[$_sProperty] = (is_array($mValue) || is_object($mValue)) ? json_encode($mValue) : $mValue; |
183
|
2 |
|
} |
184
|
|
|
|
185
|
2 |
|
return $_aReturn; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @inheritdoc |
190
|
|
|
* @return bool |
191
|
|
|
*/ |
192
|
|
|
public function isSchedulingJob() |
193
|
|
|
{ |
194
|
|
|
return false; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @inheritdoc |
199
|
|
|
* @return bool |
200
|
|
|
*/ |
201
|
5 |
|
public function isDependencyJob() |
202
|
|
|
{ |
203
|
5 |
|
return count($this->dependencies) ? true : false; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
5 |
|
public function getEntityType() |
210
|
|
|
{ |
211
|
5 |
|
return JobEntityInterface::MARATHON_TYPE; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return string |
216
|
|
|
*/ |
217
|
23 |
|
public function getKey() |
218
|
|
|
{ |
219
|
23 |
|
return $this->id; |
220
|
|
|
} |
221
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.