SDN Controller Programming Guide
71
Distributed KeyStore
KeyStore is a distributed <key, Value> store for the HP SDN HA aware applications. Key is in
string format and can be choosen by the application. <key, value> written to KeyStore by an
application can be read by application instances on same or other node of the controller cluster,
provided the accessing controller application instance knows the data access parameters
[Application name and key]. Application name separates the key spaces and hence different
applications can use same key names in the KeyStore. A user knowing the application name and
key can access the key value from any instance of the controller cluster. Applications can perform
create, get, update data, delete key operations on a <key, Value> tuples. Using keyStore service,
applications can share state with a different application or instance of same application which
might exist on different nodes of the controller cluster.
A value read is always local and it might not be the latest value [in case the value is updated in
another node context and it is yet to sync to the local node]. If the application desires to fetch the
latest value it can make use of Get latest value interface which synchronizes the value across
nodes and returns the value. Application can make use of locking services to protect a <Key,
Value> when there are parallel access [reads, writes] to the value, in which case it suggested to
use getLatestValue on the KeyValueNode
Applications can make use of the methods exposed by the following interfaces to work with
KeyStore.
HAService extends KeyStore interface and hence methods of this interface shall be accessed via
HAService in HP SDN environment.
KeyStore interface—provides the methods to store <Key, Value> tuples and query for them in
distributed KeyStore. A user with knowledge of application name and Key string can fetch the
value from any instance of the controller cluster.
KeyValueNode interface—provides the method to operate on a single <Key, Value> tuple.
KeyStore create or query interface methods return KeyValueNode. Using this interface methods
several operations like set value, get value, get latest value, get creator application name, get key
string etc., on a single <Key, Value> tuple.
Please refer to the JavaDocs for KeyStore and KeyValueNode interfaces for the detailed
explanation of the methods provided and corresponding functionality.
KeyStore Service Example:
import com.hp.sdn.ha.HAService;
import com.hp.dist.keystore.KeyStore;
import com.hp.dist.keystore.KeyValueNode;
...
@Component
public class KeyStoreUser {
private static String appName = "DemoApp";
@Reference(cardinality=ReferenceCardinality.MANDATORY_UNARY,
policy=ReferencePolicy.DYNAMIC)
private volatile HAService haService;
private void keyStoreOperations() {