Scalr\Tests\Service\Aws\RdsTest::deleteClusterObjects PHP Method

deleteClusterObjects() private method

Cleans up test objects
private deleteClusterObjects ( )
    private function deleteClusterObjects()
    {
        $rds = $this->getEnvironment()->aws(AwsTestCase::REGION)->rds;
        //Removes previously created DB Cluster Instances if they were not removed by some reason.
        try {
            /* @var $dbCluster DBClusterData */
            $dbCluster = $rds->dbCluster->describe(self::getTestName(self::NAME_INSTANCE))->get();
            $this->assertInstanceOf($this->getRdsClassName('DataType\\DBClusterData'), $dbCluster);
            foreach ($dbCluster->dBClusterMembers as $instance) {
                /* @var $instance DBInstanceData */
                $instance = $rds->dbInstance->describe($instance->dBInstanceIdentifier)->get();
                $this->removeDBInstance($instance);
            }
            if ($dbCluster->status != DBClusterData::STATUS_DELETING) {
                $dbCluster->delete(true);
                sleep(5);
                $dbCluster = $dbCluster->refresh();
            }
            $timeout = 0;
            while (isset($dbCluster->status) && $dbCluster->status == DBClusterData::STATUS_DELETING && ($timeout += static::SLEEP_TIMEOUT) < static::SLEEP_TIME) {
                sleep(static::SLEEP_TIMEOUT);
                $dbCluster = $dbCluster->refresh();
            }
            unset($dbCluster);
        } catch (ClientException $e) {
            if ($e->getErrorData()->getCode() != ErrorData::ERR_DB_CLUSTER_NOT_FOUND) {
                throw $e;
            }
        }
        //Removes previously created DB Cluster Snapshots if they were not removed by some reason.
        $snList = $rds->dbClusterSnapshot->describe(self::getTestName(self::NAME_INSTANCE));
        $this->assertInstanceOf($this->getRdsClassName('DataType\\DBClusterSnapshotList'), $snList);
        if ($snList->count() > 0) {
            /* @var $snapshot DBClusterSnapshotData */
            foreach ($snList as $snapshot) {
                $this->assertInstanceOf($this->getRdsClassName('DataType\\DBClusterSnapshotData'), $snapshot);
                $rds->dbClusterSnapshot->delete($snapshot->dBClusterSnapshotIdentifier);
            }
            $timeout = 0;
            while (($timeout += static::SLEEP_TIMEOUT) < static::SLEEP_TIME) {
                $snList->rewind();
                while ($snList->valid()) {
                    try {
                        sleep(static::SLEEP_TIMEOUT);
                        $rds->dbClusterSnapshot->describe(null, $snList->current()->dBClusterSnapshotIdentifier)->get();
                    } catch (ClientException $e) {
                        if ($e->getErrorData()->getCode() != ErrorData::ERR_DB_CLUSTER_SNAPSHOT_NOT_FOUND) {
                            throw $e;
                        }
                        $snList->offsetUnset($snList->key());
                    }
                    $snList->next();
                }
                if ($snList->count() === 0) {
                    break;
                }
            }
        }
        unset($snList);
        try {
            /* @var $subnetGroup DBSubnetGroupData */
            $subnetGroup = $rds->dbSubnetGroup->describe(self::getTestName('subnetname'))->get();
            $this->assertInstanceOf($this->getRdsClassName('DataType\\DBSubnetGroupData'), $subnetGroup);
            $this->assertTrue($rds->dbSubnetGroup->delete($subnetGroup->dBSubnetGroupName));
            unset($subnetGroup);
        } catch (ClientException $e) {
            if ($e->getErrorData()->getCode() != ErrorData::ERR_DB_SUBNET_GROUP_NOT_FOUND) {
                throw $e;
            }
        }
    }