/** * Gets server history object * * @return \Scalr\Model\Entity\Server\History Returns server history object */ public function getServerHistory() { $bSave = false; $mapping = ['envId' => 'envId', 'farmId' => 'farmId', 'farmRoleId' => 'farmRoleId', 'serverIndex' => 'index', 'cloudLocation' => 'cloudLocation']; if (!isset($this->serverHistory)) { $entity = Entity\Server\History::findPk($this->serverId); if (!$entity) { $this->serverHistory = new Entity\Server\History(); $this->serverHistory->clientId = $this->clientId; $this->serverHistory->serverId = $this->serverId; $this->serverHistory->platform = $this->platform; $this->serverHistory->cloudLocation = $this->cloudLocation; $this->serverHistory->instanceTypeName = $this->instanceTypeName; $this->serverHistory->roleId = $this->GetProperty(SERVER_PROPERTIES::ROLE_ID); $this->serverHistory->farmCreatedById = $this->GetProperty(SERVER_PROPERTIES::FARM_CREATED_BY_ID); $this->serverHistory->osType = $this->osType; $bSave = true; } else { $this->serverHistory = $entity; } if ($this->GetEnvironmentObject()->analytics->enabled) { $this->serverHistory->projectId = $this->GetProperty(SERVER_PROPERTIES::FARM_PROJECT_ID); $this->serverHistory->ccId = $this->GetProperty(SERVER_PROPERTIES::ENV_CC_ID); $bSave = true; } if (!$this->serverHistory->cloudServerId) { $this->serverHistory->cloudServerId = $this->GetCloudServerID(); $this->serverHistory->type = $this->type; $bSave = true; } } foreach ($mapping as $prop => $key) { if ($this->serverHistory->{$prop} != $this->{$key}) { $this->serverHistory->{$prop} = $this->{$key}; $bSave = true; } } if (!empty($bSave)) { $this->serverHistory->save(); } return $this->serverHistory; }
/** * xChangeInstanceType * Resizes Ec2 instance * * @param string $serverId * @param string $instanceType * @throws \Scalr\Exception\ModelException * @throws InvalidArgumentException */ public function xChangeInstanceTypeAction($serverId, $instanceType) { $dbServer = DBServer::LoadByID($serverId); $this->user->getPermissions()->validate($dbServer); if (empty($instanceType)) { throw new InvalidArgumentException('Instance type cannot be empty.'); } if ($dbServer->getType() == $instanceType) { throw new InvalidArgumentException(sprintf("The server is already of %s type.", $instanceType)); } $dbServer->GetEnvironmentObject()->aws($dbServer->GetCloudLocation())->ec2->instance->modifyAttribute($dbServer->GetCloudServerID(), InstanceAttributeType::TYPE_INSTANCE_TYPE, $instanceType); // NOTE: instance type name equals to instance type id for ec2 platform $dbServer->update(['type' => $instanceType, 'instanceTypeName' => $instanceType]); $serverHistory = Entity\Server\History::findPk($serverId); /* @var $serverHistory Entity\Server\History */ $serverHistory->instanceTypeName = $instanceType; $serverHistory->type = $instanceType; $serverHistory->save(); $this->response->success("Server's instance type has been successfully modified."); }