Merge pull request 'Fixed remotePt. Updated logic uds-service-pool' (#96) from develop into main
Reviewed-on: #96pull/97/head^2
commit
cae05070c8
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Service\UDS;
|
||||
|
||||
use AllowDynamicProperties;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Model\ClientStatus;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
|
@ -70,10 +71,29 @@ class UDSClient
|
|||
continue;
|
||||
}
|
||||
|
||||
$classroom = $servicePoolInfo['lab'];
|
||||
$maxAvailableSeats = $this->getMaxAvailableSeats($classroom);
|
||||
$servicePool['max_srvs'] = $maxAvailableSeats;
|
||||
$labId = $servicePoolInfo['lab'] ?? null;
|
||||
$imageId = $servicePoolInfo['image'] ?? null;
|
||||
|
||||
if (!$labId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$maxAvailableSeats = $this->getMaxAvailableSeats($labId, $imageId);
|
||||
|
||||
if ($maxAvailableSeats === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($maxAvailableSeats === -1) {
|
||||
$this->setLabReserved($labId, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
$servicePool['osmanager_id'] = null;
|
||||
$servicePool['max_srvs'] = $maxAvailableSeats;
|
||||
$servicePool['initial_srvs'] = $maxAvailableSeats;
|
||||
$servicePool['cache_l1_srvs'] = 0;
|
||||
$servicePool['visible'] = $maxAvailableSeats > 0;
|
||||
|
||||
$response = $this->httpClient->request('PUT', $this->udsAPIurl . 'servicespools/' . $servicePool['id'], [
|
||||
'verify_host' => false,
|
||||
|
|
@ -85,6 +105,7 @@ class UDSClient
|
|||
'body' => json_encode($servicePool)
|
||||
]);
|
||||
|
||||
$this->setLabReserved($labId, true);
|
||||
$results[] = json_decode($response->getContent(false), true);
|
||||
}
|
||||
|
||||
|
|
@ -186,17 +207,17 @@ class UDSClient
|
|||
return null;
|
||||
}
|
||||
|
||||
public function getMaxAvailableSeats(int $organizationalUnitId): int
|
||||
public function getMaxAvailableSeats(int $labId, ?int $imageId = null): ?int
|
||||
{
|
||||
$organizationalUnit = $this->entityManager->getRepository(OrganizationalUnit::class)->findOneBy(['id' => $organizationalUnitId]);
|
||||
$organizationalUnit = $this->entityManager->getRepository(OrganizationalUnit::class)->findOneBy(['id' => $labId]);
|
||||
|
||||
if (!$organizationalUnit) {
|
||||
return 0;
|
||||
if (!$organizationalUnit || !$organizationalUnit->isRemotePc()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
$remoteCalendar = $organizationalUnit->getRemoteCalendar();
|
||||
if (!$remoteCalendar || !$remoteCalendar->isAvailable()) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
$totalAvailableClients = 0;
|
||||
|
|
@ -205,12 +226,41 @@ class UDSClient
|
|||
if ($client->isMaintenance()) {
|
||||
continue;
|
||||
}
|
||||
$status = $client->getStatus();
|
||||
|
||||
$clientAvailable = in_array($status, [ClientStatus::OG_LIVE, ClientStatus::WINDOWS, ClientStatus::LINUX]);
|
||||
$totalAvailableClients += $clientAvailable ? 1 : 0;
|
||||
if (!in_array($client->getStatus(), [ClientStatus::OG_LIVE, ClientStatus::WINDOWS, ClientStatus::LINUX])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($imageId !== null && !$this->clientHasImage($client, $imageId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$totalAvailableClients++;
|
||||
}
|
||||
|
||||
return $totalAvailableClients;
|
||||
}
|
||||
|
||||
private function clientHasImage(Client $client, int $imageId): bool
|
||||
{
|
||||
foreach ($client->getPartitions() as $partition) {
|
||||
$iir = $partition->getImage();
|
||||
if ($iir && $iir->getImage() && $iir->getImage()->getId() === $imageId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function setLabReserved(int $labId, bool $reserved): void
|
||||
{
|
||||
$organizationalUnit = $this->entityManager->getRepository(OrganizationalUnit::class)->findOneBy(['id' => $labId]);
|
||||
if (!$organizationalUnit) {
|
||||
return;
|
||||
}
|
||||
|
||||
$organizationalUnit->setReserved($reserved);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue