Search in sources :

Example 41 with StatusResult

use of com.att.aro.core.datacollector.pojo.StatusResult in project VideoOptimzer by attdevsupport.

the class Compressor method zipFolder.

/**
 * Create a zip file of a folder while filtering out certain folders/files
 *
 * @param targetFolder
 *            - folder to zip
 * @param exclude
 *            - String arry of files to skip/exclude
 * @param zippedName
 *            - name of resulting zip file
 * @return
 */
public String zipFolder(String targetFolder, String[] exclude, String zippedName) {
    notifyListeners(new StatusResult(null, null, State.COMPRESSING));
    File folder = new File(targetFolder);
    File[] listOfFiles = folder.listFiles();
    if (listOfFiles == null) {
        notifyListeners(new StatusResult(false, null, State.FAILURE));
        return "";
    }
    ArrayList<String> excluded = sArrayToArrayList(exclude);
    ArrayList<File> sourceFileList = new ArrayList<>();
    for (int i = 0; i < listOfFiles.length; i++) {
        if (listOfFiles[i].isFile()) {
            if (!excluded.contains(listOfFiles[i].getName())) {
                sourceFileList.add(listOfFiles[i]);
            }
        }
    }
    if (sourceFileList.size() <= 0) {
        notifyListeners(new StatusResult(false, null, State.FAILURE));
        return "";
    }
    ZipParameters parameters = new ZipParameters();
    parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
    parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA);
    ZipFile zipfile;
    try {
        zipfile = new ZipFile(targetFolder + FILE_SEPARATOR + zippedName);
        zipfile.addFiles(sourceFileList, parameters);
    } catch (ZipException e) {
        e.printStackTrace();
    }
    notifyListeners(new StatusResult(true, null, State.DONE));
    return targetFolder + FILE_SEPARATOR + zippedName;
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) ArrayList(java.util.ArrayList) ZipException(net.lingala.zip4j.exception.ZipException) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File) ZipParameters(net.lingala.zip4j.model.ZipParameters)

Example 42 with StatusResult

use of com.att.aro.core.datacollector.pojo.StatusResult 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)

Aggregations

StatusResult (com.att.aro.core.datacollector.pojo.StatusResult)42 IOException (java.io.IOException)28 Test (org.junit.Test)20 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)19 TimeoutException (com.android.ddmlib.TimeoutException)19 IDevice (com.android.ddmlib.IDevice)17 Ignore (org.junit.Ignore)13 File (java.io.File)8 Date (java.util.Date)7 SyncService (com.android.ddmlib.SyncService)5 InstallException (com.android.ddmlib.InstallException)3 SyncException (com.android.ddmlib.SyncException)3 IAroDevice (com.att.aro.core.mobiledevice.pojo.IAroDevice)3 FileWriter (java.io.FileWriter)3 Hashtable (java.util.Hashtable)3 IDataCollector (com.att.aro.core.datacollector.IDataCollector)2 IVideoImageSubscriber (com.att.aro.core.datacollector.IVideoImageSubscriber)2 EnvironmentDetails (com.att.aro.core.datacollector.pojo.EnvironmentDetails)2 IFileManager (com.att.aro.core.fileio.IFileManager)2 AROAndroidDevice (com.att.aro.core.mobiledevice.pojo.AROAndroidDevice)2