Does OSGi-as-a-Service exist? - java

Are there any Java PaaS solutions out there that offer OSGi containers as a service?
Google App Engine --> has their own GAE server which is modified Jetty
CloudBees --> has their own RUN#Cloud container which is modified Tomcat
OpenShift --> uses JBoss/Wildfly
??? --> uses, say, Karaf or Equinox
If not a full-blown PaaS, just a clusterable/scalable OSGi host. Google turned up nothing, so I'm assuming there isn't anything like this. Thanks in advance!

(In contrast to the other answers:) No, there is no OSGi-as-a-Service in the cloud, yet.
I am currently writing my master thesis about porting an OSGi application on a PaaS, so I did my own researches about PaaS and OSGi. I did not find any satisfying solution based on OSGi in the cloud (however I did find other solutions ;). The problem is that OSGi is pretty unpopular and the cloud is notoriously trendy.
As the other questions mentioned, OSGi is a Java library. So you could set it up pretty much everywhere where Java is supported. But that would be more a IaaS solution as a PaaS solution (which you seem to look for, as you are asking for OSGi-as-a-service). You would need to setup a OSGi framework on your own and you would have no support for deploying bundles. Which degenerates this solution pretty much. So no, there is no special cloud offer for OSGi, despite there are many for Java.
However, there is a nice book called Modular Cloud Apps with OSGi from Paul Baker and Bert Ertman published by O’Reilly. The book describes their PaaS-like solution to use OSGi in the cloud. The basically setup a repository of OSGi bundles, where they stored all their stuff. Then they created a cloud image, which only contains an empty OSGi framework/server (just like Apache Karaf, but they wrote their own tool called Apache ACE for what reason ever...). They were able to boot those images and as soon as the machine was up, they just deployed the bundles from their repository to the instance (via a web interface).
There is also a video of their demo on youtube: https://www.youtube.com/watch?v=oN3jYKOQ1Tk
I think this strategy is the best PaaS-like solution you could get. But - unfortunately - this is not supported by any cloud vendor out of the box. But you could set it up on (for exmaple) Amazon very easily.
EDIT
There also exists a Build Pack for Cloud Foundry to setup a Virgo server which can run OSGi apps: https://github.com/glyn/virgo-buildpack

Take a look at Gyrex. It's not a service yet but can be used to build you're own OSGi PaaS cluster. It uses Equinox, p2 for provisioning and Jetty.
http://eclipse.org/gyrex
Disclaimer: I'm a committer and heavy user of it.

There is a commercial provider of OSGi cloud services - Paremus. They have 2 cloud products - Nimble and Service Fabric. You might want to check them out. The Nimble product is available in a limited free edition for trial.

OSGi can be used on pretty much any cloud provider that offers Java support, since it is essentially just a Java library.
The exception to this would be Google App Engine, since they don't just modify Jetty, they modify Java itself and remove the ability to create threads and classloaders, both of which are required for full OSGi support.

OSGi is basically a Java library that can run on a virtual machine that has a JDK/JRE support. But remember one stuff, out of the box support is what you are looking for and you need to customize the PaaS you choose to run your app. I think to do this, you need to choose the provider that is easiest to configure and scale. Try out Jelastic. It is easiest of the lot to cinfigure and get started. Check their jar uploads, and I think it will suffice your needs.
Let me know what you think and if this answer is of any help.
Surya

Related

How do you break a large java application into components?

I am writing a java web application using spring, hibernate and mysql. The applications is getting larger so I want to break it into smaller parts e.g. smaller projects, components or which ever way possible. For example I have login and image uploading functionality, I don't want both of these to be in a single code base or project. I want to be able to use these separately almost like separate services independent of each other. Is there a way of doing this e.g. convert the image uploading functionality into a jar and then reference this jar in the actual project? How are the Enterprise projects split?
Hope it make makes sense and please advice if I am going the right direction as it is my first project? It would be nice if someone can point me to a mini example or recommend reading.
thanks in advance
Try with OSGi. If you are using Spring, then declarative services and possibly blueprint container in OSGi specs are what you need to leverage what you have done until now.
Try reading OSGi in Action by Richard S. Hall, Karl Pauls, Stuart McCulloch, and David Savage to get an insight in this technology.
OSGi is a modularazied approach for java software development that enforces loosely coupled services creation. Quoting from the OSGi alliance website:
OSGi technology is a set of specifications that defines a dynamic component system for Java. These specifications reduce software complexity by providing a modular architecture for large-scale distributed systems as well as small, embedded applications.
Hibernate supports OSGi as it can be seen here. As for the OSGi implementation, I would recommend Equinox, but many other valid OSGi implementations exist. Since your project is a web application, you could check also Virgo
Virgo from EclipseRT is a completely module-based Java application server that is designed to run enterprise Java applications and Spring-powered applications with a high degree of flexibility and reliability
and in particular,
supports vanilla WAR files, with all their dependencies in WEB-INF/lib, and Web Application Bundles, that import their dependencies via OSGi manifest metadata, via the reference implementation of the OSGi Web Container specification, based on embedded Apache Tomcat and configured using the standard Tomcat server.xml
I ended up using maven modules and maven dependency management capability. I created a separate maven project and kept adding maven modules as needed e.g. created a module for image uploading, one module for common libraries and so on.
Each of these modules are then packaged to jar files. I then import each one of these jar files using maven dependency to my main web project.
It seems to have worked great so far. Hope this is helpful for someone else, too.

How to build desktop applications with Apache Karaf/OSGi?

Well im into building OSGi application for a while, but i can't really find some tutorials which show the way to build Desktop Application ( in any languages ) with OSGi/Karaf.
I want to use karaf because it can then wrap Felix/Equinox. Most of Tutorials i found are about Enteprise Application(WEB). So is there any tutorials, which talk about building desktop application based on OSGi/Karaf?
Here is an example of a GUI application project that uses Apache karaf:
https://bitbucket.org/lorainelab/igb-fx
Using karaf to run a gui-based desktop application decreases development time. A developer makes a change to a bundle, builds the bundle, and then uses karaf shell commands to reload just that one bundle into the running application. There is no need to restart the entire application to view the effects of the new code. This is why were are using it.
We are using OSGi because we want greater modularity in the code base and because we want to support dynamically loaded "Apps" developed by 3rd party developers who write against our genome browser API.
Sorry the main intend right now for Karaf is to be used as a Server, though it still should be possible to start some guis on top. As your already familiar with building such bundles I'm sure you most probably could use just the minor version of Karaf and place your bundles in it. I have to admit I never done this before, so I'm not really sure about it.
First of all OSGI is a component framework, it also leverages a feature missing in Java since its inception - runtime versioning. If you really need it (OSGI), it doesn't depend wether you develop a WEB or desktop application. In general I would recommend you to take a look at this documentation:
http://fusesource.com/docs/esb/4.2/deploy_osgi/Build-ModifyMaven.html
In that link you'll find how to convert an existing Maven project to bundle, check further chapters - there's info how-to deploy jars in e.g. Karaf (Karaf is an OSGI container)
Hope, this helps

Java EE 6 Application Server for Web Profile with JavaMail

I have a Java EE web application using features from the Java EE 6 web profile + the EJB Timer service and JavaMail. I'm currently using GlassFish 3.1.2 full profile during development, but I want to investigate the alternatives because:
There seems to be a bug with multipart forms in GlassFish 3.1.2 and GlassFish 3.1.1 had other problems hurting me which are fixed in 3.1.2. (catch 22...) That bug is fixed by the jar in the ticket.
There seems to be a lot more options for application servers supporting the "web profile" than the "full profile" and the former is supposed to be so much more lightweight.
I want to choose the best option for deployment
I am currently using the embedded application server feature of GlassFish for tests, so a similar facility for any alternative is desirable. At worst, I can live with stiking to GlassFish embedded for the automated tests.
Is it possible to "add" a JavaMail and EJB Timer Service implementation module to an applicaton server implementing only the web profile? Does it work well? If this is not possible, are there alternatives to using JavaMail and the EJB Timer Service?
Which application servers meeting my requirements can you recommend?
Finally, I considered using the "Asynchronous invocation" feature of EJBs which is not part of EJB lite. If I understood correctly, it is illegal to start threads manually when running in a Java EE container. In that case, how can asynchronous operations be started in the Java EE Web Profile?
I'm still relatively new to the whole Java EE ecosystem and terminology so please don't hesitate to ask me to clarify any parts of my question.
Supporting doc
Java EE 6 web profile vs Full profile
EJB 3.1 vs EJB lite
edit 1
According to the Apache TomEE doc, TomEE, TomEE+ and OpenEJB would fit the bill.
edit 2
Based on the AS 7.1 release notes, this thead and this issue JBoss AS 7.1.0 seems to implement all the features I need.
First of all, I have never used GlassFish so I cannot give you any information about that.
I'm not sure if your application is being build for a true production envrionment but jboss 7.1 does not yet have any official commercial support in case you run into trouble.
Jboss 5.1 optimized for JDK 6 has commercial support via red hat.
That being said, a jboss instance can be fully configured and is very flexible. That means that you can start with the 'web' profile and add/remove services you do not need. (Removing unused services is always advised for production environments.)
Here is a wiki that gives information about slimming a jboss profile in jboss 5. It indicates all steps needed to remove a service.
The slimming operation can also be reversed, so you can add anything you need to a certain profile.
So there are basicly two approaches:
Start with a profile like 'default' or 'all' and start removing services that are not needed for your application
Start with the 'minimal' or 'web' profile and start adding services you are missing for your application. You copy the services from a profile that has it. (I personally prefer this approach)
Adding and removing services can be a work of trial and error though. You need to search the internet for a correct guide for the service you are trying to add or remove. (Tip, always do your operations on a copy of the profile provided by the AS and document each step. That way you can start over if you did something that seems irreversible.)
I hope this is of any help.
tom's right that JBoss AS7 doesn't have commercial support yet. However, it is coming - AS7 is being productised as EAP 6 (annoyingly!), and is going into beta in a few days. The community version has been out for a few months now, and although it does have a lot of rough edges, it basically works pretty well.
AS7 has a much more modular architecture than previous versions. The idea is that you only load the modules you need, which means that although it's a full-profile implementation (as of 7.1), if you only use web profile features, you only pay the runtime cost of a web profile implementation. You still have the bits you don't need sitting on disk, but disk is cheap (7.1.0 is 125 MB all in - hardly huge).
I'm afraid i haven't used any other fully-grown app servers (not in the last decade, at least), and so can't comment on them. I believe Geronimo supports full-profile EE6, so if you don't need commercial support, that might be worth a look.
I have spent some time using Tomcat-based setups. Yes, you can add enough extras to Tomcat to create a sort of 'bionic Tomcat' that is basically an app server, but doing it yourself is work you really shouldn't be doing - pure waste. I haven't used TomEE. I'm not a big fan of Tomcat generally, i have to admit.
As you state, OpenEJB/TomEE definitely fit the bill. Here are some examples you might like based on the things you mention:
TimerService and #Schedule
TimerService and ScheduleExpression
#Asynchronous Methods
To configure your JavaMail resource in your test case, just do like so:
Properties p = new Properties();
p.setProperty("superbizMail", "new://Resource?type=javax.mail.Session");
p.setProperty("superbizMail.mail.smtp.host", "mail.superbiz.org");
p.setProperty("superbizMail.mail.smtp.port", "25");
p.setProperty("superbizMail.mail.transport.protocol", "smtp");
p.setProperty("superbizMail.mail.smtp.auth", "true");
p.setProperty("superbizMail.mail.smtp.user", "someuser");
p.setProperty("superbizMail.password", "mypassword");
EJBContainer.createEJBContainer(p);
Then inject the JavaMail Session into your EJB via:
#Resource
private Session superbizMail;
Behind the scenes the 'superbizMail.' part is shaved off all the properties and the resulting set of properties is passed into javax.mail.Session.getDefaultInstance(Properties props). The resulting Session is what is injected into the #Resource reference

Play Framework application deployment

it's been a long time working on a play app & now comes the time to deploye it. that my first time so i'm kind of lost. which hosting compagny is the best & offer good pricing ?
I'll probably post a detailed instruction of what I did, but here's a quick 2-min general idea.
Buy an Amazon Micro Instance Virtual Server (costs around $11/mo) with a debian squeeze (6.0) image
$> sudo apt-get install sun-java6-jdk6
$> sudo apt-get install mysql5
~: wget <playDownloadURL>
~: unzip *.zip
~: set path to java, play
sftp/scp your source code to /var/www/<yourApp>
$> cd /var/www/<yourApp>
$> play start
~: (not actual commands but the concept)
and you are in business.
The creator company of Play Framework, Zenexity, propose a hosting solution dedicated to Play applications: PlayApps
It's probably the best choice since it is native Play hosting.
Otherwise, you can export your Play application as a classic war:
play war yourapp -o yourapp.war
Then, this war can be deployed on every Java server (Tomcat, Glassfish, etc.). For hosting a Java application server, you'll probably need a dedicated or virtualized server.
Another solution is to deploy your app on Google App Engine. But for that, you have to developp your Play application in a specific way. In particular, you can't use classic persistence. You have to use the Siena Play module to manage your entities for Google App Engine.
I don't know if Play apps can easily be deployed on other cloud structures. Maybe on Cloud Foundry since it supports Java application but I did not tested it and there are not deploy plugins yet for this platform.
You can look at this direction Heroku
Cloudbees, http://cloudbees.com, is an excellent choice. There is even a Play Framework Module for it.
http://www.playframework.org/modules/cloudbees-0.1/home
All of my Play! apps are hosted on Google App Engine, which is free for small sites. But you can host Play! apps on any Java web hosting provider.
In this question Experiences on free and low-cost hosting for play framework applications?
there are several cloud options for play framework...
There are a number of cloud hosting solutions supported by Play. There is a module for Stax, and the message boards have mentioned success on several others. A quick search for 'deploy' on the google groups will show a number of options.
I would recommend PlayApps though, It is actually hosted on Ghandi (i think!) and the pricing plan is the same, so the Zenexity guys actually make no money from this. They have set it up to be a convenience to us developers.
GAE is an option, but it restricts what you can do with Play. The WAR file deployment option, allowing to deploy to any java servlet container is also an option, but adds the overhead and resource of the container unnecessarily, so again, not the best option.
You could try Play! Manager. It's a Manager for Play Applications much like the Tomcat Manager. Worth trying:
https://github.com/mbarbieri/playmanager
Lately I've been playing around with openshift for hosting playframework application
It looks really good, you have mysql, phpmyadmin, mongodb, mongorock, jenkins, and what's even more important, you get 5 applications with 500MB op data space for each one... for free...
I'm also using this play module to ease deployment to openshift
https://github.com/opensas/openshift/blob/master/documentation/manual/home.textile
have a look at these articles:
playlatam.wordpress.com
detailed github tutorial
article found at openshift's site
If anyone is interested on uploading on Linode please follow this thread.
Linode 512 and play! framework
I advise you to have a look at http://www.playframework-cloud.com
This PaaS platform can automatically scale up and down your application regarding your traffic. You can also finely customize if you want vertical, horizontal or both types of scalability. The consequence of this scaling is that you pay as you go : you only pay for your real consumption and not the potential one.
Deployment via git.
Non AWS, hosted in tier-4+ datacenters.
Free trial !
For AWS Boxfuse offers a very easy solution.
With Boxfuse's native Play 2 support you can now simply execute
boxfuse run my-play-app-1.0.zip -env=prod
and this will automatically:
create a minimal AMI tailor-made for your Play 2 app
create an elastic IP
create a security group with the correct permissions
launch an instance of your app
All future updates are performed as blue/green deployments with zero downtime.
This also works with Elastic Load Balancers and Auto-Scaling Groups and the Boxfuse free tier is designed to fit the AWS free tier, which effectively means that you can deploy your app at no cost.
You can read more about it here: https://boxfuse.com/blog/playframework-aws
Disclaimer: I'm the founder and CEO of Boxfuse
I would look into cloud hosting.
If you developed your application in .NET, look into Windows Azure.
Otherwise, check out Amazon EC2.
Little confusing to setup if your a firs-timer, but they have guides and stuff to help you through it, and you get 100% scalability going with the cloud.

Mini-OSGi that can run in a sandbox (like AppEngine or WebStart)?

I really like the concept of modular bundles as implemented by OSGi.
I also like "managed deployment" services like Google AppEngine (for web application) or Java WebStart (for client software).
These two ideas seem to complement each-other rather well conceptually.
However, the OSGi standard includes a couple of features that make it impossible for implementations like Felix or Equinox to run on top of sandboxed virtual machines, such as AppEngine or Webstart. In these environments, it is not possible to get direct access to a file system, for example, which precludes the OSGi bundle cache that is used to store persistent bundle state and native libraries.
Now, I have no great interest in using native libraries or have persistent bundle state. Is there some framework that implements the core bundle and services concept of OSGi (ideally in a compatible way so that OSGi bundles can be deployed into it as is), but can work without a bundle cache (and other facilities not available in a sandbox)?
I am looking for something like a limited version of Felix that works on AppEngine or WebStart.
Of course, if the WebStart engine and the Google AppEngine just provided OSGi framework services out-of-the-box that would be great, too...
Update: Another very limiting aspect of AppEngine is that you cannot start new Threads. This prevents (among other things) asynchronous bundle life-cycle management. Obviously not an issue with WebStart.
EclipseSource have a patched version of osgi engine that (kind of) working in AppEngine, download the project zip files from the blog: http://eclipsesource.com/blogs/2009/04/10/osgi-on-appengine/
I'm pretty sure it can be done, and This eclipse help page could probably get you started. If I understand it correctly, your bundles must be signed and your jnlp file needs to request all permissions.
You should talk to Chris Aniszczyk. He made it work with Equinox and Knopflerfish. See the screenshot here: http://twitpic.com/300lk He was planning on blogging about it, but I guess he is pretty busy at the moment. Here is the link to his blog: http://mea-bloga.blogspot.com/
http://code.google.com/p/lemmon/
however, check the issues for URLStreamHandler Problem.
No personal experience, just a clue that might help you.
If your sole problem comes from the bundle cache and you don't need it, you can may be get rid of it by set this property to null in Equinox or Felix ? I'm pretty sure that this cache is not mandatory to have Equinox to run (don't know for Felix)

Categories

Resources