Skip to content

Commit

Permalink
Log files logged in two-stage process to prevent early FTP upload. (#266
Browse files Browse the repository at this point in the history
)

* First attempt at RoboTutor syncing via FTP

Next:
- move code, assets, imports to different component library
- make sure it can handle import of apache-commons-net library
- test that it can handle uploading multiple files at once

* migrated FTP library to new component

* replaced local comp_ftp module with a bundled aar named "service_ftp"

* git config FTP

* consistent versioning

* created way to prevent log files from premature upload. Moved log file name initialization out of Constructor.

* service_ftp called as external APK

* FTP transfer no longer done via RoboTutor

* Removed obsolete FTP code, which was moved to RoboTransfer

* last minute code aesthetic changes to match dev
  • Loading branch information
kevindeland authored Mar 23, 2018
1 parent 9f95577 commit c1bae68
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 21 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:percent:25.2.0'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@

</application>

</manifest>
</manifest>
24 changes: 19 additions & 5 deletions app/src/main/java/cmu/xprize/robotutor/RoboTutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ public class RoboTutor extends Activity implements IReadyListener, IRoboTutor {
//
static private IGuidView guidCallBack;

public final static String LOG_PATH = Environment.getExternalStorageDirectory() + TCONST.ROBOTUTOR_FOLDER;
public final static String INIT_TIME = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
public final static String LOG_FILENAME = "RoboTutor" + "_" + BuildConfig.BUILD_TYPE + "." + BuildConfig.VERSION_NAME + "_" + INIT_TIME + "_" + Build.SERIAL;
String hotLogPath;
String readyLogPath;
public final static String DOWNLOAD_PATH = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DOWNLOADS;
public final static String EXT_ASSET_PATH = Environment.getExternalStorageDirectory() + File.separator + TCONST.ROBOTUTOR_ASSET_FOLDER;

Expand All @@ -137,6 +136,11 @@ protected void onCreate(Bundle savedInstanceState) {
//
super.onCreate(null);

hotLogPath = Environment.getExternalStorageDirectory() + TCONST.HOT_LOG_FOLDER;
readyLogPath = Environment.getExternalStorageDirectory() + TCONST.READY_LOG_FOLDER;
String initTime = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
String logFilename = "RoboTutor" + "_" + BuildConfig.BUILD_TYPE + "." + BuildConfig.VERSION_NAME + "_" + initTime + "_" + Build.SERIAL;


Log.d(TCONST.DEBUG_GRAY_SCREEN_TAG, "rt: onCreate");
// Catch all errors and cause a clean exit -
Expand Down Expand Up @@ -169,8 +173,12 @@ protected void onCreate(Bundle savedInstanceState) {
VERSION_RT = BuildConfig.VERSION_NAME;
VERSION_SPEC = CAssetObject.parseVersionSpec(VERSION_RT);

Log.w("LOG_DEBUG", "Beginning new session with LOG_FILENAME = " + logFilename);

logManager = CLogManager.getInstance();
logManager.startLogging(LOG_PATH, LOG_FILENAME);
logManager.transferHotLogs(hotLogPath, readyLogPath);

logManager.startLogging(hotLogPath, logFilename);
CErrorManager.setLogManager(logManager);

// TODO : implement time stamps
Expand Down Expand Up @@ -221,6 +229,7 @@ protected void onCreate(Bundle savedInstanceState) {
masterContainer.addAndShow(progressView);
}


/**
* This file gets the Extras that are passed from FaceLogin and uses them to set the uniqueIDs,
* SessionID and StudentID
Expand Down Expand Up @@ -350,7 +359,9 @@ protected Boolean doInBackground(Void... unused) {

try {
// TODO: Don't do this in production
// At the moment we always reinstall the tutor spec data - for development
// At the moment we always reinstall the tutor spec data - for


if(CacheSource.equals(TCONST.EXTERN)) {
tutorAssetManager.installAssets(TCONST.TUTORROOT);
logManager.postEvent_V(TAG, "INFO:Tutor Assets installed");
Expand Down Expand Up @@ -723,6 +734,9 @@ protected void onDestroy() {

logManager.postDateTimeStamp(GRAPH_MSG, "RoboTutor:SessionEnd");
logManager.stopLogging();

// after logging, transfer logs to READY folder
logManager.transferHotLogs(hotLogPath, readyLogPath);
}


Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ allprojects {
rtCompileSdkVersion=24 //Integer
rtBuildToolsVersion="25.0.0" //String

rtMinSdkVersion=21
rtMinSdkVersion=22

// Note that using target version 22 bypasses the new run-time permissions found
// in Marshmallow 23
Expand All @@ -37,7 +37,9 @@ allprojects {
// Semantic versioning description:
// <Milestone release> <Feature Release> <Patch release> <Asset Compatibility INDEX>

rtVersionName="1.5.8.1"

rtVersionName="1.5.9.1"

}
}

Expand Down
12 changes: 6 additions & 6 deletions comp_clickmask/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion rootProject.ext.rtCompileSdkVersion
buildToolsVersion rootProject.ext.rtBuildToolsVersion

defaultConfig {
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
minSdkVersion rootProject.ext.rtMinSdkVersion
targetSdkVersion rootProject.ext.rtTargetSdkVersion
versionCode rootProject.ext.rtVersionCode
versionName rootProject.ext.rtVersionName

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
5 changes: 2 additions & 3 deletions comp_counting2/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"

compileSdkVersion rootProject.ext.rtCompileSdkVersion
buildToolsVersion rootProject.ext.rtBuildToolsVersion

defaultConfig {
minSdkVersion rootProject.ext.rtMinSdkVersion
Expand Down
4 changes: 2 additions & 2 deletions comp_logging/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion rootProject.ext.rtCompileSdkVersion
buildToolsVersion rootProject.ext.rtBuildToolsVersion

defaultConfig {
minSdkVersion rootProject.ext.rtMinSdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@

package cmu.xprize.comp_logging;

import android.icu.util.Output;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.ErrorManager;


public class CLogManager implements ILogManager {
Expand Down Expand Up @@ -89,6 +95,52 @@ private CLogManager() {
}


public void transferHotLogs(String hotPath, String readyPath) {

File hotDir = new File(hotPath);

// our first time...
if (!hotDir.exists()) {
return;
}

File readyDir = new File(readyPath);

try {

// make dir if necessary
if (!readyDir.exists()) {
readyDir.mkdir();
}

for (File f : hotDir.listFiles()) {
Log.w("LOG_DEBUG", "Transferring file " + f.getName());

if (f.isDirectory()) {
// do nothing... there should not be any directories
} else {
File readyLog = new File(readyPath, f.getName());
InputStream in = new FileInputStream(f);
OutputStream out = new FileOutputStream(readyLog);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}

in.close();
out.close();

f.delete();
}
}
} catch (IOException e) {
CErrorManager.logEvent(TAG, "Transfer Error:", e, false);
}

}


public void startLogging(String logPath, String logFilename) {

log_Path = logPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

public interface ILogManager {

/**
* Transfer logs from one path to another. Separation of hot logs from ready logs prevents
* RoboTransfer from transferring a log while it is being written.
*
* @param hotPath
* @param readyPath
*/
public void transferHotLogs(String hotPath, String readyPath);

public void startLogging(String logPath, String logFileName);
public void stopLogging();

Expand Down
3 changes: 2 additions & 1 deletion util/src/main/java/cmu/xprize/util/TCONST.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ public class TCONST {
public static final String FW_RESPONSE = "FW_RESPONSE";

public static final String WRITINGTUTOR_FOLDER = "/WritingTutor/";
public static final String ROBOTUTOR_FOLDER = "/RoboTutor/";
public static final String HOT_LOG_FOLDER = "/RoboTutor_HOT/";
public static final String READY_LOG_FOLDER = "/RoboTutor/";
public static final String ROBOTUTOR_ASSET_FOLDER = "/robotutor_assets/";
public static final String GLYPHS_FOLDER = "/glyphs/";

Expand Down

1 comment on commit c1bae68

@JackMostow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also need to upload some to remote, sync some files with local, and do both with some.
How should robotransfer know which are which?

Please sign in to comment.