mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Network Usage event model adjustments (#10755)
This commit is contained in:
parent
07f4fc2e51
commit
9d263cd71b
@ -25,6 +25,7 @@ import java.util.Map;
|
|||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import com.cloud.network.Network;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
@ -246,4 +247,22 @@ public class UsageEventUtils {
|
|||||||
|
|
||||||
static final String Name = "management-server";
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1461,8 +1461,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||||||
if (isNetworkImplemented(network)) {
|
if (isNetworkImplemented(network)) {
|
||||||
s_logger.debug("Network id=" + networkId + " is already implemented");
|
s_logger.debug("Network id=" + networkId + " is already implemented");
|
||||||
implemented.set(guru, network);
|
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;
|
return implemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1522,9 +1520,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||||||
|
|
||||||
network.setRestartRequired(false);
|
network.setRestartRequired(false);
|
||||||
_networksDao.update(network.getId(), network);
|
_networksDao.update(network.getId(), network);
|
||||||
|
UsageEventUtils.publishNetworkUpdate(network);
|
||||||
implemented.set(guru, network);
|
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;
|
return implemented;
|
||||||
} catch (final NoTransitionException e) {
|
} catch (final NoTransitionException e) {
|
||||||
s_logger.error(e.getMessage());
|
s_logger.error(e.getMessage());
|
||||||
@ -3005,6 +3002,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||||||
if (updateResourceCount) {
|
if (updateResourceCount) {
|
||||||
_resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.network, isDisplayNetworkEnabled);
|
_resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.network, isDisplayNetworkEnabled);
|
||||||
}
|
}
|
||||||
|
UsageEventUtils.publishNetworkCreation(network);
|
||||||
|
|
||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
@ -3089,12 +3087,13 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||||||
s_logger.debug("Lock is acquired for network " + network + " as a part of network shutdown");
|
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));
|
s_logger.debug(String.format("Network [%s] is in Allocated state, no need to shutdown.", network));
|
||||||
return true;
|
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);
|
s_logger.debug("Network is not implemented: " + network);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -3141,6 +3140,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||||||
}
|
}
|
||||||
_networksDao.update(networkFinal.getId(), networkFinal);
|
_networksDao.update(networkFinal.getId(), networkFinal);
|
||||||
_networksDao.clearCheckForGc(networkId);
|
_networksDao.clearCheckForGc(networkId);
|
||||||
|
if (initialState == Network.State.Implemented) {
|
||||||
|
UsageEventUtils.publishNetworkUpdate(networkFinal);
|
||||||
|
}
|
||||||
result = true;
|
result = true;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@ -3393,8 +3395,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||||||
final Pair<Class<?>, Long> networkMsg = new Pair<Class<?>, Long>(Network.class, networkFinal.getId());
|
final Pair<Class<?>, Long> networkMsg = new Pair<Class<?>, Long>(Network.class, networkFinal.getId());
|
||||||
_messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, networkMsg);
|
_messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, networkMsg);
|
||||||
}
|
}
|
||||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_DELETE, network.getAccountId(), network.getDataCenterId(), network.getId(),
|
UsageEventUtils.publishNetworkDeletion(network);
|
||||||
network.getName(), network.getNetworkOfferingId(), null, null, null, Network.class.getName(), network.getUuid());
|
|
||||||
return true;
|
return true;
|
||||||
} catch (final CloudRuntimeException e) {
|
} catch (final CloudRuntimeException e) {
|
||||||
s_logger.error("Failed to delete network", e);
|
s_logger.error("Failed to delete network", e);
|
||||||
|
|||||||
@ -894,7 +894,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
boolean shutdownNetworkStatus = testOrchestrator.shutdownNetwork(networkId, reservationContext, false);
|
boolean shutdownNetworkStatus = testOrchestrator.shutdownNetwork(networkId, reservationContext, false);
|
||||||
Assert.assertFalse(shutdownNetworkStatus);
|
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)).acquireInLockTable(networkId, NetworkLockTimeout.value());
|
||||||
verify(testOrchestrator._networksDao, times(1)).releaseFromLockTable(networkId);
|
verify(testOrchestrator._networksDao, times(1)).releaseFromLockTable(networkId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2006,12 +2006,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
|
|||||||
if (implementedNetwork == null || implementedNetwork.first() == null) {
|
if (implementedNetwork == null || implementedNetwork.first() == null) {
|
||||||
s_logger.warn("Failed to provision the network " + network);
|
s_logger.warn("Failed to provision the network " + network);
|
||||||
}
|
}
|
||||||
Network implemented = implementedNetwork.second();
|
return 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;
|
|
||||||
} catch (ResourceUnavailableException ex) {
|
} catch (ResourceUnavailableException ex) {
|
||||||
s_logger.warn("Failed to implement persistent guest network " + network + "due to ", ex);
|
s_logger.warn("Failed to implement persistent guest network " + network + "due to ", ex);
|
||||||
CloudRuntimeException e = new CloudRuntimeException("Failed to implement persistent guest network");
|
CloudRuntimeException e = new CloudRuntimeException("Failed to implement persistent guest network");
|
||||||
@ -3407,8 +3402,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Network updatedNetwork = getNetwork(network.getId());
|
Network updatedNetwork = getNetwork(network.getId());
|
||||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, updatedNetwork.getAccountId(), updatedNetwork.getDataCenterId(), updatedNetwork.getId(),
|
UsageEventUtils.publishNetworkUpdate(updatedNetwork);
|
||||||
updatedNetwork.getName(), updatedNetwork.getNetworkOfferingId(), null, updatedNetwork.getState().name(), Network.class.getName(), updatedNetwork.getUuid(), true);
|
|
||||||
return updatedNetwork;
|
return updatedNetwork;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user