As most programmers know, Unit testing is a good practice. You get a quick result if you broke something vital.
And in a simple POJO (Plain Old Java Object) it's not that difficult to make a Unit test, most IDE has JUnit integrated in them.
But what about JavaEE? Now you have a servlet-container, context and persistence to worry about.
There are several solutions for this, the one that I've been focusing on is Arquillian.
Arquillian is a JBoss Community project and development is sponsored by Red Hat, Inc.
http://arquillian.org/
It's a good idé to use Maven with Arquillian. One of the reasons is that you can have different profiles for different servers (glassfish, wildfly, embedded, remote, etc).
My opinions of Maven: http://java-viking.blogspot.com/2014/05/java-ee-maven-and-gradle.html
So Arquillian can simulate JARs or WARs. You can add config-files and classes (or packages).
It can even do persistence.
So i use my Datasource from the server, simulate a War and test it remotely to the server.
The test begins with making a transaction and adding values to the database, I do this with a Facade that Netbeans like to create for JPA Entities.
I've done a test with the findAll-method to see if I get a list with the correct size, and it worked lovely.
So now it's time to test all the important stuff. On my next project I will start with the testing-stuff first now that I know of its capabilities.
So what's next?
Next is to test Arquillian Drone. The Drone-extension is for testing the actual site. So my JSF-sites can actually have automated tests. The newest 2.0.0 (alpha) can even test for mobile.
The Drone can find elements by id and actually do stuff, like login in and testing what the response site is.
So my hours of re-deploying and testing the same thing over and over again feels like a bitter cup of tea right now.
So thats it for now, I have a lot of testing to do. I will also experiment with the managed and embedded server options. But it's always good to have a "remote" server that actually is the same as the release environment,
Comment if you need help with Netbeans, Wildfly and Arquillian, the IDE in the tutorials is Eclipse and uses EclipseLink instead of the Wildfly default (hibernate),
Friday, May 9, 2014
Java EE, Maven and Gradle
So I've been looking a bit at Maven and Gradle.
Gradle is an awesome build tool that have support for the dependencies from maven repositories.
But I have a weak moment, I like the automated stuff in IDEs. And the Gradle-support for Netbeans is not perfect. You can create and open projects, but for a Java EE project, you lose some of the support.
An example is JSF. When you create a normal Web Application in Netbeans, you get automatic support for all the Web technologies it supports. But with Gradle i have to do everything manually.
This is both a good and a bad thing, the good part is to actually learn all the components that are involved, the bad is that it takes time from the coding and frustration while finding the right solution.
Maven, the old and wise, have a different problem. It's problem is that it needs the dependencies declared and downloaded (by maven) while coding.
When you code Java EE against a server, you have the libraries IN the server, the server plugins usually solves this so you don't need to worry about the libraries. They will be provided.
If your using third party libraries, you might need maven? You usually either set the libraries as modules on the server or deploy them separately example Database drivers (JDBC connectors) .
In maven you tell the dependencies to be provided, but you still need them downloaded while coding.
And then comes the kicker, the libraries that the server has, are some times more up to date then those from the maven central repositories!
Even from the same company as the server!
So I'm coding for the Wildfly 8.0 Final, and javax.mail-library isn't in the dependency jboss-javaee-spec. So I had to find it manually and hope that the different version work (1.4.5 in maven, 1.5.1 in wildfly).
So for setting up and starting to code, it's much faster with a IDE and Server-plugin then using Maven.
However!
Maven gives you more structure for different testing and lets face it, many third party libraries are easier to setup via maven. And to automatically do unit-testing in the build face is a plus.
Conclussion:
So I wish that Gradle would be better with Netbeans and I will use Maven for my projects.
Gradle is an awesome build tool that have support for the dependencies from maven repositories.
But I have a weak moment, I like the automated stuff in IDEs. And the Gradle-support for Netbeans is not perfect. You can create and open projects, but for a Java EE project, you lose some of the support.
An example is JSF. When you create a normal Web Application in Netbeans, you get automatic support for all the Web technologies it supports. But with Gradle i have to do everything manually.
This is both a good and a bad thing, the good part is to actually learn all the components that are involved, the bad is that it takes time from the coding and frustration while finding the right solution.
Maven, the old and wise, have a different problem. It's problem is that it needs the dependencies declared and downloaded (by maven) while coding.
When you code Java EE against a server, you have the libraries IN the server, the server plugins usually solves this so you don't need to worry about the libraries. They will be provided.
If your using third party libraries, you might need maven? You usually either set the libraries as modules on the server or deploy them separately example Database drivers (JDBC connectors) .
In maven you tell the dependencies to be provided, but you still need them downloaded while coding.
And then comes the kicker, the libraries that the server has, are some times more up to date then those from the maven central repositories!
Even from the same company as the server!
So I'm coding for the Wildfly 8.0 Final, and javax.mail-library isn't in the dependency jboss-javaee-spec. So I had to find it manually and hope that the different version work (1.4.5 in maven, 1.5.1 in wildfly).
So for setting up and starting to code, it's much faster with a IDE and Server-plugin then using Maven.
However!
Maven gives you more structure for different testing and lets face it, many third party libraries are easier to setup via maven. And to automatically do unit-testing in the build face is a plus.
Conclussion:
So I wish that Gradle would be better with Netbeans and I will use Maven for my projects.
Saturday, May 3, 2014
JSF 2.2 FileUpload and a way to get it back
So my Web app needed to be able to upload images for users, "connect" the user and the image and to be able to actually show the image.
Some may want to save the image in the database, this can be done with the BLOB-type. you then have to get the input stream and read it as bytes.
Pros:
All in one place, handled by the DBMS.
Cons:
Database takes much more space
Harder to export all the data for backup-solutions
So what do we do then?
We can save it on the hard drive as regular files. A risk is if the file contains a virus.
How we actually save this is rather easy. The Part-class has a "write"-method which you either can give a relative path or a absolute path. The relative path may put it in the web-applications tmp-folder, it's really the server who controls where its put.
The absolute path makes it easy to do backup scripts to make backups. The big problem is how to reach the files from the web app.
The one I have focused on is Wildfly (JBoss Application Server 8).
It was a bit tricky to find the right answer.
But in the config file for your server (domain.conf or one of the standalone confs) there is a subsystem for undertow. Undertow is the new servlet container for JBoss.
In that subsystem there is two parts that's interesting for us right now: Host and Handlers.
In the Handlers part we add
<file name="images-handler" path="your/path/to/save"/>
you can use your servers path-variables
and in the Host part
<location name="/images" handler="images-handler"/>
The handler takes care of where the folder will be retrieved from (read from) and the Host will controll how the web-app will reference it.
In this case you reach it by http://serveradress:port/images
So <graphicImage> gets problems due to it being relative to the web-app.
A simple <img> works great thou.
So either find a way to map it better or use a regular <img>
So that's it for the simple fileUpload of images, especially with Wildfly.
Code ahoy!
Upload:
So JSF 2.2 has a really simple way of doing this. You just put <h:inputFile /> and connect this to a Bean. The type should be "Part" (javax.servlet.http.Part). But to remember is that the <h:form> needs too add enctype="multipart/form-data" as an attribute, <h:form enctype="multipart/form-data">.Connect:
So now we have a Part in the Bean, but how to save it and where?Some may want to save the image in the database, this can be done with the BLOB-type. you then have to get the input stream and read it as bytes.
Pros:
All in one place, handled by the DBMS.
Cons:
Database takes much more space
Harder to export all the data for backup-solutions
So what do we do then?
We can save it on the hard drive as regular files. A risk is if the file contains a virus.
How we actually save this is rather easy. The Part-class has a "write"-method which you either can give a relative path or a absolute path. The relative path may put it in the web-applications tmp-folder, it's really the server who controls where its put.
The absolute path makes it easy to do backup scripts to make backups. The big problem is how to reach the files from the web app.
Path:
How to reach files from "above" the web-apps folder is different for the servers. Glassfish has Virtual host/server. Some has context-properties.The one I have focused on is Wildfly (JBoss Application Server 8).
It was a bit tricky to find the right answer.
But in the config file for your server (domain.conf or one of the standalone confs) there is a subsystem for undertow. Undertow is the new servlet container for JBoss.
In that subsystem there is two parts that's interesting for us right now: Host and Handlers.
In the Handlers part we add
<file name="images-handler" path="your/path/to/save"/>
you can use your servers path-variables
and in the Host part
<location name="/images" handler="images-handler"/>
The handler takes care of where the folder will be retrieved from (read from) and the Host will controll how the web-app will reference it.
In this case you reach it by http://serveradress:port/images
Display:
Now comes the last tricky part. The images-folder is reachable now BUT is reachable by the server-adress WITHOUT the web-apps adress on top of it. You can probably map it to be reachable.So <graphicImage> gets problems due to it being relative to the web-app.
A simple <img> works great thou.
So either find a way to map it better or use a regular <img>
So that's it for the simple fileUpload of images, especially with Wildfly.
Code ahoy!
Monday, April 14, 2014
JPA: Hibernate Implementation "lazily initialize a collection"
Today I have struggled half a day with a frustrating problem.
I have a ManyToMany-relationship (JPA) with two Entities. Shop and Brand, it's also bidirectional.
Hibernate and Spring-veterans sees where I'm going with this...
If I want to get a Object of Shop from the database, everythings simple. But if I want to get the attribute that's the "ManyToMany" (in this case "Brand") I would get it as a form of Collection.
But here's the kicker: Hibernate has a lazy initialization of these kinds of collections. This is for saving a lot of data loading for every time you get a Shop-object from the database.
I wanted to have a JSF-form with my data and the possibility to update it (specifically the Brands). I wanted to use the selectManyCheckBox component in JSF.
So the Hell began here.
The specific exception I got was (I also got the role-error earlier):
javax.servlet.ServletException: failed to lazily initialize a collection, could not initialize proxy - no Session
You can set the annotation of the ManyToMany to suggest "EARLY" so that it loads all the collection-data with the regular.
And that solution didn't solve my problems. It feels like I almost tried every solution known to man to solve this problem. I did beans that sole purpose was to get the Brands as a list from the Shop and try to merge it with the data in the form and the update-bean.
Of course I tried to google solutions. 95% of the links led me to thinking it was the classic lazy-problem that the Hibernate-session closed before I got my collection data.
But something wasn't right. Because I actually got the data to show in the form correctly quite early. It was the update that caused the problem.
The update was a bean that held the data from the JSF-component, they were connected.
But why did a lazy-error show when it wasn't supposed to load the data but actually update it?
I tried View filter (Open View in Session-pattern), I tried Stateful beans with EXTEND persistance unit.
After half a day I stumble to Hatim Alimam's blog were he had the same problem (but with Primeface implementation).
http://blog.hatemalimam.com/hibernate-lazyinitializationexception-and-pselectcheckboxmenu/
It was a little <f:attribute> that was needed!
If I just put <f:attribute name="collectionType" value="java.util.ArrayList" /> in the <f:selectManyCheckBox> Everything worked!
So it wasn't really the classic Lazy-problem, but with that Exception-message, one might think so...
So I hope anyone that has the same problem I had either stumble to this blog or Hatim's.
Cheers!
I have a ManyToMany-relationship (JPA) with two Entities. Shop and Brand, it's also bidirectional.
Hibernate and Spring-veterans sees where I'm going with this...
If I want to get a Object of Shop from the database, everythings simple. But if I want to get the attribute that's the "ManyToMany" (in this case "Brand") I would get it as a form of Collection.
But here's the kicker: Hibernate has a lazy initialization of these kinds of collections. This is for saving a lot of data loading for every time you get a Shop-object from the database.
I wanted to have a JSF-form with my data and the possibility to update it (specifically the Brands). I wanted to use the selectManyCheckBox component in JSF.
So the Hell began here.
The specific exception I got was (I also got the role-error earlier):
javax.servlet.ServletException: failed to lazily initialize a collection, could not initialize proxy - no Session
You can set the annotation of the ManyToMany to suggest "EARLY" so that it loads all the collection-data with the regular.
And that solution didn't solve my problems. It feels like I almost tried every solution known to man to solve this problem. I did beans that sole purpose was to get the Brands as a list from the Shop and try to merge it with the data in the form and the update-bean.
Of course I tried to google solutions. 95% of the links led me to thinking it was the classic lazy-problem that the Hibernate-session closed before I got my collection data.
But something wasn't right. Because I actually got the data to show in the form correctly quite early. It was the update that caused the problem.
The update was a bean that held the data from the JSF-component, they were connected.
But why did a lazy-error show when it wasn't supposed to load the data but actually update it?
I tried View filter (Open View in Session-pattern), I tried Stateful beans with EXTEND persistance unit.
After half a day I stumble to Hatim Alimam's blog were he had the same problem (but with Primeface implementation).
http://blog.hatemalimam.com/hibernate-lazyinitializationexception-and-pselectcheckboxmenu/
It was a little <f:attribute> that was needed!
If I just put <f:attribute name="collectionType" value="java.util.ArrayList" /> in the <f:selectManyCheckBox> Everything worked!
So it wasn't really the classic Lazy-problem, but with that Exception-message, one might think so...
So I hope anyone that has the same problem I had either stumble to this blog or Hatim's.
Cheers!
Sunday, April 13, 2014
Wildfly Injection and JPA: troublesome
So I've been making a Webapplication with classic CRUD via JPA. The database is also used for login-functions. I use JSF with Facelets for View.
JSF can manage beans easily e.g (value="#{myBean.value}")
So I thought that the Bean could be a @Entity. I even have a book that use it like that.
I then Inject the bean in my Facade (a DAO) that should persist it.
I checked so that it had the values that I gave from the View (JSF-form).
But here's the kicker!
I get "java.lang.IllegalArgumentException: Unknown entity: myclass#$Proxy$_$$_WeldClientProxy".
I tried of writing the classes manually in the persistance.xml without any luck.
After a lot of digging, I learned that the Bean that Weld injects (I use Wildfly-server that uses Weld) you doesn't actually get a real instance of your bean. You get a Proxy. So I could get the values, but it was not seen as an Entity.
I confirmed this by making a manual instance of the bean and persisting it with the same Facade-code.
The only difference was the Injection.
So my solution was to make a controller bean which had a manually created field of the bean. And use that bean e.g (value="controllerBean.myBean.value")
The controller bean then used the Facade for persistance.
This solution works for me, the controller bean can then do some validation and more.
Fine and dandy!
JSF can manage beans easily e.g (value="#{myBean.value}")
So I thought that the Bean could be a @Entity. I even have a book that use it like that.
I then Inject the bean in my Facade (a DAO) that should persist it.
I checked so that it had the values that I gave from the View (JSF-form).
But here's the kicker!
I get "java.lang.IllegalArgumentException: Unknown entity: myclass#$Proxy$_$$_WeldClientProxy".
I tried of writing the classes manually in the persistance.xml without any luck.
After a lot of digging, I learned that the Bean that Weld injects (I use Wildfly-server that uses Weld) you doesn't actually get a real instance of your bean. You get a Proxy. So I could get the values, but it was not seen as an Entity.
I confirmed this by making a manual instance of the bean and persisting it with the same Facade-code.
The only difference was the Injection.
So my solution was to make a controller bean which had a manually created field of the bean. And use that bean e.g (value="controllerBean.myBean.value")
The controller bean then used the Facade for persistance.
This solution works for me, the controller bean can then do some validation and more.
Fine and dandy!
Sunday, April 6, 2014
Wildfly, Impressions and configs
I'm using the Wildfly Java server for my current projects. I have a little Raspberry cluster of them even (I'm going to update the post how to set them up).
So how do I feel about Wildfly?
It's more configuration then programming! But after some talking to developer-friends, that's actually much of Java EE in the beginning.
So the latest part of the project was to make a Login-function. I've made a simple function like this in PHP. So I thought "what the hell".
After some research I found that Java EE hade it built in the servlet (you can even hide it in a simple html-form if you name the components just right).
So I tried to make a "customized" login which would use a form rendered by JSF and sent the values to a JavaBean which would use the servlet-login method.
Sounds easy? Yeah, that was my weekend...
By using built in functions, you got to know all the magic that actually happens, which isn't the same for every Java server, but at least similar.
First you have to choose if your going to save the users in a file, database or LDAP.
You then need to setup the security-domain to use the right options. For me, I needed to use databases,
That meant to connect it to the right JNDI (Datasource for the Database) and this was actually the last piece of the puzzle to fall into place. Many sites write a JNDI that seems to differ from the regular, but nothing is different! Just use the regular JNDI.
For database-solution you need to save the users (passwords and all) and the different roles they have in the database. You then set the queries for users and there passwords in the same security-domain.
For Wildfly you then need to create/edit the jboss-web.xml file to set it to use this security-domain (the one you configured).
You can also set the encryption and hash-algorithm for the password in the security-domain.
Then comes the web.xml configuring. At least this is the same for the most servers.
Here you get to set which options and which pages will and role will demand login and which site is the login-site and an error-site for getting the error-message (can have different for different errors).
I haven't puzzeled together all the pieces and don't really know all the requirements yet, but hopefully I will puzzle it out soon.
Hopefully this is one of the bigger obstacles I will face for my little project.
Impressions of Wildfly so far:
Fast and has many options (standalone, standalone-full, domain, etc).
Neat admin-console, and a good CLI-console.
Bad error-messages from admin-page (unknown error) is a regular occurence.
New server so it doesn't have many sources with examples yet,
Lots of configurations that needs to be done, some which you can't do from the Admin-page.
So how do I feel about Wildfly?
It's more configuration then programming! But after some talking to developer-friends, that's actually much of Java EE in the beginning.
So the latest part of the project was to make a Login-function. I've made a simple function like this in PHP. So I thought "what the hell".
After some research I found that Java EE hade it built in the servlet (you can even hide it in a simple html-form if you name the components just right).
So I tried to make a "customized" login which would use a form rendered by JSF and sent the values to a JavaBean which would use the servlet-login method.
Sounds easy? Yeah, that was my weekend...
By using built in functions, you got to know all the magic that actually happens, which isn't the same for every Java server, but at least similar.
First you have to choose if your going to save the users in a file, database or LDAP.
You then need to setup the security-domain to use the right options. For me, I needed to use databases,
That meant to connect it to the right JNDI (Datasource for the Database) and this was actually the last piece of the puzzle to fall into place. Many sites write a JNDI that seems to differ from the regular, but nothing is different! Just use the regular JNDI.
For database-solution you need to save the users (passwords and all) and the different roles they have in the database. You then set the queries for users and there passwords in the same security-domain.
For Wildfly you then need to create/edit the jboss-web.xml file to set it to use this security-domain (the one you configured).
You can also set the encryption and hash-algorithm for the password in the security-domain.
Then comes the web.xml configuring. At least this is the same for the most servers.
Here you get to set which options and which pages will and role will demand login and which site is the login-site and an error-site for getting the error-message (can have different for different errors).
I haven't puzzeled together all the pieces and don't really know all the requirements yet, but hopefully I will puzzle it out soon.
Hopefully this is one of the bigger obstacles I will face for my little project.
Impressions of Wildfly so far:
Fast and has many options (standalone, standalone-full, domain, etc).
Neat admin-console, and a good CLI-console.
Bad error-messages from admin-page (unknown error) is a regular occurence.
New server so it doesn't have many sources with examples yet,
Lots of configurations that needs to be done, some which you can't do from the Admin-page.
Thursday, March 27, 2014
Java-Cluster: Wildfly and User Configuration
Now for the Tricky parts:
First lets add a user to the raspberry for the Wildfly (we don't need to make it a sudo (administrator) user).
"sudo useradd -c "JBoss AS User" -s /bin/bash -d /home/jboss -mr jboss"
The users name is "jboss".We should then give ownership of the wildfly folder to this user
"sudo chown -R jboss:jboss /usr/jboss/wildfly-8.0.0.Final"
It's also a good idea to give the user a password:
"sudo passwd jboss"
Now lets switch to that user:
"sudo su - jboss"
First of all we need to change the memory usage of the Wildfly-server. Per default it uses a maximum of 512mb (which is ALL of the memory the Raspberry Pi has! And we need some memory for other stuff).
So edit the file /usr/jboss/wildfly-8.0.0.Final/bin/domain.conf, I usually use nano for editing (you can use vi or something else if you prefer it)
"nano /usr/jboss/wildfly-8.0.0.Final/bin/domain.conf"
Somewhere in the file there is a line "-Xms64m -Xmx512m -XX:MaxPermSize=256m"
change this to:
"-Xms64m -Xmx196m -XX:MaxPermSize=256m"
Exit nano using CTRL + X and choosing "y" to save the changes.
Now we can try to start the server, go in to the Wildfly bin-folder and run:
"./domain.sh"
It may show some red text but wait and see if it starts.
Do these steps for all the Raspberry Pi's that should be part of the Java-Cluster.
Now it's time to choose a Master. One of the Raspberries have to be the Master, the rest will be "slaves".
Ssh into the master
In the Master we will now create som Wildfly users. In the Wildfly bin-folder of the master:
./adduser.sh
Pick a Username (like "master") and a password
Choose the Management option
The Master-user don't need a secret value (the last question the scripts asks)
Now add a user for every slave (In the Master). Give them individual names, choose Management option and answer yes to the last question.
Copy the value to a file with the user names. Example:
master
slave01 <secret value="THE VALUE IT GETS" />
slave02 <secret value="THE VALUE IT GETS" />
Now lets config The Master: edit the file host.xml in the domain/configuration folder:
change:
<interfaces>
<interface name="management">
<inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:127.0.0.1}"/>
</interface>
<interface name="unsecured">
<inet-address value="127.0.0.1" />
</interface>
</interfaces>
To: where Masters IP should be the IP of the master
<interfaces>
<interface name="management"
<inet-address value="${jboss.bind.address.management:Masters IP}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:Masters IP}"/>
</interface>
<interface name="unsecured">
<inet-address value="Masters IP" />
</interface>
</interfaces>
That's it for the Master!
Now the steps that needs to be made for every slave:
Ssh into the slave
Edit the host.xml in domain/configurations of the wildfly-folder
change:
<host name="master" xmlns="urn:jboss:domain:1.1">
to:
<host name="slave01" xmlns="urn:jboss:domain:1.1">
where slave01 is the name of the management-user created in the host for this slave
Then we need to modify domain-controller section so slave can connect to master's management port (in the same file):
Change it to:
<domain-controller>
<remote host="Masters IP!!!" port="9999" security-realm="ManagementRealm"/>
</domain-controller>
Change the interface part to:
<interfaces>
<interface name="management">
<inet-address value="${jboss.bind.address.management:SLAVE IP!!!!}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:SLAVE IP!!!!}"/>
</interface>
<interface name="unsecured">
<inet-address value="SLAVE IP!!!!" />
</interface>
</interfaces>
Chane security-realm part: Chane the value of secret to that you got from creating users in Master.
comment out <local default...
<security-realms>
<security-realm name="ManagementRealm">
<server-identities>
<secret value="THE SECRET VALUE of SLAVE"/>
</server-identities>
<authentication>
<properties path="mgmt-users.properties" relative-to="jboss.domain.config.dir"/>
</authentication>
</security-realm>
</security-realms>
Now repeat for every slave.
Now test to start the master with ./domain.sh
When its started, try to start the slaves the same way.
Check the information on master, if it registers the slaves then it works!
In the next part I will discuss my results of trying a simple web-project and deploying it.
Code ahoy!
First lets add a user to the raspberry for the Wildfly (we don't need to make it a sudo (administrator) user).
"sudo useradd -c "JBoss AS User" -s /bin/bash -d /home/jboss -mr jboss"
The users name is "jboss".We should then give ownership of the wildfly folder to this user
"sudo chown -R jboss:jboss /usr/jboss/wildfly-8.0.0.Final"
It's also a good idea to give the user a password:
"sudo passwd jboss"
Now lets switch to that user:
"sudo su - jboss"
First of all we need to change the memory usage of the Wildfly-server. Per default it uses a maximum of 512mb (which is ALL of the memory the Raspberry Pi has! And we need some memory for other stuff).
So edit the file /usr/jboss/wildfly-8.0.0.Final/bin/domain.conf, I usually use nano for editing (you can use vi or something else if you prefer it)
"nano /usr/jboss/wildfly-8.0.0.Final/bin/domain.conf"
Somewhere in the file there is a line "-Xms64m -Xmx512m -XX:MaxPermSize=256m"
change this to:
"-Xms64m -Xmx196m -XX:MaxPermSize=256m"
Exit nano using CTRL + X and choosing "y" to save the changes.
Now we can try to start the server, go in to the Wildfly bin-folder and run:
"./domain.sh"
It may show some red text but wait and see if it starts.
Do these steps for all the Raspberry Pi's that should be part of the Java-Cluster.
Now it's time to choose a Master. One of the Raspberries have to be the Master, the rest will be "slaves".
Ssh into the master
In the Master we will now create som Wildfly users. In the Wildfly bin-folder of the master:
./adduser.sh
Pick a Username (like "master") and a password
Choose the Management option
The Master-user don't need a secret value (the last question the scripts asks)
Now add a user for every slave (In the Master). Give them individual names, choose Management option and answer yes to the last question.
Copy the value to a file with the user names. Example:
master
slave01 <secret value="THE VALUE IT GETS" />
slave02 <secret value="THE VALUE IT GETS" />
Now lets config The Master: edit the file host.xml in the domain/configuration folder:
change:
<interfaces>
<interface name="management">
<inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:127.0.0.1}"/>
</interface>
<interface name="unsecured">
<inet-address value="127.0.0.1" />
</interface>
</interfaces>
To: where Masters IP should be the IP of the master
<interfaces>
<interface name="management"
<inet-address value="${jboss.bind.address.management:Masters IP}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:Masters IP}"/>
</interface>
<interface name="unsecured">
<inet-address value="Masters IP" />
</interface>
</interfaces>
That's it for the Master!
Now the steps that needs to be made for every slave:
Ssh into the slave
Edit the host.xml in domain/configurations of the wildfly-folder
change:
<host name="master" xmlns="urn:jboss:domain:1.1">
to:
<host name="slave01" xmlns="urn:jboss:domain:1.1">
where slave01 is the name of the management-user created in the host for this slave
Then we need to modify domain-controller section so slave can connect to master's management port (in the same file):
Change it to:
<domain-controller>
<remote host="Masters IP!!!" port="9999" security-realm="ManagementRealm"/>
</domain-controller>
Change the interface part to:
<interfaces>
<interface name="management">
<inet-address value="${jboss.bind.address.management:SLAVE IP!!!!}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:SLAVE IP!!!!}"/>
</interface>
<interface name="unsecured">
<inet-address value="SLAVE IP!!!!" />
</interface>
</interfaces>
Chane security-realm part: Chane the value of secret to that you got from creating users in Master.
comment out <local default...
<security-realms>
<security-realm name="ManagementRealm">
<server-identities>
<secret value="THE SECRET VALUE of SLAVE"/>
</server-identities>
<authentication>
<properties path="mgmt-users.properties" relative-to="jboss.domain.config.dir"/>
</authentication>
</security-realm>
</security-realms>
Now repeat for every slave.
Now test to start the master with ./domain.sh
When its started, try to start the slaves the same way.
Check the information on master, if it registers the slaves then it works!
In the next part I will discuss my results of trying a simple web-project and deploying it.
Code ahoy!
Subscribe to:
Posts (Atom)