Commit 8538af49 authored by Michael Joyce's avatar Michael Joyce
Browse files

more interaction with lockss.

parent 8c155d11
......@@ -6,8 +6,8 @@
"ext-ctype": "*",
"ext-iconv": "*",
"ext-simplexml": "*",
"ext-zip": "*",
"ext-soap": "*",
"ext-zip": "*",
"egulias/email-validator": "^2.1",
"guzzlehttp/guzzle": "^6.5",
"laminas/laminas-soap": "^2.8",
......@@ -35,6 +35,7 @@
"symfony/web-link": "4.4.*",
"symfony/yaml": "4.4.*",
"tetranz/select2entity-bundle": "^2.9",
"twig/intl-extra": "^3.0",
"twig/string-extra": "^3.0",
"ubermichael/nines": "4.x-dev"
},
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6fffee65f2079068cc8f4813efeedcf2",
"content-hash": "13ba513931dd6d3a1a8869315ca1ed62",
"packages": [
{
"name": "composer/package-versions-deprecated",
......@@ -8426,6 +8426,69 @@
],
"time": "2020-05-21T09:56:39+00:00"
},
{
"name": "twig/intl-extra",
"version": "v3.0.5",
"source": {
"type": "git",
"url": "https://github.com/twigphp/intl-extra.git",
"reference": "6f1889920753e6ffd72b06fc1d9b363ec2cec540"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/intl-extra/zipball/6f1889920753e6ffd72b06fc1d9b363ec2cec540",
"reference": "6f1889920753e6ffd72b06fc1d9b363ec2cec540",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"symfony/intl": "^4.3|^5.0",
"twig/twig": "^2.4|^3.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^4.4.9|^5.0.9"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"Twig\\Extra\\Intl\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
}
],
"description": "A Twig extension for Intl",
"homepage": "https://twig.symfony.com",
"keywords": [
"intl",
"twig"
],
"funding": [
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/twig/twig",
"type": "tidelift"
}
],
"time": "2020-06-22T06:17:05+00:00"
},
{
"name": "twig/string-extra",
"version": "v3.0.5",
......@@ -9676,8 +9739,8 @@
"ext-ctype": "*",
"ext-iconv": "*",
"ext-simplexml": "*",
"ext-zip": "*",
"ext-soap": "*"
"ext-soap": "*",
"ext-zip": "*"
},
"platform-dev": [],
"plugin-api-version": "1.1.0"
......
......@@ -21,6 +21,8 @@ parameters:
lom.boxstatus.sender: '%env(LOM_STATUS_SENDER)%'
lom.boxstatus.contact: '%env(LOM_STATUS_CONTACT)%'
lockss.deposit.limit: 150
services:
# default configuration for services in *this* file
_defaults:
......
<?php
declare(strict_types=1);
/*
* (c) 2020 Michael Joyce <mjoyce@sfu.ca>
* This source file is subject to the GPL v2, bundled
* with this source code in the file LICENSE.
*/
namespace App\Command\Lockss;
use App\Entity\Au;
use App\Entity\Pln;
use App\Repository\AuRepository;
use App\Repository\BoxRepository;
use App\Repository\DepositRepository;
use App\Repository\PlnRepository;
use App\Services\BoxNotifier;
use App\Services\Lockss\LockssService;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use stdClass;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
abstract class AbstractLockssCommand extends Command {
/**
* @var EntityManagerInterface
*/
protected $em;
/**
* @var LoggerInterface
*/
protected $logger;
/**
* @var AuRepository
*/
protected $auRepository;
/**
* @var BoxRepository
*/
protected $boxRepository;
/**
* @var DepositRepository
*/
protected $depositRepository;
/**
* @var PlnRepository
*/
protected $plnRepository;
/**
* @var BoxNotifier
*/
protected $notifier;
/**
* @var LockssService
*/
protected $lockssService;
/**
* @var ParameterBagInterface
*/
protected $params;
public function __construct(LockssService $lockssService, ParameterBagInterface $params, string $name = null) {
parent::__construct($name);
$this->lockssService = $lockssService;
$this->params = $params;
}
/**
* @param $auIds
*
* @return Au[]
*/
protected function getAus($auIds) {
if ($auIds) {
return $this->auRepository->findBy(['id' => $auIds]);
}
return $this->auRepository->findAll();
}
protected function getBoxes($plnIds) {
if ($plnIds) {
$plns = $this->plnRepository->findBy(['id' => $plnIds]);
return $this->boxRepository->findBy([
'pln' => $plns,
'active' => true,
]);
}
return $this->boxRepository->findBy(['active' => true]);
}
/**
* @param $plnIds
*
* @return Pln[]
*/
protected function getPlns($plnIds) {
if ( ! $plnIds) {
return $this->plnRepository->findAll();
}
return $this->plnRepository->findBy(['id' => $plnIds]);
}
protected function toArray(stdClass $object) {
$array = [];
foreach ($object as $key => $value) {
if ($value instanceof stdClass) {
$array[$key] = $this->toArray($value);
} else {
$array[$key] = $value;
}
}
return $array;
}
/**
* @required
*/
public function setEntityManager(EntityManagerInterface $em) : void {
$this->em = $em;
}
/**
* @required
*/
public function setLogger(LoggerInterface $soapLogger) : void {
$this->logger = $soapLogger;
}
/**
* @required
*/
public function setAuRepository(AuRepository $repo) : void {
$this->auRepository = $repo;
}
/**
* @required
*/
public function setBoxRepository(BoxRepository $repo) : void {
$this->boxRepository = $repo;
}
/**
* @required
*/
public function setDepositRepository(DepositRepository $repo) : void {
$this->depositRepository = $repo;
}
/**
* @required
*/
public function setPlnRepository(PlnRepository $repo) : void {
$this->plnRepository = $repo;
}
/**
* @required
*/
public function setNotifier(BoxNotifier $notifier) : void {
$this->notifier = $notifier;
}
}
......@@ -10,45 +10,20 @@ declare(strict_types=1);
namespace App\Command\Lockss;
use App\Repository\BoxRepository;
use App\Repository\PlnRepository;
use App\Services\BoxNotifier;
use Exception;
use App\Entity\Box;
use App\Entity\BoxStatus;
use App\Services\Lockss\LockssService;
use App\Utilities\LockssClient;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use stdClass;
use Symfony\Component\Console\Command\Command;
use Exception;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Twig\Environment;
class ListAusCommand extends Command {
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var BoxRepository
*/
private $boxRepository;
/**
* @var PlnRepository
*/
private $plnRepository;
class AuListCommand extends AbstractLockssCommand {
protected static $defaultName = 'lockss:aus:list';
protected static $defaultName = 'lockss:list:aus';
public function __construct(string $name = null) {
parent::__construct($name);
public function __construct(LockssService $lockssService, ParameterBagInterface $params, string $name = null) {
parent::__construct($lockssService, $params, $name);
}
protected function configure() : void {
......@@ -56,40 +31,31 @@ class ListAusCommand extends Command {
$this->setDescription('List the AUs in the boxes in a network.');
}
protected function getBoxes($plnIds) {
if ($plnIds) {
$plns = $this->plnRepository->findBy(['id' => $plnIds]);
return $this->boxRepository->findBy([
'pln' => $plns,
'active' => true,
]);
}
return $this->boxRepository->findBy(['active' => true]);
}
protected function listAus(Box $box) {
$client = LockssClient::create($box);
$service = new LockssService();
$service->setClient($client);
$result = [];
try {
$result = $service->listAus();
}
catch (Exception $e) {
} catch (Exception $e) {
$this->logger->error("{$box->getIpAddress()} - {$e->getMessage()}");
}
return $result;
}
protected function execute(InputInterface $input, OutputInterface $output) : int {
$plnIds = $input->getOption('pln');
$boxes = $this->getBoxes($plnIds);
$output->writeln('listing AUs in ' . count($boxes) . ' boxes.');
foreach ($this->getBoxes($plnIds) as $box) {
$output->writeln($box);
$output->writeln('');
foreach($this->listAus($box) as $result) {
$output->writeln(" " . $result->name);
foreach ($this->listAus($box) as $result) {
$output->writeln(' ' . $result->name);
$output->writeln($result->id);
$output->writeln('');
}
......@@ -97,26 +63,4 @@ class ListAusCommand extends Command {
return 0;
}
/**
* @required
*/
public function setLogger(LoggerInterface $soapLogger) : void {
$this->logger = $soapLogger;
}
/**
* @required
*/
public function setBoxRepository(BoxRepository $repo) {
$this->boxRepository = $repo;
}
/**
* @required
*/
public function setPlnRepository(PlnRepository $repo) {
$this->plnRepository = $repo;
}
}
......@@ -12,61 +12,20 @@ namespace App\Command\Lockss;
use App\Entity\Au;
use App\Entity\AuStatus;
use App\Entity\Pln;
use App\Repository\BoxRepository;
use App\Repository\PlnRepository;
use App\Services\BoxNotifier;
use Exception;
use App\Entity\Box;
use App\Entity\BoxStatus;
use App\Services\Lockss\LockssService;
use App\Utilities\LockssClient;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use stdClass;
use Symfony\Component\Console\Command\Command;
use Exception;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Twig\Environment;
class AuStatusCommand extends Command {
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var BoxRepository
*/
private $boxRepository;
/**
* @var PlnRepository
*/
private $plnRepository;
/**
* @var BoxNotifier
*/
private $notifier;
/**
* @var LockssService
*/
private $lockssService;
class AuStatusCommand extends AbstractLockssCommand {
protected static $defaultName = 'lockss:au:status';
public function __construct(LockssService $lockssService, string $name = null) {
parent::__construct($name);
$this->lockssService = $lockssService;
public function __construct(LockssService $lockssService, ParameterBagInterface $params, string $name = null) {
parent::__construct($lockssService, $params, $name);
}
protected function configure() : void {
......@@ -75,47 +34,23 @@ class AuStatusCommand extends Command {
$this->setDescription('Check the status of one or more AUs in a PLN.');
}
/**
* @param $plnIds
*
* @return Pln[]
*/
protected function getPlns($plnIds) {
if( ! $plnIds) {
return $this->plnRepository->findAll();
}
return $this->plnRepository->findBy(['id' => $plnIds]);
}
protected function getStatus(Au $au, Box $box) {
$client = LockssClient::create($box);
$this->lockssService->setClient($client);
return $this->lockssService->auStatus($au);
}
protected function toArray(stdClass $object) {
$array = [];
foreach ($object as $key => $value) {
if ($value instanceof stdClass) {
$array[$key] = $this->toArray($value);
}
else {
$array[$key] = $value;
}
}
return $array;
return $this->lockssService->auStatus($au);
}
protected function execute(InputInterface $input, OutputInterface $output) : int {
$dryRun = $input->getOption('dry-run');
$plnIds = $input->getOption('pln');
foreach($this->getPlns($plnIds) as $pln) {
foreach ($this->getPlns($plnIds) as $pln) {
$boxes = $pln->getActiveBoxes();
foreach($pln->getAus() as $au) {
foreach ($pln->getAus() as $au) {
$auStatus = new AuStatus();
$auStatus->setAu($au);
foreach($boxes as $box) {
foreach ($boxes as $box) {
try {
$status = $this->getStatus($au, $box);
$auStatus->addStatus($box, $this->toArray($status));
......@@ -130,40 +65,4 @@ class AuStatusCommand extends Command {
return 0;
}
/**
* @required
*/
public function setEntityManager(EntityManagerInterface $em) : void {
$this->em = $em;
}
/**
* @required
*/
public function setLogger(LoggerInterface $soapLogger) : void {
$this->logger = $soapLogger;
}
/**
* @required
*/
public function setBoxRepository(BoxRepository $repo) {
$this->boxRepository = $repo;
}
/**
* @required
*/
public function setPlnRepository(PlnRepository $repo) {
$this->plnRepository = $repo;
}
/**
* @required
*/
public function setNotifier(BoxNotifier $notifier) {
$this->notifier = $notifier;
}
}
......@@ -10,66 +10,27 @@ declare(strict_types=1);
namespace App\Command\Lockss;
use App\Entity\Box;
use App\Entity\BoxStatus;
use App\Repository\BoxRepository;
use App\Repository\PlnRepository;
use App\Services\BoxNotifier;
use Exception;
use App\Entity\Box;
use App\Entity\BoxStatus;
use App\Services\Lockss\LockssService;
use App\Utilities\LockssClient;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Psr\Log\LoggerInterface;
use stdClass;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Twig\Environment;
class BoxStatusCommand extends Command {
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var BoxRepository
*/
private $boxRepository;