Skip to content

Commit eeb14e1

Browse files
author
Maxim Moinat
committed
Jar compile and command line arguments
1 parent 385361a commit eeb14e1

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

Readme.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1+
To be run with:
12
```
2-
scp src/main/org.radarcns.restructureAvroSensorTopics.java [email protected]:/home/maxim/hadoop-test/
3-
4-
javac -classpath "/opt/hadoop/share/hadoop/common/hadoop-common-2.7.1.jar:/opt/hadoop/share/hadoop/avro-tools/avro-tools-1.7.7.jar" -d wordcount_classes org.radarcns.restructureAvroSensorTopics.java
5-
6-
7-
jar -cvf restructureAvroSensorTopics.jar -C wordcount_classes/ .
8-
9-
hadoop jar restructureAvroSensorTopics.jar org.radarcns.org.radarcns.restructureAvroSensorTopics
3+
hadoop jar restructurehdfs-all-0.1.0.jar webhdfs://radar-test.thehyve.net:50070 /topicAndroidPhoneNew/ output2
104
```

build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ group 'org.radarcns.restructurehdfs'
22
version '1.0-SNAPSHOT'
33

44
apply plugin: 'java'
5+
version = '0.1.0'
56

67
sourceCompatibility = 1.8
78

@@ -16,4 +17,16 @@ dependencies {
1617
compile 'org.apache.avro:avro:1.7.7'
1718
compile 'org.apache.avro:avro-mapred:1.7.7'
1819
compile 'com.fasterxml.jackson.core:jackson-core:2.8.7'
20+
}
21+
22+
//create a single Jar with all dependencies
23+
task fatJar(type: Jar) {
24+
manifest {
25+
attributes 'Implementation-Title': 'Gradle Jar File Example',
26+
'Implementation-Version': version,
27+
'Main-Class': 'org.radarcns.restructureAvroRecords'
28+
}
29+
baseName = project.name + '-all'
30+
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
31+
with jar
1932
}

src/main/java/org/radarcns/restructureAvroSensorTopics.java renamed to src/main/java/org/radarcns/restructureAvroRecords.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.text.SimpleDateFormat;
1717
import java.util.*;
1818

19-
public class restructureAvroSensorTopics {
19+
public class restructureAvroRecords {
2020

2121
String outputPath = ".";
2222
String OUTPUT_FILE_EXTENSION = "json";
@@ -25,16 +25,15 @@ public class restructureAvroSensorTopics {
2525
SimpleDateFormat dateFormatFileName = new SimpleDateFormat("yyyyMMdd_HH");
2626

2727
public static void main(String [] args) throws Exception {
28-
System.out.println("Started!");
2928

30-
restructureAvroSensorTopics res = new restructureAvroSensorTopics();
31-
res.setInputWebHdfsURL("webhdfs://radar-test.thehyve.net:50070");
32-
res.setOutputPath("output3/");
29+
restructureAvroRecords restr = new restructureAvroRecords();
30+
restr.setInputWebHdfsURL(args[0]); //"webhdfs://radar-test.thehyve.net:50070");
31+
restr.setOutputPath(args[2]); //"output3/");
3332

34-
res.start("/topicAndroidPhoneNew/");
35-
// restructureAvroSensorTopics.processTopic("/topicE4/android_empatica_e4_inter_beat_interval/partition=0/");
36-
// restructureAvroSensorTopics.processAvroFile(new Path("/topicE4/android_empatica_e4_inter_beat_interval/partition=0/android_empatica_e4_inter_beat_interval+0+0000031485+0000031488.avro") );
37-
// restructureAvroSensorTopics.processAvroFile(new Path("/testE4Time/android_phone_acceleration/partition=0/android_phone_acceleration+0+0000590000+0000599999.avro"),"wazaa" );
33+
restr.start(args[1]); //"/topicAndroidPhoneNew/");
34+
// restructureAvroRecords.processTopic("/topicE4/android_empatica_e4_inter_beat_interval/partition=0/");
35+
// restructureAvroRecords.processAvroFile(new Path("/topicE4/android_empatica_e4_inter_beat_interval/partition=0/android_empatica_e4_inter_beat_interval+0+0000031485+0000031488.avro") );
36+
// restructureAvroRecords.processAvroFile(new Path("/testE4Time/android_phone_acceleration/partition=0/android_phone_acceleration+0+0000590000+0000599999.avro"),"wazaa" );
3837
}
3938

4039
public void setInputWebHdfsURL(String fileSystemURL) {
@@ -74,18 +73,13 @@ public void processTopic(Path topicPath) throws IOException {
7473

7574
String topicName = topicPath.getName();
7675

77-
int fileCounter = 0;
7876
while (files.hasNext()) {
7977
LocatedFileStatus locatedFileStatus = files.next();
8078

8179
System.out.println(locatedFileStatus.getPath());
8280

8381
if (locatedFileStatus.isFile())
8482
this.processAvroFile( locatedFileStatus.getPath(), topicName );
85-
fileCounter += 1;
86-
87-
if (fileCounter > 1)
88-
continue;
8983
}
9084
}
9185

@@ -119,7 +113,7 @@ public void writeRecord(GenericRecord record, String topicName) throws IOExcepti
119113
GenericRecord valueField = (GenericRecord) record.get("valueField");
120114

121115
// Make a timestamped filename YYYYMMDD_HH00.json
122-
String outputFileName = this.createFilepathFromTimestamp( (Double) valueField.get("time"));
116+
String outputFileName = this.createFilePathFromTimestamp( (Double) valueField.get("time"));
123117

124118
// Clean user id and create final output pathname
125119
String userId = keyField.get("userId").toString().replaceAll("\\W+", "");
@@ -130,7 +124,7 @@ public void writeRecord(GenericRecord record, String topicName) throws IOExcepti
130124
this.appendToFile(dirName, outputFileName, data);
131125
}
132126

133-
public String createFilepathFromTimestamp(Double time) {
127+
public String createFilePathFromTimestamp(Double time) {
134128
// Send all output to the Appendable object sb
135129
StringBuilder sb = new StringBuilder();
136130
Formatter formatter = new Formatter(sb, Locale.US);

0 commit comments

Comments
 (0)