Search in sources :

Example 1 with OutSave

use of com.att.aro.console.printstreamutils.OutSave in project VideoOptimzer by attdevsupport.

the class Application method runAnalyzer.

/**
 * Analyze a trace and produce a report either in json or html<br>
 *
 * <pre>
 * Required command:
 *   --analyze with path to trace directory of traffic.cap
 *   --output output file, error if missing
 *   --format html or json, if missing defaults to json
 *
 * @param context
 *            - Spring ApplicationContext
 * @param cmds
 *            - user commands
 */
void runAnalyzer(ApplicationContext context, Commands cmds) {
    String trace = cmds.getAnalyze();
    IAROService serv = context.getBean(IAROService.class);
    AROTraceData results = null;
    // analyze trace file or directory?
    OutSave outSave = prepareSystemOut();
    ImHereThread imHereThread = new ImHereThread(outSave.getOut(), Logger.getRootLogger());
    try {
        if (serv.isFile(trace)) {
            try {
                results = serv.analyzeFile(retrieveBestPractices(), trace);
            } catch (IOException | TsharkException e) {
                errln("Error occured analyzing trace, detail: " + e.getMessage());
                System.exit(1);
            }
        } else {
            try {
                results = serv.analyzeDirectory(retrieveBestPractices(), trace);
            } catch (IOException e) {
                errln("Error occured analyzing trace directory, detail: " + e.getMessage());
                System.exit(1);
            }
        }
        if (results != null && results.isSuccess()) {
            outSave = prepareSystemOut();
            if (cmds.getFormat().equals("json")) {
                if (serv.getJSonReport(cmds.getOutput(), results)) {
                    outln("Successfully produced JSON report: " + cmds.getOutput());
                } else {
                    errln("Failed to produce JSON report.");
                }
            } else {
                if (serv.getHtmlReport(cmds.getOutput(), results)) {
                    println("Successfully produced HTML report: " + cmds.getOutput());
                } else {
                    errln("Failed to produce HTML report.");
                }
            }
        } else {
            printError(results == null ? new ErrorCode() : results.getError());
        }
    } finally {
        imHereThread.endIndicator();
        while (imHereThread.isRunning()) {
            Thread.yield();
        }
        restoreSystemOut(outSave);
    }
    System.exit(0);
}
Also used : IAROService(com.att.aro.core.IAROService) OutSave(com.att.aro.console.printstreamutils.OutSave) TsharkException(com.att.aro.core.exception.TsharkException) IOException(java.io.IOException) ErrorCode(com.att.aro.core.pojo.ErrorCode) AROTraceData(com.att.aro.core.pojo.AROTraceData) ImHereThread(com.att.aro.console.printstreamutils.ImHereThread)

Example 2 with OutSave

use of com.att.aro.console.printstreamutils.OutSave in project VideoOptimzer by attdevsupport.

the class Application method runDataCollector.

/**
 * Launches a DataCollection. Provides an input prompt for the user to stop the
 * collection by typing "stop"
 *
 * <pre>
 * Note:
 * Do not exit collection by pressing a ctrl-c
 * Doing so will exit ARO.Console but will not stop the trace on the device.
 * </pre>
 *
 * @param context
 * @param cmds
 */
// ignoring incorrect eclipse warning
@SuppressWarnings("null")
void runDataCollector(ApplicationContext context, Commands cmds) {
    if (cmds.getOutput() != null) {
        // LOGGER.info("runDataCollector");
        IDataCollectorManager colmg = context.getBean(IDataCollectorManager.class);
        colmg.getAvailableCollectors(context);
        IDataCollector collector = null;
        switch(cmds.getStartcollector()) {
            case "rooted_android":
                collector = colmg.getRootedDataCollector();
                break;
            case "vpn_android":
                collector = colmg.getNorootedDataCollector();
                break;
            case "ios":
                collector = colmg.getIOSCollector();
                if (cmds.getSudo().isEmpty() || !collector.setPassword(cmds.getSudo())) {
                    printError(ErrorCodeRegistry.getInvalidPasswordError());
                    System.exit(1);
                }
                if ("hd".equals(cmds.getVideo()) || "sd".equals(cmds.getVideo())) {
                    printError(ErrorCodeRegistry.getInvalidiOSArgs());
                    System.exit(1);
                }
                break;
            default:
                printError(ErrorCodeRegistry.getCollectorNotfound());
                System.exit(1);
                break;
        }
        StatusResult result = null;
        if (collector == null) {
            printError(ErrorCodeRegistry.getCollectorNotfound());
            System.exit(1);
        }
        if (cmds.getOverwrite().equalsIgnoreCase("yes")) {
            String traceName = cmds.getOutput();
            IFileManager filemanager = context.getBean(IFileManager.class);
            filemanager.directoryDeleteInnerFiles(traceName);
        }
        OutSave outSave = prepareSystemOut();
        AttenuatorModel model = getAttenuateModel(cmds);
        // If the user want to collect regular iOS collection, they can proceed
        if (DataCollectorType.IOS.equals(collector.getType()) && (model.isThrottleDLEnabled() || model.isThrottleULEnabled())) {
            if (isIOSAttenuationConfirmed() && NetworkUtil.isNetworkUp("bridge100")) {
                model.setConstantThrottle(true);
                println("Collection proceeded.");
            } else {
                System.exit(1);
            }
        }
        videoOption = configureVideoOption(cmds.getVideo());
        try {
            Hashtable<String, Object> extras = new Hashtable<String, Object>();
            Orientation videoOrientation = getOrientation(cmds.getVideoOrientation());
            extras.put("video_option", getVideoOption());
            extras.put("videoOrientation", videoOrientation == null ? Orientation.PORTRAIT : videoOrientation);
            extras.put("AttenuatorModel", model);
            extras.put("assignPermission", false);
            result = runCommand(cmds, collector, cmds.getSudo(), extras);
        } finally {
            restoreSystemOut(outSave);
        }
        if (result.getError() != null) {
            outln("Caught an error:");
            printError(result.getError());
        } else {
            outSave = prepareSystemOut();
            try {
                String input = "";
                print("Data collector is running, enter stop to save trace and quit program");
                print(">");
                do {
                    input = readInput();
                } while (!input.contains("stop"));
            } finally {
                restoreSystemOut(outSave);
            }
            println("stopping collector...");
            try {
                if (collector != null)
                    collector.stopCollector();
            } finally {
                restoreSystemOut(outSave);
            }
            println("collector stopped, trace saved to: " + cmds.getOutput());
            cleanUp(context);
            println("VO exited");
            System.exit(0);
        }
    } else {
        println("No output tracefolder was entered\n");
        usageHelp();
        System.exit(1);
    }
}
Also used : OutSave(com.att.aro.console.printstreamutils.OutSave) Hashtable(java.util.Hashtable) StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) IDataCollectorManager(com.att.aro.core.datacollector.IDataCollectorManager) AttenuatorModel(com.att.aro.core.peripheral.pojo.AttenuatorModel) IDataCollector(com.att.aro.core.datacollector.IDataCollector) Orientation(com.att.aro.core.video.pojo.Orientation) IFileManager(com.att.aro.core.fileio.IFileManager)

Example 3 with OutSave

use of com.att.aro.console.printstreamutils.OutSave in project VideoOptimzer by attdevsupport.

the class Application method prepareSystemOut.

private OutSave prepareSystemOut() {
    OutSave outSave = new OutSave(System.out, Logger.getRootLogger().getLevel());
    if (utilOut.getThreshold().ordinal() < UtilOut.MessageThreshold.Verbose.ordinal()) {
        Logger.getRootLogger().setLevel(Level.WARN);
        System.setOut(new PrintStream(new NullOut()));
    }
    return outSave;
}
Also used : PrintStream(java.io.PrintStream) OutSave(com.att.aro.console.printstreamutils.OutSave) NullOut(com.att.aro.console.printstreamutils.NullOut)

Aggregations

OutSave (com.att.aro.console.printstreamutils.OutSave)3 ImHereThread (com.att.aro.console.printstreamutils.ImHereThread)1 NullOut (com.att.aro.console.printstreamutils.NullOut)1 IAROService (com.att.aro.core.IAROService)1 IDataCollector (com.att.aro.core.datacollector.IDataCollector)1 IDataCollectorManager (com.att.aro.core.datacollector.IDataCollectorManager)1 StatusResult (com.att.aro.core.datacollector.pojo.StatusResult)1 TsharkException (com.att.aro.core.exception.TsharkException)1 IFileManager (com.att.aro.core.fileio.IFileManager)1 AttenuatorModel (com.att.aro.core.peripheral.pojo.AttenuatorModel)1 AROTraceData (com.att.aro.core.pojo.AROTraceData)1 ErrorCode (com.att.aro.core.pojo.ErrorCode)1 Orientation (com.att.aro.core.video.pojo.Orientation)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Hashtable (java.util.Hashtable)1