Skip to content

Commit 3111ad9

Browse files
authored
Merge pull request #2784 from irontec/PROVIDER-2043-add-entitiy-ApplicationServerSets
Add entity application server sets
2 parents 6a9a063 + 7bdf83a commit 3111ad9

File tree

85 files changed

+3423
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3423
-93
lines changed

asterisk/agi/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
},
5858
"require": {
5959
"friendsofphp/proxy-manager-lts": "^1.0",
60-
"irontec/ivoz-provider-bundle": "^2.5",
60+
"irontec/ivoz-provider-bundle": "^2.6.11",
6161
"irontec/replacements": "^1.0",
6262
"php-mime-mail-parser/php-mime-mail-parser": "^7.0",
6363
"symfony/flex": "^1.9",

asterisk/agi/composer.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Application Server Sets
2+
3+
The Application Server Sets section allows users to manage sets of application servers by adding, deleting, and editing them.
4+
Overview
5+
6+
An Application Server Set consists of the following attributes:
7+
8+
Name: The name of the Application Server Set (string, required).
9+
Distribute Method: The method used for distributing tasks among servers (string, required). Possible values are:
10+
"Round Robin"
11+
"Hash"
12+
Description: A brief description of the Application Server Set (string, optional).
13+
Application Servers: A multi-select list where users can choose one or more application servers (string list). This can be left empty when creating an Application Server Set but is mandatory when editing.
14+
15+
Features
16+
17+
Add: Allows the user to create a new Application Server Set by providing a Name and a Distribute Method. The Description is optional, and the Application Servers list can initially be empty.
18+
Edit: Enables editing of an existing Application Server Set. While Name and Distribute Method remain mandatory, the Application Servers list must contain at least one selected server during the editing process.
19+
Delete: Permits the removal of an existing Application Server Set.
20+
21+
Field Descriptions
22+
Field Description Required
23+
Name The unique name of the Application Server Set. Yes
24+
Distribute Method The method of distributing tasks (Round Robin or Hash). Yes
25+
Description An optional description of the set. No
26+
Application Servers A multi-select list of chosen application servers. Can be empty on creation, but required on editing. No (creation), Yes (editing)
27+
Usage Notes
28+
29+
When creating a new Application Server Set, ensure that both Name and Distribute Method are provided.
30+
The Application Servers list can be left empty when first creating the set but must be populated with at least one server upon editing.

doc/sphinx/administration_portal/platform/infrastructure/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Sections in this group list the components of the platform and are not meant to
1010
proxy_users
1111
proxy_trunks
1212
media_relay_sets
13-
application_servers
13+
application_servers
14+
application_server_sets

library/DataFixtures/ORM/ProviderApplicationServer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public function load(ObjectManager $manager)
4040
$this->sanitizeEntityValues($item2);
4141
$manager->persist($item2);
4242

43+
$item3 = $this->createEntityInstance(ApplicationServer::class);
44+
(function () use ($fixture) {
45+
$this->setIp("127.1.1.2");
46+
$this->setName("test002");
47+
})->call($item3);
48+
49+
$this->addReference('_reference_ProviderApplicationServer3', $item3);
50+
$this->sanitizeEntityValues($item3);
51+
$manager->persist($item3);
4352

4453
$manager->flush();
4554
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace DataFixtures\ORM;
4+
5+
use Doctrine\Bundle\FixturesBundle\Fixture;
6+
use Doctrine\Common\DataFixtures\FixtureInterface;
7+
use Doctrine\Persistence\ObjectManager;
8+
use Doctrine\ORM\Mapping\ClassMetadata;
9+
use Ivoz\Provider\Domain\Model\ApplicationServerSet\ApplicationServerSet;
10+
11+
class ProviderApplicationServerSet extends Fixture implements FixtureInterface
12+
{
13+
use \DataFixtures\FixtureHelperTrait;
14+
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function load(ObjectManager $manager)
19+
{
20+
$fixture = $this;
21+
$this->disableLifecycleEvents($manager);
22+
$manager->getClassMetadata(ApplicationServerSet::class)->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
23+
$manager->getConnection()->exec(
24+
'INSERT INTO ApplicationServerSets (id, name, distributeMethod, description) VALUES (0, "default", "hash", "Default application server set")'
25+
);
26+
27+
$item1 = $this->createEntityInstance(ApplicationServerSet::class);
28+
(function () use ($fixture) {
29+
$this->setName('BlueApSet');
30+
$this->setDistributeMethod('hash');
31+
$this->setDescription('An Application Server Set');
32+
})->call($item1);
33+
34+
$this->addReference('_reference_ProviderApplicationServerSet1', $item1);
35+
$this->sanitizeEntityValues($item1);
36+
$manager->persist($item1);
37+
38+
$item2 = $this->createEntityInstance(ApplicationServerSet::class);
39+
(function () use ($fixture) {
40+
$this->setName('GreenApSet');
41+
$this->setDistributeMethod('rr');
42+
$this->setDescription('Another Application Server Set');
43+
})->call($item2);
44+
45+
$this->addReference('_reference_ProviderApplicationServerSet2', $item2);
46+
$this->sanitizeEntityValues($item2);
47+
$manager->persist($item2);
48+
49+
$manager->flush();
50+
}
51+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace DataFixtures\ORM;
4+
5+
use Doctrine\Bundle\FixturesBundle\Fixture;
6+
use Doctrine\Common\DataFixtures\FixtureInterface;
7+
use Doctrine\Persistence\ObjectManager;
8+
use Doctrine\ORM\Mapping\ClassMetadata;
9+
use Ivoz\Provider\Domain\Model\ApplicationServerSetRelApplicationServer\ApplicationServerSetRelApplicationServer;
10+
11+
class ProviderApplicationServerSetRelApplicationServers extends Fixture implements FixtureInterface
12+
{
13+
use \DataFixtures\FixtureHelperTrait;
14+
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function load(ObjectManager $manager)
19+
{
20+
$fixture = $this;
21+
$this->disableLifecycleEvents($manager);
22+
$manager->getClassMetadata(ApplicationServerSetRelApplicationServer::class)->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
23+
$manager->getConnection()->exec(
24+
'INSERT INTO ApplicationServerSetRelApplicationServers(applicationServerId, applicationServerSetId ) SELECT id, 0 FROM ApplicationServers'
25+
);
26+
$item1 = $this->createEntityInstance(ApplicationServerSetRelApplicationServer::class);
27+
(function () use ($fixture) {
28+
$this->setApplicationServer($fixture->getReference('_reference_ProviderApplicationServer1'));
29+
$this->setApplicationServerSet($fixture->getReference('_reference_ProviderApplicationServerSet1'));
30+
})->call($item1);
31+
$this->addReference('_reference_ApplicationServerSetRelApplicationServer1', $item1);
32+
$this->sanitizeEntityValues($item1);
33+
$manager->persist($item1);
34+
35+
$item2 = $this->createEntityInstance(ApplicationServerSetRelApplicationServer::class);
36+
(function () use ($fixture) {
37+
$this->setApplicationServer($fixture->getReference('_reference_ProviderApplicationServer2'));
38+
$this->setApplicationServerSet($fixture->getReference('_reference_ProviderApplicationServerSet1'));
39+
})->call($item2);
40+
$this->addReference('_reference_ApplicationServerSetRelApplicationServer2', $item2);
41+
$this->sanitizeEntityValues($item2);
42+
43+
$item3 = $this->createEntityInstance(ApplicationServerSetRelApplicationServer::class);
44+
(function () use ($fixture) {
45+
$this->setApplicationServer($fixture->getReference('_reference_ProviderApplicationServer1'));
46+
$this->setApplicationServerSet($fixture->getReference('_reference_ProviderApplicationServerSet2'));
47+
})->call($item3);
48+
$this->addReference('_reference_ApplicationServerSetRelApplicationServer3', $item3);
49+
$this->sanitizeEntityValues($item3);
50+
51+
$item4 = $this->createEntityInstance(ApplicationServerSetRelApplicationServer::class);
52+
(function () use ($fixture) {
53+
$this->setApplicationServer($fixture->getReference('_reference_ProviderApplicationServer3'));
54+
$this->setApplicationServerSet($fixture->getReference('_reference_ProviderApplicationServerSet2'));
55+
})->call($item4);
56+
$this->addReference('_reference_ApplicationServerSetRelApplicationServer4', $item4);
57+
$this->sanitizeEntityValues($item4);
58+
59+
$manager->flush();
60+
}
61+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Ivoz\Provider\Domain\Assembler\ApplicationServerSet;
4+
5+
use Ivoz\Core\Domain\Assert\Assertion;
6+
use Ivoz\Core\Domain\DataTransferObjectInterface;
7+
use Ivoz\Core\Domain\Model\EntityInterface;
8+
use Ivoz\Core\Domain\Service\Assembler\CustomDtoAssemblerInterface;
9+
use Ivoz\Provider\Domain\Model\ApplicationServerSet\ApplicationServerSet;
10+
use Ivoz\Provider\Domain\Model\ApplicationServerSetRelApplicationServer\ApplicationServerSetRelApplicationServerInterface;
11+
12+
class ApplicationServerSetDtoAssembler implements CustomDtoAssemblerInterface
13+
{
14+
public function toDto(EntityInterface $entity, int $depth = 0, string $context = null): DataTransferObjectInterface
15+
{
16+
Assertion::isInstanceOf($entity, ApplicationServerSet::class);
17+
18+
$dto = $entity->toDto($depth);
19+
$id = $entity->getId();
20+
21+
if (is_null($id)) {
22+
return $dto;
23+
}
24+
25+
if ($context === DataTransferObjectInterface::CONTEXT_SIMPLE) {
26+
return $dto;
27+
}
28+
29+
$relApplicationServers = $entity->getRelApplicationServers();
30+
$applicationServerIds = array_map(
31+
function (ApplicationServerSetRelApplicationServerInterface $relApplicationServer) {
32+
return (int) $relApplicationServer
33+
->getApplicationServer()
34+
?->getId();
35+
},
36+
$relApplicationServers
37+
);
38+
39+
$dto->setApplicationServers(
40+
$applicationServerIds
41+
);
42+
43+
return $dto;
44+
}
45+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Ivoz\Provider\Domain\Model\ApplicationServerSet;
4+
5+
use Ivoz\Core\Domain\Assert\Assertion;
6+
use Ivoz\Provider\Domain\Model\ApplicationServer\ApplicationServerInterface;
7+
use Ivoz\Provider\Domain\Model\ApplicationServerSetRelApplicationServer\ApplicationServerSetRelApplicationServerInterface;
8+
9+
/**
10+
* ApplicationServerSet
11+
*/
12+
class ApplicationServerSet extends ApplicationServerSetAbstract implements ApplicationServerSetInterface
13+
{
14+
use ApplicationServerSetTrait;
15+
16+
/**
17+
* @codeCoverageIgnore
18+
* @return array<string, mixed>
19+
*/
20+
public function getChangeSet(): array
21+
{
22+
return parent::getChangeSet();
23+
}
24+
25+
/**
26+
* Get id
27+
* @codeCoverageIgnore
28+
*/
29+
public function getId(): ?int
30+
{
31+
return $this->id;
32+
}
33+
34+
protected function sanitizeValues(): void
35+
{
36+
$this->sanitizeAvoidEmptyApplicationServers();
37+
}
38+
39+
/**
40+
* @return void
41+
* @throws \Assert\AssertionFailedException
42+
*/
43+
protected function sanitizeAvoidEmptyApplicationServers(): void
44+
{
45+
if ($this->isNew()) {
46+
return;
47+
}
48+
49+
$relApplicationServerSets = $this->getRelApplicationServers();
50+
51+
Assertion::notEmpty(
52+
$relApplicationServerSets
53+
);
54+
}
55+
}

0 commit comments

Comments
 (0)