Skip to content

Commit a0e592e

Browse files
DaanHooglandvishesh92weizhouapache
authored
prevent nic removal on out of bounds router stop (apache#8371)
Co-authored-by: Vishesh <[email protected]> Co-authored-by: Wei Zhou <[email protected]>
1 parent 6f3e4e6 commit a0e592e

File tree

8 files changed

+102
-122
lines changed

8 files changed

+102
-122
lines changed

api/src/main/java/com/cloud/vm/NicProfile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,6 @@ public void deallocate() {
442442

443443
@Override
444444
public String toString() {
445-
return String.format("NicProfile %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "vmId", "reservationId", "iPv4Address", "broadcastUri"));
445+
return String.format("NicProfile %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "vmId", "deviceId", "broadcastUri", "reservationId", "iPv4Address"));
446446
}
447447
}

core/src/main/java/com/cloud/serializer/GsonHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class GsonHelper {
5151
GsonBuilder loggerBuilder = new GsonBuilder();
5252
loggerBuilder.disableHtmlEscaping();
5353
loggerBuilder.setExclusionStrategies(new LoggingExclusionStrategy(s_logger));
54+
loggerBuilder.serializeSpecialFloatingPointValues();
55+
// maybe add loggerBuilder.serializeNulls(); as well?
5456
s_gogger = setDefaultGsonConfig(loggerBuilder);
5557
s_logger.info("Default Builder inited.");
5658
}

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,12 +2310,12 @@ public void releaseNic(final VirtualMachineProfile vmProfile, final Nic nic) thr
23102310

23112311
@DB
23122312
protected void releaseNic(final VirtualMachineProfile vmProfile, final long nicId) throws ConcurrentOperationException, ResourceUnavailableException {
2313-
final Pair<Network, NicProfile> networkToRelease = Transaction.execute(new TransactionCallback<Pair<Network, NicProfile>>() {
2313+
final Pair<Network, NicProfile> networkToRelease = Transaction.execute(new TransactionCallback<>() {
23142314
@Override
23152315
public Pair<Network, NicProfile> doInTransaction(final TransactionStatus status) {
23162316
final NicVO nic = _nicDao.lockRow(nicId, true);
23172317
if (nic == null) {
2318-
throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic);
2318+
throw new ConcurrentOperationException(String.format("Unable to acquire lock on nic id=%d", nicId));
23192319
}
23202320

23212321
final Nic.State originalState = nic.getState();
@@ -2329,6 +2329,9 @@ public Pair<Network, NicProfile> doInTransaction(final TransactionStatus status)
23292329
final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel
23302330
.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
23312331
if (guru.release(profile, vmProfile, nic.getReservationId())) {
2332+
if (s_logger.isDebugEnabled()) {
2333+
s_logger.debug(String.format("The nic %s on %s was released according to %s by guru %s, now updating record.", nic, profile, vmProfile, guru));
2334+
}
23322335
applyProfileToNicForRelease(nic, profile);
23332336
nic.setState(Nic.State.Allocated);
23342337
if (originalState == Nic.State.Reserved) {
@@ -2338,7 +2341,7 @@ public Pair<Network, NicProfile> doInTransaction(final TransactionStatus status)
23382341
}
23392342
}
23402343
// Perform release on network elements
2341-
return new Pair<Network, NicProfile>(network, profile);
2344+
return new Pair<>(network, profile);
23422345
} else {
23432346
nic.setState(Nic.State.Allocated);
23442347
updateNic(nic, network.getId(), -1);
@@ -2435,7 +2438,7 @@ protected void removeNic(final VirtualMachineProfile vm, final NicVO nic) {
24352438
for (final NetworkElement element : networkElements) {
24362439
if (providersToImplement.contains(element.getProvider())) {
24372440
if (s_logger.isDebugEnabled()) {
2438-
s_logger.debug("Asking " + element.getName() + " to release " + nic);
2441+
s_logger.debug(String.format("Asking %s to release %s, according to the reservation strategy %s", element.getName(), nic, nic.getReservationStrategy()));
24392442
}
24402443
try {
24412444
element.release(network, profile, vm, null);

engine/schema/src/main/java/com/cloud/vm/NicVO.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import javax.persistence.Table;
3131
import javax.persistence.Transient;
3232

33+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
3334
import org.apache.commons.lang3.builder.EqualsBuilder;
3435
import org.apache.commons.lang3.builder.HashCodeBuilder;
3536

@@ -329,17 +330,7 @@ public void setCreated(Date created) {
329330

330331
@Override
331332
public String toString() {
332-
return new StringBuilder("Nic[").append(id)
333-
.append("-")
334-
.append(instanceId)
335-
.append("-")
336-
.append(deviceId)
337-
.append("-")
338-
.append(reservationId)
339-
.append("-")
340-
.append(iPv4Address)
341-
.append("]")
342-
.toString();
333+
return String.format("Nic %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "instanceId", "deviceId", "broadcastUri", "reservationId", "iPv4Address"));
343334
}
344335

345336
@Override

server/src/main/java/com/cloud/network/guru/ControlNetworkGuru.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import javax.inject.Inject;
2222
import javax.naming.ConfigurationException;
2323

24+
import com.cloud.network.router.VirtualNetworkApplianceManager;
2425
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
2526
import org.apache.log4j.Logger;
2627

@@ -166,18 +167,24 @@ public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservat
166167
assert nic.getTrafficType() == TrafficType.Control;
167168
HypervisorType hType = vm.getHypervisorType();
168169
if ( ( (hType == HypervisorType.VMware) || (hType == HypervisorType.Hyperv) )&& isRouterVm(vm)) {
170+
if (!VirtualNetworkApplianceManager.RemoveControlIpOnStop.valueIn(vm.getVirtualMachine().getDataCenterId())) {
171+
if (s_logger.isDebugEnabled()) {
172+
s_logger.debug(String.format("not releasing %s from %s with reservationId %s, as systemvm.release.control.ip.on.stop is set to false for the data center.", nic, vm, reservationId));
173+
}
174+
return true;
175+
}
169176
long dcId = vm.getVirtualMachine().getDataCenterId();
170177
DataCenterVO dcVo = _dcDao.findById(dcId);
171178
if (dcVo.getNetworkType() != NetworkType.Basic) {
172179
super.release(nic, vm, reservationId);
173180
if (s_logger.isDebugEnabled()) {
174-
s_logger.debug("Released nic: " + nic);
181+
s_logger.debug(String.format("Released nic: %s for vm %s", nic, vm));
175182
}
176183
return true;
177184
} else {
178185
nic.deallocate();
179186
if (s_logger.isDebugEnabled()) {
180-
s_logger.debug("Released nic: " + nic);
187+
s_logger.debug(String.format("Released nic: %s for vm %s", nic, vm));
181188
}
182189
return true;
183190
}
@@ -187,7 +194,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservat
187194

188195
nic.deallocate();
189196
if (s_logger.isDebugEnabled()) {
190-
s_logger.debug("Released nic: " + nic);
197+
s_logger.debug(String.format("Released nic: %s for vm %s", nic, vm));
191198
}
192199

193200
return true;

server/src/main/java/com/cloud/network/guru/PodBasedNetworkGuru.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservat
159159
nic.deallocate();
160160

161161
if (s_logger.isDebugEnabled()) {
162-
s_logger.debug("Released nic: " + nic);
162+
s_logger.debug(String.format("Released nic: %s for vm %s", nic, vm));
163163
}
164164

165165
return true;

0 commit comments

Comments
 (0)