summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
004251a)
Nested enums could not be pushed due to an open type issue. Enums had a
composite open type, where the class name of the enum was stored. JMX was
not happy with this open type and expected a SimpleType.STRING.
After the enum is resolved, the open type is changed to SimpleType.
Change-Id: Ifce5bec70c8c3973f560260e93fadba2bd1119fa
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
augment "/config:modules/config:module/config:configuration" {
case impl-netconf {
when "/config:modules/config:module/config:type = 'impl-netconf'";
augment "/config:modules/config:module/config:configuration" {
case impl-netconf {
when "/config:modules/config:module/config:type = 'impl-netconf'";
+
+ uses tg:config-grouping;
+
leaf binaryLeaf {
type binary;
default ZGVmYXVsdEJpbg==;
leaf binaryLeaf {
type binary;
default ZGVmYXVsdEJpbg==;
rpcx:rpc-context-instance common-rpc-ctx-two;
}
rpcx:rpc-context-instance common-rpc-ctx-two;
}
+ typedef version {
+ type enumeration {
+ enum version1 {
+ value 1;
+ }
+ enum version2 {
+ value 2;
+ }
+ enum version3 {
+ value 3;
+ }
+ enum version4 {
+ value 4;
+ }
+ }
+ }
+
+ grouping config-grouping {
+
+ container from-grouping {
+ leaf enum-in-grouping {
+ type version;
+ }
+ }
+ }
+
+
identity common-rpc-ctx;
identity common-rpc-ctx-two;
identity common-rpc-ctx;
identity common-rpc-ctx-two;
import javax.management.openmbean.OpenType;
abstract class AbstractAttributeResolvingStrategy<T, O extends OpenType<?>> implements AttributeResolvingStrategy<T, O> {
import javax.management.openmbean.OpenType;
abstract class AbstractAttributeResolvingStrategy<T, O extends OpenType<?>> implements AttributeResolvingStrategy<T, O> {
- private final O openType;
public AbstractAttributeResolvingStrategy(O openType) {
this.openType = openType;
public AbstractAttributeResolvingStrategy(O openType) {
this.openType = openType;
public O getOpenType() {
return openType;
}
public O getOpenType() {
return openType;
}
+
+ /**
+ * Composite types might change during resolution. Use this setter to update open type
+ */
+ public void setOpenType(final O openType) {
+ this.openType = openType;
+ }
import javax.management.openmbean.ArrayType;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.ArrayType;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.OpenType;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
import javax.management.openmbean.OpenType;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
+ // Rebuild open type. Underlying composite types might have changed
+ if (innerTypeResolvingStrategy.getOpenType() instanceof CompositeType) {
+ try {
+ final ArrayType<?> openType = new ArrayType<Object>(getOpenType().getDimension(), innerTypeResolvingStrategy.getOpenType());
+ setOpenType(openType);
+ } catch (OpenDataException e) {
+ throw new IllegalStateException("An error occurred during restoration of array type " + this
+ + " for attribute " + attrName + " from value " + value, e);
+ }
+ }
+
LOG.debug("Attribute {} : {} parsed to type {} as {}", attrName, value, getOpenType(),
toStringArray(parsedArray));
LOG.debug("Attribute {} : {} parsed to type {} as {}", attrName, value, getOpenType(),
toStringArray(parsedArray));
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
import org.slf4j.Logger;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
import org.slf4j.Logger;
Map<String, Object> items = Maps.newHashMap();
Map<String, OpenType<?>> openTypes = Maps.newHashMap();
Map<String, Object> items = Maps.newHashMap();
Map<String, OpenType<?>> openTypes = Maps.newHashMap();
+ final String[] names = new String[getOpenType().keySet().size()];
+ OpenType<?>[] itemTypes = new OpenType[names.length];
+ int i = 0;
+
for (Object innerAttrName : innerTypes.keySet()) {
Preconditions.checkState(innerAttrName instanceof String, "Attribute name must be string");
String innerAttrNameStr = (String) innerAttrName;
for (Object innerAttrName : innerTypes.keySet()) {
Preconditions.checkState(innerAttrName instanceof String, "Attribute name must be string");
String innerAttrNameStr = (String) innerAttrName;
Optional<?> parsedInnerValue = attributeResolvingStrategy.parseAttribute(innerAttrNameStr, valueToParse);
Optional<?> parsedInnerValue = attributeResolvingStrategy.parseAttribute(innerAttrNameStr, valueToParse);
- openTypes.put(innerAttrNameStr, attributeResolvingStrategy.getOpenType());
+ if(attributeResolvingStrategy instanceof EnumAttributeResolvingStrategy) {
+ // Open type for enum contain the class name necessary for its resolution, however in a DTO
+ // the open type need to be just SimpleType.STRING so that JMX is happy
+ // After the enum attribute is resolved, change its open type back to STRING
+ openTypes.put(innerAttrNameStr, SimpleType.STRING);
+ } else {
+ openTypes.put(innerAttrNameStr, attributeResolvingStrategy.getOpenType());
+ }
items.put(yangToJavaAttrMapping.get(innerAttrNameStr),
parsedInnerValue.isPresent() ? parsedInnerValue.get() : null);
items.put(yangToJavaAttrMapping.get(innerAttrNameStr),
parsedInnerValue.isPresent() ? parsedInnerValue.get() : null);
+
+ // fill names + item types in order to reconstruct the open type for current attribute
+ names[i] = yangToJavaAttrMapping.get(innerAttrNameStr);
+ itemTypes[i] = openTypes.get(innerAttrNameStr);
+ i++;
}
CompositeDataSupport parsedValue;
try {
}
CompositeDataSupport parsedValue;
try {
+ LOG.trace("Attribute {} with open type {}. Reconstructing open type.", attrName, getOpenType());
+ setOpenType(new CompositeType(getOpenType().getTypeName(), getOpenType().getDescription(), names, names, itemTypes));
+ LOG.debug("Attribute {} with open type {}. Open type reconstructed to {}", attrName, getOpenType(), getOpenType());
parsedValue = new CompositeDataSupport(getOpenType(), items);
} catch (OpenDataException e) {
parsedValue = new CompositeDataSupport(getOpenType(), items);
} catch (OpenDataException e) {
- throw new IllegalStateException("An error occured during restoration of composite type " + this
+ throw new IllegalStateException("An error occurred during restoration of composite type " + this
+ " for attribute " + attrName + " from value " + value, e);
}
+ " for attribute " + attrName + " from value " + value, e);
}
return Optional.of(parsedValue);
}
return Optional.of(parsedValue);
}
protected Map<?, ?> preprocessValueMap(Map<?, ?> valueMap) {
return valueMap;
}
protected Map<?, ?> preprocessValueMap(Map<?, ?> valueMap) {
return valueMap;
}
// Enum constants mapping from yang -> Java and back
enumBiMap.put("one", "One");
enumBiMap.put("two", "Two");
// Enum constants mapping from yang -> Java and back
enumBiMap.put("one", "One");
enumBiMap.put("two", "Two");
+ enumBiMap.put("version1", "Version1");
+ enumBiMap.put("version2", "Version2");
<name>instance-from-code</name>
<impl-netconf xmlns="urn:opendaylight:params:xml:ns:yang:controller:test:impl">
<name>instance-from-code</name>
<impl-netconf xmlns="urn:opendaylight:params:xml:ns:yang:controller:test:impl">
+
+ <from-grouping>
+ <enum-in-grouping>version1</enum-in-grouping>
+ </from-grouping>
<sleep-factor>
2.58
</sleep-factor>
<sleep-factor>
2.58
</sleep-factor>