Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

fix(api): fix options retrieval issue #8412

Merged
merged 4 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Centreon/Application/Controller/GorgoneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

use Centreon\Domain\Gorgone\Command\Internal\ThumbprintCommand;
use Centreon\Domain\Gorgone\Interfaces\CommandInterface;
use Centreon\Domain\Gorgone\Interfaces\ServiceInterface;
use Centreon\Domain\Gorgone\Interfaces\GorgoneServiceInterface;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\View\View;
Expand All @@ -36,11 +36,11 @@
class GorgoneController extends AbstractFOSRestController
{
/**
* @var ServiceInterface
* @var GorgoneServiceInterface
*/
private $gorgoneService;

public function __construct(ServiceInterface $gorgoneService)
public function __construct(GorgoneServiceInterface $gorgoneService)
{
$this->gorgoneService = $gorgoneService;
}
Expand Down
1 change: 1 addition & 0 deletions src/Centreon/Domain/Gorgone/ActionLog.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down
10 changes: 9 additions & 1 deletion src/Centreon/Domain/Gorgone/Command/BasicCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down Expand Up @@ -35,14 +36,21 @@ trait BasicCommand
*/
private $monitoringInstanceId;

/**
* @var string|null
*/
private $bodyRequest;

/**
* We create a command for a specific poller.
*
* @param int $pollerId Poller id for which this command is intended
* @param string|null $bodyRequest
*/
public function __construct(int $pollerId)
public function __construct(int $pollerId, string $bodyRequest = null)
{
$this->monitoringInstanceId = $pollerId;
$this->bodyRequest = $bodyRequest;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Centreon/Domain/Gorgone/Command/CommandFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down Expand Up @@ -28,7 +29,7 @@ class CommandFactory
/**
* @var array<CommandInterface> GorgoneCommandInterface[]
*/
static private $commands = [];
private static $commands = [];

/**
* @param CommandInterface $command Command to add
Expand Down
1 change: 1 addition & 0 deletions src/Centreon/Domain/Gorgone/Command/EmptyCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down
8 changes: 6 additions & 2 deletions src/Centreon/Domain/Gorgone/ConfigurationLoader.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -46,7 +47,7 @@ class ConfigurationLoader implements ConfigurationLoaderApiInterface
private $optionService;

/**
* @var array<string, string> Parameters of the Gorgone server
* @var array<string, string|null> Parameters of the Gorgone server
*/
private $gorgoneParameters;

Expand Down Expand Up @@ -144,6 +145,8 @@ public function getCommandTimeout(): int

/**
* Loads configuration of the Gorgone server
*
* @throws \Exception
*/
private function loadConfiguration(): void
{
Expand All @@ -163,6 +166,7 @@ private function loadConfiguration(): void
$this->isOptionsLoaded = true;
} catch (\Exception $ex) {
$this->isOptionsLoaded = false;
throw $ex;
}
}
}
2 changes: 2 additions & 0 deletions src/Centreon/Domain/Gorgone/GorgoneException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand All @@ -17,6 +18,7 @@
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);

namespace Centreon\Domain\Gorgone;

Expand Down
5 changes: 3 additions & 2 deletions src/Centreon/Domain/Gorgone/GorgoneService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down Expand Up @@ -26,9 +27,9 @@
use Centreon\Domain\Gorgone\Interfaces\CommandRepositoryInterface;
use Centreon\Domain\Gorgone\Interfaces\ResponseInterface;
use Centreon\Domain\Gorgone\Interfaces\ResponseRepositoryInterface;
use Centreon\Domain\Gorgone\Interfaces\ServiceInterface;
use Centreon\Domain\Gorgone\Interfaces\GorgoneServiceInterface;

class GorgoneService implements ServiceInterface
class GorgoneService implements GorgoneServiceInterface
{
/**
* @var ResponseRepositoryInterface
Expand Down
5 changes: 3 additions & 2 deletions src/Centreon/Domain/Gorgone/Interfaces/CommandInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down Expand Up @@ -53,9 +54,9 @@ public function getUriRequest(): string;
/**
* Returns the body of the request that will be sent to the Gorgone server.
*
* @return string Body of the request
* @return string|null Body of the request
*/
public function getBodyRequest(): string;
public function getBodyRequest(): ?string;

/**
* Returns the monitoring instance id for which this command is intended.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand All @@ -21,7 +22,7 @@

namespace Centreon\Domain\Gorgone\Interfaces;

interface ServiceInterface
interface GorgoneServiceInterface
{
/**
* Send a command to the Gorgone server and retrieve an instance of the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down
31 changes: 16 additions & 15 deletions src/Centreon/Domain/Gorgone/Response.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down Expand Up @@ -62,7 +63,7 @@ class Response implements ResponseInterface
/**
* @var ResponseRepositoryInterface
*/
static private $staticResponseRepository;
private static $staticResponseRepository;

/**
* @var ResponseRepositoryInterface
Expand Down Expand Up @@ -118,10 +119,23 @@ public function getMessage(): ?string

/**
* @return ActionLog[]
* @throws \Exception
* @see Response::$actionLogs
*/
public function getActionLogs(): array
{
$this->actionLogs = [];
$rawResponse = $this->responseRepository->getResponse($this->command);
$jsonResponse = json_decode($rawResponse, true);
$this->error = $jsonResponse['error'] ?? null;
$this->token = (string) $jsonResponse['token'];

if ($this->error === null) {
foreach ($jsonResponse['data'] as $key => $responseData) {
$this->actionLogs[$key] = ActionLog::create($responseData);
}
}
$this->message = ((string) $jsonResponse['message'] ?? null);
return $this->actionLogs;
}

Expand All @@ -131,20 +145,7 @@ public function getActionLogs(): array
*/
public function getLastActionLog(): ?ActionLog
{
if (empty($this->actionLogs)) {
$rawResponse = $this->responseRepository->getResponse($this->command);
$jsonResponse = json_decode($rawResponse, true);
$this->error = $jsonResponse['error'] ?? null;
$this->token = (string) $jsonResponse['token'];

if ($this->error === null) {
$this->actionLogs = [];
foreach ($jsonResponse['data'] as $key => $responseData) {
$this->actionLogs[$key] = ActionLog::create($responseData);
}
}
$this->message = ((string) $jsonResponse['message'] ?? null);
}
$this->getActionLogs();
return $this->actionLogs[count($this->actionLogs) - 1] ?? null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down
11 changes: 6 additions & 5 deletions src/Centreon/Domain/Option/Option.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down Expand Up @@ -29,7 +30,7 @@ class Option
private $name;

/**
* @var string Option value
* @var string|null Option value
*/
private $value;

Expand All @@ -54,20 +55,20 @@ public function setName(string $name): Option
}

/**
* @return string
* @return string|null
* @see Option::$value
*/
public function getValue(): string
public function getValue(): ?string
{
return $this->value;
}

/**
* @param string $value
* @param string|null $value
* @return Option
* @see Option::$value
*/
public function setValue(string $value): Option
public function setValue(?string $value): Option
{
$this->value = $value;
return $this;
Expand Down
27 changes: 27 additions & 0 deletions src/Centreon/Domain/Option/OptionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);

namespace Centreon\Domain\Option;

class OptionException extends \Exception
{
}
1 change: 1 addition & 0 deletions src/Centreon/Domain/Option/OptionService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
Expand Down
Loading