Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
hajoha committed Feb 9, 2025
1 parent de333d6 commit aee5182
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 90 deletions.
4 changes: 3 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
}

-keepclassmembernames class io.netty.** { *; }
-keepclassmembers class org.jctools.** { *; }
-keepclassmembers class org.jctools.** { *; }


Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ public Result doWork() {
}
BufferedReader br;
try {
br = new BufferedReader(new FileReader(""));
br = new BufferedReader(new FileReader(input.getParameter().getLineProtocolFile()));
} catch (FileNotFoundException | NullPointerException e) {
Log.d(TAG,e.toString());
return Result.failure(output);
}
List<String> points = br.lines().collect(Collectors.toList());
try {
// Log.d(TAG, String.format("doWork: uploading %s", input.getLineProtocolFile()));
Log.d(TAG, String.format("doWork: uploading %s", input.getParameter().getLineProtocolFile()));
influx.writeRecords(points);
} catch (IOException e) {
// Log.d(TAG, String.format("doWork: upload of %s failed!", input.getLineProtocolFile()));
Log.d(TAG, String.format("doWork: upload of %s failed!", input.getParameter().getLineProtocolFile()));
return Result.failure(output);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

import java.sql.Timestamp;

public abstract class Inputs implements Parcelable {
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Parameter.Parameter;

public class Inputs implements Parcelable {


public static final String INPUT = "input";
Expand All @@ -28,9 +30,20 @@ public abstract class Inputs implements Parcelable {
private String campaignUUID;
private String sequenceUUID;
private String measurementUUID;
private Parameter parameter;


public static final Creator<Inputs> CREATOR = new Creator<Inputs>() {
@Override
public Inputs createFromParcel(Parcel in) {
return new Inputs(in);
}

@Override
public Inputs[] newArray(int size) {
return new Inputs[size];
}
};

public String getTestUUID() {
return testUUID;
Expand Down Expand Up @@ -66,14 +79,20 @@ protected Inputs(Parcel in) {
sequenceUUID = in.readString();
measurementUUID = in.readString();
testUUID = in.readString();
parameter = in.readParcelable(Parameter.class.getClassLoader());
}

public Inputs(String campaignUUID, String sequenceUUID, String measurementUUID, String testUUID) {
public Inputs(String campaignUUID, String sequenceUUID, String measurementUUID, String testUUID, Parameter parameter) {
this.timestamp = new Timestamp(System.currentTimeMillis());
this.campaignUUID = campaignUUID;
this.sequenceUUID = sequenceUUID;
this.measurementUUID = measurementUUID;
this.testUUID = testUUID;
this.parameter = parameter;
}

public Parameter getParameter() {
return parameter;
}

@Override
Expand All @@ -88,10 +107,23 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(sequenceUUID);
dest.writeString(measurementUUID);
dest.writeString(testUUID);
dest.writeParcelable(parameter, flags);
}

public Data.Builder getInputAsDataBuilder(int i, String packageName) {
return null;
}

public OneTimeWorkRequest getWorkRequestExecutor(int i, String packageName) {
return null;
}

public OneTimeWorkRequest getWorkRequestLineProtocol(int i, String packageName) {
return null;
}

public OneTimeWorkRequest getWorkRequestUpload(int i, String packageName) {
return null;
}
public abstract Data.Builder getInputAsDataBuilder(int i, String packageName);
public abstract OneTimeWorkRequest getWorkRequestExecutor(int i, String packageName);
public abstract OneTimeWorkRequest getWorkRequestLineProtocol(int i, String packageName);
public abstract OneTimeWorkRequest getWorkRequestUpload(int i, String packageName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Iperf3Input(Iperf3Parameter iperf3Parameter,
String sequenceUUID,
String measurementUUID,
String campaignUUID) {
super(testUUID, sequenceUUID, measurementUUID, campaignUUID);
super(testUUID, sequenceUUID, measurementUUID, campaignUUID, iperf3Parameter);
this.iperf3Parameter = iperf3Parameter;
}

Expand Down Expand Up @@ -101,6 +101,13 @@ public Data.Builder getInputAsDataBuilder(int i, String packageName) {
return data;
}

public Data.Builder getInputAsDataBuilder(int i) {
Data.Builder data = new Data.Builder();
data.putInt(NOTIFICATIONUMBER, i);
data.putString(Inputs.INPUT, new GsonBuilder().create().toJson(this, Iperf3Input.class));
return data;
}

@Override
public OneTimeWorkRequest getWorkRequestExecutor(int i, String packageName) {
return new OneTimeWorkRequest.Builder(Iperf3ExecutorWorker.class)
Expand All @@ -122,7 +129,7 @@ public OneTimeWorkRequest getWorkRequestLineProtocol(int i, String packageName)
.addTag(super.getCampaignUUID())
.addTag(Iperf3ToLineProtocolWorker.TAG)
.addTag(iperf3Parameter.getiPerf3UUID())
.setInputData(getInputAsDataBuilder(i, packageName).build())
.setInputData(getInputAsDataBuilder(i).build())
.build();
}

Expand All @@ -135,7 +142,7 @@ public OneTimeWorkRequest getWorkRequestUpload(int i, String packageName) {
.addTag(super.getCampaignUUID())
.addTag(Iperf3UploadWorker.TAG)
.addTag(iperf3Parameter.getiPerf3UUID())
.setInputData(getInputAsDataBuilder(i, packageName).build())
.setInputData(getInputAsDataBuilder(i).build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.Worker.InfluxDB2xUploadWorker;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Worker.Iperf3ToLineProtocolWorker;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Parameter.PingParameter;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.Worker.PingToLineProtocolWorker;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.Worker.PingWorker;


Expand All @@ -25,7 +26,7 @@ public PingInput(PingParameter pingParameter,
String sequenceUUID,
String measurementUUID,
String campaignUUID) {
super(testUUID, sequenceUUID, measurementUUID, campaignUUID);
super(testUUID, sequenceUUID, measurementUUID, campaignUUID, pingParameter);
this.pingParameter = pingParameter;
}

Expand Down Expand Up @@ -68,12 +69,12 @@ public PingInput[] newArray(int size) {
@Override
public OneTimeWorkRequest getWorkRequestLineProtocol(int i, String packageName) {
// TODO FIX
return new OneTimeWorkRequest.Builder(Iperf3ToLineProtocolWorker.class)
return new OneTimeWorkRequest.Builder(PingToLineProtocolWorker.class)
.addTag(super.getTestUUID())
.addTag(super.getMeasurementUUID())
.addTag(super.getSequenceUUID())
.addTag(super.getCampaignUUID())
.addTag("Ping") // TODO FIX
.addTag(PingToLineProtocolWorker.TAG) // TODO FIX
.setInputData(getInputAsDataBuilder(i, packageName).build())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.common.util.concurrent.ListenableFuture;
import com.google.gson.Gson;

import java.io.File;
import java.util.concurrent.ExecutionException;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Inputs.Iperf3Input;
Expand Down Expand Up @@ -68,7 +69,11 @@ public Iperf3ExecutorWorker(@NonNull Context context, @NonNull WorkerParameters
public ListenableFuture<Result> startRemoteWork() {

return CallbackToFutureAdapter.getFuture(completer -> {

File f = new File(iperf3Input.getIperf3Parameter().getLogfile());
if(f.exists() && !f.isDirectory()) {
//weird hack otherwise the worker gets enqueued two times
return completer.set(Result.success(new Data.Builder().putString("testUUID", iperf3Input.getTestUUID()).build()));
}
Log.i(TAG, "Starting "+TAG);
setForegroundAsync(createForegroundInfo(iperf3Input.getIperf3Parameter().getHost()+":"+iperf3Input.getIperf3Parameter().getPort()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@

package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Worker;

import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE;

import android.app.Notification;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import androidx.work.Data;
import androidx.work.ForegroundInfo;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

Expand All @@ -25,6 +31,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.DeviceInformation;
Expand All @@ -38,32 +45,46 @@
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Streams.TCP.TCP_UL_STREAM;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Streams.UDP.UDP_DL_STREAM;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.R;

public class Iperf3ToLineProtocolWorker extends Worker {
public static final String TAG = "Iperf3ToLineProtocolWorker";
InfluxdbConnection influx;
private final int FOREGROUND_SERVICE_TYPE = FOREGROUND_SERVICE_TYPE_SPECIAL_USE;
private SharedPreferencesGrouper spg;
private Notification notification;
private NotificationCompat.Builder notificationBuilder;

private final DeviceInformation di = GlobalVars.getInstance().get_dp().getDeviceInformation();
private int notificationID;
private Iperf3Input iperf3Input;
public Iperf3ToLineProtocolWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
Gson gson = new Gson();
String iperf3InputString = getInputData().getString(Iperf3Input.INPUT);
iperf3Input = gson.fromJson(iperf3InputString, Iperf3Input.class);
notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), "OMNT_notification_channel");
notificationID = 200+getInputData().getInt(Iperf3Input.NOTIFICATIONUMBER, 0);
spg = SharedPreferencesGrouper.getInstance(getApplicationContext());
setForegroundAsync(createForegroundInfo("Processing iPerf3 data"));
}

private void setup(){
influx = InfluxdbConnections.getRicInstance(getApplicationContext());
private ForegroundInfo createForegroundInfo(String progress) {
notification = notificationBuilder
.setContentTitle("iPerf32LineProtocol")
.setContentText(progress)
.setOngoing(true)
.setOnlyAlertOnce(true)
.setColor(Color.WHITE)
.setSmallIcon(R.mipmap.ic_launcher_foreground)
.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_DEFAULT)
.build();
return new ForegroundInfo(notificationID, notification, FOREGROUND_SERVICE_TYPE);
}



@NonNull
@Override
public Result doWork() {
setup();
Data output = new Data.Builder().putBoolean("iperf3_upload", false).build();

Iperf3Parser iperf3Parser = new Iperf3Parser(iperf3Input.getIperf3Parameter().getLogfile());
Expand All @@ -79,7 +100,8 @@ public Result doWork() {
}

LinkedList<Point> points = new LinkedList<Point>();
for (Interval interval: iperf3Parser.getIntervals().getIntervalArrayList()) {
ArrayList<Interval> intervals = iperf3Parser.getIntervals().getIntervalArrayList();
for (Interval interval: intervals) {
long tmpTimestamp = timestamp + (long) (interval.getSum().getEnd() * 1000);
int intervalIdx = iperf3Parser.getIntervals().getIntervalArrayList().indexOf(interval);
for (Stream stream: interval.getStreams().getStreamArrayList()){
Expand Down Expand Up @@ -151,6 +173,7 @@ public Result doWork() {
point.time(tmpTimestamp, WritePrecision.MS);

points.add(point);
setForegroundAsync(createForegroundInfo("Processing iPerf3 data: "+intervalIdx+"/"+intervals.size()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ private void enqueueWorkRequests(RemoteWorkManager remoteWorkManager,
Log.d(TAG, "enqueueWorkRequests: Enqueueing work Executor requests "+executorRequests.size());
Log.d(TAG, "enqueueWorkRequests: Enqueueing work LineProtocol requests "+lineProtocolRequests.size());
Log.d(TAG, "enqueueWorkRequests: Enqueueing work Upload requests "+uploadRequests.size());
remoteWorkManager.beginUniqueWork("foobar", ExistingWorkPolicy.REPLACE, executorRequests)
remoteWorkManager.beginWith(executorRequests)
.then(lineProtocolRequests)
// .then(uploadRequests)
.then(uploadRequests)
.enqueue();

CustomEventListener listener = new CustomEventListener() {
Expand Down
Loading

0 comments on commit aee5182

Please sign in to comment.