Commit 07a4955f authored by Ryo Yamashita's avatar Ryo Yamashita Committed by Yas Naoi
Browse files

Issue #3285539 by Ryo Yamashita, yas: Refactor OpenStackOperationsService to...

Issue #3285539 by Ryo Yamashita, yas: Refactor OpenStackOperationsService to AwsCloudOperationsService
parent 2a432707
Loading
Loading
Loading
Loading
+5 −1
Changes for modules/cloud_service_providers/aws_cloud/aws_cloud.services.yml: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -65,5 +65,9 @@ services:
    arguments: ['@entity_type.manager', '@aws_cloud.ec2']

  aws_cloud.cloud_orchestrator_manager:
    class: Drupal\aws_cloud\Service\AwsCloudCloudOrchestratorManager
    class: Drupal\aws_cloud\Service\AwsCloud\AwsCloudCloudOrchestratorManager
    arguments: ['@aws_cloud.cloud_formation', '@entity_field.manager', '@entity_type.manager']

  aws_cloud.operations:
    class: Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsService
    arguments: ['@plugin.manager.cloud_config_plugin', '@cloud', '@aws_cloud.ec2', '@entity_type.manager']
+13 −0
Changes for modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\aws_cloud\Controller\Ec2;

use Drupal\aws_cloud\Entity\Ec2\Instance;
use Drupal\aws_cloud\Entity\Ec2\InstanceInterface;
use Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface;
use Drupal\aws_cloud\Service\CloudWatch\CloudWatchServiceInterface;
use Drupal\aws_cloud\Service\Ec2\Ec2OperationsServiceInterface;
use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface;
@@ -39,6 +40,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
  use CloudContentEntityTrait;
  use CloudResourceTrait;

  /**
   * The AWS Cloud Operations service.
   *
   * @var \Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface
   */
  protected $awsCloudOperationsService;

  /**
   * The AWS Cloud EC2 service.
   *
@@ -119,6 +127,8 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
  /**
   * ApiController constructor.
   *
   * @param \Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface $aws_cloud_operations_service
   *   The AWS Cloud Operations service.
   * @param \Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface $ec2_service
   *   Object for interfacing with AWS API.
   * @param \Drupal\aws_cloud\Service\Ec2\Ec2OperationsServiceInterface $ec2_operations_service
@@ -141,6 +151,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
   *   The current user.
   */
  public function __construct(
    AwsCloudOperationsServiceInterface $aws_cloud_operations_service,
    Ec2ServiceInterface $ec2_service,
    Ec2OperationsServiceInterface $ec2_operations_service,
    Messenger $messenger,
@@ -152,6 +163,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
    EntityTypeManagerInterface $entity_type_manager,
    AccountInterface $current_user) {

    $this->awsCloudOperationsService = $aws_cloud_operations_service;
    $this->ec2Service = $ec2_service;
    $this->ec2OperationsService = $ec2_operations_service;
    $this->messenger = $messenger;
@@ -176,6 +188,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('aws_cloud.operations'),
      $container->get('aws_cloud.ec2'),
      $container->get('aws_cloud.ec2_operations'),
      $container->get('messenger'),
+14 −55
Changes for modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php: 14 added lines, 55 removed lines.
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\aws_cloud\Entity\Ec2\ElasticIp;
use Drupal\aws_cloud\Entity\Ec2\PublicIpEntityLinkHtmlGenerator;
use Drupal\aws_cloud\Service\Ec2\Ec2OperationsServiceInterface;
use Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface;
use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface;
use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface;
use Drupal\cloud\Service\CloudServiceInterface;
@@ -38,19 +38,19 @@ class InstanceEditForm extends AwsCloudContentForm {
  public const SECURITY_GROUP_DELIMITER = ', ';

  /**
   * The AWS Cloud EC2 operation service.
   * The AWS Cloud Operations service.
   *
   * @var \Drupal\aws_cloud\Service\Ec2\Ec2OperationsServiceInterface
   * @var \Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface
   */
  protected $ec2OperationsService;
  protected $awsCloudOperationsService;

  /**
   * AwsCloudContentForm constructor.
   *
   * @param \Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface $aws_cloud_operations_service
   *   The AWS Cloud Operations service.
   * @param \Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface $ec2_service
   *   The AWS Cloud or OpenStack EC2 Service.
   * @param \Drupal\aws_cloud\Service\Ec2\Ec2OperationsServiceInterface $ec2_operations_service
   *   The AWS Cloud EC2 operations API service.
   * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
   *   The entity repository service.
   * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
@@ -80,8 +80,9 @@ class InstanceEditForm extends AwsCloudContentForm {
   * @param \Drupal\cloud\Service\CloudServiceInterface $cloud_service
   *   The Cloud service.
   */
  public function __construct(Ec2ServiceInterface $ec2_service,
                              Ec2OperationsServiceInterface $ec2_operations_service,
  public function __construct(
    AwsCloudOperationsServiceInterface $aws_cloud_operations_service,
    Ec2ServiceInterface $ec2_service,
    EntityRepositoryInterface $entity_repository,
    EntityTypeBundleInfoInterface $entity_type_bundle_info,
    TimeInterface $time,
@@ -95,7 +96,8 @@ class InstanceEditForm extends AwsCloudContentForm {
    RouteMatchInterface $route_match,
    DateFormatterInterface $date_formatter,
    RendererInterface $renderer,
                              CloudServiceInterface $cloud_service) {
    CloudServiceInterface $cloud_service
  ) {
    parent::__construct(
      $ec2_service,
      $entity_repository,
@@ -114,7 +116,7 @@ class InstanceEditForm extends AwsCloudContentForm {
      $cloud_service
    );

    $this->ec2OperationsService = $ec2_operations_service;
    $this->awsCloudOperationsService = $aws_cloud_operations_service;
  }

  /**
@@ -122,8 +124,8 @@ class InstanceEditForm extends AwsCloudContentForm {
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('aws_cloud.operations'),
      $container->get('aws_cloud.ec2'),
      $container->get('aws_cloud.ec2_operations'),
      $container->get('entity.repository'),
      $container->get('entity_type.bundle.info'),
      $container->get('datetime.time'),
@@ -639,50 +641,7 @@ class InstanceEditForm extends AwsCloudContentForm {
   * {@inheritdoc}
   */
  public function save(array $form, FormStateInterface $form_state): void {
    $entity = $this->entity;

    $termination_timestamp = !empty($form_state->getValue('termination_timestamp')[0]['value'])
      ? $form_state->getValue('termination_timestamp')[0]['value']->getTimeStamp()
      : NULL;

    $this->ec2OperationsService->editInstanceBeforeSave(
      $entity,
      $termination_timestamp,
      $form_state->getValue('security_groups'),
      self::SECURITY_GROUP_DELIMITER
    );

    parent::save($form, $form_state);

    if (!$form_state->getValue('user_data_base64_encoded')) {
      $entity->setUserData(base64_encode($entity->getUserData()));
      $entity->save();
    }

    $user_data_default_value = $form['options']['user_data_base64_encoded']['#default_value']
      ? $form['options']['user_data']['#default_value']
      : base64_encode($form['options']['user_data']['#default_value']);

    $config = \Drupal::config('aws_cloud.settings');
    $this->ec2OperationsService->editInstanceAfterSave(
      $this->cloudService,
      $entity,
      $form_state->getValue('tags'),
      $termination_timestamp,
      $config->get('aws_cloud_scheduler') === TRUE ? $this->getSchedule() : NULL,
      NULL,
      $form['instance']['instance_type']['#default_value'],
      $form_state->getValue('security_groups'),
      self::SECURITY_GROUP_DELIMITER,
      $form['network']['security_groups']['#default_value'],
      NULL,
      $form['options']['termination_protection']['#default_value'],
      NULL,
      $user_data_default_value,
      $form_state->getValue('add_new_elastic_ip'),
      $form_state->getValue('current_allocation_id'),
      $form_state->getValue('current_association_id')
    );
    $this->awsCloudOperationsService->editInstance($this->entity, $form, $form_state);
  }

  /**
+1 −1
Changes for modules/cloud_service_providers/aws_cloud/src/Service/AwsCloud/AwsCloudCloudOrchestratorManager.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
<?php

namespace Drupal\aws_cloud\Service;
namespace Drupal\aws_cloud\Service\AwsCloud;

use Drupal\aws_cloud\Service\CloudFormation\CloudFormationServiceInterface;
use Drupal\cloud\Service\CloudOrchestratorManagerInterface;
+728 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading