Skip to content

Commit

Permalink
Send devices equipment&inventory information into database.
Browse files Browse the repository at this point in the history
  • Loading branch information
HighstreetHerbert committed Dec 17, 2018
1 parent 74b8c4d commit 1d8540b
Show file tree
Hide file tree
Showing 13 changed files with 714 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ public int doRemoveByQuery(QueryBuilder query) {
return idx;
}


/**
* Do the mapping for test prupose
* @param object
* @return json String
*/
public String getJson( T object ) {
String json = mapper.objectToJson(object);
return json;
}

/**
* Write one object into Database
Expand All @@ -107,9 +115,21 @@ public int doRemoveByQuery(QueryBuilder query) {
*/
public T doWrite( T object) {

String json = mapper.objectToJson(object);
return doWrite(object, json);

}

/**
* Write one object into Database
* @param object Object with content
* @param json
* @return This object for chained call pattern.
*/
public T doWrite( T object, String json) {

log.debug("doWrite {} {}",object.getClass().getSimpleName(), object.getEsId());

String json = mapper.objectToJson(object);
if (json != null) {
String esId = db.doWrite(dataTypeName, object, json);
object.setEsId(esId);
Expand All @@ -122,6 +142,7 @@ public T doWrite( T object) {

}


/**
* Write a list of Objects to the database.
* @param list Object list with content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,48 @@ public JsonMapperBase() {
getFactory().configure(Feature.ESCAPE_NON_ASCII, true);
}

public JsonMapperBase(int t) {

switch(t) {
case 0:
break;
case 1:
setVisibility(PropertyAccessor.ALL, Visibility.NONE);
setVisibility(PropertyAccessor.FIELD, Visibility.DEFAULT);
break;
case 2:
setVisibility(PropertyAccessor.ALL, Visibility.NONE);
setVisibility(PropertyAccessor.FIELD, Visibility.PROTECTED_AND_PUBLIC);
break;
case 3:
setVisibility(PropertyAccessor.ALL, Visibility.NONE);
setVisibility(PropertyAccessor.GETTER, Visibility.ANY);
setVisibility(PropertyAccessor.IS_GETTER, Visibility.ANY);
break;
default:
setVisibility(PropertyAccessor.ALL, Visibility.NONE);
setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
break;

}

// Deserialization
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);

// Serialization
configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
getFactory().configure(Feature.ESCAPE_NON_ASCII, true);
}



public String objectToJson( Object object ) {
String res = null;

try {

StringWriter stringEmp = new StringWriter();
writeValue(stringEmp, object);
res = stringEmp.toString();
stringEmp.close();
res = writeValueAsString(object);

} catch (JsonGenerationException e) {
LOG.debug(e.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ public synchronized void initialReadFromNetworkElement() {

microwaveEventListener.initCurrentProblemStatus(resultList);

microwaveEventListener.writeEquipment(equipment);

LOG.info("Found info at {} for device {} number of problems: {}", mountPointNodeName, getUuId(),
resultList.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.opendaylight.mwtn.base.netconf.util.GenericTransactionUtils;
import org.opendaylight.mwtn.base.netconf.wrapperc.OnfInterfacePac;
import org.opendaylight.mwtn.base.netconf.wrapperc.WrapperEquipmentPacRev170402;
import org.opendaylight.mwtn.devicemanager.impl.database.types.equipment.ExtendedEquipment;
import org.opendaylight.mwtn.devicemanager.impl.xml.ProblemNotificationXml;
import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.Equipment;
import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.EquipmentKey;
Expand All @@ -32,13 +33,16 @@ public class ONFCoreNetworkElement12Equipment {

private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Equipment.class);

private static final UniversalId EQUIPMENTROOT = new UniversalId("network-element");
private static final int EQUIPMENTROOTLEVEL = 0;

private final ONFCOreNetworkElementCoreData coreData;
private final OnfInterfacePac equipmentPac;

private final ValueNameList extensions;
private final List<UniversalId> topLevelEqUuidList;
private final List<ProblemNotificationXml> problemList;
private final List<Equipment> equipmentList;
private final List<ExtendedEquipment> equipmentList;

public ONFCoreNetworkElement12Equipment(ONFCOreNetworkElementCoreData coreData, Capabilities capabilities) {
LOG.debug("Initialize "+ONFCoreNetworkElement12Equipment.class.getName());
Expand Down Expand Up @@ -80,12 +84,37 @@ protected void readNetworkElementEquipment() {
doSyncNetworkElementEquipmentToClassVars();
}

public String getMountpoint() {
return(coreData.getMountpoint());
}

public OnfInterfacePac getEquipmentPac() {
return equipmentPac;
}

public List<UniversalId> getTopLevelEqUuidList() {
return topLevelEqUuidList;
}

public List<ExtendedEquipment> getEquipmentList() {
return equipmentList;
}

public List<Equipment> getEquipmentAll() {
List<Equipment> equipmentListAll = new ArrayList<>();

Equipment equipment = readEquipmentAll();
equipmentListAll.add(equipment);

return equipmentListAll;
}


/* ---------------------------------------------------------------------------------
* private functions
*/

private void initClassVars() {
private void initClassVars() {
this.problemList.clear();
this.equipmentList.clear();
this.extensions.clear();
Expand Down Expand Up @@ -119,7 +148,7 @@ private void doSyncNetworkElementEquipmentToClassVars() {
} else {
//Read equipment and problems
for (UniversalId uuid : topLevelEqUuidList ) {
recurseReadEquipmentProblems(uuid, problemList, equipmentList);
recurseReadEquipmentProblems(uuid, EQUIPMENTROOT, EQUIPMENTROOTLEVEL,problemList, equipmentList);
}
}
} else {
Expand All @@ -128,26 +157,29 @@ private void doSyncNetworkElementEquipmentToClassVars() {
}
}

private void recurseReadEquipmentProblems(UniversalId uuid, List<ProblemNotificationXml> problemList, List<Equipment> equipmentList) {
Equipment equipment = this.readEquipment(uuid);
if (equipment != null) {
equipmentList.add(equipment);
private void recurseReadEquipmentProblems(UniversalId uuid, UniversalId parentUuid, int treeLevel,List<ProblemNotificationXml> problemList, List<ExtendedEquipment> equipmentList) {

if (uuid != null) {

Equipment equipment = this.readEquipment(uuid);

if (this.equipmentPac != null) {
this.equipmentPac.readTheFaults(uuid, problemList);
if (equipment != null) {
equipmentList.add(new ExtendedEquipment(parentUuid.getValue(), equipment, treeLevel));

List<ContainedHolder> containedHolderListe = equipment.getContainedHolder();
if (containedHolderListe != null ) {
for (ContainedHolder containedHolder : containedHolderListe) {
recurseReadEquipmentProblems(containedHolder.getKey().getUuid(), problemList, equipmentList);
if (this.equipmentPac != null) {
this.equipmentPac.readTheFaults(uuid, problemList);

List<ContainedHolder> containedHolderListe = equipment.getContainedHolder();
if (containedHolderListe != null ) {
for (ContainedHolder containedHolder : containedHolderListe) {
recurseReadEquipmentProblems(containedHolder.getOccupyingFru(), uuid, treeLevel+1, problemList, equipmentList);
}
}
}
}
}
}



private @Nonnull InventoryInformation getInventoryInformation(ValueNameList extensions, List<String> uuids) {

InventoryInformation inventoryInformation = new InventoryInformation();
Expand All @@ -165,7 +197,7 @@ private void recurseReadEquipmentProblems(UniversalId uuid, List<ProblemNotifica
} else {
//
if (!equipmentList.isEmpty()) {
Equipment e = equipmentList.get(0);
Equipment e = equipmentList.get(0).getEquipment();
if (e.getManufacturedThing() != null) {
EquipmentType et;
if ((et = e.getManufacturedThing().getEquipmentType()) != null) {
Expand Down Expand Up @@ -198,7 +230,7 @@ private void recurseReadEquipmentProblems(UniversalId uuid, List<ProblemNotifica

final Class<?> clazzPac = Equipment.class;

LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
LOG.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
coreData.getMountpoint(), interfacePacUuid.getValue());

InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier
Expand All @@ -210,4 +242,32 @@ private void recurseReadEquipmentProblems(UniversalId uuid, List<ProblemNotifica
return res;
}

/**
* Read equipment information
* @param interfacePacUuid uuid as key for Equipment.
* @return Equipment or null
*/
private @Nullable Equipment readEquipmentAll() {

final Class<?> clazzPac = Equipment.class;

LOG.info("DBRead Get all equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(), coreData.getMountpoint());

InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(Equipment.class).build();

Equipment res = GenericTransactionUtils.readData(coreData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,equipmentIID);

return res;
}

/**
* specific toString()
*/
@Override
public String toString() {
return "ONFCoreNetworkElement12Equipment [coreData=" + coreData + ", equipmentPac=" + equipmentPac
+ ", extensions=" + extensions + ", topLevelEqUuidList=" + topLevelEqUuidList + ", problemList="
+ problemList + ", equipmentList=" + equipmentList + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,37 @@

package org.opendaylight.mwtn.devicemanager.impl.database.service;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.management.InvalidApplicationException;

import org.opendaylight.mwtn.base.database.HtDataBaseReaderAndWriter;
import org.opendaylight.mwtn.base.database.HtDatabaseClientAbstract;
import org.opendaylight.mwtn.base.database.HtDatabaseNode;
import org.opendaylight.mwtn.base.database.IndexClientBuilder;
import org.opendaylight.mwtn.base.database.JsonMapperBase;
import org.opendaylight.mwtn.base.netconf.ONFCoreNetworkElement12Equipment;
import org.opendaylight.mwtn.devicemanager.impl.database.types.EsEventBase;
import org.opendaylight.mwtn.devicemanager.impl.database.types.EsFaultCurrent;
import org.opendaylight.mwtn.devicemanager.impl.database.types.EsFaultLog;
import org.opendaylight.mwtn.devicemanager.impl.database.types.equipment.EsEquipment;
import org.opendaylight.mwtn.devicemanager.impl.database.types.equipment.EsToplevelEquipment;
import org.opendaylight.mwtn.devicemanager.impl.database.types.equipment.ExtendedEquipment;
import org.opendaylight.mwtn.devicemanager.impl.xml.AttributeValueChangedNotificationXml;
import org.opendaylight.mwtn.devicemanager.impl.xml.MwtNotificationBase;
import org.opendaylight.mwtn.devicemanager.impl.xml.ObjectCreationNotificationXml;
import org.opendaylight.mwtn.devicemanager.impl.xml.ObjectDeletionNotificationXml;
import org.opendaylight.mwtn.devicemanager.impl.xml.ProblemNotificationXml;
import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.Equipment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -52,6 +68,8 @@ public class HtDatabaseEventsService {
private HtDataBaseReaderAndWriter<EsEventBase> eventRWEventLog;
private HtDataBaseReaderAndWriter<EsFaultCurrent> eventRWFaultCurrent;
private HtDataBaseReaderAndWriter<EsFaultLog> eventRWFaultLog;
private HtDataBaseReaderAndWriter<EsEquipment> eventRWEquipment;
private HtDataBaseReaderAndWriter<EsToplevelEquipment> eventRWToplevelEquipment;


// --- Construct and initialize
Expand All @@ -68,6 +86,8 @@ public HtDatabaseEventsService(HtDatabaseNode database) {
eventRWEventLog = new HtDataBaseReaderAndWriter<>(client, EsEventBase.ESDATATYPENAME, EsEventBase.class);
eventRWFaultLog = new HtDataBaseReaderAndWriter<>(client, EsFaultLog.ESDATATYPENAME, EsFaultLog.class);
eventRWFaultCurrent = new HtDataBaseReaderAndWriter<>(client, EsFaultCurrent.ESDATATYPENAME, EsFaultCurrent.class);
eventRWToplevelEquipment = new HtDataBaseReaderAndWriter<>(client, EsToplevelEquipment.ESDATATYPENAME, EsToplevelEquipment.class);
eventRWEquipment = new HtDataBaseReaderAndWriter<>(client, EsEquipment.ESDATATYPENAME, EsEquipment.class);


} catch (Exception e) {
Expand Down Expand Up @@ -188,4 +208,31 @@ public int clearFaultsCurrentOfNodeWithObjectId(String nodeName, String objectId
return nodeNames;
}


/**
* Write inventory to DB
* @param equipment all equipment of network element
*/
public void writeInventory(ONFCoreNetworkElement12Equipment equipment) {
if (client == null) {
LOG.debug("No DB, can not write for mountpoint: {}",equipment.getMountpoint());
return;
}

LOG.debug("Write inventory to database for mountpoint: {}",equipment.getMountpoint());

EsToplevelEquipment esToplevelEquipment = new EsToplevelEquipment();
esToplevelEquipment.set(equipment);
eventRWToplevelEquipment.doWrite(esToplevelEquipment);

List<ExtendedEquipment> equipmentList = equipment.getEquipmentList();
EsEquipment esEquipment;
for (ExtendedEquipment equipment1 : equipmentList) {
esEquipment = new EsEquipment();
esEquipment.set(equipment.getMountpoint(), equipment1);
eventRWEquipment.doWrite(esEquipment);
}
}


}
Loading

0 comments on commit 1d8540b

Please sign in to comment.