From 5dc8ffae8cd8de8b50512a9c8e0ff1cf7008d766 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 29 Oct 2024 16:56:23 +0100 Subject: [PATCH 01/26] refs #1083. New entity ImageRepository --- config/api_platform/ImageRepository.yaml | 32 +++++++ migrations/Version20241029112630.php | 31 +++++++ migrations/Version20241029145213.php | 35 ++++++++ src/Dto/Input/ImageRepositoryInput.php | 88 +++++++++++++++++++ src/Dto/Output/ImageRepositoryOutput.php | 8 ++ src/Entity/Image.php | 16 ++++ src/Entity/ImageRepository.php | 86 ++++++++++++++++++ src/Repository/ImageRepository.php | 16 +--- .../Processor/ImageRepositoryProcessor.php | 8 ++ .../Provider/ImageRepositoryProvider.php | 8 ++ 10 files changed, 315 insertions(+), 13 deletions(-) create mode 100644 config/api_platform/ImageRepository.yaml create mode 100644 migrations/Version20241029112630.php create mode 100644 migrations/Version20241029145213.php create mode 100644 src/Dto/Input/ImageRepositoryInput.php create mode 100644 src/Dto/Output/ImageRepositoryOutput.php create mode 100644 src/Entity/ImageRepository.php create mode 100644 src/State/Processor/ImageRepositoryProcessor.php create mode 100644 src/State/Provider/ImageRepositoryProvider.php diff --git a/config/api_platform/ImageRepository.yaml b/config/api_platform/ImageRepository.yaml new file mode 100644 index 0000000..35d8d13 --- /dev/null +++ b/config/api_platform/ImageRepository.yaml @@ -0,0 +1,32 @@ +resources: + App\Entity\Repository: + processor: App\State\Processor\RepositoryProcessor + input: App\Dto\Input\RepositoryInput + output: App\Dto\Output\RepositoryOutput + orderBy: + RepositoryNumber: 'ASC' + normalizationContext: + groups: ['default', 'repository:read'] + denormalizationContext: + groups: ['repository:write'] + operations: + ApiPlatform\Metadata\GetCollection: + provider: App\State\Provider\RepositoryProvider + filters: + - 'api_platform.filter.repository.order' + - 'api_platform.filter.repository.search' + ApiPlatform\Metadata\Get: + provider: App\State\Provider\RepositoryProvider + ApiPlatform\Metadata\Put: + provider: App\State\Provider\RepositoryProvider + ApiPlatform\Metadata\Patch: + provider: App\State\Provider\RepositoryProvider + ApiPlatform\Metadata\Post: ~ + ApiPlatform\Metadata\Delete: ~ + +properties: + App\Entity\Repository: + id: + identifier: false + uuid: + identifier: true \ No newline at end of file diff --git a/migrations/Version20241029112630.php b/migrations/Version20241029112630.php new file mode 100644 index 0000000..49f6115 --- /dev/null +++ b/migrations/Version20241029112630.php @@ -0,0 +1,31 @@ +addSql('CREATE TABLE image_repository (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, ip VARCHAR(255) NOT NULL, comments VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_302040FBD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE image_repository'); + } +} diff --git a/migrations/Version20241029145213.php b/migrations/Version20241029145213.php new file mode 100644 index 0000000..f0c874a --- /dev/null +++ b/migrations/Version20241029145213.php @@ -0,0 +1,35 @@ +addSql('ALTER TABLE image ADD repository_id INT NOT NULL'); + $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F50C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)'); + $this->addSql('CREATE INDEX IDX_C53D045F50C9D4F7 ON image (repository_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F50C9D4F7'); + $this->addSql('DROP INDEX IDX_C53D045F50C9D4F7 ON image'); + $this->addSql('ALTER TABLE image DROP repository_id'); + } +} diff --git a/src/Dto/Input/ImageRepositoryInput.php b/src/Dto/Input/ImageRepositoryInput.php new file mode 100644 index 0000000..a7b4166 --- /dev/null +++ b/src/Dto/Input/ImageRepositoryInput.php @@ -0,0 +1,88 @@ +diskNumber = $partition->getDiskNumber(); + $this->partitionNumber = $partition->getPartitionNumber(); + $this->partitionCode = $partition->getPartitionCode(); + $this->size = $partition->getSize(); + $this->cacheContent = $partition->getCacheContent(); + $this->filesystem = $partition->getFilesystem(); + + if ($partition->getOperativeSystem()) { + $this->operativeSystem = new OperativeSystemOutput($partition->getOperativeSystem()); + } + + if ($partition->getClient()) { + $this->client = new ClientOutput($partition->getClient()); + } + $this->memoryUsage = $partition->getMemoryUsage(); + + if ($partition->getImage()) { + $this->image = new ImageOutput($partition->getImage()); + } + } + + public function createOrUpdateEntity(?Partition $partition = null): Partition + { + if (!$partition) { + $partition = new Partition(); + } + + $partition->setDiskNumber($this->diskNumber); + $partition->setPartitionNumber($this->partitionNumber); + $partition->setPartitionCode($this->partitionCode); + $partition->setSize($this->size * 1024); + $partition->setCacheContent($this->cacheContent); + $partition->setFilesystem($this->filesystem); + + if ($this->operativeSystem) { + $partition->setOperativeSystem($this->operativeSystem->getEntity()); + } + $partition->setClient($this->client->getEntity()); + $partition->setMemoryUsage($this->memoryUsage * 100); + + if ($this->image) { + $partition->setImage($this->image->getEntity()); + } + + return $partition; + } +} \ No newline at end of file diff --git a/src/Dto/Output/ImageRepositoryOutput.php b/src/Dto/Output/ImageRepositoryOutput.php new file mode 100644 index 0000000..1ede3f3 --- /dev/null +++ b/src/Dto/Output/ImageRepositoryOutput.php @@ -0,0 +1,8 @@ +repository; + } + + public function setRepository(?\App\Entity\ImageRepository $repository): static + { + $this->repository = $repository; + + return $this; + } } diff --git a/src/Entity/ImageRepository.php b/src/Entity/ImageRepository.php new file mode 100644 index 0000000..400890e --- /dev/null +++ b/src/Entity/ImageRepository.php @@ -0,0 +1,86 @@ + + */ + #[ORM\OneToMany(mappedBy: 'repository', targetEntity: Image::class)] + private Collection $images; + + public function __construct() + { + parent::__construct(); + $this->images = new ArrayCollection(); + } + + public function getIp(): ?string + { + return $this->ip; + } + + public function setIp(string $ip): static + { + $this->ip = $ip; + + return $this; + } + + public function getComments(): ?string + { + return $this->comments; + } + + public function setComments(?string $comments): static + { + $this->comments = $comments; + + return $this; + } + + /** + * @return Collection + */ + public function getImages(): Collection + { + return $this->images; + } + + public function addImage(Image $image): static + { + if (!$this->images->contains($image)) { + $this->images->add($image); + $image->setRepository($this); + } + + return $this; + } + + public function removeImage(Image $image): static + { + if ($this->images->removeElement($image)) { + // set the owning side to null (unless already changed) + if ($image->getRepository() === $this) { + $image->setRepository(null); + } + } + + return $this; + } +} diff --git a/src/Repository/ImageRepository.php b/src/Repository/ImageRepository.php index b20b95b..3e6ea6c 100644 --- a/src/Repository/ImageRepository.php +++ b/src/Repository/ImageRepository.php @@ -2,17 +2,7 @@ namespace App\Repository; -use App\Entity\Image; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; - -/** - * @extends ServiceEntityRepository - */ -class ImageRepository extends AbstractRepository +class ImageRepository { - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Image::class); - } -} + +} \ No newline at end of file diff --git a/src/State/Processor/ImageRepositoryProcessor.php b/src/State/Processor/ImageRepositoryProcessor.php new file mode 100644 index 0000000..a3afb03 --- /dev/null +++ b/src/State/Processor/ImageRepositoryProcessor.php @@ -0,0 +1,8 @@ + Date: Tue, 29 Oct 2024 16:57:30 +0100 Subject: [PATCH 02/26] refs #1081. API ImageRepository. Edit Image API with this --- config/api_platform/ImageRepository.yaml | 20 ++--- config/api_platform/Partition.yaml | 2 + config/api_platform/SoftwareProfile.yaml | 2 +- config/services.yaml | 5 ++ src/Dto/Input/ImageInput.php | 10 +++ src/Dto/Input/ImageRepositoryInput.php | 82 ++++++------------- src/Dto/Input/PartitionInput.php | 5 +- src/Dto/Output/ImageOutput.php | 4 + src/Dto/Output/ImageRepositoryOutput.php | 32 +++++++- src/Dto/Output/OrganizationalUnitOutput.php | 2 +- src/Repository/ImageRepository.php | 16 +++- src/Repository/ImageRepositoryRepository.php | 18 ++++ .../Processor/ImageRepositoryProcessor.php | 66 ++++++++++++++- .../Provider/ImageRepositoryProvider.php | 71 +++++++++++++++- 14 files changed, 251 insertions(+), 84 deletions(-) create mode 100644 src/Repository/ImageRepositoryRepository.php diff --git a/config/api_platform/ImageRepository.yaml b/config/api_platform/ImageRepository.yaml index 35d8d13..e6cb84c 100644 --- a/config/api_platform/ImageRepository.yaml +++ b/config/api_platform/ImageRepository.yaml @@ -1,31 +1,29 @@ resources: - App\Entity\Repository: - processor: App\State\Processor\RepositoryProcessor - input: App\Dto\Input\RepositoryInput - output: App\Dto\Output\RepositoryOutput - orderBy: - RepositoryNumber: 'ASC' + App\Entity\ImageRepository: + processor: App\State\Processor\ImageRepositoryProcessor + input: App\Dto\Input\ImageRepositoryInput + output: App\Dto\Output\ImageRepositoryOutput normalizationContext: groups: ['default', 'repository:read'] denormalizationContext: groups: ['repository:write'] operations: ApiPlatform\Metadata\GetCollection: - provider: App\State\Provider\RepositoryProvider + provider: App\State\Provider\ImageRepositoryProvider filters: - 'api_platform.filter.repository.order' - 'api_platform.filter.repository.search' ApiPlatform\Metadata\Get: - provider: App\State\Provider\RepositoryProvider + provider: App\State\Provider\ImageRepositoryProvider ApiPlatform\Metadata\Put: - provider: App\State\Provider\RepositoryProvider + provider: App\State\Provider\ImageRepositoryProvider ApiPlatform\Metadata\Patch: - provider: App\State\Provider\RepositoryProvider + provider: App\State\Provider\ImageRepositoryProvider ApiPlatform\Metadata\Post: ~ ApiPlatform\Metadata\Delete: ~ properties: - App\Entity\Repository: + App\Entity\ImageRepository: id: identifier: false uuid: diff --git a/config/api_platform/Partition.yaml b/config/api_platform/Partition.yaml index 7d09114..3103413 100644 --- a/config/api_platform/Partition.yaml +++ b/config/api_platform/Partition.yaml @@ -3,6 +3,8 @@ resources: processor: App\State\Processor\PartitionProcessor input: App\Dto\Input\PartitionInput output: App\Dto\Output\PartitionOutput + orderBy: + partitionNumber: 'ASC' normalizationContext: groups: ['default', 'partition:read'] denormalizationContext: diff --git a/config/api_platform/SoftwareProfile.yaml b/config/api_platform/SoftwareProfile.yaml index 899cad8..ff08333 100644 --- a/config/api_platform/SoftwareProfile.yaml +++ b/config/api_platform/SoftwareProfile.yaml @@ -17,7 +17,7 @@ resources: ApiPlatform\Metadata\Get: provider: App\State\Provider\SoftwareProfileProvider normalizationContext: - groups: ['software-profile:item:get', 'software-profile:read:collection:short'] + groups: ['software-profile:read', 'software-profile:item:get', 'software-profile:read:collection:short'] ApiPlatform\Metadata\Put: provider: App\State\Provider\SoftwareProfileProvider ApiPlatform\Metadata\Patch: diff --git a/config/services.yaml b/config/services.yaml index 294e4b8..62e58a2 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -152,3 +152,8 @@ services: bind: $collectionProvider: '@api_platform.doctrine.orm.state.collection_provider' $itemProvider: '@api_platform.doctrine.orm.state.item_provider' + + App\State\Provider\ImageRepositoryProvider: + bind: + $collectionProvider: '@api_platform.doctrine.orm.state.collection_provider' + $itemProvider: '@api_platform.doctrine.orm.state.item_provider' diff --git a/src/Dto/Input/ImageInput.php b/src/Dto/Input/ImageInput.php index c1b2e84..b994e9e 100644 --- a/src/Dto/Input/ImageInput.php +++ b/src/Dto/Input/ImageInput.php @@ -4,6 +4,7 @@ namespace App\Dto\Input; use ApiPlatform\Metadata\ApiProperty; use App\Dto\Output\ClientOutput; +use App\Dto\Output\ImageRepositoryOutput; use App\Dto\Output\OrganizationalUnitOutput; use App\Dto\Output\SoftwareProfileOutput; use App\Entity\Image; @@ -50,6 +51,10 @@ final class ImageInput #[ApiProperty(description: 'The software profile of the image')] public ?SoftwareProfileOutput $softwareProfile = null; + #[Groups(['image:write'])] + #[ApiProperty(description: 'The image repository of the image')] + public ?ImageRepositoryOutput $imageRepository = null; + #[Groups(['image:write'])] public ?bool $remotePc = false; @@ -72,6 +77,10 @@ final class ImageInput if ($image->getSoftwareProfile()) { $this->softwareProfile = new SoftwareProfileOutput($image->getSoftwareProfile()); } + + if ($image->getRepository()) { + $this->imageRepository = new ImageRepositoryOutput($image->getRepository()); + } } public function createOrUpdateEntity(?Image $image = null): Image @@ -89,6 +98,7 @@ final class ImageInput $image->setInfo($this->info); $image->setSize($this->size); $image->setSoftwareProfile($this->softwareProfile->getEntity()); + $image->setRepository($this->imageRepository->getEntity()); $image->setRemotePc($this->remotePc); return $image; diff --git a/src/Dto/Input/ImageRepositoryInput.php b/src/Dto/Input/ImageRepositoryInput.php index a7b4166..e2ea309 100644 --- a/src/Dto/Input/ImageRepositoryInput.php +++ b/src/Dto/Input/ImageRepositoryInput.php @@ -8,81 +8,49 @@ use App\Dto\Output\ImageOutput; use App\Dto\Output\OperativeSystemOutput; use App\Dto\Output\OrganizationalUnitOutput; use App\Entity\HardwareProfile; +use App\Entity\ImageRepository; use App\Entity\Menu; use App\Entity\Partition; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; -final class RepositoryInput +final class ImageRepositoryInput { - #[Groups(['partition:write'])] - #[ApiProperty(description: 'The disk number of the partition', example: 1)] - public ?int $diskNumber = null; + #[Groups(['repository:write'])] + #[ApiProperty(description: 'The name of the repository', example: "Repository 1")] + public ?string $name = null; - #[Groups(['partition:write'])] - #[ApiProperty(description: 'The number of the partition', example: 1)] - public ?int $partitionNumber = null; - - #[Groups(['partition:write'])] - #[ApiProperty(description: 'The code of the partition', example: "code")] - public ?string $partitionCode = null; - - #[Assert\NotNull()] - #[Groups(['partition:write'])] - #[ApiProperty(description: 'The size of the partition', example: 100)] - public ?int $size = null; + #[Groups(['repository:write'])] + #[ApiProperty(description: 'The IP of the repository', example: "")] + public ?string $ip = null; - public function __construct(?Repository $partition = null) + #[Groups(['repository:write'])] + #[ApiProperty(description: 'The comments of the repository', example: "Repository 1 comments")] + public ?string $comments = null; + + + public function __construct(?ImageRepository $repository = null) { - if (!$partition) { + if (!$repository) { return; } - $this->diskNumber = $partition->getDiskNumber(); - $this->partitionNumber = $partition->getPartitionNumber(); - $this->partitionCode = $partition->getPartitionCode(); - $this->size = $partition->getSize(); - $this->cacheContent = $partition->getCacheContent(); - $this->filesystem = $partition->getFilesystem(); - - if ($partition->getOperativeSystem()) { - $this->operativeSystem = new OperativeSystemOutput($partition->getOperativeSystem()); - } - - if ($partition->getClient()) { - $this->client = new ClientOutput($partition->getClient()); - } - $this->memoryUsage = $partition->getMemoryUsage(); - - if ($partition->getImage()) { - $this->image = new ImageOutput($partition->getImage()); - } + $this->name = $repository->getName(); + $this->ip = $repository->getIp(); + $this->comments = $repository->getComments(); } - public function createOrUpdateEntity(?Partition $partition = null): Partition + public function createOrUpdateEntity(?ImageRepository $repository = null): ImageRepository { - if (!$partition) { - $partition = new Partition(); + if (!$repository) { + $repository = new ImageRepository(); } - $partition->setDiskNumber($this->diskNumber); - $partition->setPartitionNumber($this->partitionNumber); - $partition->setPartitionCode($this->partitionCode); - $partition->setSize($this->size * 1024); - $partition->setCacheContent($this->cacheContent); - $partition->setFilesystem($this->filesystem); + $repository->setName($this->name); + $repository->setIp($this->ip); + $repository->setComments($this->comments); - if ($this->operativeSystem) { - $partition->setOperativeSystem($this->operativeSystem->getEntity()); - } - $partition->setClient($this->client->getEntity()); - $partition->setMemoryUsage($this->memoryUsage * 100); - - if ($this->image) { - $partition->setImage($this->image->getEntity()); - } - - return $partition; + return $repository; } } \ No newline at end of file diff --git a/src/Dto/Input/PartitionInput.php b/src/Dto/Input/PartitionInput.php index 2e7d366..635149f 100644 --- a/src/Dto/Input/PartitionInput.php +++ b/src/Dto/Input/PartitionInput.php @@ -101,10 +101,7 @@ final class PartitionInput $partition->setOperativeSystem($this->operativeSystem->getEntity()); } $partition->setClient($this->client->getEntity()); - - if ($this->memoryUsage) { - $partition->setMemoryUsage($this->memoryUsage * 100); - } + $partition->setMemoryUsage($this->memoryUsage * 100); if ($this->image) { $partition->setImage($this->image->getEntity()); diff --git a/src/Dto/Output/ImageOutput.php b/src/Dto/Output/ImageOutput.php index fe91429..6569676 100644 --- a/src/Dto/Output/ImageOutput.php +++ b/src/Dto/Output/ImageOutput.php @@ -39,6 +39,9 @@ final class ImageOutput extends AbstractOutput #[Groups(['image:read'])] public ?SoftwareProfileOutput $softwareProfile = null; + #[Groups(['image:read'])] + public ?ImageRepositoryOutput $imageRepository = null; + #[Groups(['image:read'])] public \DateTime $createdAt; @@ -58,6 +61,7 @@ final class ImageOutput extends AbstractOutput $this->info = $image->getInfo(); $this->size = $image->getSize(); $this->softwareProfile = $image->getSoftwareProfile() ? new SoftwareProfileOutput($image->getSoftwareProfile()) : null; + $this->imageRepository = $image->getRepository() ? new ImageRepositoryOutput($image->getRepository()) : null; $this->remotePc = $image->isRemotePc(); $this->createdAt = $image->getCreatedAt(); $this->createdBy = $image->getCreatedBy(); diff --git a/src/Dto/Output/ImageRepositoryOutput.php b/src/Dto/Output/ImageRepositoryOutput.php index 1ede3f3..a940da1 100644 --- a/src/Dto/Output/ImageRepositoryOutput.php +++ b/src/Dto/Output/ImageRepositoryOutput.php @@ -2,7 +2,37 @@ namespace App\Dto\Output; -class ImageRepositoryOutput +use ApiPlatform\Metadata\Get; +use App\Entity\ImageRepository; +use Symfony\Component\Serializer\Annotation\Groups; + +#[Get(shortName: 'ImageRepository')] +class ImageRepositoryOutput extends AbstractOutput { + #[Groups(['repository:read', 'image:read'])] + public ?string $name = ''; + + #[Groups(['repository:read'])] + public ?string $ip = ''; + + #[Groups(['repository:read'])] + public ?string $comments = ''; + + #[Groups(['repository:read'])] + public \DateTime $createdAt; + + #[Groups(['repository:read'])] + public ?string $createdBy = null; + + public function __construct(ImageRepository $imageRepository) + { + parent::__construct($imageRepository); + + $this->name = $imageRepository->getName(); + $this->ip = $imageRepository->getIp(); + $this->comments = $imageRepository->getComments(); + $this->createdAt = $imageRepository->getCreatedAt(); + $this->createdBy = $imageRepository->getCreatedBy(); + } } \ No newline at end of file diff --git a/src/Dto/Output/OrganizationalUnitOutput.php b/src/Dto/Output/OrganizationalUnitOutput.php index 9d9ca7c..f1daa30 100644 --- a/src/Dto/Output/OrganizationalUnitOutput.php +++ b/src/Dto/Output/OrganizationalUnitOutput.php @@ -11,7 +11,7 @@ use Symfony\Component\Serializer\Annotation\Groups; #[Get(shortName: 'OrganizationalUnit')] final class OrganizationalUnitOutput extends AbstractOutput { - #[Groups(['organizational-unit:read', "client:read", "user:read", 'organizational-unit:read:collection:short'])] + #[Groups(['organizational-unit:read', "client:read", "user:read", 'organizational-unit:read:collection:short', 'software-profile:read'])] public string $name; #[Groups(['organizational-unit:read'])] diff --git a/src/Repository/ImageRepository.php b/src/Repository/ImageRepository.php index 3e6ea6c..b20b95b 100644 --- a/src/Repository/ImageRepository.php +++ b/src/Repository/ImageRepository.php @@ -2,7 +2,17 @@ namespace App\Repository; -class ImageRepository -{ +use App\Entity\Image; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; -} \ No newline at end of file +/** + * @extends ServiceEntityRepository + */ +class ImageRepository extends AbstractRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Image::class); + } +} diff --git a/src/Repository/ImageRepositoryRepository.php b/src/Repository/ImageRepositoryRepository.php new file mode 100644 index 0000000..ba83114 --- /dev/null +++ b/src/Repository/ImageRepositoryRepository.php @@ -0,0 +1,18 @@ + + */ +class ImageRepositoryRepository extends AbstractRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, ImageRepository::class); + } +} diff --git a/src/State/Processor/ImageRepositoryProcessor.php b/src/State/Processor/ImageRepositoryProcessor.php index a3afb03..a107ce7 100644 --- a/src/State/Processor/ImageRepositoryProcessor.php +++ b/src/State/Processor/ImageRepositoryProcessor.php @@ -2,7 +2,67 @@ namespace App\State\Processor; -class ImageRepositoryProcessor -{ +use ApiPlatform\Metadata\Delete; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\Metadata\Patch; +use ApiPlatform\Metadata\Post; +use ApiPlatform\Metadata\Put; +use ApiPlatform\State\ProcessorInterface; +use ApiPlatform\Validator\ValidatorInterface; +use App\Dto\Input\ImageRepositoryInput; +use App\Dto\Output\ImageRepositoryOutput; +use App\Repository\ImageRepositoryRepository; -} \ No newline at end of file +readonly class ImageRepositoryProcessor implements ProcessorInterface +{ + public function __construct( + private ImageRepositoryRepository $imageRepository, + private ValidatorInterface $validator + ) + { + } + + /** + * @throws \Exception + */ + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ImageRepositoryOutput|null + { + switch ($operation){ + case $operation instanceof Post: + case $operation instanceof Put: + case $operation instanceof Patch: + return $this->processCreateOrUpdate($data, $operation, $uriVariables, $context); + case $operation instanceof Delete: + return $this->processDelete($data, $operation, $uriVariables, $context); + } + } + + /** + * @throws \Exception + */ + private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): ImageRepositoryOutput + { + if (!($data instanceof ImageRepositoryInput)) { + throw new \Exception(sprintf('data is not instance of %s', ImageRepositoryInput::class)); + } + + $entity = null; + if (isset($uriVariables['uuid'])) { + $entity = $this->imageRepository->findOneByUuid($uriVariables['uuid']); + } + + $repository = $data->createOrUpdateEntity($entity); + $this->validator->validate($repository); + $this->imageRepository->save($repository); + + return new ImageRepositoryOutput($repository); + } + + private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null + { + $user = $this->imageRepository->findOneByUuid($uriVariables['uuid']); + $this->imageRepository->delete($user); + + return null; + } +} diff --git a/src/State/Provider/ImageRepositoryProvider.php b/src/State/Provider/ImageRepositoryProvider.php index 8ae18b3..4230b45 100644 --- a/src/State/Provider/ImageRepositoryProvider.php +++ b/src/State/Provider/ImageRepositoryProvider.php @@ -2,7 +2,72 @@ namespace App\State\Provider; -class ImageRepositoryProvider -{ +use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\Metadata\Patch; +use ApiPlatform\Metadata\Put; +use ApiPlatform\State\Pagination\TraversablePaginator; +use ApiPlatform\State\ProviderInterface; +use App\Dto\Input\ImageInput; +use App\Dto\Input\ImageRepositoryInput; +use App\Dto\Output\ImageOutput; +use App\Dto\Output\ImageRepositoryOutput; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -} \ No newline at end of file +readonly class ImageRepositoryProvider implements ProviderInterface +{ + public function __construct( + private ProviderInterface $collectionProvider, + private ProviderInterface $itemProvider + ) + { + } + + public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null + { + switch ($operation){ + case $operation instanceof GetCollection: + return $this->provideCollection($operation, $uriVariables, $context); + case $operation instanceof Patch: + case $operation instanceof Put: + return $this->provideInput($operation, $uriVariables, $context); + case $operation instanceof Get: + return $this->provideItem($operation, $uriVariables, $context); + } + } + + private function provideCollection(Operation $operation, array $uriVariables = [], array $context = []): object + { + $paginator = $this->collectionProvider->provide($operation, $uriVariables, $context); + + $items = new \ArrayObject(); + foreach ($paginator->getIterator() as $item){ + $items[] = new ImageRepositoryOutput($item); + } + + return new TraversablePaginator($items, $paginator->getCurrentPage(), $paginator->getItemsPerPage(), $paginator->getTotalItems()); + } + + public function provideItem(Operation $operation, array $uriVariables = [], array $context = []): object|array|null + { + $item = $this->itemProvider->provide($operation, $uriVariables, $context); + + if (!$item) { + throw new NotFoundHttpException('Image not found'); + } + + return new ImageRepositoryOutput($item); + } + + public function provideInput(Operation $operation, array $uriVariables = [], array $context = []): object|array|null + { + if (isset($uriVariables['uuid'])) { + $item = $this->itemProvider->provide($operation, $uriVariables, $context); + + return $item !== null ? new ImageRepositoryInput($item) : null; + } + + return new ImageRepositoryInput(); + } +} From 5a7afc23b9ef416412247fe9fcc7ae10309b0146 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 29 Oct 2024 17:13:10 +0100 Subject: [PATCH 03/26] refs #1081. API ImageRepository. Edit Image API with this --- src/Factory/ImageFactory.php | 1 + src/Factory/ImageRepositoryFactory.php | 56 ++++++++++++++++++++++++++ tests/Functional/ImageTest.php | 6 +++ 3 files changed, 63 insertions(+) create mode 100644 src/Factory/ImageRepositoryFactory.php diff --git a/src/Factory/ImageFactory.php b/src/Factory/ImageFactory.php index 52822df..d0a59fb 100644 --- a/src/Factory/ImageFactory.php +++ b/src/Factory/ImageFactory.php @@ -38,6 +38,7 @@ final class ImageFactory extends ModelFactory 'path' => self::faker()->text(255), 'size' => self::faker()->randomNumber(), 'softwareProfile' => SoftwareProfileFactory::new(), + 'repository' => ImageRepositoryFactory::new(), 'updatedAt' => self::faker()->dateTime(), 'remotePc' => self::faker()->boolean(), ]; diff --git a/src/Factory/ImageRepositoryFactory.php b/src/Factory/ImageRepositoryFactory.php new file mode 100644 index 0000000..9308fb9 --- /dev/null +++ b/src/Factory/ImageRepositoryFactory.php @@ -0,0 +1,56 @@ + + */ +final class ImageRepositoryFactory extends ModelFactory +{ + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services + * + * @todo inject services if required + */ + public function __construct() + { + parent::__construct(); + } + + public static function getClass(): string + { + return ImageRepository::class; + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories + * + * @todo add your default values here + */ + protected function getDefaults(): array + { + return [ + 'createdAt' => self::faker()->dateTime(), + 'ip' => self::faker()->text(255), + 'name' => self::faker()->text(255), + 'updatedAt' => self::faker()->dateTime() + ]; + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization + */ + protected function initialize(): self + { + return $this + // ->afterInstantiate(function(ImageRepository $imageRepository): void {}) + ; + } +} diff --git a/tests/Functional/ImageTest.php b/tests/Functional/ImageTest.php index eee855f..6f0e399 100644 --- a/tests/Functional/ImageTest.php +++ b/tests/Functional/ImageTest.php @@ -4,10 +4,12 @@ namespace Functional; use App\Entity\Client; use App\Entity\Image; +use App\Entity\ImageRepository; use App\Entity\OrganizationalUnit; use App\Entity\SoftwareProfile; use App\Factory\ClientFactory; use App\Factory\ImageFactory; +use App\Factory\ImageRepositoryFactory; use App\Factory\OrganizationalUnitFactory; use App\Factory\SoftwareProfileFactory; use App\Factory\UserFactory; @@ -67,11 +69,15 @@ class ImageTest extends AbstractTest SoftwareProfileFactory::createOne(['description' => self::SOFTWARE_PROFILE]); $swPIri = $this->findIriBy(SoftwareProfile::class, ['description' => self::SOFTWARE_PROFILE]); + ImageRepositoryFactory::createOne(['name' => 'repository-test']); + $irIri = $this->findIriBy(ImageRepository::class, ['name' => 'repository-test']); + $this->createClientWithCredentials()->request('POST', '/images',['json' => [ 'name' => self::IMAGE_CREATE, 'size' => 123, 'path' => '/path/to/image', 'softwareProfile' => $swPIri, + 'imageRepository' => $irIri ]]); $this->assertResponseStatusCodeSame(201); From 3d0b4f25e2f5effa4d5b29233dbb520060cd582c Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 30 Oct 2024 10:53:25 +0100 Subject: [PATCH 04/26] refs #1082. ImageRepository Test --- tests/Functional/ImageRepositoryTest.php | 133 +++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 tests/Functional/ImageRepositoryTest.php diff --git a/tests/Functional/ImageRepositoryTest.php b/tests/Functional/ImageRepositoryTest.php new file mode 100644 index 0000000..da616c6 --- /dev/null +++ b/tests/Functional/ImageRepositoryTest.php @@ -0,0 +1,133 @@ + self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + ImageRepositoryFactory::createMany(10); + + $this->createClientWithCredentials()->request('GET', '/image-repositories'); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/ImageRepository', + '@id' => '/image-repositories', + '@type' => 'hydra:Collection', + 'hydra:totalItems' => 10, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateRepository(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + $this->createClientWithCredentials()->request('POST', '/image-repositories',['json' => [ + 'name' => self::REPOSITORY_CREATE, + 'comments' => self::REPOSITORY_CREATE, + 'ip' => '127.0.0.1' + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/ImageRepositoryOutput', + '@type' => 'ImageRepository', + 'name' => self::REPOSITORY_CREATE, + 'comments' => self::REPOSITORY_CREATE, + 'ip' => '127.0.0.1' + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testUpdateRepository(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + ImageRepositoryFactory::createOne(['name' => self::REPOSITORY_UPDATE, 'comments' => self::REPOSITORY_UPDATE]); + $iri = $this->findIriBy(ImageRepository::class, ['name' => self::REPOSITORY_UPDATE]); + + $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ + 'name' => self::REPOSITORY_UPDATE, + 'comments' => self::REPOSITORY_UPDATE, + 'ip' => '127.0.0.1' + ]]); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains([ + '@id' => $iri, + 'name' => self::REPOSITORY_UPDATE, + 'comments' => self::REPOSITORY_UPDATE, + 'ip' => '127.0.0.1' + ]); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function testDeleteRepository(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + ImageRepositoryFactory::createOne(['name' => self::REPOSITORY_DELETE, 'comments' => self::REPOSITORY_DELETE]); + $iri = $this->findIriBy(ImageRepository::class, ['name' => self::REPOSITORY_DELETE]); + $this->createClientWithCredentials()->request('DELETE', $iri); + $this->assertResponseStatusCodeSame(204); + $this->assertNull( + static::getContainer()->get('doctrine')->getRepository(ImageRepository::class)->findOneBy(['name' => self::REPOSITORY_DELETE]) + ); + } +} \ No newline at end of file From 0545add493698c022bb3180d5a60640079ab1f40 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Thu, 7 Nov 2024 15:04:38 +0100 Subject: [PATCH 05/26] refs #1087. CreateImage. First commit --- config/api_platform/Image.yaml | 1 + config/services/api_platform.yaml | 7 +- migrations/Version20241105070853.php | 43 +++++++++ migrations/Version20241105085054.php | 35 +++++++ migrations/Version20241106133332.php | 31 ++++++ migrations/Version20241107074832.php | 31 ++++++ .../OgAgent/CreateImageActionController.php | 90 +++++++++++++++++ src/Controller/OgAgent/StatusAction.php | 30 ++++-- .../AgentController.php} | 5 +- .../OgAgent/Webhook/ClientsController.php | 67 +++++++++++++ .../OgAgent/Webhook/GetStatusAction.php | 44 --------- .../{ => Webhook}/OgAgentController.php | 14 ++- src/Dto/Input/ClientInput.php | 13 ++- src/Dto/Input/ImageInput.php | 79 ++++++++++----- src/Dto/Output/ClientOutput.php | 5 + src/Dto/Output/ImageOutput.php | 8 ++ src/Dto/Output/ImageRepositoryOutput.php | 2 +- src/Dto/Output/OperativeSystemOutput.php | 2 +- src/Dto/Output/TraceOutput.php | 4 + src/Entity/Client.php | 6 +- src/Entity/Image.php | 96 ++++++++++++------- src/Entity/NetworkSettings.php | 6 +- src/Entity/OgRepository.php | 86 ----------------- src/Entity/Trace.php | 15 +++ src/Factory/ImageFactory.php | 2 - src/Model/ClientStatus.php | 50 ++++++++++ src/Model/TraceStatus.php | 4 +- src/Repository/OgRepositoryRepository.php | 18 ---- src/State/Processor/ImageProcessor.php | 9 +- tests/Functional/ImageTest.php | 2 - 30 files changed, 564 insertions(+), 241 deletions(-) create mode 100644 migrations/Version20241105070853.php create mode 100644 migrations/Version20241105085054.php create mode 100644 migrations/Version20241106133332.php create mode 100644 migrations/Version20241107074832.php create mode 100644 src/Controller/OgAgent/CreateImageActionController.php rename src/Controller/OgAgent/{OgAdmClientController.php => Webhook/AgentController.php} (98%) create mode 100644 src/Controller/OgAgent/Webhook/ClientsController.php delete mode 100644 src/Controller/OgAgent/Webhook/GetStatusAction.php rename src/Controller/OgAgent/{ => Webhook}/OgAgentController.php (89%) delete mode 100644 src/Entity/OgRepository.php create mode 100644 src/Model/ClientStatus.php delete mode 100644 src/Repository/OgRepositoryRepository.php diff --git a/config/api_platform/Image.yaml b/config/api_platform/Image.yaml index 37ab891..3bb12ef 100644 --- a/config/api_platform/Image.yaml +++ b/config/api_platform/Image.yaml @@ -13,6 +13,7 @@ resources: filters: - 'api_platform.filter.image.order' - 'api_platform.filter.image.search' + - 'api_platform.filter.image.boolean' ApiPlatform\Metadata\Get: provider: App\State\Provider\ImageProvider ApiPlatform\Metadata\Put: diff --git a/config/services/api_platform.yaml b/config/services/api_platform.yaml index b5f7b49..04feaea 100644 --- a/config/services/api_platform.yaml +++ b/config/services/api_platform.yaml @@ -64,6 +64,11 @@ services: arguments: [ { 'id': 'exact', 'name': 'partial', } ] tags: [ 'api_platform.filter' ] + api_platform.filter.image.boolean: + parent: 'api_platform.doctrine.orm.boolean_filter' + arguments: [ { 'created': ~ } ] + tags: [ 'api_platform.filter' ] + api_platform.filter.og_live.order: parent: 'api_platform.doctrine.orm.order_filter' arguments: @@ -211,7 +216,7 @@ services: api_platform.filter.trace.search: parent: 'api_platform.doctrine.orm.search_filter' - arguments: [ { 'id': 'exact', 'command.id': 'exact', 'client.id': 'exact' } ] + arguments: [ { 'id': 'exact', 'command.id': 'exact', 'client.id': 'exact', status: 'exact' } ] tags: [ 'api_platform.filter' ] api_platform.filter.trace.order: diff --git a/migrations/Version20241105070853.php b/migrations/Version20241105070853.php new file mode 100644 index 0000000..3249af5 --- /dev/null +++ b/migrations/Version20241105070853.php @@ -0,0 +1,43 @@ +addSql('ALTER TABLE client ADD CONSTRAINT FK_C744045550C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)'); + $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045FFB84408A'); + $this->addSql('DROP INDEX IDX_C53D045FFB84408A ON image'); + $this->addSql('ALTER TABLE image ADD partition_info VARCHAR(255) DEFAULT NULL, CHANGE organizational_unit_id parent_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F727ACA70 FOREIGN KEY (parent_id) REFERENCES image (id)'); + $this->addSql('CREATE INDEX IDX_C53D045F727ACA70 ON image (parent_id)'); + $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B5450C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B5450C9D4F7'); + $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F727ACA70'); + $this->addSql('DROP INDEX IDX_C53D045F727ACA70 ON image'); + $this->addSql('ALTER TABLE image DROP partition_info, CHANGE parent_id organizational_unit_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045FFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); + $this->addSql('CREATE INDEX IDX_C53D045FFB84408A ON image (organizational_unit_id)'); + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C744045550C9D4F7'); + } +} diff --git a/migrations/Version20241105085054.php b/migrations/Version20241105085054.php new file mode 100644 index 0000000..bfd061c --- /dev/null +++ b/migrations/Version20241105085054.php @@ -0,0 +1,35 @@ +addSql('ALTER TABLE image ADD client_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F19EB6921 FOREIGN KEY (client_id) REFERENCES client (id)'); + $this->addSql('CREATE INDEX IDX_C53D045F19EB6921 ON image (client_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F19EB6921'); + $this->addSql('DROP INDEX IDX_C53D045F19EB6921 ON image'); + $this->addSql('ALTER TABLE image DROP client_id'); + } +} diff --git a/migrations/Version20241106133332.php b/migrations/Version20241106133332.php new file mode 100644 index 0000000..745afee --- /dev/null +++ b/migrations/Version20241106133332.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE trace ADD job_id VARCHAR(255) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE trace DROP job_id'); + } +} diff --git a/migrations/Version20241107074832.php b/migrations/Version20241107074832.php new file mode 100644 index 0000000..8481fc2 --- /dev/null +++ b/migrations/Version20241107074832.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE image ADD created TINYINT(1) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE image DROP created'); + } +} diff --git a/src/Controller/OgAgent/CreateImageActionController.php b/src/Controller/OgAgent/CreateImageActionController.php new file mode 100644 index 0000000..4f58327 --- /dev/null +++ b/src/Controller/OgAgent/CreateImageActionController.php @@ -0,0 +1,90 @@ +getClient()->getIp()) { + throw new ValidatorException('IP is required'); + } + + $partitionInfo = json_decode($image->getPartitionInfo(), true); + + $data = [ + 'dsk' => (string) $partitionInfo['numDisk'], + 'par' => (string) $partitionInfo['numPartition'], + 'cpt' => "83", + 'idi' => $image->getUuid(), + 'nci' => $image->getName(), + 'ipr' => $image->getRepository()->getIp(), + 'nfn' => 'CrearImagen', + 'ids' => '0' + ]; + + try { + $response = $this->httpClient->request('POST', 'https://localhost:4444/CloningEngine/CrearImagen', [ + 'verify_peer' => false, + 'verify_host' => false, + 'headers' => [ + 'Content-Type' => 'application/json', + ], + 'json' => $data, + ]); + + } catch (TransportExceptionInterface $e) { + return new JsonResponse( + data: ['error' => $e->getMessage()], + status: Response::HTTP_INTERNAL_SERVER_ERROR + ); + } + + $jobId = json_decode($response->getContent(), true)['job_id']; + + $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Crear Imagen']); + + $client = $image->getClient(); + $client->setStatus(ClientStatus::BUSY); + $this->entityManager->persist($client); + + $trace = new Trace(); + $trace->setClient($image->getClient()); + $trace->setCommand($command ?? null); + $trace->setStatus('pending'); + $trace->setJobId($jobId); + $trace->setExecutedAt(new \DateTime()); + + $this->entityManager->persist($trace); + $this->entityManager->flush(); + + return new JsonResponse(status: Response::HTTP_OK); + } +} diff --git a/src/Controller/OgAgent/StatusAction.php b/src/Controller/OgAgent/StatusAction.php index d0ff631..9478b47 100644 --- a/src/Controller/OgAgent/StatusAction.php +++ b/src/Controller/OgAgent/StatusAction.php @@ -3,7 +3,9 @@ namespace App\Controller\OgAgent; use App\Entity\Client; +use App\Entity\OperativeSystem; use App\Entity\Partition; +use App\Model\ClientStatus; use App\Model\OgLiveStatus; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -40,20 +42,20 @@ class StatusAction extends AbstractController } try { - $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [ - 'verify_peer' => false, // Desactivar verificación del certificado - 'verify_host' => false, // Desactivar verificación del nombre del host - 'timeout' => 10, // Tiempo máximo de espera + $response = $this->httpClient->request('POST', 'https://localhost:4444/ogAdmClient/status', [ + 'verify_peer' => false, + 'verify_host' => false, + 'timeout' => 10, 'headers' => [ - 'Content-Type' => 'application/json', // Cabecera de tipo de contenido + 'Content-Type' => 'application/json', ], - 'json' => [], // Cuerpo de la solicitud como JSON + 'json' => [], ]); $statusCode = $response->getStatusCode(); - $client->setStatus($statusCode === Response::HTTP_OK ? 'active' : 'off'); + $client->setStatus($statusCode === Response::HTTP_OK ? ClientStatus::OG_LIVE : ClientStatus::OFF); } catch (TransportExceptionInterface $e) { - $client->setStatus('off'); + $client->setStatus(ClientStatus::OFF); return new JsonResponse( data: ['error' => $e->getMessage()], @@ -72,6 +74,18 @@ class StatusAction extends AbstractController $partitionEntity = new Partition(); } + if (isset($cfg['soi']) && $cfg['soi'] !== '') { + $operativeSystem = $this->entityManager->getRepository(OperativeSystem::class) + ->findOneBy(['name' => $cfg['soi']]); + + if (!$operativeSystem) { + $operativeSystem = new OperativeSystem(); + $operativeSystem->setName($cfg['soi']); + $this->entityManager->persist($operativeSystem); + } + $partitionEntity->setOperativeSystem($operativeSystem); + } + $partitionEntity->setClient($client); $partitionEntity->setDiskNumber($cfg['disk']); $partitionEntity->setPartitionNumber($cfg['par']); diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/Webhook/AgentController.php similarity index 98% rename from src/Controller/OgAgent/OgAdmClientController.php rename to src/Controller/OgAgent/Webhook/AgentController.php index 4ec47f4..0d459ed 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/Webhook/AgentController.php @@ -2,12 +2,11 @@ declare(strict_types=1); -namespace App\Controller\OgAgent; +namespace App\Controller\OgAgent\Webhook; use App\Entity\Client; use App\Entity\OrganizationalUnit; use App\Entity\Partition; -use App\Model\OrganizationalUnitTypes; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -17,7 +16,7 @@ use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Attribute\Route; #[AsController] -class OgAdmClientController extends AbstractController +class AgentController extends AbstractController { public function __construct( protected readonly EntityManagerInterface $entityManager diff --git a/src/Controller/OgAgent/Webhook/ClientsController.php b/src/Controller/OgAgent/Webhook/ClientsController.php new file mode 100644 index 0000000..a5bb67a --- /dev/null +++ b/src/Controller/OgAgent/Webhook/ClientsController.php @@ -0,0 +1,67 @@ +toArray(); + $requiredFields = ['nfn', 'idi', 'dsk', 'par', 'cpt', 'ipr', 'inv_sft', 'ids', 'res', 'der', 'job_id']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + if ($data['nfn'] === 'RESPUESTA_CrearImagen') { + $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]); + $image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $data['idi']]); + + if ($data['res'] === 1) { + $trace->setStatus(TraceStatus::SUCCESS); + $trace->setFinishedAt(new \DateTime()); + + $image->setCreated(true); + + } else { + $trace->setStatus(TraceStatus::FAILED); + $trace->setFinishedAt(new \DateTime()); + $trace->setOutput($data['der']); + + $image->setCreated(false); + } + $this->entityManager->persist($image); + + $client = $trace->getClient(); + $client->setStatus(ClientStatus::OG_LIVE); + + $this->entityManager->persist($trace); + $this->entityManager->flush(); + + } + + return new JsonResponse([], Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Controller/OgAgent/Webhook/GetStatusAction.php b/src/Controller/OgAgent/Webhook/GetStatusAction.php deleted file mode 100644 index fc256f8..0000000 --- a/src/Controller/OgAgent/Webhook/GetStatusAction.php +++ /dev/null @@ -1,44 +0,0 @@ -getContent(), true); - - if (!is_array($data)) { - return new JsonResponse(['error' => 'Invalid JSON data'], Response::HTTP_BAD_REQUEST); - } - - - - return new JsonResponse(data: $data, status: Response::HTTP_OK); - } -} \ No newline at end of file diff --git a/src/Controller/OgAgent/OgAgentController.php b/src/Controller/OgAgent/Webhook/OgAgentController.php similarity index 89% rename from src/Controller/OgAgent/OgAgentController.php rename to src/Controller/OgAgent/Webhook/OgAgentController.php index 9fc6edd..082ca13 100644 --- a/src/Controller/OgAgent/OgAgentController.php +++ b/src/Controller/OgAgent/Webhook/OgAgentController.php @@ -2,18 +2,26 @@ declare(strict_types=1); -namespace App\Controller\OgAgent; +namespace App\Controller\OgAgent\Webhook; +use App\Entity\Client; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Annotation\Route; -use Symfony\Component\HttpFoundation\JsonResponse; #[AsController] class OgAgentController extends AbstractController { + public function __construct( + protected readonly EntityManagerInterface $entityManager + ) + { + } + #[Route('/opengnsys/rest/ogagent/started', methods: ['POST'])] public function agentStarted(Request $request): JsonResponse { @@ -26,7 +34,7 @@ class OgAgentController extends AbstractController } } - // Procesar los datos recibidos si es necesario + $client = $this->entityManager->getRepository(Client::class)->findOneBy(['mac' => $data['mac']]); return new JsonResponse([], Response::HTTP_OK); } diff --git a/src/Dto/Input/ClientInput.php b/src/Dto/Input/ClientInput.php index 8e78aa0..c7e22e6 100644 --- a/src/Dto/Input/ClientInput.php +++ b/src/Dto/Input/ClientInput.php @@ -4,12 +4,14 @@ namespace App\Dto\Input; use ApiPlatform\Metadata\ApiProperty; use App\Dto\Output\HardwareProfileOutput; +use App\Dto\Output\ImageRepositoryOutput; use App\Dto\Output\MenuOutput; use App\Dto\Output\OgLiveOutput; use App\Dto\Output\OrganizationalUnitOutput; use App\Dto\Output\PxeTemplateOutput; use App\Entity\Client; -use App\Entity\OgRepository; +use App\Entity\ImageRepository; +use App\Model\ClientStatus; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; @@ -64,7 +66,7 @@ final class ClientInput description: 'El estado del cliente', example: 'active' )] - public ?string $status = 'off'; + public ?string $status = ClientStatus::OFF; #[Assert\NotNull(message: 'validators.organizational_unit.not_null')] #[Groups(['client:write', 'client:patch'])] @@ -107,7 +109,7 @@ final class ClientInput #[ApiProperty( description: 'descriptions.client.validation' )] - public ?OgRepository $repository = null; + public ?ImageRepositoryOutput $repository = null; #[Groups(['client:write'])] #[ApiProperty( @@ -147,6 +149,10 @@ final class ClientInput if ($client->getHardwareProfile()) { $this->hardwareProfile = new HardwareProfileOutput($client->getHardwareProfile()); } + + if ($client->getRepository()) { + $this->repository = $client->getRepository(); + } } public function createOrUpdateEntity(?Client $client = null): Client @@ -165,6 +171,7 @@ final class ClientInput $client->setMenu($this->menu?->getEntity()); $client->setOgLive($this->ogLive?->getEntity()); $client->setHardwareProfile($this->hardwareProfile?->getEntity()); + $client->setRepository($this->repository?->getEntity()); $client->setTemplate($this->template?->getEntity()); $client->setPosition($this->position); $client->setStatus($this->status); diff --git a/src/Dto/Input/ImageInput.php b/src/Dto/Input/ImageInput.php index b994e9e..4f2ccae 100644 --- a/src/Dto/Input/ImageInput.php +++ b/src/Dto/Input/ImageInput.php @@ -6,9 +6,11 @@ use ApiPlatform\Metadata\ApiProperty; use App\Dto\Output\ClientOutput; use App\Dto\Output\ImageRepositoryOutput; use App\Dto\Output\OrganizationalUnitOutput; +use App\Dto\Output\PartitionOutput; use App\Dto\Output\SoftwareProfileOutput; use App\Entity\Image; use App\Entity\OrganizationalUnit; +use App\Entity\Partition; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; @@ -32,20 +34,8 @@ final class ImageInput public ?string $type = null; #[Groups(['image:write'])] - #[ApiProperty(description: 'The path of the image', example: "/path/to/image")] - public ?string $path = null; - - #[Groups(['image:write'])] - #[ApiProperty(description: 'The revision of the image', example: "1.0")] - public ?string $revision = null; - - #[Groups(['image:write'])] - #[ApiProperty(description: 'The info of the image', example: "Image 1 info")] - public ?string $info = null; - - #[Groups(['image:write'])] - #[ApiProperty(description: 'The size of the image', example: 1024)] - public ?int $size = null; + #[ApiProperty(description: 'The type of the image', example: "Server")] + public ?string $source = 'input'; #[Groups(['image:write'])] #[ApiProperty(description: 'The software profile of the image')] @@ -56,6 +46,19 @@ final class ImageInput public ?ImageRepositoryOutput $imageRepository = null; #[Groups(['image:write'])] + #[ApiProperty(description: 'The client of the image')] + public ?ClientOutput $client = null; + + #[Groups(['image:write'])] + #[ApiProperty(description: 'The client of the image')] + public ?PartitionOutput $partition = null; + + #[Groups(['image:write'])] + #[ApiProperty(description: 'The parent of the image')] + public ?self $parent = null; + + #[Groups(['image:write'])] + #[ApiProperty(description: 'The remote pc of the image')] public ?bool $remotePc = false; public function __construct(?Image $image = null) @@ -68,10 +71,6 @@ final class ImageInput $this->description = $image->getDescription(); $this->comments = $image->getComments(); $this->type = $image->getType(); - $this->path = $image->getPath(); - $this->revision = $image->getRevision(); - $this->info = $image->getInfo(); - $this->size = $image->getSize(); $this->remotePc = $image->isRemotePc(); if ($image->getSoftwareProfile()) { @@ -81,6 +80,14 @@ final class ImageInput if ($image->getRepository()) { $this->imageRepository = new ImageRepositoryOutput($image->getRepository()); } + + if ($image->getClient()) { + $this->client = new ClientOutput($image->getClient()); + } + + if ($image->getParent()) { + $this->parent = new self($image->getParent()); + } } public function createOrUpdateEntity(?Image $image = null): Image @@ -93,13 +100,37 @@ final class ImageInput $image->setDescription($this->description); $image->setComments($this->comments); $image->setType($this->type); - $image->setPath($this->path); - $image->setRevision($this->revision); - $image->setInfo($this->info); - $image->setSize($this->size); - $image->setSoftwareProfile($this->softwareProfile->getEntity()); - $image->setRepository($this->imageRepository->getEntity()); + + if ($this->softwareProfile) { + $image->setSoftwareProfile($this->softwareProfile->getEntity()); + } + + $image->setRepository($this->imageRepository ? $this->imageRepository->getEntity() + : $this->client->getEntity()->getRepository()); + + if ($this->client) { + $image->setClient($this->client->getEntity()); + } + + if ($this->parent) { + $image->setParent($this->parent->getEntity()); + } + $image->setRemotePc($this->remotePc); + $image->setCreated(false); + + $partitionInfo = []; + + if ($this->partition) { + /** @var Partition $partition */ + $partition = $this->partition->getEntity(); + $partitionInfo["numDisk"] = $partition->getDiskNumber(); + $partitionInfo["numPartition"] = $partition->getPartitionNumber(); + $partitionInfo["partitionCode"] = $partition->getPartitionCode(); + $partitionInfo["filesystem"] = $partition->getFilesystem(); + $partitionInfo["osName"] = $partition->getOperativeSystem()?->getName(); + $image->setPartitionInfo(json_encode($partitionInfo)); + } return $image; } diff --git a/src/Dto/Output/ClientOutput.php b/src/Dto/Output/ClientOutput.php index 3d9399c..d751f6d 100644 --- a/src/Dto/Output/ClientOutput.php +++ b/src/Dto/Output/ClientOutput.php @@ -48,6 +48,10 @@ final class ClientOutput extends AbstractOutput #[ApiProperty(readableLink: true )] public ?HardwareProfileOutput $hardwareProfile = null; + #[Groups(['client:read'])] + #[ApiProperty(readableLink: true )] + public ?ImageRepositoryOutput $repository = null; + #[Groups(['client:read', 'organizational-unit:read'])] #[ApiProperty(readableLink: true )] public ?PxeTemplateOutput $template = null; @@ -99,6 +103,7 @@ final class ClientOutput extends AbstractOutput $this->menu = $client->getMenu() ? new MenuOutput($client->getMenu()) : null; $this->position = $client->getPosition(); $this->template = $client->getTemplate() ? new PxeTemplateOutput($client->getTemplate()) : null; + $this->repository = $client->getRepository() ? new ImageRepositoryOutput($client->getRepository()) : null; $this->hardwareProfile = $client->getHardwareProfile() ? new HardwareProfileOutput($client->getHardwareProfile()) : null; $this->subnet = $client->getSubnet()?->getIpAddress(); $this->ogLive = $client->getOgLive() ? new OgLiveOutput($client->getOgLive()) : null; diff --git a/src/Dto/Output/ImageOutput.php b/src/Dto/Output/ImageOutput.php index 6569676..1f6dbfa 100644 --- a/src/Dto/Output/ImageOutput.php +++ b/src/Dto/Output/ImageOutput.php @@ -36,12 +36,18 @@ final class ImageOutput extends AbstractOutput #[Groups(['image:read'])] public ?bool $remotePc = null; + #[Groups(['image:read'])] + public ?bool $created = null; + #[Groups(['image:read'])] public ?SoftwareProfileOutput $softwareProfile = null; #[Groups(['image:read'])] public ?ImageRepositoryOutput $imageRepository = null; + #[Groups(['image:read'])] + public ?array $partitionInfo = null; + #[Groups(['image:read'])] public \DateTime $createdAt; @@ -62,7 +68,9 @@ final class ImageOutput extends AbstractOutput $this->size = $image->getSize(); $this->softwareProfile = $image->getSoftwareProfile() ? new SoftwareProfileOutput($image->getSoftwareProfile()) : null; $this->imageRepository = $image->getRepository() ? new ImageRepositoryOutput($image->getRepository()) : null; + $this->partitionInfo = json_decode($image->getPartitionInfo(), true); $this->remotePc = $image->isRemotePc(); + $this->created = $image->isCreated(); $this->createdAt = $image->getCreatedAt(); $this->createdBy = $image->getCreatedBy(); } diff --git a/src/Dto/Output/ImageRepositoryOutput.php b/src/Dto/Output/ImageRepositoryOutput.php index a940da1..5a7faa4 100644 --- a/src/Dto/Output/ImageRepositoryOutput.php +++ b/src/Dto/Output/ImageRepositoryOutput.php @@ -9,7 +9,7 @@ use Symfony\Component\Serializer\Annotation\Groups; #[Get(shortName: 'ImageRepository')] class ImageRepositoryOutput extends AbstractOutput { - #[Groups(['repository:read', 'image:read'])] + #[Groups(['repository:read', 'image:read', 'client:read'])] public ?string $name = ''; #[Groups(['repository:read'])] diff --git a/src/Dto/Output/OperativeSystemOutput.php b/src/Dto/Output/OperativeSystemOutput.php index bac0169..fac3ef1 100644 --- a/src/Dto/Output/OperativeSystemOutput.php +++ b/src/Dto/Output/OperativeSystemOutput.php @@ -9,7 +9,7 @@ use Symfony\Component\Serializer\Annotation\Groups; #[Get(shortName: 'OperativeSystem')] final class OperativeSystemOutput extends AbstractOutput { - #[Groups(['operative-system:read', 'partition:read', 'software-profile:read'])] + #[Groups(['operative-system:read', 'partition:read', 'software-profile:read', 'client:read'])] public string $name; #[Groups(['operative-system:read'])] diff --git a/src/Dto/Output/TraceOutput.php b/src/Dto/Output/TraceOutput.php index 265a9b2..465da71 100644 --- a/src/Dto/Output/TraceOutput.php +++ b/src/Dto/Output/TraceOutput.php @@ -19,6 +19,9 @@ final class TraceOutput extends AbstractOutput #[Groups(['trace:read'])] public string $status; + #[Groups(['trace:read'])] + public ?string $jobId = null; + #[Groups(['trace:read'])] public ?\DateTimeInterface $executedAt = null; @@ -41,6 +44,7 @@ final class TraceOutput extends AbstractOutput $this->command = new CommandOutput($trace->getCommand()); $this->client = new ClientOutput($trace->getClient()); $this->status = $trace->getStatus(); + $this->jobId = $trace->getJobId(); $this->executedAt = $trace->getExecutedAt(); $this->output = $trace->getOutput(); $this->finishedAt = $trace->getFinishedAt(); diff --git a/src/Entity/Client.php b/src/Entity/Client.php index 37546ed..0095ac7 100644 --- a/src/Entity/Client.php +++ b/src/Entity/Client.php @@ -61,7 +61,7 @@ class Client extends AbstractEntity private ?PxeTemplate $template = null; #[ORM\ManyToOne(inversedBy: 'clients')] - private ?OgRepository $repository = null; + private ?ImageRepository $repository = null; #[ORM\ManyToOne(inversedBy: 'clients')] #[ORM\JoinColumn( onDelete: 'SET NULL')] @@ -260,12 +260,12 @@ class Client extends AbstractEntity } - public function getRepository(): ?OgRepository + public function getRepository(): ?ImageRepository { return $this->repository; } - public function setRepository(?OgRepository $repository): static + public function setRepository(?ImageRepository $repository): static { $this->repository = $repository; diff --git a/src/Entity/Image.php b/src/Entity/Image.php index 5951f38..9f86cac 100644 --- a/src/Entity/Image.php +++ b/src/Entity/Image.php @@ -37,12 +37,6 @@ class Image extends AbstractEntity #[ORM\JoinColumn(nullable: true)] private ?SoftwareProfile $softwareProfile = null; - /** - * @var Collection - */ - #[ORM\OneToMany(mappedBy: 'image', targetEntity: Partition::class)] - private Collection $partitions; - #[ORM\Column] private ?bool $remotePc = null; @@ -50,6 +44,18 @@ class Image extends AbstractEntity #[ORM\JoinColumn(nullable: false)] private ?\App\Entity\ImageRepository $repository = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $partitionInfo = null; + + #[ORM\ManyToOne(targetEntity: self::class)] + private ?self $parent = null; + + #[ORM\ManyToOne] + private ?Client $client = null; + + #[ORM\Column(nullable: true)] + private ?bool $created = null; + public function __construct() { parent::__construct(); @@ -152,36 +158,6 @@ class Image extends AbstractEntity return $this; } - /** - * @return Collection - */ - public function getPartitions(): Collection - { - return $this->partitions; - } - - public function addPartition(Partition $partition): static - { - if (!$this->partitions->contains($partition)) { - $this->partitions->add($partition); - $partition->setImage($this); - } - - return $this; - } - - public function removePartition(Partition $partition): static - { - if ($this->partitions->removeElement($partition)) { - // set the owning side to null (unless already changed) - if ($partition->getImage() === $this) { - $partition->setImage(null); - } - } - - return $this; - } - public function isRemotePc(): ?bool { return $this->remotePc; @@ -205,4 +181,52 @@ class Image extends AbstractEntity return $this; } + + public function getPartitionInfo(): ?string + { + return $this->partitionInfo; + } + + public function setPartitionInfo(?string $partitionInfo): static + { + $this->partitionInfo = $partitionInfo; + + return $this; + } + + public function getParent(): ?self + { + return $this->parent; + } + + public function setParent(?self $parent): static + { + $this->parent = $parent; + + return $this; + } + + public function getClient(): ?Client + { + return $this->client; + } + + public function setClient(?Client $client): static + { + $this->client = $client; + + return $this; + } + + public function isCreated(): ?bool + { + return $this->created; + } + + public function setCreated(?bool $created): static + { + $this->created = $created; + + return $this; + } } diff --git a/src/Entity/NetworkSettings.php b/src/Entity/NetworkSettings.php index bbd2080..7e5a9ac 100644 --- a/src/Entity/NetworkSettings.php +++ b/src/Entity/NetworkSettings.php @@ -67,7 +67,7 @@ class NetworkSettings extends AbstractEntity private ?bool $validation = null; #[ORM\ManyToOne] - private ?OgRepository $repository = null; + private ?ImageRepository $repository = null; #[ORM\ManyToOne] private ?OgLive $ogLive = null; @@ -298,12 +298,12 @@ class NetworkSettings extends AbstractEntity return $this; } - public function getRepository(): ?OgRepository + public function getRepository(): ?ImageRepository { return $this->repository; } - public function setRepository(?OgRepository $repository): static + public function setRepository(?ImageRepository $repository): static { $this->repository = $repository; diff --git a/src/Entity/OgRepository.php b/src/Entity/OgRepository.php deleted file mode 100644 index 9aaaa74..0000000 --- a/src/Entity/OgRepository.php +++ /dev/null @@ -1,86 +0,0 @@ - - */ - #[ORM\OneToMany(mappedBy: 'repository', targetEntity: Client::class)] - private Collection $clients; - - public function __construct() - { - parent::__construct(); - $this->clients = new ArrayCollection(); - } - - public function getIpAddress(): ?string - { - return $this->ipAddress; - } - - public function setIpAddress(string $ipAddress): static - { - $this->ipAddress = $ipAddress; - - return $this; - } - - public function getDescription(): ?string - { - return $this->description; - } - - public function setDescription(?string $description): static - { - $this->description = $description; - - return $this; - } - - /** - * @return Collection - */ - public function getClients(): Collection - { - return $this->clients; - } - - public function addClient(Client $client): static - { - if (!$this->clients->contains($client)) { - $this->clients->add($client); - $client->setRepository($this); - } - - return $this; - } - - public function removeClient(Client $client): static - { - if ($this->clients->removeElement($client)) { - // set the owning side to null (unless already changed) - if ($client->getRepository() === $this) { - $client->setRepository(null); - } - } - - return $this; - } -} diff --git a/src/Entity/Trace.php b/src/Entity/Trace.php index 1f2f318..275c9ef 100644 --- a/src/Entity/Trace.php +++ b/src/Entity/Trace.php @@ -29,6 +29,9 @@ class Trace extends AbstractEntity #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] private ?\DateTimeInterface $finishedAt = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $jobId = null; + public function getClient(): ?Client { return $this->client; @@ -100,4 +103,16 @@ class Trace extends AbstractEntity return $this; } + + public function getJobId(): ?string + { + return $this->jobId; + } + + public function setJobId(?string $jobId): static + { + $this->jobId = $jobId; + + return $this; + } } diff --git a/src/Factory/ImageFactory.php b/src/Factory/ImageFactory.php index d0a59fb..692c49d 100644 --- a/src/Factory/ImageFactory.php +++ b/src/Factory/ImageFactory.php @@ -35,8 +35,6 @@ final class ImageFactory extends ModelFactory return [ 'createdAt' => self::faker()->dateTime(), 'name' => self::faker()->text(255), - 'path' => self::faker()->text(255), - 'size' => self::faker()->randomNumber(), 'softwareProfile' => SoftwareProfileFactory::new(), 'repository' => ImageRepositoryFactory::new(), 'updatedAt' => self::faker()->dateTime(), diff --git a/src/Model/ClientStatus.php b/src/Model/ClientStatus.php new file mode 100644 index 0000000..0ef5b22 --- /dev/null +++ b/src/Model/ClientStatus.php @@ -0,0 +1,50 @@ + 'Apagado', + self::INITIALIZING => 'Inicializando', + self::OG_LIVE => 'OG Live', + self::BUSY => 'Ocupado', + self::LINUX => 'Linux', + self::LINUX_SESSION => 'Sesión Linux', + self::MACOS => 'MacOS', + self::WINDOWS => 'Windows', + self::WINDOWS_SESSION => 'Sesión Windows', + ]; + public static function getClientStatuses(): array + { + return self::CLIENT_STATUSES; + } + + public static function getClientStatus(string $clientStatus): ?string + { + return self::CLIENT_STATUSES[$clientStatus] ?? null; + } + + public static function getClientStatusKeys(): array + { + return array_keys(self::CLIENT_STATUSES); + } +} \ No newline at end of file diff --git a/src/Model/TraceStatus.php b/src/Model/TraceStatus.php index fc790b2..d055a3f 100644 --- a/src/Model/TraceStatus.php +++ b/src/Model/TraceStatus.php @@ -6,13 +6,13 @@ final class TraceStatus { public const string PENDING = 'pending'; public const string IN_PROGRESS = 'in-progress'; - public const string COMPLETED = 'completed'; + public const string SUCCESS = 'success'; public const string FAILED = 'failed'; private const array STATUS = [ self::PENDING => 'Pendiente', self::IN_PROGRESS => 'En progreso', - self::COMPLETED => 'Completado', + self::SUCCESS => 'Finalizado con éxito', self::FAILED => 'Fallido', ]; diff --git a/src/Repository/OgRepositoryRepository.php b/src/Repository/OgRepositoryRepository.php deleted file mode 100644 index 0db2b01..0000000 --- a/src/Repository/OgRepositoryRepository.php +++ /dev/null @@ -1,18 +0,0 @@ - - */ -class OgRepositoryRepository extends AbstractRepository -{ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, self::class); - } -} diff --git a/src/State/Processor/ImageProcessor.php b/src/State/Processor/ImageProcessor.php index 833225d..89ef94e 100644 --- a/src/State/Processor/ImageProcessor.php +++ b/src/State/Processor/ImageProcessor.php @@ -9,6 +9,7 @@ use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\Put; use ApiPlatform\State\ProcessorInterface; use ApiPlatform\Validator\ValidatorInterface; +use App\Controller\OgAgent\CreateImageActionController; use App\Dto\Input\ImageInput; use App\Dto\Output\ImageOutput; use App\Repository\ImageRepository; @@ -17,7 +18,8 @@ readonly class ImageProcessor implements ProcessorInterface { public function __construct( private ImageRepository $imageRepository, - private ValidatorInterface $validator + private ValidatorInterface $validator, + private CreateImageActionController $createImageActionController ) { } @@ -52,6 +54,11 @@ readonly class ImageProcessor implements ProcessorInterface } $image = $data->createOrUpdateEntity($entity); + + if ($data->source !== 'input') { + $response = $this->createImageActionController->__invoke($image); + } + $this->validator->validate($image); $this->imageRepository->save($image); diff --git a/tests/Functional/ImageTest.php b/tests/Functional/ImageTest.php index 6f0e399..f682a18 100644 --- a/tests/Functional/ImageTest.php +++ b/tests/Functional/ImageTest.php @@ -105,14 +105,12 @@ class ImageTest extends AbstractTest $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ 'name' => self::IMAGE_UPDATE, - 'size' => 123 ]]); $this->assertResponseIsSuccessful(); $this->assertJsonContains([ '@id' => $iri, 'name' => self::IMAGE_UPDATE, - 'size' => 123 ]); } From a0ae000dca36e39c97676e097e3b249b88fbc7f1 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Fri, 15 Nov 2024 09:04:19 +0100 Subject: [PATCH 06/26] refs #1087. CreateImage --- src/Controller/DeployImageAction.php | 94 +++++++++++++++++++ ...onController.php => CreateImageAction.php} | 23 ++--- .../AbstractOgRepositoryController.php | 8 ++ .../OgRepository/GetCollectionAction.php | 42 +++++++++ .../Image/CreateAuxFilesAction.php | 8 ++ .../Image/DeletePermanentAction.php | 8 ++ .../OgRepository/Image/DeleteTrashAction.php | 39 ++++++++ .../OgRepository/Image/DeployImageAction.php | 37 ++++++++ .../OgRepository/Image/GetAction.php | 8 ++ src/Controller/OgRepository/StatusAction.php | 40 ++++++++ src/Controller/OgRepository/SyncAction.php | 52 ++++++++++ .../Webhook/ResponseController.php | 8 ++ src/Dto/Input/DeployImageInput.php | 8 ++ src/Model/DeployImageTypes.php | 8 ++ src/Model/DeployMethodTypes.php | 8 ++ src/Model/ImageStatus.php | 8 ++ src/Service/OgRepository/StatusService.php | 8 ++ src/Service/Trace/CreateService.php | 8 ++ 18 files changed, 401 insertions(+), 14 deletions(-) create mode 100644 src/Controller/DeployImageAction.php rename src/Controller/OgAgent/{CreateImageActionController.php => CreateImageAction.php} (82%) create mode 100644 src/Controller/OgRepository/AbstractOgRepositoryController.php create mode 100644 src/Controller/OgRepository/GetCollectionAction.php create mode 100644 src/Controller/OgRepository/Image/CreateAuxFilesAction.php create mode 100644 src/Controller/OgRepository/Image/DeletePermanentAction.php create mode 100644 src/Controller/OgRepository/Image/DeleteTrashAction.php create mode 100644 src/Controller/OgRepository/Image/DeployImageAction.php create mode 100644 src/Controller/OgRepository/Image/GetAction.php create mode 100644 src/Controller/OgRepository/StatusAction.php create mode 100644 src/Controller/OgRepository/SyncAction.php create mode 100644 src/Controller/OgRepository/Webhook/ResponseController.php create mode 100644 src/Dto/Input/DeployImageInput.php create mode 100644 src/Model/DeployImageTypes.php create mode 100644 src/Model/DeployMethodTypes.php create mode 100644 src/Model/ImageStatus.php create mode 100644 src/Service/OgRepository/StatusService.php create mode 100644 src/Service/Trace/CreateService.php diff --git a/src/Controller/DeployImageAction.php b/src/Controller/DeployImageAction.php new file mode 100644 index 0000000..e61f4f3 --- /dev/null +++ b/src/Controller/DeployImageAction.php @@ -0,0 +1,94 @@ +entityManager->getRepository(Command::class)->findOneBy(['name' => 'Restaurar Imagen']); + + $partitionInfo = json_decode($image->getPartitionInfo(), true); + + $inputData = [ + 'method' => $input->method, + 'client' => $input->client->getEntity()->getUuid(), + 'image' => $image->getUuid(), + 'p2pMode' => $input->p2pMode, + 'p2pTime' => $input->p2pTime, + 'mcastIp' => $input->mcastIp, + 'mcastPort' => $input->mcastPort, + 'mcastSpeed' => $input->mcastSpeed, + 'mcastMode' => $input->mcastMode, + 'numDisk' => (string) $partitionInfo['numDisk'], + 'numPartition' => (string) $partitionInfo['numPartition'], + ]; + + switch ($input->method){ + case DeployMethodTypes::UNICAST: + $data = [ + 'dsk' => (string) $partitionInfo['numDisk'], + 'par' => (string) $partitionInfo['numPartition'], + 'ifs' => "1", + 'cpt' => "83", + 'idi' => $image->getUuid(), + 'nci' => $image->getName(), + 'ipr' => $image->getRepository()->getIp(), + 'nfn' => 'RestaurarImagen', + 'ptc' => DeployMethodTypes::UNICAST, + 'ids' => '0' + ]; + + $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $command, $input->client->getEntity()); + $this->createService->__invoke($input->client->getEntity(), $command, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); + + break; + + case DeployMethodTypes::MULTICAST: + $data = [ + 'dsk' => (string) $image->getPartitionInfo()['numDisk'], + 'par' => (string) $image->getPartitionInfo()['numPartition'], + 'cpt' => "83", + 'idi' => $image->getUuid(), + 'nci' => $image->getName(), + 'ipr' => $image->getRepository()->getIp(), + 'nfn' => 'CrearImagen', + 'ids' => '0' + ]; + + $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $command); + $this->createService->__invoke($image->getClient(), $command, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); + + break; + } + + + return new JsonResponse(data: [], status: Response::HTTP_OK); + } +} diff --git a/src/Controller/OgAgent/CreateImageActionController.php b/src/Controller/OgAgent/CreateImageAction.php similarity index 82% rename from src/Controller/OgAgent/CreateImageActionController.php rename to src/Controller/OgAgent/CreateImageAction.php index 4f58327..abdec18 100644 --- a/src/Controller/OgAgent/CreateImageActionController.php +++ b/src/Controller/OgAgent/CreateImageAction.php @@ -9,6 +9,8 @@ use App\Entity\Command; use App\Entity\Image; use App\Entity\Trace; use App\Model\ClientStatus; +use App\Model\TraceStatus; +use App\Service\Trace\CreateService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -21,16 +23,16 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; -class CreateImageActionController extends AbstractController +class CreateImageAction extends AbstractController { public function __construct( protected readonly EntityManagerInterface $entityManager, - protected readonly HttpClientInterface $httpClient + protected readonly HttpClientInterface $httpClient, + protected readonly CreateService $createService, ) { } - public function __invoke(Image $image): JsonResponse { if (!$image->getClient()->getIp()) { @@ -51,7 +53,7 @@ class CreateImageActionController extends AbstractController ]; try { - $response = $this->httpClient->request('POST', 'https://localhost:4444/CloningEngine/CrearImagen', [ + $response = $this->httpClient->request('POST', 'https://'.$image->getClient()->getIp().':8000/CloningEngine/CrearImagen', [ 'verify_peer' => false, 'verify_host' => false, 'headers' => [ @@ -74,17 +76,10 @@ class CreateImageActionController extends AbstractController $client = $image->getClient(); $client->setStatus(ClientStatus::BUSY); $this->entityManager->persist($client); - - $trace = new Trace(); - $trace->setClient($image->getClient()); - $trace->setCommand($command ?? null); - $trace->setStatus('pending'); - $trace->setJobId($jobId); - $trace->setExecutedAt(new \DateTime()); - - $this->entityManager->persist($trace); $this->entityManager->flush(); - return new JsonResponse(status: Response::HTTP_OK); + $this->createService->__invoke($image->getClient(), $command, TraceStatus::IN_PROGRESS, $jobId, []); + + return new JsonResponse(data: $image, status: Response::HTTP_OK); } } diff --git a/src/Controller/OgRepository/AbstractOgRepositoryController.php b/src/Controller/OgRepository/AbstractOgRepositoryController.php new file mode 100644 index 0000000..f77270d --- /dev/null +++ b/src/Controller/OgRepository/AbstractOgRepositoryController.php @@ -0,0 +1,8 @@ +request('GET', $this->ogRepositoryApiUrl.'/ogrepository/v1/images', [ + 'headers' => [ + 'accept' => 'application/json', + ], + ]); + } catch (TransportExceptionInterface $e) { + return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); + } + + $data = json_decode($response->getContent(), true); + + return new JsonResponse( data: $data, status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Controller/OgRepository/Image/CreateAuxFilesAction.php b/src/Controller/OgRepository/Image/CreateAuxFilesAction.php new file mode 100644 index 0000000..7ef1b26 --- /dev/null +++ b/src/Controller/OgRepository/Image/CreateAuxFilesAction.php @@ -0,0 +1,8 @@ +getImageFullsum()) { + throw new ValidatorException('Fullsum is required'); + } + + $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$data->getRepository()->getIp().'/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); + + $this->entityManager->remove($data); + $this->entityManager->flush(); + + return new JsonResponse(data: $content, status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Controller/OgRepository/Image/DeployImageAction.php b/src/Controller/OgRepository/Image/DeployImageAction.php new file mode 100644 index 0000000..3471190 --- /dev/null +++ b/src/Controller/OgRepository/Image/DeployImageAction.php @@ -0,0 +1,37 @@ +client; + + $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Deploy Imagen']); + $this->createService->__invoke($data->getClient(), $command, TraceStatus::IN_PROGRESS, null); + + + return new JsonResponse(data: [], status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Controller/OgRepository/Image/GetAction.php b/src/Controller/OgRepository/Image/GetAction.php new file mode 100644 index 0000000..1f35cf5 --- /dev/null +++ b/src/Controller/OgRepository/Image/GetAction.php @@ -0,0 +1,8 @@ +request('GET', $data->getIp().'/ogrepository/v1/status', [ + 'headers' => [ + 'accept' => 'application/json', + ], + ]); + } catch (TransportExceptionInterface $e) { + return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); + } + + $data = json_decode($response->getContent(), true); + + return new JsonResponse( data: $data, status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Controller/OgRepository/SyncAction.php b/src/Controller/OgRepository/SyncAction.php new file mode 100644 index 0000000..198c468 --- /dev/null +++ b/src/Controller/OgRepository/SyncAction.php @@ -0,0 +1,52 @@ +createRequest($httpClient, 'GET', $this->ogRepositoryApiUrl . '/ogrepository/v1/images'); + + if (!isset($content['output']['REPOSITORY']['images'])) { + return new JsonResponse(data: 'No images found', status: Response::HTTP_NOT_FOUND); + } + + foreach ($content['output']['REPOSITORY']['images'] as $image) { + $imageEntity = $this->entityManager->getRepository(Image::class)->findOneBy(['imageFullsum' => $image['fullsum']]); + if (!$imageEntity) { + $imageEntity = new Image(); + $imageEntity->setName($image['name'].$image['type']); + $imageEntity->setImageFullsum($image['fullsum']); + $imageEntity->setRemotePc(false); + } + $this->entityManager->persist($imageEntity); + } + $this->entityManager->flush(); + + return new JsonResponse(data: $content, status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Controller/OgRepository/Webhook/ResponseController.php b/src/Controller/OgRepository/Webhook/ResponseController.php new file mode 100644 index 0000000..c3d7de3 --- /dev/null +++ b/src/Controller/OgRepository/Webhook/ResponseController.php @@ -0,0 +1,8 @@ + Date: Fri, 15 Nov 2024 09:06:28 +0100 Subject: [PATCH 07/26] refs #1151. Integracion ogRepository --- migrations/Version20241108062659.php | 31 ++++++++++ migrations/Version20241111101047.php | 31 ++++++++++ migrations/Version20241113084353.php | 33 +++++++++++ migrations/Version20241114081247.php | 31 ++++++++++ migrations/Version20241115074840.php | 31 ++++++++++ .../AbstractOgRepositoryController.php | 56 ++++++++++++++++++- .../OgRepository/GetCollectionAction.php | 22 ++------ .../Image/CreateAuxFilesAction.php | 54 +++++++++++++++++- .../Image/DeletePermanentAction.php | 35 +++++++++++- .../OgRepository/Image/DeleteTrashAction.php | 6 +- .../OgRepository/Image/DeployImageAction.php | 3 +- .../OgRepository/Image/GetAction.php | 32 ++++++++++- src/Controller/OgRepository/StatusAction.php | 14 +---- src/Controller/OgRepository/SyncAction.php | 12 ++-- .../Webhook/ResponseController.php | 55 +++++++++++++++++- src/Service/OgRepository/StatusService.php | 38 +++++++++++++ 16 files changed, 433 insertions(+), 51 deletions(-) create mode 100644 migrations/Version20241108062659.php create mode 100644 migrations/Version20241111101047.php create mode 100644 migrations/Version20241113084353.php create mode 100644 migrations/Version20241114081247.php create mode 100644 migrations/Version20241115074840.php diff --git a/migrations/Version20241108062659.php b/migrations/Version20241108062659.php new file mode 100644 index 0000000..8d345ea --- /dev/null +++ b/migrations/Version20241108062659.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE image ADD image_fullsum VARCHAR(255) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE image DROP image_fullsum'); + } +} diff --git a/migrations/Version20241111101047.php b/migrations/Version20241111101047.php new file mode 100644 index 0000000..75b1819 --- /dev/null +++ b/migrations/Version20241111101047.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE image ADD status VARCHAR(255) NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE image DROP status'); + } +} diff --git a/migrations/Version20241113084353.php b/migrations/Version20241113084353.php new file mode 100644 index 0000000..7b81205 --- /dev/null +++ b/migrations/Version20241113084353.php @@ -0,0 +1,33 @@ +addSql('ALTER TABLE network_settings ADD og_log VARCHAR(255) DEFAULT NULL, ADD og_share VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE trace ADD input VARCHAR(255) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE network_settings DROP og_log, DROP og_share'); + $this->addSql('ALTER TABLE trace DROP input'); + } +} diff --git a/migrations/Version20241114081247.php b/migrations/Version20241114081247.php new file mode 100644 index 0000000..65c180c --- /dev/null +++ b/migrations/Version20241114081247.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE trace CHANGE input input JSON DEFAULT NULL COMMENT \'(DC2Type:json)\''); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE trace CHANGE input input VARCHAR(255) DEFAULT NULL'); + } +} diff --git a/migrations/Version20241115074840.php b/migrations/Version20241115074840.php new file mode 100644 index 0000000..5246bdf --- /dev/null +++ b/migrations/Version20241115074840.php @@ -0,0 +1,31 @@ +addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON image (name)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON image'); + } +} diff --git a/src/Controller/OgRepository/AbstractOgRepositoryController.php b/src/Controller/OgRepository/AbstractOgRepositoryController.php index f77270d..0d1f141 100644 --- a/src/Controller/OgRepository/AbstractOgRepositoryController.php +++ b/src/Controller/OgRepository/AbstractOgRepositoryController.php @@ -1,8 +1,58 @@ [ + 'accept' => 'application/json', + 'Content-Type' => 'application/json' + ], + ]); + + try { + $response = $this->httpClient->request($method, $url, $params); + + return json_decode($response->getContent(), true); + } catch (ClientExceptionInterface | ServerExceptionInterface $e) { + $response = $e->getResponse(); + $content = json_decode($response->getContent(false), true); + throw new HttpException($response->getStatusCode(), $content['error'] ?? 'An error occurred'); + } catch (TransportExceptionInterface $e) { + throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, $e->getMessage()); + } + } +} diff --git a/src/Controller/OgRepository/GetCollectionAction.php b/src/Controller/OgRepository/GetCollectionAction.php index 74bd7fd..f99bde0 100644 --- a/src/Controller/OgRepository/GetCollectionAction.php +++ b/src/Controller/OgRepository/GetCollectionAction.php @@ -1,10 +1,8 @@ request('GET', $this->ogRepositoryApiUrl.'/ogrepository/v1/images', [ - 'headers' => [ - 'accept' => 'application/json', - ], - ]); - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); - } + $content = $this->createRequest($httpClient, 'GET', 'http://'.$data->getIp(). '/ogrepository/v1/images'); - $data = json_decode($response->getContent(), true); - - return new JsonResponse( data: $data, status: Response::HTTP_OK); + return new JsonResponse( data: $content, status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgRepository/Image/CreateAuxFilesAction.php b/src/Controller/OgRepository/Image/CreateAuxFilesAction.php index 7ef1b26..199b9da 100644 --- a/src/Controller/OgRepository/Image/CreateAuxFilesAction.php +++ b/src/Controller/OgRepository/Image/CreateAuxFilesAction.php @@ -2,7 +2,57 @@ namespace App\Controller\OgRepository\Image; -class CreateAuxFilesAction -{ +use App\Controller\OgRepository\AbstractOgRepositoryController; +use App\Entity\Command; +use App\Entity\Image; +use App\Model\ImageStatus; +use App\Model\TraceStatus; +use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Validator\Exception\ValidatorException; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; +use Symfony\Contracts\HttpClient\HttpClientInterface; +#[AsController] +class CreateAuxFilesAction extends AbstractOgRepositoryController +{ + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ClientExceptionInterface + */ + public function __invoke(Image $data): JsonResponse + { + if (!$data->getName()) { + throw new ValidatorException('Name is required'); + } + + $params = [ + 'json' => [ + 'image' => $data->getName().'.img' + ] + ]; + + $content = $this->createRequest('POST', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/torrentsum', $params); + $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Crear Imagen']); + + $inputData = [ + 'imageName' => $data->getName(), + 'imageUuid' => $data->getUuid(), + ]; + + $this->createService->__invoke($data->getClient(), $command, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); + + $data->setStatus(ImageStatus::IN_PROGRESS); + $this->entityManager->persist($data); + $this->entityManager->flush(); + + return new JsonResponse(data: $content, status: Response::HTTP_OK); + } } \ No newline at end of file diff --git a/src/Controller/OgRepository/Image/DeletePermanentAction.php b/src/Controller/OgRepository/Image/DeletePermanentAction.php index ca82015..e560c6e 100644 --- a/src/Controller/OgRepository/Image/DeletePermanentAction.php +++ b/src/Controller/OgRepository/Image/DeletePermanentAction.php @@ -2,7 +2,38 @@ namespace App\Controller\OgRepository\Image; -class DeletePermanentAction -{ +use App\Controller\OgRepository\AbstractOgRepositoryController; +use App\Entity\Image; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Validator\Exception\ValidatorException; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; +use Symfony\Contracts\HttpClient\HttpClientInterface; +#[AsController] +class DeletePermanentAction extends AbstractOgRepositoryController +{ + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ClientExceptionInterface + */ + public function __invoke(Image $data, HttpClientInterface $httpClient): JsonResponse + { + if (!$data->getImageFullsum()) { + throw new ValidatorException('Fullsum is required'); + } + + $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$data->getRepository()->getIp().'/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); + + $this->entityManager->remove($data); + $this->entityManager->flush(); + + return new JsonResponse(data: $content, status: Response::HTTP_OK); + } } \ No newline at end of file diff --git a/src/Controller/OgRepository/Image/DeleteTrashAction.php b/src/Controller/OgRepository/Image/DeleteTrashAction.php index 0fe3b5f..59c671b 100644 --- a/src/Controller/OgRepository/Image/DeleteTrashAction.php +++ b/src/Controller/OgRepository/Image/DeleteTrashAction.php @@ -4,6 +4,7 @@ namespace App\Controller\OgRepository\Image; use App\Controller\OgRepository\AbstractOgRepositoryController; use App\Entity\Image; +use App\Model\ImageStatus; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; @@ -15,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class DeleteAction extends AbstractOgRepositoryController +class DeleteTrashAction extends AbstractOgRepositoryController { /** * @throws TransportExceptionInterface @@ -31,7 +32,8 @@ class DeleteAction extends AbstractOgRepositoryController $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$data->getRepository()->getIp().'/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); - $this->entityManager->remove($data); + $data->setStatus(ImageStatus::TRASH); + $this->entityManager->persist($data); $this->entityManager->flush(); return new JsonResponse(data: $content, status: Response::HTTP_OK); diff --git a/src/Controller/OgRepository/Image/DeployImageAction.php b/src/Controller/OgRepository/Image/DeployImageAction.php index 3471190..db85293 100644 --- a/src/Controller/OgRepository/Image/DeployImageAction.php +++ b/src/Controller/OgRepository/Image/DeployImageAction.php @@ -8,6 +8,7 @@ use App\Entity\Command; use App\Entity\Image; use App\Model\TraceStatus; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; @@ -16,7 +17,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class DeployImage extends AbstractOgRepositoryController +class DeployImageAction extends AbstractOgRepositoryController { /** * @throws TransportExceptionInterface diff --git a/src/Controller/OgRepository/Image/GetAction.php b/src/Controller/OgRepository/Image/GetAction.php index 1f35cf5..79df992 100644 --- a/src/Controller/OgRepository/Image/GetAction.php +++ b/src/Controller/OgRepository/Image/GetAction.php @@ -2,7 +2,35 @@ namespace App\Controller\OgRepository\Image; -class GetAction -{ +use App\Controller\OgRepository\AbstractOgRepositoryController; +use App\Entity\Image; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Validator\Exception\ValidatorException; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; +use Symfony\Contracts\HttpClient\HttpClientInterface; +#[AsController] +class GetAction extends AbstractOgRepositoryController +{ + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ClientExceptionInterface + */ + public function __invoke(Image $data): JsonResponse + { + if (!$data->getImageFullsum()) { + throw new ValidatorException('Fullsum is required'); + } + + $content = $this->createRequest('GET', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/'.$data->getImageFullsum()); + + return new JsonResponse(data: $content, status: Response::HTTP_OK); + } } \ No newline at end of file diff --git a/src/Controller/OgRepository/StatusAction.php b/src/Controller/OgRepository/StatusAction.php index 0b6e0e1..74c2654 100644 --- a/src/Controller/OgRepository/StatusAction.php +++ b/src/Controller/OgRepository/StatusAction.php @@ -23,18 +23,8 @@ class StatusAction extends AbstractOgRepositoryController */ public function __invoke(ImageRepository $data, HttpClientInterface $httpClient): JsonResponse { - try { - $response = $httpClient->request('GET', $data->getIp().'/ogrepository/v1/status', [ - 'headers' => [ - 'accept' => 'application/json', - ], - ]); - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); - } + $content = $this->createRequest('GET', 'http://'.$data->getIp(). ':8006/ogrepository/v1/status'); - $data = json_decode($response->getContent(), true); - - return new JsonResponse( data: $data, status: Response::HTTP_OK); + return new JsonResponse( data: $content, status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgRepository/SyncAction.php b/src/Controller/OgRepository/SyncAction.php index 198c468..957c939 100644 --- a/src/Controller/OgRepository/SyncAction.php +++ b/src/Controller/OgRepository/SyncAction.php @@ -1,17 +1,13 @@ createRequest($httpClient, 'GET', $this->ogRepositoryApiUrl . '/ogrepository/v1/images'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$data->getIp(). '/ogrepository/v1/images'); if (!isset($content['output']['REPOSITORY']['images'])) { return new JsonResponse(data: 'No images found', status: Response::HTTP_NOT_FOUND); diff --git a/src/Controller/OgRepository/Webhook/ResponseController.php b/src/Controller/OgRepository/Webhook/ResponseController.php index c3d7de3..7a7d0d2 100644 --- a/src/Controller/OgRepository/Webhook/ResponseController.php +++ b/src/Controller/OgRepository/Webhook/ResponseController.php @@ -2,7 +2,58 @@ namespace App\Controller\OgRepository\Webhook; -class ResponseController -{ +use App\Entity\Image; +use App\Entity\Trace; +use App\Model\ImageStatus; +use App\Model\TraceStatus; +use Doctrine\ORM\EntityManagerInterface; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Routing\Annotation\Route; +#[AsController] +class ResponseController extends AbstractController +{ + public function __construct( + protected readonly EntityManagerInterface $entityManager + ) + { + } + + #[Route('/og-repository/webhook', name: 'og_repository_webhook', methods: ['POST'])] + public function repositoryWebhook(Request $request): JsonResponse + { + $data = json_decode($request->getContent(), true); + + $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]); + $imageUuid = $trace->getInput()['imageUuid']; + + $image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $imageUuid]); + + if ($image === null) { + $trace->setStatus(TraceStatus::FAILED); + $trace->setFinishedAt(new \DateTime()); + $trace->setOutput('Image not found'); + $this->entityManager->persist($trace); + $this->entityManager->flush(); + + return new JsonResponse(['message' => 'Image not found'], Response::HTTP_NOT_FOUND); + } + + $image->setImageFullsum($data['image_id']); + $image->setStatus(ImageStatus::SUCCESS); + $this->entityManager->persist($image); + + $trace->setStatus(TraceStatus::SUCCESS); + $trace->setFinishedAt(new \DateTime()); + + $this->entityManager->persist($trace); + $this->entityManager->flush(); + + return new JsonResponse($data, Response::HTTP_OK); + + } } \ No newline at end of file diff --git a/src/Service/OgRepository/StatusService.php b/src/Service/OgRepository/StatusService.php index fd9e8ea..248021b 100644 --- a/src/Service/OgRepository/StatusService.php +++ b/src/Service/OgRepository/StatusService.php @@ -2,7 +2,45 @@ namespace App\Service\OgRepository; +use Symfony\Component\HttpClient\HttpClient; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; + class StatusService { + public function __construct( + ) + { + } + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ClientExceptionInterface + */ + public function __invoke() + { + + $httpClient = HttpClient::create([ + 'verify_peer' => false, + 'verify_host' => false, + ]); + + try { + $response = $httpClient->request('GET', ''.'/ogrepository/v1/status', [ + 'headers' => [ + 'accept' => 'application/json', + ], + ]); + } catch (TransportExceptionInterface $e) { + return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); + } + + return json_decode($response->getContent(), true); + } } \ No newline at end of file From aee03d6a858f712adaa833cdb01e3f0543ed54b1 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Fri, 15 Nov 2024 09:09:35 +0100 Subject: [PATCH 08/26] refs #1088. Deploy Image --- src/Dto/Input/DeployImageInput.php | 45 ++++++++++++++++++++++++++ src/Model/DeployImageTypes.php | 22 ++++++++++++- src/Model/DeployMethodTypes.php | 24 +++++++++++++- src/Model/ImageStatus.php | 29 ++++++++++++++++- src/State/Processor/ImageProcessor.php | 4 +-- 5 files changed, 119 insertions(+), 5 deletions(-) diff --git a/src/Dto/Input/DeployImageInput.php b/src/Dto/Input/DeployImageInput.php index 1c889f3..af79406 100644 --- a/src/Dto/Input/DeployImageInput.php +++ b/src/Dto/Input/DeployImageInput.php @@ -2,7 +2,52 @@ namespace App\Dto\Input; +use ApiPlatform\Metadata\ApiProperty; +use App\Dto\Output\ClientOutput; +use App\Dto\Output\ImageOutput; +use App\Dto\Output\PartitionOutput; +use App\Validator\Constraints\OrganizationalUnitMulticastMode; +use App\Validator\Constraints\OrganizationalUnitMulticastPort; +use App\Validator\Constraints\OrganizationalUnitP2PMode; +use Symfony\Component\Serializer\Annotation\Groups; + class DeployImageInput { + #[Groups(['image:write'])] + #[ApiProperty(description: 'The type of the image deployment', example: "")] + public ?string $type = null; + + #[Groups(['image:write'])] + #[ApiProperty(description: 'The type of the image deployment', example: "")] + public ?string $method = null; + + #[Groups(['image:write'])] + #[ApiProperty(description: 'The client to deploy the image')] + public ?ClientOutput $client = null; + + #[Groups(['image:write'])] + #[ApiProperty(description: 'The partition to deploy the image')] + public ?PartitionOutput $partition = null; + + #[OrganizationalUnitP2PMode] + #[Groups(['image:write'])] + public ?string $p2pMode = null; + + #[Groups(['organizational-unit:write'])] + public ?int $p2pTime = null; + + #[Groups(['image:write'])] + public ?string $mcastIp = null; + + #[Groups(['image:write'])] + public ?int $mcastSpeed = null; + + #[OrganizationalUnitMulticastPort] + #[Groups(['image:write'])] + public ?int $mcastPort = null; + + #[OrganizationalUnitMulticastMode] + #[Groups(['image:write'])] + public ?string $mcastMode = null; } \ No newline at end of file diff --git a/src/Model/DeployImageTypes.php b/src/Model/DeployImageTypes.php index 85f6d2c..4146246 100644 --- a/src/Model/DeployImageTypes.php +++ b/src/Model/DeployImageTypes.php @@ -2,7 +2,27 @@ namespace App\Model; -class DeployImageTypes +final class DeployImageTypes { + public const string DEPLOY_IMAGE = 'deploy-image'; + public const string UPDATE_CACHE = 'update-cache'; + private const array DEPLOYMENT_IMAGE_TYPES = [ + self::DEPLOY_IMAGE => 'Unidad Organizativa', + self::UPDATE_CACHE => 'Grupo de aulas', + ]; + public static function getDeploymentImageTypes(): array + { + return self::DEPLOYMENT_IMAGE_TYPES; + } + + public static function getDeploymentImageType(string $type): ?string + { + return self::DEPLOYMENT_IMAGE_TYPES[$type] ?? null; + } + + public static function getDeploymentImageTypeKeys(): array + { + return array_keys(self::DEPLOYMENT_IMAGE_TYPES); + } } \ No newline at end of file diff --git a/src/Model/DeployMethodTypes.php b/src/Model/DeployMethodTypes.php index 51ad0cd..9eb464c 100644 --- a/src/Model/DeployMethodTypes.php +++ b/src/Model/DeployMethodTypes.php @@ -2,7 +2,29 @@ namespace App\Model; -class DeployMethodTypes +final class DeployMethodTypes { + public const string MULTICAST = 'multicast'; + public const string UNICAST = 'unicast'; + public const string TORRENT = 'torrent'; + private const array DEPLOYMENT_METHOD_TYPES = [ + self::MULTICAST => 'Multicast', + self::UNICAST => 'Unicast', + self::TORRENT => 'Torrent', + ]; + + public static function getDeploymentMethodTypes(): array + { + return self::DEPLOYMENT_METHOD_TYPES; + } + + public static function getDeploymentMethodType(string $type): ?string + { + return self::DEPLOYMENT_METHOD_TYPES[$type] ?? null; + } + public static function getDeploymentMethodTypeKeys(): array + { + return array_keys(self::DEPLOYMENT_METHOD_TYPES); + } } \ No newline at end of file diff --git a/src/Model/ImageStatus.php b/src/Model/ImageStatus.php index f59c244..d46af96 100644 --- a/src/Model/ImageStatus.php +++ b/src/Model/ImageStatus.php @@ -2,7 +2,34 @@ namespace App\Model; -class ImageStatus +final class ImageStatus { + public const string PENDING = 'pending'; + public const string IN_PROGRESS = 'in-progress'; + public const string SUCCESS = 'success'; + public const string TRASH = 'trash'; + public const string FAILED = 'failed'; + private const array STATUS = [ + self::PENDING => 'Pendiente', + self::IN_PROGRESS => 'En progreso', + self::TRASH => 'Papelera', + self::SUCCESS => 'Completado', + self::FAILED => 'Fallido', + ]; + + public static function getStatus(): array + { + return self::STATUS; + } + + public static function getImageStatus(string $status): ?string + { + return self::STATUS[$status] ?? null; + } + + public static function getStatusKeys(): array + { + return array_keys(self::STATUS); + } } \ No newline at end of file diff --git a/src/State/Processor/ImageProcessor.php b/src/State/Processor/ImageProcessor.php index 89ef94e..bcda6ed 100644 --- a/src/State/Processor/ImageProcessor.php +++ b/src/State/Processor/ImageProcessor.php @@ -9,7 +9,7 @@ use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\Put; use ApiPlatform\State\ProcessorInterface; use ApiPlatform\Validator\ValidatorInterface; -use App\Controller\OgAgent\CreateImageActionController; +use App\Controller\OgAgent\CreateImageAction; use App\Dto\Input\ImageInput; use App\Dto\Output\ImageOutput; use App\Repository\ImageRepository; @@ -19,7 +19,7 @@ readonly class ImageProcessor implements ProcessorInterface public function __construct( private ImageRepository $imageRepository, private ValidatorInterface $validator, - private CreateImageActionController $createImageActionController + private CreateImageAction $createImageActionController ) { } From 03e36f621834451307ff8a3f8b51d211d80a5b0e Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Fri, 15 Nov 2024 09:39:35 +0100 Subject: [PATCH 09/26] refs #1087. CreateImage. Output and webhooks controllers --- config/api_platform/Image.yaml | 43 ++++++++++ config/api_platform/ImageRepository.yaml | 26 ++++++ config/packages/security.yaml | 1 + config/services/api_platform.yaml | 2 +- src/Controller/OgAgent/DeployImageAction.php | 82 +++++++++++++++++++ src/Controller/OgAgent/StatusAction.php | 4 +- .../OgAgent/Webhook/ClientsController.php | 41 +++++++++- .../OgAgent/Webhook/OgAgentController.php | 16 ++++ src/Dto/Input/ClientInput.php | 2 +- src/Dto/Input/ImageInput.php | 2 + src/Dto/Output/ImageOutput.php | 8 ++ src/Dto/Output/TraceOutput.php | 4 + src/Entity/Client.php | 2 + src/Entity/Image.php | 35 +++++++- src/Entity/NetworkSettings.php | 30 +++++++ src/Entity/Trace.php | 15 ++++ src/Factory/ImageFactory.php | 1 + src/OpenApi/OpenApiFactory.php | 54 +++++++++++- 18 files changed, 358 insertions(+), 10 deletions(-) create mode 100644 src/Controller/OgAgent/DeployImageAction.php diff --git a/config/api_platform/Image.yaml b/config/api_platform/Image.yaml index 3bb12ef..a338c1e 100644 --- a/config/api_platform/Image.yaml +++ b/config/api_platform/Image.yaml @@ -23,6 +23,49 @@ resources: ApiPlatform\Metadata\Post: ~ ApiPlatform\Metadata\Delete: ~ + get_image_ogrepository: + shortName: OgRepository Server + description: Get image in OgRepository + class: ApiPlatform\Metadata\Get + method: GET + input: false + uriTemplate: /images/server/{uuid}/get + controller: App\Controller\OgRepository\Image\GetAction + + create_aux_files_image_ogrepository: + shortName: OgRepository Server + class: ApiPlatform\Metadata\Post + method: POST + input: false + uriTemplate: /images/server/{uuid}/create-aux-files + controller: App\Controller\OgRepository\Image\CreateAuxFilesAction + + deploy_image_ogrepository: + shortName: OgRepository Server + class: ApiPlatform\Metadata\Post + method: POST + input: App\Dto\Input\DeployImageInput + uriTemplate: /images/{uuid}/deploy-image + controller: App\Controller\DeployImageAction + + trash_delete_image_ogrepository: + shortName: OgRepository Server + description: Delete Image in OgRepository + class: ApiPlatform\Metadata\Delete + method: DELETE + input: false + uriTemplate: /images/server/{uuid}/delete-trash + controller: App\Controller\OgRepository\Image\DeleteTrashAction + + permanent_delete_image_ogrepository: + shortName: OgRepository Server + description: Delete Image in OgRepository + class: ApiPlatform\Metadata\Delete + method: DELETE + input: false + uriTemplate: /images/server/{uuid}/delete-permanent + controller: App\Controller\OgRepository\Image\DeletePermanentAction + properties: App\Entity\Image: id: diff --git a/config/api_platform/ImageRepository.yaml b/config/api_platform/ImageRepository.yaml index e6cb84c..43010ef 100644 --- a/config/api_platform/ImageRepository.yaml +++ b/config/api_platform/ImageRepository.yaml @@ -22,6 +22,32 @@ resources: ApiPlatform\Metadata\Post: ~ ApiPlatform\Metadata\Delete: ~ + image_ogrepository_sync: + shortName: OgRepository Server + class: ApiPlatform\Metadata\Post + method: POST + input: false + uriTemplate: /image-repositories/server/sync + controller: App\Controller\OgRepository\SyncAction + + get_collection_images_ogrepository: + shortName: OgRepository Server + description: Get collection of image in OgRepository + class: ApiPlatform\Metadata\Get + method: GET + input: false + uriTemplate: /image-repositories/server/get-collection + controller: App\Controller\OgRepository\GetCollectionAction + + images_ogrepository_status: + shortName: OgRepository Server + description: Get status of OgRepository + class: ApiPlatform\Metadata\Get + method: GET + input: false + uriTemplate: /image-repositories/server/{uuid}/status + controller: App\Controller\OgRepository\StatusAction + properties: App\Entity\ImageRepository: id: diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 568ba93..ac8c830 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -30,6 +30,7 @@ security: - { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI docs - { path: ^/auth/login, roles: PUBLIC_ACCESS } - { path: ^/opengnsys/rest, roles: PUBLIC_ACCESS } + - { path: ^/og-repository/webhook, roles: PUBLIC_ACCESS } - { path: ^/og-lives/install/webhook, roles: PUBLIC_ACCESS } - { path: ^/auth/refresh, roles: PUBLIC_ACCESS } - { path: ^/, roles: IS_AUTHENTICATED_FULLY } diff --git a/config/services/api_platform.yaml b/config/services/api_platform.yaml index 04feaea..5987770 100644 --- a/config/services/api_platform.yaml +++ b/config/services/api_platform.yaml @@ -61,7 +61,7 @@ services: api_platform.filter.image.search: parent: 'api_platform.doctrine.orm.search_filter' - arguments: [ { 'id': 'exact', 'name': 'partial', } ] + arguments: [ { 'id': 'exact', 'name': 'partial', 'repository.id': 'exact'} ] tags: [ 'api_platform.filter' ] api_platform.filter.image.boolean: diff --git a/src/Controller/OgAgent/DeployImageAction.php b/src/Controller/OgAgent/DeployImageAction.php new file mode 100644 index 0000000..0d3e7d3 --- /dev/null +++ b/src/Controller/OgAgent/DeployImageAction.php @@ -0,0 +1,82 @@ +getClient()->getIp()) { + throw new ValidatorException('IP is required'); + } + + $partitionInfo = json_decode($image->getPartitionInfo(), true); + + $data = [ + 'dsk' => (string) $partitionInfo['numDisk'], + 'par' => (string) $partitionInfo['numPartition'], + 'ifs' => "1", + 'idi' => $image->getUuid(), + 'nci' => $image->getName(), + 'ipr' => $image->getRepository()->getIp(), + 'nfn' => 'RestaurarImagen', + 'ptc' => 'unicast', + '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, + ]); + + } catch (TransportExceptionInterface $e) { + 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; + } +} diff --git a/src/Controller/OgAgent/StatusAction.php b/src/Controller/OgAgent/StatusAction.php index 9478b47..5428a33 100644 --- a/src/Controller/OgAgent/StatusAction.php +++ b/src/Controller/OgAgent/StatusAction.php @@ -42,7 +42,7 @@ class StatusAction extends AbstractController } try { - $response = $this->httpClient->request('POST', 'https://localhost:4444/ogAdmClient/status', [ + $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [ 'verify_peer' => false, 'verify_host' => false, 'timeout' => 10, @@ -90,7 +90,7 @@ class StatusAction extends AbstractController $partitionEntity->setDiskNumber($cfg['disk']); $partitionEntity->setPartitionNumber($cfg['par']); $partitionEntity->setSize($cfg['tam']); - $partitionEntity->setMemoryUsage($cfg['uso']); + $partitionEntity->setMemoryUsage(((int) $cfg['uso']) * 100); $this->entityManager->persist($partitionEntity); } } diff --git a/src/Controller/OgAgent/Webhook/ClientsController.php b/src/Controller/OgAgent/Webhook/ClientsController.php index a5bb67a..eb79d72 100644 --- a/src/Controller/OgAgent/Webhook/ClientsController.php +++ b/src/Controller/OgAgent/Webhook/ClientsController.php @@ -2,9 +2,13 @@ namespace App\Controller\OgAgent\Webhook; +use App\Controller\OgRepository\Image\CreateAuxFilesAction; use App\Entity\Image; +use App\Entity\OperativeSystem; +use App\Entity\Partition; use App\Entity\Trace; use App\Model\ClientStatus; +use App\Model\ImageStatus; use App\Model\TraceStatus; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -13,21 +17,33 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; +use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] class ClientsController extends AbstractController { public function __construct( - protected readonly EntityManagerInterface $entityManager + protected readonly EntityManagerInterface $entityManager, + public readonly CreateAuxFilesAction $createAuxFilesAction ) { } + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ClientExceptionInterface + */ #[Route('/opengnsys/rest/clients/status/webhook', methods: ['POST'])] public function index(Request $request): JsonResponse { $data = $request->toArray(); - $requiredFields = ['nfn', 'idi', 'dsk', 'par', 'cpt', 'ipr', 'inv_sft', 'ids', 'res', 'der', 'job_id']; + $requiredFields = ['nfn', 'idi', 'dsk', 'par', 'ids', 'res', 'der', 'job_id']; foreach ($requiredFields as $field) { if (!isset($data[$field])) { @@ -42,8 +58,9 @@ class ClientsController extends AbstractController if ($data['res'] === 1) { $trace->setStatus(TraceStatus::SUCCESS); $trace->setFinishedAt(new \DateTime()); - + $image->setStatus(ImageStatus::PENDING); $image->setCreated(true); + $this->createAuxFilesAction->__invoke($image); } else { $trace->setStatus(TraceStatus::FAILED); @@ -59,7 +76,25 @@ class ClientsController extends AbstractController $this->entityManager->persist($trace); $this->entityManager->flush(); + } + if ($data['nfn'] === 'RESPUESTA_RestaurarImagen') { + $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]); + $image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $data['idi']]); + + if ($data['res'] === 1) { + $trace->setStatus(TraceStatus::SUCCESS); + $trace->setFinishedAt(new \DateTime()); + $image->setStatus(ImageStatus::PENDING); + } else { + $trace->setStatus(TraceStatus::FAILED); + $trace->setFinishedAt(new \DateTime()); + $trace->setOutput($data['der']); + } + + $this->entityManager->persist($image); + $this->entityManager->persist($trace); + $this->entityManager->flush(); } return new JsonResponse([], Response::HTTP_OK); diff --git a/src/Controller/OgAgent/Webhook/OgAgentController.php b/src/Controller/OgAgent/Webhook/OgAgentController.php index 082ca13..27f129b 100644 --- a/src/Controller/OgAgent/Webhook/OgAgentController.php +++ b/src/Controller/OgAgent/Webhook/OgAgentController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Controller\OgAgent\Webhook; use App\Entity\Client; +use App\Model\ClientStatus; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -35,6 +36,21 @@ class OgAgentController extends AbstractController } $client = $this->entityManager->getRepository(Client::class)->findOneBy(['mac' => $data['mac']]); + if (!$client) { + return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); + } + + switch ($data['ostype']) { + case 'Linux': + $client->setStatus(ClientStatus::LINUX); + break; + + default: + return new JsonResponse(['message' => 'Invalid status'], Response::HTTP_BAD_REQUEST); + } + + $this->entityManager->persist($client); + $this->entityManager->flush(); return new JsonResponse([], Response::HTTP_OK); } diff --git a/src/Dto/Input/ClientInput.php b/src/Dto/Input/ClientInput.php index c7e22e6..3f07594 100644 --- a/src/Dto/Input/ClientInput.php +++ b/src/Dto/Input/ClientInput.php @@ -151,7 +151,7 @@ final class ClientInput } if ($client->getRepository()) { - $this->repository = $client->getRepository(); + $this->repository = new ImageRepositoryOutput($client->getRepository()); } } diff --git a/src/Dto/Input/ImageInput.php b/src/Dto/Input/ImageInput.php index 4f2ccae..1d29283 100644 --- a/src/Dto/Input/ImageInput.php +++ b/src/Dto/Input/ImageInput.php @@ -11,6 +11,7 @@ use App\Dto\Output\SoftwareProfileOutput; use App\Entity\Image; use App\Entity\OrganizationalUnit; use App\Entity\Partition; +use App\Model\ImageStatus; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; @@ -100,6 +101,7 @@ final class ImageInput $image->setDescription($this->description); $image->setComments($this->comments); $image->setType($this->type); + $image->setStatus(ImageStatus::PENDING); if ($this->softwareProfile) { $image->setSoftwareProfile($this->softwareProfile->getEntity()); diff --git a/src/Dto/Output/ImageOutput.php b/src/Dto/Output/ImageOutput.php index 1f6dbfa..235e88b 100644 --- a/src/Dto/Output/ImageOutput.php +++ b/src/Dto/Output/ImageOutput.php @@ -48,6 +48,12 @@ final class ImageOutput extends AbstractOutput #[Groups(['image:read'])] public ?array $partitionInfo = null; + #[Groups(['image:read'])] + public ?string $imageFullsum = ''; + + #[Groups(['image:read'])] + public ?string $status = null; + #[Groups(['image:read'])] public \DateTime $createdAt; @@ -66,6 +72,8 @@ final class ImageOutput extends AbstractOutput $this->revision = $image->getRevision(); $this->info = $image->getInfo(); $this->size = $image->getSize(); + $this->imageFullsum = $image->getImageFullsum(); + $this->status = $image->getStatus(); $this->softwareProfile = $image->getSoftwareProfile() ? new SoftwareProfileOutput($image->getSoftwareProfile()) : null; $this->imageRepository = $image->getRepository() ? new ImageRepositoryOutput($image->getRepository()) : null; $this->partitionInfo = json_decode($image->getPartitionInfo(), true); diff --git a/src/Dto/Output/TraceOutput.php b/src/Dto/Output/TraceOutput.php index 465da71..e3a9b2d 100644 --- a/src/Dto/Output/TraceOutput.php +++ b/src/Dto/Output/TraceOutput.php @@ -28,6 +28,9 @@ final class TraceOutput extends AbstractOutput #[Groups(['trace:read'])] public ?string $output = null; + #[Groups(['trace:read'])] + public ?array $input = null; + #[Groups(['trace:read'])] public ?\DateTimeInterface $finishedAt = null; @@ -47,6 +50,7 @@ final class TraceOutput extends AbstractOutput $this->jobId = $trace->getJobId(); $this->executedAt = $trace->getExecutedAt(); $this->output = $trace->getOutput(); + $this->input = $trace->getInput(); $this->finishedAt = $trace->getFinishedAt(); $this->createdAt = $trace->getCreatedAt(); $this->createdBy = $trace->getCreatedBy(); diff --git a/src/Entity/Client.php b/src/Entity/Client.php index 0095ac7..8f3ee49 100644 --- a/src/Entity/Client.php +++ b/src/Entity/Client.php @@ -15,6 +15,8 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; #[UniqueEntity(fields: ['mac'], message: 'This MAC address is already in use.')] class Client extends AbstractEntity { + + // TODO nueva variable bool isTeacher use NameableTrait; #[ORM\Column(length: 255, nullable: true)] diff --git a/src/Entity/Image.php b/src/Entity/Image.php index 9f86cac..dc2c8ba 100644 --- a/src/Entity/Image.php +++ b/src/Entity/Image.php @@ -6,8 +6,11 @@ use App\Repository\ImageRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; #[ORM\Entity(repositoryClass: ImageRepository::class)] +#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_NAME', fields: ['name'])] +#[UniqueEntity(fields: ['name'], message: 'validators.image.name.unique')] class Image extends AbstractEntity { use NameableTrait; @@ -56,10 +59,16 @@ class Image extends AbstractEntity #[ORM\Column(nullable: true)] private ?bool $created = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $imageFullsum = null; + + #[ORM\Column(length: 255)] + private ?string $status = null; + + public function __construct() { parent::__construct(); - $this->partitions = new ArrayCollection(); } public function getDescription(): ?string @@ -229,4 +238,28 @@ class Image extends AbstractEntity return $this; } + + public function getImageFullsum(): ?string + { + return $this->imageFullsum; + } + + public function setImageFullsum(?string $imageFullsum): static + { + $this->imageFullsum = $imageFullsum; + + return $this; + } + + public function getStatus(): ?string + { + return $this->status; + } + + public function setStatus(string $status): static + { + $this->status = $status; + + return $this; + } } diff --git a/src/Entity/NetworkSettings.php b/src/Entity/NetworkSettings.php index 7e5a9ac..8ba83ee 100644 --- a/src/Entity/NetworkSettings.php +++ b/src/Entity/NetworkSettings.php @@ -72,6 +72,12 @@ class NetworkSettings extends AbstractEntity #[ORM\ManyToOne] private ?OgLive $ogLive = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $ogLog = null; + + #[ORM\Column(length: 255, nullable: true)] + private ?string $ogShare = null; + public function __construct() { parent::__construct(); @@ -321,4 +327,28 @@ class NetworkSettings extends AbstractEntity return $this; } + + public function getOgLog(): ?string + { + return $this->ogLog; + } + + public function setOgLog(?string $ogLog): static + { + $this->ogLog = $ogLog; + + return $this; + } + + public function getOgShare(): ?string + { + return $this->ogShare; + } + + public function setOgShare(?string $ogShare): static + { + $this->ogShare = $ogShare; + + return $this; + } } diff --git a/src/Entity/Trace.php b/src/Entity/Trace.php index 275c9ef..ae416bf 100644 --- a/src/Entity/Trace.php +++ b/src/Entity/Trace.php @@ -32,6 +32,9 @@ class Trace extends AbstractEntity #[ORM\Column(length: 255, nullable: true)] private ?string $jobId = null; + #[ORM\Column(type: "json", nullable: true)] + private ?array $input = null; + public function getClient(): ?Client { return $this->client; @@ -115,4 +118,16 @@ class Trace extends AbstractEntity return $this; } + + public function getInput(): ?array + { + return $this->input; + } + + public function setInput(?array $input): static + { + $this->input = $input; + + return $this; + } } diff --git a/src/Factory/ImageFactory.php b/src/Factory/ImageFactory.php index 692c49d..80fbdcf 100644 --- a/src/Factory/ImageFactory.php +++ b/src/Factory/ImageFactory.php @@ -35,6 +35,7 @@ final class ImageFactory extends ModelFactory return [ 'createdAt' => self::faker()->dateTime(), 'name' => self::faker()->text(255), + 'status' => self::faker()->randomElement(['IN_PROGRESS', 'FINISHED', 'ERROR']), 'softwareProfile' => SoftwareProfileFactory::new(), 'repository' => ImageRepositoryFactory::new(), 'updatedAt' => self::faker()->dateTime(), diff --git a/src/OpenApi/OpenApiFactory.php b/src/OpenApi/OpenApiFactory.php index 2f4935e..71ce331 100644 --- a/src/OpenApi/OpenApiFactory.php +++ b/src/OpenApi/OpenApiFactory.php @@ -21,7 +21,8 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface $this->addRefreshToken($openApi); $this->addOgAgentEndpoints($openApi); $this->addUDsEndpoints($openApi); - $this->addStatusEndpoint($openApi); + $this->addOgBootStatusEndpoint($openApi); + $this->addOgRepositoryStatusEndpoint($openApi); $this->addInstallOgLiveWebhookEndpoint($openApi); return $openApi; @@ -689,7 +690,7 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface )); } - private function addStatusEndpoint(OpenApi $openApi): void + private function addOgBootStatusEndpoint(OpenApi $openApi): void { $openApi ->getPaths() @@ -738,6 +739,55 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface )); } + private function addOgRepositoryStatusEndpoint(OpenApi $openApi): void + { + $openApi + ->getPaths() + ->addPath('/og-repository/status', (new Model\PathItem())->withGet( + (new Model\Operation('getStatus')) + ->withTags(['OgRepository']) + ->withResponses([ + Response::HTTP_OK => [ + 'description' => 'Service status', + 'content' => [ + 'application/json' => [ + 'schema' => [ + 'type' => 'object', + 'properties' => [ + 'status' => [ + 'type' => 'string', + 'example' => 'ok', + ], + 'uptime' => [ + 'type' => 'integer', + 'example' => 12345, + ], + ], + ], + ], + ], + ], + Response::HTTP_SERVICE_UNAVAILABLE => [ + 'description' => 'Service unavailable', + 'content' => [ + 'application/json' => [ + 'schema' => [ + 'type' => 'object', + 'properties' => [ + 'error' => [ + 'type' => 'string', + 'example' => 'Service is down', + ], + ], + ], + ], + ], + ], + ]) + ->withSummary('Get service status') + )); + } + private function addUDsEndpoints(OpenApi $openApi): void { $openApi->getPaths()->addPath('/opengnsys/rest//ous', (new Model\PathItem())->withGet( From 805fd700261b8fd410d8fe82674dd0b9b8fc9d6c Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Fri, 15 Nov 2024 09:39:56 +0100 Subject: [PATCH 10/26] Improvements in trace --- src/Service/Trace/CreateService.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Service/Trace/CreateService.php b/src/Service/Trace/CreateService.php index c518697..1af179f 100644 --- a/src/Service/Trace/CreateService.php +++ b/src/Service/Trace/CreateService.php @@ -2,7 +2,32 @@ namespace App\Service\Trace; -class CreateService -{ +use App\Entity\Client; +use App\Entity\Command; +use App\Entity\Trace; +use Doctrine\ORM\EntityManagerInterface; +readonly class CreateService +{ + public function __construct( + private EntityManagerInterface $entityManager + ) + { + } + + public function __invoke(Client $client, Command $command, string $status, ?string $jobId = null, array $input): Trace + { + $trace = new Trace(); + $trace->setClient($client); + $trace->setCommand($command ?? null); + $trace->setStatus($status); + $trace->setJobId($jobId); + $trace->setExecutedAt(new \DateTime()); + $trace->setInput($input); + + $this->entityManager->persist($trace); + $this->entityManager->flush(); + + return $trace; + } } \ No newline at end of file From 0ace220ff61835c923974005fa865e30c07120ee Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Fri, 15 Nov 2024 14:27:07 +0100 Subject: [PATCH 11/26] refs #1154. Added env.json --- env.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 env.json diff --git a/env.json b/env.json new file mode 100644 index 0000000..1a246ee --- /dev/null +++ b/env.json @@ -0,0 +1,10 @@ +{ + "vars": { + "OG_BOOT_API_URL": "http:\/\/192.168.18.48", + "OG_DHCP_API_URL": "http:\/\/192.168.18.48:81", + "UDS_AUTH_LOGIN": "Usuarios locales", + "UDS_AUTH_USERNAME": "natiqindel", + "UDS_AUTH_PASSWORD": "correct horse battery staple", + "UDS_URL": "https:\/\/localhost:8087\/uds\/rest\/" + } +} \ No newline at end of file From ace170f1c27978c64b6afaaf1aaa0ccc0b66640f Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Fri, 15 Nov 2024 14:29:19 +0100 Subject: [PATCH 12/26] Revert deploy --- docker-compose-deploy.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker-compose-deploy.yml b/docker-compose-deploy.yml index 8f04f0f..9b10ee4 100644 --- a/docker-compose-deploy.yml +++ b/docker-compose-deploy.yml @@ -40,6 +40,9 @@ services: XDEBUG_CLIENT_HOST: 127.17.0.1 XDEBUG_CLIENT_PORT: 9003 PHP_IDE_CONFIG: serverName=ogcore + volumes: + - ogpublic:/var/www/html/public + networks: - ogcore-network image: opengnsys/ogcore-php:static @@ -47,5 +50,6 @@ services: volumes: database_data: + networks: ogcore-network: From 116a773b6ed75e8edb110bacbc820b808d60ac8c Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Fri, 15 Nov 2024 14:30:59 +0100 Subject: [PATCH 13/26] Add volumes volume files --- docker-compose-deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose-deploy.yml b/docker-compose-deploy.yml index 9b10ee4..4c9bf3b 100644 --- a/docker-compose-deploy.yml +++ b/docker-compose-deploy.yml @@ -42,6 +42,8 @@ services: PHP_IDE_CONFIG: serverName=ogcore volumes: - ogpublic:/var/www/html/public + - /opt/opengnsys/ogCore/etc/.env:/var/www/html/.env + - /opt/opengnsys/ogCore/etc/env.json://var/www/html/env.json networks: - ogcore-network From 404ee80d68e9211ec1bf43072150fdbea61d017a Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Fri, 15 Nov 2024 19:01:49 +0100 Subject: [PATCH 14/26] refs #1154. API env_vars --- config/services.yaml | 12 +--- docker/xdebug.ini | 5 -- src/Controller/EnvDataController.php | 65 +++++++++++++++++++ .../OgBoot/AbstractOgBootController.php | 4 +- .../OgBoot/PxeBootFile/PostAction.php | 21 +++--- .../OgDhcp/AbstractOgDhcpController.php | 2 + .../UDS/RemoteCalendarSyncUdsAction.php | 2 + src/DependencyInjection/JsonEnvVarLoader.php | 31 +++++++++ src/Service/OgBoot/StatusService.php | 4 +- src/Service/OgDhcp/StatusService.php | 6 +- src/Service/UDS/UDSClient.php | 5 ++ 11 files changed, 129 insertions(+), 28 deletions(-) delete mode 100644 docker/xdebug.ini create mode 100644 src/Controller/EnvDataController.php create mode 100644 src/DependencyInjection/JsonEnvVarLoader.php diff --git a/config/services.yaml b/config/services.yaml index 62e58a2..0987229 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -4,22 +4,16 @@ imports: parameters: services: + App\DependencyInjection\JsonEnvVarLoader: + tags: ['container.env_var_loader'] + _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. - bind: - $ogBootApiUrl: '%env(OGBOOT_API_URL)%' - $ogDhcpApiUrl: '%env(OGDHCP_API_URL)%' - $udsAPIurl: '%env(UDS_URL)%' - $udsAuthLogin: '%env(UDS_AUTH_LOGIN)%' - $udsAuthUsername: '%env(UDS_AUTH_USERNAME)%' - $udsAuthPassword: '%env(UDS_AUTH_PASSWORD)%' - App\: resource: '../src/' exclude: - - '../src/DependencyInjection/' - '../src/Entity/' - '../src/Kernel.php' diff --git a/docker/xdebug.ini b/docker/xdebug.ini deleted file mode 100644 index af39592..0000000 --- a/docker/xdebug.ini +++ /dev/null @@ -1,5 +0,0 @@ -xdebug.mode=debug -xdebug.start_with_request=trigger -xdebug.discover_client_host = 1 -xdebug.client_host=${XDEBUG_CLIENT_HOST} -xdebug.client_port=${XDEBUG_CLIENT_PORT} \ No newline at end of file diff --git a/src/Controller/EnvDataController.php b/src/Controller/EnvDataController.php new file mode 100644 index 0000000..c0a0dae --- /dev/null +++ b/src/Controller/EnvDataController.php @@ -0,0 +1,65 @@ +kernel->getProjectDir(); + + $fileName = $projectDir . DIRECTORY_SEPARATOR . self::ENV_VARS_FILE; + if (!is_file($fileName)) { + throw new \RuntimeException('File not found: '.$fileName); + } + + $content = json_decode(file_get_contents($fileName), true); + + return new JsonResponse(['vars' => $content['vars']]); + } + + #[Route('/env-vars', methods: ['POST'])] + public function updateEnvVars(Request $request): JsonResponse + { + $data = json_decode($request->getContent(), true); + $projectDir = $this->kernel->getProjectDir(); + + $fileName = $projectDir . DIRECTORY_SEPARATOR . self::ENV_VARS_FILE; + + if (!isset($data['vars']) || !is_array($data['vars'])) { + return new JsonResponse(['error' => 'Invalid payload'], Response::HTTP_BAD_REQUEST); + } + + $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + + if ($json === false) { + throw new \RuntimeException('Failed to encode JSON: ' . json_last_error_msg()); + } + + if (file_put_contents($fileName, $json) === false) { + throw new \RuntimeException('Failed to write to file: ' . self::ENV_VARS_FILE); + } + + return new JsonResponse(['message' => 'Variables updated successfully']); + } +} diff --git a/src/Controller/OgBoot/AbstractOgBootController.php b/src/Controller/OgBoot/AbstractOgBootController.php index 7e96b1c..942e757 100644 --- a/src/Controller/OgBoot/AbstractOgBootController.php +++ b/src/Controller/OgBoot/AbstractOgBootController.php @@ -6,6 +6,7 @@ namespace App\Controller\OgBoot; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; @@ -20,7 +21,8 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; abstract class AbstractOgBootController extends AbstractController { public function __construct( - protected readonly string $ogBootApiUrl, + #[Autowire(env: 'OG_BOOT_API_URL')] + private string $ogBootApiUrl, protected readonly EntityManagerInterface $entityManager ) { diff --git a/src/Controller/OgBoot/PxeBootFile/PostAction.php b/src/Controller/OgBoot/PxeBootFile/PostAction.php index 506b4b9..01dd970 100644 --- a/src/Controller/OgBoot/PxeBootFile/PostAction.php +++ b/src/Controller/OgBoot/PxeBootFile/PostAction.php @@ -36,23 +36,24 @@ class PostAction extends AbstractOgBootController 'mac' => strtolower($client->getMac()), 'lang' => 'es_ES.UTF_8', 'ip' => $client->getIp(), - 'server_ip' => '192.168.2.4', + //'server_ip' => '192.168.2.4', //rootServer (ogCore) 'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(), 'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0', 'computer_name' => $client->getName(), 'netiface' => $client->getNetiface(), 'group' => $client->getOrganizationalUnit()->getName(), - 'ogrepo' => $client->getRepository() ? $client->getRepository()->getIpAddress() : '192.168.2.4', - 'oglive' => '192.168.2.4', + 'ogrepo' => $client->getRepository() ? $client->getRepository()->getIp() : '192.168.2.4', + //'ogcore' => 'parametro_consola', + //'oglive' => '192.168.2.4', 'oglog' => '192.168.2.4', - 'ogshare' => '192.168.2.4', - 'oglivedir' => 'ogLive', - 'ogprof' => 'false', + //'ogshare' => '192.168.2.4', + 'oglivedir' => $client->getOgLive()->getFilename(), + 'ogprof' => 'false', // cliente del profesor 'hardprofile' => $client->getHardwareProfile() ? $client->getHardwareProfile()->getDescription() : 'default', - 'ogntp' => $client->getOrganizationalUnit()->getNetworkSettings()?->getNtp(), - 'ogdns' => $client->getOrganizationalUnit()->getNetworkSettings()?->getDns(), - 'ogProxy' => $client->getOrganizationalUnit()->getNetworkSettings()?->getProxy(), - 'ogunit' => '', + 'ogntp' => $client->getOrganizationalUnit()->getNetworkSettings()?->getNtp(), //optional + 'ogdns' => $client->getOrganizationalUnit()->getNetworkSettings()?->getDns(), //optional + 'ogProxy' => $client->getOrganizationalUnit()->getNetworkSettings()?->getProxy(), //optional + // 'ogunit' => '', //eliminar 'resolution' => '788' ]; diff --git a/src/Controller/OgDhcp/AbstractOgDhcpController.php b/src/Controller/OgDhcp/AbstractOgDhcpController.php index 2e4e6f5..9166a1e 100644 --- a/src/Controller/OgDhcp/AbstractOgDhcpController.php +++ b/src/Controller/OgDhcp/AbstractOgDhcpController.php @@ -7,6 +7,7 @@ namespace App\Controller\OgDhcp; use App\Service\Utils\GetIpAddressAndNetmaskFromCIDRService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; @@ -21,6 +22,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; abstract class AbstractOgDhcpController extends AbstractController { public function __construct( + #[Autowire(env: 'OG_DHCP_API_URL')] protected readonly string $ogDhcpApiUrl, protected readonly EntityManagerInterface $entityManager, protected readonly GetIpAddressAndNetmaskFromCIDRService $getIpAddressAndNetmaskFromCIDRService diff --git a/src/Controller/UDS/RemoteCalendarSyncUdsAction.php b/src/Controller/UDS/RemoteCalendarSyncUdsAction.php index 019534b..c5ac842 100644 --- a/src/Controller/UDS/RemoteCalendarSyncUdsAction.php +++ b/src/Controller/UDS/RemoteCalendarSyncUdsAction.php @@ -8,6 +8,7 @@ use App\Model\OrganizationalUnitTypes; use App\Service\UDS\UDSClient; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; @@ -16,6 +17,7 @@ class RemoteCalendarSyncUdsAction extends AbstractController { public function __construct( + #[Autowire(env: 'UDS_URL')] private readonly UDSClient $udsClient ) { diff --git a/src/DependencyInjection/JsonEnvVarLoader.php b/src/DependencyInjection/JsonEnvVarLoader.php new file mode 100644 index 0000000..fefa07a --- /dev/null +++ b/src/DependencyInjection/JsonEnvVarLoader.php @@ -0,0 +1,31 @@ +kernel->getProjectDir(); + + $fileName = $projectDir . DIRECTORY_SEPARATOR . self::ENV_VARS_FILE; + if (!is_file($fileName)) { + throw new \RuntimeException('File not found: '.$fileName); + } + + $content = json_decode(file_get_contents($fileName), true); + + return $content['vars']; + } +} \ No newline at end of file diff --git a/src/Service/OgBoot/StatusService.php b/src/Service/OgBoot/StatusService.php index c935e28..021f030 100644 --- a/src/Service/OgBoot/StatusService.php +++ b/src/Service/OgBoot/StatusService.php @@ -2,6 +2,7 @@ namespace App\Service\OgBoot; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; @@ -15,7 +16,8 @@ use Symfony\Component\HttpClient\HttpClient; readonly class StatusService { public function __construct( - private string $ogBootApiUrl + #[Autowire(env: 'OG_BOOT_API_URL')] + private string $ogBootApiUrl ) { } diff --git a/src/Service/OgDhcp/StatusService.php b/src/Service/OgDhcp/StatusService.php index 6e434bf..cc2a352 100644 --- a/src/Service/OgDhcp/StatusService.php +++ b/src/Service/OgDhcp/StatusService.php @@ -2,6 +2,7 @@ namespace App\Service\OgDhcp; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -10,10 +11,11 @@ use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; -class StatusService +readonly class StatusService { public function __construct( - private string $ogDhcpApiUrl + #[Autowire(env: 'OG_DHCP_API_URL')] + private string $ogDhcpApiUrl ) { } diff --git a/src/Service/UDS/UDSClient.php b/src/Service/UDS/UDSClient.php index 3d3f161..a8e79c4 100644 --- a/src/Service/UDS/UDSClient.php +++ b/src/Service/UDS/UDSClient.php @@ -5,6 +5,7 @@ namespace App\Service\UDS; use AllowDynamicProperties; use App\Entity\OrganizationalUnit; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -24,9 +25,13 @@ class UDSClient public function __construct( private HttpClientInterface $httpClient, private readonly EntityManagerInterface $entityManager, + #[Autowire(env: 'UDS_URL')] private string $udsAPIurl, + #[Autowire(env: 'UDS_AUTH_LOGIN')] private string $udsAuthLogin, + #[Autowire(env: 'UDS_AUTH_USERNAME')] private string $udsAuthUsername, + #[Autowire(env: 'UDS_AUTH_PASSWORD')] private string $udsAuthPassword, ) { From 87d16e9d720741498da4069f5b330481080d8601 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 18 Nov 2024 10:08:20 +0100 Subject: [PATCH 15/26] refs #1154. Fixed API env_vars protected var --- composer.lock | 14 +++++++------- src/Controller/OgBoot/AbstractOgBootController.php | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.lock b/composer.lock index e2c3c61..2bfe6d3 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "696433794f1d706f6d16af7589d2c1ea", + "content-hash": "aaa904068da3e39927da2e6658330011", "packages": [ { "name": "api-platform/core", @@ -3768,16 +3768,16 @@ }, { "name": "symfony/dotenv", - "version": "v6.4.10", + "version": "v6.4.13", "source": { "type": "git", "url": "https://github.com/symfony/dotenv.git", - "reference": "2ae0c84cc9be0dc1eeb86016970b63c764d8472e" + "reference": "436ae2dd89360fea8c7d5ff3f48ecf523c80bfb4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dotenv/zipball/2ae0c84cc9be0dc1eeb86016970b63c764d8472e", - "reference": "2ae0c84cc9be0dc1eeb86016970b63c764d8472e", + "url": "https://api.github.com/repos/symfony/dotenv/zipball/436ae2dd89360fea8c7d5ff3f48ecf523c80bfb4", + "reference": "436ae2dd89360fea8c7d5ff3f48ecf523c80bfb4", "shasum": "" }, "require": { @@ -3822,7 +3822,7 @@ "environment" ], "support": { - "source": "https://github.com/symfony/dotenv/tree/v6.4.10" + "source": "https://github.com/symfony/dotenv/tree/v6.4.13" }, "funding": [ { @@ -3838,7 +3838,7 @@ "type": "tidelift" } ], - "time": "2024-07-09T18:29:35+00:00" + "time": "2024-09-28T07:43:51+00:00" }, { "name": "symfony/error-handler", diff --git a/src/Controller/OgBoot/AbstractOgBootController.php b/src/Controller/OgBoot/AbstractOgBootController.php index 942e757..eef632b 100644 --- a/src/Controller/OgBoot/AbstractOgBootController.php +++ b/src/Controller/OgBoot/AbstractOgBootController.php @@ -22,8 +22,8 @@ abstract class AbstractOgBootController extends AbstractController { public function __construct( #[Autowire(env: 'OG_BOOT_API_URL')] - private string $ogBootApiUrl, - protected readonly EntityManagerInterface $entityManager + protected string $ogBootApiUrl, + protected readonly EntityManagerInterface $entityManager ) { } From 8a512f603f63063a0ca2950534ddef4bfd5504b0 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 20 Nov 2024 14:47:45 +0100 Subject: [PATCH 16/26] Publish release if TAG name exists --- Jenkinsfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index c0e936e..802522e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -72,6 +72,10 @@ pipeline { docker.image("${DOCKER_IDENTITY}").push("latest") docker.image("${DOCKER_IDENTITY_NGINX}").push("latest") } + if (env.TAG_NAME) { + docker.image("${DOCKER_IDENTITY}").push("${env.TAG_NAME}") + docker.image("${DOCKER_IDENTITY_NGINX}").push("${env.TAG_NAME}") + } } } } From 5c912654172223952d6036e60765017b2c9ee725 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 20 Nov 2024 14:55:56 +0100 Subject: [PATCH 17/26] Remove debug stuff --- docker/Dockerfile-jenkins-php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docker/Dockerfile-jenkins-php b/docker/Dockerfile-jenkins-php index 370b3c2..2702ee7 100644 --- a/docker/Dockerfile-jenkins-php +++ b/docker/Dockerfile-jenkins-php @@ -19,13 +19,6 @@ ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/do RUN chmod +x /usr/local/bin/install-php-extensions RUN install-php-extensions sockets -# Add xdebug -RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS -RUN apk add --update linux-headers -RUN pecl install xdebug -RUN docker-php-ext-enable xdebug -RUN apk del -f .build-deps -COPY ./docker/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini COPY . /var/www/html From 2f89e5bc578d9decc0c1f44d7382561d0dd0c567 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 20 Nov 2024 16:00:44 +0100 Subject: [PATCH 18/26] Updated APIS, and general improvements --- config/api_platform/Image.yaml | 17 +++-- env.json | 5 +- migrations/Version20241120050107.php | 35 +++++++++ src/Controller/DeployImageAction.php | 36 ++-------- src/Controller/OgAgent/CreateImageAction.php | 7 +- src/Controller/OgAgent/DeployImageAction.php | 8 ++- src/Controller/OgAgent/StatusAction.php | 71 ++++++++++++------- .../OgAgent/Webhook/AgentController.php | 26 ++----- .../OgAgent/Webhook/ClientsController.php | 46 ++++++++++-- .../OgBoot/AbstractOgBootController.php | 2 + src/Controller/OgBoot/OgLive/GetAction.php | 2 +- .../OgBoot/OgLive/GetCollectionAction.php | 2 +- .../OgBoot/OgLive/GetDefaultAction.php | 2 +- .../OgBoot/OgLive/GetIsosAction.php | 2 +- .../OgBoot/OgLive/InstallAction.php | 2 +- .../OgBoot/OgLive/SetDefaultAction.php | 2 +- src/Controller/OgBoot/OgLive/SyncAction.php | 2 +- .../OgBoot/OgLive/UninstallAction.php | 2 +- .../OgBoot/PxeBootFile/GetAction.php | 2 +- .../PxeBootFile/GetCollectionAction.php | 2 +- .../OgBoot/PxeBootFile/PostAction.php | 17 ++--- .../OgBoot/PxeTemplate/DeleteAction.php | 2 +- .../OgBoot/PxeTemplate/GetAction.php | 2 +- .../PxeTemplate/GetCollectionAction.php | 2 +- .../OgBoot/PxeTemplate/PostAction.php | 2 +- .../OgBoot/PxeTemplate/SyncAction.php | 2 +- .../OgDhcp/AbstractOgDhcpController.php | 2 +- src/Controller/OgDhcp/Subnet/DeleteAction.php | 2 +- .../OgDhcp/Subnet/DeleteHostAction.php | 2 +- src/Controller/OgDhcp/Subnet/GetAction.php | 2 +- .../OgDhcp/Subnet/GetCollectionAction.php | 2 +- .../OgDhcp/Subnet/GetHostsAction.php | 2 +- src/Controller/OgDhcp/Subnet/PostAction.php | 2 +- .../OgDhcp/Subnet/PostHostAction.php | 2 +- src/Controller/OgDhcp/Subnet/PutAction.php | 2 +- .../OgDhcp/Subnet/PutHostAction.php | 2 +- src/Controller/OgDhcp/Subnet/SyncAction.php | 2 +- .../Image/CreateAuxFilesAction.php | 4 +- .../Image/DeletePermanentAction.php | 2 +- .../OgRepository/Image/DeleteTrashAction.php | 2 +- .../OgRepository/Image/DeployImageAction.php | 6 +- .../OgRepository/Image/RecoverAction.php | 51 +++++++++++++ src/Dto/Input/NetworkSettingsInput.php | 10 +++ src/Dto/Output/NetworkSettingsOutput.php | 8 +++ src/Dto/Output/TraceOutput.php | 4 +- src/Entity/Trace.php | 9 ++- src/Model/CommandTypes.php | 38 ++++++++++ src/Model/ImageStatus.php | 2 + src/Service/CreatePartitionService.php | 50 +++++++++++++ src/Service/Trace/CreateService.php | 4 +- src/State/Processor/ImageProcessor.php | 2 +- translations/validators.en.yaml | 1 + translations/validators.es.yaml | 1 + 53 files changed, 375 insertions(+), 141 deletions(-) create mode 100644 migrations/Version20241120050107.php create mode 100644 src/Controller/OgRepository/Image/RecoverAction.php create mode 100644 src/Model/CommandTypes.php create mode 100644 src/Service/CreatePartitionService.php diff --git a/config/api_platform/Image.yaml b/config/api_platform/Image.yaml index a338c1e..8aea897 100644 --- a/config/api_platform/Image.yaml +++ b/config/api_platform/Image.yaml @@ -51,8 +51,8 @@ resources: trash_delete_image_ogrepository: shortName: OgRepository Server description: Delete Image in OgRepository - class: ApiPlatform\Metadata\Delete - method: DELETE + class: ApiPlatform\Metadata\Post + method: POST input: false uriTemplate: /images/server/{uuid}/delete-trash controller: App\Controller\OgRepository\Image\DeleteTrashAction @@ -60,12 +60,21 @@ resources: permanent_delete_image_ogrepository: shortName: OgRepository Server description: Delete Image in OgRepository - class: ApiPlatform\Metadata\Delete - method: DELETE + class: ApiPlatform\Metadata\Post + method: POST input: false uriTemplate: /images/server/{uuid}/delete-permanent controller: App\Controller\OgRepository\Image\DeletePermanentAction + recover_image_ogrepository: + shortName: OgRepository Server + description: Recover Image in OgRepository + class: ApiPlatform\Metadata\Post + method: POST + input: false + uriTemplate: /images/server/{uuid}/recover + controller: App\Controller\OgRepository\Image\RecoverAction + properties: App\Entity\Image: id: diff --git a/env.json b/env.json index 1a246ee..d5d8034 100644 --- a/env.json +++ b/env.json @@ -1,7 +1,8 @@ { "vars": { - "OG_BOOT_API_URL": "http:\/\/192.168.18.48", - "OG_DHCP_API_URL": "http:\/\/192.168.18.48:81", + "OG_BOOT_API_URL": "192.168.68.58", + "OG_DHCP_API_URL": "192.168.68.58:81", + "OG_CORE_IP": "192.168.68.62", "UDS_AUTH_LOGIN": "Usuarios locales", "UDS_AUTH_USERNAME": "natiqindel", "UDS_AUTH_PASSWORD": "correct horse battery staple", diff --git a/migrations/Version20241120050107.php b/migrations/Version20241120050107.php new file mode 100644 index 0000000..3b0b972 --- /dev/null +++ b/migrations/Version20241120050107.php @@ -0,0 +1,35 @@ +addSql('ALTER TABLE trace DROP FOREIGN KEY FK_315BD5A133E1689A'); + $this->addSql('DROP INDEX IDX_315BD5A133E1689A ON trace'); + $this->addSql('ALTER TABLE trace ADD command VARCHAR(255) DEFAULT NULL, DROP command_id'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE trace ADD command_id INT NOT NULL, DROP command'); + $this->addSql('ALTER TABLE trace ADD CONSTRAINT FK_315BD5A133E1689A FOREIGN KEY (command_id) REFERENCES command (id)'); + $this->addSql('CREATE INDEX IDX_315BD5A133E1689A ON trace (command_id)'); + } +} diff --git a/src/Controller/DeployImageAction.php b/src/Controller/DeployImageAction.php index e61f4f3..7b8cf9e 100644 --- a/src/Controller/DeployImageAction.php +++ b/src/Controller/DeployImageAction.php @@ -8,6 +8,7 @@ use App\Dto\Input\DeployImageInput; use App\Entity\Command; use App\Entity\Image; use App\Entity\OrganizationalUnit; +use App\Model\CommandTypes; use App\Model\DeployMethodTypes; use App\Model\TraceStatus; use App\Service\Trace\CreateService; @@ -32,8 +33,6 @@ class DeployImageAction extends AbstractController public function __invoke(DeployImageInput $input, Image $image): JsonResponse { - $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Restaurar Imagen']); - $partitionInfo = json_decode($image->getPartitionInfo(), true); $inputData = [ @@ -52,43 +51,18 @@ class DeployImageAction extends AbstractController switch ($input->method){ case DeployMethodTypes::UNICAST: - $data = [ - 'dsk' => (string) $partitionInfo['numDisk'], - 'par' => (string) $partitionInfo['numPartition'], - 'ifs' => "1", - 'cpt' => "83", - 'idi' => $image->getUuid(), - 'nci' => $image->getName(), - 'ipr' => $image->getRepository()->getIp(), - 'nfn' => 'RestaurarImagen', - 'ptc' => DeployMethodTypes::UNICAST, - 'ids' => '0' - ]; - - $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $command, $input->client->getEntity()); - $this->createService->__invoke($input->client->getEntity(), $command, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); + $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::UNICAST); + $this->createService->__invoke($input->client->getEntity(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); break; case DeployMethodTypes::MULTICAST: - $data = [ - 'dsk' => (string) $image->getPartitionInfo()['numDisk'], - 'par' => (string) $image->getPartitionInfo()['numPartition'], - 'cpt' => "83", - 'idi' => $image->getUuid(), - 'nci' => $image->getName(), - 'ipr' => $image->getRepository()->getIp(), - 'nfn' => 'CrearImagen', - 'ids' => '0' - ]; - - $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $command); - $this->createService->__invoke($image->getClient(), $command, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); + $agentJobId = $this->deployImageOgAgentAction->__invoke($image, $input, DeployMethodTypes::MULTICAST); + $this->createService->__invoke($image->getClient(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, $agentJobId, $inputData); break; } - return new JsonResponse(data: [], status: Response::HTTP_OK); } } diff --git a/src/Controller/OgAgent/CreateImageAction.php b/src/Controller/OgAgent/CreateImageAction.php index abdec18..4e01293 100644 --- a/src/Controller/OgAgent/CreateImageAction.php +++ b/src/Controller/OgAgent/CreateImageAction.php @@ -9,6 +9,8 @@ use App\Entity\Command; use App\Entity\Image; use App\Entity\Trace; use App\Model\ClientStatus; +use App\Model\CommandTypes; +use App\Model\ImageStatus; use App\Model\TraceStatus; use App\Service\Trace\CreateService; use Doctrine\ORM\EntityManagerInterface; @@ -71,14 +73,15 @@ class CreateImageAction extends AbstractController $jobId = json_decode($response->getContent(), true)['job_id']; - $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Crear Imagen']); + $image->setStatus(ImageStatus::IN_PROGRESS); + $this->entityManager->persist($image); $client = $image->getClient(); $client->setStatus(ClientStatus::BUSY); $this->entityManager->persist($client); $this->entityManager->flush(); - $this->createService->__invoke($image->getClient(), $command, TraceStatus::IN_PROGRESS, $jobId, []); + $this->createService->__invoke($image->getClient(), CommandTypes::CREATE_IMAGE, TraceStatus::IN_PROGRESS, $jobId, []); return new JsonResponse(data: $image, status: Response::HTTP_OK); } diff --git a/src/Controller/OgAgent/DeployImageAction.php b/src/Controller/OgAgent/DeployImageAction.php index 0d3e7d3..c8e2d01 100644 --- a/src/Controller/OgAgent/DeployImageAction.php +++ b/src/Controller/OgAgent/DeployImageAction.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Controller\OgAgent; +use App\Dto\Input\DeployImageInput; use App\Entity\Client; use App\Entity\Command; use App\Entity\Image; @@ -34,7 +35,7 @@ class DeployImageAction extends AbstractController } - public function __invoke(Image $image, Command $command, Client $client) + public function __invoke(Image $image, DeployImageInput $input, string $method) { if (!$image->getClient()->getIp()) { throw new ValidatorException('IP is required'); @@ -42,6 +43,9 @@ class DeployImageAction extends AbstractController $partitionInfo = json_decode($image->getPartitionInfo(), true); + /** @var Client $client */ + $client = $input->client->getEntity(); + $data = [ 'dsk' => (string) $partitionInfo['numDisk'], 'par' => (string) $partitionInfo['numPartition'], @@ -50,7 +54,7 @@ class DeployImageAction extends AbstractController 'nci' => $image->getName(), 'ipr' => $image->getRepository()->getIp(), 'nfn' => 'RestaurarImagen', - 'ptc' => 'unicast', + 'ptc' => $method, 'ids' => '0' ]; diff --git a/src/Controller/OgAgent/StatusAction.php b/src/Controller/OgAgent/StatusAction.php index 5428a33..a8f7211 100644 --- a/src/Controller/OgAgent/StatusAction.php +++ b/src/Controller/OgAgent/StatusAction.php @@ -7,6 +7,7 @@ use App\Entity\OperativeSystem; use App\Entity\Partition; use App\Model\ClientStatus; use App\Model\OgLiveStatus; +use App\Service\CreatePartitionService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpClient\HttpClient; @@ -26,7 +27,8 @@ class StatusAction extends AbstractController { public function __construct( protected readonly EntityManagerInterface $entityManager, - protected readonly HttpClientInterface $httpClient + protected readonly HttpClientInterface $httpClient, + protected readonly CreatePartitionService $createPartitionService ) {} /** @@ -41,6 +43,17 @@ class StatusAction extends AbstractController throw new ValidatorException('IP is required'); } + if ($client->getStatus() === ClientStatus::OG_LIVE) { + $this->getOgLiveStatus($client); + } + + if ($client->getStatus() === ClientStatus::LINUX) { + $this->getSOStatus($client); + } + } + + public function getOgLiveStatus (Client $client): JsonResponse + { try { $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [ 'verify_peer' => false, @@ -66,33 +79,43 @@ class StatusAction extends AbstractController $data = json_decode($response->getContent(), true); if (isset($data['cfg'])) { - foreach ($data['cfg'] as $cfg) { - $partitionEntity = $this->entityManager->getRepository(Partition::class) - ->findOneBy(['client' => $client, 'diskNumber' => $cfg['disk'], 'partitionNumber' => $cfg['par']]); + $this->createPartitionService->__invoke($data, $client); + } - if (!$partitionEntity) { - $partitionEntity = new Partition(); - } + $this->entityManager->persist($client); + $this->entityManager->flush(); - if (isset($cfg['soi']) && $cfg['soi'] !== '') { - $operativeSystem = $this->entityManager->getRepository(OperativeSystem::class) - ->findOneBy(['name' => $cfg['soi']]); + return new JsonResponse(status: Response::HTTP_OK); + } - if (!$operativeSystem) { - $operativeSystem = new OperativeSystem(); - $operativeSystem->setName($cfg['soi']); - $this->entityManager->persist($operativeSystem); - } - $partitionEntity->setOperativeSystem($operativeSystem); - } + public function getSOStatus (Client $client): JsonResponse + { + try { + $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/status', [ + 'verify_peer' => false, + 'verify_host' => false, + 'timeout' => 10, + 'headers' => [ + 'Content-Type' => 'application/json', + ], + 'json' => [], + ]); + $statusCode = $response->getStatusCode(); + $client->setStatus($statusCode === Response::HTTP_OK ? ClientStatus::LINUX : ClientStatus::OFF); - $partitionEntity->setClient($client); - $partitionEntity->setDiskNumber($cfg['disk']); - $partitionEntity->setPartitionNumber($cfg['par']); - $partitionEntity->setSize($cfg['tam']); - $partitionEntity->setMemoryUsage(((int) $cfg['uso']) * 100); - $this->entityManager->persist($partitionEntity); - } + } catch (TransportExceptionInterface $e) { + $client->setStatus(ClientStatus::OFF); + + return new JsonResponse( + data: ['error' => $e->getMessage()], + status: Response::HTTP_INTERNAL_SERVER_ERROR + ); + } + + $data = json_decode($response->getContent(), true); + + if (isset($data['cfg'])) { + $this->createPartitionService->__invoke($data, $client); } $this->entityManager->persist($client); diff --git a/src/Controller/OgAgent/Webhook/AgentController.php b/src/Controller/OgAgent/Webhook/AgentController.php index 0d459ed..4ed9f5d 100644 --- a/src/Controller/OgAgent/Webhook/AgentController.php +++ b/src/Controller/OgAgent/Webhook/AgentController.php @@ -7,6 +7,7 @@ namespace App\Controller\OgAgent\Webhook; use App\Entity\Client; use App\Entity\OrganizationalUnit; use App\Entity\Partition; +use App\Service\CreatePartitionService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -19,7 +20,8 @@ use Symfony\Component\Routing\Attribute\Route; class AgentController extends AbstractController { public function __construct( - protected readonly EntityManagerInterface $entityManager + protected readonly EntityManagerInterface $entityManager, + protected readonly CreatePartitionService $createPartitionService ) { } @@ -42,26 +44,10 @@ class AgentController extends AbstractController return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); } - foreach ($data['cfg'] as $cfg) { - if (isset($cfg['disk']) && isset($cfg['par'])) { - $partitionEntity = $this->entityManager->getRepository(Partition::class) - ->findOneBy(['client' => $clientEntity, 'diskNumber' => $cfg['disk'], 'partitionNumber' => $cfg['par']]); - - if (!$partitionEntity) { - $partitionEntity = new Partition(); - } - - $partitionEntity->setClient($clientEntity); - $partitionEntity->setDiskNumber((int)$cfg['disk']); - $partitionEntity->setPartitionNumber((int) $cfg['par']); - $partitionEntity->setSize((int) $cfg['tam'] ?? null); - $partitionEntity->setMemoryUsage((int) $cfg['uso'] * 100 ?? null); - $partitionEntity->setFileSystem($cfg['fsi'] ?? null); - - $this->entityManager->persist($partitionEntity); - } + if (isset($data['cfg'])) { + $this->createPartitionService->__invoke($data, $clientEntity); } - + $this->entityManager->flush(); $center = $this->entityManager->getRepository(OrganizationalUnit::class)->find($clientEntity->getOrganizationalUnit()->getId()); diff --git a/src/Controller/OgAgent/Webhook/ClientsController.php b/src/Controller/OgAgent/Webhook/ClientsController.php index eb79d72..2ceb9ee 100644 --- a/src/Controller/OgAgent/Webhook/ClientsController.php +++ b/src/Controller/OgAgent/Webhook/ClientsController.php @@ -6,10 +6,14 @@ use App\Controller\OgRepository\Image\CreateAuxFilesAction; use App\Entity\Image; use App\Entity\OperativeSystem; use App\Entity\Partition; +use App\Entity\Software; +use App\Entity\SoftwareProfile; use App\Entity\Trace; use App\Model\ClientStatus; use App\Model\ImageStatus; +use App\Model\SoftwareTypes; use App\Model\TraceStatus; +use App\Service\CreatePartitionService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -28,7 +32,8 @@ class ClientsController extends AbstractController { public function __construct( protected readonly EntityManagerInterface $entityManager, - public readonly CreateAuxFilesAction $createAuxFilesAction + public readonly CreateAuxFilesAction $createAuxFilesAction, + protected readonly CreatePartitionService $createPartitionService ) { } @@ -55,18 +60,24 @@ class ClientsController extends AbstractController $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]); $image = $this->entityManager->getRepository(Image::class)->findOneBy(['uuid' => $data['idi']]); + if (!$image) { + return new JsonResponse(['message' => 'Image not found'], Response::HTTP_NOT_FOUND); + } + if ($data['res'] === 1) { $trace->setStatus(TraceStatus::SUCCESS); $trace->setFinishedAt(new \DateTime()); - $image->setStatus(ImageStatus::PENDING); + $image->setStatus(ImageStatus::AUX_FILES_PENDING); $image->setCreated(true); + if (isset($data['cfg'])) { + $this->createPartitionService->__invoke($data, $image->getClient()); + } + $this->createSoftwareProfile($data['inv_sft'], $image); $this->createAuxFilesAction->__invoke($image); - } else { $trace->setStatus(TraceStatus::FAILED); $trace->setFinishedAt(new \DateTime()); $trace->setOutput($data['der']); - $image->setCreated(false); } $this->entityManager->persist($image); @@ -99,4 +110,31 @@ class ClientsController extends AbstractController return new JsonResponse([], Response::HTTP_OK); } + + public function createSoftwareProfile (string $base64Data, Image $image): void + { + $decodedData = base64_decode($base64Data); + + $softwareList = explode("\n", $decodedData); + + $softwareProfile = new SoftwareProfile(); + $softwareProfile->setDescription('Perfil : '.$image->getName()); + $softwareProfile->setOrganizationalUnit($image->getClient()->getOrganizationalUnit()); + + foreach ($softwareList as $software) { + $software = trim($software); + $softwareEntity = $this->entityManager->getRepository(Software::class)->findOneBy(['name' => $software]); + if (!$softwareEntity) { + $softwareEntity = new Software(); + $softwareEntity->setName($software); + $softwareEntity->setType(SoftwareTypes::APPLICATION); + $this->entityManager->persist($softwareEntity); + } + + $softwareEntity->addSoftwareProfile($softwareProfile); + } + + $this->entityManager->persist($softwareProfile); + $this->entityManager->flush(); + } } \ No newline at end of file diff --git a/src/Controller/OgBoot/AbstractOgBootController.php b/src/Controller/OgBoot/AbstractOgBootController.php index eef632b..ee8b178 100644 --- a/src/Controller/OgBoot/AbstractOgBootController.php +++ b/src/Controller/OgBoot/AbstractOgBootController.php @@ -23,6 +23,8 @@ abstract class AbstractOgBootController extends AbstractController public function __construct( #[Autowire(env: 'OG_BOOT_API_URL')] protected string $ogBootApiUrl, + #[Autowire(env: 'OG_CORE_IP')] + protected string $ogCoreIP, protected readonly EntityManagerInterface $entityManager ) { diff --git a/src/Controller/OgBoot/OgLive/GetAction.php b/src/Controller/OgBoot/OgLive/GetAction.php index 8635aee..54ebe45 100644 --- a/src/Controller/OgBoot/OgLive/GetAction.php +++ b/src/Controller/OgBoot/OgLive/GetAction.php @@ -29,7 +29,7 @@ class GetAction extends AbstractOgBootController throw new ValidatorException('Checksum is required'); } - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/GetCollectionAction.php b/src/Controller/OgBoot/OgLive/GetCollectionAction.php index 930b237..41cacdf 100644 --- a/src/Controller/OgBoot/OgLive/GetCollectionAction.php +++ b/src/Controller/OgBoot/OgLive/GetCollectionAction.php @@ -24,7 +24,7 @@ class GetCollectionAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/GetDefaultAction.php b/src/Controller/OgBoot/OgLive/GetDefaultAction.php index 94f3456..3c77859 100644 --- a/src/Controller/OgBoot/OgLive/GetDefaultAction.php +++ b/src/Controller/OgBoot/OgLive/GetDefaultAction.php @@ -23,7 +23,7 @@ class GetDefaultAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/default'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default'); return new JsonResponse(status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/GetIsosAction.php b/src/Controller/OgBoot/OgLive/GetIsosAction.php index 90ddb19..1acdbd2 100644 --- a/src/Controller/OgBoot/OgLive/GetIsosAction.php +++ b/src/Controller/OgBoot/OgLive/GetIsosAction.php @@ -24,7 +24,7 @@ class GetIsosAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/isos'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/isos'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/OgLive/InstallAction.php b/src/Controller/OgBoot/OgLive/InstallAction.php index e2bbe17..07b68ac 100644 --- a/src/Controller/OgBoot/OgLive/InstallAction.php +++ b/src/Controller/OgBoot/OgLive/InstallAction.php @@ -38,7 +38,7 @@ class InstallAction extends AbstractOgBootController ] ]; - $content = $this->createRequest($httpClient, 'POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params); + $content = $this->createRequest($httpClient, 'POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params); $data->setStatus(OgLiveStatus::PENDING); $entityManager->persist($data); diff --git a/src/Controller/OgBoot/OgLive/SetDefaultAction.php b/src/Controller/OgBoot/OgLive/SetDefaultAction.php index 3cf7184..896ac3b 100644 --- a/src/Controller/OgBoot/OgLive/SetDefaultAction.php +++ b/src/Controller/OgBoot/OgLive/SetDefaultAction.php @@ -36,7 +36,7 @@ class SetDefaultAction extends AbstractOgBootController ] ]; - $content = $this->createRequest($httpClient, 'PUT', $this->ogBootApiUrl.'/ogboot/v1/oglives/default', $params); + $content = $this->createRequest($httpClient, 'PUT', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/default', $params); $oldDefaultOgLive = $this->entityManager->getRepository(OgLive::class)->findBy(['isDefault' => true]); diff --git a/src/Controller/OgBoot/OgLive/SyncAction.php b/src/Controller/OgBoot/OgLive/SyncAction.php index 0c036a2..791dba5 100644 --- a/src/Controller/OgBoot/OgLive/SyncAction.php +++ b/src/Controller/OgBoot/OgLive/SyncAction.php @@ -27,7 +27,7 @@ class SyncAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl . '/ogboot/v1/oglives'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/oglives'); foreach ($content['message']['installed_ogLives'] as $ogLive) { $ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]); diff --git a/src/Controller/OgBoot/OgLive/UninstallAction.php b/src/Controller/OgBoot/OgLive/UninstallAction.php index d0ea542..70b3c0b 100644 --- a/src/Controller/OgBoot/OgLive/UninstallAction.php +++ b/src/Controller/OgBoot/OgLive/UninstallAction.php @@ -31,7 +31,7 @@ class UninstallAction extends AbstractOgBootController throw new ValidatorException('Checksum is required'); } - $content = $this->createRequest($httpClient, 'DELETE', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); + $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); $entityManager->remove($data); $entityManager->flush(); diff --git a/src/Controller/OgBoot/PxeBootFile/GetAction.php b/src/Controller/OgBoot/PxeBootFile/GetAction.php index 7f51e2b..4f4fb02 100644 --- a/src/Controller/OgBoot/PxeBootFile/GetAction.php +++ b/src/Controller/OgBoot/PxeBootFile/GetAction.php @@ -27,7 +27,7 @@ class GetAction extends AbstractOgBootController public function __invoke(Client $client, HttpClientInterface $httpClient): JsonResponse { try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxes/'.$client->getMac(), [ + $response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes/'.$client->getMac(), [ 'headers' => [ 'accept' => 'application/json', ], diff --git a/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php b/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php index f870364..3d53a9f 100644 --- a/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php +++ b/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php @@ -26,7 +26,7 @@ class GetCollectionAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/pxes'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/PxeBootFile/PostAction.php b/src/Controller/OgBoot/PxeBootFile/PostAction.php index 01dd970..1bc03ba 100644 --- a/src/Controller/OgBoot/PxeBootFile/PostAction.php +++ b/src/Controller/OgBoot/PxeBootFile/PostAction.php @@ -36,19 +36,20 @@ class PostAction extends AbstractOgBootController 'mac' => strtolower($client->getMac()), 'lang' => 'es_ES.UTF_8', 'ip' => $client->getIp(), - //'server_ip' => '192.168.2.4', //rootServer (ogCore) + 'server_ip' => $this->ogBootApiUrl, 'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(), 'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0', 'computer_name' => $client->getName(), 'netiface' => $client->getNetiface(), 'group' => $client->getOrganizationalUnit()->getName(), - 'ogrepo' => $client->getRepository() ? $client->getRepository()->getIp() : '192.168.2.4', - //'ogcore' => 'parametro_consola', - //'oglive' => '192.168.2.4', - 'oglog' => '192.168.2.4', - //'ogshare' => '192.168.2.4', + 'ogrepo' => $client->getRepository()->getIp() , + 'ogcore' => $this->ogCoreIP, + 'oglive' => $this->ogBootApiUrl, + 'oglog' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgLog(), + 'ogshare' => $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare() + ? $client->getOrganizationalUnit()->getNetworkSettings()?->getOgShare(): $this->ogBootApiUrl, 'oglivedir' => $client->getOgLive()->getFilename(), - 'ogprof' => 'false', // cliente del profesor + 'ogprof' => 'false', 'hardprofile' => $client->getHardwareProfile() ? $client->getHardwareProfile()->getDescription() : 'default', 'ogntp' => $client->getOrganizationalUnit()->getNetworkSettings()?->getNtp(), //optional 'ogdns' => $client->getOrganizationalUnit()->getNetworkSettings()?->getDns(), //optional @@ -58,7 +59,7 @@ class PostAction extends AbstractOgBootController ]; try { - $response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/pxes', [ + $response = $httpClient->request('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxes', [ 'headers' => [ 'accept' => 'application/json', 'Content-Type' => 'application/json', diff --git a/src/Controller/OgBoot/PxeTemplate/DeleteAction.php b/src/Controller/OgBoot/PxeTemplate/DeleteAction.php index ba6c49d..eb42411 100644 --- a/src/Controller/OgBoot/PxeTemplate/DeleteAction.php +++ b/src/Controller/OgBoot/PxeTemplate/DeleteAction.php @@ -27,7 +27,7 @@ class DeleteAction extends AbstractOgBootController public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { try { - $response = $httpClient->request('DELETE', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName(), [ + $response = $httpClient->request('DELETE', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName(), [ 'headers' => [ 'accept' => 'application/json', ], diff --git a/src/Controller/OgBoot/PxeTemplate/GetAction.php b/src/Controller/OgBoot/PxeTemplate/GetAction.php index 5bbc2c0..6a61c17 100644 --- a/src/Controller/OgBoot/PxeTemplate/GetAction.php +++ b/src/Controller/OgBoot/PxeTemplate/GetAction.php @@ -26,7 +26,7 @@ class GetAction extends AbstractOgBootController public function __invoke(PxeTemplate $template, HttpClientInterface $httpClient): JsonResponse { try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$template->getName(), [ + $response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$template->getName(), [ 'headers' => [ 'accept' => 'application/json', ], diff --git a/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php b/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php index c294cae..623c8d3 100644 --- a/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php +++ b/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php @@ -25,7 +25,7 @@ class GetCollectionAction extends AbstractOgBootController public function __invoke(HttpClientInterface $httpClient): JsonResponse { try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [ + $response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [ 'headers' => [ 'accept' => 'application/json', ], diff --git a/src/Controller/OgBoot/PxeTemplate/PostAction.php b/src/Controller/OgBoot/PxeTemplate/PostAction.php index a448bf1..e6fd198 100644 --- a/src/Controller/OgBoot/PxeTemplate/PostAction.php +++ b/src/Controller/OgBoot/PxeTemplate/PostAction.php @@ -27,7 +27,7 @@ class PostAction extends AbstractOgBootController public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { try { - $response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [ + $response = $httpClient->request('POST', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [ 'headers' => [ 'accept' => 'application/json', 'Content-Type' => 'application/json', diff --git a/src/Controller/OgBoot/PxeTemplate/SyncAction.php b/src/Controller/OgBoot/PxeTemplate/SyncAction.php index 50746bd..8d85270 100644 --- a/src/Controller/OgBoot/PxeTemplate/SyncAction.php +++ b/src/Controller/OgBoot/PxeTemplate/SyncAction.php @@ -28,7 +28,7 @@ class SyncAction extends AbstractOgBootController */ public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl . '/ogboot/v1/pxe-templates'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogBootApiUrl . '/ogboot/v1/pxe-templates'); foreach ($content['message'] as $template) { $templateEntity = $this->entityManager->getRepository(PxeTemplate::class)->findOneBy(['name' => $template]); diff --git a/src/Controller/OgDhcp/AbstractOgDhcpController.php b/src/Controller/OgDhcp/AbstractOgDhcpController.php index 9166a1e..9288698 100644 --- a/src/Controller/OgDhcp/AbstractOgDhcpController.php +++ b/src/Controller/OgDhcp/AbstractOgDhcpController.php @@ -25,7 +25,7 @@ abstract class AbstractOgDhcpController extends AbstractController #[Autowire(env: 'OG_DHCP_API_URL')] protected readonly string $ogDhcpApiUrl, protected readonly EntityManagerInterface $entityManager, - protected readonly GetIpAddressAndNetmaskFromCIDRService $getIpAddressAndNetmaskFromCIDRService + protected readonly GetIpAddressAndNetmaskFromCIDRService $getIpAddressAndNetmaskFromCIDRService, ) { } diff --git a/src/Controller/OgDhcp/Subnet/DeleteAction.php b/src/Controller/OgDhcp/Subnet/DeleteAction.php index a00555a..7b9554c 100644 --- a/src/Controller/OgDhcp/Subnet/DeleteAction.php +++ b/src/Controller/OgDhcp/Subnet/DeleteAction.php @@ -29,7 +29,7 @@ class DeleteAction extends AbstractOgDhcpController throw new ValidatorException('Data Id is required'); } - $content = $this->createRequest($httpClient, 'DELETE', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId()); + $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId()); $this->entityManager->remove($data); $this->entityManager->flush(); diff --git a/src/Controller/OgDhcp/Subnet/DeleteHostAction.php b/src/Controller/OgDhcp/Subnet/DeleteHostAction.php index cf32b80..8b2c251 100644 --- a/src/Controller/OgDhcp/Subnet/DeleteHostAction.php +++ b/src/Controller/OgDhcp/Subnet/DeleteHostAction.php @@ -42,7 +42,7 @@ class DeleteHostAction extends AbstractOgDhcpController ] ]; - $content = $this->createRequest($httpClient, 'DELETE', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId().'/hosts', $params); + $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId().'/hosts', $params); $data->removeClient($client); $this->entityManager->persist($data); diff --git a/src/Controller/OgDhcp/Subnet/GetAction.php b/src/Controller/OgDhcp/Subnet/GetAction.php index 77f1bce..257e26b 100644 --- a/src/Controller/OgDhcp/Subnet/GetAction.php +++ b/src/Controller/OgDhcp/Subnet/GetAction.php @@ -29,7 +29,7 @@ class GetAction extends AbstractOgDhcpController throw new ValidatorException('Checksum is required'); } - $content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId()); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId()); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgDhcp/Subnet/GetCollectionAction.php b/src/Controller/OgDhcp/Subnet/GetCollectionAction.php index 9f9324c..95381d0 100644 --- a/src/Controller/OgDhcp/Subnet/GetCollectionAction.php +++ b/src/Controller/OgDhcp/Subnet/GetCollectionAction.php @@ -23,7 +23,7 @@ class GetCollectionAction extends AbstractOgDhcpController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl . '/ogdhcp/v1/subnets'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogDhcpApiUrl . '/ogdhcp/v1/subnets'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgDhcp/Subnet/GetHostsAction.php b/src/Controller/OgDhcp/Subnet/GetHostsAction.php index 52ca307..8056945 100644 --- a/src/Controller/OgDhcp/Subnet/GetHostsAction.php +++ b/src/Controller/OgDhcp/Subnet/GetHostsAction.php @@ -29,7 +29,7 @@ class GetHostsAction extends AbstractOgDhcpController throw new ValidatorException('Checksum is required'); } - $content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId().'/hosts'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId().'/hosts'); return new JsonResponse(data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgDhcp/Subnet/PostAction.php b/src/Controller/OgDhcp/Subnet/PostAction.php index a4824f1..8cc41d1 100644 --- a/src/Controller/OgDhcp/Subnet/PostAction.php +++ b/src/Controller/OgDhcp/Subnet/PostAction.php @@ -35,7 +35,7 @@ class PostAction extends AbstractOgDhcpController ] ]; - $content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets' , $params); + $content = $this->createRequest($httpClient, 'POST', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets' , $params); $data->setServerId($content['message']['id']); $data->setSynchronized(true); diff --git a/src/Controller/OgDhcp/Subnet/PostHostAction.php b/src/Controller/OgDhcp/Subnet/PostHostAction.php index 4330f8d..c6e3872 100644 --- a/src/Controller/OgDhcp/Subnet/PostHostAction.php +++ b/src/Controller/OgDhcp/Subnet/PostHostAction.php @@ -44,7 +44,7 @@ class PostHostAction extends AbstractOgDhcpController 'json' => $data ]; - $content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getServerId().'/hosts', $params); + $content = $this->createRequest($httpClient, 'POST', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getServerId().'/hosts', $params); $subnet->addClient($clientEntity); $this->entityManager->persist($subnet); diff --git a/src/Controller/OgDhcp/Subnet/PutAction.php b/src/Controller/OgDhcp/Subnet/PutAction.php index 9e3004c..080f0bc 100644 --- a/src/Controller/OgDhcp/Subnet/PutAction.php +++ b/src/Controller/OgDhcp/Subnet/PutAction.php @@ -38,7 +38,7 @@ class PutAction extends AbstractOgDhcpController ] ]; - $content = $this->createRequest($httpClient, 'PUT', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId(), $params); + $content = $this->createRequest($httpClient, 'PUT', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId(), $params); $this->entityManager->persist($data); $this->entityManager->flush(); diff --git a/src/Controller/OgDhcp/Subnet/PutHostAction.php b/src/Controller/OgDhcp/Subnet/PutHostAction.php index 3815ca4..5ba614a 100644 --- a/src/Controller/OgDhcp/Subnet/PutHostAction.php +++ b/src/Controller/OgDhcp/Subnet/PutHostAction.php @@ -42,7 +42,7 @@ class PutHostAction extends AbstractOgDhcpController 'json' => $data ]; - $content = $this->createRequest($httpClient, 'PUT', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getId().'/hosts', $params); + $content = $this->createRequest($httpClient, 'PUT', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getId().'/hosts', $params); } return new JsonResponse(status: Response::HTTP_OK); diff --git a/src/Controller/OgDhcp/Subnet/SyncAction.php b/src/Controller/OgDhcp/Subnet/SyncAction.php index 29c86dc..0c301d7 100644 --- a/src/Controller/OgDhcp/Subnet/SyncAction.php +++ b/src/Controller/OgDhcp/Subnet/SyncAction.php @@ -26,7 +26,7 @@ class SyncAction extends AbstractOgDhcpController */ public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', $this->ogDhcpApiUrl . '/ogdhcp/v1/subnets'); + $content = $this->createRequest($httpClient, 'GET', 'http://'.$this->ogDhcpApiUrl . '/ogdhcp/v1/subnets'); $arraySync = []; diff --git a/src/Controller/OgRepository/Image/CreateAuxFilesAction.php b/src/Controller/OgRepository/Image/CreateAuxFilesAction.php index 199b9da..70c9461 100644 --- a/src/Controller/OgRepository/Image/CreateAuxFilesAction.php +++ b/src/Controller/OgRepository/Image/CreateAuxFilesAction.php @@ -5,6 +5,7 @@ namespace App\Controller\OgRepository\Image; use App\Controller\OgRepository\AbstractOgRepositoryController; use App\Entity\Command; use App\Entity\Image; +use App\Model\CommandTypes; use App\Model\ImageStatus; use App\Model\TraceStatus; use Doctrine\ORM\EntityManagerInterface; @@ -40,14 +41,13 @@ class CreateAuxFilesAction extends AbstractOgRepositoryController ]; $content = $this->createRequest('POST', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/torrentsum', $params); - $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Crear Imagen']); $inputData = [ 'imageName' => $data->getName(), 'imageUuid' => $data->getUuid(), ]; - $this->createService->__invoke($data->getClient(), $command, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); + $this->createService->__invoke($data->getClient(), CommandTypes::CREATE_IMAGE_AUX_FILE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); $data->setStatus(ImageStatus::IN_PROGRESS); $this->entityManager->persist($data); diff --git a/src/Controller/OgRepository/Image/DeletePermanentAction.php b/src/Controller/OgRepository/Image/DeletePermanentAction.php index e560c6e..de36d77 100644 --- a/src/Controller/OgRepository/Image/DeletePermanentAction.php +++ b/src/Controller/OgRepository/Image/DeletePermanentAction.php @@ -29,7 +29,7 @@ class DeletePermanentAction extends AbstractOgRepositoryController throw new ValidatorException('Fullsum is required'); } - $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$data->getRepository()->getIp().'/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); + $content = $this->createRequest( 'DELETE', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); $this->entityManager->remove($data); $this->entityManager->flush(); diff --git a/src/Controller/OgRepository/Image/DeleteTrashAction.php b/src/Controller/OgRepository/Image/DeleteTrashAction.php index 59c671b..80a5c76 100644 --- a/src/Controller/OgRepository/Image/DeleteTrashAction.php +++ b/src/Controller/OgRepository/Image/DeleteTrashAction.php @@ -30,7 +30,7 @@ class DeleteTrashAction extends AbstractOgRepositoryController throw new ValidatorException('Fullsum is required'); } - $content = $this->createRequest($httpClient, 'DELETE', 'http://'.$data->getRepository()->getIp().'/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); + $content = $this->createRequest('DELETE', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); $data->setStatus(ImageStatus::TRASH); $this->entityManager->persist($data); diff --git a/src/Controller/OgRepository/Image/DeployImageAction.php b/src/Controller/OgRepository/Image/DeployImageAction.php index db85293..c90a6e6 100644 --- a/src/Controller/OgRepository/Image/DeployImageAction.php +++ b/src/Controller/OgRepository/Image/DeployImageAction.php @@ -6,6 +6,7 @@ use App\Controller\OgRepository\AbstractOgRepositoryController; use App\Dto\Input\DeployImageInput; use App\Entity\Command; use App\Entity\Image; +use App\Model\CommandTypes; use App\Model\TraceStatus; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -20,7 +21,6 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; class DeployImageAction extends AbstractOgRepositoryController { /** - * @throws TransportExceptionInterface * @throws ServerExceptionInterface * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface @@ -29,9 +29,7 @@ class DeployImageAction extends AbstractOgRepositoryController { $client = $input->client; - $command = $this->entityManager->getRepository(Command::class)->findOneBy(['name' => 'Deploy Imagen']); - $this->createService->__invoke($data->getClient(), $command, TraceStatus::IN_PROGRESS, null); - + $this->createService->__invoke($data->getClient(), CommandTypes::DEPLOY_IMAGE, TraceStatus::IN_PROGRESS, null); return new JsonResponse(data: [], status: Response::HTTP_OK); } diff --git a/src/Controller/OgRepository/Image/RecoverAction.php b/src/Controller/OgRepository/Image/RecoverAction.php new file mode 100644 index 0000000..4e6b820 --- /dev/null +++ b/src/Controller/OgRepository/Image/RecoverAction.php @@ -0,0 +1,51 @@ +getImageFullsum()) { + throw new ValidatorException('Fullsum is required'); + } + + $params = [ + 'json' => [ + 'ID_img' => $data->getImageFullsum() + ] + ]; + + + $content = $this->createRequest('POST', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/trash/images', $params); + + $data->setStatus(ImageStatus::SUCCESS); + $this->entityManager->persist($data); + $this->entityManager->flush(); + + return new JsonResponse(data: $content, status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Dto/Input/NetworkSettingsInput.php b/src/Dto/Input/NetworkSettingsInput.php index e4dd125..6f33126 100644 --- a/src/Dto/Input/NetworkSettingsInput.php +++ b/src/Dto/Input/NetworkSettingsInput.php @@ -76,6 +76,12 @@ class NetworkSettingsInput #[Groups(['organizational-unit:write'])] public ?bool $validation = null; + #[Groups(['organizational-unit:write'])] + public ?string $oglog = null; + + #[Groups(['organizational-unit:write'])] + public ?string $ogshare = null; + public function __construct(?NetworkSettings $networkSettings = null) { if (!$networkSettings) { @@ -95,6 +101,8 @@ class NetworkSettingsInput $this->mcastSpeed = $networkSettings->getMcastSpeed(); $this->mcastPort = $networkSettings->getMcastPort(); $this->mcastMode = $networkSettings->getMcastMode(); + $this->oglog = $networkSettings->getOglog(); + $this->ogshare = $networkSettings->getOgshare(); if ($networkSettings->getMenu()) { $this->menu = new MenuOutput($networkSettings->getMenu()); @@ -130,6 +138,8 @@ class NetworkSettingsInput $networkSettings->setMcastSpeed($this->mcastSpeed); $networkSettings->setMcastPort($this->mcastPort); $networkSettings->setMcastMode($this->mcastMode); + $networkSettings->setOglog($this->oglog); + $networkSettings->setOgshare($this->ogshare); if ($this->menu) { $networkSettings->setMenu($this->menu->getEntity()); diff --git a/src/Dto/Output/NetworkSettingsOutput.php b/src/Dto/Output/NetworkSettingsOutput.php index c85361e..b13489e 100644 --- a/src/Dto/Output/NetworkSettingsOutput.php +++ b/src/Dto/Output/NetworkSettingsOutput.php @@ -57,6 +57,12 @@ final class NetworkSettingsOutput extends AbstractOutput #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] public ?OgLiveOutput $ogLive = null; + #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] + public ?string $oglog = null; + + #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] + public ?string $ogshare = null; + #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] public ?bool $validation = null; @@ -83,6 +89,8 @@ final class NetworkSettingsOutput extends AbstractOutput $this->mcastSpeed = $networkSettings->getMcastSpeed(); $this->mcastPort = $networkSettings->getMcastPort(); $this->mcastMode = $networkSettings->getMcastMode(); + $this->oglog = $networkSettings->getOglog(); + $this->ogshare = $networkSettings->getOgshare(); if ($networkSettings->getMenu()) { $this->menu = new MenuOutput($networkSettings->getMenu()); diff --git a/src/Dto/Output/TraceOutput.php b/src/Dto/Output/TraceOutput.php index e3a9b2d..8bbc100 100644 --- a/src/Dto/Output/TraceOutput.php +++ b/src/Dto/Output/TraceOutput.php @@ -11,7 +11,7 @@ use Symfony\Component\Serializer\Annotation\Groups; final class TraceOutput extends AbstractOutput { #[Groups(['trace:read'])] - public CommandOutput $command; + public ?string $command; #[Groups(['trace:read'])] public ClientOutput $client; @@ -44,7 +44,7 @@ final class TraceOutput extends AbstractOutput { parent::__construct($trace); - $this->command = new CommandOutput($trace->getCommand()); + $this->command = $trace->getCommand(); $this->client = new ClientOutput($trace->getClient()); $this->status = $trace->getStatus(); $this->jobId = $trace->getJobId(); diff --git a/src/Entity/Trace.php b/src/Entity/Trace.php index ae416bf..08bcc81 100644 --- a/src/Entity/Trace.php +++ b/src/Entity/Trace.php @@ -13,9 +13,8 @@ class Trace extends AbstractEntity #[ORM\JoinColumn(nullable: false)] private ?Client $client = null; - #[ORM\ManyToOne(inversedBy: 'traces')] - #[ORM\JoinColumn(nullable: false)] - private ?Command $command = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $command = null; #[ORM\Column(length: 255)] private ?string $status = null; @@ -47,12 +46,12 @@ class Trace extends AbstractEntity return $this; } - public function getCommand(): ?Command + public function getCommand(): ?string { return $this->command; } - public function setCommand(?Command $command): static + public function setCommand(?string $command): static { $this->command = $command; diff --git a/src/Model/CommandTypes.php b/src/Model/CommandTypes.php new file mode 100644 index 0000000..4744681 --- /dev/null +++ b/src/Model/CommandTypes.php @@ -0,0 +1,38 @@ + 'Deploy Image', + self::RESTORE_IMAGE => 'Update Cache', + self::CREATE_IMAGE => 'Create Image', + self::CREATE_IMAGE_AUX_FILE => 'Crear fichero auxiliar en repositorio', + self::POWER_ON => 'Encender', + self::REBOOT => 'Reiniciar', + self::SHUTDOWN => 'Apagar', + self::LOGIN => 'Login', + self::LOGOUT => 'Logout', + ]; + + public static function getCommandTypes(): array + { + return self::COMMAND_TYPES; + } + + public static function getCommandType(string $type): ?string + { + return self::COMMAND_TYPES[$type] ?? null; + } +} \ No newline at end of file diff --git a/src/Model/ImageStatus.php b/src/Model/ImageStatus.php index d46af96..3ef24f1 100644 --- a/src/Model/ImageStatus.php +++ b/src/Model/ImageStatus.php @@ -6,6 +6,7 @@ final class ImageStatus { public const string PENDING = 'pending'; public const string IN_PROGRESS = 'in-progress'; + public const string AUX_FILES_PENDING = 'aux-files-pending'; public const string SUCCESS = 'success'; public const string TRASH = 'trash'; public const string FAILED = 'failed'; @@ -13,6 +14,7 @@ final class ImageStatus private const array STATUS = [ self::PENDING => 'Pendiente', self::IN_PROGRESS => 'En progreso', + self::AUX_FILES_PENDING => 'Archivos auxiliares pendientes', self::TRASH => 'Papelera', self::SUCCESS => 'Completado', self::FAILED => 'Fallido', diff --git a/src/Service/CreatePartitionService.php b/src/Service/CreatePartitionService.php new file mode 100644 index 0000000..48b903f --- /dev/null +++ b/src/Service/CreatePartitionService.php @@ -0,0 +1,50 @@ +entityManager->getRepository(Partition::class) + ->findOneBy(['client' => $clientEntity, 'diskNumber' => $cfg['disk'], 'partitionNumber' => $cfg['par']]); + + if (!$partitionEntity) { + $partitionEntity = new Partition(); + } + + if (isset($cfg['soi']) && $cfg['soi'] !== '') { + $operativeSystem = $this->entityManager->getRepository(OperativeSystem::class) + ->findOneBy(['name' => $cfg['soi']]); + + if (!$operativeSystem) { + $operativeSystem = new OperativeSystem(); + $operativeSystem->setName($cfg['soi']); + $this->entityManager->persist($operativeSystem); + } + $partitionEntity->setOperativeSystem($operativeSystem); + } + + $partitionEntity->setClient($clientEntity); + $partitionEntity->setDiskNumber($cfg['disk']); + $partitionEntity->setPartitionNumber($cfg['par']); + $partitionEntity->setSize($cfg['tam']); + $partitionEntity->setMemoryUsage(((int) $cfg['uso']) * 100); + $this->entityManager->persist($partitionEntity); + } + + $this->entityManager->flush(); + } +} \ No newline at end of file diff --git a/src/Service/Trace/CreateService.php b/src/Service/Trace/CreateService.php index 1af179f..12a3459 100644 --- a/src/Service/Trace/CreateService.php +++ b/src/Service/Trace/CreateService.php @@ -15,11 +15,11 @@ readonly class CreateService { } - public function __invoke(Client $client, Command $command, string $status, ?string $jobId = null, array $input): Trace + public function __invoke(Client $client, ?string $command, string $status, string $jobId, ?array $input = []): Trace { $trace = new Trace(); $trace->setClient($client); - $trace->setCommand($command ?? null); + $trace->setCommand($command); $trace->setStatus($status); $trace->setJobId($jobId); $trace->setExecutedAt(new \DateTime()); diff --git a/src/State/Processor/ImageProcessor.php b/src/State/Processor/ImageProcessor.php index bcda6ed..8d79868 100644 --- a/src/State/Processor/ImageProcessor.php +++ b/src/State/Processor/ImageProcessor.php @@ -54,12 +54,12 @@ readonly class ImageProcessor implements ProcessorInterface } $image = $data->createOrUpdateEntity($entity); + $this->validator->validate($image); if ($data->source !== 'input') { $response = $this->createImageActionController->__invoke($image); } - $this->validator->validate($image); $this->imageRepository->save($image); return new ImageOutput($image); diff --git a/translations/validators.en.yaml b/translations/validators.en.yaml index 7881069..2ed5bc8 100644 --- a/translations/validators.en.yaml +++ b/translations/validators.en.yaml @@ -37,6 +37,7 @@ validators: image: name: not_blank: 'The name should not be blank.' + unique: 'The name should be unique.' network_settings: ip_address: diff --git a/translations/validators.es.yaml b/translations/validators.es.yaml index 9f11c35..a6bbf00 100644 --- a/translations/validators.es.yaml +++ b/translations/validators.es.yaml @@ -37,6 +37,7 @@ validators: image: name: not_blank: 'El nombre no debería estar vacío.' + unique: 'El nombre debería ser único. Ya existe una imagen con ese nombre.' network_settings: ip_address: From 8094fdae3e48b5325771f9c93ebc7844a2bc41e1 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 20 Nov 2024 16:02:13 +0100 Subject: [PATCH 19/26] Updated APIS, and general improvements --- docker-compose-ci-template.yaml | 4 ---- docker-compose-ci.yaml | 4 ---- docker-compose-deploy.yml | 4 ---- docker-compose.yaml | 4 ---- docker/Dockerfile-php | 9 --------- 5 files changed, 25 deletions(-) diff --git a/docker-compose-ci-template.yaml b/docker-compose-ci-template.yaml index b407aa8..3daf1ae 100644 --- a/docker-compose-ci-template.yaml +++ b/docker-compose-ci-template.yaml @@ -36,10 +36,6 @@ services: dockerfile: ./docker/Dockerfile-jenkins-php depends_on: - database - environment: - XDEBUG_CLIENT_HOST: 127.17.0.1 - XDEBUG_CLIENT_PORT: 9003 - PHP_IDE_CONFIG: serverName=ogcore networks: - ogcore-network image: ogcore-php:static diff --git a/docker-compose-ci.yaml b/docker-compose-ci.yaml index d6442f7..897d8c5 100644 --- a/docker-compose-ci.yaml +++ b/docker-compose-ci.yaml @@ -35,10 +35,6 @@ services: dockerfile: ./docker/Dockerfile-jenkins-php depends_on: - database - environment: - XDEBUG_CLIENT_HOST: 127.17.0.1 - XDEBUG_CLIENT_PORT: 9003 - PHP_IDE_CONFIG: serverName=ogcore networks: - ogcore-network diff --git a/docker-compose-deploy.yml b/docker-compose-deploy.yml index 4c9bf3b..62a5a22 100644 --- a/docker-compose-deploy.yml +++ b/docker-compose-deploy.yml @@ -36,10 +36,6 @@ services: dockerfile: ./docker/Dockerfile-jenkins-php depends_on: - database - environment: - XDEBUG_CLIENT_HOST: 127.17.0.1 - XDEBUG_CLIENT_PORT: 9003 - PHP_IDE_CONFIG: serverName=ogcore volumes: - ogpublic:/var/www/html/public - /opt/opengnsys/ogCore/etc/.env:/var/www/html/.env diff --git a/docker-compose.yaml b/docker-compose.yaml index 8a5bd62..b6c7909 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -39,10 +39,6 @@ services: - ./:/var/www/html depends_on: - database - environment: - XDEBUG_CLIENT_HOST: 127.17.0.1 - XDEBUG_CLIENT_PORT: 9003 - PHP_IDE_CONFIG: serverName=ogcore networks: - ogcore-network diff --git a/docker/Dockerfile-php b/docker/Dockerfile-php index a4cdcb8..e8be930 100644 --- a/docker/Dockerfile-php +++ b/docker/Dockerfile-php @@ -19,15 +19,6 @@ ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/do RUN chmod +x /usr/local/bin/install-php-extensions RUN install-php-extensions sockets -# Add xdebug -RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS -RUN apk add --update linux-headers -RUN pecl install xdebug -RUN docker-php-ext-enable xdebug -RUN apk del -f .build-deps - -COPY ./docker/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini - # Generate SSH keys RUN ssh-keygen -t rsa -b 4096 -f /root/.ssh/id_rsa -N "" From 80b39db99337293ead707120a8b741c6102eff2c Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 20 Nov 2024 17:16:34 +0100 Subject: [PATCH 20/26] Updated database schema. Removed old versions --- migrations/Version20240617113606.php | 81 ------------ migrations/Version20240618062825.php | 39 ------ migrations/Version20240618083013.php | 41 ------ migrations/Version20240618113629.php | 31 ----- migrations/Version20240619083230.php | 33 ----- migrations/Version20240619084701.php | 31 ----- migrations/Version20240619104206.php | 35 ----- migrations/Version20240620095914.php | 33 ----- migrations/Version20240620100039.php | 33 ----- migrations/Version20240621085144.php | 33 ----- migrations/Version20240701123613.php | 33 ----- migrations/Version20240702132742.php | 41 ------ migrations/Version20240703090301.php | 35 ----- migrations/Version20240715084147.php | 43 ------ migrations/Version20240717094811.php | 31 ----- migrations/Version20240718064611.php | 31 ----- migrations/Version20240801130155.php | 35 ----- migrations/Version20240808140716.php | 31 ----- migrations/Version20240812095940.php | 43 ------ migrations/Version20240812135824.php | 43 ------ migrations/Version20240814130427.php | 31 ----- migrations/Version20240819062421.php | 33 ----- migrations/Version20240819140045.php | 33 ----- migrations/Version20240820063513.php | 41 ------ migrations/Version20240820064106.php | 31 ----- migrations/Version20240821065158.php | 31 ----- migrations/Version20240827102833.php | 31 ----- migrations/Version20240902124157.php | 33 ----- migrations/Version20240903081001.php | 35 ----- migrations/Version20240904134540.php | 35 ----- migrations/Version20240905080435.php | 32 ----- migrations/Version20240916073039.php | 31 ----- migrations/Version20240916091601.php | 37 ------ migrations/Version20240917064754.php | 43 ------ migrations/Version20240917091950.php | 35 ----- migrations/Version20240917092207.php | 31 ----- migrations/Version20240924071858.php | 31 ----- migrations/Version20240924090429.php | 41 ------ migrations/Version20240924095558.php | 31 ----- migrations/Version20240924100335.php | 31 ----- migrations/Version20240924102357.php | 31 ----- migrations/Version20240926085224.php | 35 ----- migrations/Version20240926104532.php | 32 ----- migrations/Version20240930131003.php | 45 ------- migrations/Version20241002062742.php | 31 ----- migrations/Version20241008080902.php | 35 ----- migrations/Version20241008081013.php | 31 ----- migrations/Version20241008092247.php | 31 ----- migrations/Version20241008092849.php | 35 ----- migrations/Version20241014053130.php | 31 ----- migrations/Version20241014082029.php | 33 ----- migrations/Version20241014102105.php | 33 ----- migrations/Version20241015154123.php | 31 ----- migrations/Version20241016063657.php | 37 ------ migrations/Version20241016065729.php | 31 ----- migrations/Version20241018055534.php | 39 ------ migrations/Version20241018060155.php | 31 ----- migrations/Version20241019073142.php | 31 ----- migrations/Version20241021061008.php | 33 ----- migrations/Version20241021071250.php | 43 ------ migrations/Version20241021201438.php | 31 ----- migrations/Version20241029112630.php | 31 ----- migrations/Version20241029145213.php | 35 ----- migrations/Version20241105070853.php | 43 ------ migrations/Version20241105085054.php | 35 ----- migrations/Version20241106133332.php | 31 ----- migrations/Version20241107074832.php | 31 ----- migrations/Version20241108062659.php | 31 ----- migrations/Version20241111101047.php | 31 ----- migrations/Version20241113084353.php | 33 ----- migrations/Version20241114081247.php | 31 ----- migrations/Version20241115074840.php | 31 ----- migrations/Version20241120050107.php | 35 ----- migrations/Version20241120160808.php | 189 +++++++++++++++++++++++++++ src/Service/OgBoot/StatusService.php | 2 +- src/Service/OgDhcp/StatusService.php | 2 +- 76 files changed, 191 insertions(+), 2543 deletions(-) delete mode 100644 migrations/Version20240617113606.php delete mode 100644 migrations/Version20240618062825.php delete mode 100644 migrations/Version20240618083013.php delete mode 100644 migrations/Version20240618113629.php delete mode 100644 migrations/Version20240619083230.php delete mode 100644 migrations/Version20240619084701.php delete mode 100644 migrations/Version20240619104206.php delete mode 100644 migrations/Version20240620095914.php delete mode 100644 migrations/Version20240620100039.php delete mode 100644 migrations/Version20240621085144.php delete mode 100644 migrations/Version20240701123613.php delete mode 100644 migrations/Version20240702132742.php delete mode 100644 migrations/Version20240703090301.php delete mode 100644 migrations/Version20240715084147.php delete mode 100644 migrations/Version20240717094811.php delete mode 100644 migrations/Version20240718064611.php delete mode 100644 migrations/Version20240801130155.php delete mode 100644 migrations/Version20240808140716.php delete mode 100644 migrations/Version20240812095940.php delete mode 100644 migrations/Version20240812135824.php delete mode 100644 migrations/Version20240814130427.php delete mode 100644 migrations/Version20240819062421.php delete mode 100644 migrations/Version20240819140045.php delete mode 100644 migrations/Version20240820063513.php delete mode 100644 migrations/Version20240820064106.php delete mode 100644 migrations/Version20240821065158.php delete mode 100644 migrations/Version20240827102833.php delete mode 100644 migrations/Version20240902124157.php delete mode 100644 migrations/Version20240903081001.php delete mode 100644 migrations/Version20240904134540.php delete mode 100644 migrations/Version20240905080435.php delete mode 100644 migrations/Version20240916073039.php delete mode 100644 migrations/Version20240916091601.php delete mode 100644 migrations/Version20240917064754.php delete mode 100644 migrations/Version20240917091950.php delete mode 100644 migrations/Version20240917092207.php delete mode 100644 migrations/Version20240924071858.php delete mode 100644 migrations/Version20240924090429.php delete mode 100644 migrations/Version20240924095558.php delete mode 100644 migrations/Version20240924100335.php delete mode 100644 migrations/Version20240924102357.php delete mode 100644 migrations/Version20240926085224.php delete mode 100644 migrations/Version20240926104532.php delete mode 100644 migrations/Version20240930131003.php delete mode 100644 migrations/Version20241002062742.php delete mode 100644 migrations/Version20241008080902.php delete mode 100644 migrations/Version20241008081013.php delete mode 100644 migrations/Version20241008092247.php delete mode 100644 migrations/Version20241008092849.php delete mode 100644 migrations/Version20241014053130.php delete mode 100644 migrations/Version20241014082029.php delete mode 100644 migrations/Version20241014102105.php delete mode 100644 migrations/Version20241015154123.php delete mode 100644 migrations/Version20241016063657.php delete mode 100644 migrations/Version20241016065729.php delete mode 100644 migrations/Version20241018055534.php delete mode 100644 migrations/Version20241018060155.php delete mode 100644 migrations/Version20241019073142.php delete mode 100644 migrations/Version20241021061008.php delete mode 100644 migrations/Version20241021071250.php delete mode 100644 migrations/Version20241021201438.php delete mode 100644 migrations/Version20241029112630.php delete mode 100644 migrations/Version20241029145213.php delete mode 100644 migrations/Version20241105070853.php delete mode 100644 migrations/Version20241105085054.php delete mode 100644 migrations/Version20241106133332.php delete mode 100644 migrations/Version20241107074832.php delete mode 100644 migrations/Version20241108062659.php delete mode 100644 migrations/Version20241111101047.php delete mode 100644 migrations/Version20241113084353.php delete mode 100644 migrations/Version20241114081247.php delete mode 100644 migrations/Version20241115074840.php delete mode 100644 migrations/Version20241120050107.php create mode 100644 migrations/Version20241120160808.php diff --git a/migrations/Version20240617113606.php b/migrations/Version20240617113606.php deleted file mode 100644 index 3c98a3c..0000000 --- a/migrations/Version20240617113606.php +++ /dev/null @@ -1,81 +0,0 @@ -addSql('CREATE TABLE client (id INT AUTO_INCREMENT NOT NULL, organizational_unit_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, serial_number VARCHAR(255) DEFAULT NULL, netiface VARCHAR(255) DEFAULT NULL, net_driver VARCHAR(255) DEFAULT NULL, mac VARCHAR(255) DEFAULT NULL, ip VARCHAR(255) DEFAULT NULL, status VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_C7440455D17F50A6 (uuid), INDEX IDX_C7440455FB84408A (organizational_unit_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE hardware (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, type VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_FE99E9E0D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE hardware_profile (id INT AUTO_INCREMENT NOT NULL, organizational_unit_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_2D9A2460D17F50A6 (uuid), INDEX IDX_2D9A2460FB84408A (organizational_unit_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE hardware_profile_hardware (hardware_profile_id INT NOT NULL, hardware_id INT NOT NULL, INDEX IDX_18C7E12CFA495C1 (hardware_profile_id), INDEX IDX_18C7E12C9CC762B (hardware_id), PRIMARY KEY(hardware_profile_id, hardware_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE menu (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, title VARCHAR(255) NOT NULL, resolution VARCHAR(255) NOT NULL, comments VARCHAR(255) DEFAULT NULL, public_url VARCHAR(255) DEFAULT NULL, private_url VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_7D053A93D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE network_settings (id INT AUTO_INCREMENT NOT NULL, menu_id INT DEFAULT NULL, hardware_profile_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, proxy VARCHAR(255) DEFAULT NULL, dns VARCHAR(255) DEFAULT NULL, netmask VARCHAR(255) DEFAULT NULL, router VARCHAR(255) DEFAULT NULL, ntp VARCHAR(255) DEFAULT NULL, p2p_time INT DEFAULT NULL, p2p_mode VARCHAR(255) DEFAULT NULL, mcast_ip VARCHAR(255) DEFAULT NULL, mcast_speed INT DEFAULT NULL, mcast_mode VARCHAR(255) DEFAULT NULL, mcast_port INT DEFAULT NULL, validation TINYINT(1) DEFAULT NULL, UNIQUE INDEX UNIQ_48869B54D17F50A6 (uuid), INDEX IDX_48869B54CCD7E912 (menu_id), INDEX IDX_48869B54CFA495C1 (hardware_profile_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE organizational_unit (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, network_settings_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, path VARCHAR(255) DEFAULT NULL, level INT DEFAULT NULL, slug VARCHAR(255) DEFAULT NULL, type VARCHAR(255) NOT NULL, location VARCHAR(255) DEFAULT NULL, projector TINYINT(1) DEFAULT NULL, board TINYINT(1) DEFAULT NULL, capacity INT DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_749AEB2DD17F50A6 (uuid), INDEX IDX_749AEB2D727ACA70 (parent_id), INDEX IDX_749AEB2D9B9A36D0 (network_settings_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE `partition` (id INT AUTO_INCREMENT NOT NULL, client_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, disk_number INT DEFAULT NULL, partition_number INT DEFAULT NULL, partition_code VARCHAR(255) DEFAULT NULL, size INT NOT NULL, cache_content VARCHAR(255) DEFAULT NULL, filesystem VARCHAR(255) DEFAULT NULL, os_name VARCHAR(255) NOT NULL, memory_usage INT NOT NULL, UNIQUE INDEX UNIQ_9EB910E4D17F50A6 (uuid), INDEX IDX_9EB910E419EB6921 (client_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE refresh_tokens (id INT AUTO_INCREMENT NOT NULL, refresh_token VARCHAR(128) NOT NULL, username VARCHAR(255) NOT NULL, valid DATETIME NOT NULL, UNIQUE INDEX UNIQ_9BACE7E1C74F2195 (refresh_token), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, username VARCHAR(180) NOT NULL, roles JSON NOT NULL COMMENT \'(DC2Type:json)\', password VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8D93D649D17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_USERNAME (username), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE user_organizational_unit (user_id INT NOT NULL, organizational_unit_id INT NOT NULL, INDEX IDX_5E59845FA76ED395 (user_id), INDEX IDX_5E59845FFB84408A (organizational_unit_id), PRIMARY KEY(user_id, organizational_unit_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE user_group (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, permissions JSON NOT NULL COMMENT \'(DC2Type:json)\', name VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8F02BF9DD17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE user_group_user (user_group_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_3AE4BD51ED93D47 (user_group_id), INDEX IDX_3AE4BD5A76ED395 (user_id), PRIMARY KEY(user_group_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455FB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); - $this->addSql('ALTER TABLE hardware_profile ADD CONSTRAINT FK_2D9A2460FB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); - $this->addSql('ALTER TABLE hardware_profile_hardware ADD CONSTRAINT FK_18C7E12CFA495C1 FOREIGN KEY (hardware_profile_id) REFERENCES hardware_profile (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE hardware_profile_hardware ADD CONSTRAINT FK_18C7E12C9CC762B FOREIGN KEY (hardware_id) REFERENCES hardware (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B54CCD7E912 FOREIGN KEY (menu_id) REFERENCES menu (id)'); - $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B54CFA495C1 FOREIGN KEY (hardware_profile_id) REFERENCES hardware_profile (id)'); - $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2D727ACA70 FOREIGN KEY (parent_id) REFERENCES organizational_unit (id) ON DELETE SET NULL'); - $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2D9B9A36D0 FOREIGN KEY (network_settings_id) REFERENCES network_settings (id)'); - $this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E419EB6921 FOREIGN KEY (client_id) REFERENCES client (id)'); - $this->addSql('ALTER TABLE user_organizational_unit ADD CONSTRAINT FK_5E59845FA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE user_organizational_unit ADD CONSTRAINT FK_5E59845FFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE user_group_user ADD CONSTRAINT FK_3AE4BD51ED93D47 FOREIGN KEY (user_group_id) REFERENCES user_group (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE user_group_user ADD CONSTRAINT FK_3AE4BD5A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455FB84408A'); - $this->addSql('ALTER TABLE hardware_profile DROP FOREIGN KEY FK_2D9A2460FB84408A'); - $this->addSql('ALTER TABLE hardware_profile_hardware DROP FOREIGN KEY FK_18C7E12CFA495C1'); - $this->addSql('ALTER TABLE hardware_profile_hardware DROP FOREIGN KEY FK_18C7E12C9CC762B'); - $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B54CCD7E912'); - $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B54CFA495C1'); - $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2D727ACA70'); - $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2D9B9A36D0'); - $this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E419EB6921'); - $this->addSql('ALTER TABLE user_organizational_unit DROP FOREIGN KEY FK_5E59845FA76ED395'); - $this->addSql('ALTER TABLE user_organizational_unit DROP FOREIGN KEY FK_5E59845FFB84408A'); - $this->addSql('ALTER TABLE user_group_user DROP FOREIGN KEY FK_3AE4BD51ED93D47'); - $this->addSql('ALTER TABLE user_group_user DROP FOREIGN KEY FK_3AE4BD5A76ED395'); - $this->addSql('DROP TABLE client'); - $this->addSql('DROP TABLE hardware'); - $this->addSql('DROP TABLE hardware_profile'); - $this->addSql('DROP TABLE hardware_profile_hardware'); - $this->addSql('DROP TABLE menu'); - $this->addSql('DROP TABLE network_settings'); - $this->addSql('DROP TABLE organizational_unit'); - $this->addSql('DROP TABLE `partition`'); - $this->addSql('DROP TABLE refresh_tokens'); - $this->addSql('DROP TABLE user'); - $this->addSql('DROP TABLE user_organizational_unit'); - $this->addSql('DROP TABLE user_group'); - $this->addSql('DROP TABLE user_group_user'); - } -} diff --git a/migrations/Version20240618062825.php b/migrations/Version20240618062825.php deleted file mode 100644 index 7cb73fe..0000000 --- a/migrations/Version20240618062825.php +++ /dev/null @@ -1,39 +0,0 @@ -addSql('ALTER TABLE client ADD menu_id INT DEFAULT NULL, ADD hardware_profile_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455CCD7E912 FOREIGN KEY (menu_id) REFERENCES menu (id)'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455CFA495C1 FOREIGN KEY (hardware_profile_id) REFERENCES hardware_profile (id)'); - $this->addSql('CREATE INDEX IDX_C7440455CCD7E912 ON client (menu_id)'); - $this->addSql('CREATE INDEX IDX_C7440455CFA495C1 ON client (hardware_profile_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455CCD7E912'); - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455CFA495C1'); - $this->addSql('DROP INDEX IDX_C7440455CCD7E912 ON client'); - $this->addSql('DROP INDEX IDX_C7440455CFA495C1 ON client'); - $this->addSql('ALTER TABLE client DROP menu_id, DROP hardware_profile_id'); - } -} diff --git a/migrations/Version20240618083013.php b/migrations/Version20240618083013.php deleted file mode 100644 index df541b8..0000000 --- a/migrations/Version20240618083013.php +++ /dev/null @@ -1,41 +0,0 @@ -addSql('CREATE TABLE hardware_type (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_2AA5A113D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE operative_system (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_E9C44095D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE operative_system_type (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_4A13A156D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE hardware ADD type_id INT DEFAULT NULL, DROP type'); - $this->addSql('ALTER TABLE hardware ADD CONSTRAINT FK_FE99E9E0C54C8C93 FOREIGN KEY (type_id) REFERENCES hardware_type (id)'); - $this->addSql('CREATE INDEX IDX_FE99E9E0C54C8C93 ON hardware (type_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE hardware DROP FOREIGN KEY FK_FE99E9E0C54C8C93'); - $this->addSql('DROP TABLE hardware_type'); - $this->addSql('DROP TABLE operative_system'); - $this->addSql('DROP TABLE operative_system_type'); - $this->addSql('DROP INDEX IDX_FE99E9E0C54C8C93 ON hardware'); - $this->addSql('ALTER TABLE hardware ADD type VARCHAR(255) DEFAULT NULL, DROP type_id'); - } -} diff --git a/migrations/Version20240618113629.php b/migrations/Version20240618113629.php deleted file mode 100644 index c9e1d5a..0000000 --- a/migrations/Version20240618113629.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON organizational_unit (name)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON organizational_unit'); - } -} diff --git a/migrations/Version20240619083230.php b/migrations/Version20240619083230.php deleted file mode 100644 index ea1e30b..0000000 --- a/migrations/Version20240619083230.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_IP ON client (ip)'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_MAC ON client (mac)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP INDEX UNIQ_IDENTIFIER_IP ON client'); - $this->addSql('DROP INDEX UNIQ_IDENTIFIER_MAC ON client'); - } -} diff --git a/migrations/Version20240619084701.php b/migrations/Version20240619084701.php deleted file mode 100644 index 22e781b..0000000 --- a/migrations/Version20240619084701.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE client ADD validation TINYINT(1) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP validation'); - } -} diff --git a/migrations/Version20240619104206.php b/migrations/Version20240619104206.php deleted file mode 100644 index d4654c9..0000000 --- a/migrations/Version20240619104206.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('ALTER TABLE `partition` ADD operative_system_id INT DEFAULT NULL, DROP os_name'); - $this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E4F1E9F66E FOREIGN KEY (operative_system_id) REFERENCES operative_system (id)'); - $this->addSql('CREATE INDEX IDX_9EB910E4F1E9F66E ON `partition` (operative_system_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E4F1E9F66E'); - $this->addSql('DROP INDEX IDX_9EB910E4F1E9F66E ON `partition`'); - $this->addSql('ALTER TABLE `partition` ADD os_name VARCHAR(255) NOT NULL, DROP operative_system_id'); - } -} diff --git a/migrations/Version20240620095914.php b/migrations/Version20240620095914.php deleted file mode 100644 index 5e4d7f2..0000000 --- a/migrations/Version20240620095914.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E419EB6921'); - $this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E419EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE SET NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E419EB6921'); - $this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E419EB6921 FOREIGN KEY (client_id) REFERENCES client (id)'); - } -} diff --git a/migrations/Version20240620100039.php b/migrations/Version20240620100039.php deleted file mode 100644 index 7aa27c5..0000000 --- a/migrations/Version20240620100039.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E419EB6921'); - $this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E419EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E419EB6921'); - $this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E419EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE SET NULL'); - } -} diff --git a/migrations/Version20240621085144.php b/migrations/Version20240621085144.php deleted file mode 100644 index 8286ec6..0000000 --- a/migrations/Version20240621085144.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON organizational_unit'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON organizational_unit (name, parent_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON organizational_unit'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON organizational_unit (name)'); - } -} diff --git a/migrations/Version20240701123613.php b/migrations/Version20240701123613.php deleted file mode 100644 index e83b75e..0000000 --- a/migrations/Version20240701123613.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455FB84408A'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455FB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455FB84408A'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455FB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); - } -} diff --git a/migrations/Version20240702132742.php b/migrations/Version20240702132742.php deleted file mode 100644 index 91069d5..0000000 --- a/migrations/Version20240702132742.php +++ /dev/null @@ -1,41 +0,0 @@ -addSql('CREATE TABLE software (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_77D068CFD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE software_profile (id INT AUTO_INCREMENT NOT NULL, organizational_unit_id INT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_B70C3C9BD17F50A6 (uuid), INDEX IDX_B70C3C9BFB84408A (organizational_unit_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE software_profile_software (software_profile_id INT NOT NULL, software_id INT NOT NULL, INDEX IDX_3DDFEC7ED42A742 (software_profile_id), INDEX IDX_3DDFEC7D7452741 (software_id), PRIMARY KEY(software_profile_id, software_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE software_profile ADD CONSTRAINT FK_B70C3C9BFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); - $this->addSql('ALTER TABLE software_profile_software ADD CONSTRAINT FK_3DDFEC7ED42A742 FOREIGN KEY (software_profile_id) REFERENCES software_profile (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE software_profile_software ADD CONSTRAINT FK_3DDFEC7D7452741 FOREIGN KEY (software_id) REFERENCES software (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE software_profile DROP FOREIGN KEY FK_B70C3C9BFB84408A'); - $this->addSql('ALTER TABLE software_profile_software DROP FOREIGN KEY FK_3DDFEC7ED42A742'); - $this->addSql('ALTER TABLE software_profile_software DROP FOREIGN KEY FK_3DDFEC7D7452741'); - $this->addSql('DROP TABLE software'); - $this->addSql('DROP TABLE software_profile'); - $this->addSql('DROP TABLE software_profile_software'); - } -} diff --git a/migrations/Version20240703090301.php b/migrations/Version20240703090301.php deleted file mode 100644 index 9a7588b..0000000 --- a/migrations/Version20240703090301.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('CREATE TABLE image (id INT AUTO_INCREMENT NOT NULL, client_id INT NOT NULL, software_profile_id INT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, path VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, revision VARCHAR(255) DEFAULT NULL, info VARCHAR(255) DEFAULT NULL, size INT NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_C53D045FD17F50A6 (uuid), INDEX IDX_C53D045F19EB6921 (client_id), INDEX IDX_C53D045FED42A742 (software_profile_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F19EB6921 FOREIGN KEY (client_id) REFERENCES client (id)'); - $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045FED42A742 FOREIGN KEY (software_profile_id) REFERENCES software_profile (id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F19EB6921'); - $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045FED42A742'); - $this->addSql('DROP TABLE image'); - } -} diff --git a/migrations/Version20240715084147.php b/migrations/Version20240715084147.php deleted file mode 100644 index 0db212c..0000000 --- a/migrations/Version20240715084147.php +++ /dev/null @@ -1,43 +0,0 @@ -addSql('CREATE TABLE user_user_group (user_id INT NOT NULL, user_group_id INT NOT NULL, INDEX IDX_28657971A76ED395 (user_id), INDEX IDX_286579711ED93D47 (user_group_id), PRIMARY KEY(user_id, user_group_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE user_user_group ADD CONSTRAINT FK_28657971A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE user_user_group ADD CONSTRAINT FK_286579711ED93D47 FOREIGN KEY (user_group_id) REFERENCES user_group (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE user_group_user DROP FOREIGN KEY FK_3AE4BD51ED93D47'); - $this->addSql('ALTER TABLE user_group_user DROP FOREIGN KEY FK_3AE4BD5A76ED395'); - $this->addSql('DROP TABLE user_group_user'); - $this->addSql('ALTER TABLE hardware_profile CHANGE organizational_unit_id organizational_unit_id INT NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE TABLE user_group_user (user_group_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_3AE4BD5A76ED395 (user_id), INDEX IDX_3AE4BD51ED93D47 (user_group_id), PRIMARY KEY(user_group_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); - $this->addSql('ALTER TABLE user_group_user ADD CONSTRAINT FK_3AE4BD51ED93D47 FOREIGN KEY (user_group_id) REFERENCES user_group (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE user_group_user ADD CONSTRAINT FK_3AE4BD5A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE user_user_group DROP FOREIGN KEY FK_28657971A76ED395'); - $this->addSql('ALTER TABLE user_user_group DROP FOREIGN KEY FK_286579711ED93D47'); - $this->addSql('DROP TABLE user_user_group'); - $this->addSql('ALTER TABLE hardware_profile CHANGE organizational_unit_id organizational_unit_id INT DEFAULT NULL'); - } -} diff --git a/migrations/Version20240717094811.php b/migrations/Version20240717094811.php deleted file mode 100644 index c1eb1f2..0000000 --- a/migrations/Version20240717094811.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE TABLE view (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, favourite TINYINT(1) NOT NULL, filters JSON DEFAULT NULL COMMENT \'(DC2Type:json)\', name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_FEFDAB8ED17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE view'); - } -} diff --git a/migrations/Version20240718064611.php b/migrations/Version20240718064611.php deleted file mode 100644 index fedb106..0000000 --- a/migrations/Version20240718064611.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE client ADD position JSON DEFAULT NULL COMMENT \'(DC2Type:json)\''); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP position'); - } -} diff --git a/migrations/Version20240801130155.php b/migrations/Version20240801130155.php deleted file mode 100644 index 5c389bf..0000000 --- a/migrations/Version20240801130155.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('ALTER TABLE view ADD user_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8EA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); - $this->addSql('CREATE INDEX IDX_FEFDAB8EA76ED395 ON view (user_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE view DROP FOREIGN KEY FK_FEFDAB8EA76ED395'); - $this->addSql('DROP INDEX IDX_FEFDAB8EA76ED395 ON view'); - $this->addSql('ALTER TABLE view DROP user_id'); - } -} diff --git a/migrations/Version20240808140716.php b/migrations/Version20240808140716.php deleted file mode 100644 index b61c4df..0000000 --- a/migrations/Version20240808140716.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE TABLE og_live (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, download_url VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_3D6B7739D17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE og_live'); - } -} diff --git a/migrations/Version20240812095940.php b/migrations/Version20240812095940.php deleted file mode 100644 index 448e24e..0000000 --- a/migrations/Version20240812095940.php +++ /dev/null @@ -1,43 +0,0 @@ -addSql('CREATE TABLE pxe_boot_file (id INT AUTO_INCREMENT NOT NULL, template_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_7FD1F34BD17F50A6 (uuid), INDEX IDX_7FD1F34B5DA0FB8 (template_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE pxe_template (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, template_content VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_73197554D17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE pxe_boot_file ADD CONSTRAINT FK_7FD1F34B5DA0FB8 FOREIGN KEY (template_id) REFERENCES pxe_template (id)'); - $this->addSql('ALTER TABLE client ADD pxe_boot_file_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455D4CBF752 FOREIGN KEY (pxe_boot_file_id) REFERENCES pxe_boot_file (id)'); - $this->addSql('CREATE INDEX IDX_C7440455D4CBF752 ON client (pxe_boot_file_id)'); - $this->addSql('ALTER TABLE og_live ADD checksum VARCHAR(255) DEFAULT NULL, ADD distribution VARCHAR(255) DEFAULT NULL, ADD kernel VARCHAR(255) DEFAULT NULL, ADD architecture VARCHAR(255) DEFAULT NULL, ADD revision VARCHAR(255) DEFAULT NULL, ADD directory VARCHAR(255) DEFAULT NULL, ADD filename VARCHAR(255) DEFAULT NULL, ADD installed TINYINT(1) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455D4CBF752'); - $this->addSql('ALTER TABLE pxe_boot_file DROP FOREIGN KEY FK_7FD1F34B5DA0FB8'); - $this->addSql('DROP TABLE pxe_boot_file'); - $this->addSql('DROP TABLE pxe_template'); - $this->addSql('ALTER TABLE og_live DROP checksum, DROP distribution, DROP kernel, DROP architecture, DROP revision, DROP directory, DROP filename, DROP installed'); - $this->addSql('DROP INDEX IDX_C7440455D4CBF752 ON client'); - $this->addSql('ALTER TABLE client DROP pxe_boot_file_id'); - } -} diff --git a/migrations/Version20240812135824.php b/migrations/Version20240812135824.php deleted file mode 100644 index 5bd9784..0000000 --- a/migrations/Version20240812135824.php +++ /dev/null @@ -1,43 +0,0 @@ -addSql('CREATE TABLE og_repository (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, ip_address VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_2E0FDA37D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE client ADD repository_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C744045550C9D4F7 FOREIGN KEY (repository_id) REFERENCES og_repository (id)'); - $this->addSql('CREATE INDEX IDX_C744045550C9D4F7 ON client (repository_id)'); - $this->addSql('ALTER TABLE network_settings ADD repository_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B5450C9D4F7 FOREIGN KEY (repository_id) REFERENCES og_repository (id)'); - $this->addSql('CREATE INDEX IDX_48869B5450C9D4F7 ON network_settings (repository_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C744045550C9D4F7'); - $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B5450C9D4F7'); - $this->addSql('DROP TABLE og_repository'); - $this->addSql('DROP INDEX IDX_48869B5450C9D4F7 ON network_settings'); - $this->addSql('ALTER TABLE network_settings DROP repository_id'); - $this->addSql('DROP INDEX IDX_C744045550C9D4F7 ON client'); - $this->addSql('ALTER TABLE client DROP repository_id'); - } -} diff --git a/migrations/Version20240814130427.php b/migrations/Version20240814130427.php deleted file mode 100644 index 8e2cabc..0000000 --- a/migrations/Version20240814130427.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE pxe_template CHANGE template_content template_content TINYTEXT NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE pxe_template CHANGE template_content template_content VARCHAR(255) NOT NULL'); - } -} diff --git a/migrations/Version20240819062421.php b/migrations/Version20240819062421.php deleted file mode 100644 index 79b21f8..0000000 --- a/migrations/Version20240819062421.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE og_live ADD synchronized TINYINT(1) DEFAULT NULL'); - $this->addSql('ALTER TABLE pxe_template ADD synchronized TINYINT(1) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE og_live DROP synchronized'); - $this->addSql('ALTER TABLE pxe_template DROP synchronized'); - } -} diff --git a/migrations/Version20240819140045.php b/migrations/Version20240819140045.php deleted file mode 100644 index 01a67ef..0000000 --- a/migrations/Version20240819140045.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE og_live ADD `default` TINYINT(1) DEFAULT NULL'); - $this->addSql('ALTER TABLE pxe_boot_file ADD synchronized TINYINT(1) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE og_live DROP `default`'); - $this->addSql('ALTER TABLE pxe_boot_file DROP synchronized'); - } -} diff --git a/migrations/Version20240820063513.php b/migrations/Version20240820063513.php deleted file mode 100644 index 42803dd..0000000 --- a/migrations/Version20240820063513.php +++ /dev/null @@ -1,41 +0,0 @@ -addSql('ALTER TABLE client ADD og_live_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id)'); - $this->addSql('CREATE INDEX IDX_C7440455F7E54CF3 ON client (og_live_id)'); - $this->addSql('ALTER TABLE network_settings ADD og_live_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B54F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id)'); - $this->addSql('CREATE INDEX IDX_48869B54F7E54CF3 ON network_settings (og_live_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B54F7E54CF3'); - $this->addSql('DROP INDEX IDX_48869B54F7E54CF3 ON network_settings'); - $this->addSql('ALTER TABLE network_settings DROP og_live_id'); - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455F7E54CF3'); - $this->addSql('DROP INDEX IDX_C7440455F7E54CF3 ON client'); - $this->addSql('ALTER TABLE client DROP og_live_id'); - } -} diff --git a/migrations/Version20240820064106.php b/migrations/Version20240820064106.php deleted file mode 100644 index 2e387f6..0000000 --- a/migrations/Version20240820064106.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE og_live CHANGE `default` is_default TINYINT(1) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE og_live CHANGE is_default `default` TINYINT(1) DEFAULT NULL'); - } -} diff --git a/migrations/Version20240821065158.php b/migrations/Version20240821065158.php deleted file mode 100644 index dfcd85a..0000000 --- a/migrations/Version20240821065158.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE pxe_template CHANGE template_content template_content LONGTEXT NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE pxe_template CHANGE template_content template_content TINYTEXT NOT NULL'); - } -} diff --git a/migrations/Version20240827102833.php b/migrations/Version20240827102833.php deleted file mode 100644 index 00ab457..0000000 --- a/migrations/Version20240827102833.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE TABLE subnet (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, netmask VARCHAR(255) NOT NULL, ip_address VARCHAR(255) NOT NULL, next_server VARCHAR(255) NOT NULL, boot_file_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_91C24216D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE subnet'); - } -} diff --git a/migrations/Version20240902124157.php b/migrations/Version20240902124157.php deleted file mode 100644 index 5c320b9..0000000 --- a/migrations/Version20240902124157.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE network_settings ADD next_server VARCHAR(255) DEFAULT NULL, ADD boot_file_name VARCHAR(255) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE network_settings ADD og_live_id INT DEFAULT NULL, DROP next_server, DROP boot_file_name'); - $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B54F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id)'); - - } -} diff --git a/migrations/Version20240903081001.php b/migrations/Version20240903081001.php deleted file mode 100644 index 9202867..0000000 --- a/migrations/Version20240903081001.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('ALTER TABLE organizational_unit ADD subnet_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2DC9CF9478 FOREIGN KEY (subnet_id) REFERENCES subnet (id)'); - $this->addSql('CREATE INDEX IDX_749AEB2DC9CF9478 ON organizational_unit (subnet_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2DC9CF9478'); - $this->addSql('DROP INDEX IDX_749AEB2DC9CF9478 ON organizational_unit'); - $this->addSql('ALTER TABLE organizational_unit DROP subnet_id'); - } -} diff --git a/migrations/Version20240904134540.php b/migrations/Version20240904134540.php deleted file mode 100644 index df9dd35..0000000 --- a/migrations/Version20240904134540.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('ALTER TABLE client CHANGE og_live_id subnet_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455C9CF9478 FOREIGN KEY (subnet_id) REFERENCES subnet (id)'); - $this->addSql('CREATE INDEX IDX_C7440455C9CF9478 ON client (subnet_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455C9CF9478'); - $this->addSql('DROP INDEX IDX_C7440455C9CF9478 ON client'); - $this->addSql('ALTER TABLE client CHANGE subnet_id og_live_id INT DEFAULT NULL'); - } -} diff --git a/migrations/Version20240905080435.php b/migrations/Version20240905080435.php deleted file mode 100644 index 82c72f8..0000000 --- a/migrations/Version20240905080435.php +++ /dev/null @@ -1,32 +0,0 @@ -addSql('ALTER TABLE og_live ADD status VARCHAR(255) NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE og_live DROP status'); - - } -} diff --git a/migrations/Version20240916073039.php b/migrations/Version20240916073039.php deleted file mode 100644 index ba99c0b..0000000 --- a/migrations/Version20240916073039.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE TABLE command (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, script VARCHAR(255) NOT NULL, comments VARCHAR(255) DEFAULT NULL, read_only TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8ECAEAD4D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE command'); - } -} diff --git a/migrations/Version20240916091601.php b/migrations/Version20240916091601.php deleted file mode 100644 index 9f3304d..0000000 --- a/migrations/Version20240916091601.php +++ /dev/null @@ -1,37 +0,0 @@ -addSql('CREATE TABLE command_group (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, position INT NOT NULL, name VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_FE6811F6D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE command_group_command (command_group_id INT NOT NULL, command_id INT NOT NULL, INDEX IDX_118CE215C7B800D6 (command_group_id), INDEX IDX_118CE21533E1689A (command_id), PRIMARY KEY(command_group_id, command_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE command_group_command ADD CONSTRAINT FK_118CE215C7B800D6 FOREIGN KEY (command_group_id) REFERENCES command_group (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE command_group_command ADD CONSTRAINT FK_118CE21533E1689A FOREIGN KEY (command_id) REFERENCES command (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE command_group_command DROP FOREIGN KEY FK_118CE215C7B800D6'); - $this->addSql('ALTER TABLE command_group_command DROP FOREIGN KEY FK_118CE21533E1689A'); - $this->addSql('DROP TABLE command_group'); - $this->addSql('DROP TABLE command_group_command'); - } -} diff --git a/migrations/Version20240917064754.php b/migrations/Version20240917064754.php deleted file mode 100644 index 64f1f9b..0000000 --- a/migrations/Version20240917064754.php +++ /dev/null @@ -1,43 +0,0 @@ -addSql('CREATE TABLE command_task (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, datetime DATETIME NOT NULL, notes VARCHAR(255) DEFAULT NULL, status VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_F3D475A8D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE command_task_command (command_task_id INT NOT NULL, command_id INT NOT NULL, INDEX IDX_BB417CA862DC5265 (command_task_id), INDEX IDX_BB417CA833E1689A (command_id), PRIMARY KEY(command_task_id, command_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE command_task_command_group (command_task_id INT NOT NULL, command_group_id INT NOT NULL, INDEX IDX_C43618BD62DC5265 (command_task_id), INDEX IDX_C43618BDC7B800D6 (command_group_id), PRIMARY KEY(command_task_id, command_group_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE command_task_command ADD CONSTRAINT FK_BB417CA862DC5265 FOREIGN KEY (command_task_id) REFERENCES command_task (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE command_task_command ADD CONSTRAINT FK_BB417CA833E1689A FOREIGN KEY (command_id) REFERENCES command (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE command_task_command_group ADD CONSTRAINT FK_C43618BD62DC5265 FOREIGN KEY (command_task_id) REFERENCES command_task (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE command_task_command_group ADD CONSTRAINT FK_C43618BDC7B800D6 FOREIGN KEY (command_group_id) REFERENCES command_group (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE command_task_command DROP FOREIGN KEY FK_BB417CA862DC5265'); - $this->addSql('ALTER TABLE command_task_command DROP FOREIGN KEY FK_BB417CA833E1689A'); - $this->addSql('ALTER TABLE command_task_command_group DROP FOREIGN KEY FK_C43618BD62DC5265'); - $this->addSql('ALTER TABLE command_task_command_group DROP FOREIGN KEY FK_C43618BDC7B800D6'); - $this->addSql('DROP TABLE command_task'); - $this->addSql('DROP TABLE command_task_command'); - $this->addSql('DROP TABLE command_task_command_group'); - } -} diff --git a/migrations/Version20240917091950.php b/migrations/Version20240917091950.php deleted file mode 100644 index 7645fa2..0000000 --- a/migrations/Version20240917091950.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('CREATE TABLE trace (id INT AUTO_INCREMENT NOT NULL, client_id INT NOT NULL, command_id INT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, status VARCHAR(255) NOT NULL, output VARCHAR(255) DEFAULT NULL, executed_at DATETIME NOT NULL, finished_at DATETIME NOT NULL, UNIQUE INDEX UNIQ_315BD5A1D17F50A6 (uuid), INDEX IDX_315BD5A119EB6921 (client_id), INDEX IDX_315BD5A133E1689A (command_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE trace ADD CONSTRAINT FK_315BD5A119EB6921 FOREIGN KEY (client_id) REFERENCES client (id)'); - $this->addSql('ALTER TABLE trace ADD CONSTRAINT FK_315BD5A133E1689A FOREIGN KEY (command_id) REFERENCES command (id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE trace DROP FOREIGN KEY FK_315BD5A119EB6921'); - $this->addSql('ALTER TABLE trace DROP FOREIGN KEY FK_315BD5A133E1689A'); - $this->addSql('DROP TABLE trace'); - } -} diff --git a/migrations/Version20240917092207.php b/migrations/Version20240917092207.php deleted file mode 100644 index f291bd8..0000000 --- a/migrations/Version20240917092207.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE trace CHANGE finished_at finished_at DATETIME DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE trace CHANGE finished_at finished_at DATETIME NOT NULL'); - } -} diff --git a/migrations/Version20240924071858.php b/migrations/Version20240924071858.php deleted file mode 100644 index d758402..0000000 --- a/migrations/Version20240924071858.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE command CHANGE script script LONGTEXT NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE command CHANGE script script VARCHAR(255) NOT NULL'); - } -} diff --git a/migrations/Version20240924090429.php b/migrations/Version20240924090429.php deleted file mode 100644 index ba9563c..0000000 --- a/migrations/Version20240924090429.php +++ /dev/null @@ -1,41 +0,0 @@ -addSql('CREATE TABLE remote_calendar (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_BD3BDE0AD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE remote_calendar_rule (id INT AUTO_INCREMENT NOT NULL, remote_calendar_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, busy_weekdays JSON NOT NULL COMMENT \'(DC2Type:json)\', busy_from_hour DATETIME NOT NULL, busy_to_hour DATETIME NOT NULL, is_remote_available TINYINT(1) NOT NULL, available_from_date DATE NOT NULL, available_to_date DATE NOT NULL, available_reason VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_EE93D058D17F50A6 (uuid), INDEX IDX_EE93D058C56641EE (remote_calendar_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE remote_calendar_rule ADD CONSTRAINT FK_EE93D058C56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id)'); - $this->addSql('ALTER TABLE organizational_unit ADD remote_calendar_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2DC56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id)'); - $this->addSql('CREATE INDEX IDX_749AEB2DC56641EE ON organizational_unit (remote_calendar_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2DC56641EE'); - $this->addSql('ALTER TABLE remote_calendar_rule DROP FOREIGN KEY FK_EE93D058C56641EE'); - $this->addSql('DROP TABLE remote_calendar'); - $this->addSql('DROP TABLE remote_calendar_rule'); - $this->addSql('DROP INDEX IDX_749AEB2DC56641EE ON organizational_unit'); - $this->addSql('ALTER TABLE organizational_unit DROP remote_calendar_id'); - } -} diff --git a/migrations/Version20240924095558.php b/migrations/Version20240924095558.php deleted file mode 100644 index b8b2d3b..0000000 --- a/migrations/Version20240924095558.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE remote_calendar_rule CHANGE busy_from_hour busy_from_hour TIME NOT NULL, CHANGE busy_to_hour busy_to_hour TIME NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE remote_calendar_rule CHANGE busy_from_hour busy_from_hour DATETIME NOT NULL, CHANGE busy_to_hour busy_to_hour DATETIME NOT NULL'); - } -} diff --git a/migrations/Version20240924100335.php b/migrations/Version20240924100335.php deleted file mode 100644 index 9edf05f..0000000 --- a/migrations/Version20240924100335.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON remote_calendar (name)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON remote_calendar'); - } -} diff --git a/migrations/Version20240924102357.php b/migrations/Version20240924102357.php deleted file mode 100644 index 069d3d3..0000000 --- a/migrations/Version20240924102357.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE remote_calendar_rule CHANGE busy_weekdays busy_weekdays JSON DEFAULT NULL COMMENT \'(DC2Type:json)\', CHANGE busy_from_hour busy_from_hour TIME DEFAULT NULL, CHANGE busy_to_hour busy_to_hour TIME DEFAULT NULL, CHANGE available_from_date available_from_date DATE DEFAULT NULL, CHANGE available_to_date available_to_date DATE DEFAULT NULL, CHANGE available_reason available_reason VARCHAR(255) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE remote_calendar_rule CHANGE busy_weekdays busy_weekdays JSON NOT NULL COMMENT \'(DC2Type:json)\', CHANGE busy_from_hour busy_from_hour TIME NOT NULL, CHANGE busy_to_hour busy_to_hour TIME NOT NULL, CHANGE available_from_date available_from_date DATE NOT NULL, CHANGE available_to_date available_to_date DATE NOT NULL, CHANGE available_reason available_reason VARCHAR(255) NOT NULL'); - } -} diff --git a/migrations/Version20240926085224.php b/migrations/Version20240926085224.php deleted file mode 100644 index b05ce37..0000000 --- a/migrations/Version20240926085224.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('ALTER TABLE remote_calendar_rule DROP FOREIGN KEY FK_EE93D058C56641EE'); - $this->addSql('ALTER TABLE remote_calendar_rule CHANGE remote_calendar_id remote_calendar_id INT NOT NULL'); - $this->addSql('ALTER TABLE remote_calendar_rule ADD CONSTRAINT FK_EE93D058C56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE remote_calendar_rule DROP FOREIGN KEY FK_EE93D058C56641EE'); - $this->addSql('ALTER TABLE remote_calendar_rule CHANGE remote_calendar_id remote_calendar_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE remote_calendar_rule ADD CONSTRAINT FK_EE93D058C56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id)'); - } -} diff --git a/migrations/Version20240926104532.php b/migrations/Version20240926104532.php deleted file mode 100644 index 125bc93..0000000 --- a/migrations/Version20240926104532.php +++ /dev/null @@ -1,32 +0,0 @@ -addSql('ALTER TABLE command_group DROP position'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE organizational_unit ADD FK_749AEB2DC56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id)'); - $this->addSql('ALTER TABLE command_group ADD position INT NOT NULL'); - } -} diff --git a/migrations/Version20240930131003.php b/migrations/Version20240930131003.php deleted file mode 100644 index 68b2308..0000000 --- a/migrations/Version20240930131003.php +++ /dev/null @@ -1,45 +0,0 @@ -addSql('CREATE TABLE command_task_client (command_task_id INT NOT NULL, client_id INT NOT NULL, INDEX IDX_F97A827D62DC5265 (command_task_id), INDEX IDX_F97A827D19EB6921 (client_id), PRIMARY KEY(command_task_id, client_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE command_task_client ADD CONSTRAINT FK_F97A827D62DC5265 FOREIGN KEY (command_task_id) REFERENCES command_task (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE command_task_client ADD CONSTRAINT FK_F97A827D19EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455F7E54CF3'); - $this->addSql('DROP INDEX IDX_C7440455F7E54CF3 ON client'); - $this->addSql('ALTER TABLE client ADD og_live_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id)'); - $this->addSql('CREATE INDEX IDX_C7440455F7E54CF3 ON client (og_live_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE command_task_client DROP FOREIGN KEY FK_F97A827D62DC5265'); - $this->addSql('ALTER TABLE command_task_client DROP FOREIGN KEY FK_F97A827D19EB6921'); - $this->addSql('DROP TABLE command_task_client'); - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455F7E54CF3'); - $this->addSql('DROP INDEX IDX_C7440455F7E54CF3 ON client'); - $this->addSql('ALTER TABLE client DROP og_live_id'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455F7E54CF3 FOREIGN KEY (subnet_id) REFERENCES og_live (id)'); - $this->addSql('CREATE INDEX IDX_C7440455F7E54CF3 ON client (subnet_id)'); - } -} diff --git a/migrations/Version20241002062742.php b/migrations/Version20241002062742.php deleted file mode 100644 index d867007..0000000 --- a/migrations/Version20241002062742.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE organizational_unit ADD remote_pc TINYINT(1) NOT NULL, ADD reserved TINYINT(1) NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE organizational_unit DROP remote_pc, DROP reserved'); - } -} diff --git a/migrations/Version20241008080902.php b/migrations/Version20241008080902.php deleted file mode 100644 index dc61c00..0000000 --- a/migrations/Version20241008080902.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('ALTER TABLE `partition` ADD image_id INT NOT NULL'); - $this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E43DA5256D FOREIGN KEY (image_id) REFERENCES image (id)'); - $this->addSql('CREATE INDEX IDX_9EB910E43DA5256D ON `partition` (image_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E43DA5256D'); - $this->addSql('DROP INDEX IDX_9EB910E43DA5256D ON `partition`'); - $this->addSql('ALTER TABLE `partition` DROP image_id'); - } -} diff --git a/migrations/Version20241008081013.php b/migrations/Version20241008081013.php deleted file mode 100644 index 87b726c..0000000 --- a/migrations/Version20241008081013.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE client ADD maintenance TINYINT(1) NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP maintenance'); - } -} diff --git a/migrations/Version20241008092247.php b/migrations/Version20241008092247.php deleted file mode 100644 index 033c6bc..0000000 --- a/migrations/Version20241008092247.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE image CHANGE software_profile_id software_profile_id INT DEFAULT NULL, CHANGE path path VARCHAR(255) DEFAULT NULL, CHANGE type type VARCHAR(255) DEFAULT NULL, CHANGE size size INT DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE image CHANGE software_profile_id software_profile_id INT NOT NULL, CHANGE path path VARCHAR(255) NOT NULL, CHANGE type type VARCHAR(255) NOT NULL, CHANGE size size INT NOT NULL'); - } -} diff --git a/migrations/Version20241008092849.php b/migrations/Version20241008092849.php deleted file mode 100644 index 5c39be2..0000000 --- a/migrations/Version20241008092849.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('ALTER TABLE image ADD organizational_unit_id INT NOT NULL'); - $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045FFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); - $this->addSql('CREATE INDEX IDX_C53D045FFB84408A ON image (organizational_unit_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045FFB84408A'); - $this->addSql('DROP INDEX IDX_C53D045FFB84408A ON image'); - $this->addSql('ALTER TABLE image DROP organizational_unit_id'); - } -} diff --git a/migrations/Version20241014053130.php b/migrations/Version20241014053130.php deleted file mode 100644 index 5abd23e..0000000 --- a/migrations/Version20241014053130.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE subnet ADD server_id INT DEFAULT NULL, ADD synchronized TINYINT(1) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE subnet DROP server_id, DROP synchronized'); - } -} diff --git a/migrations/Version20241014082029.php b/migrations/Version20241014082029.php deleted file mode 100644 index 7777645..0000000 --- a/migrations/Version20241014082029.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455C9CF9478'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455C9CF9478 FOREIGN KEY (subnet_id) REFERENCES subnet (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455C9CF9478'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455C9CF9478 FOREIGN KEY (subnet_id) REFERENCES subnet (id)'); - } -} diff --git a/migrations/Version20241014102105.php b/migrations/Version20241014102105.php deleted file mode 100644 index 6015cff..0000000 --- a/migrations/Version20241014102105.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455C9CF9478'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455C9CF9478 FOREIGN KEY (subnet_id) REFERENCES subnet (id) ON DELETE SET NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455C9CF9478'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455C9CF9478 FOREIGN KEY (subnet_id) REFERENCES subnet (id) ON DELETE CASCADE'); - } -} diff --git a/migrations/Version20241015154123.php b/migrations/Version20241015154123.php deleted file mode 100644 index 8a87c52..0000000 --- a/migrations/Version20241015154123.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE `partition` CHANGE image_id image_id INT DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE `partition` CHANGE image_id image_id INT NOT NULL'); - } -} diff --git a/migrations/Version20241016063657.php b/migrations/Version20241016063657.php deleted file mode 100644 index 340af96..0000000 --- a/migrations/Version20241016063657.php +++ /dev/null @@ -1,37 +0,0 @@ -addSql('ALTER TABLE software ADD type VARCHAR(255) NOT NULL'); - $this->addSql('ALTER TABLE software_profile ADD operative_system_id INT NOT NULL'); - $this->addSql('ALTER TABLE software_profile ADD CONSTRAINT FK_B70C3C9BF1E9F66E FOREIGN KEY (operative_system_id) REFERENCES operative_system (id)'); - $this->addSql('CREATE INDEX IDX_B70C3C9BF1E9F66E ON software_profile (operative_system_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE software DROP type'); - $this->addSql('ALTER TABLE software_profile DROP FOREIGN KEY FK_B70C3C9BF1E9F66E'); - $this->addSql('DROP INDEX IDX_B70C3C9BF1E9F66E ON software_profile'); - $this->addSql('ALTER TABLE software_profile DROP operative_system_id'); - } -} diff --git a/migrations/Version20241016065729.php b/migrations/Version20241016065729.php deleted file mode 100644 index a33c8e2..0000000 --- a/migrations/Version20241016065729.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE software_profile CHANGE operative_system_id operative_system_id INT DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE software_profile CHANGE operative_system_id operative_system_id INT NOT NULL'); - } -} diff --git a/migrations/Version20241018055534.php b/migrations/Version20241018055534.php deleted file mode 100644 index 0c1d5ab..0000000 --- a/migrations/Version20241018055534.php +++ /dev/null @@ -1,39 +0,0 @@ -addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045FFB84408A'); - $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F19EB6921'); - $this->addSql('DROP INDEX IDX_C53D045F19EB6921 ON image'); - $this->addSql('DROP INDEX IDX_C53D045FFB84408A ON image'); - $this->addSql('ALTER TABLE image DROP client_id, DROP organizational_unit_id'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE image ADD client_id INT NOT NULL, ADD organizational_unit_id INT NOT NULL'); - $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045FFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); - $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F19EB6921 FOREIGN KEY (client_id) REFERENCES client (id)'); - $this->addSql('CREATE INDEX IDX_C53D045F19EB6921 ON image (client_id)'); - $this->addSql('CREATE INDEX IDX_C53D045FFB84408A ON image (organizational_unit_id)'); - } -} diff --git a/migrations/Version20241018060155.php b/migrations/Version20241018060155.php deleted file mode 100644 index 48d75fb..0000000 --- a/migrations/Version20241018060155.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE image ADD remote_pc TINYINT(1) NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE image DROP remote_pc'); - } -} diff --git a/migrations/Version20241019073142.php b/migrations/Version20241019073142.php deleted file mode 100644 index 645dac2..0000000 --- a/migrations/Version20241019073142.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE client ADD agent_job_id VARCHAR(255) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP agent_job_id'); - } -} diff --git a/migrations/Version20241021061008.php b/migrations/Version20241021061008.php deleted file mode 100644 index 84ba8f8..0000000 --- a/migrations/Version20241021061008.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455F7E54CF3'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id) ON DELETE SET NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455F7E54CF3'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id)'); - } -} diff --git a/migrations/Version20241021071250.php b/migrations/Version20241021071250.php deleted file mode 100644 index 054ddd6..0000000 --- a/migrations/Version20241021071250.php +++ /dev/null @@ -1,43 +0,0 @@ -addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455D4CBF752'); - $this->addSql('ALTER TABLE pxe_boot_file DROP FOREIGN KEY FK_7FD1F34B5DA0FB8'); - $this->addSql('DROP TABLE pxe_boot_file'); - $this->addSql('DROP INDEX IDX_C7440455D4CBF752 ON client'); - $this->addSql('ALTER TABLE client CHANGE pxe_boot_file_id template_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C74404555DA0FB8 FOREIGN KEY (template_id) REFERENCES pxe_template (id)'); - $this->addSql('CREATE INDEX IDX_C74404555DA0FB8 ON client (template_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE TABLE pxe_boot_file (id INT AUTO_INCREMENT NOT NULL, template_id INT DEFAULT NULL, uuid CHAR(36) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci` COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, updated_by VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, synchronized TINYINT(1) DEFAULT NULL, INDEX IDX_7FD1F34B5DA0FB8 (template_id), UNIQUE INDEX UNIQ_7FD1F34BD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); - $this->addSql('ALTER TABLE pxe_boot_file ADD CONSTRAINT FK_7FD1F34B5DA0FB8 FOREIGN KEY (template_id) REFERENCES pxe_template (id)'); - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C74404555DA0FB8'); - $this->addSql('DROP INDEX IDX_C74404555DA0FB8 ON client'); - $this->addSql('ALTER TABLE client CHANGE template_id pxe_boot_file_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455D4CBF752 FOREIGN KEY (pxe_boot_file_id) REFERENCES pxe_boot_file (id)'); - $this->addSql('CREATE INDEX IDX_C7440455D4CBF752 ON client (pxe_boot_file_id)'); - } -} diff --git a/migrations/Version20241021201438.php b/migrations/Version20241021201438.php deleted file mode 100644 index 7c1dc59..0000000 --- a/migrations/Version20241021201438.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE client ADD pxe_sync TINYINT(1) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE client DROP pxe_sync'); - } -} diff --git a/migrations/Version20241029112630.php b/migrations/Version20241029112630.php deleted file mode 100644 index 49f6115..0000000 --- a/migrations/Version20241029112630.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE TABLE image_repository (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, ip VARCHAR(255) NOT NULL, comments VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_302040FBD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE image_repository'); - } -} diff --git a/migrations/Version20241029145213.php b/migrations/Version20241029145213.php deleted file mode 100644 index f0c874a..0000000 --- a/migrations/Version20241029145213.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('ALTER TABLE image ADD repository_id INT NOT NULL'); - $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F50C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)'); - $this->addSql('CREATE INDEX IDX_C53D045F50C9D4F7 ON image (repository_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F50C9D4F7'); - $this->addSql('DROP INDEX IDX_C53D045F50C9D4F7 ON image'); - $this->addSql('ALTER TABLE image DROP repository_id'); - } -} diff --git a/migrations/Version20241105070853.php b/migrations/Version20241105070853.php deleted file mode 100644 index 3249af5..0000000 --- a/migrations/Version20241105070853.php +++ /dev/null @@ -1,43 +0,0 @@ -addSql('ALTER TABLE client ADD CONSTRAINT FK_C744045550C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)'); - $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045FFB84408A'); - $this->addSql('DROP INDEX IDX_C53D045FFB84408A ON image'); - $this->addSql('ALTER TABLE image ADD partition_info VARCHAR(255) DEFAULT NULL, CHANGE organizational_unit_id parent_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F727ACA70 FOREIGN KEY (parent_id) REFERENCES image (id)'); - $this->addSql('CREATE INDEX IDX_C53D045F727ACA70 ON image (parent_id)'); - $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B5450C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B5450C9D4F7'); - $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F727ACA70'); - $this->addSql('DROP INDEX IDX_C53D045F727ACA70 ON image'); - $this->addSql('ALTER TABLE image DROP partition_info, CHANGE parent_id organizational_unit_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045FFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); - $this->addSql('CREATE INDEX IDX_C53D045FFB84408A ON image (organizational_unit_id)'); - $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C744045550C9D4F7'); - } -} diff --git a/migrations/Version20241105085054.php b/migrations/Version20241105085054.php deleted file mode 100644 index bfd061c..0000000 --- a/migrations/Version20241105085054.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('ALTER TABLE image ADD client_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F19EB6921 FOREIGN KEY (client_id) REFERENCES client (id)'); - $this->addSql('CREATE INDEX IDX_C53D045F19EB6921 ON image (client_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F19EB6921'); - $this->addSql('DROP INDEX IDX_C53D045F19EB6921 ON image'); - $this->addSql('ALTER TABLE image DROP client_id'); - } -} diff --git a/migrations/Version20241106133332.php b/migrations/Version20241106133332.php deleted file mode 100644 index 745afee..0000000 --- a/migrations/Version20241106133332.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE trace ADD job_id VARCHAR(255) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE trace DROP job_id'); - } -} diff --git a/migrations/Version20241107074832.php b/migrations/Version20241107074832.php deleted file mode 100644 index 8481fc2..0000000 --- a/migrations/Version20241107074832.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE image ADD created TINYINT(1) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE image DROP created'); - } -} diff --git a/migrations/Version20241108062659.php b/migrations/Version20241108062659.php deleted file mode 100644 index 8d345ea..0000000 --- a/migrations/Version20241108062659.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE image ADD image_fullsum VARCHAR(255) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE image DROP image_fullsum'); - } -} diff --git a/migrations/Version20241111101047.php b/migrations/Version20241111101047.php deleted file mode 100644 index 75b1819..0000000 --- a/migrations/Version20241111101047.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE image ADD status VARCHAR(255) NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE image DROP status'); - } -} diff --git a/migrations/Version20241113084353.php b/migrations/Version20241113084353.php deleted file mode 100644 index 7b81205..0000000 --- a/migrations/Version20241113084353.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE network_settings ADD og_log VARCHAR(255) DEFAULT NULL, ADD og_share VARCHAR(255) DEFAULT NULL'); - $this->addSql('ALTER TABLE trace ADD input VARCHAR(255) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE network_settings DROP og_log, DROP og_share'); - $this->addSql('ALTER TABLE trace DROP input'); - } -} diff --git a/migrations/Version20241114081247.php b/migrations/Version20241114081247.php deleted file mode 100644 index 65c180c..0000000 --- a/migrations/Version20241114081247.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE trace CHANGE input input JSON DEFAULT NULL COMMENT \'(DC2Type:json)\''); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE trace CHANGE input input VARCHAR(255) DEFAULT NULL'); - } -} diff --git a/migrations/Version20241115074840.php b/migrations/Version20241115074840.php deleted file mode 100644 index 5246bdf..0000000 --- a/migrations/Version20241115074840.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON image (name)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON image'); - } -} diff --git a/migrations/Version20241120050107.php b/migrations/Version20241120050107.php deleted file mode 100644 index 3b0b972..0000000 --- a/migrations/Version20241120050107.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('ALTER TABLE trace DROP FOREIGN KEY FK_315BD5A133E1689A'); - $this->addSql('DROP INDEX IDX_315BD5A133E1689A ON trace'); - $this->addSql('ALTER TABLE trace ADD command VARCHAR(255) DEFAULT NULL, DROP command_id'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE trace ADD command_id INT NOT NULL, DROP command'); - $this->addSql('ALTER TABLE trace ADD CONSTRAINT FK_315BD5A133E1689A FOREIGN KEY (command_id) REFERENCES command (id)'); - $this->addSql('CREATE INDEX IDX_315BD5A133E1689A ON trace (command_id)'); - } -} diff --git a/migrations/Version20241120160808.php b/migrations/Version20241120160808.php new file mode 100644 index 0000000..b08b321 --- /dev/null +++ b/migrations/Version20241120160808.php @@ -0,0 +1,189 @@ +addSql('CREATE TABLE client (id INT AUTO_INCREMENT NOT NULL, organizational_unit_id INT DEFAULT NULL, menu_id INT DEFAULT NULL, hardware_profile_id INT DEFAULT NULL, template_id INT DEFAULT NULL, repository_id INT DEFAULT NULL, subnet_id INT DEFAULT NULL, og_live_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, serial_number VARCHAR(255) DEFAULT NULL, netiface VARCHAR(255) DEFAULT NULL, net_driver VARCHAR(255) DEFAULT NULL, mac VARCHAR(255) DEFAULT NULL, ip VARCHAR(255) DEFAULT NULL, status VARCHAR(255) DEFAULT NULL, validation TINYINT(1) DEFAULT NULL, position JSON DEFAULT NULL COMMENT \'(DC2Type:json)\', maintenance TINYINT(1) NOT NULL, agent_job_id VARCHAR(255) DEFAULT NULL, pxe_sync TINYINT(1) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_C7440455D17F50A6 (uuid), INDEX IDX_C7440455FB84408A (organizational_unit_id), INDEX IDX_C7440455CCD7E912 (menu_id), INDEX IDX_C7440455CFA495C1 (hardware_profile_id), INDEX IDX_C74404555DA0FB8 (template_id), INDEX IDX_C744045550C9D4F7 (repository_id), INDEX IDX_C7440455C9CF9478 (subnet_id), INDEX IDX_C7440455F7E54CF3 (og_live_id), UNIQUE INDEX UNIQ_IDENTIFIER_IP (ip), UNIQUE INDEX UNIQ_IDENTIFIER_MAC (mac), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE command (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, script LONGTEXT NOT NULL, comments VARCHAR(255) DEFAULT NULL, read_only TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8ECAEAD4D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE command_group (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_FE6811F6D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE command_group_command (command_group_id INT NOT NULL, command_id INT NOT NULL, INDEX IDX_118CE215C7B800D6 (command_group_id), INDEX IDX_118CE21533E1689A (command_id), PRIMARY KEY(command_group_id, command_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE command_task (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, datetime DATETIME NOT NULL, notes VARCHAR(255) DEFAULT NULL, status VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_F3D475A8D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE command_task_command (command_task_id INT NOT NULL, command_id INT NOT NULL, INDEX IDX_BB417CA862DC5265 (command_task_id), INDEX IDX_BB417CA833E1689A (command_id), PRIMARY KEY(command_task_id, command_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE command_task_command_group (command_task_id INT NOT NULL, command_group_id INT NOT NULL, INDEX IDX_C43618BD62DC5265 (command_task_id), INDEX IDX_C43618BDC7B800D6 (command_group_id), PRIMARY KEY(command_task_id, command_group_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE command_task_client (command_task_id INT NOT NULL, client_id INT NOT NULL, INDEX IDX_F97A827D62DC5265 (command_task_id), INDEX IDX_F97A827D19EB6921 (client_id), PRIMARY KEY(command_task_id, client_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE hardware (id INT AUTO_INCREMENT NOT NULL, type_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_FE99E9E0D17F50A6 (uuid), INDEX IDX_FE99E9E0C54C8C93 (type_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE hardware_profile (id INT AUTO_INCREMENT NOT NULL, organizational_unit_id INT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_2D9A2460D17F50A6 (uuid), INDEX IDX_2D9A2460FB84408A (organizational_unit_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE hardware_profile_hardware (hardware_profile_id INT NOT NULL, hardware_id INT NOT NULL, INDEX IDX_18C7E12CFA495C1 (hardware_profile_id), INDEX IDX_18C7E12C9CC762B (hardware_id), PRIMARY KEY(hardware_profile_id, hardware_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE hardware_type (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_2AA5A113D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE image (id INT AUTO_INCREMENT NOT NULL, software_profile_id INT DEFAULT NULL, repository_id INT NOT NULL, parent_id INT DEFAULT NULL, client_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, path VARCHAR(255) DEFAULT NULL, type VARCHAR(255) DEFAULT NULL, revision VARCHAR(255) DEFAULT NULL, info VARCHAR(255) DEFAULT NULL, size INT DEFAULT NULL, remote_pc TINYINT(1) NOT NULL, partition_info VARCHAR(255) DEFAULT NULL, created TINYINT(1) DEFAULT NULL, image_fullsum VARCHAR(255) DEFAULT NULL, status VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_C53D045FD17F50A6 (uuid), INDEX IDX_C53D045FED42A742 (software_profile_id), INDEX IDX_C53D045F50C9D4F7 (repository_id), INDEX IDX_C53D045F727ACA70 (parent_id), INDEX IDX_C53D045F19EB6921 (client_id), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE image_repository (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, ip VARCHAR(255) NOT NULL, comments VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_302040FBD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE menu (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, title VARCHAR(255) NOT NULL, resolution VARCHAR(255) NOT NULL, comments VARCHAR(255) DEFAULT NULL, public_url VARCHAR(255) DEFAULT NULL, private_url VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_7D053A93D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE network_settings (id INT AUTO_INCREMENT NOT NULL, menu_id INT DEFAULT NULL, hardware_profile_id INT DEFAULT NULL, repository_id INT DEFAULT NULL, og_live_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, next_server VARCHAR(255) DEFAULT NULL, boot_file_name VARCHAR(255) DEFAULT NULL, proxy VARCHAR(255) DEFAULT NULL, dns VARCHAR(255) DEFAULT NULL, netmask VARCHAR(255) DEFAULT NULL, router VARCHAR(255) DEFAULT NULL, ntp VARCHAR(255) DEFAULT NULL, p2p_time INT DEFAULT NULL, p2p_mode VARCHAR(255) DEFAULT NULL, mcast_ip VARCHAR(255) DEFAULT NULL, mcast_speed INT DEFAULT NULL, mcast_mode VARCHAR(255) DEFAULT NULL, mcast_port INT DEFAULT NULL, validation TINYINT(1) DEFAULT NULL, og_log VARCHAR(255) DEFAULT NULL, og_share VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_48869B54D17F50A6 (uuid), INDEX IDX_48869B54CCD7E912 (menu_id), INDEX IDX_48869B54CFA495C1 (hardware_profile_id), INDEX IDX_48869B5450C9D4F7 (repository_id), INDEX IDX_48869B54F7E54CF3 (og_live_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE og_live (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, download_url VARCHAR(255) DEFAULT NULL, checksum VARCHAR(255) DEFAULT NULL, distribution VARCHAR(255) DEFAULT NULL, kernel VARCHAR(255) DEFAULT NULL, architecture VARCHAR(255) DEFAULT NULL, revision VARCHAR(255) DEFAULT NULL, directory VARCHAR(255) DEFAULT NULL, filename VARCHAR(255) DEFAULT NULL, installed TINYINT(1) DEFAULT NULL, is_default TINYINT(1) DEFAULT NULL, status VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, synchronized TINYINT(1) DEFAULT NULL, UNIQUE INDEX UNIQ_3D6B7739D17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE operative_system (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_E9C44095D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE operative_system_type (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_4A13A156D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE organizational_unit (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, network_settings_id INT DEFAULT NULL, subnet_id INT DEFAULT NULL, remote_calendar_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, path VARCHAR(255) DEFAULT NULL, level INT DEFAULT NULL, slug VARCHAR(255) DEFAULT NULL, type VARCHAR(255) NOT NULL, location VARCHAR(255) DEFAULT NULL, projector TINYINT(1) DEFAULT NULL, board TINYINT(1) DEFAULT NULL, capacity INT DEFAULT NULL, remote_pc TINYINT(1) NOT NULL, reserved TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_749AEB2DD17F50A6 (uuid), INDEX IDX_749AEB2D727ACA70 (parent_id), INDEX IDX_749AEB2D9B9A36D0 (network_settings_id), INDEX IDX_749AEB2DC9CF9478 (subnet_id), INDEX IDX_749AEB2DC56641EE (remote_calendar_id), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name, parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE `partition` (id INT AUTO_INCREMENT NOT NULL, client_id INT DEFAULT NULL, operative_system_id INT DEFAULT NULL, image_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, disk_number INT DEFAULT NULL, partition_number INT DEFAULT NULL, partition_code VARCHAR(255) DEFAULT NULL, size INT NOT NULL, cache_content VARCHAR(255) DEFAULT NULL, filesystem VARCHAR(255) DEFAULT NULL, memory_usage INT NOT NULL, UNIQUE INDEX UNIQ_9EB910E4D17F50A6 (uuid), INDEX IDX_9EB910E419EB6921 (client_id), INDEX IDX_9EB910E4F1E9F66E (operative_system_id), INDEX IDX_9EB910E43DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE pxe_template (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, template_content LONGTEXT NOT NULL, name VARCHAR(255) NOT NULL, synchronized TINYINT(1) DEFAULT NULL, UNIQUE INDEX UNIQ_73197554D17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE refresh_tokens (id INT AUTO_INCREMENT NOT NULL, refresh_token VARCHAR(128) NOT NULL, username VARCHAR(255) NOT NULL, valid DATETIME NOT NULL, UNIQUE INDEX UNIQ_9BACE7E1C74F2195 (refresh_token), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE remote_calendar (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_BD3BDE0AD17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE remote_calendar_rule (id INT AUTO_INCREMENT NOT NULL, remote_calendar_id INT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, busy_weekdays JSON DEFAULT NULL COMMENT \'(DC2Type:json)\', busy_from_hour TIME DEFAULT NULL, busy_to_hour TIME DEFAULT NULL, is_remote_available TINYINT(1) NOT NULL, available_from_date DATE DEFAULT NULL, available_to_date DATE DEFAULT NULL, available_reason VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_EE93D058D17F50A6 (uuid), INDEX IDX_EE93D058C56641EE (remote_calendar_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE software (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, type VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_77D068CFD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE software_profile (id INT AUTO_INCREMENT NOT NULL, organizational_unit_id INT NOT NULL, operative_system_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_B70C3C9BD17F50A6 (uuid), INDEX IDX_B70C3C9BFB84408A (organizational_unit_id), INDEX IDX_B70C3C9BF1E9F66E (operative_system_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE software_profile_software (software_profile_id INT NOT NULL, software_id INT NOT NULL, INDEX IDX_3DDFEC7ED42A742 (software_profile_id), INDEX IDX_3DDFEC7D7452741 (software_id), PRIMARY KEY(software_profile_id, software_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE subnet (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, netmask VARCHAR(255) NOT NULL, ip_address VARCHAR(255) NOT NULL, next_server VARCHAR(255) NOT NULL, boot_file_name VARCHAR(255) NOT NULL, server_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, synchronized TINYINT(1) DEFAULT NULL, UNIQUE INDEX UNIQ_91C24216D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE trace (id INT AUTO_INCREMENT NOT NULL, client_id INT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, command VARCHAR(255) DEFAULT NULL, status VARCHAR(255) NOT NULL, output VARCHAR(255) DEFAULT NULL, executed_at DATETIME NOT NULL, finished_at DATETIME DEFAULT NULL, job_id VARCHAR(255) DEFAULT NULL, input JSON DEFAULT NULL COMMENT \'(DC2Type:json)\', UNIQUE INDEX UNIQ_315BD5A1D17F50A6 (uuid), INDEX IDX_315BD5A119EB6921 (client_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, username VARCHAR(180) NOT NULL, roles JSON NOT NULL COMMENT \'(DC2Type:json)\', password VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8D93D649D17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_USERNAME (username), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE user_user_group (user_id INT NOT NULL, user_group_id INT NOT NULL, INDEX IDX_28657971A76ED395 (user_id), INDEX IDX_286579711ED93D47 (user_group_id), PRIMARY KEY(user_id, user_group_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE user_organizational_unit (user_id INT NOT NULL, organizational_unit_id INT NOT NULL, INDEX IDX_5E59845FA76ED395 (user_id), INDEX IDX_5E59845FFB84408A (organizational_unit_id), PRIMARY KEY(user_id, organizational_unit_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE user_group (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, permissions JSON NOT NULL COMMENT \'(DC2Type:json)\', name VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8F02BF9DD17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE view (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, favourite TINYINT(1) NOT NULL, filters JSON DEFAULT NULL COMMENT \'(DC2Type:json)\', name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_FEFDAB8ED17F50A6 (uuid), INDEX IDX_FEFDAB8EA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455FB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455CCD7E912 FOREIGN KEY (menu_id) REFERENCES menu (id)'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455CFA495C1 FOREIGN KEY (hardware_profile_id) REFERENCES hardware_profile (id)'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C74404555DA0FB8 FOREIGN KEY (template_id) REFERENCES pxe_template (id)'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C744045550C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455C9CF9478 FOREIGN KEY (subnet_id) REFERENCES subnet (id) ON DELETE SET NULL'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id) ON DELETE SET NULL'); + $this->addSql('ALTER TABLE command_group_command ADD CONSTRAINT FK_118CE215C7B800D6 FOREIGN KEY (command_group_id) REFERENCES command_group (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE command_group_command ADD CONSTRAINT FK_118CE21533E1689A FOREIGN KEY (command_id) REFERENCES command (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE command_task_command ADD CONSTRAINT FK_BB417CA862DC5265 FOREIGN KEY (command_task_id) REFERENCES command_task (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE command_task_command ADD CONSTRAINT FK_BB417CA833E1689A FOREIGN KEY (command_id) REFERENCES command (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE command_task_command_group ADD CONSTRAINT FK_C43618BD62DC5265 FOREIGN KEY (command_task_id) REFERENCES command_task (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE command_task_command_group ADD CONSTRAINT FK_C43618BDC7B800D6 FOREIGN KEY (command_group_id) REFERENCES command_group (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE command_task_client ADD CONSTRAINT FK_F97A827D62DC5265 FOREIGN KEY (command_task_id) REFERENCES command_task (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE command_task_client ADD CONSTRAINT FK_F97A827D19EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE hardware ADD CONSTRAINT FK_FE99E9E0C54C8C93 FOREIGN KEY (type_id) REFERENCES hardware_type (id)'); + $this->addSql('ALTER TABLE hardware_profile ADD CONSTRAINT FK_2D9A2460FB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); + $this->addSql('ALTER TABLE hardware_profile_hardware ADD CONSTRAINT FK_18C7E12CFA495C1 FOREIGN KEY (hardware_profile_id) REFERENCES hardware_profile (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE hardware_profile_hardware ADD CONSTRAINT FK_18C7E12C9CC762B FOREIGN KEY (hardware_id) REFERENCES hardware (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045FED42A742 FOREIGN KEY (software_profile_id) REFERENCES software_profile (id)'); + $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F50C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)'); + $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F727ACA70 FOREIGN KEY (parent_id) REFERENCES image (id)'); + $this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F19EB6921 FOREIGN KEY (client_id) REFERENCES client (id)'); + $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B54CCD7E912 FOREIGN KEY (menu_id) REFERENCES menu (id)'); + $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B54CFA495C1 FOREIGN KEY (hardware_profile_id) REFERENCES hardware_profile (id)'); + $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B5450C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)'); + $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B54F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id)'); + $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2D727ACA70 FOREIGN KEY (parent_id) REFERENCES organizational_unit (id) ON DELETE SET NULL'); + $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2D9B9A36D0 FOREIGN KEY (network_settings_id) REFERENCES network_settings (id)'); + $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2DC9CF9478 FOREIGN KEY (subnet_id) REFERENCES subnet (id)'); + $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2DC56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id)'); + $this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E419EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E4F1E9F66E FOREIGN KEY (operative_system_id) REFERENCES operative_system (id)'); + $this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E43DA5256D FOREIGN KEY (image_id) REFERENCES image (id)'); + $this->addSql('ALTER TABLE remote_calendar_rule ADD CONSTRAINT FK_EE93D058C56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE software_profile ADD CONSTRAINT FK_B70C3C9BFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); + $this->addSql('ALTER TABLE software_profile ADD CONSTRAINT FK_B70C3C9BF1E9F66E FOREIGN KEY (operative_system_id) REFERENCES operative_system (id)'); + $this->addSql('ALTER TABLE software_profile_software ADD CONSTRAINT FK_3DDFEC7ED42A742 FOREIGN KEY (software_profile_id) REFERENCES software_profile (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE software_profile_software ADD CONSTRAINT FK_3DDFEC7D7452741 FOREIGN KEY (software_id) REFERENCES software (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE trace ADD CONSTRAINT FK_315BD5A119EB6921 FOREIGN KEY (client_id) REFERENCES client (id)'); + $this->addSql('ALTER TABLE user_user_group ADD CONSTRAINT FK_28657971A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE user_user_group ADD CONSTRAINT FK_286579711ED93D47 FOREIGN KEY (user_group_id) REFERENCES user_group (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE user_organizational_unit ADD CONSTRAINT FK_5E59845FA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE user_organizational_unit ADD CONSTRAINT FK_5E59845FFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8EA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455FB84408A'); + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455CCD7E912'); + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455CFA495C1'); + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C74404555DA0FB8'); + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C744045550C9D4F7'); + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455C9CF9478'); + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455F7E54CF3'); + $this->addSql('ALTER TABLE command_group_command DROP FOREIGN KEY FK_118CE215C7B800D6'); + $this->addSql('ALTER TABLE command_group_command DROP FOREIGN KEY FK_118CE21533E1689A'); + $this->addSql('ALTER TABLE command_task_command DROP FOREIGN KEY FK_BB417CA862DC5265'); + $this->addSql('ALTER TABLE command_task_command DROP FOREIGN KEY FK_BB417CA833E1689A'); + $this->addSql('ALTER TABLE command_task_command_group DROP FOREIGN KEY FK_C43618BD62DC5265'); + $this->addSql('ALTER TABLE command_task_command_group DROP FOREIGN KEY FK_C43618BDC7B800D6'); + $this->addSql('ALTER TABLE command_task_client DROP FOREIGN KEY FK_F97A827D62DC5265'); + $this->addSql('ALTER TABLE command_task_client DROP FOREIGN KEY FK_F97A827D19EB6921'); + $this->addSql('ALTER TABLE hardware DROP FOREIGN KEY FK_FE99E9E0C54C8C93'); + $this->addSql('ALTER TABLE hardware_profile DROP FOREIGN KEY FK_2D9A2460FB84408A'); + $this->addSql('ALTER TABLE hardware_profile_hardware DROP FOREIGN KEY FK_18C7E12CFA495C1'); + $this->addSql('ALTER TABLE hardware_profile_hardware DROP FOREIGN KEY FK_18C7E12C9CC762B'); + $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045FED42A742'); + $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F50C9D4F7'); + $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F727ACA70'); + $this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F19EB6921'); + $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B54CCD7E912'); + $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B54CFA495C1'); + $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B5450C9D4F7'); + $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B54F7E54CF3'); + $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2D727ACA70'); + $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2D9B9A36D0'); + $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2DC9CF9478'); + $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2DC56641EE'); + $this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E419EB6921'); + $this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E4F1E9F66E'); + $this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E43DA5256D'); + $this->addSql('ALTER TABLE remote_calendar_rule DROP FOREIGN KEY FK_EE93D058C56641EE'); + $this->addSql('ALTER TABLE software_profile DROP FOREIGN KEY FK_B70C3C9BFB84408A'); + $this->addSql('ALTER TABLE software_profile DROP FOREIGN KEY FK_B70C3C9BF1E9F66E'); + $this->addSql('ALTER TABLE software_profile_software DROP FOREIGN KEY FK_3DDFEC7ED42A742'); + $this->addSql('ALTER TABLE software_profile_software DROP FOREIGN KEY FK_3DDFEC7D7452741'); + $this->addSql('ALTER TABLE trace DROP FOREIGN KEY FK_315BD5A119EB6921'); + $this->addSql('ALTER TABLE user_user_group DROP FOREIGN KEY FK_28657971A76ED395'); + $this->addSql('ALTER TABLE user_user_group DROP FOREIGN KEY FK_286579711ED93D47'); + $this->addSql('ALTER TABLE user_organizational_unit DROP FOREIGN KEY FK_5E59845FA76ED395'); + $this->addSql('ALTER TABLE user_organizational_unit DROP FOREIGN KEY FK_5E59845FFB84408A'); + $this->addSql('ALTER TABLE view DROP FOREIGN KEY FK_FEFDAB8EA76ED395'); + $this->addSql('DROP TABLE client'); + $this->addSql('DROP TABLE command'); + $this->addSql('DROP TABLE command_group'); + $this->addSql('DROP TABLE command_group_command'); + $this->addSql('DROP TABLE command_task'); + $this->addSql('DROP TABLE command_task_command'); + $this->addSql('DROP TABLE command_task_command_group'); + $this->addSql('DROP TABLE command_task_client'); + $this->addSql('DROP TABLE hardware'); + $this->addSql('DROP TABLE hardware_profile'); + $this->addSql('DROP TABLE hardware_profile_hardware'); + $this->addSql('DROP TABLE hardware_type'); + $this->addSql('DROP TABLE image'); + $this->addSql('DROP TABLE image_repository'); + $this->addSql('DROP TABLE menu'); + $this->addSql('DROP TABLE network_settings'); + $this->addSql('DROP TABLE og_live'); + $this->addSql('DROP TABLE operative_system'); + $this->addSql('DROP TABLE operative_system_type'); + $this->addSql('DROP TABLE organizational_unit'); + $this->addSql('DROP TABLE `partition`'); + $this->addSql('DROP TABLE pxe_template'); + $this->addSql('DROP TABLE refresh_tokens'); + $this->addSql('DROP TABLE remote_calendar'); + $this->addSql('DROP TABLE remote_calendar_rule'); + $this->addSql('DROP TABLE software'); + $this->addSql('DROP TABLE software_profile'); + $this->addSql('DROP TABLE software_profile_software'); + $this->addSql('DROP TABLE subnet'); + $this->addSql('DROP TABLE trace'); + $this->addSql('DROP TABLE user'); + $this->addSql('DROP TABLE user_user_group'); + $this->addSql('DROP TABLE user_organizational_unit'); + $this->addSql('DROP TABLE user_group'); + $this->addSql('DROP TABLE view'); + } +} diff --git a/src/Service/OgBoot/StatusService.php b/src/Service/OgBoot/StatusService.php index 021f030..740e95e 100644 --- a/src/Service/OgBoot/StatusService.php +++ b/src/Service/OgBoot/StatusService.php @@ -36,7 +36,7 @@ readonly class StatusService ]); try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/status', [ + $response = $httpClient->request('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/status', [ 'headers' => [ 'accept' => 'application/json', ], diff --git a/src/Service/OgDhcp/StatusService.php b/src/Service/OgDhcp/StatusService.php index cc2a352..6c9cadf 100644 --- a/src/Service/OgDhcp/StatusService.php +++ b/src/Service/OgDhcp/StatusService.php @@ -34,7 +34,7 @@ readonly class StatusService ]); try { - $response = $httpClient->request('GET', $this->ogDhcpApiUrl.'/ogdhcp/v1/status', [ + $response = $httpClient->request('GET', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/status', [ 'headers' => [ 'accept' => 'application/json', ], From eb5aff8e7f2984f45dd2c87110aca1fa35a07f5e Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 20 Nov 2024 17:41:31 +0100 Subject: [PATCH 21/26] Updated Jankinsfile to send email first --- Jenkinsfile | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 802522e..c303b21 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -83,19 +83,7 @@ pipeline { } post { - always { - sh "docker compose -f ${DOCKER_COMPOSE_FILE} cp php:/report/phpunit.xml phpunit.xml" - // Publish JUnit test results - xunit ( - thresholds: [ skipped(failureThreshold: '0') , failed(failureThreshold: '0') ], - tools: [ PHPUnit(pattern: 'phpunit.xml') ] - ) - // Remove containers - - sh "docker compose -f ${DOCKER_COMPOSE_FILE} down" - sh "docker compose -f ${DOCKER_COMPOSE_FILE} rm -f" - sh "docker rmi ${DOCKER_IDENTITY}" - sh "docker rmi ${DOCKER_IDENTITY_NGINX}" + always { script { def committerEmail = sh ( script: "git show -s --pretty=%ae", @@ -113,6 +101,17 @@ pipeline { Opengnsys CI """ } + sh "docker compose -f ${DOCKER_COMPOSE_FILE} cp php:/report/phpunit.xml phpunit.xml" + // Publish JUnit test results + xunit ( + thresholds: [ skipped(failureThreshold: '0') , failed(failureThreshold: '0') ], + tools: [ PHPUnit(pattern: 'phpunit.xml') ] + ) + // Remove containers + sh "docker compose -f ${DOCKER_COMPOSE_FILE} down" + sh "docker compose -f ${DOCKER_COMPOSE_FILE} rm -f" + sh "docker rmi ${DOCKER_IDENTITY}" + sh "docker rmi ${DOCKER_IDENTITY_NGINX}" } } } From 38eb3775f1bf4a78523052913a83419af80b5241 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 20 Nov 2024 17:43:42 +0100 Subject: [PATCH 22/26] Updated database schema. Removed old versions --- config/api_platform/ImageRepository.yaml | 4 ++-- src/Controller/OgAgent/StatusAction.php | 5 +++++ src/Controller/OgRepository/GetCollectionAction.php | 4 ++-- src/Controller/OgRepository/SyncAction.php | 10 ++++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/config/api_platform/ImageRepository.yaml b/config/api_platform/ImageRepository.yaml index 43010ef..7ff7d33 100644 --- a/config/api_platform/ImageRepository.yaml +++ b/config/api_platform/ImageRepository.yaml @@ -24,8 +24,8 @@ resources: image_ogrepository_sync: shortName: OgRepository Server - class: ApiPlatform\Metadata\Post - method: POST + class: ApiPlatform\Metadata\Get + method: GET input: false uriTemplate: /image-repositories/server/sync controller: App\Controller\OgRepository\SyncAction diff --git a/src/Controller/OgAgent/StatusAction.php b/src/Controller/OgAgent/StatusAction.php index a8f7211..201361d 100644 --- a/src/Controller/OgAgent/StatusAction.php +++ b/src/Controller/OgAgent/StatusAction.php @@ -50,6 +50,11 @@ class StatusAction extends AbstractController if ($client->getStatus() === ClientStatus::LINUX) { $this->getSOStatus($client); } + + return new JsonResponse( + data: ['status' => $client->getStatus()], + status: Response::HTTP_OK + ); } public function getOgLiveStatus (Client $client): JsonResponse diff --git a/src/Controller/OgRepository/GetCollectionAction.php b/src/Controller/OgRepository/GetCollectionAction.php index f99bde0..594385a 100644 --- a/src/Controller/OgRepository/GetCollectionAction.php +++ b/src/Controller/OgRepository/GetCollectionAction.php @@ -21,9 +21,9 @@ class GetCollectionAction extends AbstractOgRepositoryController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(ImageRepository $data, HttpClientInterface $httpClient): JsonResponse + public function __invoke(ImageRepository $data): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', 'http://'.$data->getIp(). '/ogrepository/v1/images'); + $content = $this->createRequest('GET', 'http://'.$data->getIp(). ':8006/ogrepository/v1/images'); return new JsonResponse( data: $content, status: Response::HTTP_OK); } diff --git a/src/Controller/OgRepository/SyncAction.php b/src/Controller/OgRepository/SyncAction.php index 957c939..4fb4da5 100644 --- a/src/Controller/OgRepository/SyncAction.php +++ b/src/Controller/OgRepository/SyncAction.php @@ -4,7 +4,7 @@ namespace App\Controller\OgRepository; use App\Entity\Image; use App\Entity\ImageRepository; -use Doctrine\ORM\EntityManagerInterface; +use App\Model\ImageStatus; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; @@ -12,7 +12,6 @@ use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; -use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] class SyncAction extends AbstractOgRepositoryController @@ -23,9 +22,9 @@ class SyncAction extends AbstractOgRepositoryController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(ImageRepository $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse + public function __invoke(ImageRepository $data): JsonResponse { - $content = $this->createRequest($httpClient, 'GET', 'http://'.$data->getIp(). '/ogrepository/v1/images'); + $content = $this->createRequest('GET', 'http://'.$data->getIp(). ':8006/ogrepository/v1/images'); if (!isset($content['output']['REPOSITORY']['images'])) { return new JsonResponse(data: 'No images found', status: Response::HTTP_NOT_FOUND); @@ -36,6 +35,9 @@ class SyncAction extends AbstractOgRepositoryController if (!$imageEntity) { $imageEntity = new Image(); $imageEntity->setName($image['name'].$image['type']); + $imageEntity->setStatus(ImageStatus::SUCCESS); + $imageEntity->setRepository($data); + $imageEntity->setCreated(true ); $imageEntity->setImageFullsum($image['fullsum']); $imageEntity->setRemotePc(false); } From 1e998c9a3a813c005fab552168314ca5da894174 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 20 Nov 2024 18:04:41 +0100 Subject: [PATCH 23/26] Stop and delete docke containers before running --- Jenkinsfile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c303b21..6e7b885 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -22,8 +22,17 @@ pipeline { } stage('Build Environment') { steps { + sh """ + if [ -z "$(docker ps -q)" ]; then + echo "Docker is not running" + else + echo "Docker is running" + fi + docker stop $(docker ps -a -q) + docker rm $(docker ps -a -q) + """ script { - + docker.build("${DOCKER_IDENTITY}", '-f docker/Dockerfile-jenkins-php .') docker.build("${DOCKER_IDENTITY_NGINX}", '-f docker/Dockerfile-nginx .') } From 81da6b7a34d22fa74bd0988dbb1db8bd47f2a95b Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 20 Nov 2024 18:05:53 +0100 Subject: [PATCH 24/26] Fix typo --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6e7b885..8c6c876 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -22,7 +22,7 @@ pipeline { } stage('Build Environment') { steps { - sh """ + sh ''' if [ -z "$(docker ps -q)" ]; then echo "Docker is not running" else @@ -30,7 +30,7 @@ pipeline { fi docker stop $(docker ps -a -q) docker rm $(docker ps -a -q) - """ + ''' script { docker.build("${DOCKER_IDENTITY}", '-f docker/Dockerfile-jenkins-php .') From b0efe07977ca167167c21dc020813647f5dba6db Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 20 Nov 2024 18:16:29 +0100 Subject: [PATCH 25/26] Improvements in ogBoot API --- config/api_platform/Client.yaml | 1 + src/Controller/OgAgent/StatusAction.php | 28 ++++++++------------- src/Controller/OgBoot/OgLive/SyncAction.php | 3 ++- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/config/api_platform/Client.yaml b/config/api_platform/Client.yaml index d1e1d84..33a92c3 100644 --- a/config/api_platform/Client.yaml +++ b/config/api_platform/Client.yaml @@ -38,6 +38,7 @@ resources: class: ApiPlatform\Metadata\Post method: POST input: false + output: false uriTemplate: /clients/{uuid}/agent/status controller: App\Controller\OgAgent\StatusAction diff --git a/src/Controller/OgAgent/StatusAction.php b/src/Controller/OgAgent/StatusAction.php index 201361d..d0492dc 100644 --- a/src/Controller/OgAgent/StatusAction.php +++ b/src/Controller/OgAgent/StatusAction.php @@ -43,21 +43,21 @@ class StatusAction extends AbstractController throw new ValidatorException('IP is required'); } - if ($client->getStatus() === ClientStatus::OG_LIVE) { - $this->getOgLiveStatus($client); + if ($client->getStatus() === ClientStatus::OG_LIVE || $client->getStatus() === ClientStatus::OFF) { + $response = $this->getOgLiveStatus($client); } if ($client->getStatus() === ClientStatus::LINUX) { - $this->getSOStatus($client); + $response = $this->getSOStatus($client); } return new JsonResponse( - data: ['status' => $client->getStatus()], - status: Response::HTTP_OK + data: ['status' => $response], + status: $response === Response::HTTP_OK ? Response::HTTP_OK : Response::HTTP_INTERNAL_SERVER_ERROR ); } - public function getOgLiveStatus (Client $client): JsonResponse + public function getOgLiveStatus (Client $client): JsonResponse|int { try { $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [ @@ -75,10 +75,7 @@ class StatusAction extends AbstractController } catch (TransportExceptionInterface $e) { $client->setStatus(ClientStatus::OFF); - return new JsonResponse( - data: ['error' => $e->getMessage()], - status: Response::HTTP_INTERNAL_SERVER_ERROR - ); + return Response::HTTP_INTERNAL_SERVER_ERROR; } $data = json_decode($response->getContent(), true); @@ -90,10 +87,10 @@ class StatusAction extends AbstractController $this->entityManager->persist($client); $this->entityManager->flush(); - return new JsonResponse(status: Response::HTTP_OK); + return Response::HTTP_OK; } - public function getSOStatus (Client $client): JsonResponse + public function getSOStatus (Client $client): JsonResponse|int { try { $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/opengnsys/status', [ @@ -111,10 +108,7 @@ class StatusAction extends AbstractController } catch (TransportExceptionInterface $e) { $client->setStatus(ClientStatus::OFF); - return new JsonResponse( - data: ['error' => $e->getMessage()], - status: Response::HTTP_INTERNAL_SERVER_ERROR - ); + return Response::HTTP_INTERNAL_SERVER_ERROR; } $data = json_decode($response->getContent(), true); @@ -126,6 +120,6 @@ class StatusAction extends AbstractController $this->entityManager->persist($client); $this->entityManager->flush(); - return new JsonResponse(status: Response::HTTP_OK); + return Response::HTTP_OK; } } \ No newline at end of file diff --git a/src/Controller/OgBoot/OgLive/SyncAction.php b/src/Controller/OgBoot/OgLive/SyncAction.php index 791dba5..9de363e 100644 --- a/src/Controller/OgBoot/OgLive/SyncAction.php +++ b/src/Controller/OgBoot/OgLive/SyncAction.php @@ -19,6 +19,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] class SyncAction extends AbstractOgBootController { + const string OG_BOOT_DIRECTORY = '/opt/opengnsys/ogboot/tftpboot//'; /** * @throws TransportExceptionInterface * @throws ServerExceptionInterface @@ -53,7 +54,7 @@ class SyncAction extends AbstractOgBootController */ private function extracted(OgLive|null $ogLiveEntity, mixed $ogLive): void { - $ogLiveEntity->setName($ogLive['directory']); + $ogLiveEntity->setName(str_replace(self::OG_BOOT_DIRECTORY, '', $ogLive['directory'])); $ogLiveEntity->setInstalled(true); $ogLiveEntity->setArchitecture($ogLive['architecture']); $ogLiveEntity->setDistribution($ogLive['distribution']); From fed369eb1fe62c8fdbf92a52ecab4d7cff36a4b0 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 20 Nov 2024 18:40:11 +0100 Subject: [PATCH 26/26] Improve Jenkinsfile --- Jenkinsfile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8c6c876..64117be 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,13 +23,15 @@ pipeline { stage('Build Environment') { steps { sh ''' - if [ -z "$(docker ps -q)" ]; then - echo "Docker is not running" - else - echo "Docker is running" + # Detener todos los contenedores si hay alguno ejecutándose + if [ $(docker ps -q | wc -l) -gt 0 ]; then + docker stop $(docker ps -q) + fi + + # Eliminar todos los contenedores si hay alguno detenido + if [ $(docker ps -a -q | wc -l) -gt 0 ]; then + docker rm $(docker ps -a -q) fi - docker stop $(docker ps -a -q) - docker rm $(docker ps -a -q) ''' script {