1 | <?php |
||
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, $key) { |
|
|
|||
152 | 4 | return !is_null($value) || empty($value); |
|
153 | 4 | }, |
|
154 | 4 | ARRAY_FILTER_USE_BOTH // there is no ARRAY_FILTER_USE_VALUE |
|
155 | ); |
||
156 | |||
157 | 4 | if (isset($return["networks"]) |
|
158 | 4 | && count($return["networks"]) == 1 // you can only have one bridge or host network |
|
159 | 4 | && $return["networks"][0]->mode != "container") |
|
160 | { |
||
161 | $return["networks"][0] = (array) $return["networks"][0]; |
||
162 | unset($return["networks"][0]["name"]); // only "container" networks can have names |
||
163 | } |
||
164 | |||
165 | 4 | return $return; |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * @inheritdoc |
||
170 | * @return \ArrayIterator |
||
171 | */ |
||
172 | 5 | public function getIterator() |
|
176 | |||
177 | /** |
||
178 | * @inheritdoc |
||
179 | * @return array |
||
180 | */ |
||
181 | 5 | public function getSimpleArrayCopy() |
|
191 | |||
192 | /** |
||
193 | * @inheritdoc |
||
194 | * @return bool |
||
195 | */ |
||
196 | public function isSchedulingJob() |
||
200 | |||
201 | /** |
||
202 | * @inheritdoc |
||
203 | * @return bool |
||
204 | */ |
||
205 | 5 | public function isDependencyJob() |
|
209 | |||
210 | /** |
||
211 | * @return string |
||
212 | */ |
||
213 | 5 | public function getEntityType() |
|
217 | |||
218 | /** |
||
219 | * @return string |
||
220 | */ |
||
221 | 28 | public function getKey() |
|
225 | } |
||
226 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.