001// Generated by delombok at Mon Oct 12 22:59:35 BST 2020
002/*
003 *  Licensed to the Apache Software Foundation (ASF) under one
004 *  or more contributor license agreements.  See the NOTICE file
005 *  distributed with this work for additional information
006 *  regarding copyright ownership.  The ASF licenses this file
007 *  to you under the Apache License, Version 2.0 (the
008 *  "License"); you may not use this file except in compliance
009 *  with the License.  You may obtain a copy of the License at
010 *
011 *        http://www.apache.org/licenses/LICENSE-2.0
012 *
013 *  Unless required by applicable law or agreed to in writing,
014 *  software distributed under the License is distributed on an
015 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 *  KIND, either express or implied.  See the License for the
017 *  specific language governing permissions and limitations
018 *  under the License.
019 */
020package org.apache.isis.extensions.commandreplay.secondary.analysis;
021
022import java.util.List;
023import javax.inject.Inject;
024import javax.inject.Named;
025import org.springframework.core.annotation.Order;
026import org.springframework.stereotype.Service;
027import org.apache.isis.applib.annotation.DomainService;
028import org.apache.isis.applib.annotation.OrderPrecedence;
029import org.apache.isis.extensions.commandlog.impl.jdo.CommandJdo;
030import org.apache.isis.extensions.commandreplay.secondary.analyser.CommandReplayAnalyser;
031
032@Service
033@Named("isisExtensionsCommandReplaySecondary.CommandReplayAnalysisService")
034@Order(OrderPrecedence.MIDPOINT)
035public class CommandReplayAnalysisService {
036    @java.lang.SuppressWarnings("all")
037    private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(CommandReplayAnalysisService.class);
038
039    /**
040     * if hit an issue with the command having been replayed, then mark this
041
042     * as in error.
043
044     * This will effectively block the running of any further commands until the adminstrator fixes the issue.
045     */
046    public void analyse(final CommandJdo commandJdo) {
047        final String analysis = analyseReplay(commandJdo);
048        commandJdo.saveAnalysis(analysis);
049    }
050
051    private String analyseReplay(final CommandJdo commandJdo) {
052        for (final CommandReplayAnalyser analyser : analysers) {
053            try {
054                String reason = analyser.analyzeReplay(commandJdo);
055                if (reason != null) {
056                    return reason;
057                }
058            } catch (Exception ex) {
059                final String className = analyser.getClass().getName();
060                log.warn("{} threw exception: ", className, ex);
061                return className + " threw exception: " + ex.getMessage();
062            }
063        }
064        return null;
065    }
066
067    @Inject
068    List<CommandReplayAnalyser> analysers;
069}