Skip to content

Commit 194e768

Browse files
committed
Network Usage event model adjustments
1 parent f13cf59 commit 194e768

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,10 @@ void implementNetworkElementsAndResources(DeployDestination dest, ReservationCon
348348
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;
349349

350350
void unmanageNics(VirtualMachineProfile vm);
351+
352+
void publishNetworkCreation(Network network);
353+
354+
void publishNetworkUpdate(Network network);
355+
356+
void publishNetworkDeletion(Network network);
351357
}

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,8 +1461,6 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final
14611461
if (isNetworkImplemented(network)) {
14621462
s_logger.debug("Network id=" + networkId + " is already implemented");
14631463
implemented.set(guru, network);
1464-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, network.getAccountId(), network.getDataCenterId(), network.getId(),
1465-
network.getName(), network.getNetworkOfferingId(), null, network.getState().name(), Network.class.getName(), network.getUuid(), true);
14661464
return implemented;
14671465
}
14681466

@@ -1522,9 +1520,8 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final
15221520

15231521
network.setRestartRequired(false);
15241522
_networksDao.update(network.getId(), network);
1523+
publishNetworkUpdate(network);
15251524
implemented.set(guru, network);
1526-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, network.getAccountId(), network.getDataCenterId(), network.getId(),
1527-
network.getName(), network.getNetworkOfferingId(), null, null, null, network.getState().name(), network.getUuid());
15281525
return implemented;
15291526
} catch (final NoTransitionException e) {
15301527
s_logger.error(e.getMessage());
@@ -3005,6 +3002,7 @@ public Network doInTransaction(final TransactionStatus status) {
30053002
if (updateResourceCount) {
30063003
_resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.network, isDisplayNetworkEnabled);
30073004
}
3005+
publishNetworkCreation(network);
30083006

30093007
return network;
30103008
}
@@ -3141,6 +3139,7 @@ public Boolean doInTransaction(final TransactionStatus status) {
31413139
}
31423140
_networksDao.update(networkFinal.getId(), networkFinal);
31433141
_networksDao.clearCheckForGc(networkId);
3142+
publishNetworkUpdate(networkFinal);
31443143
result = true;
31453144
} else {
31463145
try {
@@ -3393,8 +3392,7 @@ public List<VlanVO> doInTransaction(TransactionStatus status) {
33933392
final Pair<Class<?>, Long> networkMsg = new Pair<Class<?>, Long>(Network.class, networkFinal.getId());
33943393
_messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, networkMsg);
33953394
}
3396-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_DELETE, network.getAccountId(), network.getDataCenterId(), network.getId(),
3397-
network.getName(), network.getNetworkOfferingId(), null, null, null, Network.class.getName(), network.getUuid());
3395+
publishNetworkDeletion(network);
33983396
return true;
33993397
} catch (final CloudRuntimeException e) {
34003398
s_logger.error("Failed to delete network", e);
@@ -4780,6 +4778,27 @@ public void unmanageNics(VirtualMachineProfile vm) {
47804778
}
47814779
}
47824780

4781+
@Override
4782+
public void publishNetworkCreation(Network network) {
4783+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, network.getAccountId(), network.getDataCenterId(),
4784+
network.getId(), network.getName(), network.getNetworkOfferingId(), null, null, null, network.getState().name(),
4785+
network.getUuid());
4786+
}
4787+
4788+
@Override
4789+
public void publishNetworkUpdate(Network network) {
4790+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, network.getAccountId(), network.getDataCenterId(),
4791+
network.getId(), network.getName(), network.getNetworkOfferingId(), null, network.getState().name(),
4792+
Network.class.getName(), network.getUuid(), true);
4793+
}
4794+
4795+
@Override
4796+
public void publishNetworkDeletion(Network network) {
4797+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_DELETE, network.getAccountId(), network.getDataCenterId(),
4798+
network.getId(), network.getName(), network.getNetworkOfferingId(), null, null, null,
4799+
Network.class.getName(), network.getUuid());
4800+
}
4801+
47834802
@Override
47844803
public String getConfigComponentName() {
47854804
return NetworkOrchestrationService.class.getSimpleName();

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,12 +1997,7 @@ private Network implementedNetworkInCreation(final Account caller, final DataCen
19971997
if (implementedNetwork == null || implementedNetwork.first() == null) {
19981998
s_logger.warn("Failed to provision the network " + network);
19991999
}
2000-
Network implemented = implementedNetwork.second();
2001-
if (implemented != null) {
2002-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, implemented.getAccountId(), implemented.getDataCenterId(), implemented.getId(),
2003-
implemented.getName(), implemented.getNetworkOfferingId(), null, null, null, Network.class.getName(), implemented.getUuid());
2004-
}
2005-
return implemented;
2000+
return implementedNetwork.second();
20062001
} catch (ResourceUnavailableException ex) {
20072002
s_logger.warn("Failed to implement persistent guest network " + network + "due to ", ex);
20082003
CloudRuntimeException e = new CloudRuntimeException("Failed to implement persistent guest network");
@@ -3398,8 +3393,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
33983393
}
33993394
}
34003395
Network updatedNetwork = getNetwork(network.getId());
3401-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, updatedNetwork.getAccountId(), updatedNetwork.getDataCenterId(), updatedNetwork.getId(),
3402-
updatedNetwork.getName(), updatedNetwork.getNetworkOfferingId(), null, updatedNetwork.getState().name(), Network.class.getName(), updatedNetwork.getUuid(), true);
3396+
_networkMgr.publishNetworkUpdate(updatedNetwork);
34033397
return updatedNetwork;
34043398
}
34053399

server/src/test/java/com/cloud/vpc/MockNetworkManagerImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,18 @@ public Pair<NicProfile, Integer> importNic(String macAddress, int deviceId, Netw
10521052
public void unmanageNics(VirtualMachineProfile vm) {
10531053
}
10541054

1055+
@Override
1056+
public void publishNetworkCreation(Network network) {
1057+
}
1058+
1059+
@Override
1060+
public void publishNetworkUpdate(Network network) {
1061+
}
1062+
1063+
@Override
1064+
public void publishNetworkDeletion(Network network) {
1065+
}
1066+
10551067
@Override
10561068
public Pair<List<? extends GuestVlan>, Integer> listGuestVlans(ListGuestVlansCmd cmd) {
10571069
return null;

0 commit comments

Comments
 (0)