use of org.pentaho.platform.api.action.ActionInvocationException in project pentaho-platform by pentaho.
the class DefaultActionInvoker method invokeActionImpl.
/**
* Invokes the provided {@link IAction} as the provided {@code actionUser}.
*
* @param actionBean the {@link IAction} being invoked
* @param actionUser The user invoking the {@link IAction}
* @param params the {@link Map} or parameters needed to invoke the {@link IAction}
* @return the {@link IActionInvokeStatus} object containing information about the action invocation
* @throws Exception when the {@code IAction} cannot be invoked for some reason.
*/
protected IActionInvokeStatus invokeActionImpl(final IAction actionBean, final String actionUser, final Map<String, Serializable> params) throws Exception {
final String workItemUid = ActionUtil.extractUid(params);
if (actionBean == null || params == null) {
final String failureMessage = Messages.getInstance().getCantInvokeNullAction();
WorkItemLifecycleEventUtil.publish(workItemUid, params, WorkItemLifecyclePhase.FAILED, failureMessage);
throw new ActionInvocationException(failureMessage);
}
WorkItemLifecycleEventUtil.publish(workItemUid, params, WorkItemLifecyclePhase.IN_PROGRESS);
if (logger.isDebugEnabled()) {
logger.debug(Messages.getInstance().getRunningInBackgroundLocally(actionBean.getClass().getName(), params));
}
// set the locale, if not already set
if (params.get(LocaleHelper.USER_LOCALE_PARAM) == null || StringUtils.isEmpty(params.get(LocaleHelper.USER_LOCALE_PARAM).toString())) {
params.put(LocaleHelper.USER_LOCALE_PARAM, LocaleHelper.getLocale());
}
// remove the scheduling infrastructure properties
ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_ACTIONCLASS);
ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_ACTIONID);
ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_ACTIONUSER);
// build the stream provider
final IBackgroundExecutionStreamProvider streamProvider = getStreamProvider(params);
ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_STREAMPROVIDER);
ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_UIPASSPARAM);
final ActionRunner actionBeanRunner = new ActionRunner(actionBean, actionUser, params, streamProvider);
final IActionInvokeStatus status = new ActionInvokeStatus();
status.setStreamProvider(streamProvider);
boolean requiresUpdate = false;
try {
if ((StringUtil.isEmpty(actionUser)) || (actionUser.equals("system session"))) {
// $NON-NLS-1$
// For now, don't try to run quartz jobs as authenticated if the user
// that created the job is a system user. See PPP-2350
requiresUpdate = SecurityHelper.getInstance().runAsAnonymous(actionBeanRunner);
} else {
requiresUpdate = SecurityHelper.getInstance().runAsUser(actionUser, actionBeanRunner);
}
} catch (final Throwable t) {
WorkItemLifecycleEventUtil.publish(workItemUid, params, WorkItemLifecyclePhase.FAILED, t.toString());
status.setThrowable(t);
}
status.setRequiresUpdate(requiresUpdate);
// Set the execution Status
status.setExecutionStatus(actionBean.isExecutionSuccessful());
return status;
}
use of org.pentaho.platform.api.action.ActionInvocationException in project pentaho-platform by pentaho.
the class ActionUtil method createActionBean.
/**
* Returns an instance of {@link IAction} created from the provided parameters.
*
* @param actionClassName the name of the class being resolved
* @param actionId the is of the action which corresponds to some bean id
* @return {@link IAction} created from the provided parameters.
* @throws Exception when the {@link IAction} cannot be created for some reason
*/
public static IAction createActionBean(final String actionClassName, final String actionId, final boolean retryBeanInstantiationIfFailed) throws ActionInvocationException {
Object actionBean = null;
Class<?> actionClass = null;
try {
actionClass = resolveActionClass(actionClassName, actionId, retryBeanInstantiationIfFailed);
actionBean = actionClass.newInstance();
} catch (final Exception e) {
throw new ActionInvocationException(Messages.getInstance().getErrorString("ActionUtil.ERROR_0002_FAILED_TO_CREATE_ACTION", StringUtils.isEmpty(actionId) ? (actionClass == null ? "?" : actionClass.getName()) : actionId, e));
}
if (!(actionBean instanceof IAction)) {
throw new ActionInvocationException(Messages.getInstance().getErrorString("ActionUtil.ERROR_0003_ACTION_WRONG_TYPE", actionClass.getName(), IAction.class.getName()));
}
return (IAction) actionBean;
}
use of org.pentaho.platform.api.action.ActionInvocationException in project pentaho-platform by pentaho.
the class ActionUtil method resolveActionClass.
/**
* Returns the {@link Class} that corresponds to the provides {@code actionClassName} and {@code beanId}.
*
* @param actionClassName the name of the class being resolved
* @param beanId the beanId of the class being resolved
* @param retryBeanInstantiationIfFailed re-trigger bean instantiation attempt, should it fail for some reason
* @return the {@link Class} that corresponds to the provides {@code actionClassName} and {@code beanId}
* @throws PluginBeanException when the plugin required to resolve the bean class from the {@code beanId} cannot be
* created
* @throws Exception when the required parameters are not provided
*/
static Class<?> resolveActionClass(final String actionClassName, final String beanId, final boolean retryBeanInstantiationIfFailed) throws PluginBeanException, ActionInvocationException {
Class<?> clazz = null;
if (StringUtils.isEmpty(beanId) && StringUtils.isEmpty(actionClassName)) {
throw new ActionInvocationException(Messages.getInstance().getErrorString("ActionUtil.ERROR_0001_REQUIRED_PARAM_MISSING", INVOKER_ACTIONCLASS, INVOKER_ACTIONID));
}
final long retryCount = (retryBeanInstantiationIfFailed ? RETRY_COUNT : 1);
// millis
final long retrySleepCount = (retryBeanInstantiationIfFailed ? RETRY_SLEEP_AMOUNT : 1);
for (int i = 0; i < retryCount; i++) {
try {
if (!StringUtils.isEmpty(beanId)) {
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
clazz = pluginManager.loadClass(beanId);
if (clazz != null) {
return clazz;
}
}
// we will execute this only if the beanId is not provided, or if the beanId cannot be resolved
if (!StringUtils.isEmpty(actionClassName)) {
clazz = Class.forName(actionClassName);
return clazz;
}
} catch (Throwable t) {
try {
Thread.sleep(retrySleepCount);
} catch (InterruptedException ie) {
logger.info(ie.getMessage(), ie);
}
}
}
// which can typically happen at system startup
throw new ActionInvocationException(Messages.getInstance().getErrorString("ActionUtil.ERROR_0002_FAILED_TO_CREATE_ACTION", StringUtils.isEmpty(beanId) ? actionClassName : beanId));
}
Aggregations