8 Configuring the Script Interceptor
- Overview of the Script Interceptor
Script interceptors are provided as a means to perform tasks before or immediately after a scaling operation has been completed. - Configuring Error Handling for a Script Interceptor
When configuring a preprocessor or postprocessor script for a script interceptor, you can specify an error handler script to use if an error occurs during the execution of the main script. - Reserved Environment Variables
Script interceptors can pass both computed and dynamic parameters as environment variables to scripts. In addition, WLDF includes a set of reserved environment variables that can be used in scripts.
Overview of the Script Interceptor
Script interceptors can execute two main types of scripts:
-
Preprocessor scripts execute tasks prior to a scaling operation
-
Postprocessor scripts execute tasks immediately after a scaling operation
Script interceptors can also execute error handler scripts if an error occurs during the execution of the preprocessor or postprocessor scripts. And multiple script interceptor instances can be used in an interceptor chain for a scaling operation.
Note:
If the execution of a preprocessor script fails, then neither the associated scaling operation nor any subsequently configured interceptors are invoked. If a postprocessor script fails, the scaling action that preceded the invocation of that script cannot be reverted or otherwise cancelled.
Script interceptors are configured using the ScriptInterceptorMBean
. Example 8-1 offers a sample script interceptor configuration.
Example 8-1 Configuring a Script Interceptor
EditServiceMBean editService = mbsFactory.getEditService(); ConfigurationManagerMBean configManager = editService.getConfigurationManager(); configManager.startEdit(5000, 5000); DomainMBean domainMBean = editService.getDomainConfiguration(); InterceptorsMBean interceptors = (InterceptorsMBean) domainMBean.getInterceptors(); ScriptInterceptorMBean scriptInterceptor1 = interceptors.createScriptInterceptor("script-1"); scriptInterceptor1.setPriority(50); PreProcessorScriptMBean pre1 = scriptInterceptor1.getPreProcessor(); pre1.setWorkingDirectory(domainMBean.getRootDirectory()); pre1.setPathToScript("/bin/sh"); pre1.setArguments(new String[] {domainMBean.getRootDirectory() + "/scripts/interceptors/echo-arg-interceptor.sh", "first"}); Properties envAsProps = new Properties(); envAsProps.put("env-key-1", "env-1-value"); envAsProps.put("env-key-2", "env-2-value"); envAsProps.put("env-key-3", "env-3-value"); pre1.setEnvironment(envAsProps); ScriptInterceptorMBean scriptInterceptor2 = interceptors.createScriptInterceptor("script-2"); scriptInterceptor2.setPriority(20); PreProcessorScriptMBean pre2 = scriptInterceptor2.getPreProcessor(); pre2.setWorkingDirectory(domainMBean.getRootDirectory()); pre2.setPathToScript("/bin/sh"); pre2.setArguments(new String[] {domainMBean.getRootDirectory() + "/scripts/interceptors/echo-arg-interceptor.sh", "second"}); configManager.save(); configManager.activate(5000);
Parent topic: Configuring the Script Interceptor
Configuring Error Handling for a Script Interceptor
When configuring a preprocessor or postprocessor script for a script interceptor, you can specify an error handler script to use if an error occurs during the execution of the main script.
The error handler script is executed using the same arguments and environment properties as the command script.
Parent topic: Configuring the Script Interceptor
Reserved Environment Variables
WLS_SCRIPT_THIS_STEP_FAILED
, each of these variables can be passed to preprocessor scripts, postprocessor scripts, and error handler scripts.
Table 8-1 Reserved Environment Variables
Environment Variable | Description |
---|---|
|
This variable is passed to error-handler scripts only. Value 'false' indicates some subsequent step failed.
|
|
Represents the path to the output properties file that scripts may create. The contents of the file will be read and passed to subsequent scripts. |
|
Represents the path to the temporary directory in which scripts may create temporary files. |
|
Represents the name of the dynamic cluster that is being scaled up or down. |
|
Represents the current scaling operation, which is either |
|
Represents the minimum size of the dynamic cluster. |
|
Represents the maximum size of the dynamic cluster. |
|
Represents the current size of the dynamic cluster. |
|
Represents the names of candidate servers that may be chosen to be started or stopped. |
|
Represents the number of running servers in the cluster that are requested to be either incremented or decremented. |
|
Represents the actual number of servers that will be started or stopped (which may be smaller than the requested scaling size). |
|
Represents the names of the servers that are chosen to be started or stopped during scale up or scale down operations. |
Parent topic: Configuring the Script Interceptor