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

Issue #3292794 by Ryo Yamashita, yas: Add the function to start AWS Cloud instance in the SPA

parent 4254148b
Loading
Loading
Loading
Loading
+11 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/aws_cloud/instance.ts: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -175,6 +175,17 @@ const AWS_CLOUD_INSTANCE_TEMPLATE: EntityFormTemplate[] = [
      }
    ],
  },
  {
    cloudServiceProvider: 'aws_cloud',
    entityName: 'instance',
    actionType: 'start',
    entityRecords: [
      {
        type: 'label',
        text: 'Are you sure you want to start the {{name}} {{entityName}}?',
      }
    ],
  },
  {
    cloudServiceProvider: 'aws_cloud',
    entityName: 'instance',
+10 −9
Changes for modules/cloud_service_providers/aws_cloud/aws_cloud.routing.yml: 10 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -939,15 +939,6 @@ entity.aws_cloud_instance.private_ips:
  options:
    perm: 'access dashboard'

entity.aws_cloud_instance.start:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_instance/{entity_id}/start'
  defaults:
    _controller: '\Drupal\aws_cloud\Controller\Ec2\ApiController::operateInstance'
    command: start
  methods: [POST]
  requirements:
    _entity_access: 'aws_cloud_instance.start'

entity.aws_cloud_instance.associate_elastic_ip:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_instance/{entity_id}/associate_elastic_ip'
  defaults:
@@ -1002,6 +993,16 @@ entity.aws_cloud_instance.reboot:
  requirements:
    _entity_access: 'aws_cloud_instance.reboot'

entity.aws_cloud_instance.start:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_instance/{entity_id}/start'
  defaults:
    _controller: '\Drupal\aws_cloud\Controller\Ec2\ApiController::operateEntity'
    entity_type_id: aws_cloud_instance
    command: start
  methods: [POST]
  requirements:
    _entity_access: 'aws_cloud_instance.start'

entity.aws_cloud_instance.stop:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_instance/{entity_id}/stop'
  defaults:
+4 −0
Changes for modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -870,6 +870,10 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
        $method_name = 'rebootInstance';
        break;

      case 'start_aws_cloud_instance':
        $method_name = 'startInstance';
        break;

      case 'stop_aws_cloud_instance':
        $method_name = 'stopInstance';
        break;
+11 −9
Changes for modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceRebootForm.php: 11 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

namespace Drupal\aws_cloud\Form\Ec2;

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\EntityLinkRendererInterface;
@@ -32,10 +32,10 @@ class InstanceRebootForm extends AwsDeleteUpdateEntityForm {
  /**
   * InstanceRebootForm 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 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
@@ -56,8 +56,8 @@ class InstanceRebootForm extends AwsDeleteUpdateEntityForm {
   *   The cloud service provider plugin manager (CloudConfigPluginManager).
   */
  public function __construct(
    AwsCloudOperationsServiceInterface $aws_cloud_operations_service,
    Ec2ServiceInterface $ec2_service,
                              Ec2OperationsServiceInterface $ec2_operations_service,
    EntityRepositoryInterface $entity_repository,
    EntityTypeBundleInfoInterface $entity_type_bundle_info,
    TimeInterface $time,
@@ -66,7 +66,8 @@ class InstanceRebootForm extends AwsDeleteUpdateEntityForm {
    CacheBackendInterface $cacheRender,
    CachedDiscoveryClearerInterface $plugin_cache_clearer,
    EntityLinkRendererInterface $entity_link_renderer,
                              CloudConfigPluginManagerInterface $cloud_config_plugin_manager) {
    CloudConfigPluginManagerInterface $cloud_config_plugin_manager
  ) {
    parent::__construct(
      $ec2_service,
      $entity_repository,
@@ -80,7 +81,7 @@ class InstanceRebootForm extends AwsDeleteUpdateEntityForm {
      $cloud_config_plugin_manager
    );

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

  /**
@@ -88,8 +89,8 @@ class InstanceRebootForm extends AwsDeleteUpdateEntityForm {
   */
  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'),
@@ -106,9 +107,10 @@ class InstanceRebootForm extends AwsDeleteUpdateEntityForm {
   * {@inheritdoc}
   */
  public function getQuestion(): TranslatableMarkup {
    /** @var \Drupal\aws_cloud\Entity\Ec2\InstanceInterface $entity */
    $entity = $this->entity;

    if ($this->ec2Service->isInstanceCloudOrchestrator($this->entity->getInstanceId()) === TRUE) {
    if ($this->ec2Service->isInstanceCloudOrchestrator($entity->getInstanceId()) === TRUE) {
      $this->messenger()->addWarning($this->t('Attempting to reboot Cloud Orchestrator instance.  Cloud Orchestrator will stop responding until the reboot is completed.'));
    }

@@ -128,7 +130,7 @@ class InstanceRebootForm extends AwsDeleteUpdateEntityForm {
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state): void {
    $this->awsCloudOperationsService->rebootInstance($this->entity);
    $this->awsCloudOperationsService->rebootInstance($this->entity, $form, $form_state);
  }

}
+14 −20
Changes for modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceStartForm.php: 14 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

namespace Drupal\aws_cloud\Form\Ec2;

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\EntityLinkRendererInterface;
@@ -25,19 +25,19 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class InstanceStartForm extends AwsDeleteUpdateEntityForm {

  /**
   * 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
   */
  private $ec2OperationsService;
  protected $awsCloudOperationsService;

  /**
   * InstanceStartForm 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 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
@@ -57,8 +57,9 @@ class InstanceStartForm extends AwsDeleteUpdateEntityForm {
   * @param \Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface $cloud_config_plugin_manager
   *   The cloud service provider plugin manager (CloudConfigPluginManager).
   */
  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,
@@ -67,7 +68,8 @@ class InstanceStartForm extends AwsDeleteUpdateEntityForm {
    CacheBackendInterface $cacheRender,
    CachedDiscoveryClearerInterface $plugin_cache_clearer,
    EntityLinkRendererInterface $entity_link_renderer,
                              CloudConfigPluginManagerInterface $cloud_config_plugin_manager) {
    CloudConfigPluginManagerInterface $cloud_config_plugin_manager
  ) {
    parent::__construct(
      $ec2_service,
      $entity_repository,
@@ -81,7 +83,7 @@ class InstanceStartForm extends AwsDeleteUpdateEntityForm {
      $cloud_config_plugin_manager
    );

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

  /**
@@ -89,8 +91,8 @@ class InstanceStartForm extends AwsDeleteUpdateEntityForm {
   */
  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'),
@@ -125,15 +127,7 @@ class InstanceStartForm extends AwsDeleteUpdateEntityForm {
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state): void {

    $entity = $this->entity;

    if (!$this->updateEntitySubmitForm($form_state, $entity)) {
      return;
    }

    $this->ec2OperationsService->startInstance($entity);
    $form_state->setRedirect("view.{$entity->getEntityTypeId()}.list", ['cloud_context' => $entity->getCloudContext()]);
    $this->awsCloudOperationsService->startInstance($this->entity, $form, $form_state);
  }

}
Loading