Skip to content
Snippets Groups Projects
Commit eaa1aff4 authored by Ryo Yamashita's avatar Ryo Yamashita Committed by Yas Naoi
Browse files

Issue #3232983 by Ryo Yamashita, yas, baldwinlouie: Refactor type hinting of Ec2OperationsService

parent f5d97c52
Branches 2497145-front-page
No related tags found
No related merge requests found
......@@ -2,10 +2,12 @@
namespace Drupal\aws_cloud\Service\Ec2;
use Drupal\aws_cloud\Entity\Ec2\ElasticIp;
use Drupal\Core\Entity\EntityDeleteFormTrait;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\aws_cloud\Entity\Ec2\ElasticIpInterface;
use Drupal\aws_cloud\Entity\Ec2\InstanceInterface;
use Drupal\aws_cloud\entity\ec2\ImageInterface;
use Drupal\cloud\Service\CloudServiceBase;
/**
......@@ -58,7 +60,7 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
/**
* {@inheritdoc}
*/
public function startInstance(EntityInterface $entity): bool {
public function startInstance(InstanceInterface $entity): bool {
$this->ec2Service->setCloudContext($entity->getCloudContext());
$result = $this->ec2Service->startInstances([
'InstanceIds' => [
......@@ -98,7 +100,7 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
/**
* {@inheritdoc}
*/
public function stopInstance(EntityInterface $entity): bool {
public function stopInstance(InstanceInterface $entity): bool {
$this->ec2Service->setCloudContext($entity->getCloudContext());
$result = $this->ec2Service->stopInstances([
'InstanceIds' => [
......@@ -138,11 +140,11 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
/**
* {@inheritdoc}
*/
public function rebootInstance(EntityInterface $entity): bool {
$this->ec2Service->setCloudContext($this->entity->getCloudContext());
public function rebootInstance(InstanceInterface $entity): bool {
$this->ec2Service->setCloudContext($entity->getCloudContext());
$result = $this->ec2Service->rebootInstances([
'InstanceIds' => [
$this->entity->getInstanceId(),
$entity->getInstanceId(),
],
]);
......@@ -174,7 +176,7 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
/**
* {@inheritdoc}
*/
public function deleteInstance(EntityInterface $entity): bool {
public function deleteInstance(InstanceInterface $entity): bool {
$this->entity = $entity;
$this->ec2Service->setCloudContext($entity->getCloudContext());
......@@ -210,7 +212,7 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
/**
* {@inheritdoc}
*/
public function getConsoleOutputFromInstance(EntityInterface $entity): string {
public function getConsoleOutputFromInstance(InstanceInterface $entity): string {
$this->ec2Service->setCloudContext($entity->getCloudContext());
$result = $this->ec2Service->getConsoleOutput(['InstanceId' => $entity->getInstanceId()]);
......@@ -229,13 +231,13 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
* @param string $image_id
* Image id to load.
*
* @return null|\Drupal\Core\Entity\EntityInterface
* @return null|\Drupal\aws_cloud\entity\ec2\ImageInterface
* NULL if not found else Image entity.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
private function loadNewImage($cloud_context, $image_id): ?EntityInterface {
private function loadNewImage(string $cloud_context, string $image_id): ?ImageInterface {
$entity = NULL;
$entities = $this->entityTypeManager
->getStorage('aws_cloud_image')
......@@ -258,13 +260,13 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
* @param string $cloud_context
* The cloud context.
*
* @return \Drupal\aws_cloud\Entity\Ec2\ElasticIp
* @return \Drupal\aws_cloud\Entity\Ec2\ElasticIpInterface
* The loaded aws_cloud_elastic_ip entity.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
private function getElasticIp($allocation_id, $cloud_context): ElasticIp {
private function getElasticIp(string $allocation_id, string $cloud_context): ElasticIpInterface {
$elastic_ip = FALSE;
$results = $this->entityTypeManager
->getStorage('aws_cloud_elastic_ip')
......@@ -281,7 +283,7 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
/**
* {@inheritdoc}
*/
public function createImageFromInstance(EntityInterface $entity, array $param): bool {
public function createImageFromInstance(InstanceInterface $entity, array $param): bool {
$this->ec2Service->setCloudContext($entity->getCloudContext());
$imageName = $param['imageName'];
$noRebootFlg = $param['noRebootFlg'];
......@@ -322,7 +324,7 @@ class Ec2OperationsService extends CloudServiceBase implements Ec2OperationsServ
/**
* {@inheritdoc}
*/
public function associateElasticIpForInstance(EntityInterface $entity, array $param): bool {
public function associateElasticIpForInstance(InstanceInterface $entity, array $param): bool {
$this->ec2Service->setCloudContext($entity->getCloudContext());
$allocation_id = $param['allocationId'];
$network_interface_id = $param['networkInterfaceId'];
......
......@@ -2,7 +2,7 @@
namespace Drupal\aws_cloud\Service\Ec2;
use Drupal\Core\Entity\EntityInterface;
use Drupal\aws_cloud\Entity\Ec2\InstanceInterface;
/**
* The Interface for Ec2OperationsService.
......@@ -12,62 +12,62 @@ interface Ec2OperationsServiceInterface {
/**
* Start AWS Cloud instance.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \Drupal\aws_cloud\Entity\Ec2\InstanceInterface $entity
* The AWS Cloud instance entity.
*
* @return bool
* TRUE when the process succeeds.
*/
public function startInstance(EntityInterface $entity): bool;
public function startInstance(InstanceInterface $entity): bool;
/**
* Stop AWS Cloud instance.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \Drupal\aws_cloud\Entity\Ec2\InstanceInterface $entity
* The AWS Cloud instance entity.
*
* @return bool
* TRUE when the process succeeds.
*/
public function stopInstance(EntityInterface $entity): bool;
public function stopInstance(InstanceInterface $entity): bool;
/**
* Reboot AWS Cloud instance.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \Drupal\aws_cloud\Entity\Ec2\InstanceInterface $entity
* The AWS Cloud instance entity.
*
* @return bool
* TRUE when the process succeeds.
*/
public function rebootInstance(EntityInterface $entity): bool;
public function rebootInstance(InstanceInterface $entity): bool;
/**
* Delete AWS Cloud instance.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \Drupal\aws_cloud\Entity\Ec2\InstanceInterface $entity
* The AWS Cloud instance entity.
*
* @return bool
* TRUE when the process succeeds.
*/
public function deleteInstance(EntityInterface $entity): bool;
public function deleteInstance(InstanceInterface $entity): bool;
/**
* Get console output from AWS Cloud instance.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \Drupal\aws_cloud\Entity\Ec2\InstanceInterface $entity
* The AWS Cloud instance entity.
*
* @return string
* Console output.
*/
public function getConsoleOutputFromInstance(EntityInterface $entity): string;
public function getConsoleOutputFromInstance(InstanceInterface $entity): string;
/**
* Create image from AWS Cloud instance.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \Drupal\aws_cloud\Entity\Ec2\InstanceInterface $entity
* The AWS Cloud instance entity.
* @param array $param
* Parameter.
......@@ -75,12 +75,12 @@ interface Ec2OperationsServiceInterface {
* @return bool
* TRUE when the process succeeds.
*/
public function createImageFromInstance(EntityInterface $entity, array $param): bool;
public function createImageFromInstance(InstanceInterface $entity, array $param): bool;
/**
* Associate an Elastic IP for AWS Cloud instance.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \Drupal\aws_cloud\Entity\Ec2\InstanceInterface $entity
* The AWS Cloud instance entity.
* @param array $param
* Parameter.
......@@ -88,6 +88,6 @@ interface Ec2OperationsServiceInterface {
* @return bool
* TRUE when the process succeeds.
*/
public function associateElasticIpForInstance(EntityInterface $entity, array $param): bool;
public function associateElasticIpForInstance(InstanceInterface $entity, array $param): bool;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment