Installing Worklight Server CE and deploying the SWAMI app - Page 5


4) Create a sample Project in Worklight Studio (Eclipse)

Open up Eclipse (I'm assuming that you already have Android SDK, Worklight Developer installed, as explained in a previous article)

Create a Worklight project (File > New > Worklight Project).
Assign the name 'simpleProject', and accept the default project template 'Hybrid Application'.
In the next panel, name the application 'simpleApp', and then click Finish.
Build the application.

Open the apps folder, right-click the subfolder 'simpleApp', and then
click Run As > Run on Worklight Development Server.

In the Project Explorer view, open the bin folder that was created by this task.
Right-click 'simpleProject.war' and click Properties.
The properties show the path to the WAR file.
This path is used in the next step when we Deploy the WAR to the Worklight Server.

We will repeat this same exercise later on when we do the same thing for the 'SWAMI' app - we'll locate the 'MIR.war' file and upload that to the Worklight Server.  I just wanted to follow the PDF instructions and use a sample Project, just in-case anything went wrong  :-)


Now, switching back to the 'Server Configuration Tool', select 'File/Add Worklight Runtime Environment'.  In the dialog box that pops up, select the 'Hello Worklight Server' that we created earlier.
For the new runtime, let's call it 'First Runtime' (again when we repeat this later we'll call this 'MIR').
In the 'General' panel, load the .war file that is at the location we noted ealier on.
Repeat the same as we did earlier for the 'Database Properties' panel.
Again, we just need to press the [Deploy] button and we'll see the ANT scripts executing at the bottom of the screen.

I chose to restart everything at this point.

>server stop simpleServer

>server start simpleServer

Wait for this to finish before doing the next part.  The PDF says to double-click the worklight-console.url.  I don't know what I missed, but I didn't have this, so to achieve the samething manually, you just need to open a web browser and navigate to:
http://localhost:9080/worklightconsole

You'll be presented with a login screen, enter demo/demo.


Initially I had the message that 'No Runtime Environments were available' displayed on the screen.  I found a reboot of the Windows laptop sorted this out.  By doing this, I actually bypassed what the real issue was.  Was it, the MySQL, WLP, Worklight Server that needed recycling? I could have diagnosed it better, but I went with the lazy option.  Well, it was almost midnight when I was doing this step :-D


Click the [Choose File] button and locate the .wlapp file from the simpleApp project from the Eclipse environment.  Then press the [Submit] button to Deploy the application to the Worklight Server.  You will now see that the application has been deployed.



If you click on the 'Preview as Common Resources' link this actually opens up the mobile web application itself.  Our sample app only displayed a simple text message, we can make sure that it is running okay by clicking on the link.



Excellent!  Okay, we've now proven that this process works okay.  Now let's repeat the same exercise, this time adding the 'MIR' application.  The common .wlapp, the android .wlapp and the .adapter need to be uploaded.

So, I was able to upload the .adapter with no problem.  Although I did notice that I had a hard-coded IP Address inside the Adapter!  This will need to be changed.



I then attempted to upload the android .wlapp (that is 6.2Mb).  Now, I did notice all of the alerting messages that got thrown up earlier telling me that MySQL has a 4Mb limit for the maximum allowed network packet.
So, I opened up the MySQL Workbench, selected the 'Options File' and the 'Networking' tab.
The max_allowed_packet was set to '4M'.  I changed this to '16M' and 'Applied' the change.
In fact, I think I also restarted the service too.  what I also noticed was that, as I had created 2 users, root and worklight, I had to repeat the exercise for both of the users.



I then went through the exercise of attempting to upload the android .wlapp and it just kept going until either a) I got bored or b) I received a session timeout c) I realised that it was nearly 1am on a school night!  I decided to come back to this the following day.

I checked the messages.log file and there was an exception that was being thrown in the background.
-----------------------------------------
Caused by: <openjpa-1.2.2-r422266:898935 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored inline. {prepstmnt 911984531 INSERT INTO APPLICATIONS_ENVIRONMENTS (AUTHENTICITY_CHECK_RULE, CACHED_DEP_DATA, DEPLOY_TIME, ENVIRONMENT, DEPLOYABLE_RESOURCE, RESOURCE_HASH, VERSION, VERSION_LOCKED, APPLICATION_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(String) ENABLED, (InputStream) java.io.ByteArrayInputStream@7286b721, (Timestamp) 2014-09-03 10:02:50.886, (String) android, (InputStream) java.io.ByteArrayInputStream@af664ec, (String) 6702930e2cc03ee6691f5782f375df806c803d75, (String) 1.0, (int) 0, (long) 3]} [code=1118, state=42000]
FailedObject: com.ibm.worklight.dataaccess.jpa.entity.ApplicationEnvironmentEntity@6d849d1b
at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4246)
at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4211)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:102)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:72)
at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:131)
at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:82)
at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:89)
at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:72)
at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:543)
at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:105)
at org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:721)
at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
... 13 more
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored inline. {prepstmnt 911984531 INSERT INTO APPLICATIONS_ENVIRONMENTS (AUTHENTICITY_CHECK_RULE, CACHED_DEP_DATA, DEPLOY_TIME, ENVIRONMENT, DEPLOYABLE_RESOURCE, RESOURCE_HASH, VERSION, VERSION_LOCKED, APPLICATION_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(String) ENABLED, (InputStream) java.io.ByteArrayInputStream@7286b721, (Timestamp) 2014-09-03 10:02:50.886, (String) android, (InputStream) java.io.ByteArrayInputStream@af664ec, (String) 6702930e2cc03ee6691f5782f375df806c803d75, (String) 1.0, (int) 0, (long) 3]} [code=1118, state=42000]
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:192)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:57)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:866)
at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:269)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1590)
at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.executeUpdate(PreparedStatementManagerImpl.java:151)
at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:120)
... 23 more
-----------------------------------------

To cut a long story short, I found an article that provided me with a solution.




So, I changed the innodb_log_file_size to 256M, restarted everything and uploaded and SUCCESS!
I added the common .wlapp also.



As you can see the Android and Common Resources .wlapps are now added to the Worklight Server.

We can test that they are okay, by clicking either the 'Android' link or the 'Preview as Common Resources' link.  They'll open up in a new browser and show that the app is functioning.




So, we now have installed IBM Worklight Server, deployed the App Center, deployed the Worklight Console (that allows us to upload the mobile apps we create in the Worklight Studio (Eclipse)).  Now we just need to run the MIR application on an Android device, when we press the 'Start of Day' tab and the 'Initiate Start of Day Sync' button, we'll be able to see that the device will connect to the Worklight Adapter, the Worklight Adapter will then connect to the listening ExpressJS REST API that will then fetch the data from the running mongoDB and return the data back through the Worklight Adapter to the device.

When I get back onto my home network, I'll test this out and provide evidence that it all works as expected.  Why wait until then?  Well....I have full control over the network IP addresses etc...


Cool, I've got this all setup on my Windows 7 laptop.....but I'd really like to repeat the exercise (and re-rest these steps) by getting this all running on my new MacBookPro.  (click HERE for details of that little journey!)


Now that this has been proven, I can look at seeing what I need to do to be able to graft this off my Windows laptop and onto the Raspberry Pi and the Open Pandora.  I would really like to have it running on the Raspberry Pi (as I can share that over the internet to my devices), but for pure geek points, I'd love to have it running on the Open Pandora (just 'cos!).

What next?  Well, Raspberry Pi's are cheap.  I'll get a couple more and then look at setting up a Cluster of Worklight Servers.  Mainly for learning purposes.


What I really "should" be doing though is now focusing on the ACE! project.  Well, now that I have a Worklight Server setup properly I have the platform to be able to conduct the features that I want to achieve with the ACE! project.

Comments