我正在尝试使用 MD-SAL 的 Databroker 来保存数据列表,在多次修改 yang 文件和 InstanceIdentifier 但总是面临类似的验证问题后,例如
java.util.concurrent.ExecutionException: TransactionCommitFailedException{message=canCommit encountered an unexpected failure, errorList=[RpcError [message=canCommit encountered an unexpected failure, severity=ERROR, errorType=APPLICATION, tag=operation-failed, applicationTag=null, info=null, cause=org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException: Child /(urn:opendaylight:params:xml:ns:yang:testDataBroker?revision=2015-01-05)service-datas is not present in schema tree.]]}
at org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture.wrapInExecutionExc
我的目标是使用 rpc save-device-info 从休息中获取数据。然后使用databroker api将数据保存在内存中,最后测试数据是否可以成功复制到其他集群节点。
杨档案:
module testDataBroker {
yang-version 1;
namespace "urn:opendaylight:params:xml:ns:yang:testDataBroker";
prefix "testDataBroker";
revision "2015-01-05" {
description "Initial revision of testDataBroker model";
}
container service-datas {
list service-data {
key "service-id";
uses service-id;
uses device-info;
}
}
grouping device-info {
container device-info {
leaf device-name {
type string;
config false;
}
leaf device-description {
type string;
config false;
}
}
}
grouping service-id {
leaf service-id {
type string;
mandatory true;
}
}
rpc save-device-info {
input {
uses service-id;
uses device-info;
}
output {
uses device-info;
}
}
rpc get-device-info {
output {
uses device-info;
}
}
}
Java 代码
@Override public Future<RpcResult<SaveDeviceInfoOutput>> saveDeviceInfo(SaveDeviceInfoInput input) {
String name = input.getDeviceInfo().getDeviceName();
String description = input.getDeviceInfo().getDeviceDescription();
String serviceId = input.getServiceId();
WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
DeviceInfo deviceInfo = new DeviceInfoBuilder().setDeviceDescription(description).setDeviceName(name).build();
ServiceData serviceData = new ServiceDataBuilder().setServiceId(serviceId).setDeviceInfo(deviceInfo).build();
InstanceIdentifier<ServiceData> instanceIdentifier =
InstanceIdentifier.builder(ServiceDatas.class).child(ServiceData.class, serviceData.getKey()).build();
writeTransaction.put(LogicalDatastoreType.CONFIGURATION, instanceIdentifier, serviceData, true);
boolean isFailed = false;
try {
writeTransaction.submit().get();
log.info("Create containers succeeded!");
} catch (InterruptedException | ExecutionException e) {
log.error("Create containers failed: ", e);
isFailed = true;
}
return isFailed ?
RpcResultBuilder.success(new SaveDeviceInfoOutputBuilder())
.withError(RpcError.ErrorType.RPC, "Create container failed").buildFuture() :
RpcResultBuilder.success(new SaveDeviceInfoOutputBuilder().setDeviceInfo(input.getDeviceInfo()))
.buildFuture();
}
真的需要你的帮助。谢谢。
更新:使用相同版本的 md-sal 包,我仅在一个 ODL 而不是集群节点上安装了功能 odl-toaster。来自 odl-toaster 的 rpc 似乎在单个节点上正常工作。