getClient()->getIp()) { throw new ValidatorException('IP is required'); } $partitionInfo = json_decode($image->getPartitionInfo(), true); /** @var Client $client */ $client = $input->client->getEntity(); /** @var Partition $partition */ $partition = $input->partition->getEntity(); $method = match ($input->method) { DeployMethodTypes::MULTICAST_UFTP_DIRECT, DeployMethodTypes::MULTICAST_UDPCAST_DIRECT, => 'multicast-direct', DeployMethodTypes::MULTICAST, DeployMethodTypes::MULTICAST_UFTP, DeployMethodTypes::MULTICAST_UDPCAST => 'multicast', DeployMethodTypes::UNICAST_DIRECT => 'unicast-direct', DeployMethodTypes::UNICAST => 'unicast', DeployMethodTypes::TORRENT => 'torrent', default => throw new ValidatorException('Invalid method'), }; $ptcMulticastValue = "$method $input->mcastPort:$input->mcastMode:$input->mcastIp:$input->mcastSpeed:$input->maxClients:$input->maxTime"; $ptcTorrentValue = "$method $input->p2pMode:$input->p2pTime"; $ptcUnicastValue = $method; $ptcValue = match ($input->method) { DeployMethodTypes::MULTICAST, DeployMethodTypes::MULTICAST_UFTP, DeployMethodTypes::MULTICAST_UFTP_DIRECT, DeployMethodTypes::MULTICAST_UDPCAST, DeployMethodTypes::MULTICAST_UDPCAST_DIRECT => $ptcMulticastValue, DeployMethodTypes::UNICAST, DeployMethodTypes::UNICAST_DIRECT => $ptcUnicastValue, DeployMethodTypes::TORRENT => $ptcTorrentValue, default => throw new ValidatorException('Invalid method'), }; $data = [ 'dsk' => (string) $partition->getDiskNumber(), 'par' => (string) $partition->getPartitionNumber(), 'ifs' => "1", 'idi' => $image->getUuid(), 'nci' => $image->getName(), 'ipr' => $image->getRepository()->getIp(), 'nfn' => 'RestaurarImagen', 'ptc' => $ptcValue, 'ids' => '0' ]; try { $response = $this->httpClient->request('POST', 'https://'.$client->getIp().':8000/CloningEngine/RestaurarImagen', [ 'verify_peer' => false, 'verify_host' => false, 'headers' => [ 'Content-Type' => 'application/json', ], 'json' => $data, ]); $this->logger->info('Deploying image', ['image' => $image->getId()]); } catch (TransportExceptionInterface $e) { $this->logger->error('Error deploying image', ['image' => $image->getId(), 'error' => $e->getMessage()]); return new JsonResponse( data: ['error' => $e->getMessage()], status: Response::HTTP_INTERNAL_SERVER_ERROR ); } $jobId = json_decode($response->getContent(), true)['job_id']; $client->setStatus(ClientStatus::BUSY); $this->entityManager->persist($client); $this->entityManager->flush(); return $jobId; } }