Search in sources :

Example 36 with StatusResult

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

the class AROController method getDevices.

private int getDevices(IAroDevices aroDevices, List<IDataCollector> collectors, DataCollectorType collectorType) {
    int count = 0;
    for (IDataCollector iDataCollector : collectors) {
        if (iDataCollector.getType().equals(collectorType) && aroDevices != null) {
            if (Util.isMacOS() && iDataCollector.getType().equals(DataCollectorType.IOS)) {
                StatusResult status = new StatusResult();
                IAroDevice[] aroDeviceArray = iDataCollector.getDevices(status);
                aroDevices.addDeviceArray(aroDeviceArray);
                count = aroDeviceArray == null ? 0 : aroDeviceArray.length;
            } else {
                IDevice[] androidDevices = getConnectedDevices();
                if (androidDevices != null && androidDevices.length > 0) {
                    aroDevices.addDeviceArray(androidDevices);
                }
                count = androidDevices == null ? 0 : androidDevices.length;
            }
        }
    }
    return count;
}
Also used : IAroDevice(com.att.aro.core.mobiledevice.pojo.IAroDevice) StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) IDevice(com.android.ddmlib.IDevice) IDataCollector(com.att.aro.core.datacollector.IDataCollector)

Example 37 with StatusResult

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

the class AROController method startCollector.

/**
 * Start the collector on device
 *
 * @param deviceId
 * @param traceFolderName
 * @param videoOption
 * @param secure
 */
public StatusResult startCollector(IAroDevice device, String traceFolderName, Hashtable<String, Object> extraParams) {
    StatusResult result = null;
    LOG.info("starting collector:" + traceFolderName + " " + extraParams);
    getAvailableCollectors();
    collector = device.getCollector();
    if (collector == null) {
        collector = loadCollector(device);
    }
    traceFolderPath = getTraceFolderPath(device, traceFolderName);
    IFileManager fileManager = context.getBean(IFileManager.class);
    if (!fileManager.directoryExistAndNotEmpty(traceFolderPath)) {
        result = collector.startCollector(false, traceFolderPath, null, true, device.getId(), extraParams, collector.getPassword());
        traceStartTime = new Date();
        if (result.isSuccess()) {
            LOG.info("Result : traffic capture launched successfully");
            traceDuration = 0;
        } else {
            LOG.error("Result trace success:" + result.isSuccess() + ", Name :" + result.getError().getName() + ", Description :" + result.getError().getDescription());
            LOG.error("device logcat:");
        }
    } else {
        LOG.info("Illegal path:" + traceFolderPath);
        result = new StatusResult();
        result.setError(ErrorCodeRegistry.getTraceFolderNotFound());
        return result;
    }
    return result;
}
Also used : StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) Date(java.util.Date) IFileManager(com.att.aro.core.fileio.IFileManager)

Example 38 with StatusResult

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

the class AROController method stopCollector.

/**
 * Stop the current collection process in a clean manner.
 */
public void stopCollector(CollectorStatus collectorstatus) {
    if (collector == null) {
        return;
    }
    LOG.debug("stopCollector() check if running");
    if (collector.isTrafficCaptureRunning(1) && !collectorstatus.equals(CollectorStatus.CANCELLED)) {
        // FIXME THINKS THE CAPTURE IS RUNNING AFTER STOP
        StatusResult result = collector.stopCollector();
        LOG.info("stopped collector, result:" + result);
        if (collector.getType().equals(DataCollectorType.IOS) && (!collector.isDeviceDataPulled())) {
            this.theView.setDeviceDataPulled(false);
        }
        if (result.isSuccess()) {
            Date traceStopTime = new Date();
            traceDuration = traceStopTime.getTime() - traceStartTime.getTime();
            this.theView.updateCollectorStatus(collectorstatus, result);
        } else {
            traceDuration = 0;
            this.theView.updateCollectorStatus(null, result);
        }
    } else {
        collector.haltCollectorInDevice();
    }
}
Also used : StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) Date(java.util.Date)

Example 39 with StatusResult

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

the class FileSubmit method run.

@Override
public void run() {
    runState = true;
    LOG.info("Start Sending...");
    StatusResult statusResult = sendPost(url, file1, file2);
    LOG.info("Forward Status to subscriber");
    LOG.info(String.format("forward results \"%s\" \"%s\"to :%s", statusResult.isSuccess(), statusResult.getData(), subscriber.getClass().getSimpleName()));
    String result = statusResult.getData().toString();
    if (StringUtils.isEmpty(result)) {
        statusResult.setSuccess(false);
        result = "Status: " + statusResult.getStatus() + ". Reason: " + statusResult.getStatusInfo();
    }
    subscriber.receiveResults(this.getClass(), statusResult.isSuccess(), result);
    LOG.info("Finished Sending...");
    LOG.info("Results : Success:" + statusResult.isSuccess() + ", Response:" + statusResult.getData());
    runState = false;
}
Also used : StatusResult(com.att.aro.core.datacollector.pojo.StatusResult)

Example 40 with StatusResult

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

the class FileSubmit method sendPost.

@POST
public StatusResult sendPost(String url, File file1, File file2) {
    StatusResult statusResult = new StatusResult();
    LOG.info("URL:" + url);
    LOG.info("Send POST multipart");
    LOG.info(String.format("part1:%s", file1));
    LOG.info(String.format("part2:%s", file2));
    LOG.info("Building Client...");
    final Client client = ClientBuilder.newBuilder().register(MultiPartFeature.class).build();
    LOG.info("fin: ClientBuilder.newBuilder().register(MultiPartFeature.class).build()");
    client.property(ClientProperties.REQUEST_ENTITY_PROCESSING, "CHUNKED");
    client.property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024);
    if (useAuthentication) {
        String userName = SettingsImpl.getInstance().getAttribute("user.name");
        String userPassword = SettingsImpl.getInstance().getAttribute("user.password");
        if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(userPassword)) {
            HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(userName, userPassword);
            client.register(feature);
        }
    }
    FormDataMultiPart formDataMultiPart = new FormDataMultiPart();
    FileDataBodyPart part1 = new FileDataBodyPart("file", file1, MediaType.APPLICATION_OCTET_STREAM_TYPE);
    FileDataBodyPart part2 = new FileDataBodyPart("file", file2, MediaType.APPLICATION_JSON_TYPE);
    LOG.info(String.format("File Information: FileDataBodyPart(%s, %s)", file1.getName(), file2.getName()));
    formDataMultiPart.bodyPart(part1).bodyPart(part2).setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
    WebTarget target = client.target(url);
    long timeStart = System.currentTimeMillis();
    LOG.info("Initiate POST to " + url);
    if (isRunning()) {
        Entity<FormDataMultiPart> theEntity = Entity.entity(formDataMultiPart, formDataMultiPart.getMediaType());
        Response response = null;
        long timeEnd;
        try {
            response = target.request().post(theEntity);
            timeEnd = System.currentTimeMillis();
            LOG.debug("post finished :" + response.getStatus());
            LOG.debug("POST process time :" + ((double) (timeEnd - timeStart)) / 1000);
            statusResult.setSuccess(true);
            statusResult.setData("elapsed time: " + ((double) (timeEnd - timeStart) / 1000));
            statusResult.setStatus(response.getStatus());
            statusResult.setStatusInfo(response.getStatusInfo().getReasonPhrase());
            statusResult.setData(response.readEntity(String.class));
        } catch (Exception e) {
            timeEnd = System.currentTimeMillis();
            LOG.error(String.format("target.request().post(%s) Exception :%s", theEntity.toString(), e.getMessage()));
            LOG.error("target.request().post(theEntity) Exception :" + e.getMessage());
            LOG.error("POST process time :" + ((double) (timeEnd - timeStart)) / 1000);
            statusResult.setSuccess(false);
            statusResult.setData(e);
            statusResult.setError(ErrorCodeRegistry.getPostError(e.getMessage()));
            return statusResult;
        } finally {
            try {
                LOG.debug("closing the multipart - formDataMultiPart.close()");
                formDataMultiPart.close();
            } catch (IOException e) {
                LOG.error("Error :" + e.getMessage());
            }
        }
        // Use response object to verify upload success
        if (response != null) {
            LOG.info("RESULTS :" + response.toString());
            LOG.info("RESULTS DATA :" + statusResult.getData().toString());
        }
        LOG.debug("Total time :" + timeEnd + " - " + timeStart + " = " + ((double) (timeEnd - timeStart) / 1000));
    }
    return statusResult;
}
Also used : IOException(java.io.IOException) IOException(java.io.IOException) Response(javax.ws.rs.core.Response) HttpAuthenticationFeature(org.glassfish.jersey.client.authentication.HttpAuthenticationFeature) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) FileDataBodyPart(org.glassfish.jersey.media.multipart.file.FileDataBodyPart) POST(javax.ws.rs.POST)

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