+ @Override
+ public void postEquipmentState(String nodeId, String circuitPackName, boolean activate)
+ throws OpenRoadmInterfaceException {
+
+ InstanceIdentifier<CircuitPacks> circuitPackIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(
+ CircuitPacks.class, new CircuitPacksKey(circuitPackName));
+ Optional<CircuitPacks> cpOpt = this.deviceTransactionManager.getDataFromDevice(nodeId,
+ LogicalDatastoreType.CONFIGURATION, circuitPackIID, Timeouts.DEVICE_READ_TIMEOUT,
+ Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+ CircuitPacks cp = null;
+ if (cpOpt.isPresent()) {
+ cp = cpOpt.get();
+ } else {
+ throw new OpenRoadmInterfaceException(String.format(
+ "Could not find CircuitPack %s in equipment config datastore for node %s", circuitPackName, nodeId));
+ }
+ CircuitPacksBuilder cpBldr = new CircuitPacksBuilder(cp);
+ boolean change = false;
+ if (activate) {
+ if (cpBldr.getEquipmentState()!=null && !cpBldr.getEquipmentState().equals(States.NotReservedInuse)) {
+ cpBldr.setEquipmentState(States.NotReservedInuse);
+ change = true;
+ }
+ } else {
+ if ((cpBldr.getEquipmentState()!=null && !cpBldr.getEquipmentState().equals(States.NotReservedAvailable))) {
+ cpBldr.setEquipmentState(States.NotReservedAvailable);
+ change = true;
+ }
+ }
+ if (change) {
+ Future<Optional<DeviceTransaction>> deviceTxFuture = this.deviceTransactionManager.getDeviceTransaction(
+ nodeId);
+ DeviceTransaction deviceTx;
+ try {
+ Optional<DeviceTransaction> deviceTxOpt = deviceTxFuture.get();
+ if (deviceTxOpt.isPresent()) {
+ deviceTx = deviceTxOpt.get();
+ } else {
+ throw new OpenRoadmInterfaceException(String.format("Device transaction was not found for node %s!",
+ nodeId));
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ throw new OpenRoadmInterfaceException(String.format("Failed to obtain device transaction for node %s!",
+ nodeId), e);
+ }
+ deviceTx.put(LogicalDatastoreType.CONFIGURATION, circuitPackIID, cpBldr.build());
+ ListenableFuture<Void> txSubmitFuture = deviceTx.submit(Timeouts.DEVICE_WRITE_TIMEOUT,
+ Timeouts.DEVICE_WRITE_TIMEOUT_UNIT);
+ try {
+ txSubmitFuture.get();
+ LOG.info("Successfully posted equipment state change on node {}", nodeId);
+ } catch (InterruptedException | ExecutionException e) {
+ throw new OpenRoadmInterfaceException(String.format("Failed to post equipment state on node %s!",
+ nodeId), e);
+ }
+ }
+ }