Hello Guys,
This is another update to the proof of concept, and today we are doing big improvements to cover other parts of the representation that we did not cover yet: fetching data from Hawkular, and turning that into entities/views.
First, let's look at fetching data from Hawkular's Inventory:
# Create Client
client = Hawkular::Client.new(
credentials: { username: 'jdoe', password: 'password' },
options: { tenant: 'hawkular' }
)
# Get all feeds available on the server
feeds = client.inventory.list_feeds
# Get all resources
feeds.map do |feed|
# We get the resources for the feed
resources = client.inventory.list_resources_for_feed(feed, true)
# Then we make them presentable
HawkularResourceCollection.new(resources).prepare
end
The first new thing here is HawkularResourceCollection, which does the following:
Gets the raw representation of the properties defined by Hawkular
This is necessary because we want to use everything the server gives us, not only what the gem decides to expose.
Creates the entities by mapping the data (we will cover that soon).
Merge other resource properties for the servers.
This last step is a little more complicated: there are two kinds of resources that we get from the inventory: servers (like WildFly Servers) and what I call resources: java runtime, operating systems, and so on. We need some properties on the server that are exposed from the runtime/os, like immutability controls, so we merge those to all the servers on the feed.
To map the data to the entities, we use EntityMapper, a class that does exactly this mapping. Besides that, it does name transformation for properties, feed extracting, unescaping of paths, and returning a hash. When we need to persist anything, this is the data that we generate for the field, so persisting and fetching data from the db can looks like this:
# Getting data from the db, raw_hash being our json field to save the response
server = MiddlewareServer.last
entity = Entity.constantize(server.raw_hash)
# And persisting an entity to the db
server.update(raw_hash: entity.data)
The generated hash is then fed to Entity.constantize, which returns the entities we will use to render.
So, we have the data, and we have the entities. I have a standalone setup running, generated by hawkinit, and the response contains the following:
A WildFly Server
The Java Runtime
The Operating System
Which will use the following entities/views to render (refer to old emails/README.md for more on this):

Well, that's it. If you download the code at the github repo, you can see this in action, by just running the server and visiting ./ It will list everything hawkular found running, in pretty pretty json using the defined views.