Showing posts with label oVirt. Show all posts
Showing posts with label oVirt. Show all posts

Thursday, August 6, 2015

Google Play release!

  Since the previous 0.2beta release only one week passed by and suddenly we now have 1.0 version which is released on Google Play Store!

  This week was quite intensive even our mentor now actively contributes, not just code reviewing. My main feature for 1.0 version was to add support for Migrate VM action. This task includes new concepts of moVirt that I've still been not familiar with - which one is REST API.

  REST is used to perform communication between server and clients (oVirt and moVirt in this case). Briefly, you can post data or actions from client to add or perform them on server; or acquire for entities, stored on the server. At that point moVirt already had some actions like: start, stop, reboot VM, etc. My task was simply to extend current interface with one new action. But migration was a bit more complex, because it has options inside Action entity where you can set the destination host to migrate VM, or leave it empty to migrate to default host. After spending some time learning about REST and JSON, I've made new class that extends empty Action with destination host option, and it looks simply like this:
@JsonRootName("action")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ActionMigrate extends Action {

    public Host host;

    public ActionMigrate(String hostId) {
        host = new Host();
        host.id = hostId;
    }
}
   After REST part has been made we need UI to run it. Important part is to show user the list of available hosts to choose. And because I'm not experienced user of Android, I've been thinking in concept that such choices made through dialogue windows. And I've started to read guides about dialogues in Android. I found that AlertDialogue may perfectly fit the requirements, because it supports lists with items to choose which are loaded from database. And after I finally made clean and reliably class to show this dialogue, we found that list doesn't support scrolling so only first 4 items shows! I haven't seen any warning in SDK documentations and guides that this dialogue shows only first 4 items. What a shame...
 
  There was several ways to fix this, but I decided to transform from dialogue to activity, and set layout from scratch, and as a result it now looks even better.
Pic. 1. Migrate VM activity.

Wednesday, July 29, 2015

New MoVirt release - introduction of augmented reality

  I decided to date this post for MoVirt release and since release has been delayed this post is delayed too.

  But now 0.2 beta version of MoVirt is available to everyone, and I'm very happy about this because the main feature introduced in this version is my work on augmented reality! You can check how does it work in this video:

  Also you can download latest test build for Android from here if you are using oVirt or interested in virtualization. This is unsigned package, so you need to copy .apk file into your android device, enable "Unknown sources" in Settings and install .apk file.

  To prepare this release I've spent three weeks fixing various bugs, stability and usability issues along with refactoring and cleaning some parts of the code. And there were two "interesting" tasks which annoyed me a lot.

  The first task was about android synchronization. We noticed that automatic synchronization with oVirt server happens only once a day and this may be not very good behavior for monitoring software, because you can easily skip some important events if you are relying on notifications from moVirt. According to android SDK documentation:
When a network connection is available, the Android system sends out a message every few seconds to keep the device's TCP/IP connection open. This message also goes to the ContentResolver of each app. By calling setSyncAutomatically(), you can run the sync adapter whenever the ContentResolver receives the message.
"every few seconds", but this is not working in moVirt for some reason. People at stackoverflow.com says that android documentation misguiding in some topics especially about synchronization, and I found the only working solution is to enable periodic sync with fixed custom interval which is not recommended. There is one more solution (which is possibly the best) is to use push-notifications via GCM, but this is far-far future plans which requires modification also in oVirt server.

  The second task was about proper storing time in database. Since we have information at what time connection to server was lost and when was the last successful synchronization, we need to store this information in database to share between activities and sessions (detailed about necessity of using database in previous post). My first thought was to use java.sql.Timestamp class because it specially designed to store time and date in database. As I understand this class contains Unix Time which is UTC time and converts to properly formatted string to store in database.
public String toString()
Formats a timestamp in JDBC timestamp escape format. yyyy-mm-dd hh:mm:ss.fffffffff, where ffffffffff indicates nanoseconds.
Everything was looking fine until I realized that time in database stored in local time zone! And if you change time zone in your device it will show wrong time. Who in the world needs to store date and time in database in local time zone? And why does this Timestamp class do this conversion implicitly in toString() function with no obvious way to avoid this conversion? Ok, there are LOTS of other classes to work with time in java, and I decided to find some ready to use code snippets to store time as string in database in UTC... I've spent three days trying different solutions and all of them was wrong and shows the wrong time, because every class in Java performs implicit time zone conversion even if it is not needed and not obvious for this action. So I stopped to store time in database just as Unix Time and convert to string only while displaying and this seems to work.