Mod aaa-12 修复无法获取cpu、内存的bug。
RCA: SOL: 修改人:dongxiancun 检视人:dongxiancun
This commit is contained in:
parent
f0df2f8df2
commit
86c714344f
|
@ -26,9 +26,7 @@ module device-status {
|
|||
container memory-infos {
|
||||
description "内存的状态信息";
|
||||
leaf memory-total {
|
||||
type int16 {
|
||||
range "0..100";
|
||||
}
|
||||
type int64 ;
|
||||
}
|
||||
leaf usage-rate {
|
||||
type int16 {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
package com.cmcc.cmhi.huawei.impl;
|
||||
|
||||
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
|
||||
import org.opendaylight.controller.md.sal.binding.api.MountPointService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -16,13 +17,15 @@ public class HuaweiDriverProvider {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(HuaweiDriverProvider.class);
|
||||
|
||||
private final DataBroker dataBroker;
|
||||
private final MountPointService mountService;
|
||||
private HuaweiDriverRegister register = null;
|
||||
private HuaweiNetconfSpeaker netconfSpeaker = null;
|
||||
|
||||
public HuaweiDriverProvider(final DataBroker dataBroker) {
|
||||
public HuaweiDriverProvider(final DataBroker dataBroker, final MountPointService mountService) {
|
||||
this.dataBroker = dataBroker;
|
||||
this.mountService = mountService;
|
||||
this.register = new HuaweiDriverRegister(this.dataBroker);
|
||||
this.netconfSpeaker = new HuaweiNetconfSpeaker(this.dataBroker);
|
||||
this.netconfSpeaker = new HuaweiNetconfSpeaker(this.dataBroker, this.mountService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,12 +52,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev15
|
|||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
|
||||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
|
||||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
|
||||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
|
||||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
|
||||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
|
||||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
|
||||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
|
||||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
|
||||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
|
||||
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
|
||||
import org.opendaylight.yangtools.concepts.ListenerRegistration;
|
||||
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -75,7 +77,7 @@ import static org.opendaylight.controller.md.sal.binding.api.DataObjectModificat
|
|||
|
||||
|
||||
public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInfo>,
|
||||
BindingAwareProvider, AutoCloseable {
|
||||
AutoCloseable {
|
||||
|
||||
private final ListenerRegistration<HuaweiNetconfSpeaker> configurationReg;
|
||||
private MountPointService mountService;
|
||||
|
@ -93,8 +95,9 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
private ThreadFactory timeThreadFactory = new ThreadFactoryBuilder().setNameFormat("huawei-pool-%d").setDaemon(true).build();
|
||||
|
||||
|
||||
public HuaweiNetconfSpeaker(DataBroker dataBroker) {
|
||||
public HuaweiNetconfSpeaker(DataBroker dataBroker, MountPointService mountService) {
|
||||
this.dataBroker = dataBroker;
|
||||
this.mountService = mountService;
|
||||
InstanceIdentifier<ConnectorInfo> connectPath = InstanceIdentifier.create(ConnectorInfo.class);
|
||||
final DataTreeIdentifier<ConnectorInfo> dataTreeIdentifier = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, connectPath);
|
||||
configurationReg = dataBroker.registerDataTreeChangeListener(dataTreeIdentifier, this);
|
||||
|
@ -131,7 +134,7 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
.build();
|
||||
|
||||
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
|
||||
transaction.put(LogicalDatastoreType.CONFIGURATION, NetconfIidFactory.netconfNodeIid(nodeId.getValue()), node);
|
||||
transaction.put(LogicalDatastoreType.CONFIGURATION, NetconfIidFactory.netconfNodeIid(nodeId.getValue()), node, true);
|
||||
|
||||
Futures.addCallback(transaction.submit(), new FutureCallback<Void>() {
|
||||
|
||||
|
@ -143,7 +146,7 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
|
||||
@Override
|
||||
public void onSuccess(Void avoid) {
|
||||
LOG.debug("NetconfNode={} created successfully", netconfNode);
|
||||
LOG.info("NetconfNode={} created successfully", netconfNode);
|
||||
startTask(connectDevice.getId().getValue());
|
||||
}
|
||||
});
|
||||
|
@ -172,22 +175,22 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
configurationReg.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* A method called when the session to MD-SAL is established. It initializes
|
||||
* references to MD-SAL services needed throughout the lifetime of the
|
||||
* huawei netconf application and registers its RPC implementation and Data change
|
||||
* Listener with the MD-SAL
|
||||
* <p>
|
||||
* The skeleton for this method was generated with the MD-SAL application
|
||||
* archetype.
|
||||
*
|
||||
* @param session Reference to the established MD-SAL session
|
||||
*/
|
||||
@Override
|
||||
public void onSessionInitiated(BindingAwareBroker.ProviderContext session) {
|
||||
LOG.info("HuaweiNetconfSpeaker Session Initiated");
|
||||
this.mountService = session.getSALService(MountPointService.class);
|
||||
}
|
||||
// /**
|
||||
// * A method called when the session to MD-SAL is established. It initializes
|
||||
// * references to MD-SAL services needed throughout the lifetime of the
|
||||
// * huawei netconf application and registers its RPC implementation and Data change
|
||||
// * Listener with the MD-SAL
|
||||
// * <p>
|
||||
// * The skeleton for this method was generated with the MD-SAL application
|
||||
// * archetype.
|
||||
// *
|
||||
// * @param session Reference to the established MD-SAL session
|
||||
// */
|
||||
// @Override
|
||||
// public void onSessionInitiated(BindingAwareBroker.ProviderContext session) {
|
||||
// LOG.info("HuaweiNetconfSpeaker Session Initiated");
|
||||
// this.mountService = session.getSALService(MountPointService.class);
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -261,8 +264,12 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
ScheduledExecutorService pool = new ScheduledThreadPoolExecutor(2, timeThreadFactory,
|
||||
new ThreadPoolExecutor.AbortPolicy());
|
||||
pool.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
readInfoFromDevice(nodeId);
|
||||
}, 0, 10000, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
LOG.error("捕获一个异常:{}", e);
|
||||
}
|
||||
}, 180000, 10000, TimeUnit.MILLISECONDS);
|
||||
if (Objects.nonNull(threads.get(nodeId))) {
|
||||
LOG.info("remove exist pool in thread map");
|
||||
if (!threads.get(nodeId).isShutdown()) {
|
||||
|
@ -285,13 +292,15 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
}
|
||||
|
||||
private void readInfoFromDevice(String nodeId) {
|
||||
LOG.info("开始向华为设备获取cpu信息!");
|
||||
final Optional<MountPoint> hwNodeOptional = mountService.getMountPoint(NETCONF_TOPO_IID
|
||||
.child(Node.class, new NodeKey(new NodeId(nodeId))));
|
||||
|
||||
LOG.info("开始向华为设备获取cpu信息2!");
|
||||
Preconditions.checkArgument(hwNodeOptional.isPresent(),
|
||||
"Unable to locate mountpoint: %s, not mounted yet or not configured",
|
||||
nodeId);
|
||||
final MountPoint hwNode = hwNodeOptional.get();
|
||||
LOG.info("Get the DataBroker for the mounted node !");
|
||||
|
||||
// Get the DataBroker for the mounted node
|
||||
final DataBroker hwNodeBroker = hwNode.getService(DataBroker.class).get();
|
||||
|
@ -308,7 +317,7 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
InstanceIdentifier<CpuInfos> iid =
|
||||
InstanceIdentifier.create(Devm.class).child(CpuInfos.class);
|
||||
Optional<CpuInfos> cupInfos;
|
||||
LOG.info("开始向华为设备获取cpu信息!");
|
||||
LOG.info("开始向华为设备读取cupInfos!");
|
||||
try {
|
||||
// Read from a transaction is asynchronous, but a simple
|
||||
// get/checkedGet makes the call synchronous
|
||||
|
@ -331,9 +340,10 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
iid, nodeId);
|
||||
}
|
||||
//write cpu information to layer
|
||||
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfos> cpuIid = NETCONF_TOPO_IID.child(Node.class).
|
||||
augmentation(NodeCpu.class).
|
||||
child(org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfos.class);
|
||||
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfos> cpuIid = NETCONF_TOPO_IID
|
||||
.child(Node.class, new NodeKey(new NodeId(nodeId)))
|
||||
.augmentation(NodeCpu.class)
|
||||
.child(org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfos.class);
|
||||
for (int i = 0; i < ifcList.size(); i++) {
|
||||
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
|
||||
writeTransaction.put(LogicalDatastoreType.OPERATIONAL, cpuIid, ifcList.get(i));
|
||||
|
@ -369,7 +379,8 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
LOG.info("Show memory with serial {},cpu usage is {} ",
|
||||
memoryInfo.getKey().getPosition(), memoryInfo.getDoMemoryUsage());
|
||||
MemoryInfosBuilder builder = new MemoryInfosBuilder();
|
||||
org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos temp = builder.setMemoryTotal(memoryInfo.getOsMemoryTotal().shortValue()).
|
||||
LOG.info("Huawei Device {} OsMemoryTotal is: {}", nodeId, memoryInfo.getOsMemoryTotal());
|
||||
org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos temp = builder.setMemoryTotal(memoryInfo.getOsMemoryTotal()).
|
||||
setUsageRate(memoryInfo.getOsMemoryUsage().shortValue()).build();
|
||||
memoryList.add(temp);
|
||||
|
||||
|
@ -380,9 +391,10 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
}
|
||||
|
||||
//write memory information to layer
|
||||
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos> customMemoryIID = NETCONF_TOPO_IID.child(Node.class).
|
||||
augmentation(NodeMemory.class).
|
||||
child(org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos.class);
|
||||
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos> customMemoryIID = NETCONF_TOPO_IID
|
||||
.child(Node.class, new NodeKey(new NodeId(nodeId)))
|
||||
.augmentation(NodeMemory.class)
|
||||
.child(org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos.class);
|
||||
for (int i = 0; i < memoryList.size(); i++) {
|
||||
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
|
||||
writeTransaction.put(LogicalDatastoreType.OPERATIONAL, customMemoryIID, memoryList.get(i));
|
||||
|
@ -433,9 +445,11 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
|||
|
||||
|
||||
//write interface information to layer
|
||||
InstanceIdentifier<TpInfos> tpinfosIID = NETCONF_TOPO_IID.child(Node.class).
|
||||
child(TerminationPoint.class).augmentation(TpExt.class).child(TpInfos.class);
|
||||
for (int i = 0; i < tpInfosList.size(); i++) {
|
||||
InstanceIdentifier<TpInfos> tpinfosIID = NETCONF_TOPO_IID
|
||||
.child(Node.class, new NodeKey(new NodeId(nodeId)))
|
||||
.child(TerminationPoint.class, new TerminationPointKey(new TpId(tpInfosList.get(i).getTpName())))
|
||||
.augmentation(TpExt.class).child(TpInfos.class);
|
||||
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
|
||||
writeTransaction.put(LogicalDatastoreType.OPERATIONAL, tpinfosIID, tpInfosList.get(i));
|
||||
Futures.addCallback(writeTransaction.submit(), new FutureCallback<Void>() {
|
||||
|
|
|
@ -14,11 +14,14 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
|
|||
<reference id="dataBroker"
|
||||
interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
|
||||
odl:type="default"/>
|
||||
<reference id="mountService"
|
||||
interface="org.opendaylight.controller.md.sal.binding.api.MountPointService" />
|
||||
|
||||
<bean id="provider"
|
||||
class="com.cmcc.cmhi.huawei.impl.HuaweiDriverProvider"
|
||||
init-method="init" destroy-method="close">
|
||||
<argument ref="dataBroker"/>
|
||||
<argument ref="mountService"/>
|
||||
</bean>
|
||||
|
||||
</blueprint>
|
||||
|
|
Loading…
Reference in New Issue