Archive for March 2022
Traveling with Camel in the Java-verse
Sometimes I feel like Alice in Wonderland, you never know what is going to happen and which strange beast I am going to face.
Today’s beast is Camel: I have nothing against it, I barely know what it is, but I have just seen another episode of “I am a bored developer, let me try a new framework. One day it will be useful”
So in Camel you have a RouteBuilder, inside the route a message is delivered to all the Handler registered. There is an xml configuration file where you can define beans with spring
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans classpath:/org/springframework/beans/factory/xml/spring-beans-4.3.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<!-- camelContext is the Camel runtime, where we can host Camel routes -->
<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
<camel:routeBuilder ref="routerBuilder"/>
</camel:camelContext>
<bean id="routerBuilder" class="MyRouteBuilder"/>
<bean id="A" class="AClass"/>
<bean id="B" class="BClass"/>
</beans>
So this create a context, 3 beans and the first one is the route builder. Inside MyRouteBuilder you can
from("timer://simpleTimer?period={{timer}}")
.to("bean:A")
.to("bean:B");
so you can tell that the source event to process is just a timer that is expiring, then the 2 handlers have to be invoked.
Quite overkill to use a framework like Camel to just do periodically a couple of calls. At least this time the beast I faced was not so difficult to understand.
Many thanks to https://www.baeldung.com/apache-camel-intro that always provide good short articles to understand quickly what is going on.
PyTorch Anaconda and root ca certificates
Unfortunately, or fortunately depending from which point you look at the problem, here we have a tool installed on all pc that intercepts and filters all the http and https traffic, the idea is to prevent access to unwanted sites, places where there can be malware, non business related sites…
I still do not understand why I can access facebook from here, but anywhay this kind of tool is problematic when you try to use some developer tools that do something about security.
For instance I am trying to install pytorch, and to do that I need to install anaconda, and once done that I need to download many packages.
Anaconda is good at finding what you need to install, but it detects that there is this “man in the middle” tool that is spying all the traffic. It sees that there is something wrong in the signed certificates that are using with the tls connection.
Only option is to add this tool root certificate authority inside the trusted root certificates authority.
First step is to obtain the root ca certificates in pem format, you must save them as files ending with .crt extension
openssl s_client -showcerts -servername wikipedia.org -connect wikipedia.org:443
It will show the pem fcertificates chain, you need to pick the last one, that is the root certificate.
If you want to see the certificate content you can use
openssl x509 -in pem3.crt -text #where pem3 is the certificate I saved
I followed a tutorial on ubuntu, https://ubuntu.com/server/docs/security-trust-store. For the root user it works perfectly fine, but not for my user
finally with this command
curl-config --ca
I have been able to understand that the location used from curl and anaconda is not the one from the ubuntu os. anaconda must have installed some new version for its purposes and the curl with my account was not working.
So I linked
ln -s /etc/ssl/certs/ca-certificates.crt cacert.pem
inside
$HOME/anaconda3/ssl
and something magic happened, now I can use curl with the man in the middle tool.
Half done – double pain
I am checking some alerts, they should verify some complicated conditions, to test some values decided by a customer. The report names are funcy and do not tell all the story, all the checks that are done. The alert name cannot be changed so its name diverged from what is checked, even for which customer it is set up. Some of the conditions are not even getting data.
Frustration
One colleague at some point has really done a shity job, what should I do now, go to see him and complain? Redo the job for him? Listen to the fact he was in a rush?
The problems with half done stuff, because you are in a rush, are always the sames.
they are half done – so they are not good – you cannot trust them.
If all seems good, you always have a douth, is it really true?
If something is wrong and then was good, it makes you loose time.
So the confidence is lost, and you are sure you will pay again with your time for something not finished.
If still this is something only for yourself, you may maybe leave with it for a while, only you or your team knows.
Much worse if it is somebody outside your team that notices it, your stuff start becoming suspicios and people loose confidence, not just on that part but ultimately on all the stuff your team is doing.
So please, if it is half-done, it is just not-done, no bullshit: the sooner you admit is not done the better it is.
Java constant pool
From time to time I still read the java journal, sometimes the articles you can find are very esotheric.
java class file constant pool, this article explains that class files contains a table with some constants. This is quite normal, I remember is the same in windows executables or in linux binaries, there is always a table containing string constants numeric constants, function names etc.
I never imagined that it was so structured in java, that you have constants referencing classes and methods and these constants are used in the byte code so extensively. So if you have 15 minutes to spend on the articile, you will get some real exoteric knowledge.
IntelliJ editor shortcuts
As lame user I am only using menus and I am using a lot the mouse do to everything.
One good friend has sent me this link, a presentation from a java champion about productivity with intellij. I never imagined there existed such kind of features in an editor, and now I undestand finally why an idee can get so big.
Have a look to https://www.youtube.com/watch?v=cK19rE2V9UY , it will help you a lot
Intellij and multiple projects
I am new to Intellij, I started using it since few days. I see you can start quickly working on a new project and you can have multiple windows for multiple projects. So far so good.
Usually I have one big maven project composed of many submodules, so I was quite happy with this one project one window approach.
Now I changed team and the approach is different here, different repos with different projects, and one references the other. Having one window one project was not nice anymore. I started looking for something similar to eclipse tree.
It is actually easy to do that. You just need to create one empty project. Then you create a new module from existing sources, for each of the project you want to import. And that’s all, you have many projects in the same window.
But this is not fitting to what I need. I realized that clicking on one class brings to decompiled sources and not to the real sources contained in another module… I definitively need to take more time exploring Intellij, and getting used to how it works.
Another day spent reading sources
Yep, you cannot easily keep all the sources in a single repository, and when you have many many of them it is easy to miss the one you need. Repos are usually organized in a pyramidal way, the main project and then inside many repos managed by the team. It is like they are tagged by team and not by purpose.
The pyramidal organization is easy to achieve, has the nice property that each element has just one parent, but you may have multiple concerns. You may want to group toghether project with labels. These repos are for deployment, these repos are for scheduling, these repos are for that project… the concerns may overlap one with another.
This make me think at the switch from tree organized mail into gmail organization where you have labels: at the beginning it is strange but in the end it simplifies the life.
This is definitively a whish I make to Atlassian guys, add labels to repositories, so that you can focus on related things, please do it.
Till then still relaying on the fact similar repo starts a bit with the same way, SPbla SPbli…
Yet another way of doing unit testing
scalatest
easy to read article, you test(“my name”) and define a code block: https://www.scalatest.org/getting_started_with_fun_suite
a bit boring to learn another way of doing test but at least you do not need to define the useless function signature etc.
This seem a more complete description of FunTest, which is function test and not jus Fun; let’s home it is also a bit fun…
kerberos login
It finally happened, after years earing from time to time about kerberos I had to use it, and at least for switching users was super stupid
kinit -k -t /path/tokeys/repo/temp.k who@DOMAIN
ksu newuser -e /bin/bash
then you have to know where the keys file is and somebody has to have done the set-up already, but this is another story