===== Die Befehle der Admin Konsole der Oracle NoSQL DB im eigenen Programm integrieren =====
Über die Klasse CommandServiceAPI kann auch im eigenen Programmcode auf die Befehle der Admin Konsole der NoSQL Datenbank zugegriffen werden.
=== Initialisieren ===
..
public static CommandServiceAPI csi = null;
public static String adminNode = "localost";
public static int adminPort = 5000;
..
/**
* init the Command API
*/
public static void init(String nodeName, int RMIPort) {
log(" =============Get PerfMap Demo ==========================");
try {
if (csi == null) {
csi = RegistryUtils.getAdmin(nodeName, RMIPort);
}
}
catch (Exception ex) {
log(ex.toString());
}
}
=== Beispiel für den Aufruf der Performance Statistik ohne den lästigen Header der Amin Konsole===
/**
* show the performance Satistik of the KStore
*/
public static void showPerfStat() {
log(" =============Get PerfMap Demo ==========================");
try {
if (csi == null) {
init(adminNode, adminPort);
}
Map perfmap = csi.getPerfMap();
for (PerfEvent pe : perfmap.values()) {
System.out.println(pe.getColumnFormatted());
}
}
catch (Exception ex) {
log(ex.toString());
}
log(" =============Get PerfMap Demo ==========================");
}
===Beispiel für die Anzeige der Topology===
/**
* show the Topology Overview of the KStore
*/
public static void showTopology(){
log(" =============show Part Map ==========================");
try {
if (csi == null) {
init(adminNode, adminPort);
}
Topology topo = csi.getTopology();
PartitionMap part = topo.getPartitionMap();
for (Topology.Component com : part.getAll()) {
System.out.println(com.toString());
}
for ( StorageNode sn : topo.getSortedStorageNodes() ){
System.out.println("Read from "+ sn.getStorageNodeId() +" read :: "+sn.toString());
}
}
catch (Exception ex) {
log(ex.toString());
}
log(" =============show Part Map ==========================");
}
=== Beispiel für eine Anzeige des Status der einzelnen Nodes in einer CSV Sicht ===
public static void showTopologyCSV() {
try {
if (csi == null) {
init(adminNode, adminPort);
}
// get the topo
Topology topo = csi.getTopology();
//register util
RegistryUtils regUtils = new RegistryUtils(topo);
// grep the status
ServiceStatus status = ServiceStatus.UNREACHABLE;
// For all Storage Nodes
StorageNodeStatus snStatus = null;
StorageNodeAgentAPI sna = null;
RepNodeStatus rnStatus = null;
RepNodeAdminAPI rna = null;
String repRole = "MASTER";
for (StorageNode sn : topo.getSortedStorageNodes()) {
sna = regUtils.getStorageNodeAgent(sn.getStorageNodeId());
snStatus = sna.ping();
status = snStatus.getServiceStatus();
System.out.printf("nosqlTopo=%s|%s|%s|null\n",sn.getStorageNodeId(),sn.toString(),status);
RepGroupMap snrepgrp = topo.getRepGroupMap();
for (RepGroup r : snrepgrp.getAll()) {
for (RepNode rn2 : r.getRepNodes()) {
rna = regUtils.getRepNodeAdmin(rn2.getResourceId());
rnStatus = rna.ping();
status = rnStatus.getServiceStatus();
if (sn.getStorageNodeId().equals(rn2.getStorageNodeId())) {
if (rnStatus.getReplicationState().isMaster()) {
repRole = "MASTER";
} else {
repRole = "REPLICA";
}
System.out.printf("nosqlTopo=%s|%s|%s|%s\n",rn2.toString(),r.toString(),status,repRole);
}
}
}
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
==== Version abfragen ====
Erste Version,geht über die ganze Topology, kann noch verbessert werden .-)!
public static void showVersion() {
String version = "n/a";
String datacenter = "n/a";
String storeName = "n/a";
String numPartions = "100";
try {
if (csi == null) {
init(adminNode, adminPort);
}
// get the topo
Topology topo = csi.getTopology();
storeName = topo.getKVStoreName();
numPartions = ""+topo.getPartitionMap().size();
//register util
RegistryUtils regUtils = new RegistryUtils(topo);
RepNodeAdminAPI rna = null;
KVVersion rnVersion = null;
RepGroupMap snrepgrp = topo.getRepGroupMap();
for (RepGroup r : snrepgrp.getAll()) {
for (RepNode rn2 : r.getRepNodes()) {
rna = regUtils.getRepNodeAdmin(rn2.getResourceId());
rnVersion = rna.getInfo().getSoftwareVersion();
version = rnVersion.getNumericVersionString();
datacenter = topo.getDatacenter(rn2.getStorageNodeId()).getName();
}
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
System.out.printf("Version %s| DataCenter %s| Storename %s| Anzahl Partitionen %s\n", version, datacenter,storeName,numPartions);
}