# Depoy Maximo EAR # Version 1.0.0 param ($AppName, $CellName, $ClusterName, $EARFile, [switch] $Help, $NodeName , $ServerName, $UserName, $VirtualHost, $WebServerName, $HostName ) $global:WebSphereHost="localhost" # Print the usage for the script. function PrintHelp { Write-Host " -AppName The name of the application to deploy, such as MAXIMO (required). -CellName The WebSphere cell name, for example ctgCell01 (required). -ClusterName The name of the cluster to deploy the application to. -EARFile The path to the Maximo EAR file (required). -HostName The name of the WebSphere deployment manaager server. -NodeName The WebSphere Node name, for example ctgNode01 (required). -Password The WeBSphere user password (required). -ServerName The name of the server to deploy the application to, for example MXServer. -UserName The WebSphere user name, typically wasadmin (required). -VirtualHost The name of the virtual host to deploy the application to, for example maximo_host (required). -WebServerName The name of the web server to bind the application to, for example webserver1. -Help Print this help message." exit } # Prints and error message and then exits the program with a 1 exit code. function PrintErrorAndExit { param ($Message) Write-Host " $Message " exit } # Ask the user if they want to try again, exit if they enter no or n. function AskToTryAgain { param($Message) [string]$Response = "" Write-Host "" While ($Response.Length -eq 0 -Or !(($Response -eq "n") -Or ($Response -eq "no") -Or ($Response -eq "y") -Or ($Response -eq "yes"))) { $Response = (Read-Host "$Message. Try again? (Y/N)" ).ToLower() } return $Response -eq "y" -Or $Response -eq "yes" } # Convert the secure password string into plain text that can be used with the command line. Function ConvertFrom-SecureString-AsPlainText { [CmdletBinding()] param ( [Parameter( Mandatory = $true, ValueFromPipeline = $true )] [System.Security.SecureString] $SecureString ) $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString); $PlainTextString = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr); $PlainTextString; } # Validate the inputs and perform basic sanity checks, such as files and paths exist. function ValidateInputs() { if ([string]::IsNullOrEmpty($AppName) ) { PrintErrorAndExit -Message "Error: The application name is required." } if ([string]::IsNullOrEmpty( $CellName)) { PrintErrorAndExit -Message "Error: The WebSphere cell name is required." } if ([string]::IsNullOrEmpty( $ClusterName) -and [string]::IsNullOrEmpty( $ServerName) ) { PrintErrorAndExit -Message "Error: Either a server name or a cluster name is required." } if ([string]::IsNullOrEmpty( $EARFile)) { PrintErrorAndExit -Message "Error: The path to the Maximo EAR file is required." } if (!(Test-Path -Path $EARFile)) { PrintErrorAndExit -Message "Error: The EAR file $EARFile does not exist." } if ([string]::IsNullOrEmpty( $HostName)) { PrintErrorAndExit -Message "Error: The WebSphere Deployment Manager host name is required." } if ([string]::IsNullOrEmpty( $NodeName)) { PrintErrorAndExit -Message "Error: The WebSphere node name is required." } if ([string]::IsNullOrEmpty( $UserName)) { PrintErrorAndExit -Message "Error: The WebSphere user name is required." } if ([string]::IsNullOrEmpty( $VirtualHost)) { PrintErrorAndExit -Message "Error: The WebSphere virtual host name is required." } if ([string]::IsNullOrEmpty( $WebServerName)) { PrintErrorAndExit -Message "Error: The WebSphere web server name is required." } } function deployApplication(){ param ($InternalUserName, $InternalPassword, $InternalEarFile, $InternalAppName, $InternalVirtualHost, $InternalCellName, $InternalNodeName, $InternalWebServerName) $CurrentDir = Get-Location $DeployScript = "${CurrentDir}\scripts\deploy-application.py" $Command = "${CurrentDir}\wasclient\ThinWsadmin.bat" $ClusterOrServerName = "" if (!([string]::IsNullOrEmpty($ClusterName))){ $ClusterOrServerName="$ClusterName" }else{ $ClusterOrServerName="$ServerName" } $Params = "-username $InternalUserName -password $InternalPassword -host $WebSphereHost -f $DeployScript $InternalEarFile $InternalAppName $InternalVirtualHost $InternalCellName $InternalNodeName $ClusterOrServerName $InternalWebServerName".Split(" ") # This command deploys the application to the provided cluster or server Write-Host "Executing command $Command $Params" (& $Command $Params) if ($LASTEXITCODE -ne 0) { PrintErrorAndExit "Error: Could not deploy the application." } } # Gets the WebSphere user password from the command line. function GetPassword() { Read-Host 'Enter the WebSphere user password' -AsSecureString } # prints the help / usage information if ($help) { PrintHelp } else { ValidateInputs if(!([string]::IsNullOrEmpty($HostName))){ Set-Variable -Name "WebSphereHost" -value $HostName -scope global } # Get the WebSphere user password if ([string]::IsNullOrEmpty($Password)) { Do { $Password = ConvertFrom-SecureString-AsPlainText ( GetPassword ) if ([string]::IsNullOrEmpty($Password)) { if (!(AskToTryAgain -Message "The WebSphere user password is required.")) { exit } } } While ([string]::IsNullOrEmpty($Password)) } deployApplication -InternalUserName $UserName -InternalPassword $Password -InternalEarFile $EARFile -InternalAppName $AppName -InternalVirtualHost $VirtualHost -InternalCellName $CellName -InternalNodeName $NodeName -InternalWebServerName $WebServerName exit }