Copilot commented on code in PR #13325:
URL: https://github.com/apache/cloudstack/pull/13325#discussion_r4184722310


##########
engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java:
##########
@@ -777,6 +777,11 @@ private void updateRouterIpInNetworkDetails(Long 
networkId, String routerIp, Str
         }
     }
 
+    private void saveNetworkRateInDetails(long networkId, NetworkOffering 
offering, long dataCenterId) {
+        Integer rate = 
_configMgr.getNetworkOfferingNetworkRate(offering.getId(), dataCenterId);
+        networkDetailsDao.addDetail(networkId, ApiConstants.NETWORKRATE, 
String.valueOf(rate), true);

Review Comment:
   This writes the new network's `networkrate` detail before 
`NetworkMigrationManagerImpl.makeCopyOfNetwork()` calls `copyNetworkDetails()`. 
That copier persists every detail from the old network, including the old 
`networkrate`, so the destination ends up with duplicate rows and 
`findDetail()` can return the stale value that the API exposes. Exclude 
`ApiConstants.NETWORKRATE` from the generic copy or copy it with an upsert 
after the old details are copied.



##########
engine/schema/src/main/java/com/cloud/upgrade/NetworkRateBackfill.java:
##########
@@ -0,0 +1,251 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.upgrade;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDaoImpl;
+import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDao;
+import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDaoImpl;
+
+import com.cloud.dc.DataCenterDetailVO;
+import com.cloud.dc.dao.DataCenterDetailsDaoImpl;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkDaoImpl;
+import com.cloud.network.dao.NetworkDetailsDao;
+import com.cloud.network.dao.NetworkDetailsDaoImpl;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.service.ServiceOfferingVO;
+import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.service.dao.ServiceOfferingDaoImpl;
+import com.cloud.utils.db.TransactionLegacy;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.dao.VMInstanceDao;
+import com.cloud.vm.dao.VMInstanceDaoImpl;
+
+/**
+ * Backfills {@code nics.network_rate} and the {@code network_details} 
"networkrate" entry for
+ * pre-existing NICs/networks, deliberately frozen to the pre-feature 
precedence of
+ * {@link com.cloud.network.NetworkModelImpl#getNetworkRate} - do not redirect 
this to call the
+ * live method, whose precedence will keep evolving. Also backfills the {@code 
vpc_details}
+ * "publicnetworkrate" entry for pre-existing VPCs with a fixed "unlimited" 
value, since both

Review Comment:
   The migration deliberately computes the pre-feature precedence, but the live 
`NetworkModelImpl.getNetworkRate` now uses the service offering for every user 
NIC and the system offering before the network offering for router guest NICs. 
Upgrading an existing deployment therefore writes the old network-offering rate 
into `nics.network_rate`; the new NIC/VR API responses read that persisted 
value and can report a rate that is not effective after the upgrade. Backfill 
with the new precedence (or recompute these rows after migration) instead of 
freezing the old behavior.
   
   This issue also appears on line 81 of the same file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to