* php cs fixes, testing ci build
This commit is contained in:
parent
8d7f1b68c6
commit
951ca64943
@ -20,7 +20,12 @@ class CiConfig implements JsonSerializable
|
|||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="CiConfigItem", mappedBy="dailyConfig", cascade={"persist", "remove"}, orphanRemoval=true)
|
* @ORM\OneToMany(
|
||||||
|
* targetEntity="CiConfigItem",
|
||||||
|
* mappedBy="dailyConfig",
|
||||||
|
* cascade={"persist", "remove"},
|
||||||
|
* orphanRemoval=true
|
||||||
|
* )
|
||||||
* @var CiConfigItem[]
|
* @var CiConfigItem[]
|
||||||
*/
|
*/
|
||||||
private $configItems;
|
private $configItems;
|
||||||
@ -75,7 +80,7 @@ class CiConfig implements JsonSerializable
|
|||||||
*/
|
*/
|
||||||
public function addConfigItem(CiConfigItem $item): CiConfig
|
public function addConfigItem(CiConfigItem $item): CiConfig
|
||||||
{
|
{
|
||||||
if(!$this->configItems->contains($item)) {
|
if (!$this->configItems->contains($item)) {
|
||||||
$this->configItems->add($item);
|
$this->configItems->add($item);
|
||||||
$item->setDailyConfig($this);
|
$item->setDailyConfig($this);
|
||||||
}
|
}
|
||||||
@ -100,7 +105,7 @@ class CiConfig implements JsonSerializable
|
|||||||
*/
|
*/
|
||||||
public function removeConfigItem(CiConfigItem $item): CiConfig
|
public function removeConfigItem(CiConfigItem $item): CiConfig
|
||||||
{
|
{
|
||||||
if($this->configItems->contains($item)) {
|
if ($this->configItems->contains($item)) {
|
||||||
$this->configItems->removeElement($item);
|
$this->configItems->removeElement($item);
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@ -285,7 +285,7 @@ class CiConfigItem implements JsonSerializable
|
|||||||
*/
|
*/
|
||||||
public function removeNode(string $node): CiConfigItem
|
public function removeNode(string $node): CiConfigItem
|
||||||
{
|
{
|
||||||
$this->nodes = array_filter($this->nodes, function($item) use ($node) {
|
$this->nodes = array_filter($this->nodes, function ($item) use ($node) {
|
||||||
return $item != $node;
|
return $item != $node;
|
||||||
});
|
});
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@ -7,6 +7,18 @@ use Psr\Http\Message\ResponseInterface;
|
|||||||
|
|
||||||
class PreFlightMiddleware
|
class PreFlightMiddleware
|
||||||
{
|
{
|
||||||
|
const ALLOW_HEADERS = [
|
||||||
|
'DNT',
|
||||||
|
'X-CustomHeader',
|
||||||
|
'Keep-Alive',
|
||||||
|
'User-Agent',
|
||||||
|
'X-Requested-With',
|
||||||
|
'If-Modified-Since',
|
||||||
|
'Cache-Control',
|
||||||
|
'Content-Type',
|
||||||
|
'Authorization',
|
||||||
|
];
|
||||||
|
|
||||||
public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
|
public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
|
||||||
{
|
{
|
||||||
$requestMethod = strtoupper($request->getMethod());
|
$requestMethod = strtoupper($request->getMethod());
|
||||||
@ -15,7 +27,7 @@ class PreFlightMiddleware
|
|||||||
->withHeader('Accept', 'OPTIONS,GET,POST,PUT,PATCH,DELETE')
|
->withHeader('Accept', 'OPTIONS,GET,POST,PUT,PATCH,DELETE')
|
||||||
->withHeader('Access-Control-Allow-Origin', '*')
|
->withHeader('Access-Control-Allow-Origin', '*')
|
||||||
->withHeader('Access-Control-Allow-Methods', 'OPTIONS,GET,POST,PUT,PATCH,DELETE')
|
->withHeader('Access-Control-Allow-Methods', 'OPTIONS,GET,POST,PUT,PATCH,DELETE')
|
||||||
->withHeader('Access-Control-Allow-Headers', 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization');
|
->withHeader('Access-Control-Allow-Headers', implode(",", self::ALLOW_HEADERS));
|
||||||
}
|
}
|
||||||
return $next($request, $response);
|
return $next($request, $response);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,14 +6,27 @@ use Zend\Diactoros\Response\JsonResponse;
|
|||||||
|
|
||||||
class JsonCorsResponse extends JsonResponse
|
class JsonCorsResponse extends JsonResponse
|
||||||
{
|
{
|
||||||
public function __construct($data,
|
const ALLOW_HEADERS = [
|
||||||
$status = 200,
|
'DNT',
|
||||||
array $headers = [],
|
'X-CustomHeader',
|
||||||
$encodingOptions = self::DEFAULT_JSON_FLAGS)
|
'Keep-Alive',
|
||||||
{
|
'User-Agent',
|
||||||
|
'X-Requested-With',
|
||||||
|
'If-Modified-Since',
|
||||||
|
'Cache-Control',
|
||||||
|
'Content-Type',
|
||||||
|
'Authorization',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
$data,
|
||||||
|
$status = 200,
|
||||||
|
array $headers = [],
|
||||||
|
$encodingOptions = self::DEFAULT_JSON_FLAGS
|
||||||
|
) {
|
||||||
$headers['Access-Control-Allow-Origin'] = '*';
|
$headers['Access-Control-Allow-Origin'] = '*';
|
||||||
$headers['Access-Control-Allow-Methods'] = 'OPTIONS,GET,POST,PUT,PATCH,DELETE';
|
$headers['Access-Control-Allow-Methods'] = 'OPTIONS,GET,POST,PUT,PATCH,DELETE';
|
||||||
$headers['Access-Control-Allow-Headers'] = 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
$headers['Access-Control-Allow-Headers'] = implode(",", self::ALLOW_HEADERS);
|
||||||
parent::__construct($data, $status, $headers, $encodingOptions);
|
parent::__construct($data, $status, $headers, $encodingOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,7 +86,7 @@ class CiConfigService
|
|||||||
*/
|
*/
|
||||||
public function update(int $id, array $data)
|
public function update(int $id, array $data)
|
||||||
{
|
{
|
||||||
if(null === ($entity = $this->em->find(CiConfig::class, $id))) {
|
if (null === ($entity = $this->em->find(CiConfig::class, $id))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->hydrator->hydrate($data, $entity);
|
$this->hydrator->hydrate($data, $entity);
|
||||||
|
|||||||
@ -92,7 +92,7 @@ class CiExecutorService
|
|||||||
|
|
||||||
$cache = $this->getCache(self::JCAT_CACHE_KEY);
|
$cache = $this->getCache(self::JCAT_CACHE_KEY);
|
||||||
$result = $cache->getItem(self::PACKAGE_CACHE_KEY, $success);
|
$result = $cache->getItem(self::PACKAGE_CACHE_KEY, $success);
|
||||||
if(!$success) {
|
if (!$success) {
|
||||||
$config2Html = $this->getConfig2Html();
|
$config2Html = $this->getConfig2Html();
|
||||||
$staplerTokens = $this->getStaplerTokens($config2Html, "JCAT_TYPE");
|
$staplerTokens = $this->getStaplerTokens($config2Html, "JCAT_TYPE");
|
||||||
$packages =$this->getJcatVersions($staplerTokens['url'], $staplerTokens['token']);
|
$packages =$this->getJcatVersions($staplerTokens['url'], $staplerTokens['token']);
|
||||||
@ -117,7 +117,7 @@ class CiExecutorService
|
|||||||
|
|
||||||
$cache = $this->getCache(self::STREAM_CACHE_KEY);
|
$cache = $this->getCache(self::STREAM_CACHE_KEY);
|
||||||
$result = $cache->getItem(self::STREAM_CACHE_KEY, $success);
|
$result = $cache->getItem(self::STREAM_CACHE_KEY, $success);
|
||||||
if(!$success) {
|
if (!$success) {
|
||||||
$config2Html = $this->getConfig2Html();
|
$config2Html = $this->getConfig2Html();
|
||||||
$streams =$this->getStreams($config2Html);
|
$streams =$this->getStreams($config2Html);
|
||||||
$cache->setItem(self::STREAM_CACHE_KEY, serialize($streams));
|
$cache->setItem(self::STREAM_CACHE_KEY, serialize($streams));
|
||||||
@ -159,9 +159,10 @@ class CiExecutorService
|
|||||||
// if(0 == count($availableNodes)) {
|
// if(0 == count($availableNodes)) {
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
// @todo remove this part, and check for sub-job success that also needs to be saved, if any node fails, all nodes fail now
|
// @todo remove this part, and check for sub-job success that also needs to be saved
|
||||||
foreach($nodes as $node) {
|
// if any node fails, all nodes fail now
|
||||||
if(!$this->isNodeOnline($node) || !$this->isNodeIdle($node)) {
|
foreach ($nodes as $node) {
|
||||||
|
if (!$this->isNodeOnline($node) || !$this->isNodeIdle($node)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,7 +171,7 @@ class CiExecutorService
|
|||||||
// @todo reorganize this into config1build?
|
// @todo reorganize this into config1build?
|
||||||
$config1Status = $this->buildConfigOne($nodes);
|
$config1Status = $this->buildConfigOne($nodes);
|
||||||
$config1JobId = $this->getConfig1JobId();
|
$config1JobId = $this->getConfig1JobId();
|
||||||
while(!$this->isConfig1Built($config1JobId)) {
|
while (!$this->isConfig1Built($config1JobId)) {
|
||||||
sleep(2);
|
sleep(2);
|
||||||
set_time_limit(30);
|
set_time_limit(30);
|
||||||
}
|
}
|
||||||
@ -179,7 +180,7 @@ class CiExecutorService
|
|||||||
$config2Html = $this->getConfig2Html();
|
$config2Html = $this->getConfig2Html();
|
||||||
$streams = $this->getStreams($config2Html);
|
$streams = $this->getStreams($config2Html);
|
||||||
$staplerTokens = $this->getStaplerTokens($config2Html, "STREAM");
|
$staplerTokens = $this->getStaplerTokens($config2Html, "STREAM");
|
||||||
if(true === ($streamExists = in_array($configItem->getStream(), $streams))) {
|
if (true === ($streamExists = in_array($configItem->getStream(), $streams))) {
|
||||||
$package = $this->getPackage($configItem->getStream(), $staplerTokens['url'], $staplerTokens['token']);
|
$package = $this->getPackage($configItem->getStream(), $staplerTokens['url'], $staplerTokens['token']);
|
||||||
} else {
|
} else {
|
||||||
$package = false;
|
$package = false;
|
||||||
@ -187,11 +188,11 @@ class CiExecutorService
|
|||||||
$jcatVersions = $this->getJcatVersions($staplerTokens['url'], $staplerTokens['token']);
|
$jcatVersions = $this->getJcatVersions($staplerTokens['url'], $staplerTokens['token']);
|
||||||
|
|
||||||
// Check if the desired JCAT version is available, try to create it if it's not
|
// Check if the desired JCAT version is available, try to create it if it's not
|
||||||
if(!in_array($configItem->getJcat(), $jcatVersions)) {
|
if (!in_array($configItem->getJcat(), $jcatVersions)) {
|
||||||
// wait for jcat package to become available
|
// wait for jcat package to become available
|
||||||
$this->addJcatPackageToJenkins($configItem->getJcat());
|
$this->addJcatPackageToJenkins($configItem->getJcat());
|
||||||
$jcatDeployJobId = $this->getJcatDeployJobId();
|
$jcatDeployJobId = $this->getJcatDeployJobId();
|
||||||
while(!$this->isJcatPackageDeployed($jcatDeployJobId)) {
|
while (!$this->isJcatPackageDeployed($jcatDeployJobId)) {
|
||||||
sleep(2);
|
sleep(2);
|
||||||
set_time_limit(30);
|
set_time_limit(30);
|
||||||
}
|
}
|
||||||
@ -200,18 +201,24 @@ class CiExecutorService
|
|||||||
|
|
||||||
$nodeBases = [];
|
$nodeBases = [];
|
||||||
$nodeTraffics = [];
|
$nodeTraffics = [];
|
||||||
foreach($nodes as $type => $typeNodes) {
|
foreach ($nodes as $type => $typeNodes) {
|
||||||
foreach($typeNodes as $node => $backupPostfix) {
|
foreach ($typeNodes as $node => $backupPostfix) {
|
||||||
if(false === strpos($node, "-")) {
|
if (false === strpos($node, "-")) {
|
||||||
$nodeBaseName = sprintf("%s_%s", $node, $backupPostfix);
|
$nodeBaseName = sprintf("%s_%s", $node, $backupPostfix);
|
||||||
$nodeBases[$node] = in_array($nodeBaseName, $this->getNodeBaseNames($config2Html, $node)) ? $nodeBaseName : false;
|
$nodeBases[$node] = in_array($nodeBaseName, $this->getNodeBaseNames($config2Html, $node))
|
||||||
|
? $nodeBaseName
|
||||||
|
: false;
|
||||||
$nodeTraffics[$node] = $this->getNodeTrafficConfigs($config2Html, $node);
|
$nodeTraffics[$node] = $this->getNodeTrafficConfigs($config2Html, $node);
|
||||||
} else {
|
} else {
|
||||||
list($zone1, $zone2) = explode("-", $node);
|
list($zone1, $zone2) = explode("-", $node);
|
||||||
$zone1BaseName = sprintf("%s_%s", $zone1, $backupPostfix);
|
$zone1BaseName = sprintf("%s_%s", $zone1, $backupPostfix);
|
||||||
$zone2BaseName = sprintf("%s_%s", $zone2, $backupPostfix);
|
$zone2BaseName = sprintf("%s_%s", $zone2, $backupPostfix);
|
||||||
$nodeBases[$zone1] = in_array($zone1BaseName, $this->getNodeBaseNames($config2Html, $zone1)) ? $zone1BaseName : false;
|
$nodeBases[$zone1] = in_array($zone1BaseName, $this->getNodeBaseNames($config2Html, $zone1))
|
||||||
$nodeBases[$zone2] = in_array($zone2BaseName, $this->getNodeBaseNames($config2Html, $zone2)) ? $zone2BaseName : false;
|
? $zone1BaseName
|
||||||
|
: false;
|
||||||
|
$nodeBases[$zone2] = in_array($zone2BaseName, $this->getNodeBaseNames($config2Html, $zone2))
|
||||||
|
? $zone2BaseName
|
||||||
|
: false;
|
||||||
$nodeTraffics[$node] = $this->getNodeTrafficConfigs($config2Html, str_replace("-", "_", $node));
|
$nodeTraffics[$node] = $this->getNodeTrafficConfigs($config2Html, str_replace("-", "_", $node));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,7 +257,7 @@ class CiExecutorService
|
|||||||
$response = $this->httpClient->send();
|
$response = $this->httpClient->send();
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
$parsedResponse = Json::decode($body);
|
$parsedResponse = Json::decode($body);
|
||||||
if($parsedResponse->building == true) {
|
if ($parsedResponse->building == true) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +269,7 @@ class CiExecutorService
|
|||||||
$response = $this->httpClient->send();
|
$response = $this->httpClient->send();
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
$parsedResponse = Json::decode($body);
|
$parsedResponse = Json::decode($body);
|
||||||
if($parsedResponse->building == true) {
|
if ($parsedResponse->building == true) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -276,12 +283,13 @@ class CiExecutorService
|
|||||||
private function buildConfigOne($nodes): bool
|
private function buildConfigOne($nodes): bool
|
||||||
{
|
{
|
||||||
$appendParams = [];
|
$appendParams = [];
|
||||||
foreach($nodes as $type => $typeNodes) {
|
foreach ($nodes as $type => $typeNodes) {
|
||||||
foreach($typeNodes as $node => $basePostfix) {
|
foreach ($typeNodes as $node => $basePostfix) {
|
||||||
$appendParams[] = sprintf("%s=%s", $type, $node);
|
$appendParams[] = sprintf("%s=%s", $type, $node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->httpClient->setUri($this->jenkinsBaseUrl . self::CONFIG_1_PATH . '/buildWithParameters?delay=0sec&' . implode("&", $appendParams));
|
$uri = $this->jenkinsBaseUrl . self::CONFIG_1_PATH . '/buildWithParameters?delay=0sec&';
|
||||||
|
$this->httpClient->setUri($uri . implode("&", $appendParams));
|
||||||
$this->httpClient->resetParameters(false, false);
|
$this->httpClient->resetParameters(false, false);
|
||||||
$request = $this->httpClient->getRequest();
|
$request = $this->httpClient->getRequest();
|
||||||
$request->setMethod('POST');
|
$request->setMethod('POST');
|
||||||
@ -321,7 +329,7 @@ class CiExecutorService
|
|||||||
$response = $this->httpClient->send();
|
$response = $this->httpClient->send();
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
$parsedResponse = Json::decode($body);
|
$parsedResponse = Json::decode($body);
|
||||||
if($parsedResponse->building == false) {
|
if ($parsedResponse->building == false) {
|
||||||
if ($parsedResponse->result == 'SUCCESS') {
|
if ($parsedResponse->result == 'SUCCESS') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -342,7 +350,7 @@ class CiExecutorService
|
|||||||
$request = $this->httpClient->getRequest();
|
$request = $this->httpClient->getRequest();
|
||||||
$request->setMethod('GET');
|
$request->setMethod('GET');
|
||||||
$response = $this->httpClient->send();
|
$response = $this->httpClient->send();
|
||||||
if($response->getStatusCode() == 401) {
|
if ($response->getStatusCode() == 401) {
|
||||||
throw new \Exception("Not authenticated");
|
throw new \Exception("Not authenticated");
|
||||||
}
|
}
|
||||||
return $response->getBody();
|
return $response->getBody();
|
||||||
@ -350,7 +358,8 @@ class CiExecutorService
|
|||||||
|
|
||||||
private function getStaplerTokens($config2Body, $blockName = "STREAM")
|
private function getStaplerTokens($config2Body, $blockName = "STREAM")
|
||||||
{
|
{
|
||||||
if(0 === ($didMatch = preg_match(sprintf('#referencedParameters\.push\("%s"\);.*?makeStaplerProxy\(\'(.*?)\',\'(.*?)\'.*?// Create Jenkins proxy#msi', $blockName), $config2Body, $matches))) {
|
$pattern = '#referencedParameters\.push\("%s"\);.*?makeStaplerProxy\(\'(.*?)\',\'(.*?)\'.*?// Create#msi';
|
||||||
|
if (0 === ($didMatch = preg_match(sprintf($pattern, $blockName), $config2Body, $matches))) {
|
||||||
throw new \Exception("Couldn't match stapler tokens in response body");
|
throw new \Exception("Couldn't match stapler tokens in response body");
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
@ -370,11 +379,11 @@ class CiExecutorService
|
|||||||
$xpath = new \DOMXPath($domDocument);
|
$xpath = new \DOMXPath($domDocument);
|
||||||
$element = $xpath->query($xpathQuery);
|
$element = $xpath->query($xpathQuery);
|
||||||
|
|
||||||
if($element->length == 0) {
|
if ($element->length == 0) {
|
||||||
throw new \Exception("Can't find STREAM");
|
throw new \Exception("Can't find STREAM");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($element[0]->nextSibling->nodeName != "select") {
|
if ($element[0]->nextSibling->nodeName != "select") {
|
||||||
throw new \Exception("Can't find STREAM dropdown");
|
throw new \Exception("Can't find STREAM dropdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +393,7 @@ class CiExecutorService
|
|||||||
}
|
}
|
||||||
|
|
||||||
sort($streams, SORT_NATURAL);
|
sort($streams, SORT_NATURAL);
|
||||||
return array_values(array_filter(array_unique($streams), function($item){
|
return array_values(array_filter(array_unique($streams), function ($item) {
|
||||||
return $item != "" && $item != "none";
|
return $item != "" && $item != "none";
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -400,18 +409,18 @@ class CiExecutorService
|
|||||||
$request->setMethod('POST');
|
$request->setMethod('POST');
|
||||||
$request->setContent(sprintf('["STREAM=%s"]', $stream));
|
$request->setContent(sprintf('["STREAM=%s"]', $stream));
|
||||||
$updateResponse = $this->httpClient->send();
|
$updateResponse = $this->httpClient->send();
|
||||||
if(!$updateResponse->isSuccess()) {
|
if (!$updateResponse->isSuccess()) {
|
||||||
throw new \Exception("Stapler doUpdate error");
|
throw new \Exception("Stapler doUpdate error");
|
||||||
}
|
}
|
||||||
sleep(1);
|
sleep(1);
|
||||||
$this->httpClient->setUri($this->jenkinsBaseUrl . $url . '/getChoicesForUI');
|
$this->httpClient->setUri($this->jenkinsBaseUrl . $url . '/getChoicesForUI');
|
||||||
$request->setContent("[]");
|
$request->setContent("[]");
|
||||||
$choicesResponse = $this->httpClient->send();
|
$choicesResponse = $this->httpClient->send();
|
||||||
if(!$choicesResponse->isSuccess()) {
|
if (!$choicesResponse->isSuccess()) {
|
||||||
throw new \Exception("Stapler getChoicesForUI error");
|
throw new \Exception("Stapler getChoicesForUI error");
|
||||||
}
|
}
|
||||||
$packages = Json::decode($choicesResponse->getBody());
|
$packages = Json::decode($choicesResponse->getBody());
|
||||||
if($packages[0][0] == "Script error") {
|
if ($packages[0][0] == "Script error") {
|
||||||
throw new \Exception("STREAM stapler script error");
|
throw new \Exception("STREAM stapler script error");
|
||||||
}
|
}
|
||||||
return array_shift($packages[0]);
|
return array_shift($packages[0]);
|
||||||
@ -461,19 +470,19 @@ class CiExecutorService
|
|||||||
$request->setMethod('POST');
|
$request->setMethod('POST');
|
||||||
$request->setContent('["JCAT_TYPE=INSTALLED"]');
|
$request->setContent('["JCAT_TYPE=INSTALLED"]');
|
||||||
$updateResponse = $this->httpClient->send();
|
$updateResponse = $this->httpClient->send();
|
||||||
if(!$updateResponse->isSuccess()) {
|
if (!$updateResponse->isSuccess()) {
|
||||||
throw new \Exception("Stapler doUpdate error");
|
throw new \Exception("Stapler doUpdate error");
|
||||||
}
|
}
|
||||||
sleep(1);
|
sleep(1);
|
||||||
$this->httpClient->setUri($this->jenkinsBaseUrl . $url . '/getChoicesForUI');
|
$this->httpClient->setUri($this->jenkinsBaseUrl . $url . '/getChoicesForUI');
|
||||||
$request->setContent("[]");
|
$request->setContent("[]");
|
||||||
$choicesResponse = $this->httpClient->send();
|
$choicesResponse = $this->httpClient->send();
|
||||||
if(!$choicesResponse->isSuccess()) {
|
if (!$choicesResponse->isSuccess()) {
|
||||||
throw new \Exception("Stapler getChoicesForUI error");
|
throw new \Exception("Stapler getChoicesForUI error");
|
||||||
}
|
}
|
||||||
$jcats = Json::decode($choicesResponse->getBody());
|
$jcats = Json::decode($choicesResponse->getBody());
|
||||||
rsort($jcats[0]);
|
rsort($jcats[0]);
|
||||||
if($jcats[0][0] == "Script error") {
|
if ($jcats[0][0] == "Script error") {
|
||||||
throw new \Exception("JCAT stapler script error");
|
throw new \Exception("JCAT stapler script error");
|
||||||
}
|
}
|
||||||
return $jcats[0];
|
return $jcats[0];
|
||||||
@ -490,11 +499,11 @@ class CiExecutorService
|
|||||||
$xpath = new \DOMXPath($domDocument);
|
$xpath = new \DOMXPath($domDocument);
|
||||||
$element = $xpath->query($xpathQuery);
|
$element = $xpath->query($xpathQuery);
|
||||||
|
|
||||||
if($element->length == 0) {
|
if ($element->length == 0) {
|
||||||
throw new \Exception(sprintf("Can't find %s_BASE_BACKUP", $nodeName));
|
throw new \Exception(sprintf("Can't find %s_BASE_BACKUP", $nodeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($element[0]->nextSibling->nodeName != "select") {
|
if ($element[0]->nextSibling->nodeName != "select") {
|
||||||
throw new \Exception(sprintf("Can't find %s_BASE_BACKUP dropdown", $nodeName));
|
throw new \Exception(sprintf("Can't find %s_BASE_BACKUP dropdown", $nodeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +513,9 @@ class CiExecutorService
|
|||||||
}
|
}
|
||||||
|
|
||||||
rsort($baseNames, SORT_NATURAL);
|
rsort($baseNames, SORT_NATURAL);
|
||||||
return array_filter($baseNames, function($item){return $item != "";});
|
return array_filter($baseNames, function ($item) {
|
||||||
|
return $item != "";
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getNodeTrafficConfigs($config2Body, $nodeName)
|
private function getNodeTrafficConfigs($config2Body, $nodeName)
|
||||||
@ -518,11 +529,11 @@ class CiExecutorService
|
|||||||
$xpath = new \DOMXPath($domDocument);
|
$xpath = new \DOMXPath($domDocument);
|
||||||
$element = $xpath->query($xpathQuery);
|
$element = $xpath->query($xpathQuery);
|
||||||
|
|
||||||
if($element->length == 0) {
|
if ($element->length == 0) {
|
||||||
throw new \Exception(sprintf("Can't find %s_TRAFFIC", $nodeName));
|
throw new \Exception(sprintf("Can't find %s_TRAFFIC", $nodeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($element[0]->nextSibling->nodeName != "select") {
|
if ($element[0]->nextSibling->nodeName != "select") {
|
||||||
throw new \Exception(sprintf("Can't find %s_TRAFFIC dropdown", $nodeName));
|
throw new \Exception(sprintf("Can't find %s_TRAFFIC dropdown", $nodeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -532,7 +543,9 @@ class CiExecutorService
|
|||||||
}
|
}
|
||||||
|
|
||||||
rsort($trafficConfigs, SORT_NATURAL);
|
rsort($trafficConfigs, SORT_NATURAL);
|
||||||
return array_filter($trafficConfigs, function($item){return $item != "";});
|
return array_filter($trafficConfigs, function ($item) {
|
||||||
|
return $item != "";
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -544,10 +557,15 @@ class CiExecutorService
|
|||||||
* @param array $nodeTraffics
|
* @param array $nodeTraffics
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function buildConfigTwo(CiConfigItem $configItem, $package, array $nodes, array $nodeBases, array $nodeTraffics)
|
private function buildConfigTwo(
|
||||||
{
|
CiConfigItem $configItem,
|
||||||
|
$package,
|
||||||
|
array $nodes,
|
||||||
|
array $nodeBases,
|
||||||
|
array $nodeTraffics
|
||||||
|
) {
|
||||||
$params = [];
|
$params = [];
|
||||||
if(false === $package) {
|
if (false === $package) {
|
||||||
// stream doesn't exist, have to be created as new. enforces test to be nightly
|
// stream doesn't exist, have to be created as new. enforces test to be nightly
|
||||||
$params[] = "MODE=nightly";
|
$params[] = "MODE=nightly";
|
||||||
$params[] = "NEW_STREAM=" . $configItem->getStream();
|
$params[] = "NEW_STREAM=" . $configItem->getStream();
|
||||||
@ -560,18 +578,18 @@ class CiExecutorService
|
|||||||
$params[] = "JCAT_DIR__MAIN=" . $configItem->getJcat();
|
$params[] = "JCAT_DIR__MAIN=" . $configItem->getJcat();
|
||||||
$params[] = "JCAT_DIR__UPGRADE=" . $configItem->getJcat();
|
$params[] = "JCAT_DIR__UPGRADE=" . $configItem->getJcat();
|
||||||
|
|
||||||
foreach($nodes as $node) {
|
foreach ($nodes as $node) {
|
||||||
if(false === strpos($node, "-")) {
|
if (false === strpos($node, "-")) {
|
||||||
$params[] = sprintf("%s_BASE_BACKUP=%s_%s", $node, $node, $nodeBases[$node]);
|
$params[] = sprintf("%s_BASE_BACKUP=%s_%s", $node, $node, $nodeBases[$node]);
|
||||||
} else {
|
} else {
|
||||||
list($zone1, $zone2) = explode("-", $node);
|
list($zone1, $zone2) = explode("-", $node);
|
||||||
$params[] = sprintf("%s_BASE_BACKUP=%s_%s",$zone1, $zone1, $nodeBases[$zone1]);
|
$params[] = sprintf("%s_BASE_BACKUP=%s_%s", $zone1, $zone1, $nodeBases[$zone1]);
|
||||||
$params[] = sprintf("%s_BASE_BACKUP=%s_%s",$zone2, $zone2, $nodeBases[$zone2]);
|
$params[] = sprintf("%s_BASE_BACKUP=%s_%s", $zone2, $zone2, $nodeBases[$zone2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo create suites parameters
|
// todo create suites parameters
|
||||||
foreach ($this->testTypeMap as $callable => $paramName) {
|
foreach ($this->testTypeMap as $callable => $paramName) {
|
||||||
if($configItem->$callable()) {
|
if ($configItem->$callable()) {
|
||||||
$params[] = sprintf("%s_SUITES=%s", $node, $paramName);
|
$params[] = sprintf("%s_SUITES=%s", $node, $paramName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -579,7 +597,8 @@ class CiExecutorService
|
|||||||
$params[] = sprintf("%s_TRAFFIC=%s", $node, $nodeTraffics[$node]);
|
$params[] = sprintf("%s_TRAFFIC=%s", $node, $nodeTraffics[$node]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->httpClient->setUri($this->jenkinsBaseUrl . self::CONFIG_2_PATH . '/buildWithParameters?delay=0sec&' . implode("&", $params));
|
$uri = $this->jenkinsBaseUrl . self::CONFIG_2_PATH . '/buildWithParameters?delay=0sec&';
|
||||||
|
$this->httpClient->setUri($uri . implode("&", $params));
|
||||||
$this->httpClient->resetParameters(false, false);
|
$this->httpClient->resetParameters(false, false);
|
||||||
$request = $this->httpClient->getRequest();
|
$request = $this->httpClient->getRequest();
|
||||||
$request->setMethod('POST');
|
$request->setMethod('POST');
|
||||||
@ -614,42 +633,44 @@ class CiExecutorService
|
|||||||
preg_match('#TSP_JCAT-([0-9]{3,}\.[0-9]+)(.*)?#', $jcatVersion, $matches);
|
preg_match('#TSP_JCAT-([0-9]{3,}\.[0-9]+)(.*)?#', $jcatVersion, $matches);
|
||||||
|
|
||||||
$version = $matches[1];
|
$version = $matches[1];
|
||||||
$deployType = trim($matches[2],"_");
|
$deployType = trim($matches[2], "_");
|
||||||
unset($matches);
|
unset($matches);
|
||||||
|
|
||||||
// package has no type specified, or type is COMMON
|
// package has no type specified, or type is COMMON
|
||||||
if($deployType == "" || $deployType == "COMMON") {
|
if ($deployType == "" || $deployType == "COMMON") {
|
||||||
$uri = self::JCAT_DEPLOY_SOURCE_URL . sprintf("/JCAT-%s/TSP_JCAT-%s.tar.gz", $version, $version);
|
$uri = self::JCAT_DEPLOY_SOURCE_URL . sprintf("/JCAT-%s/TSP_JCAT-%s.tar.gz", $version, $version);
|
||||||
$this->httpClient->setUri($uri);
|
$this->httpClient->setUri($uri);
|
||||||
$this->httpClient->resetParameters(false, false);
|
$this->httpClient->resetParameters(false, false);
|
||||||
$request = $this->httpClient->getRequest();
|
$request = $this->httpClient->getRequest();
|
||||||
$request->setMethod('HEAD');
|
$request->setMethod('HEAD');
|
||||||
$response = $this->httpClient->send();
|
$response = $this->httpClient->send();
|
||||||
if($response->isOk()) {
|
if ($response->isOk()) {
|
||||||
return $uri;
|
return $uri;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// package type specified exists on jcat server
|
// package type specified exists on jcat server
|
||||||
$uri = self::JCAT_DEPLOY_SOURCE_URL . sprintf("/JCAT-%s-%s/TSP_JCAT-%s-%s.tar.gz", $deployType, $version, $deployType, $version);
|
$filePattern = "/JCAT-%s-%s/TSP_JCAT-%s-%s.tar.gz";
|
||||||
|
$uri = self::JCAT_DEPLOY_SOURCE_URL . sprintf($filePattern, $deployType, $version, $deployType, $version);
|
||||||
$this->httpClient->setUri($uri);
|
$this->httpClient->setUri($uri);
|
||||||
$this->httpClient->resetParameters(false, false);
|
$this->httpClient->resetParameters(false, false);
|
||||||
$request = $this->httpClient->getRequest();
|
$request = $this->httpClient->getRequest();
|
||||||
$request->setMethod('HEAD');
|
$request->setMethod('HEAD');
|
||||||
$response = $this->httpClient->send();
|
$response = $this->httpClient->send();
|
||||||
if($response->isOk()) {
|
if ($response->isOk()) {
|
||||||
return $uri;
|
return $uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
// package type specified exists with 'TSP' prefix on jcat server
|
// package type specified exists with 'TSP' prefix on jcat server
|
||||||
$uri = self::JCAT_DEPLOY_SOURCE_URL . sprintf("/JCAT-TSP%s-%s/TSP_JCAT-TSP%s-%s.tar.gz", $deployType, $version, $deployType, $version);
|
$filePattern = "/JCAT-TSP%s-%s/TSP_JCAT-TSP%s-%s.tar.gz";
|
||||||
|
$uri = self::JCAT_DEPLOY_SOURCE_URL . sprintf($filePattern, $deployType, $version, $deployType, $version);
|
||||||
$this->httpClient->setUri($uri);
|
$this->httpClient->setUri($uri);
|
||||||
$this->httpClient->resetParameters(false, false);
|
$this->httpClient->resetParameters(false, false);
|
||||||
$request = $this->httpClient->getRequest();
|
$request = $this->httpClient->getRequest();
|
||||||
$request->setMethod('HEAD');
|
$request->setMethod('HEAD');
|
||||||
$response = $this->httpClient->send();
|
$response = $this->httpClient->send();
|
||||||
if($response->isOk()) {
|
if ($response->isOk()) {
|
||||||
return $uri;
|
return $uri;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -664,10 +685,11 @@ class CiExecutorService
|
|||||||
"NEW_DEPLOY_URL=$jcatDeployUri",
|
"NEW_DEPLOY_URL=$jcatDeployUri",
|
||||||
"ACTION=add",
|
"ACTION=add",
|
||||||
];
|
];
|
||||||
foreach($availableJcatTargetNodes as $node) {
|
foreach ($availableJcatTargetNodes as $node) {
|
||||||
$appendParams[] = "NODES=$node";
|
$appendParams[] = "NODES=$node";
|
||||||
}
|
}
|
||||||
$this->httpClient->setUri($this->jenkinsBaseUrl . self::ADD_JCAT_PATH . '/buildWithParameters?delay=0sec&' . implode("&", $appendParams));
|
$uri = $this->jenkinsBaseUrl . self::ADD_JCAT_PATH . '/buildWithParameters?delay=0sec&';
|
||||||
|
$this->httpClient->setUri($uri . implode("&", $appendParams));
|
||||||
$this->httpClient->resetParameters(false, false);
|
$this->httpClient->resetParameters(false, false);
|
||||||
$request = $this->httpClient->getRequest();
|
$request = $this->httpClient->getRequest();
|
||||||
$request->setMethod('POST');
|
$request->setMethod('POST');
|
||||||
@ -700,7 +722,7 @@ class CiExecutorService
|
|||||||
$response = $this->httpClient->send();
|
$response = $this->httpClient->send();
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
$parsedResponse = Json::decode($body);
|
$parsedResponse = Json::decode($body);
|
||||||
if($parsedResponse->inQueue == false) {
|
if ($parsedResponse->inQueue == false) {
|
||||||
if ($parsedResponse->lastBuild->number == $parsedResponse->lastSuccessfulBuild->number) {
|
if ($parsedResponse->lastBuild->number == $parsedResponse->lastSuccessfulBuild->number) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -725,11 +747,11 @@ class CiExecutorService
|
|||||||
$xpath = new \DOMXPath($domDocument);
|
$xpath = new \DOMXPath($domDocument);
|
||||||
$element = $xpath->query($xpathQuery);
|
$element = $xpath->query($xpathQuery);
|
||||||
|
|
||||||
if($element->length == 0) {
|
if ($element->length == 0) {
|
||||||
throw new \Exception("Can't find NODES");
|
throw new \Exception("Can't find NODES");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($element[0]->nextSibling->nodeName != "select") {
|
if ($element[0]->nextSibling->nodeName != "select") {
|
||||||
throw new \Exception("Can't find NODES dropdown");
|
throw new \Exception("Can't find NODES dropdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -750,7 +772,7 @@ class CiExecutorService
|
|||||||
$request = $this->httpClient->getRequest();
|
$request = $this->httpClient->getRequest();
|
||||||
$request->setMethod('HEAD');
|
$request->setMethod('HEAD');
|
||||||
$response = $this->httpClient->send();
|
$response = $this->httpClient->send();
|
||||||
if($response->isRedirect()) {
|
if ($response->isRedirect()) {
|
||||||
$this->httpClient->setOptions(['maxredirects' => 5]);
|
$this->httpClient->setOptions(['maxredirects' => 5]);
|
||||||
return rtrim($response->getHeaders()->get("location")->getFieldValue(), "/");
|
return rtrim($response->getHeaders()->get("location")->getFieldValue(), "/");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,8 @@ class CiNodeService
|
|||||||
private $nodes = [
|
private $nodes = [
|
||||||
[
|
[
|
||||||
"name" => 'esx4b', "type" => 'esx', "size" => 1, "team" => "detoqs",
|
"name" => 'esx4b', "type" => 'esx', "size" => 1, "team" => "detoqs",
|
||||||
"bases" => ["7101_base_Jenkins_CI_20161006"], "defaultBase" => "7101_base_Jenkins_CI_20161006", "canAutoStart" => true,
|
"bases" => ["7101_base_Jenkins_CI_20161006"], "defaultBase" => "7101_base_Jenkins_CI_20161006",
|
||||||
|
"canAutoStart" => true,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"name" => 'esx10a', "type" => 'esx', "size" => 1, "team" => "detoqs",
|
"name" => 'esx10a', "type" => 'esx', "size" => 1, "team" => "detoqs",
|
||||||
@ -32,7 +33,8 @@ class CiNodeService
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
"name" => 'takumi', "type" => 'esx', "size" => 1, "team" => "detoqs",
|
"name" => 'takumi', "type" => 'esx', "size" => 1, "team" => "detoqs",
|
||||||
"bases" => ["7000_base_Jenkins_CI_20160701"], "defaultBase" => "7000_base_Jenkins_CI_20160701", "canAutoStart" => true,
|
"bases" => ["7000_base_Jenkins_CI_20160701"], "defaultBase" => "7000_base_Jenkins_CI_20160701",
|
||||||
|
"canAutoStart" => true,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"name" => 'cwsled', "type" => 'maia', "size" => 1, "team" => "taurus",
|
"name" => 'cwsled', "type" => 'maia', "size" => 1, "team" => "taurus",
|
||||||
@ -84,11 +86,13 @@ class CiNodeService
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
"name" => 'natasha', "type" => 'nsp6.1', "size" => 2, "team" => "trex",
|
"name" => 'natasha', "type" => 'nsp6.1', "size" => 2, "team" => "trex",
|
||||||
"bases" => ["7101_base_Jenkins_CI_20161217"], "defaultBase" => "7101_base_Jenkins_CI_20161217", "canAutoStart" => true,
|
"bases" => ["7101_base_Jenkins_CI_20161217"], "defaultBase" => "7101_base_Jenkins_CI_20161217",
|
||||||
|
"canAutoStart" => true,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"name" => 'mazsola-tade', "type" => 'nsp6.1', "size" => 1, "team" => "vikinx",
|
"name" => 'mazsola-tade', "type" => 'nsp6.1', "size" => 1, "team" => "vikinx",
|
||||||
"bases" => ["7111_base_Jenkins_CI_20170130"], "defaultBase" => "7111_base_Jenkins_CI_20170130", "canAutoStart" => true,
|
"bases" => ["7111_base_Jenkins_CI_20170130"], "defaultBase" => "7111_base_Jenkins_CI_20170130",
|
||||||
|
"canAutoStart" => true,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"name" => 'pikkolo', "type" => 'nsp6.1', "size" => 1, "team" => "taurus",
|
"name" => 'pikkolo', "type" => 'nsp6.1', "size" => 1, "team" => "taurus",
|
||||||
@ -131,21 +135,21 @@ class CiNodeService
|
|||||||
|
|
||||||
public function getNode($node): ?array
|
public function getNode($node): ?array
|
||||||
{
|
{
|
||||||
return array_pop(array_filter($this->nodes, function($item) use ($node) {
|
return array_pop(array_filter($this->nodes, function ($item) use ($node) {
|
||||||
return $item['name'] == $node;
|
return $item['name'] == $node;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTestNodeList(array $nodes): ?array
|
public function getTestNodeList(array $nodes): ?array
|
||||||
{
|
{
|
||||||
$filteredNodes = array_filter($this->nodes, function($item) use ($nodes) {
|
$filteredNodes = array_filter($this->nodes, function ($item) use ($nodes) {
|
||||||
return in_array($item['name'], $nodes);
|
return in_array($item['name'], $nodes);
|
||||||
});
|
});
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($filteredNodes as $filteredNode) {
|
foreach ($filteredNodes as $filteredNode) {
|
||||||
$type = strtoupper($filteredNode['type']);
|
$type = strtoupper($filteredNode['type']);
|
||||||
if(!isset($result[$type])) {
|
if (!isset($result[$type])) {
|
||||||
$result[$type] = [];
|
$result[$type] = [];
|
||||||
}
|
}
|
||||||
$result[$type][$filteredNode['name']] = $filteredNode['defaultBase'];
|
$result[$type][$filteredNode['name']] = $filteredNode['defaultBase'];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user