setName('app_api:app:unregister'); $this->setDescription('Unregister external app'); $this->addArgument('appid', InputArgument::REQUIRED); $this->addOption( 'silent', null, InputOption::VALUE_NONE, 'Print only minimum and only errors.'); $this->addOption( 'force', null, InputOption::VALUE_NONE, 'Continue removal even if errors.'); $this->addOption('keep-data', null, InputOption::VALUE_NONE, 'Keep ExApp data (volume) [deprecated, data is kept by default].'); $this->addOption('rm-data', null, InputOption::VALUE_NONE, 'Remove ExApp data (persistent storage volume).'); $this->addUsage('test_app'); $this->addUsage('test_app --silent'); $this->addUsage('test_app --rm-data'); $this->addUsage('test_app --silent --force --rm-data'); } protected function execute(InputInterface $input, OutputInterface $output): int { $appId = $input->getArgument('appid'); $silent = $input->getOption('silent'); $force = $input->getOption('force'); $rmData = $input->getOption('rm-data'); $exApp = $this->exAppService->getExApp($appId); if ($exApp === null) { if ($silent) { return 0; } $output->writeln(sprintf('ExApp %s not found. Failed to unregister.', $appId)); return 1; } if ($exApp->getEnabled()) { if (!$this->service->disableExApp($exApp)) { if (!$silent) { $output->writeln(sprintf('Error during disabling %s ExApp.', $appId)); } if (!$force) { return 1; } } elseif (!$silent) { $output->writeln(sprintf('ExApp %s successfully disabled.', $appId)); } } $daemonConfig = $this->daemonConfigService->getDaemonConfigByName($exApp->getDaemonConfigName()); if ($daemonConfig === null) { if (!$silent) { $output->writeln( sprintf('Failed to get ExApp %s DaemonConfig by name %s', $appId, $exApp->getDaemonConfigName()) ); } if (!$force) { return 1; } } if ($daemonConfig->getAcceptsDeployId() === $this->dockerActions->getAcceptsDeployId()) { $this->dockerActions->initGuzzleClient($daemonConfig); if (boolval($exApp->getDeployConfig()['harp'] ?? false)) { if ($this->dockerActions->removeExApp($this->dockerActions->buildDockerUrl($daemonConfig), $exApp->getAppid(), removeData: $rmData)) { if (!$silent) { $output->writeln(sprintf('Failed to remove ExApp %s', $appId)); $output->writeln('Hint: If the container was already removed manually, you can use the --force option to fully remove it from AppAPI.'); } if (!$force) { return 1; } } else { if (!$silent) { $output->writeln(sprintf('ExApp %s successfully removed', $appId)); } } } else { $containerName = $this->dockerActions->buildExAppContainerName($appId); $removeResult = $this->dockerActions->removeContainer( $this->dockerActions->buildDockerUrl($daemonConfig), $containerName ); if ($removeResult) { if (!$silent) { $output->writeln(sprintf('Failed to remove ExApp %s container', $appId)); $output->writeln(sprintf('Hint: If the container "%s" was already removed manually, you can use the --force option to fully remove it from AppAPI.', $containerName)); } if (!$force) { return 1; } } elseif (!$silent) { $output->writeln(sprintf('ExApp %s container successfully removed', $appId)); } if ($rmData) { $volumeName = $this->dockerActions->buildExAppVolumeName($appId); $removeVolumeResult = $this->dockerActions->removeVolume( $this->dockerActions->buildDockerUrl($daemonConfig), $volumeName ); if (!$silent) { if (isset($removeVolumeResult['error'])) { $output->writeln(sprintf('Failed to remove ExApp %s volume: %s', $appId, $volumeName)); } else { $output->writeln(sprintf('ExApp %s data volume successfully removed', $appId)); } } } } } if (!$this->exAppService->unregisterExApp($appId)) { if (!$silent) { $output->writeln(sprintf('Failed to unregister ExApp %s.', $appId)); } if (!$force) { return 1; } } if (!$silent) { $output->writeln(sprintf('ExApp %s successfully unregistered.', $appId)); } return 0; } }