use of com.axway.ats.agent.core.configuration.AgentConfigurator in project ats-framework by Axway.
the class AgentConfigurationClient method applyConfigurationAndReloadAgentComponents.
/**
* Apply the new settings
*
* @param agentSettings a list with Agent settings to change
* @throws AgentException
*/
private void applyConfigurationAndReloadAgentComponents(Properties agentSettings) throws AgentException {
// include the Agent configuration
AgentConfigurator agentConfigurator = new AgentConfigurator(agentSettings);
List<Configurator> configurators = new ArrayList<Configurator>();
configurators.add(agentConfigurator);
if (atsAgent.equals(LOCAL_JVM)) {
// executed in the JVM of the test executor
// the already loaded Agent components are first unloaded
MainComponentLoader.getInstance().destroy();
// the initialization procedure implicitly applies the new configurations
// and then loads up again the Agent components
MainComponentLoader.getInstance().initialize(configurators);
} else {
// send the new configuration to the remote Agent instance
new RemoteConfigurationManager().pushConfiguration(atsAgent, agentConfigurator);
}
}
use of com.axway.ats.agent.core.configuration.AgentConfigurator in project ats-framework by Axway.
the class AgentWsContextListener method contextInitialized.
/*
* (non-Javadoc)
*
* @see
* javax.servlet.ServletContextListener#contextInitialized(javax.servlet
* .ServletContextEvent)
*/
@Override
public void contextInitialized(ServletContextEvent servletEvent) {
ServletContext servletContext = servletEvent.getServletContext();
servletContext.log("Servlet context initialized event is received. Starting registering configurators");
try {
new ClasspathUtils().logProblematicJars();
} catch (RuntimeException e) {
log.warn("Error caught while trying to get all JARs in classpath", e);
// do not rethrow exception as this will stop deployment on incompliant servers like JBoss
}
// create the default web service configurator
String pathToConfigFile = servletContext.getRealPath("/WEB-INF");
AgentConfigurator defaultConfigurator = new AgentConfigurator(pathToConfigFile);
TemplateActionsConfigurator templateActionsConfigurator = new TemplateActionsConfigurator(pathToConfigFile);
List<Configurator> configurators = new ArrayList<Configurator>();
configurators.add(defaultConfigurator);
configurators.add(templateActionsConfigurator);
log.info("Initializing ATS Agent web service, start component registration");
try {
MainComponentLoader.getInstance().initialize(configurators);
} catch (AgentException ae) {
throw new RuntimeException("Unable to initialize Agent component loader", ae);
}
}
use of com.axway.ats.agent.core.configuration.AgentConfigurator in project ats-framework by Axway.
the class AgentWsImpl method pushConfiguration.
/**
* Apply client configuration to the server
*
* @param configurators the serialized configurators to be applied
* @throws AgentException on error
*/
@SuppressWarnings("unchecked")
@WebMethod
public void pushConfiguration(@WebParam(name = "configurators") byte[] serializedConfigurators) throws AgentException {
final String caller = getCaller();
ThreadsPerCaller.registerThread(caller);
ByteArrayInputStream byteInStream = new ByteArrayInputStream(serializedConfigurators);
ObjectInputStream objectInStream;
try {
objectInStream = new ObjectInputStream(byteInStream);
List<Configurator> configurators = (List<Configurator>) objectInStream.readObject();
// Check if AgentConfigurator is set. In such case we will need to reload the
// Agent components as this configuration defines the way Agent components are loaded.
boolean needToReloadComponents = false;
for (Configurator configurator : configurators) {
if (configurator instanceof AgentConfigurator) {
needToReloadComponents = true;
break;
}
}
if (needToReloadComponents) {
// the already loaded Agent components are first unloaded
MainComponentLoader.getInstance().destroy();
// the initialization procedure will implicitly apply the new configurations
// and then will load up again the Agent components
MainComponentLoader.getInstance().initialize(configurators);
} else {
// just apply the configurations
ConfigurationManager.getInstance().apply(configurators);
}
} catch (IOException ioe) {
final String msg = "IO error while serializing configurators";
// log on the monitored machine
log.error(msg, ioe);
throw new AgentException(msg, ioe);
} catch (ClassNotFoundException cnfe) {
final String msg = "Could not deserialize configurators";
// log on the monitored machine
log.error(msg, cnfe);
throw new AgentException(msg, cnfe);
} catch (Exception e) {
final String msg = "Error applying configurators";
// log on the monitored machine
log.error(msg, e);
throw new AgentException(msg, e);
} finally {
ThreadsPerCaller.unregisterThread();
}
}
Aggregations