- public void updateVpnInstanceOpWithType(VpnInstanceOpDataEntry.BgpvpnType choice, @NonNull Uuid vpn) {
- String primaryRd = getVpnRd(vpn.getValue());
- if (primaryRd == null) {
- LOG.debug("updateVpnInstanceOpWithType: Update BgpvpnType {} for {}."
- + "Primary RD not found", choice, vpn.getValue());
- return;
- }
- InstanceIdentifier<VpnInstanceOpDataEntry> id = InstanceIdentifier.builder(VpnInstanceOpData.class)
- .child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(primaryRd)).build();
-
- Optional<VpnInstanceOpDataEntry> vpnInstanceOpDataEntryOptional =
- read(LogicalDatastoreType.OPERATIONAL, id);
- if (!vpnInstanceOpDataEntryOptional.isPresent()) {
- LOG.debug("updateVpnInstanceOpWithType: Update BgpvpnType {} for {}."
- + "VpnInstanceOpDataEntry not found", choice, vpn.getValue());
- return;
- }
- VpnInstanceOpDataEntry vpnInstanceOpDataEntry = vpnInstanceOpDataEntryOptional.get();
- if (vpnInstanceOpDataEntry.getBgpvpnType().equals(choice)) {
- LOG.debug("updateVpnInstanceOpWithType: Update BgpvpnType {} for {}."
- + "VpnInstanceOpDataEntry already set", choice, vpn.getValue());
- return;
- }
- VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder(vpnInstanceOpDataEntry);
- builder.setBgpvpnType(choice);
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
- tx.merge(id, builder.build(), false);
- LOG.debug("updateVpnInstanceOpWithType: sent merge to operDS BgpvpnType {} for {}", choice, vpn.getValue());
- }), LOG, "Error updating VPN instance op {} with type {}", vpn, choice);
+ public void updateVpnInstanceWithBgpVpnType(VpnInstance.BgpvpnType bgpvpnType, @NonNull Uuid vpnName) {
+ jobCoordinator.enqueueJob("VPN-" + vpnName.getValue(), () -> {
+ VpnInstance vpnInstance = getVpnInstance(dataBroker, vpnName);
+ if (vpnInstance == null) {
+ LOG.error("updateVpnInstanceWithBgpVpnType: Failed to Update VpnInstance {} with BGP-VPN type {}."
+ + "VpnInstance is does not exist in the CONFIG. Do nothing.", vpnName.getValue(), bgpvpnType);
+ return Collections.emptyList();
+ }
+ if (vpnInstance.isL2vpn()) {
+ LOG.error("updateVpnInstanceWithBgpVpnType: Failed to Update VpnInstance {} with BGP-VPN type {}."
+ + "VpnInstance is L2 instance. Do nothing.", vpnName.getValue(), bgpvpnType);
+ return Collections.emptyList();
+ }
+ VpnInstanceBuilder builder = new VpnInstanceBuilder(vpnInstance);
+ builder.setBgpvpnType(bgpvpnType);
+ InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class)
+ .child(VpnInstance.class, new VpnInstanceKey(vpnName.getValue())).build();
+ LOG.info("updateVpnInstanceWithBgpVpnType: Successfully updated the VpnInstance {} with BGP-VPN type {}",
+ vpnName.getValue(), bgpvpnType);
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ CONFIGURATION, tx -> tx.merge(vpnIdentifier, builder.build())));
+ });