+
+ /**
+ * This method does a post(edit-config) on a given circuit-packs subtree to
+ * change its equipment-state.
+ *
+ * @param nodeId
+ * Netconf device.
+ * @param logicalConnPoint
+ * Logical Connection point resulting from PortMapping to
+ * retrieve associated circuit-pack.
+ * @param mps
+ * Mount point service.
+ * @param activate
+ * true to configure the circuit-pack to "NotReservedInuse".
+ * false to configure the circuit-pack to "NotReservedAvailable".
+ * @return true/false based on status of operation.
+ */
+ private boolean activateService(String nodeId, String logicalConnPoint, MountPointService mps, boolean activate) {
+ DataBroker deviceDb = PortMapping.getDeviceDataBroker(nodeId, mps);
+ String circuitPack = PortMapping.getMapping(nodeId, logicalConnPoint, db).getSupportingCircuitPackName();
+
+ InstanceIdentifier<CircuitPacks> circuitPackIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey(circuitPack));
+ ReadOnlyTransaction readTx = deviceDb.newReadOnlyTransaction();
+ // retrieve relevent CircuitPack object
+ Optional<CircuitPacks> cpObject;
+ CircuitPacks cp = null;
+ try {
+ cpObject = readTx.read(LogicalDatastoreType.CONFIGURATION, circuitPackIID).get();
+ if (cpObject.isPresent()) {
+ cp = cpObject.get();
+ } else {
+ LOG.info("Could not find CircuitPack {} in equipment config datastore for nodeId {}", circuitPack,
+ nodeId);
+ return false;
+ }
+
+ } catch (InterruptedException | ExecutionException ex) {
+ LOG.error("Issue reading config datastore on node {}", nodeId, ex);
+ }
+ CircuitPacksBuilder cpBldr = new CircuitPacksBuilder(cp);
+ if (activate) {
+ cpBldr.setEquipmentState(States.NotReservedInuse);
+ } else {
+ cpBldr.setEquipmentState(States.NotReservedAvailable);
+ }
+ WriteTransaction wt = deviceDb.newWriteOnlyTransaction();
+ wt.put(LogicalDatastoreType.CONFIGURATION, circuitPackIID, cpBldr.build());
+ try {
+ wt.submit().get(15, TimeUnit.SECONDS);
+ LOG.info("Successfully posted Equipment State on circuit pack {} on node {}", circuitPack, nodeId);
+ return true;
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ LOG.warn("Failed to post {} on node {}", circuitPack, nodeId, e);
+ return false;
+ }
+ }