Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFCORE-6726] Use Prospero --rm option to automatically delete the ca… #5893

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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%" (
Expand All @@ -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.
Expand All @@ -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.

Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}"
;;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down