Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,10 @@ 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 @@ -1461,8 +1461,6 @@
if (isNetworkImplemented(network)) {
s_logger.debug("Network id=" + networkId + " is already implemented");
implemented.set(guru, 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);
return implemented;
}

Expand Down Expand Up @@ -1522,9 +1520,8 @@

network.setRestartRequired(false);
_networksDao.update(network.getId(), network);
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);
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, network.getAccountId(), network.getDataCenterId(), network.getId(),
network.getName(), network.getNetworkOfferingId(), null, null, null, network.getState().name(), network.getUuid());
return implemented;
} catch (final NoTransitionException e) {
s_logger.error(e.getMessage());
Expand Down Expand Up @@ -3005,6 +3002,7 @@
if (updateResourceCount) {
_resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.network, isDisplayNetworkEnabled);
}
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 @@ -3089,12 +3087,13 @@
s_logger.debug("Lock is acquired for network " + network + " as a part of network shutdown");
}

if (network.getState() == Network.State.Allocated) {
final Network.State initialState = network.getState();
if (initialState == Network.State.Allocated) {
s_logger.debug(String.format("Network [%s] is in Allocated state, no need to shutdown.", network));
return true;
}

if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) {
if (initialState != Network.State.Implemented && initialState != Network.State.Shutdown) {
s_logger.debug("Network is not implemented: " + network);
return false;
}
Expand Down Expand Up @@ -3141,6 +3140,9 @@
}
_networksDao.update(networkFinal.getId(), networkFinal);
_networksDao.clearCheckForGc(networkId);
if (initialState == Network.State.Implemented) {
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 {
try {
Expand Down Expand Up @@ -3393,8 +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);
}
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_DELETE, network.getAccountId(), network.getDataCenterId(), network.getId(),
network.getName(), network.getNetworkOfferingId(), null, null, null, Network.class.getName(), network.getUuid());
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 @@ -4780,6 +4781,27 @@
}
}

@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());
}

Check warning on line 4789 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#L4785-L4789

Added lines #L4785 - L4789 were not covered by tests

@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);
}

Check warning on line 4796 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#L4792-L4796

Added lines #L4792 - L4796 were not covered by tests

@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());
}

Check warning on line 4803 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#L4799-L4803

Added lines #L4799 - L4803 were not covered by tests

@Override
public String getConfigComponentName() {
return NetworkOrchestrationService.class.getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ public void testShutdownNetworkInImplementingState() {
boolean shutdownNetworkStatus = testOrchestrator.shutdownNetwork(networkId, reservationContext, false);
Assert.assertFalse(shutdownNetworkStatus);

verify(network, times(3)).getState();
verify(network).getState();
verify(testOrchestrator._networksDao, times(1)).acquireInLockTable(networkId, NetworkLockTimeout.value());
verify(testOrchestrator._networksDao, times(1)).releaseFromLockTable(networkId);
}
Expand Down
10 changes: 2 additions & 8 deletions server/src/main/java/com/cloud/network/NetworkServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1997,12 +1997,7 @@
if (implementedNetwork == null || implementedNetwork.first() == null) {
s_logger.warn("Failed to provision the network " + network);
}
Network implemented = implementedNetwork.second();
if (implemented != null) {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, implemented.getAccountId(), implemented.getDataCenterId(), implemented.getId(),
implemented.getName(), implemented.getNetworkOfferingId(), null, null, null, Network.class.getName(), implemented.getUuid());
}
return implemented;
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 @@ -3398,8 +3393,7 @@
}
}
Network updatedNetwork = getNetwork(network.getId());
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, updatedNetwork.getAccountId(), updatedNetwork.getDataCenterId(), updatedNetwork.getId(),
updatedNetwork.getName(), updatedNetwork.getNetworkOfferingId(), null, updatedNetwork.getState().name(), Network.class.getName(), updatedNetwork.getUuid(), true);
_networkMgr.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: 12 additions & 0 deletions server/src/test/java/com/cloud/vpc/MockNetworkManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,18 @@ 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