Skip to content

Commit f4da219

Browse files
committed
WIP : extract NetworkService
WIP : move stuff between network manager and network service. at this point there is about 700 lines of duplicated code WIP: Leave creation of default offerings to NetworkManager init WIP: clean up imports Signed-off-by: Chiradeep Vittal <chiradeep@apache.org>
1 parent a64b386 commit f4da219

5 files changed

Lines changed: 3264 additions & 2589 deletions

File tree

api/src/com/cloud/network/NetworkService.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package com.cloud.network;
1818

1919
import java.util.List;
20-
import java.util.Map;
21-
import java.util.Set;
2220

2321
import com.cloud.api.commands.CreateNetworkCmd;
2422
import com.cloud.api.commands.ListNetworksCmd;
@@ -29,8 +27,6 @@
2927
import com.cloud.exception.InsufficientCapacityException;
3028
import com.cloud.exception.ResourceAllocationException;
3129
import com.cloud.exception.ResourceUnavailableException;
32-
import com.cloud.network.Network.Capability;
33-
import com.cloud.network.Network.Provider;
3430
import com.cloud.network.Network.Service;
3531
import com.cloud.network.Networks.TrafficType;
3632
import com.cloud.user.Account;
@@ -63,22 +59,12 @@ boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws Concurrent
6359

6460
IpAddress getIp(long id);
6561

66-
NetworkProfile convertNetworkToNetworkProfile(long networkId);
67-
68-
Map<Service, Map<Capability, String>> getNetworkCapabilities(long networkId);
6962

7063
boolean isNetworkAvailableInDomain(long networkId, long domainId);
7164

72-
Long getDedicatedNetworkDomain(long networkId);
73-
7465
Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser,
7566
String domainSuffix, Long networkOfferingId, Boolean changeCidr);
7667

77-
Integer getNetworkRate(long networkId, Long vmId);
78-
79-
Network getSystemNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType);
80-
81-
Map<Service, Set<Provider>> getNetworkOfferingServiceProvidersMap(long networkOfferingId);
8268

8369
PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed,
8470
List<String> isolationMethods, String broadcastDomainRange, Long domainId, List<String> tags, String name);
@@ -93,8 +79,6 @@ PhysicalNetwork updatePhysicalNetwork(Long id, String networkSpeed, List<String>
9379

9480
List<? extends Service> listNetworkServices(String providerName);
9581

96-
List<? extends Provider> listSupportedNetworkServiceProviders(String serviceName);
97-
9882
PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(Long physicalNetworkId, String providerName,
9983
Long destinationPhysicalNetworkId, List<String> enabledServices);
10084

@@ -126,17 +110,14 @@ PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkI
126110

127111
Pair<List<? extends PhysicalNetworkTrafficType>, Integer> listTrafficTypes(Long physicalNetworkId);
128112

129-
PhysicalNetwork getDefaultPhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType);
130113

131114
Network getExclusiveGuestNetwork(long zoneId);
132115

133116
List<Pair<TrafficType, String>> listTrafficTypeImplementor(ListTrafficTypeImplementorsCmd cmd);
134117

135118
List<? extends Network> getIsolatedNetworksWithSourceNATOwnedByAccountInZone(long zoneId, Account owner);
136119

137-
List<? extends Network> listNetworksByVpc(long vpcId);
138120

139-
boolean isVmPartOfNetwork(long vmId, long ntwkId);
140121

141122
/**
142123
* @param networkId
@@ -169,9 +150,5 @@ IpAddress associateIPToNetwork(long ipId, long networkId) throws InsufficientAdd
169150
Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, String vlan,
170151
String startIp, String endIP, String gateway, String netmask, long networkOwnerId, Long vpcId)
171152
throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException;
172-
/**
173-
* @param network
174-
* @return
175-
*/
176-
boolean canUseForDeploy(Network network);
153+
177154
}

server/src/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
import com.cloud.network.Network.Provider;
110110
import com.cloud.network.Network.Service;
111111
import com.cloud.network.NetworkManager;
112+
import com.cloud.network.NetworkService;
112113
import com.cloud.network.NetworkVO;
113114
import com.cloud.network.Networks.BroadcastDomainType;
114115
import com.cloud.network.Networks.TrafficType;
@@ -210,6 +211,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
210211
@Inject
211212
NetworkManager _networkMgr;
212213
@Inject
214+
NetworkService _networkSvc;
215+
@Inject
213216
ClusterDao _clusterDao;
214217
@Inject
215218
AlertManager _alertMgr;
@@ -1535,7 +1538,7 @@ public DataCenter editZone(UpdateZoneCmd cmd) {
15351538
_networkMgr.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Storage);
15361539
} catch (InvalidParameterValueException noStorage) {
15371540
PhysicalNetworkTrafficTypeVO mgmtTraffic = _trafficTypeDao.findBy(mgmtPhyNetwork.getId(), TrafficType.Management);
1538-
_networkMgr.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(), TrafficType.Storage.toString(), mgmtTraffic.getXenNetworkLabel(), mgmtTraffic.getKvmNetworkLabel(),
1541+
_networkSvc.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(), TrafficType.Storage.toString(), mgmtTraffic.getXenNetworkLabel(), mgmtTraffic.getKvmNetworkLabel(),
15391542
mgmtTraffic.getVmwareNetworkLabel(), mgmtTraffic.getSimulatorNetworkLabel(), mgmtTraffic.getVlan());
15401543
s_logger.info("No storage traffic type was specified by admin, create default storage traffic on physical network " + mgmtPhyNetwork.getId() + " with same configure of management traffic type");
15411544
}

server/src/com/cloud/network/NetworkManager.java

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.cloud.offering.NetworkOffering;
4949
import com.cloud.offerings.NetworkOfferingVO;
5050
import com.cloud.user.Account;
51+
import com.cloud.user.User;
5152
import com.cloud.utils.Pair;
5253
import com.cloud.vm.Nic;
5354
import com.cloud.vm.NicProfile;
@@ -61,7 +62,7 @@
6162
* NetworkManager manages the network for the different end users.
6263
*
6364
*/
64-
public interface NetworkManager extends NetworkService {
65+
public interface NetworkManager {
6566
/**
6667
* Assigns a new public ip address.
6768
*
@@ -192,6 +193,8 @@ boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId
192193
Map<Capability, String> getNetworkServiceCapabilities(long networkId, Service service);
193194

194195
boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException;
196+
197+
boolean applyIpAssociations(Network network, boolean rulesRevoked, boolean continueOnError, List<PublicIp> publicIps) throws ResourceUnavailableException;
195198

196199
boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services);
197200

@@ -472,10 +475,72 @@ NicProfile createNicForVm(Network network, NicProfile requested, ReservationCont
472475
*/
473476
PublicIp assignDedicateIpAddress(Account owner, Long guestNtwkId, Long vpcId, long dcId, boolean isSourceNat) throws ConcurrentOperationException, InsufficientAddressCapacityException;
474477

478+
NetworkProfile convertNetworkToNetworkProfile(long networkId);
475479

476480
/**
477481
* @return
478482
*/
479483
int getNetworkLockTimeout();
480484

485+
486+
boolean cleanupIpResources(long addrId, long userId, Account caller);
487+
488+
489+
boolean restartNetwork(Long networkId, Account callerAccount,
490+
User callerUser, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
491+
492+
493+
boolean shutdownNetworkElementsAndResources(ReservationContext context,
494+
boolean b, NetworkVO network);
495+
496+
497+
void implementNetworkElementsAndResources(DeployDestination dest,
498+
ReservationContext context, NetworkVO network,
499+
NetworkOfferingVO findById) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException;
500+
501+
502+
Map<Service, Map<Capability, String>> getNetworkCapabilities(long networkId);
503+
504+
505+
Network getSystemNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType);
506+
507+
508+
Long getDedicatedNetworkDomain(long networkId);
509+
510+
511+
Map<Service, Set<Provider>> getNetworkOfferingServiceProvidersMap(long networkOfferingId);
512+
513+
514+
List<? extends Provider> listSupportedNetworkServiceProviders(String serviceName);
515+
516+
List<? extends Network> listNetworksByVpc(long vpcId);
517+
518+
boolean canUseForDeploy(Network network);
519+
520+
Network getExclusiveGuestNetwork(long zoneId);
521+
522+
long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficType);
523+
524+
Integer getNetworkRate(long networkId, Long vmId);
525+
526+
527+
boolean isVmPartOfNetwork(long vmId, long ntwkId);
528+
529+
PhysicalNetwork getDefaultPhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType);
530+
531+
532+
Network getNetwork(long networkId);
533+
534+
535+
IpAddress getIp(long sourceIpAddressId);
536+
537+
538+
IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller,
539+
DataCenter zone) throws ConcurrentOperationException, ResourceAllocationException, InsufficientAddressCapacityException;
540+
541+
542+
Map<String, String> finalizeServicesAndProvidersForNetwork(NetworkOffering offering,
543+
Long physicalNetworkId);
544+
545+
481546
}

0 commit comments

Comments
 (0)