Search in sources :

Example 1 with AgentConfigurator

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);
    }
}
Also used : Configurator(com.axway.ats.agent.core.configuration.Configurator) RemoteLoggingConfigurator(com.axway.ats.agent.core.configuration.RemoteLoggingConfigurator) GenericAgentConfigurator(com.axway.ats.agent.core.configuration.GenericAgentConfigurator) AgentConfigurator(com.axway.ats.agent.core.configuration.AgentConfigurator) ArrayList(java.util.ArrayList) GenericAgentConfigurator(com.axway.ats.agent.core.configuration.GenericAgentConfigurator) AgentConfigurator(com.axway.ats.agent.core.configuration.AgentConfigurator) RemoteConfigurationManager(com.axway.ats.agent.webapp.client.configuration.RemoteConfigurationManager)

Example 2 with 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);
    }
}
Also used : Configurator(com.axway.ats.agent.core.configuration.Configurator) AgentConfigurator(com.axway.ats.agent.core.configuration.AgentConfigurator) TemplateActionsConfigurator(com.axway.ats.agent.core.configuration.TemplateActionsConfigurator) AgentException(com.axway.ats.agent.core.exceptions.AgentException) TemplateActionsConfigurator(com.axway.ats.agent.core.configuration.TemplateActionsConfigurator) ArrayList(java.util.ArrayList) ServletContext(javax.servlet.ServletContext) ClasspathUtils(com.axway.ats.core.utils.ClasspathUtils) AgentConfigurator(com.axway.ats.agent.core.configuration.AgentConfigurator)

Example 3 with AgentConfigurator

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();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Configurator(com.axway.ats.agent.core.configuration.Configurator) AgentConfigurator(com.axway.ats.agent.core.configuration.AgentConfigurator) AgentException(com.axway.ats.agent.core.exceptions.AgentException) ArrayList(java.util.ArrayList) List(java.util.List) AgentConfigurator(com.axway.ats.agent.core.configuration.AgentConfigurator) IOException(java.io.IOException) InternalComponentException(com.axway.ats.agent.core.exceptions.InternalComponentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchActionException(com.axway.ats.agent.core.exceptions.NoSuchActionException) NoCompatibleMethodFoundException(com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) IOException(java.io.IOException) ActionExecutionException(com.axway.ats.agent.core.exceptions.ActionExecutionException) ObjectInputStream(java.io.ObjectInputStream) WebMethod(javax.jws.WebMethod)

Aggregations

AgentConfigurator (com.axway.ats.agent.core.configuration.AgentConfigurator)3 Configurator (com.axway.ats.agent.core.configuration.Configurator)3 ArrayList (java.util.ArrayList)3 AgentException (com.axway.ats.agent.core.exceptions.AgentException)2 GenericAgentConfigurator (com.axway.ats.agent.core.configuration.GenericAgentConfigurator)1 RemoteLoggingConfigurator (com.axway.ats.agent.core.configuration.RemoteLoggingConfigurator)1 TemplateActionsConfigurator (com.axway.ats.agent.core.configuration.TemplateActionsConfigurator)1 ActionExecutionException (com.axway.ats.agent.core.exceptions.ActionExecutionException)1 InternalComponentException (com.axway.ats.agent.core.exceptions.InternalComponentException)1 NoCompatibleMethodFoundException (com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException)1 NoSuchActionException (com.axway.ats.agent.core.exceptions.NoSuchActionException)1 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)1 RemoteConfigurationManager (com.axway.ats.agent.webapp.client.configuration.RemoteConfigurationManager)1 ClasspathUtils (com.axway.ats.core.utils.ClasspathUtils)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 List (java.util.List)1 WebMethod (javax.jws.WebMethod)1 ServletContext (javax.servlet.ServletContext)1