use of com.axway.ats.agent.core.model.EnvironmentCleanupHandler in project ats-framework by Axway.
the class EnvironmentHandler method getEnvironmentCleanupHandlerInstance.
/**
* Get the instance of the cleanup class for the given component. If such does not exist, create it.
*
* @param className the FQDN of the cleanup class
* @return the instance of the cleanup class
*
* @throws ActionExecutionException if the class instance cannot be created
*/
private EnvironmentCleanupHandler getEnvironmentCleanupHandlerInstance(Component component) throws ActionExecutionException {
String componentName = component.getComponentName();
Class<? extends EnvironmentCleanupHandler> cleanupHandler = component.getActionMap().getCleanupHandler();
//no cleanup handler defined for the component
if (cleanupHandler == null) {
return null;
}
try {
EnvironmentCleanupHandler cleanupClassInstance = cleanupClassInstances.get(componentName);
if (cleanupClassInstance == null) {
cleanupClassInstance = cleanupHandler.newInstance();
cleanupClassInstances.put(componentName, cleanupClassInstance);
}
return cleanupClassInstance;
} catch (IllegalAccessException iae) {
throw new ActionExecutionException("Could not access cleanup class " + cleanupHandler.getName(), iae);
} catch (InstantiationException ie) {
throw new ActionExecutionException("Could not instantiate cleanup class " + cleanupHandler.getName(), ie);
}
}
use of com.axway.ats.agent.core.model.EnvironmentCleanupHandler in project ats-framework by Axway.
the class EnvironmentHandler method restore.
/**
* Restore the environment for a given component - this will restore the environment
* described in the Agent descriptor file and also call the EnvironmentCleanupHandler.clean()
* method for the component
*
* @param componentName The name of the component
* @param environmentName The name of the environment configuration
* @param folderPath The path of the backup folder. Used to execute restore from a backup folder
* other than the defined in the environment, that's why it's optional
* @throws ActionExecutionException If the EnvironmentCleanupHandler implementation cannot be found or accessed
* @throws NoSuchComponentException If there is no component with this name
* @throws InternalComponentException If the EnvironmentCleanupHandler.clean() implementation throws an exception
* @throws AgentException If an exception occurs during restore of environment described in Agent descriptor
*/
public void restore(String componentName, String environmentName, String folderPath) throws ActionExecutionException, NoSuchComponentException, InternalComponentException, AgentException {
Component component = ComponentRepository.getInstance().getComponent(componentName);
log.debug("Executing environment restore for component '" + componentName + "'" + (environmentName == null ? "" : " using environment '" + environmentName + "'") + (folderPath == null ? "" : " from folder '" + folderPath + "'"));
//first restore the environment associated with the current component
ComponentEnvironment componentEnvironment;
if (environmentName == null) {
componentEnvironment = ComponentRepository.getInstance().getComponentEnvironment(componentName);
} else {
componentEnvironment = ComponentRepository.getInstance().getComponentEnvironment(componentName, environmentName);
}
//check if there is environment configuration
if (componentEnvironment != null) {
componentEnvironment.restore(folderPath);
}
// FIXME: What about if environmentName != null, do we have to call cleanupHandler.clean()
// or we have to add a new method in EnvironmentCleanupHandler, eg. clean( environmentName )
//restore environment for the specified component
EnvironmentCleanupHandler cleanupHandler = getEnvironmentCleanupHandlerInstance(component);
if (cleanupHandler != null) {
log.debug("Executing cleanup for component '" + componentName + "'");
cleanupHandler.clean();
} else {
log.debug("No cleanup hanlder defined for component '" + componentName + "'");
}
}
Aggregations