Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AisStore archiver with incoming UDP instead of TCP #1

Open
iBugged opened this issue Dec 13, 2016 · 7 comments
Open

AisStore archiver with incoming UDP instead of TCP #1

iBugged opened this issue Dec 13, 2016 · 7 comments

Comments

@iBugged
Copy link

iBugged commented Dec 13, 2016

Hi there,

We are using the archiver to save AIS data into a Cassandra cluster. To launch the archiver, we are using the following command:

java -jar ais-store-cli-0.4-SNAPSHOT.jar archive src=127.0.0.1:1337

The data is forwarded to our server on UDP port 1337. If we enter the code above, we are receiving the next error:

13:13:59.323 [Thread-2] INFO dk.dma.ais.reader.AisTcpReader - Connecting to source 127.0.0.1:1337
13:13:59.323 [Thread-2] ERROR dk.dma.ais.reader.AisTcpReader - Could not connect to: 127.0.0.1:1337: Connection refused (Connection refused)

The error suggests that the archiver is using a TCP-connection, but we receive our data on UDP (port 1337). Is there any possibility to receive data on UDP instead of TCP?

Kind regards,

@kaspernielsen
Copy link
Contributor

kaspernielsen commented Dec 13, 2016

The source passing is done in this function https://github.com/dma-ais/AisLib/blob/master/ais-lib-communication/src/main/java/dk/dma/ais/reader/AisReaders.java
Line 182-210.

There is a AisUdpReader class that can be used instead of AisTcpReader.
But there is not implemented any kind of functionality for parsing the command line parameters into a UDP reader.

But it should be fairly easy for you to modify that method to instantiate a AisUdpReader instead of a AisTcpReader. And just compile a new jar

@iBugged
Copy link
Author

iBugged commented Dec 13, 2016

So, if I understand you correctly, we have to find that AisReaders.java file and change Tcp to Udp in the lines you have mentioned?

We have cloned the repository and installed it using mvn. That mvn install command provides us the jar that we can execute, correct? The AisReaders.java is not included in the AisStore-repository as far as I know, so how can I change Tcp to Udp before the jar is compiled? I have already installed a Java decompiler, but that doesn't allow me to change the file :(

@kaspernielsen
Copy link
Contributor

No reason to decompile anything.
Just change the line in AIS-LIB compile a new jar.

And build AisStore again.
You need to upgrade the reference in https://github.com/dma-ais/AisStore/blob/master/ais-store-common/pom.xml
to 2.3-SNAPSHOT from 2.2-SNAPSHOT

@iBugged
Copy link
Author

iBugged commented Dec 14, 2016

There is just one thing I do not understand and that is how we edit that AisReaders file. We do not clone the AisLib repo, that is done automatically when we do mvn install in the AisStore repository. Do we have to download AisLib ourself, change the line and then include that in AisStore?

I have never worked with Java before, so this is all new to me. I try to understand and search for things I might need, but I do not have found anything relevant for me.

@kaspernielsen
Copy link
Contributor

kaspernielsen commented Dec 14, 2016

No problem

git clone git@github.com:dma-ais/AisLib.git

replace https://github.com/dma-ais/AisLib/blob/master/ais-lib-communication/src/main/java/dk/dma/ais/reader/AisReaders.java using your favorite editor

cd AisLib
mvn install

Git clone git@github.com:dma-ais/AisStore.git
upgrade reference to Ais Lib in You need to upgrade the reference in https://github.com/dma-ais/AisStore/blob/master/ais-store-common/pom.xml
to 2.3-SNAPSHOT from 2.2-SNAPSHOT
cd AisStore
mvn install

You should have a new executable jar in ais-store-cli/target

@iBugged
Copy link
Author

iBugged commented Dec 15, 2016

Thanks for your reply! We will try to change the AisReaders file so it works with UDP today and I will let you know if it is successfull or not.

I really appreciate your support, I don't think we could fix it by myself!

@iBugged
Copy link
Author

iBugged commented Dec 15, 2016

Alright, we have changed line 182-210 as following:

static AisUdpReader parseSource(String fullSource) {
try (Scanner s = new Scanner(fullSource);) {
s.useDelimiter("\s*=\s*");
if (!s.hasNext()) {
throw new IllegalArgumentException("Source must be of the format src=host:port,host:port, was "
+ fullSource);
}
String src = s.next();
if (!s.hasNext()) {
throw new IllegalArgumentException(
"A list of hostname:ports must follow the source (format src=host:port,host:port), was "
+ fullSource);
}
AisUdpReader r = new AisUdpReader();
try (Scanner s1 = new Scanner(s.next())) {
s1.useDelimiter("\s*,\s*");
if (!s1.hasNext()) {
throw new IllegalArgumentException(
"Source must have at least one host:port (format src=host:port,host:port), was "
+ fullSource);
}
while (s1.hasNext()) {
r.addHostPort(HostAndPort.fromString(s1.next()));
}
}
r.setSourceId(src);
return r;
}
}

After that, we have installed using Maven, mvn install gave the following output (and errors :():

[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] AIS Parent ......................................... SUCCESS [ 0.166 s]
[INFO] AIS Messages ....................................... SUCCESS [ 2.885 s]
[INFO] AIS Communication .................................. FAILURE [ 1.996 s]
[INFO] AIS utils .......................................... SKIPPED
[INFO] AisLib CLI ......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.335 s
[INFO] Finished at: 2016-12-15T15:11:36+01:00
[INFO] Final Memory: 24M/388M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project ais-lib-communication: Compilation failure: Compilation failure:
[ERROR] /root/AisLib/ais-lib-communication/src/main/java/dk/dma/ais/reader/AisReaders.java:[52,41] incompatible types: dk.dma.ais.reader.AisUdpReader cannot be converted to dk.dma.ais.reader.AisTcpReader
[ERROR] /root/AisLib/ais-lib-communication/src/main/java/dk/dma/ais/reader/AisReaders.java:[195,30] no suitable constructor found for AisUdpReader(no arguments)
[ERROR] constructor dk.dma.ais.reader.AisUdpReader.AisUdpReader(int) is not applicable
[ERROR] (actual and formal argument lists differ in length)
[ERROR] constructor dk.dma.ais.reader.AisUdpReader.AisUdpReader(java.lang.String,int) is not applicable
[ERROR] (actual and formal argument lists differ in length)
[ERROR] /root/AisLib/ais-lib-communication/src/main/java/dk/dma/ais/reader/AisReaders.java:[204,22] cannot find symbol
[ERROR] symbol: method addHostPort(com.google.common.net.HostAndPort)
[ERROR] location: variable r of type dk.dma.ais.reader.AisUdpReader
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :ais-lib-communication

Any idea how to fix this or did we miss something really important?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants