public function tearDown()
 {
     // Delete local files
     $finder = new Finder();
     $fs = new Filesystem();
     $fs->remove($finder->files()->in($this->tmpDir . "/download"));
     $fs->remove($finder->files()->in($this->tmpDir));
     $fs->remove($this->tmpDir . "/download");
     $fs->remove($this->tmpDir);
     // Delete file uploads
     $options = new ListFilesOptions();
     $options->setTags(["docker-bundle-test"]);
     $files = $this->client->listFiles($options);
     foreach ($files as $file) {
         $this->client->deleteFile($file["id"]);
     }
     if ($this->client->bucketExists("in.c-docker-test")) {
         // Delete tables
         foreach ($this->client->listTables("in.c-docker-test") as $table) {
             $this->client->dropTable($table["id"]);
         }
         // Delete bucket
         $this->client->dropBucket("in.c-docker-test");
     }
     if ($this->client->bucketExists("in.c-docker-test-redshift")) {
         // Delete tables
         foreach ($this->client->listTables("in.c-docker-test-redshift") as $table) {
             $this->client->dropTable($table["id"]);
         }
         // Delete bucket
         $this->client->dropBucket("in.c-docker-test-redshift");
     }
 }
Example #2
0
 /**
  * @throws \Exception
  * @throws \Keboola\StorageApi\ClientException
  */
 protected function clearBucket()
 {
     // Delete tables and bucket
     if ($this->client->bucketExists("out.c-tde-test")) {
         foreach ($this->client->listTables("out.c-tde-test") as $table) {
             $this->client->dropTable($table["id"]);
         }
         // Delete bucket
         $this->client->dropBucket("out.c-tde-test");
     }
 }
 public function deleteWriter($id)
 {
     $bucket = $this->storageApi->getBucket($this->getSysBucketId($id));
     foreach ($bucket['tables'] as $table) {
         $this->storageApi->dropTable($table['id']);
     }
     $this->storageApi->dropBucket($bucket['id']);
 }
 protected function setUp($driver = null)
 {
     self::$client = static::createClient();
     $this->container = self::$client->getContainer();
     $sapiToken = $this->container->getParameter('storage_api.test.token');
     $sapiUrl = $this->container->getParameter('storage_api.test.url');
     self::$client->setServerParameters(['HTTP_X-StorageApi-Token' => $sapiToken]);
     $this->storageApi = new SapiClient(['token' => $sapiToken, 'url' => $sapiUrl, 'userAgent' => $this->componentName]);
     if ($driver != null) {
         $this->configuration = new Configuration($this->componentName . '-' . $driver, $this->storageApi, $driver);
     } else {
         $this->configuration = new Configuration($this->componentName, $this->storageApi);
     }
     // Cleanup
     $sysBucketId = $this->configuration->getSysBucketId($this->writerId);
     if ($this->storageApi->bucketExists($sysBucketId)) {
         $accTables = $this->storageApi->listTables($sysBucketId);
         foreach ($accTables as $table) {
             $this->storageApi->dropTable($table['id']);
         }
         $this->storageApi->dropBucket($sysBucketId);
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $force = $input->getOption('force');
     /**
      * @var QuestionHelper $helper
      */
     $helper = $this->getHelper('question');
     $question = new Question('Please enter your manage token: ');
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $manageToken = $helper->ask($input, $output, $question);
     $manageClient = new \Keboola\ManageApi\Client(["token" => $manageToken]);
     $this->client = new \GuzzleHttp\Client(['base_uri' => 'https://connection.keboola.com/manage/', 'headers' => ['X-KBC-ManageApiToken' => $manageToken, 'Accept-Encoding' => 'gzip', 'User-Agent' => $this->getUserAgent()]]);
     $this->dbOrchestrationManager = $this->getContainer()->get('orchestrator.doctrine.orchestration_manager');
     foreach ($manageClient->listMaintainers() as $maintainer) {
         $maintainerPrinted = false;
         $output->write('M');
         foreach ($this->loadOrganizations($maintainer) as $organization) {
             $organizationPrinted = false;
             $output->write('O');
             foreach ($manageClient->listOrganizationProjects($organization['id']) as $project) {
                 if ($project['isDisabled']) {
                     $output->write('P');
                     continue;
                 }
                 if (!$this->loadProjectOrchestrations($project['id']) && !$this->loadProjectDeletedOrchestrations($project['id'])) {
                     $output->write('P');
                     continue;
                 }
                 // delete orchestrator bucket if exists
                 if (!$maintainerPrinted) {
                     $maintainerPrinted = true;
                     $output->writeln("\t" . $maintainer['name']);
                 }
                 if (!$organizationPrinted) {
                     $organizationPrinted = true;
                     $output->writeln("\t\t" . $organization['name']);
                 }
                 $output->writeln("\t\t\t" . $project['name'] . " (" . $project['id'] . ")");
                 $projectToken = $manageClient->createProjectStorageToken($project['id'], ["description" => "Orchestrator old table deletion", "canManageBuckets" => true, "canReadAllFileUploads" => true, "expiresIn" => 1800]);
                 $client = new Client(["token" => $projectToken["token"]]);
                 foreach ($client->listBuckets() as $bucket) {
                     $bucketId = 'sys.c-orchestrator';
                     if ($bucket['id'] != $bucketId) {
                         continue;
                     }
                     // bucket delete
                     if ($force) {
                         try {
                             $client->dropBucket($bucketId, array('force' => true));
                             $output->writeln("\t\t\t\tOrchestrator bucket deleted");
                         } catch (Exception $e) {
                             $output->writeln("\t\t\t\t" . $e->getMessage());
                             continue;
                         }
                         $manageClient->addNotification(array('type' => 'common', 'projectId' => $project['id'], 'title' => sprintf(' Orchestrator bucket %s was removed from your project -- %s', 'sys.c-orchestrator', $project['name']), 'message' => 'As we announced on our [blog](http://status.keboola.com/orchestrator-table-deletion-announcement), ' . 'we have deleted the unused orchestrator bucket from your KBC storage. ' . 'This message is just for your information and has no effect on your existing orchestrations.'));
                         $output->writeln("\t\t\t\tNotification created");
                     } else {
                         $output->writeln("\t\t\t\tOrchestrator bucket will be deleted");
                     }
                 }
             }
         }
     }
 }