Пример #1
0
 public function testFeature()
 {
     $this->assertTrue(defined('TEST_ORCHESTRATOR_HAS_FEATURE_SAPI_TOKEN'));
     $this->assertNotEmpty(constant('TEST_ORCHESTRATOR_HAS_FEATURE_SAPI_TOKEN'));
     $this->assertTrue(defined('TEST_ORCHESTRATOR_FEATURE'));
     $this->assertNotEmpty(constant('TEST_ORCHESTRATOR_FEATURE'));
     $token = new Token(new StorageApiClient(array('token' => TEST_ORCHESTRATOR_HAS_FEATURE_SAPI_TOKEN, 'url' => TEST_ORCHESTRATOR_SAPI_URL)));
     $this->assertTrue($token->hasEnabledFeature(TEST_ORCHESTRATOR_FEATURE));
     $this->assertFalse($token->hasEnabledFeature(md5(TEST_ORCHESTRATOR_FEATURE)));
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $this->dbOrchestrationManager = $this->getContainer()->get('orchestrator.doctrine.orchestration_manager');
     $projects = array();
     if ($input->getOption('projectId')) {
         $projects[(int) $input->getOption('projectId')] = (int) $input->getOption('projectId');
     } else {
         foreach ($this->dbOrchestrationManager->findOrchestrations(array()) as $orchestration) {
             $projects[$orchestration->getProjectId()] = (int) $orchestration->getProjectId();
         }
     }
     foreach ($projects as $projectId) {
         $output->writeln(sprintf('<info>[%s] Check start</info>', $projectId));
         $filter = array('projectId' => $projectId);
         foreach ($this->dbOrchestrationManager->findOrchestrations($filter) as $orchestration) {
             try {
                 $jobClient = $this->createProjectSapi($orchestration);
                 $token = new StorageApi\Token($jobClient);
                 if ($token->hasEnabledFeature(StorageApi\Token::ORCHESTRATOR_NEW_CONFIGURATION)) {
                     $output->writeln("\t" . sprintf('<comment>[%s] (%s) %s - New configuration already enabled</comment>', $orchestration->getProjectId(), $orchestration->getId(), $orchestration->getName()));
                     continue;
                 }
             } catch (DisabledException $e) {
                 $message = $e->getMessage();
                 if ($e->getPrevious()) {
                     $message = sprintf('%s: %s', $message, $e->getPrevious()->getMessage());
                 }
                 $output->writeln("\t" . sprintf('<error>[%s] (%s) %s - ' . $message . '</error>', $orchestration->getProjectId(), $orchestration->getId(), $orchestration->getName()));
                 continue;
             }
             $orchestration = $this->dbOrchestrationManager->findOrchestrationById($orchestration->getId(), $token, false);
             // validate configuration
             try {
                 $this->validateToken($jobClient);
                 if (!$input->getOption('onlyErrors')) {
                     $output->writeln("\t" . sprintf('<info>[%s] (%s) %s - Checked</info>', $orchestration->getProjectId(), $orchestration->getId(), $orchestration->getName()));
                 }
             } catch (StorageApi\InvalidStateException $e) {
                 $output->writeln("\t" . sprintf('<error>[%s] (%s) %s - %s</error>', $orchestration->getProjectId(), $orchestration->getId(), $orchestration->getName(), $e->getMessage()));
             }
         }
         $output->writeln(sprintf('<info>[%s] Check finished</info>', $projectId));
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $this->dbOrchestrationManager = $this->getContainer()->get('orchestrator.doctrine.orchestration_manager');
     $skippedCount = 0;
     $successCount = 0;
     $errorCount = 0;
     $force = $input->getOption('force');
     $projectId = $input->getArgument('projectId');
     $this->logger->info('configuration-migration.start ' . $projectId, array('test' => $force ? true : false));
     foreach ($this->loadProjectOrchestrations($projectId) as $orchestration) {
         try {
             $jobClient = $this->createProjectSapi($orchestration);
             $token = new StorageApi\Token($jobClient);
             if ($token->hasEnabledFeature(StorageApi\Token::ORCHESTRATOR_NEW_CONFIGURATION)) {
                 throw new DisabledException('Migration skipped: new configuration already enabled');
             }
         } catch (DisabledException $e) {
             $message = $e->getMessage();
             if ($e->getPrevious()) {
                 $message = sprintf('%s: %s', $message, $e->getMessage());
             }
             $output->writeln(sprintf('<error>' . $message . '</error>'));
             $this->logger->info('configuration-migration.failed ' . $projectId, array('test' => $force ? true : false, 'reason' => $message));
             $output->writeln(sprintf('<error>Finished with errors</error>'));
             return JobCommand::STATUS_ERROR;
         }
         $orchestration = $this->dbOrchestrationManager->findOrchestrationById($orchestration->getId(), $token, true);
         $components = new Components($jobClient);
         // remove old configuration
         $oldConfiguration = null;
         try {
             $oldConfiguration = $components->getConfiguration(KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME, sprintf("%s-%s", KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME, $orchestration->getId()));
         } catch (ClientException $e) {
             if ($e->getCode() !== 404) {
                 throw $e;
             }
         }
         if ($force) {
             // create or update configuration
             $orchestrationTaskManager = new StorageApi\OrchestrationTaskManager($jobClient);
             $orchestrationTaskManager->updateTasks($orchestration);
             // validate configuration
             try {
                 $this->validateConfiguration($orchestration, $jobClient);
                 $output->writeln(sprintf('<info>(%s) %s - Migrated</info>', $orchestration->getId(), $orchestration->getName()));
                 if ($oldConfiguration) {
                     $components->deleteConfiguration(KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME, $oldConfiguration['id']);
                     $output->writeln(sprintf('<comment>(%s) - Old configuration deleted</comment>', $oldConfiguration['id']));
                 }
                 $successCount++;
             } catch (StorageApi\InvalidStateException $e) {
                 $output->writeln(sprintf('<error>' . $e->getMessage() . '</error>'));
                 $errorCount++;
             }
         } else {
             $output->writeln(sprintf('<comment>(%s) %s - Will be migrated</comment>', $orchestration->getId(), $orchestration->getName()));
             if ($oldConfiguration) {
                 $output->writeln(sprintf('<comment>(%s) - Old configuration will be deleted</comment>', $oldConfiguration['id']));
             }
             $skippedCount++;
         }
     }
     if ($errorCount) {
         $output->writeln(sprintf('<error>Finished with errors</error>'));
     } else {
         $output->writeln(sprintf('<info>Finished</info>'));
     }
     $this->logger->info('configuration-migration.migrated ' . $projectId, array('test' => $force ? true : false, 'successCount' => $successCount, 'errorCount' => $errorCount, 'skippedCount' => $skippedCount));
     if ($errorCount) {
         return JobCommand::STATUS_ERROR;
     }
 }