Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move Usage network event publishing methods to UsageEventUtils
  • Loading branch information
winterhazel committed Apr 25, 2025
commit 2ce77d37680d194a87dc1c495a122cb662507f09
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,4 @@ void implementNetworkElementsAndResources(DeployDestination dest, ReservationCon
Pair<NicProfile, Integer> importNic(final String macAddress, int deviceId, final Network network, final Boolean isDefaultNic, final VirtualMachine vm, final Network.IpAddresses ipAddresses, final DataCenter datacenter, boolean forced) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException;

void unmanageNics(VirtualMachineProfile vm);

void publishNetworkCreation(Network network);

void publishNetworkUpdate(Network network);

void publishNetworkDeletion(Network network);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.annotation.PostConstruct;
import javax.inject.Inject;

import com.cloud.network.Network;
import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
Expand Down Expand Up @@ -246,4 +247,22 @@

static final String Name = "management-server";

public static void publishNetworkCreation(Network network) {
publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, network.getAccountId(), network.getDataCenterId(),
network.getId(), network.getName(), network.getNetworkOfferingId(), null, null, null, network.getState().name(),
network.getUuid());
}

Check warning on line 254 in engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java

View check run for this annotation

Codecov / codecov/patch

engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java#L250-L254

Added lines #L250 - L254 were not covered by tests

public static void publishNetworkUpdate(Network network) {
publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, network.getAccountId(), network.getDataCenterId(),
network.getId(), network.getName(), network.getNetworkOfferingId(), null, network.getState().name(),
Network.class.getName(), network.getUuid(), true);
}

Check warning on line 260 in engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java

View check run for this annotation

Codecov / codecov/patch

engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java#L256-L260

Added lines #L256 - L260 were not covered by tests

public static void publishNetworkDeletion(Network network) {
publishUsageEvent(EventTypes.EVENT_NETWORK_DELETE, network.getAccountId(), network.getDataCenterId(),
network.getId(), network.getName(), network.getNetworkOfferingId(), null, null, null,
Network.class.getName(), network.getUuid());
}

Check warning on line 266 in engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java

View check run for this annotation

Codecov / codecov/patch

engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java#L262-L266

Added lines #L262 - L266 were not covered by tests

}
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@

network.setRestartRequired(false);
_networksDao.update(network.getId(), network);
publishNetworkUpdate(network);
UsageEventUtils.publishNetworkUpdate(network);

Check warning on line 1523 in engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1523 was not covered by tests
implemented.set(guru, network);
return implemented;
} catch (final NoTransitionException e) {
Expand Down Expand Up @@ -3002,7 +3002,7 @@
if (updateResourceCount) {
_resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.network, isDisplayNetworkEnabled);
}
publishNetworkCreation(network);
UsageEventUtils.publishNetworkCreation(network);

Check warning on line 3005 in engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L3005 was not covered by tests

return network;
}
Expand Down Expand Up @@ -3141,7 +3141,7 @@
_networksDao.update(networkFinal.getId(), networkFinal);
_networksDao.clearCheckForGc(networkId);
if (initialState == Network.State.Implemented) {
publishNetworkUpdate(networkFinal);
UsageEventUtils.publishNetworkUpdate(networkFinal);

Check warning on line 3144 in engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L3144 was not covered by tests
}
result = true;
} else {
Expand Down Expand Up @@ -3395,7 +3395,7 @@
final Pair<Class<?>, Long> networkMsg = new Pair<Class<?>, Long>(Network.class, networkFinal.getId());
_messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, networkMsg);
}
publishNetworkDeletion(network);
UsageEventUtils.publishNetworkDeletion(network);

Check warning on line 3398 in engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L3398 was not covered by tests
return true;
} catch (final CloudRuntimeException e) {
s_logger.error("Failed to delete network", e);
Expand Down Expand Up @@ -4781,27 +4781,6 @@
}
}

@Override
public void publishNetworkCreation(Network network) {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, network.getAccountId(), network.getDataCenterId(),
network.getId(), network.getName(), network.getNetworkOfferingId(), null, null, null, network.getState().name(),
network.getUuid());
}

@Override
public void publishNetworkUpdate(Network network) {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, network.getAccountId(), network.getDataCenterId(),
network.getId(), network.getName(), network.getNetworkOfferingId(), null, network.getState().name(),
Network.class.getName(), network.getUuid(), true);
}

@Override
public void publishNetworkDeletion(Network network) {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_DELETE, network.getAccountId(), network.getDataCenterId(),
network.getId(), network.getName(), network.getNetworkOfferingId(), null, null, null,
Network.class.getName(), network.getUuid());
}

@Override
public String getConfigComponentName() {
return NetworkOrchestrationService.class.getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@
if (implementedNetwork == null || implementedNetwork.first() == null) {
s_logger.warn("Failed to provision the network " + network);
}
return implementedNetwork.second();

Check warning on line 2000 in server/src/main/java/com/cloud/network/NetworkServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/network/NetworkServiceImpl.java#L2000

Added line #L2000 was not covered by tests
} catch (ResourceUnavailableException ex) {
s_logger.warn("Failed to implement persistent guest network " + network + "due to ", ex);
CloudRuntimeException e = new CloudRuntimeException("Failed to implement persistent guest network");
Expand Down Expand Up @@ -3393,7 +3393,7 @@
}
}
Network updatedNetwork = getNetwork(network.getId());
_networkMgr.publishNetworkUpdate(updatedNetwork);
UsageEventUtils.publishNetworkUpdate(updatedNetwork);

Check warning on line 3396 in server/src/main/java/com/cloud/network/NetworkServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/network/NetworkServiceImpl.java#L3396

Added line #L3396 was not covered by tests
return updatedNetwork;
}

Expand Down
12 changes: 0 additions & 12 deletions server/src/test/java/com/cloud/vpc/MockNetworkManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1052,18 +1052,6 @@ public Pair<NicProfile, Integer> importNic(String macAddress, int deviceId, Netw
public void unmanageNics(VirtualMachineProfile vm) {
}

@Override
public void publishNetworkCreation(Network network) {
}

@Override
public void publishNetworkUpdate(Network network) {
}

@Override
public void publishNetworkDeletion(Network network) {
}

@Override
public Pair<List<? extends GuestVlan>, Integer> listGuestVlans(ListGuestVlansCmd cmd) {
return null;
Expand Down
Loading