Commit f761aa87 authored by Roman Ondráček's avatar Roman Ondráček

Config: refactor scheduler manager

Signed-off-by: Roman Ondráček's avatarRoman Ondráček <ondracek.roman@centrum.cz>
parent a58c7b07
Pipeline #2147 failed with stages
in 10 minutes and 13 seconds
......@@ -21,6 +21,7 @@ declare(strict_types = 1);
namespace App\ConfigModule\Models;
use App\CoreModule\Models\JsonFileManager;
use Nette\IOException;
use Nette\SmartObject;
use Nette\Utils\JsonException;
......@@ -49,6 +50,18 @@ class MainManager {
$this->fileManager = $fileManager;
}
/**
* Returns the path of cache directory
* @return string Cache directory path
*/
public function getCacheDir(): string {
try {
return $this->load()['cacheDir'];
} catch (IOException | JsonException $e) {
return '/var/cache/iqrf-gateway-daemon/';
}
}
/**
* Converts the main configuration form array to JSON array
* @return mixed[] Array for form
......
......@@ -24,7 +24,6 @@ use App\CoreModule\Models\CommandManager;
use App\CoreModule\Models\JsonFileManager;
use App\ServiceModule\Exceptions\NotSupportedInitSystemException;
use App\ServiceModule\Models\ServiceManager;
use Nette\IOException;
use Nette\SmartObject;
use Nette\Utils\Finder;
use Nette\Utils\JsonException;
......@@ -76,11 +75,7 @@ class SchedulerManager {
$this->genericConfigManager = $genericManager;
$this->serviceManager = $serviceManager;
$this->timeManager = $timeManager;
try {
$path = $mainManager->load()['cacheDir'] . '/scheduler/';
} catch (IOException | JsonException $e) {
$path = '/var/cache/iqrf-gateway-daemon/scheduler/';
}
$path = $mainManager->getCacheDir() . '/scheduler/';
$this->fileManager = new JsonFileManager($path, $commandManager);
}
......
......@@ -28,11 +28,9 @@ use DateTime;
use Nette\Application\BadRequestException;
use Nette\Application\Responses\FileResponse;
use Nette\Http\FileUpload;
use Nette\IOException;
use Nette\SmartObject;
use Nette\Utils\FileSystem;
use Nette\Utils\Finder;
use Nette\Utils\JsonException;
use SplFileInfo;
use ZipArchive;
......@@ -48,11 +46,6 @@ class SchedulerMigrationManager {
*/
private $configDirectory;
/**
* @var MainManager Main configuration manager
*/
private $mainConfigManager;
/**
* @var string Path to ZIP archive
*/
......@@ -69,12 +62,7 @@ class SchedulerMigrationManager {
* @param ServiceManager $serviceManager Service manager
*/
public function __construct(MainManager $mainManager, ServiceManager $serviceManager) {
$this->mainConfigManager = $mainManager;
try {
$this->configDirectory = $this->mainConfigManager->load()['cacheDir'] . '/scheduler/';
} catch (IOException | JsonException $e) {
$this->configDirectory = '/var/cache/iqrfgd2/scheduler/';
}
$this->configDirectory = $mainManager->getCacheDir() . '/scheduler/';
$this->serviceManager = $serviceManager;
}
......
......@@ -28,7 +28,6 @@ use App\IqrfNetModule\Exceptions\EmptyResponseException;
use DateTime;
use Nette\Application\BadRequestException;
use Nette\Application\Responses\FileResponse;
use Nette\IOException;
use Nette\SmartObject;
use Nette\Utils\JsonException;
......@@ -97,11 +96,7 @@ class DiagnosticsManager {
public function __construct(string $confDir, string $logDir, CommandManager $commandManager, InfoManager $infoManager, MainManager $mainManager, NetworkManager $networkManager, VersionManager $versionManager) {
$this->commandManager = $commandManager;
$this->infoManager = $infoManager;
try {
$this->cacheDir = $mainManager->load()['cacheDir'];
} catch (JsonException | IOException $e) {
$this->cacheDir = '/var/cache/iqrf-gateway-daemon/';
}
$this->cacheDir = $mainManager->getCacheDir();
$this->confDir = $confDir;
$this->logDir = $logDir;
$this->networkManager = $networkManager;
......
......@@ -197,9 +197,9 @@ class SchedulerManagerTest extends TestCase {
$schemaManager = new ComponentSchemaManager($schemaPath, $commandManager);
$genericConfigManager = new GenericManager($fileManager, $schemaManager);
$mainConfigManager = Mockery::mock(MainManager::class);
$mainConfigManager->shouldReceive('load')->andReturn(['cacheDir' => $configPath]);
$mainConfigManager->shouldReceive('getCacheDir')->andReturn($configPath);
$mainConfigManagerTemp = Mockery::mock(MainManager::class);
$mainConfigManagerTemp->shouldReceive('load')->andReturn(['cacheDir' => $configTempPath]);
$mainConfigManagerTemp->shouldReceive('getCacheDir')->andReturn($configTempPath);
$this->timeManager = new TaskTimeManager();
$this->serviceManager = Mockery::mock(ServiceManager::class);
$this->manager = new SchedulerManager($mainConfigManager, $genericConfigManager, $this->timeManager, $this->serviceManager, $commandManager);
......
......@@ -134,7 +134,7 @@ class SchedulerMigrationManagerTest extends TestCase {
$commandManager = new CommandManager(false, $commandStack);
$this->fileManager = new FileManager($this->configPath, $commandManager);
$mainConfigManager = Mockery::mock(MainManager::class);
$mainConfigManager->shouldReceive('load')->andReturn(['cacheDir' => $this->configTempPath . '/..']);
$mainConfigManager->shouldReceive('getCacheDir')->andReturn($this->configTempPath . '/..');
$serviceManager = Mockery::mock(ServiceManager::class);
$serviceManager->shouldReceive('restart');
$this->manager = new SchedulerMigrationManager($mainConfigManager, $serviceManager);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment