Skip to content

Commit

Permalink
add large scale infastructure design changes and api support
Browse files Browse the repository at this point in the history
  • Loading branch information
utarsuno committed May 28, 2019
1 parent cde5952 commit 93cbdff
Show file tree
Hide file tree
Showing 144 changed files with 3,574 additions and 1,473 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ output_files_to_ignore/
generated_output/
depreciated/

*.pyc


Thumbs.db
npm-debug.log
/bower_components
Expand Down
2 changes: 1 addition & 1 deletion applications/asset_server/code_manager/report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<testcase name="test_get_sha512sum" class="CodeManager\Tests\FileUtilitiesTest" classname="CodeManager.Tests.FileUtilitiesTest" file="/quasar_source/applications/asset_server/code_manager/tests/universal_utilities/files/FileUtilitiesTest.php" line="57" assertions="1" time="0.003045"/>
<testcase name="test_matches_sha512sum" class="CodeManager\Tests\FileUtilitiesTest" classname="CodeManager.Tests.FileUtilitiesTest" file="/quasar_source/applications/asset_server/code_manager/tests/universal_utilities/files/FileUtilitiesTest.php" line="61" assertions="1" time="0.001648"/>
<testcase name="test_get_size" class="CodeManager\Tests\FileUtilitiesTest" classname="CodeManager.Tests.FileUtilitiesTest" file="/quasar_source/applications/asset_server/code_manager/tests/universal_utilities/files/FileUtilitiesTest.php" line="65" assertions="1" time="0.000296"/>
<testcase name="test_get_yaml_contents" class="CodeManager\Tests\FileUtilitiesTest" classname="CodeManager.Tests.FileUtilitiesTest" file="/quasar_source/applications/asset_server/code_manager/tests/universal_utilities/files/FileUtilitiesTest.php" line="72" assertions="1" time="0.024752"/>
<testcase name="test_get_yaml" class="CodeManager\Tests\FileUtilitiesTest" classname="CodeManager.Tests.FileUtilitiesTest" file="/quasar_source/applications/asset_server/code_manager/tests/universal_utilities/files/FileUtilitiesTest.php" line="72" assertions="1" time="0.024752"/>
</testsuite>
<testsuite name="CodeManager\Tests\PathUtilitiesTest" file="/quasar_source/applications/asset_server/code_manager/tests/universal_utilities/files/PathUtilitiesTest.php" tests="3" assertions="17" errors="0" failures="0" skipped="0" time="0.005212">
<testcase name="test_remove_layer" class="CodeManager\Tests\PathUtilitiesTest" classname="CodeManager.Tests.PathUtilitiesTest" file="/quasar_source/applications/asset_server/code_manager/tests/universal_utilities/files/PathUtilitiesTest.php" line="21" assertions="4" time="0.000089"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;


abstract class AbstractCommand extends Command {

public const COMMAND_NAME = 'must_be_set_by_child_command_class';
Expand All @@ -24,11 +25,13 @@ protected function configure(): void {
$this->add_required_arguments();
}

protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): ?int {
$this->input = $input;
$this->output = $output;
return $this->run_command();
}

abstract protected function add_required_arguments(): void;

abstract protected function run_command();
abstract protected function run_command(): int;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace CodeManager\Command\Abstractions;

use QuasarSource\Traits\TraitPatternName;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;


abstract class PreparedCommand {
use TraitPatternName;

public const CMD_DB_SCHEMA_UPDATE = 'doctrine:schema:update';
public const CMD_DB_SCHEMA_VALIDATE = 'doctrine:schema:validate';

/** @var Command */
private $cmd;
/** @var BufferedOutput */
private $output;
/** @var ArrayInput */
private $input;
/** @var string */
protected $results;
/** @var int */
protected $exit_code;

public function __construct(string $name, Command $command, array $input=[]) {
$this->set_name($name);
$this->cmd = $command;
$this->output = new BufferedOutput();
$this->input = new ArrayInput($input);
}

public function run_command(): void {
$this->exit_code = $this->cmd->run($this->input, $this->output);
$this->results = $this->output->fetch();
$this->on_command_completed();
}

abstract protected function on_command_completed(): void;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,17 @@
namespace CodeManager\Command;

use CodeManager\Service\CodeBuilderService;
use QuasarSource\Utilities\ArrayUtilities;
use QuasarSource\Utilities\Exceptions\ExceptionUtilities;
use QuasarSource\Utilities\StringUtilities;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use QuasarSource\Utilities\Processes\ProcessUtilities as RUN;
use QuasarSource\Utilities\Files\PathUtilities as PATH;
use QuasarSource\Utilities\StringUtilities as STR;


class CodeHealthCheckCommand extends Command {

public const COMMAND_NAME = 'code:health_check';
protected static $defaultName = self::COMMAND_NAME;

/** @var CodeBuilderService */
private $code_builder;

public function __construct(CodeBuilderService $code_builder) {
Expand All @@ -41,8 +34,7 @@ protected function configure(): void {
}

protected function execute(InputInterface $input, OutputInterface $output) {
//previous_execute
$this->code_builder->set_code_builder_command($this);
$this->code_builder->prepare_code_health_check($this->getApplication());
$this->code_builder->run_code_health_check();

#var_dump('TODO: run_composer_self_update');
Expand All @@ -51,41 +43,4 @@ protected function execute(InputInterface $input, OutputInterface $output) {

return 0;
}

public function update_db_schema(): string {
$command = $this->getApplication()->find('doctrine:schema:update');
$cmd_output = new BufferedOutput();
$result = $command->run(
new ArrayInput(
[
'-vvv' => null,
'--no-interaction' => null,
'--force' => null
]
),
$cmd_output
);
#var_dump($result);
$output = $cmd_output->fetch();
return $output;
#$output = STR::split_into_non_empty_lines($output);
#return $output;
}

public function check_db_health(bool & $mapping_healthy, bool & $schema_healthy): void {
$command = $this->getApplication()->find('doctrine:schema:validate');
$cmd_output = new BufferedOutput();
$result = $command->run(new ArrayInput([]), $cmd_output);
#var_dump($result);
$output = $cmd_output->fetch();
$output = STR::split_into_non_empty_lines($output);

if (count($output) !== 6) {
ExceptionUtilities::throw_exception('DB Check has invalid output<<' . json_encode($output) . '>>');
}

$mapping_healthy = STR::contains($output[2], '[OK]');
$schema_healthy = STR::contains($output[5], '[OK]');
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace CodeManager\Command\Prepared;
use CodeManager\Command\Abstractions\PreparedCommand;
use QuasarSource\Utilities\StringUtilities;
use Symfony\Component\Console\Command\Command;


class DBSchemaUpdate extends PreparedCommand {

/** @var bool */
private $db_schema_was_updated = false;

public function __construct(Command $command) {
parent::__construct(PreparedCommand::CMD_DB_SCHEMA_UPDATE, $command, [
'-vvv' => null,
'--no-interaction' => null,
'--force' => null
]);
}

protected function on_command_completed(): void {
#var_dump($this->results);
if (StringUtilities::contains($this->results, 'Updating database schema')) {
$this->db_schema_was_updated = true;
}
}

public function did_db_schema_update(): bool {
return $this->db_schema_was_updated;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace CodeManager\Command\Prepared;
use CodeManager\Command\Abstractions\PreparedCommand;
use Symfony\Component\Console\Command\Command;
use QuasarSource\Utilities\Exceptions\ExceptionUtilities as DBG;
use QuasarSource\Utilities\StringUtilities as STR;


class DBSchemaValidate extends PreparedCommand {

/** @var bool */
private $is_healthy_mapping;
/** @var bool */
private $is_healthy_schema;

public function __construct(Command $command) {
parent::__construct(PreparedCommand::CMD_DB_SCHEMA_UPDATE, $command, []);
}

protected function on_command_completed(): void {
#if ($this->exit_code !== 0) {
# DBG::throw_exception('DB Health CMD had non 0 exit code{' . $this->exit_code . '} with output {' . $this->results . '}');
#}

$output = STR::split_into_non_empty_lines($this->results);

if (count($output) !== 6) {
DBG::throw_exception('DB Check has invalid output<<' . json_encode($output) . '>>');
}

$this->is_healthy_mapping = STR::contains($output[2], '[OK]');
$this->is_healthy_schema = STR::contains($output[5], '[OK]');
}

public function is_healthy_schema(): bool {
return $this->is_healthy_schema;
}

public function is_healthy_mapping(): bool {
return $this->is_healthy_mapping;
}
}
Loading

0 comments on commit 93cbdff

Please sign in to comment.