
It's no secret that RedHat has been promoting its own cloud product for about six months, and not the usual file storage, but a cloud computing service, with a free version of the Developer Edition. Java is indicated as one of the supported platforms, which for many can be very useful against the background of a rather small number of free Java hosts. And if you take java, then one of the most advanced platforms is offered here, namely Jboss AS 7.1, which means compatibility with most technologies and projects developed under the auspices of Jboss. The wide possibilities of the service are combined with simplicity, while the developers are so confident in the quality and availability of the service that they did not hesitate to even write about it “easy-peasy”.
Recently I had to try OpenShift in work, like Java - hosting for a small private project. Impressions, if briefly - yes, the developers of RedHat everything turned out, all the details further ...
To begin with - a few facts from the developer documentation.
OpenShift is a service platform that supports several languages ​​/ frameworks, the list of which will obviously be expanded. At the moment, you can develop applications in languages ​​such as java, php, ruby, python, perl. The user for 1 account can create up to 3 applications for which virtual machines (gear) are allocated with the following characteristics:
512 MB RAM
100 MB swap
1 GB disk space
What is the performance of this machine, not reported, but for comparison: the start of JBoss AS 7.1.1 with a small application on my laptop with a core-i5 2450M processor (2 cores, 2.5 GHz) takes 31 seconds, and the same application on OpenShift starts in 29 seconds.
The characteristics of machines can be slightly improved by reducing their number.
1 GB of disk space is used on:
• git repository
• Compiled application
• Database
• Logs
• data files
It is possible to configure a scalable application in which the database server will occupy a separate machine, that is, it will receive a “clean” gigabyte.
Additional disk space can also be solicited by writing to
openshift@redhat.com or IRC (#openshift on freenode).
Applications / machines can be equipped with supporting services (cartridge), such as databases, build systems, monitoring, cron.
Hello, cloud!
So, let's try to create an application running under JBoss AS 7.1.
First you need to get an OpenShift account. Make it simple: go to the address
https://openshift.redhat.com/app/account/new , we specify our RedHat login or email address, create a password and enter the captcha. After receiving confirmation by email, you are the owner of your OpenShift account.
Before proceeding further, you should install the OpenShift client and development tools.
')
Client and development tools
Client installation is described in detail in the documentation at
docs.redhat.com/docs/en-US/OpenShift/2.0/html/Getting_Started_Guide/index.html and is different for different operating systems. For Windows, this is installing Cygwin with a number of packages, then RubyGems, and finally, the rhc client itself. There are no tricks here, you just need to reproduce the steps that are indicated in the instructions.
As for development tools, this is a set of plug-ins for Eclipse 3.7, called JBoss Tools 3.3.0, installation instructions at
www.jboss.org/tools/download/installation/update_3_3 , download address
www.jboss.org/tools/download / dev (core plugins). At the moment there is no final release, you have to install version Beta3. Installing plugins is done in the usual way - either online, directly from Eclipse (update site), or from an offline archive. When you install from an offline archive, you actually need the connection, because Eclipse still downloads something from the network. Nothing can be done - Beta version.
Before installing plugins, note that the default jre in Eclipse points to the directory with the JDK, and not with the JRE, otherwise the process will loop.To work with java and JBoss AS, I recommend installing the entire set; for other languages, it’s enough to install JBoss Cloud Development Tools.
A little trick: under the 64-bit version of Eclipse, not everything is working (at least in Windows), so even if you have a 64-bit OS, I recommend installing the 32-bit JDK and 32-bit Eclipse. At the same time, no one bothers to launch the applications themselves under the 64-bit version of the JDK.
I also recommend downloading and installing:
• Maven, version 3 or higher (
http://maven.apache.org/ ), the installation consists in unpacking and adding the bin directory to the path variable. After installation, in Eclipse, specify the path to the Maven settings (to the conf / settings.xml file), the Maven setting -> User settings
• JBoss AS 7.1.1 (
http://www.jboss.org/jbossas ), installation is unpacking, then the server can be connected to Eclipse to run and debug applications directly from the development environment.
Domain Registration
So, the account is created, the development tools are installed, what next?
The next step is to create a “domain”. Domain is a suffix in the name, or namespace (namespace) that all your applications will have:
applicationname-namespace.rhcloud.com .
The name of the "domain" should consist of letters and numbers, think of something unique, not yet occupied by others and not included in the list of banned words. The domain name in the future can be changed.
Domain can be registered both in the OpenShift web-interface and in the console client. I recommend the second, since in this case, along with the registration of the domain, ssh keys and other necessary files will be generated. For convenience of working with the console, I recommend to add a line like this immediately to the ~ / .openshift / express.conf file:
default_rhlogin = rhlogin@example.comwhere rhlogin@example.com is the login or email you used during registration. This line will avoid the need to enter your login in each command.
So, to register the "domain" enter the command:
$ rhc domain create -n DomainName
A password will be requested to your account, after which a domain will be created and, if necessary, ssh keys.
Make sure everything is fine:
$ rhc domain show
You can also open the web-interface, and make sure that the domain is created and the key is added (
https://openshift.redhat.com/app/account ).
Create an application.
Applications can be created both in the web interface and in the console client or in Eclipse. I tried all 3 ways, the most reliable - from the web interface. The remaining methods also worked, but not 100% (possibly due to communication problems). In addition, the web interface does not need to remember the types of applications and cartridges; a full menu is provided from which we select the necessary items.
So, we specify the type of application (jbossas-7), the name, and - the application is created. If desired, add cartridges (for example, mysql-5.1 and phpmyadmin-3.4).
At the moment it is already possible at the address
applicationname-namespace.rhcloud.com to see the page - the preparation of your application.
When adding cartridges with database servers, the login and password to the database are reported, the application does not need to report them, since they are stored in environment variables. Thanks to this, even if you forgot the password yourself, you can later look at it by logging in on ssh to your server (the ssh address is available in the web console):
$ ssh 177682d.......0eb4fe@app-domain.rhcloud.com [app-domain.rhcloud.com ~]\> export
This command will display all variables, including the username and password of the database.
The following database servers are currently available:
• MongoDB NoSQL Database 2.0
• MySQL Database 5.1
• PostgreSQL Database 8.4
Ports to servers are closed, but it is possible to forward them via ssh to your computer, and then use the existing managers to work with the database. In addition, after installing MongoDB and MySQL, it becomes possible to install RockMongo 1.1 and phpMyAdmin 3.4 cartridges, respectively, to manage the database via the web.
At the moment there is no possibility to use DB cartridges if they do not belong to this application, that is, as long as the 1: 1 relationship (application: database).
We edit and publish the application.
In order to further develop the application, import it into Eclipse.
Select File -> Import -> Existing OpenShift Application, enter the login and password, specify the path to the ssh key that was created when creating the domain, specify the imported application. You will be asked to specify the path to the local git-repository, I recommend to specify the home-directory (in this case it will be easier to work in the console client).
The application will be copied to the specified repository (the name of the subdirectory corresponds to the name of the application) and imported into Eclipse.
Not all the contents of the directory will be imported into the project, perhaps some files will have to be opened and edited separately (for example, if we want to work with databases or use authentication), but in the simplest case, all that is needed is already in the project.
The imported application – template is not empty. It already has:
• All necessary catalogs
• index.html
• web.xml and faces-config.xml descriptors
• pom.xml
It should be remembered that the application is assembled on the server in accordance with the Maven - pom.xml script, so even if it is built in Eclipse, the assembly will not work on the server if the dependencies were not specified in pom.xml.
Let's say we want to use richfaces. To do this, add the following dependencies:
<dependency> <groupId>org.richfaces.core</groupId> <artifactId>richfaces-core-impl</artifactId> <version>4.2.2.Final</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.richfaces.ui</groupId> <artifactId>richfaces-components-ui</artifactId> <version>4.2.2.Final</version> <scope>runtime</scope> </dependency>
If Maven was configured correctly, then the necessary libraries automatically download, and you can already add richfaces components to index.html. After adding the components and writing the bin code, we get our first jsf page, for example:
demo-rlab.rhcloud.comIn order to publish the edited application, simply make Commit from the local repository to the server. The server will be stopped, the necessary files are transferred to the repository, then compilation and launch. We are convinced that the start was successful, for which we output the log to the console on command
$ rhc app tail -a demo -f demo/logs/server.log -o '-n 5000'
(replace demo with the name of your application)
I must say that the project is developing right before our eyes, and literally 2 weeks ago, the template started without errors, and now there are errors due to new extensions added to the .openshift / config / standalone.xml file. If these errors are very disturbing, I recommend that you remove all the excess from there, but it is better not to pay attention - it will probably work soon.
Backup
Backup and restore are performed in the console:
$ rhc app snapshot save -a YourApplication -f ArchivePath
As a result, an archive will be created with a full copy of the repository, with all settings, database contents. Recovery is performed by the command
$ rhc app snapshot restore
findings
The service was really convenient. Beginner can be difficult for the initial installation of the client and development tools, but everything else is done easily. If you compare with other cloud services, then create an account and the first application is probably even easier than getting a place on the dropbox. In this case, the developer receives not only a modern platform for applications, but also tools for collective development and all sorts of additional services.
Of course, the resources allocated in the Developer Edition will not allow you to roam, but for creating demos and gadgets, this is probably an ideal service.
Much remains behind the scenes, for example, features of working with a database or jaas - authentication, but if someone interested in the topic, I am ready to write a sequel. I also suggest that those who have already tried OpenShift share their impressions.