SDN Controller Programming Guide
91
To enable this, a secondary index for each of these columns needs to be created and maintained.
This secondary index is another column family and it is called the secondary column family. An
example is AlertsBySeverity column family as shown below.
The secondary column families use composite columns and a row in AlertsBySeverity would look
like this.
RowKey CRITICAL : 1 | CRITICAL : 2 | INFO : 3 | WARNING : 5 | ……
Here the first part of the composite column name is the value of Severity that is wanted to match
and the second part of the column name is the primary key / row key of the matching row in the
main column family. To lookup all Alerts matching Severity = CRITICAL, rows 1 and 2 will be
returned. Do an additional lookup in the main column family to retrieve the data from rows 1 and
2. Once the data is retrieved, convert the same into a storable and return the query back to the
application.
CassandraAlertDao.java AlertsBySeverity Column Family:
public static class SeverityComposite implements
Serializable, Comparable<SeverityComposite>{
@Component (ordinal = 0)
private String severity;
@Component (ordinal = 1)
private String id;
private SeverityComposite(Severity severity, String id) {
this.severity = (severity == null) ? null :severity.name();
this.id = id;
}
public Severity getSeverity() {
return Enum.valueOf(Severity.class, this.severity);
}
public String getId() {
return this.id;
}
@Override
public int hashCode() {
...
}
@Override
public boolean equals(Object obj) {
...
}
@Override
public int compareTo(SeverityComposite other) {