Search in sources :

Example 1 with Progress

use of com.cognifide.cq.cqsm.api.logger.Progress in project APM by Cognifide.

the class ModifyExecutor method runSafe.

private void runSafe(ResourceResolver resolver, Script script) throws PersistenceException {
    final String scriptPath = script.getPath();
    try {
        scriptManager.process(script, Mode.VALIDATION, resolver);
        if (script.isValid()) {
            Progress progress = scriptManager.process(script, Mode.AUTOMATIC_RUN, resolver);
            logStatus(scriptPath, progress.isSuccess());
        } else {
            LOG.warn(String.format("Executor won't execute script - it is not valid: %s", scriptPath));
        }
    } catch (RepositoryException e) {
        LOG.error("Script cannot be processed because of repository error: {}", scriptPath, e);
    }
}
Also used : Progress(com.cognifide.cq.cqsm.api.logger.Progress) RepositoryException(javax.jcr.RepositoryException)

Example 2 with Progress

use of com.cognifide.cq.cqsm.api.logger.Progress in project APM by Cognifide.

the class ReplicationExecutor method process.

private void process(final Script script, ResourceResolver resolver) throws PersistenceException {
    final String scriptPath = script.getPath();
    try {
        scriptManager.process(script, Mode.VALIDATION, resolver);
        if (script.isValid()) {
            final Progress progress = scriptManager.process(script, Mode.AUTOMATIC_RUN, resolver);
            logStatus(scriptPath, progress.isSuccess());
        } else {
            LOG.warn("Schedule executor cannot execute script which is not valid: {}", scriptPath);
        }
    } catch (RepositoryException e) {
        LOG.error("Script cannot be processed because of repository error: {}", scriptPath, e);
    }
}
Also used : Progress(com.cognifide.cq.cqsm.api.logger.Progress) RepositoryException(javax.jcr.RepositoryException)

Example 3 with Progress

use of com.cognifide.cq.cqsm.api.logger.Progress in project APM by Cognifide.

the class ScheduleExecutor method processScript.

private void processScript(Script script, ResourceResolver resolver) throws PersistenceException {
    final String scriptPath = script.getPath();
    try {
        scriptManager.process(script, Mode.VALIDATION, resolver);
        if (script.isValid()) {
            final Progress progress = scriptManager.process(script, Mode.AUTOMATIC_RUN, resolver);
            logStatus(scriptPath, progress.isSuccess());
        } else {
            LOG.warn("Schedule executor cannot execute script which is not valid: {}", scriptPath);
        }
    } catch (RepositoryException e) {
        LOG.error("Script cannot be processed because of repository error: {}", scriptPath, e);
    }
}
Also used : Progress(com.cognifide.cq.cqsm.api.logger.Progress) RepositoryException(javax.jcr.RepositoryException)

Example 4 with Progress

use of com.cognifide.cq.cqsm.api.logger.Progress in project APM by Cognifide.

the class RemoteScriptExecutionActionReceiver method handleAction.

@Override
public void handleAction(final ValueMap valueMap) {
    Preconditions.checkState(instanceTypeProvider.isOnAuthor(), "Action Receiver has to be called in author");
    String userId = valueMap.get(ReplicationAction.PROPERTY_USER_ID, String.class);
    SlingHelper.operateTraced(resolverFactory, userId, new OperateCallback() {

        @Override
        public void operate(ResourceResolver resolver) throws Exception {
            // FIXME would be lovely to cast ValueMap -> ModifiableEntryBuilder
            String scriptLocation = valueMap.get(ModifiableEntryBuilder.FILE_PATH_PROPERTY, String.class);
            Resource scriptResource = resolver.getResource(scriptLocation);
            Script script = scriptResource.adaptTo(ScriptImpl.class);
            InstanceDetails instanceDetails = getInstanceDetails(valueMap);
            Progress progress = getProgress(valueMap, resolver.getUserID());
            Calendar executionTime = getCalendar(valueMap);
            Mode mode = getMode(valueMap);
            history.logRemote(script, mode, progress, instanceDetails, executionTime);
        }
    });
}
Also used : Script(com.cognifide.cq.cqsm.api.scripts.Script) Progress(com.cognifide.cq.cqsm.api.logger.Progress) InstanceDetails(com.cognifide.cq.cqsm.api.history.InstanceDetails) ScriptImpl(com.cognifide.cq.cqsm.core.scripts.ScriptImpl) Calendar(java.util.Calendar) Mode(com.cognifide.cq.cqsm.api.executors.Mode) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) OperateCallback(com.cognifide.cq.cqsm.core.utils.sling.OperateCallback)

Example 5 with Progress

use of com.cognifide.cq.cqsm.api.logger.Progress in project APM by Cognifide.

the class ScriptManagerImpl method execute.

private Progress execute(Script script, final Mode mode, Map<String, String> customDefinitions, ResourceResolver resolver) throws ExecutionException, RepositoryException {
    if (script == null) {
        throw new ExecutionException("Script is not specified");
    }
    if (mode == null) {
        throw new ExecutionException("Execution mode is not specified");
    }
    final String path = script.getPath();
    actionFactory.update();
    LOG.info(String.format("Script execution started: %s [%s]", path, mode));
    Progress progress = new ProgressImpl(resolver.getUserID());
    final List<ActionDescriptor> descriptors = parseAllDescriptors(script, customDefinitions, resolver);
    final ActionExecutor actionExecutor = createExecutor(mode, resolver);
    final Context context = actionExecutor.getContext();
    final SessionSavingPolicy savingPolicy = context.getSavingPolicy();
    eventManager.trigger(Event.BEFORE_EXECUTE, script, mode, progress);
    for (ActionDescriptor descriptor : descriptors) {
        ActionResult result = actionExecutor.execute(descriptor);
        progress.addEntry(descriptor, result);
        if ((Status.ERROR == result.getStatus()) && (Mode.DRY_RUN != mode)) {
            eventManager.trigger(Event.AFTER_EXECUTE, script, mode, progress);
            return progress;
        }
        savingPolicy.save(context.getSession(), SessionSavingMode.EVERY_ACTION);
    }
    savingPolicy.save(context.getSession(), SessionSavingMode.SINGLE);
    eventManager.trigger(Event.AFTER_EXECUTE, script, mode, progress);
    return progress;
}
Also used : Context(com.cognifide.cq.cqsm.api.executors.Context) ProgressImpl(com.cognifide.cq.cqsm.core.progress.ProgressImpl) ActionExecutor(com.cognifide.cq.cqsm.core.actions.executor.ActionExecutor) Progress(com.cognifide.cq.cqsm.api.logger.Progress) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) ActionDescriptor(com.cognifide.cq.cqsm.api.actions.ActionDescriptor) SessionSavingPolicy(com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy) ExecutionException(com.cognifide.cq.cqsm.api.exceptions.ExecutionException)

Aggregations

Progress (com.cognifide.cq.cqsm.api.logger.Progress)11 RepositoryException (javax.jcr.RepositoryException)6 Script (com.cognifide.cq.cqsm.api.scripts.Script)4 Mode (com.cognifide.cq.cqsm.api.executors.Mode)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 ExecutionException (com.cognifide.cq.cqsm.api.exceptions.ExecutionException)2 ProgressImpl (com.cognifide.cq.cqsm.core.progress.ProgressImpl)2 ActionDescriptor (com.cognifide.cq.cqsm.api.actions.ActionDescriptor)1 ActionResult (com.cognifide.cq.cqsm.api.actions.ActionResult)1 Context (com.cognifide.cq.cqsm.api.executors.Context)1 InstanceDetails (com.cognifide.cq.cqsm.api.history.InstanceDetails)1 ModifiableScript (com.cognifide.cq.cqsm.api.scripts.ModifiableScript)1 ActionExecutor (com.cognifide.cq.cqsm.core.actions.executor.ActionExecutor)1 ScriptImpl (com.cognifide.cq.cqsm.core.scripts.ScriptImpl)1 SessionSavingPolicy (com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy)1 OperateCallback (com.cognifide.cq.cqsm.core.utils.sling.OperateCallback)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1