Skip to content

Commit 7277461

Browse files
authored
MCLOUD-5637: Update all error codes in ece-tools (magento#726)
1 parent 83b8e57 commit 7277461

File tree

126 files changed

+2424
-568
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+2424
-568
lines changed

config/services.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<service id="Magento\MagentoCloud\Step\Deploy\InstallUpdate" autowire="false" />
4747
<service id="Magento\MagentoCloud\Step\Deploy\InstallUpdate\ConfigUpdate" autowire="false" />
4848
<service id="Magento\MagentoCloud\Step\Deploy\PreDeploy" autowire="false" />
49+
<service id="Magento\MagentoCloud\Step\PostDeploy\CleanCache" autowire="false" />
4950
<service id="Magento\MagentoCloud\Step\SkipStep" autowire="false" />
5051
<service id="Magento\MagentoCloud\Step\StepException" autowire="false" />
5152
<service id="Magento\MagentoCloud\Step\ValidateConfiguration" autowire="false" />
@@ -76,6 +77,18 @@
7677
Magento\MagentoCloud\Config\ValidatorInterface::LEVEL_NOTICE
7778
</argument>
7879
</service>
80+
<service id="CleanCache.Deploy" class="Magento\MagentoCloud\Step\PostDeploy\CleanCache">
81+
<argument key="$stageConfig" type="service" id="Magento\MagentoCloud\Config\Stage\DeployInterface" />
82+
<argument key="$errorCode" type="constant">
83+
Magento\MagentoCloud\App\Error::DEPLOY_CACHE_FLUSH_COMMAND_FAILED
84+
</argument>
85+
</service>
86+
<service id="CleanCache.PostDeploy" class="Magento\MagentoCloud\Step\PostDeploy\CleanCache">
87+
<argument key="$stageConfig" type="service" id="Magento\MagentoCloud\Config\Stage\PostDeployInterface" />
88+
<argument key="$errorCode" type="constant">
89+
Magento\MagentoCloud\App\Error::PD_CACHE_FLUSH_COMMAND_FAILED
90+
</argument>
91+
</service>
7992
<service id="Symfony\Component\Serializer\Encoder\XmlEncoder"/>
8093
<service id="Symfony\Component\Process\ExecutableFinder"/>
8194
<!-- Interface mappings -->

scenario/deploy.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
<argument name="steps" xsi:type="array">
117117
<item name="enable-cron" xsi:type="object" priority="100">Magento\MagentoCloud\Step\PostDeploy\EnableCron</item>
118118
<item name="backup" xsi:type="object" priority="200">Magento\MagentoCloud\Step\PostDeploy\Backup</item>
119-
<item name="clean-cache" xsi:type="object" priority="300">Magento\MagentoCloud\Step\PostDeploy\CleanCache</item>
119+
<item name="clean-cache" xsi:type="object" priority="300">CleanCache.Deploy</item>
120120
</argument>
121121
</arguments>
122122
</step>

scenario/post-deploy.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</step>
1414
<step name="enable-cron" type="Magento\MagentoCloud\Step\PostDeploy\EnableCron" priority="300"/>
1515
<step name="backup" type="Magento\MagentoCloud\Step\PostDeploy\Backup" priority="400"/>
16-
<step name="clean-cache" type="Magento\MagentoCloud\Step\PostDeploy\CleanCache" priority="500"/>
16+
<step name="clean-cache" type="CleanCache.PostDeploy" priority="500"/>
1717
<step name="warm-up" type="Magento\MagentoCloud\Step\PostDeploy\WarmUp" priority="600"/>
1818
<step name="time-to-first-byte" type="Magento\MagentoCloud\Step\PostDeploy\TimeToFirstByte" priority="700"/>
1919
</scenario>

src/App/Error.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\App;
9+
10+
/**
11+
* Class for constants of all possible critical errors which can stop deployment process.
12+
*/
13+
class Error
14+
{
15+
public const BUILD_ENV_PHP_IS_NOT_WRITABLE = 2;
16+
public const BUILD_CONFIG_NOT_DEFINED = 3;
17+
public const BUILD_CONFIG_PARSE_FAILED = 4;
18+
public const BUILD_CONFIG_UNABLE_TO_READ = 5;
19+
public const BUILD_CONFIG_UNABLE_TO_READ_SCHEMA_YAML = 6;
20+
public const BUILD_CONFIG_PHP_IS_NOT_WRITABLE = 7;
21+
public const BUILD_CANT_READ_COMPOSER_JSON = 8;
22+
public const BUILD_COMPOSER_MISSED_REQUIRED_AUTOLOAD = 9;
23+
public const BUILD_WRONG_CONFIGURATION_MAGENTO_ENV_YAML = 10;
24+
public const BUILD_MODULE_ENABLE_COMMAND_FAILED = 11;
25+
public const BUILD_PATCH_APPLYING_FAILED = 12;
26+
public const BUILD_FILE_LOCAL_XML_IS_NOT_WRITABLE = 13;
27+
public const BUILD_FAILED_COPY_SAMPLE_DATA = 14;
28+
public const BUILD_DI_COMPILATION_FAILED = 15;
29+
public const BUILD_COMPOSER_DUMP_AUTOLOAD_FAILED = 16;
30+
public const BUILD_BALER_NOT_FOUND = 17;
31+
public const BUILD_UTILITY_NOT_FOUND = 18;
32+
public const BUILD_SCD_FAILED = 19;
33+
public const BUILD_SCD_COMPRESSION_FAILED = 20;
34+
public const BUILD_SCD_COPYING_FAILED = 21;
35+
public const BUILD_WRITABLE_DIRECTORY_COPYING_FAILED = 22;
36+
public const BUILD_UNABLE_TO_CREATE_LOGGER = 23;
37+
public const BUILD_CLEAN_INIT_PUB_STATIC_FAILED = 24;
38+
public const BUILD_COMPOSER_PACKAGE_NOT_FOUND = 25;
39+
40+
public const DEPLOY_WRONG_CACHE_CONFIGURATION = 101;
41+
public const DEPLOY_ENV_PHP_IS_NOT_WRITABLE = 102;
42+
public const DEPLOY_CONFIG_NOT_DEFINED = 103;
43+
public const DEPLOY_CONFIG_PARSE_FAILED = 104;
44+
public const DEPLOY_CONFIG_UNABLE_TO_READ = 105;
45+
public const DEPLOY_CONFIG_UNABLE_TO_READ_SCHEMA_YAML = 106;
46+
public const DEPLOY_REDIS_CACHE_CLEAN_FAILED = 107;
47+
public const DEPLOY_MAINTENANCE_MODE_ENABLING_FAILED = 108;
48+
public const DEPLOY_WRONG_CONFIGURATION_DB = 109;
49+
public const DEPLOY_WRONG_CONFIGURATION_SESSION = 110;
50+
public const DEPLOY_WRONG_CONFIGURATION_SEARCH = 111;
51+
public const DEPLOY_WRONG_CONFIGURATION_RESOURCE = 112;
52+
public const DEPLOY_ELASTIC_SUITE_WITHOUT_ES = 113;
53+
public const DEPLOY_ELASTIC_SUITE_WRONG_ENGINE = 114;
54+
public const DEPLOY_QUERY_EXECUTION_FAILED = 115;
55+
public const DEPLOY_INSTALL_COMMAND_FAILED = 116;
56+
public const DEPLOY_CONFIG_IMPORT_COMMAND_FAILED = 117;
57+
public const DEPLOY_UTILITY_NOT_FOUND = 118;
58+
public const DEPLOY_SCD_FAILED = 119;
59+
public const DEPLOY_SCD_COMPRESSION_FAILED = 120;
60+
public const DEPLOY_SCD_CANNOT_UPDATE_VERSION = 121;
61+
public const DEPLOY_SCD_CLEAN_FAILED = 122;
62+
public const DEPLOY_SPLIT_DB_COMMAND_FAILED = 123;
63+
public const DEPLOY_VIEW_PREPROCESSED_CLEAN_FAILED = 124;
64+
public const DEPLOY_FILE_CREDENTIALS_EMAIL_NOT_WRITABLE = 125;
65+
public const DEPLOY_UPGRADE_COMMAND_FAILED = 126;
66+
public const DEPLOY_CACHE_FLUSH_COMMAND_FAILED = 127;
67+
public const DEPLOY_MAINTENANCE_MODE_DISABLING_FAILED = 128;
68+
public const DEPLOY_UNABLE_TO_READ_RESET_PASSWORD_TMPL = 129;
69+
70+
public const PD_DEPLOY_IS_FAILED = 201;
71+
public const PD_ENV_PHP_IS_NOT_WRITABLE = 202;
72+
public const PD_CONFIG_NOT_DEFINED = 203;
73+
public const PD_CONFIG_PARSE_FAILED = 204;
74+
public const PD_CONFIG_UNABLE_TO_READ = 205;
75+
public const PD_CONFIG_UNABLE_TO_READ_SCHEMA_YAML = 206;
76+
public const PD_DURING_PAGE_WARM_UP = 207;
77+
public const PD_DURING_TIME_TO_FIRST_BYTE = 208;
78+
public const PD_CACHE_FLUSH_COMMAND_FAILED = 227;
79+
80+
public const GLOBAL_CONFIG_NOT_DEFINED = 243;
81+
public const GLOBAL_CONFIG_PARSE_FAILED = 244;
82+
public const GLOBAL_CONFIG_UNABLE_TO_READ = 245;
83+
public const GLOBAL_CONFIG_UNABLE_TO_READ_SCHEMA_YAML = 246;
84+
}

src/App/Logger.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\MagentoCloud\App;
99

10+
use Magento\MagentoCloud\App\Logger\Prepare\ErrorLogFile;
1011
use Magento\MagentoCloud\Filesystem\DirectoryList;
1112
use Magento\MagentoCloud\Filesystem\FileList;
1213
use Magento\MagentoCloud\Filesystem\Driver\File;
@@ -41,6 +42,7 @@ class Logger extends \Monolog\Logger
4142
* @param FileList $fileList
4243
* @param Pool $pool
4344
* @param SanitizeProcessor $sanitizeProcessor
45+
* @param ErrorLogFile $errorLogFile
4446
*
4547
* @throws LoggerException
4648
*/
@@ -49,13 +51,15 @@ public function __construct(
4951
DirectoryList $directoryList,
5052
FileList $fileList,
5153
Pool $pool,
52-
SanitizeProcessor $sanitizeProcessor
54+
SanitizeProcessor $sanitizeProcessor,
55+
ErrorLogFile $errorLogFile
5356
) {
5457
$this->file = $file;
5558
$this->directoryList = $directoryList;
5659
$this->fileList = $fileList;
5760

5861
$this->prepare();
62+
$errorLogFile->prepare();
5963

6064
parent::__construct('default', $pool->getHandlers(), [$sanitizeProcessor]);
6165
}

src/App/Logger/HandlerFactory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\MagentoCloud\App\Logger;
99

10+
use Illuminate\Contracts\Config\Repository;
1011
use Magento\MagentoCloud\App\Logger\Gelf\HandlerFactory as GelfHandlerFactory;
1112
use Magento\MagentoCloud\Config\GlobalSection;
1213
use Magento\MagentoCloud\Config\Log as LogConfig;
@@ -24,6 +25,7 @@ class HandlerFactory
2425
{
2526
const HANDLER_STREAM = 'stream';
2627
const HANDLER_FILE = 'file';
28+
const HANDLER_FILE_ERROR = 'file_errors';
2729
const HANDLER_EMAIL = 'email';
2830
const HANDLER_SLACK = 'slack';
2931
const HANDLER_GELF = 'gelf';
@@ -71,7 +73,6 @@ public function __construct(
7173
/**
7274
* @param string $handler
7375
* @return HandlerInterface
74-
* @throws \Exception
7576
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7677
*/
7778
public function create(string $handler): HandlerInterface
@@ -88,6 +89,12 @@ public function create(string $handler): HandlerInterface
8889
$this->levelResolver->resolve($configuration->get('min_level', LogConfig::LEVEL_DEBUG))
8990
);
9091
break;
92+
case static::HANDLER_FILE_ERROR:
93+
$handlerInstance = new StreamHandler(
94+
$configuration->get('file'),
95+
$this->levelResolver->resolve($configuration->get('min_level', LogConfig::LEVEL_WARNING))
96+
);
97+
break;
9198
case static::HANDLER_STREAM:
9299
$defaultLevelStream = $levelOverride ?: LogConfig::LEVEL_INFO;
93100
$handlerInstance = new StreamHandler(

src/App/Logger/Pool.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
namespace Magento\MagentoCloud\App\Logger;
99

10+
use Magento\MagentoCloud\App\Error;
1011
use Magento\MagentoCloud\App\LoggerException;
1112
use Monolog\Handler\HandlerInterface;
1213
use Magento\MagentoCloud\Config\Log as LogConfig;
1314
use Exception;
15+
use Symfony\Component\Yaml\Exception\ParseException;
1416

1517
/**
1618
* The pool of handlers.
@@ -74,12 +76,10 @@ public function getHandlers(): array
7476

7577
$this->handlers[] = $handler;
7678
}
77-
} catch (Exception $exception) {
78-
throw new LoggerException(
79-
$exception->getMessage(),
80-
$exception->getCode(),
81-
$exception
82-
);
79+
} catch (ParseException $e) {
80+
throw new LoggerException($e->getMessage(), Error::BUILD_CONFIG_PARSE_FAILED, $e);
81+
} catch (Exception $e) {
82+
throw new LoggerException($e->getMessage(), $e->getCode(), $e);
8383
}
8484

8585
return $this->handlers;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\App\Logger\Prepare;
9+
10+
use Magento\MagentoCloud\App\LoggerException;
11+
use Magento\MagentoCloud\Filesystem\DirectoryList;
12+
use Magento\MagentoCloud\Filesystem\Driver\File;
13+
use Magento\MagentoCloud\Filesystem\FileList;
14+
use Magento\MagentoCloud\Filesystem\FileSystemException;
15+
use Magento\MagentoCloud\Package\UndefinedPackageException;
16+
17+
/**
18+
* Uses for copying error log file from build phase if needed.
19+
*/
20+
class ErrorLogFile
21+
{
22+
/**
23+
* @var File
24+
*/
25+
private $file;
26+
27+
/**
28+
* @var DirectoryList
29+
*/
30+
private $directoryList;
31+
32+
/**
33+
* @var FileList
34+
*/
35+
private $fileList;
36+
37+
/**
38+
* @param File $file
39+
* @param DirectoryList $directoryList
40+
* @param FileList $fileList
41+
*
42+
*/
43+
public function __construct(
44+
File $file,
45+
DirectoryList $directoryList,
46+
FileList $fileList
47+
) {
48+
$this->file = $file;
49+
$this->directoryList = $directoryList;
50+
$this->fileList = $fileList;
51+
}
52+
53+
/**
54+
* Checks and copies error log file from build phase if needed
55+
*
56+
* @throws LoggerException
57+
*/
58+
public function prepare()
59+
{
60+
try {
61+
$this->file->createDirectory($this->directoryList->getLog());
62+
63+
$deployErrorLogPath = $this->fileList->getCloudErrorLog();
64+
$buildPhaseErrorLogPath = $this->fileList->getInitCloudErrorLog();
65+
if ($this->isNeedToCopyBuildErrorLogFile($deployErrorLogPath, $buildPhaseErrorLogPath)) {
66+
$this->file->copy($buildPhaseErrorLogPath, $deployErrorLogPath);
67+
}
68+
} catch (FileSystemException | UndefinedPackageException $exception) {
69+
throw new LoggerException(
70+
$exception->getMessage(),
71+
$exception->getCode(),
72+
$exception
73+
);
74+
}
75+
}
76+
77+
/**
78+
* Checks if error log file from build phase should be copied
79+
*
80+
* @param string $deployLogPath
81+
* @param string $buildPhaseLogPath
82+
* @return bool
83+
* @throws FileSystemException
84+
*/
85+
private function isNeedToCopyBuildErrorLogFile(string $deployLogPath, string $buildPhaseLogPath): bool
86+
{
87+
$buildLogFileExists = $this->file->isExists($buildPhaseLogPath);
88+
if (!$buildLogFileExists) {
89+
return false;
90+
}
91+
92+
$deployLogFileExists = $this->file->isExists($deployLogPath);
93+
if (!$deployLogFileExists) {
94+
return true;
95+
}
96+
97+
return false === strpos(
98+
$this->file->fileGetContents($deployLogPath),
99+
$this->file->fileGetContents($buildPhaseLogPath)
100+
);
101+
}
102+
}

0 commit comments

Comments
 (0)