Search in sources :

Example 1 with ActionMethod

use of com.axway.ats.agent.core.action.ActionMethod in project ats-framework by Axway.

the class ActionHandler method executeAction.

/**
     * Execute an action on the remote host, pass the arguments as Objects 
     * 
     * @param caller            the remote caller
     * @param componentName     the name of the component
     * @param actionName        the name of the action
     * @param args              list of Object arguments
     * @return                  the result of the execution as an Object
     * 
     * @throws NoSuchComponentException     if the given component is not registered
     * @throws NoSuchActionException        if the given action is not registered
     * @throws ActionExecutionException     if exception occurred during action execution
     * @throws NoCompatibleMethodFoundException if no compatible method is found for this action
     */
public static Object executeAction(String caller, String componentName, String actionName, Object[] args) throws NoSuchComponentException, NoSuchActionException, ActionExecutionException, InternalComponentException, NoCompatibleMethodFoundException {
    //get the component action map for this caller
    //if component with this name does not exist, a NoSuchComponentException is thrown
    ComponentActionMap actionMap = ComponentRepository.getInstance().getComponentActionMap(caller, componentName);
    //get the argument types
    Class<?>[] argTypes = new Class<?>[args.length];
    for (int i = 0; i < args.length; i++) {
        if (args[i] == null) {
            argTypes[i] = Void.TYPE;
        } else {
            argTypes[i] = args[i].getClass();
        }
    }
    ActionMethod actionMethod = actionMap.getActionMethod(actionName, argTypes);
    Object actionClassInstance = actionMap.getCachedActionClassInstance(caller, actionMethod);
    //invoke the action
    return actionMethod.invoke(actionClassInstance, args, true);
}
Also used : ActionMethod(com.axway.ats.agent.core.action.ActionMethod)

Example 2 with ActionMethod

use of com.axway.ats.agent.core.action.ActionMethod in project ats-framework by Axway.

the class ComponentActionMap method addAction.

/**
     * Add an action to the component map
     *
     * @param actionName    name of the action
     * @param method        the method which implements the action
     * @throws ActionAlreadyDefinedException    if an action with this name has already been defined
     */
private void addAction(String actionName, String actionClassName, String actionMethodName, Method method, Class<?> actualClass, boolean isRegularAction) throws ActionAlreadyDefinedException {
    ActionMethodContainer methodContainer = actions.get(actionName);
    if (methodContainer == null) {
        methodContainer = new ActionMethodContainer(componentName, actionName);
        actions.put(actionName, methodContainer);
    }
    ActionMethod actionMethod;
    if (isRegularAction) {
        actionMethod = new ActionMethod(componentName, actionName, method, actualClass);
    } else {
        actionMethod = new TemplateActionMethod(componentName, actionName, actionClassName, actionMethodName, method, actualClass);
    }
    methodContainer.add(actionMethod);
}
Also used : ActionMethod(com.axway.ats.agent.core.action.ActionMethod) TemplateActionMethod(com.axway.ats.agent.core.action.TemplateActionMethod) ActionMethodContainer(com.axway.ats.agent.core.action.ActionMethodContainer) TemplateActionMethod(com.axway.ats.agent.core.action.TemplateActionMethod)

Example 3 with ActionMethod

use of com.axway.ats.agent.core.action.ActionMethod in project ats-framework by Axway.

the class AbstractActionTask method invokeActions.

/**
     * Invoke one iteration of all actions in the queue
     * 
     * @throws InterruptedException
     */
protected final void invokeActions() throws InterruptedException {
    UserActionsMonitoringAgent userActionsMonitoringAgent = UserActionsMonitoringAgent.getInstance(caller);
    if (log.isDebugEnabled()) {
        log.debug("Starting '" + queueName + "' queue for " + (++nIterations) + "th time");
    }
    //generate the input arguments for all action invokers
    generateInputArguments();
    long queueDuration = 0;
    long actionStartTimestamp = 0;
    long actionEndTimestamp = 0;
    if (this.itManager != null) {
        // inform a new iteration is starting now
        this.itManager.setIterationStartTime(this, System.currentTimeMillis());
    }
    try {
        for (int i = 0; i < actionInvokers.size(); i++) {
            // start cycling all actions in this iteration
            ActionInvoker actionInvoker = actionInvokers.get(i);
            Object actionClassInstance = actionClassInstances.get(i);
            ActionMethod actionMethod = actionInvoker.getActionMethod();
            final String actionName = actionInvoker.getActionName();
            final String transferUnit = actionMethod.getTransferUnit();
            // read some settings
            final boolean registerActionExecution = actionMethod.isRegisterActionExecution();
            final boolean registerActionExecutionInQueueExecutionTime = actionMethod.isRegisterActionExecutionInQueueExecutionTime();
            final boolean isTemplateActionMethod = actionMethod instanceof TemplateActionMethod;
            final boolean logCheckpoints = !isTemplateActionMethod || REGISTER_FULL_AND_NET_ACTION_TIME_FOR_TEMPLATE_ACTIONS;
            // checkpoint name. For template actions by default only network time is tracked.
            // Here "-full" adds total action processing including XML (de)serializations, parameterization
            String checkpointName;
            if (!isTemplateActionMethod) {
                checkpointName = actionName;
            } else {
                checkpointName = actionName + "-full";
            }
            // start a checkpoint
            userActionsMonitoringAgent.actionStarted(actionName);
            if (registerActionExecution) {
                actionStartTimestamp = System.currentTimeMillis();
                if (logCheckpoints && !isLoggingInBatchMode) {
                    log.startCheckpoint(checkpointName, transferUnit, actionStartTimestamp);
                }
            }
            // invoke the current action
            Object actionReturnedResult = null;
            try {
                actionReturnedResult = actionInvoker.invoke(actionClassInstance);
            } catch (Exception e) {
                // the action failed - end the checkpoint
                if (registerActionExecution) {
                    if (logCheckpoints) {
                        if (isLoggingInBatchMode) {
                            log.insertCheckpoint(checkpointName, actionStartTimestamp, 0, 0, transferUnit, CheckpointResult.FAILED);
                        } else {
                            log.endCheckpoint(checkpointName, 0, CheckpointResult.FAILED);
                        }
                    }
                    QueueExecutionStatistics.getInstance().registerActionExecutionResult(queueName, actionName, false);
                }
                // re-throw the exception
                throw e;
            } finally {
                userActionsMonitoringAgent.actionEnded(actionName);
            }
            // the action passed
            if (registerActionExecution) {
                actionEndTimestamp = System.currentTimeMillis();
                long responseTimeMs = actionEndTimestamp - actionStartTimestamp;
                long transferSize = 0;
                if (transferUnit.length() > 0) {
                    transferSize = (Long) actionReturnedResult;
                }
                if (logCheckpoints) {
                    if (isLoggingInBatchMode) {
                        log.insertCheckpoint(checkpointName, actionStartTimestamp, responseTimeMs, transferSize, transferUnit, CheckpointResult.PASSED);
                    } else {
                        log.endCheckpoint(checkpointName, transferSize, CheckpointResult.PASSED, actionEndTimestamp);
                    }
                }
                if (registerActionExecutionInQueueExecutionTime) {
                    if (isTemplateActionMethod) {
                        // add net time in queue instead of full processing time
                        if (actionReturnedResult instanceof CompositeResult) {
                            CompositeResult res = (CompositeResult) actionReturnedResult;
                            responseTimeMs = res.getReqRespNetworkTime();
                        }
                    }
                    queueDuration += responseTimeMs;
                }
                QueueExecutionStatistics.getInstance().registerActionExecutionResult(queueName, actionName, true);
            }
        }
    // end cycling all actions in this iteration
    } catch (Exception e) {
        // We are particularly interested if the thread was interrupted
        Throwable cause = e.getCause();
        if (cause != null && cause instanceof InterruptedException) {
            // the thread was interrupted
            if (this.timedOut) {
                // the thread was interrupted due to timeout, log the timeout and go to next iteration
                log.error("Iteration timed out in " + this.timedOutSeconds + " seconds - skipping to next iteration");
                // reset our flag as we will start another iteration
                this.timedOut = false;
                this.timedOutSeconds = 0;
            } else {
                // the thread interrupted, but not due to timeout, maybe the user cancelled the queue
                this.externallyInterrupted = true;
                throw (InterruptedException) cause;
            }
        } else {
            // some kind of generic exception has occurred
            log.error("Exception caught during invocation - skipping to next iteration", e);
        }
        //continue to the next iteration
        return;
    } finally {
        if (this.itManager != null) {
            this.itManager.clearIterationStartTime();
        }
    }
    if (registerActionsInQueueExecutionTime) {
        log.insertCheckpoint(ATS_ACTION__QUEUE_EXECUTION_TIME, queueDuration, CheckpointResult.PASSED);
    }
}
Also used : CompositeResult(com.axway.ats.agent.core.templateactions.CompositeResult) ActionMethod(com.axway.ats.agent.core.action.ActionMethod) TemplateActionMethod(com.axway.ats.agent.core.action.TemplateActionMethod) NoSuchActionException(com.axway.ats.agent.core.exceptions.NoSuchActionException) NoCompatibleMethodFoundException(com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) ActionExecutionException(com.axway.ats.agent.core.exceptions.ActionExecutionException) TemplateActionMethod(com.axway.ats.agent.core.action.TemplateActionMethod) ActionInvoker(com.axway.ats.agent.core.action.ActionInvoker) UserActionsMonitoringAgent(com.axway.ats.agent.core.monitoring.UserActionsMonitoringAgent)

Aggregations

ActionMethod (com.axway.ats.agent.core.action.ActionMethod)3 TemplateActionMethod (com.axway.ats.agent.core.action.TemplateActionMethod)2 ActionInvoker (com.axway.ats.agent.core.action.ActionInvoker)1 ActionMethodContainer (com.axway.ats.agent.core.action.ActionMethodContainer)1 ActionExecutionException (com.axway.ats.agent.core.exceptions.ActionExecutionException)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 UserActionsMonitoringAgent (com.axway.ats.agent.core.monitoring.UserActionsMonitoringAgent)1 CompositeResult (com.axway.ats.agent.core.templateactions.CompositeResult)1