From 4bea0c958094bb30075ead24e4992a3ff0d85f21 Mon Sep 17 00:00:00 2001 From: Yeray Borges Date: Tue, 5 Mar 2024 13:45:59 +0000 Subject: [PATCH] [WFCORE-6726] Use Prospero --rm option to automatically delete the candidate server after applying it Jira issue: https://issues.redhat.com/browse/WFCORE-6726 --- .../content/bin/installation-manager.bat | 28 ------------------- .../content/bin/installation-manager.ps1 | 22 --------------- .../content/bin/installation-manager.sh | 12 -------- .../core/instmgr/InstMgrCandidateStatus.java | 7 +---- .../wildfly/core/instmgr/InstMgrService.java | 2 +- 5 files changed, 2 insertions(+), 69 deletions(-) diff --git a/core-feature-pack/common/src/main/resources/content/bin/installation-manager.bat b/core-feature-pack/common/src/main/resources/content/bin/installation-manager.bat index 629fc3b5675..53f12367291 100644 --- a/core-feature-pack/common/src/main/resources/content/bin/installation-manager.bat +++ b/core-feature-pack/common/src/main/resources/content/bin/installation-manager.bat @@ -15,7 +15,6 @@ set INST_MGR_LOG_PROPERTIES=%~2 rem For security, reset the environment variables first set INST_MGR_COMMAND= set INST_MGR_STATUS= -set INST_MGR_PREPARED_SERVER_DIR= set PROPS_FILE=%INSTALLATION_HOME%\bin\installation-manager.properties if not exist "%PROPS_FILE%" ( @@ -27,12 +26,6 @@ if not exist "%PROPS_FILE%" ( rem Read Script variable configuration for /F "usebackq tokens=1* eol=# delims==" %%G IN ("%PROPS_FILE%") do (set %%G=%%H) -rem remove escape characters necessary to store values in a property file -setlocal EnableDelayedExpansion -set "INST_MGR_PREPARED_SERVER_DIR=!INST_MGR_PREPARED_SERVER_DIR:\:=:!" -set "INST_MGR_PREPARED_SERVER_DIR=!INST_MGR_PREPARED_SERVER_DIR:\\=\!" -setlocal DisableDelayedExpansion - rem Check the status is the expected IF NOT DEFINED INST_MGR_STATUS ( echo ERROR: Cannot read the Installation Manager status. @@ -46,26 +39,6 @@ if "%INST_MGR_STATUS%" neq "PREPARED" ( goto EOF ) -rem Check we have a server prepared -if NOT DEFINED INST_MGR_PREPARED_SERVER_DIR ( - echo ERROR: Installation Manager prepared server directory was not set. - - goto EOF -) - -if "%INST_MGR_PREPARED_SERVER_DIR%"=="" ( - echo ERROR: Installation Manager prepared server directory was not set. - - goto EOF -) - -dir /b/a "%INST_MGR_PREPARED_SERVER_DIR%" | findstr "^" >nul -if %errorlevel% equ 1 ( - echo ERROR: There is no a Candidate Server prepared. - - goto EOF -) - IF NOT DEFINED %INST_MGR_COMMAND ( echo ERROR: Installation Manager command was not set. @@ -84,7 +57,6 @@ set INST_MGR_RESULT=%errorlevel% if %INST_MGR_RESULT% equ 0 ( echo INFO: The Candidate Server was successfully applied. - rmdir /S /Q "%INST_MGR_PREPARED_SERVER_DIR%" echo|set /p"=INST_MGR_STATUS=CLEAN" > "%PROPS_FILE%" goto EOF ) diff --git a/core-feature-pack/common/src/main/resources/content/bin/installation-manager.ps1 b/core-feature-pack/common/src/main/resources/content/bin/installation-manager.ps1 index 15f021b3f01..f4e0f1b06f0 100644 --- a/core-feature-pack/common/src/main/resources/content/bin/installation-manager.ps1 +++ b/core-feature-pack/common/src/main/resources/content/bin/installation-manager.ps1 @@ -26,7 +26,6 @@ function Sanitize-Path { # For security, reset the environment variables first Set-Variable -Name INST_MGR_COMMAND -Scope Script Set-Variable -Name INST_MGR_STATUS -Scope Script -Set-Variable -Name INST_MGR_PREPARED_SERVER_DIR -Scope Script $propsFile="$installationHome\bin\installation-manager.properties" if ($propsFile -eq $null) { @@ -71,26 +70,6 @@ if ($INST_MGR_STATUS -ne "PREPARED") { return } -# Check we have a server prepared -if ($INST_MGR_PREPARED_SERVER_DIR -eq $null) { - Write-Error "ERROR: Installation Manager prepared server directory was not set." - return -} - -$INST_MGR_PREPARED_SERVER_DIR = Sanitize-Path -inputPath $INST_MGR_PREPARED_SERVER_DIR -Write-Debug "Sanitized INST_MGR_PREPARED_SERVER_DIR=$INST_MGR_PREPARED_SERVER_DIR" - -if (Test-Path -Path $INST_MGR_PREPARED_SERVER_DIR -PathType Container) { - $files = Get-ChildItem -Path $INST_MGR_PREPARED_SERVER_DIR - if ($files -eq $null) { - Write-Error "ERROR: There is no a Candidate Server prepared." - return - } -} else { - Write-Error "ERROR: There is no a Candidate Server prepared." - return -} - if ($INST_MGR_COMMAND -eq $null) { Write-Error "ERROR: Installation Manager command was not set." return @@ -107,7 +86,6 @@ try if ($exitCode -eq 0) { Write-Host "INFO: The Candidate Server was successfully applied." - Remove-Item -Path $INST_MGR_PREPARED_SERVER_DIR -Recurse -Force $resetStatus = "INST_MGR_STATUS=CLEAN" "$resetStatus" | Set-Content -Path $propsFile } elseif ($exitCode -eq 1) { diff --git a/core-feature-pack/common/src/main/resources/content/bin/installation-manager.sh b/core-feature-pack/common/src/main/resources/content/bin/installation-manager.sh index 9853d4ba08b..cc435d27c0a 100755 --- a/core-feature-pack/common/src/main/resources/content/bin/installation-manager.sh +++ b/core-feature-pack/common/src/main/resources/content/bin/installation-manager.sh @@ -12,7 +12,6 @@ INST_MGR_LOG_PROPERTIES="${2}" # For security, reset the environment variables first unset INST_MGR_COMMAND unset INST_MGR_STATUS -unset INST_MGR_PREPARED_SERVER_DIR PROPS_FILE="${INSTALLATION_HOME}/bin/installation-manager.properties" if ! [ -e "${PROPS_FILE}" ]; then @@ -35,16 +34,6 @@ if ! [ "${INST_MGR_STATUS}" == "PREPARED" ]; then exit fi -if [ x"${INST_MGR_PREPARED_SERVER_DIR}" == "x" ]; then - echo "ERROR: Installation Manager prepared server directory was not set." - exit -fi - -if ! [ -d "${INST_MGR_PREPARED_SERVER_DIR}" ] || ! [ -n "$(ls -A "${INST_MGR_PREPARED_SERVER_DIR}")" ]; then - echo "ERROR: There is no a Candidate Server prepared." - exit -fi - if [ x"${INST_MGR_COMMAND}" == "x" ]; then echo "ERROR: Installation Manager command was not set." exit @@ -58,7 +47,6 @@ case $INST_MGR_RESULT in 0) # 0 Successful program execution. echo "INFO: The Candidate Server was successfully applied." - rm -rf "${INST_MGR_PREPARED_SERVER_DIR}" echo "INST_MGR_STATUS=CLEAN" > "${PROPS_FILE}" ;; diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrCandidateStatus.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrCandidateStatus.java index f2e0fee7847..29ac9b1c355 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrCandidateStatus.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrCandidateStatus.java @@ -19,18 +19,14 @@ */ class InstMgrCandidateStatus { private Path properties; - private Path prepareServerPath; public static final String INST_MGR_STATUS_KEY = "INST_MGR_STATUS"; public static final String INST_MGR_COMMAND_KEY = "INST_MGR_COMMAND"; - public static final String INST_MGR_PREPARED_SERVER_DIR_KEY = "INST_MGR_PREPARED_SERVER_DIR"; - public enum Status {ERROR, CLEAN, PREPARING, PREPARED} - void initialize(Path properties, Path prepareServerPath) { + void initialize(Path properties) { this.properties = properties.normalize().toAbsolutePath(); - this.prepareServerPath = prepareServerPath; } Status getStatus() throws IOException { @@ -76,7 +72,6 @@ private void setStatus(Status status, String command) throws IOException { try (FileOutputStream out = new FileOutputStream(properties.toString())) { prop.setProperty(INST_MGR_COMMAND_KEY, command); prop.setProperty(INST_MGR_STATUS_KEY, status.name()); - prop.setProperty(INST_MGR_PREPARED_SERVER_DIR_KEY, this.prepareServerPath.toFile().getAbsolutePath()); prop.store(out, null); } } diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrService.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrService.java index 90866715649..96e9f7d45a9 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrService.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrService.java @@ -73,7 +73,7 @@ public void start(StartContext startContext) throws StartException { // Properties file used to send information to the launch scripts Path propertiesPath = homeDir.resolve("bin").resolve("installation-manager.properties"); - this.candidateStatus.initialize(propertiesPath, prepareServerPath); + this.candidateStatus.initialize(propertiesPath); try { if (candidateStatus.getStatus() == InstMgrCandidateStatus.Status.PREPARING) { candidateStatus.setFailed();