use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method implementNetworkElementsAndResources.
@Override
public void implementNetworkElementsAndResources(final DeployDestination dest, final ReservationContext context, final Network network, final NetworkOffering offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException {
// Associate a source NAT IP (if one isn't already associated with the network) if this is a
// 1) 'Isolated' or 'Shared' guest virtual network in the advance zone
// 2) network has sourceNat service
// 3) network offering does not support a shared source NAT rule
final boolean sharedSourceNat = offering.getSharedSourceNat();
final Zone zone = _zoneRepository.findById(network.getDataCenterId()).orElse(null);
if (!sharedSourceNat && _networkModel.areServicesSupportedInNetwork(network.getId(), Service.SourceNat) && (network.getGuestType() == GuestType.Isolated || network.getGuestType() == GuestType.Shared && zone.getNetworkType() == com.cloud.model.enumeration.NetworkType.Advanced)) {
List<IPAddressVO> ips = null;
final Account owner = _entityMgr.findById(Account.class, network.getAccountId());
if (network.getVpcId() != null) {
ips = _ipAddressDao.listByVpc(network.getVpcId(), true);
if (ips.isEmpty()) {
final Vpc vpc = _vpcMgr.getActiveVpc(network.getVpcId());
s_logger.debug("Creating a source nat ip for vpc " + vpc);
_vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
}
} else {
ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
if (ips.isEmpty()) {
s_logger.debug("Creating a source nat ip for network " + network);
_ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
}
}
}
// get providers to implement
final List<Provider> providersToImplement = getNetworkProviders(network.getId());
implementNetworkElements(dest, context, network, offering, providersToImplement);
for (final NetworkElement element : networkElements) {
if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
((AggregatedCommandExecutor) element).prepareAggregatedExecution(network, dest);
}
}
try {
// reapply all the firewall/staticNat/lb rules
s_logger.debug("Reprogramming network " + network + " as a part of network implement");
if (!reprogramNetworkRules(network.getId(), CallContext.current().getCallingAccount(), network)) {
s_logger.warn("Failed to re-program the network as a part of network " + network + " implement");
// see DataCenterVO.java
final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
throw ex;
}
for (final NetworkElement element : networkElements) {
if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
if (!((AggregatedCommandExecutor) element).completeAggregatedExecution(network, dest)) {
s_logger.warn("Failed to re-program the network as a part of network " + network + " implement due to aggregated commands execution failure!");
// see DataCenterVO.java
final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
throw ex;
}
}
}
} finally {
for (final NetworkElement element : networkElements) {
if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
((AggregatedCommandExecutor) element).cleanupAggregatedExecution(network, dest);
}
}
}
}
use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method getServiceProvidersMap.
private Map<Service, Set<Provider>> getServiceProvidersMap(final long networkId) {
final Map<Service, Set<Provider>> map = new HashMap<>();
final List<NetworkServiceMapVO> nsms = _ntwkSrvcDao.getServicesInNetwork(networkId);
for (final NetworkServiceMapVO nsm : nsms) {
Set<Provider> providers = map.get(Service.getService(nsm.getService()));
if (providers == null) {
providers = new HashSet<>();
}
providers.add(Provider.getProvider(nsm.getProvider()));
map.put(Service.getService(nsm.getService()), providers);
}
return map;
}
use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method rollbackNicForMigration.
@Override
public void rollbackNicForMigration(final VirtualMachineProfile src, final VirtualMachineProfile dst) {
for (final NicProfile nicDst : dst.getNics()) {
final NetworkVO network = _networksDao.findById(nicDst.getNetworkId());
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
final NicProfile nicSrc = findNicProfileById(src, nicDst.getId());
final ReservationContext src_context = new ReservationContextImpl(nicSrc.getReservationId(), null, null);
final ReservationContext dst_context = new ReservationContextImpl(nicDst.getReservationId(), null, null);
if (guru instanceof NetworkMigrationResponder) {
((NetworkMigrationResponder) guru).rollbackMigration(nicDst, network, dst, src_context, dst_context);
}
final List<Provider> providersToImplement = getNetworkProviders(network.getId());
for (final NetworkElement element : networkElements) {
if (providersToImplement.contains(element.getProvider())) {
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
}
if (element instanceof NetworkMigrationResponder) {
((NetworkMigrationResponder) element).rollbackMigration(nicDst, network, dst, src_context, dst_context);
}
}
}
}
}
use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method prepareAllNicsForMigration.
/*
Prepare All Nics for migration including the nics dynamically created and not stored in DB
This is a temporary workaround work KVM migration
Once clean fix is added by stored dynamically nics is DB, this workaround won't be needed
*/
@Override
public void prepareAllNicsForMigration(final VirtualMachineProfile vm, final DeployDestination dest) {
final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
final ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), null, null);
Long guestNetworkId = null;
for (final NicVO nic : nics) {
final NetworkVO network = _networksDao.findById(nic.getNetworkId());
if (network.getTrafficType().equals(TrafficType.Guest) && network.getGuestType().equals(GuestType.Isolated)) {
guestNetworkId = network.getId();
}
final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.getNetworkTag(vm.getHypervisorType(), network));
if (guru instanceof NetworkMigrationResponder) {
if (!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)) {
// XXX: Transaction error
s_logger.error("NetworkGuru " + guru + " prepareForMigration failed.");
}
}
final List<Provider> providersToImplement = getNetworkProviders(network.getId());
for (final NetworkElement element : networkElements) {
if (providersToImplement.contains(element.getProvider())) {
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + "" + network.getPhysicalNetworkId());
}
if (element instanceof NetworkMigrationResponder) {
if (!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)) {
// XXX: Transaction error
s_logger.error("NetworkElement " + element + " prepareForMigration failed.");
}
}
}
}
guru.updateNicProfile(profile, network);
vm.addNic(profile);
}
final List<String> addedURIs = new ArrayList<>();
if (guestNetworkId != null) {
final List<IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(guestNetworkId, null);
for (final IPAddressVO userIp : publicIps) {
final PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
final URI broadcastUri = BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag());
final long ntwkId = publicIp.getNetworkId();
final Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(ntwkId, vm.getId(), broadcastUri.toString());
if (nic == null && !addedURIs.contains(broadcastUri.toString())) {
// Nic details are not available in DB
// Create nic profile for migration
s_logger.debug("Creating nic profile for migration. BroadcastUri: " + broadcastUri.toString() + " NetworkId: " + ntwkId + " Vm: " + vm.getId());
final NetworkVO network = _networksDao.findById(ntwkId);
_networkModel.getNetworkRate(network.getId(), vm.getId());
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
final NicProfile profile = new NicProfile();
profile.setIPv4Address(userIp.getAddress().toString());
profile.setIPv4Netmask(publicIp.getNetmask());
profile.setIPv4Gateway(publicIp.getGateway());
profile.setMacAddress(publicIp.getMacAddress());
profile.setBroadcastType(network.getBroadcastDomainType());
profile.setTrafficType(network.getTrafficType());
profile.setBroadcastUri(broadcastUri);
profile.setIsolationUri(Networks.IsolationType.Vlan.toUri(publicIp.getVlanTag()));
profile.setName(_networkModel.getNetworkTag(vm.getHypervisorType(), network));
profile.setNetworId(network.getId());
guru.updateNicProfile(profile, network);
vm.addNic(profile);
addedURIs.add(broadcastUri.toString());
}
}
}
}
use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method shutdownNetworkElementsAndResources.
@Override
public boolean shutdownNetworkElementsAndResources(final ReservationContext context, final boolean cleanupElements, final Network network) {
// get providers to shutdown
final List<Provider> providersToShutdown = getNetworkProviders(network.getId());
// 1) Cleanup all the rules for the network. If it fails, just log the failure and proceed with shutting down
// the elements
boolean cleanupResult = true;
boolean cleanupNeeded = false;
try {
for (final Provider provider : providersToShutdown) {
if (provider.cleanupNeededOnShutdown()) {
cleanupNeeded = true;
break;
}
}
if (cleanupNeeded) {
cleanupResult = shutdownNetworkResources(network.getId(), context.getAccount(), context.getCaller().getId());
}
} catch (final Exception ex) {
s_logger.warn("shutdownNetworkRules failed during the network " + network + " shutdown due to ", ex);
} finally {
// just warn the administrator that the network elements failed to shutdown
if (!cleanupResult) {
s_logger.warn("Failed to cleanup network id=" + network.getId() + " resources as a part of shutdownNetwork");
}
}
// 2) Shutdown all the network elements
boolean success = true;
for (final NetworkElement element : networkElements) {
if (providersToShutdown.contains(element.getProvider())) {
try {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending network shutdown to " + element.getName());
}
if (!element.shutdown(network, context, cleanupElements)) {
s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName());
success = false;
}
} catch (final ResourceUnavailableException e) {
s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
success = false;
} catch (final ConcurrentOperationException e) {
s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
success = false;
} catch (final Exception e) {
s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
success = false;
}
}
}
return success;
}
Aggregations