Sitemap

Connecting to Hawk programmatically

3 min readJan 16, 2019

--

This article describes how to connect and interact with a Hawk index programmatically and discuss the similarities with the Hawk CLI interface.

What is Hawk?

Hawk is a model indexing framework, that is, a framework that mirrors the elements of models into a NoSQL database against which model navigation (read-only) is performed more efficiently than conventional file-based storage.

Hawk is more than just an alternative NoSQL-storage for models as it provides several query languages (including OrientDB SQL, EOL and EPL) along with automatic and (sometimes) incremental index synchronization of arbitrary model repositories (possibly versioned controlled).

The Hawk Thrift Java API

The Hawk Thrift Java API is a client and therefore requires a Hawk server to be up and running before we can interact with it.

Prerequisite: Create a server

Via the Hawk Server Releases

  1. Download the server use one of the hawk-server-* releases
  2. Before you run it, ensure the mondo-server.ini file is properly configured (port-wise). More setup details.
  3. Run the application

Via the Hawk Eclipse Preferences

  1. Go to the Eclipse Preferences > Hawk Servers section and select Add
Press enter or click to view image in full size

1. Connect to the Server

Via Hawk’s Thrift Java API

You will need to import the following hawk plugins along with their dependencies: org.hawk.service.api which provides a Thrift interface to Hawk and org.hawk.service.artemis which provides ActiveMQ Artemis dependencies.

The following is an example of how to connect to a Hawk server such as the one created in the pre-requisites.

import org.hawk.service.api.Hawk;
import org.hawk.service.api.utils.APIUtils;
public static void main(){
String username, password;
String url = "http://localhost:8080/thrift/hawk/tuple";
ThriftProtocol clientProtocol = ThriftProtocol.guessFromURL(url);
Hawk.Client client = APIUtils.connectTo(Hawk.Client.class,
url, clientProtocol, username, password);
}

Via the Hawk CLI

Get Betty Sanchez’s stories in your inbox

Join Medium for free to get updates from this writer.

The Hawk CLI is a wrapper around the Hawk Thrift Java API and provides methods that wrap the required logic to perform key Hawk operations.

You may download the CLI from the Hawk releases and execute the following in the console

> hawkConnect <url> [username] [password]

2. Create a remote Hawk instance to connect to

If you don’t have a Hawk server in the background you will not be able to connect to it. With the server ready, you can create one hawk instance in any of the following ways:

Via Hawk’s Thrift Java API

import org.hawk.service.api.Hawk;
import org.hawk.service.api.utils.APIUtils;
public static void main(){
... // after connecting to the server
String name = "myHawkInstanceNewName"
// Any other backend plugin
String backend = "org.hawk.orientdb.OrientDatabase"
Integer minimumDelay, maximumDelay;
List<String> enabledPlugins;
client.createInstance(name, backend, minimumDelay, maximumDelay, enabledPlugins);
}

Via the Hawk CLI

> hawkAddInstance <name> <backend> [minDelay] [maxDelay|0]

Via the Hawk Eclipse View

  1. To get the view go in Eclipse to Window > Show View > Other… and select “Hawk”

2. Tap on the database like symbol and (a) in instance type select RemoteHawkInstance, and (b) in Remote location ensure that the address and port match those of the running server . Don’t forget to setup the name and default model, meta-model, updater and backend plugins along with the minimum and maximum indexing delays.

More functionality in CLI and Thrift

There are more functions to interact with Hawk.

  • The list of commands from the CLI is available in the hawk wiki.
  • The list of methods available from the Hawk Thrift Java API is available in the hawk wiki as well.

Observations:

The list of API methods of the Thrift API is not listed

--

--

Betty Sanchez
Betty Sanchez

Written by Betty Sanchez

Computer Science PhD student in the University of York.