Search in sources :

Example 36 with AgentException

use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.

the class LocalLoadExecutor method executeActions.

@Override
public void executeActions(List<ActionRequest> actionRequests) throws AgentException {
    log.info("Start executing action queue '" + queueName + "'." + (threadingPattern.isBlockUntilCompletion() ? " And wait to finish." : ""));
    // start queue in the database and retrieve its ID
    int queueId = retrieveQueueId(queueSequence, HostUtils.getLocalHostIP());
    try {
        MultiThreadedActionHandler.getInstance(ThreadsPerCaller.getCaller()).executeActions("LOCAL", queueName, queueId, actionRequests, threadingPattern, loaderDataConfig);
        if (threadingPattern.isBlockUntilCompletion()) {
            log.endLoadQueue(queueName, LoadQueueResult.PASSED);
            log.info("Finished executing action queue '" + queueName + "'");
        } else {
            // wait in another thread until the queue finish
            ImportantThread helpThread = new ImportantThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        MultiThreadedActionHandler.getInstance(ThreadsPerCaller.getCaller()).waitUntilQueueFinish(queueName);
                        log.endLoadQueue(queueName, LoadQueueResult.PASSED);
                        log.info("Finished executing action queue '" + queueName + "'");
                    } catch (NoSuchLoadQueueException e) {
                        log.error("Error waiting for action queue '" + queueName + "' completion", e);
                        log.endLoadQueue(queueName, LoadQueueResult.FAILED);
                    }
                }
            });
            helpThread.setDescription(queueName);
            helpThread.start();
            log.info("Action queue '" + queueName + "' scheduled for asynchronous execution");
        }
    } catch (Exception e) {
        throw new AgentException(e.getMessage(), e);
    }
}
Also used : AgentException(com.axway.ats.agent.core.exceptions.AgentException) ImportantThread(com.axway.ats.agent.core.threading.ImportantThread) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchLoadQueueException(com.axway.ats.agent.core.threading.exceptions.NoSuchLoadQueueException) NoSuchLoadQueueException(com.axway.ats.agent.core.threading.exceptions.NoSuchLoadQueueException)

Example 37 with AgentException

use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.

the class RemoteExecutor method wrapActionRequest.

/**
     * Wrap the action request into an ActionWrapper so it is easily
     * passed to the web service
     *
     * @param actionRequest the action request to wrap
     * @return the action wrapper
     * @throws AgentException on error
     */
protected final ActionWrapper wrapActionRequest(ActionRequest actionRequest) throws AgentException {
    Object[] arguments = actionRequest.getArguments();
    List<ArgumentWrapper> wrappedArguments = new ArrayList<ArgumentWrapper>();
    try {
        //a byte stream
        for (Object argument : arguments) {
            ArgumentWrapper argWrapper = new ArgumentWrapper();
            ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
            ObjectOutputStream objectOutStream = new ObjectOutputStream(byteOutStream);
            objectOutStream.writeObject(argument);
            argWrapper.setArgumentValue(byteOutStream.toByteArray());
            wrappedArguments.add(argWrapper);
        }
    } catch (IOException ioe) {
        throw new AgentException("Could not serialize input arguments", ioe);
    }
    //construct the action wrapper
    ActionWrapper actionWrapper = new ActionWrapper();
    actionWrapper.setComponentName(actionRequest.getComponentName());
    actionWrapper.setActionName(actionRequest.getActionName());
    actionWrapper.getArgs().addAll(wrappedArguments);
    return actionWrapper;
}
Also used : AgentException(com.axway.ats.agent.core.exceptions.AgentException) ArrayList(java.util.ArrayList) ActionWrapper(com.axway.ats.agent.webapp.client.ActionWrapper) ArgumentWrapper(com.axway.ats.agent.webapp.client.ArgumentWrapper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 38 with AgentException

use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.

the class AgentMonitoringClient method getMonitoringResults.

/**
     * @return the latest info about the Agent users activity
     * @throws AgentException
     */
@SuppressWarnings("unchecked")
public List<MonitorResults> getMonitoringResults() throws AgentException {
    // get the client instance
    AgentService agentServicePort = AgentServicePool.getInstance().getClient(atsAgent);
    try {
        ByteArrayInputStream byteInStream = new ByteArrayInputStream(agentServicePort.getMonitoringResults());
        ObjectInputStream objectInStream = new ObjectInputStream(byteInStream);
        return (List<MonitorResults>) objectInStream.readObject();
    } catch (Exception ioe) {
        // log hint for further serialization issue investigation
        log.error(ioe);
        throw new AgentException(ioe);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AgentException(com.axway.ats.agent.core.exceptions.AgentException) List(java.util.List) AgentException(com.axway.ats.agent.core.exceptions.AgentException) ObjectInputStream(java.io.ObjectInputStream)

Example 39 with AgentException

use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.

the class DynamicComponentLoader method loadComponents.

@Override
protected void loadComponents(ComponentRepository componentRepository) throws AgentException {
    if (componentsLocation == null || !componentsLocation.isDirectory() || !componentsLocation.exists()) {
        throw new AgentException("Components location not set, does not exist or is not a directory");
    }
    log.debug("Unloading any existing components");
    //clear the action map before registering
    componentRepository.clear();
    //init the class loader for loading the action classes
    ClassLoader currentClassLoader = DynamicComponentLoader.class.getClassLoader();
    actionClassesClassLoader = new ReversedDelegationClassLoader(new URL[] {}, currentClassLoader);
    File[] files = componentsLocation.listFiles();
    // java.io.File constructor accepts URIs where ClassLoader requires URLs
    List<URI> jarFileURIs = new ArrayList<URI>();
    if (files != null) {
        //get only the jar files
        for (File file : files) {
            if (file.getAbsolutePath().endsWith(".jar")) {
                try {
                    // file.toURL() is deprecated and in case with spaces in directories there were errors
                    URI jarFileURI = file.toURI();
                    jarFileURIs.add(jarFileURI);
                    //add the jar file to our custom class loader
                    //it may not be an Agent component (i.e. no descriptor) but
                    //an Agent component might depend on it anyway
                    actionClassesClassLoader.addURL(jarFileURI.toURL());
                } catch (MalformedURLException mue) {
                    log.warn("Malformed URL", mue);
                }
            }
        }
    }
    for (URI uri : jarFileURIs) {
        JarFile jarFile = null;
        try {
            jarFile = new JarFile(new File(uri));
            JarEntry entry = jarFile.getJarEntry(COMPONENT_DESCRIPTOR_NAME);
            if (entry != null) {
                log.info("Found component library in '" + uri.toURL().getFile() + "', starting registration process");
                InputStream descriptorStream = jarFile.getInputStream(entry);
                ConfigurationParser configParser = new ConfigurationParser();
                try {
                    configParser.parse(descriptorStream, (new File(uri)).getAbsolutePath());
                    registerComponent(configParser, componentRepository);
                    log.info("Successfully registered component library with name '" + configParser.getComponentName() + "'");
                } catch (Exception e) {
                    log.warn("Exception thrown while loading library '" + uri.toURL().getFile() + "', skipping it", e);
                    continue;
                }
            }
        } catch (IOException ioe) {
            try {
                log.warn("Could not open library '" + uri.toURL().getFile() + "', skipping it");
            } catch (MalformedURLException e) {
                log.error(e);
            }
        } finally {
            IoUtils.closeStream(jarFile);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URI(java.net.URI) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) IOException(java.io.IOException) ConfigurationParser(com.axway.ats.agent.core.ConfigurationParser) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 40 with AgentException

use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.

the class SystemMonitor method initializeSystemMonitoringProcess.

private void initializeSystemMonitoringProcess(String monitoredHost, Set<FullReadingBean> readings) throws MonitoringException {
    log.debug("Initializing the system monitoring process on " + monitoredHost);
    try {
        InternalSystemMonitoringOperations sysMonitoringActions = new InternalSystemMonitoringOperations(monitoredHost);
        sysMonitoringActions.initializeMonitoring(new ArrayList<FullReadingBean>(readings), startTimestamp, pollInterval);
    } catch (AgentException e) {
        throw new MonitoringException("Could not start the system monitoring process on " + monitoredHost + ". For more details check loader logs on that machine", e);
    }
}
Also used : InternalSystemMonitoringOperations(com.axway.ats.agent.components.monitoring.operations.clients.InternalSystemMonitoringOperations) AgentException(com.axway.ats.agent.core.exceptions.AgentException) MonitoringException(com.axway.ats.monitoring.model.exceptions.MonitoringException) FullReadingBean(com.axway.ats.common.performance.monitor.beans.FullReadingBean)

Aggregations

AgentException (com.axway.ats.agent.core.exceptions.AgentException)42 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)11 AgentException_Exception (com.axway.ats.agent.webapp.client.AgentException_Exception)9 AgentService (com.axway.ats.agent.webapp.client.AgentService)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ObjectOutputStream (java.io.ObjectOutputStream)7 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)6 InternalComponentException (com.axway.ats.agent.webapp.client.InternalComponentException)6 InternalComponentException_Exception (com.axway.ats.agent.webapp.client.InternalComponentException_Exception)6 ActionExecutionException (com.axway.ats.agent.core.exceptions.ActionExecutionException)5 InternalComponentException (com.axway.ats.agent.core.exceptions.InternalComponentException)5 NoCompatibleMethodFoundException (com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException)5 NoSuchActionException (com.axway.ats.agent.core.exceptions.NoSuchActionException)5 MonitoringException (com.axway.ats.monitoring.model.exceptions.MonitoringException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ObjectInputStream (java.io.ObjectInputStream)5 WebMethod (javax.jws.WebMethod)5 DatabaseEnvironmentUnit (com.axway.ats.environment.database.DatabaseEnvironmentUnit)4 File (java.io.File)4