1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Chapi\Component\RemoteClients; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Chapi\Component\Http\HttpClientInterface; |
7
|
|
|
use Chapi\Entity\Chronos\ChronosJobEntity; |
8
|
|
|
use Chapi\Entity\JobEntityInterface; |
9
|
|
|
use Chapi\Exception\HttpConnectionException; |
10
|
|
|
use Symfony\Component\Config\Definition\Exception\Exception; |
11
|
|
|
|
12
|
|
|
class MarathonApiClient implements ApiClientInterface |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** @var HttpClientInterface */ |
16
|
|
|
private $oHttpClient; |
17
|
|
|
|
18
|
9 |
|
public function __construct( |
19
|
|
|
HttpClientInterface $oHttpClient |
20
|
|
|
) |
21
|
|
|
{ |
22
|
9 |
|
$this->oHttpClient = $oHttpClient; |
23
|
9 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @link: https://mesos.github.io/chronos/docs/api.html#listing-jobs |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
1 |
|
public function listingJobs() |
30
|
|
|
{ |
31
|
1 |
|
$oResponse = $this->oHttpClient->get('/v2/apps'); |
32
|
1 |
|
if (200 == $oResponse->getStatusCode()) |
33
|
|
|
{ |
34
|
1 |
|
return $oResponse->json(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return []; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param JobEntityInterface $oJobEntity |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
1 |
|
public function addingJob(JobEntityInterface $oJobEntity) |
45
|
|
|
{ |
46
|
1 |
|
$_sTargetEndpoint = '/v2/apps'; |
47
|
|
|
|
48
|
1 |
|
$_oResponse = $this->oHttpClient->postJsonData($_sTargetEndpoint, $oJobEntity); |
49
|
1 |
|
return ($_oResponse->getStatusCode() == 201); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param JobEntityInterface|ChronosJobEntity $oJobEntity |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
1 |
|
public function updatingJob(JobEntityInterface $oJobEntity) |
57
|
|
|
{ |
58
|
1 |
|
$_sJobName = $oJobEntity->getKey(); |
|
|
|
|
59
|
1 |
|
$_sTargetEndpoint = '/v2/apps/' . $_sJobName; |
60
|
|
|
|
61
|
1 |
|
$_oResponse = $this->oHttpClient->putJsonData($_sTargetEndpoint, $oJobEntity); |
62
|
1 |
|
return ($_oResponse->getStatusCode() == 200); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $sJobName |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
1 |
|
public function removeJob($sJobName) |
70
|
|
|
{ |
71
|
1 |
|
$_sTargetEndpoint = '/v2/apps/' . $sJobName; |
72
|
|
|
|
73
|
1 |
|
$_oResponse = $this->oHttpClient->delete($_sTargetEndpoint); |
74
|
1 |
|
return ($_oResponse->getStatusCode() == 200); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $sJobName |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function getJobStats($sJobName) |
82
|
|
|
{ |
83
|
|
|
return []; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns true if the client can be connected to. |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
5 |
View Code Duplication |
public function ping() |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
try { |
93
|
5 |
|
$this->oHttpClient->get('/v2/info'); |
94
|
4 |
|
} catch (HttpConnectionException $e) |
95
|
|
|
{ |
96
|
|
|
if ( |
97
|
4 |
|
$e->getCode() == HttpConnectionException::ERROR_CODE_REQUEST_EXCEPTION || |
98
|
4 |
|
$e->getCode() == HttpConnectionException::ERROR_CODE_CONNECT_EXCEPTION |
99
|
|
|
) |
100
|
|
|
{ |
101
|
2 |
|
return false; |
102
|
|
|
} |
103
|
|
|
} |
104
|
3 |
|
return true; |
105
|
|
|
} |
106
|
|
|
} |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.