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

Commit

Permalink
enh(resources): fetch ack / dt in detail only if needed (#11888)
Browse files Browse the repository at this point in the history
* enh(resources): fetch ack / dt in detail only if needed

* Update src/Core/Application/RealTime/UseCase/FindMetaService/FindMetaService.php

Co-authored-by: TamazC <103252125+TamazC@users.noreply.github.com>
  • Loading branch information
2 people authored and tuntoja committed Oct 12, 2022
1 parent 5a2395a commit baf2d11
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 11 deletions.
12 changes: 10 additions & 2 deletions src/Core/Application/RealTime/UseCase/FindHost/FindHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ public function __invoke(int $hostId, FindHostPresenterInterface $presenter): vo
$host->addHostgroup($hostgroup);
}

$acknowledgement = $host->isAcknowledged() === true
? $this->acknowledgementRepository->findOnGoingAcknowledgementByHostId($hostId)
: null;

$downtimes = $host->isInDowntime() === true
? $this->downtimeRepository->findOnGoingDowntimesByHostId($hostId)
: [];

/**
* Obfuscate the passwords in Host commandLine
* @todo Re-write this code when monitoring repository will be migrated to new architecture
Expand All @@ -111,8 +119,8 @@ public function __invoke(int $hostId, FindHostPresenterInterface $presenter): vo
$presenter->present(
$this->createResponse(
$host,
$this->downtimeRepository->findOnGoingDowntimesByHostId($hostId),
$this->acknowledgementRepository->findOnGoingAcknowledgementByHostId($hostId)
$downtimes,
$acknowledgement
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,20 @@ public function __invoke(
$hostId = $metaService->getHostId();
$serviceId = $metaService->getServiceId();

$acknowledgement = $metaService->isAcknowledged() === true
? $this->acknowledgementRepository->findOnGoingAcknowledgementByHostIdAndServiceId($hostId, $serviceId)
: null;

$downtimes = $metaService->isInDowntime() === true
? $this->downtimeRepository->findOnGoingDowntimesByHostIdAndServiceId($hostId, $serviceId)
: [];

$presenter->present(
$this->createResponse(
$metaService,
$metaServiceConfiguration,
$this->downtimeRepository->findOnGoingDowntimesByHostIdAndServiceId($hostId, $serviceId),
$this->acknowledgementRepository->findOnGoingAcknowledgementByHostIdAndServiceId($hostId, $serviceId)
$downtimes,
$acknowledgement
)
);
}
Expand Down
13 changes: 11 additions & 2 deletions src/Core/Application/RealTime/UseCase/FindService/FindService.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,20 @@ public function __invoke(
*/
$service->setCommandLine($this->obfuscatePasswordInServiceCommandLine($service));


$acknowledgement = $service->isAcknowledged() === true
? $this->acknowledgementRepository->findOnGoingAcknowledgementByHostIdAndServiceId($hostId, $serviceId)
: null;

$downtimes = $service->isInDowntime() === true
? $this->downtimeRepository->findOnGoingDowntimesByHostIdAndServiceId($hostId, $serviceId)
: [];

$presenter->present(
$this->createResponse(
$service,
$this->downtimeRepository->findOnGoingDowntimesByHostIdAndServiceId($hostId, $serviceId),
$this->acknowledgementRepository->findOnGoingAcknowledgementByHostIdAndServiceId($hostId, $serviceId),
$downtimes,
$acknowledgement,
$host
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ public function testFindHostAsAdmin(): void
/**
* @var Host
*/
$host = HostTest::createHostModel();
$host = (HostTest::createHostModel())
->setIsAcknowledged(true)
->setIsInDowntime(true);

$this->repository
->expects($this->once())
Expand Down Expand Up @@ -308,7 +310,9 @@ public function testFindHostAsNonAdmin(): void
/**
* @var Host
*/
$host = HostTest::createHostModel();
$host = (HostTest::createHostModel())
->setIsAcknowledged(true)
->setIsInDowntime(true);

$this->repository
->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ public function testMetaServiceFound(): void
->setAdmin(false);

$metaServiceConfiguration = MetaServiceConfigurationTest::createMetaServiceModel();
$metaService = MetaServiceTest::createMetaServiceModel();
$metaService = (MetaServiceTest::createMetaServiceModel())
->setIsAcknowledged(true)
->setIsInDowntime(true);

$downtimes[] = (new Downtime(1, 1, 10))
->setCancelled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ public function testFindServiceAsAdmin(): void
/**
* @var Service
*/
$service = ServiceTest::createServiceModel();
$service = (ServiceTest::createServiceModel())
->setIsAcknowledged(true)
->setIsInDowntime(true);

$servicegroup = new Servicegroup(1, 'ALL');

$this->hostRepository
Expand Down Expand Up @@ -420,7 +423,10 @@ public function testFindServiceAsNonAdmin(): void
);

$host = HostTest::createHostModel();
$service = ServiceTest::createServiceModel();
$service = (ServiceTest::createServiceModel())
->setIsAcknowledged(true)
->setIsInDowntime(true);

$servicegroup = new Servicegroup(1, 'ALL');

$this->hostRepository
Expand Down

0 comments on commit baf2d11

Please sign in to comment.