Search in sources :

Example 1 with Configurator

use of com.axway.ats.agent.core.configuration.Configurator 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 Configurator

use of com.axway.ats.agent.core.configuration.Configurator 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 Configurator

use of com.axway.ats.agent.core.configuration.Configurator 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)

Example 4 with Configurator

use of com.axway.ats.agent.core.configuration.Configurator in project ats-framework by Axway.

the class RemoteConfigurationManager method pushConfiguration.

/**
     * Push the provided configuration to the remote Agent
     *
     * @param atsAgent host to push the configuration to
     * @param configurator the configurator
     * @throws AgentException
     */
public void pushConfiguration(String atsAgent, Configurator configurator) throws AgentException {
    // get the client instance
    AgentService agentServicePort = AgentServicePool.getInstance().getClient(atsAgent);
    List<Configurator> configurators = new ArrayList<Configurator>();
    configurators.add(configurator);
    String checkServerLogsStr = ". Check server logs for more details.";
    try {
        // serialize the configurators
        ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutStream = new ObjectOutputStream(byteOutStream);
        objectOutStream.writeObject(configurators);
        agentServicePort.pushConfiguration(byteOutStream.toByteArray());
        log.info("Successfully set the " + configurator.getDescription() + " on ATS Agent at '" + atsAgent + "'");
    } catch (IOException ioe) {
        // log hint for further serialization issue investigation
        String msg = "Could not serialize configurators" + checkServerLogsStr;
        log.error(msg, ioe);
        throw new AgentException(msg, ioe);
    } catch (AgentException_Exception ae) {
        String msg = ae.getMessage() + checkServerLogsStr;
        log.error(msg, ae);
        throw new AgentException(msg, ae.getCause());
    } catch (Exception e) {
        String msg = e.getMessage() + checkServerLogsStr;
        log.error(msg, e);
        throw new AgentException(msg, e);
    }
}
Also used : AgentService(com.axway.ats.agent.webapp.client.AgentService) Configurator(com.axway.ats.agent.core.configuration.Configurator) AgentException(com.axway.ats.agent.core.exceptions.AgentException) ArrayList(java.util.ArrayList) AgentException_Exception(com.axway.ats.agent.webapp.client.AgentException_Exception) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) AgentException(com.axway.ats.agent.core.exceptions.AgentException) AgentException_Exception(com.axway.ats.agent.webapp.client.AgentException_Exception) IOException(java.io.IOException)

Example 5 with Configurator

use of com.axway.ats.agent.core.configuration.Configurator in project ats-framework by Axway.

the class EnvironmentCleanupClient method pushConfiguration.

/**
     * Apply the new settings
     *
     * @param agentSettings a list with Agent settings to change
     * @throws AgentException
     */
private void pushConfiguration(Configurator configurator) throws AgentException {
    List<Configurator> configurators = new ArrayList<Configurator>();
    configurators.add(configurator);
    if (atsAgent.equals(LOCAL_JVM)) {
        // 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 Agent configuration
        new RemoteConfigurationManager().pushConfiguration(atsAgent, configurator);
    }
}
Also used : Configurator(com.axway.ats.agent.core.configuration.Configurator) EnvironmentConfigurator(com.axway.ats.agent.core.configuration.EnvironmentConfigurator) ArrayList(java.util.ArrayList) RemoteConfigurationManager(com.axway.ats.agent.webapp.client.configuration.RemoteConfigurationManager)

Aggregations

Configurator (com.axway.ats.agent.core.configuration.Configurator)5 ArrayList (java.util.ArrayList)5 AgentConfigurator (com.axway.ats.agent.core.configuration.AgentConfigurator)3 AgentException (com.axway.ats.agent.core.exceptions.AgentException)3 RemoteConfigurationManager (com.axway.ats.agent.webapp.client.configuration.RemoteConfigurationManager)2 IOException (java.io.IOException)2 EnvironmentConfigurator (com.axway.ats.agent.core.configuration.EnvironmentConfigurator)1 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 AgentException_Exception (com.axway.ats.agent.webapp.client.AgentException_Exception)1 AgentService (com.axway.ats.agent.webapp.client.AgentService)1 ClasspathUtils (com.axway.ats.core.utils.ClasspathUtils)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1