Skip to content

Commit 86e51eb

Browse files
author
Alex Huang
committed
Made changes to the exceptions thrown by NetworkManagerImpl
1 parent 0105c03 commit 86e51eb

9 files changed

Lines changed: 29 additions & 85 deletions

File tree

‎api/src/com/cloud/network/router/VirtualRouter.java‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,11 @@ public enum Role {
2828
DHCP_FIREWALL_LB_PASSWD_USERDATA,
2929
DHCP_USERDATA
3030
}
31-
/**
32-
* @return the mac address for the router.
33-
*/
34-
public String getGuestMacAddress();
35-
36-
public String getGuestIpAddress();
37-
38-
public String getPublicMacAddress();
39-
40-
public String getPublicNetmask();
41-
4231
/**
4332
* @return the ram size for this machine.
4433
*/
4534
public int getRamSize();
4635

47-
public String getGuestNetmask();
48-
49-
/**
50-
* @return the public ip address used for source nat.
51-
*/
52-
String getPublicIpAddress();
53-
54-
String getDomain();
55-
5636
Role getRole();
5737

5838
void setRamSize(int ramSize);

‎core/src/com/cloud/vm/DomainRouterVO.java‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
4949
@Column(name="public_netmask")
5050
private String publicNetmask;
5151

52-
@Column(name="guest_mac_address")
53-
private String guestMacAddress;
54-
5552
@Column(name="guest_ip_address")
5653
private String guestIpAddress;
5754

@@ -96,19 +93,10 @@ public void setPublicNetmask(String publicNetmask) {
9693
this.publicNetmask = publicNetmask;
9794
}
9895

99-
public void setGuestMacAddress(String routerMacAddress) {
100-
this.guestMacAddress = routerMacAddress;
101-
}
102-
10396
public long getNetworkId() {
10497
return networkId;
10598
}
10699

107-
@Override
108-
public String getGuestNetmask() {
109-
return guestNetmask;
110-
}
111-
112100
public void setGuestIpAddress(String routerIpAddress) {
113101
this.guestIpAddress = routerIpAddress;
114102
}
@@ -122,17 +110,14 @@ public long getDataCenterId() {
122110
return dataCenterId;
123111
}
124112

125-
@Override
126113
public String getPublicNetmask() {
127114
return publicNetmask;
128115
}
129116

130-
@Override
131117
public String getPublicMacAddress() {
132118
return publicMacAddress;
133119
}
134120

135-
@Override
136121
public String getGuestIpAddress() {
137122
return guestIpAddress;
138123
}
@@ -141,7 +126,6 @@ protected DomainRouterVO() {
141126
super();
142127
}
143128

144-
@Override
145129
public String getDomain() {
146130
return domain;
147131
}
@@ -156,16 +140,10 @@ public void setRamSize(int ramSize) {
156140
this.ramSize = ramSize;
157141
}
158142

159-
@Override
160143
public String getPublicIpAddress() {
161144
return publicIpAddress;
162145
}
163146

164-
@Override
165-
public String getGuestMacAddress() {
166-
return guestMacAddress;
167-
}
168-
169147
@Override
170148
public Role getRole() {
171149
return role;

‎server/src/com/cloud/api/ApiResponseHelper.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,6 @@ public DomainRouterResponse createDomainRouterResponse(VirtualRouter router) {
11411141
routerResponse.setTemplateId(router.getTemplateId());
11421142
routerResponse.setCreated(router.getCreated());
11431143
routerResponse.setState(router.getState());
1144-
routerResponse.setNetworkDomain(router.getDomain());
11451144

11461145
if (router.getHostId() != null) {
11471146
routerResponse.setHostId(router.getHostId());
@@ -1175,6 +1174,7 @@ public DomainRouterResponse createDomainRouterResponse(VirtualRouter router) {
11751174
routerResponse.setGuestMacAddress(singleNicProfile.getMacAddress());
11761175
routerResponse.setGuestNetmask(singleNicProfile.getNetmask());
11771176
routerResponse.setGuestNetworkId(singleNicProfile.getNetworkId());
1177+
routerResponse.setNetworkDomain(network.getNetworkDomain());
11781178
}
11791179
}
11801180
}

‎server/src/com/cloud/ha/HighAvailabilityManagerImpl.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
* || stop.retry.wait | time to wait before retrying the stop | seconds | 120 ||
110110
* }
111111
**/
112-
@SuppressWarnings("unchecked")
113112
@Local(value={HighAvailabilityManager.class})
114113
public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
115114
protected static final Logger s_logger = Logger.getLogger(HighAvailabilityManagerImpl.class);
@@ -198,7 +197,7 @@ public void scheduleRestartForVmsOnHost(final HostVO host) {
198197
// collect list of vm names for the alert email
199198
VMInstanceVO vm = vms.get(0);
200199
if (vm.isHaEnabled()) {
201-
sb.append(" " + vm.getName());
200+
sb.append(" " + vm);
202201
}
203202
for (int i = 1; i < vms.size(); i++) {
204203
vm = vms.get(i);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public interface NetworkManager extends NetworkService {
144144
Network createNetwork(long networkOfferingId, String name, String displayText, Boolean isShared, Boolean isDefault, Long zoneId, String gateway, String cidr, String vlanId, String networkDomain, Account owner) throws ConcurrentOperationException, InsufficientCapacityException;
145145

146146
/**
147+
* @throws InsufficientCapacityException
147148
* Associates an ip address list to an account. The list of ip addresses are all addresses associated with the given vlan id.
148149
* @param userId
149150
* @param accountId

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ protected Account getAccountForApiCommand(String accountName, Long domainId) thr
444444
return account;
445445
}
446446

447+
@Override
447448
public boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException {
448449
List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId());
449450
List<PublicIp> publicIps = new ArrayList<PublicIp>();
@@ -1385,7 +1386,6 @@ public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityEx
13851386
Long domainId = cmd.getDomainId();
13861387

13871388
Account owner = _accountMgr.finalizeOwner(ctxAccount, accountName, domainId);
1388-
13891389
// if end ip is not specified, default it to startIp
13901390
if (endIP == null && startIP != null) {
13911391
endIP = startIP;
@@ -1412,7 +1412,7 @@ public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityEx
14121412

14131413
// If networkDomain is not specified, take it from the global configuration
14141414
if (networkDomain == null) {
1415-
networkDomain = _networkDomain;
1415+
networkDomain = "cs"+Long.toHexString(owner.getId())+_networkDomain;
14161416
}
14171417

14181418
// Check if zone exists
@@ -1474,7 +1474,6 @@ public Network createNetwork(long networkOfferingId, String name, String display
14741474

14751475
Transaction txn = Transaction.currentTxn();
14761476
txn.start();
1477-
14781477
// Create network
14791478
DataCenterDeployment plan = new DataCenterDeployment(zoneId, null, null, null);
14801479
NetworkVO userNetwork = new NetworkVO();
@@ -2197,6 +2196,7 @@ public List<? extends PasswordResetElement> getPasswordResetElements() {
21972196
return elements;
21982197
}
21992198

2199+
@Override
22002200
public boolean zoneIsConfiguredForExternalNetworking(long zoneId) {
22012201
DataCenterVO zone = _dcDao.findById(zoneId);
22022202

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ public void run() {
670670
}
671671
}
672672

673-
private VmDataCommand generateVmDataCommand(VirtualRouter router, String vmPrivateIpAddress,
673+
private VmDataCommand generateVmDataCommand(DomainRouterVO router, String vmPrivateIpAddress,
674674
String userData, String serviceOffering, String zoneName, String guestIpAddress, String vmName, String vmInstanceName, long vmId, String publicKey) {
675675
VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress);
676676

@@ -755,7 +755,7 @@ public static boolean isAdmin(short accountType) {
755755
}
756756

757757
@Override
758-
public VirtualRouter deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map<Param, Object> params) throws InsufficientCapacityException,
758+
public DomainRouterVO deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map<Param, Object> params) throws InsufficientCapacityException,
759759
ConcurrentOperationException, ResourceUnavailableException {
760760
long dcId = dest.getDataCenter().getId();
761761

@@ -824,7 +824,7 @@ public VirtualRouter deployVirtualRouter(Network guestNetwork, DeployDestination
824824
}
825825

826826
@Override
827-
public VirtualRouter deployDhcp(Network guestNetwork, DeployDestination dest, Account owner, Map<Param, Object> params) throws InsufficientCapacityException,
827+
public DomainRouterVO deployDhcp(Network guestNetwork, DeployDestination dest, Account owner, Map<Param, Object> params) throws InsufficientCapacityException,
828828
StorageUnavailableException, ConcurrentOperationException, ResourceUnavailableException {
829829
long dcId = dest.getDataCenter().getId();
830830

@@ -994,7 +994,6 @@ public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<DomainRou
994994
router.setPublicMacAddress(nic.getMacAddress());
995995
} else if (nic.getTrafficType() == TrafficType.Guest) {
996996
router.setGuestIpAddress(nic.getIp4Address());
997-
router.setGuestMacAddress(nic.getMacAddress());
998997
} else if (nic.getTrafficType() == TrafficType.Control) {
999998
router.setPrivateIpAddress(nic.getIp4Address());
1000999
router.setPrivateMacAddress(nic.getMacAddress());
@@ -1197,7 +1196,7 @@ private DomainRouterVO stop(DomainRouterVO router, User user, Account caller) th
11971196
public VirtualRouter addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile<UserVm> profile, DeployDestination dest,
11981197
ReservationContext context, Boolean startDhcp) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
11991198

1200-
VirtualRouter router = startDhcp ? deployDhcp(network, dest, profile.getOwner(), profile.getParameters()) : deployVirtualRouter(network, dest, profile.getOwner(), profile.getParameters());
1199+
DomainRouterVO router = startDhcp ? deployDhcp(network, dest, profile.getOwner(), profile.getParameters()) : deployVirtualRouter(network, dest, profile.getOwner(), profile.getParameters());
12011200

12021201
_userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine());
12031202

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
262262
String _name;
263263
String _instance;
264264
String _zone;
265-
String _defaultNetworkDomain;
266265

267266
private ConfigurationDao _configDao;
268267

@@ -1052,14 +1051,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
10521051

10531052
Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
10541053

1055-
_defaultNetworkDomain = configs.get("domain");
1056-
if (_defaultNetworkDomain == null) {
1057-
_defaultNetworkDomain = ".myvm.com";
1058-
}
1059-
if (!_defaultNetworkDomain.startsWith(".")) {
1060-
_defaultNetworkDomain = "." + _defaultNetworkDomain;
1061-
}
1062-
10631054
_instance = configs.get("instance.name");
10641055
if (_instance == null) {
10651056
_instance = "DEFAULT";
@@ -1856,6 +1847,9 @@ public void removeInstanceFromInstanceGroup(long vmId) {
18561847
}
18571848

18581849
private boolean validPassword(String password) {
1850+
if (password == null || password.length() == 0) {
1851+
return false;
1852+
}
18591853
for (int i = 0; i < password.length(); i++) {
18601854
if (password.charAt(i) == ' ') {
18611855
return false;
@@ -1970,20 +1964,6 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE
19701964
}
19711965
}
19721966

1973-
// Check that the password was passed in and is valid
1974-
String password = PasswordGenerator.generateRandomPassword(6);
1975-
if (!template.getEnablePassword()) {
1976-
password = "saved_password";
1977-
}
1978-
if (password == null || password.equals("") || (!validPassword(password))) {
1979-
throw new InvalidParameterValueException("A valid password for this virtual machine was not provided.");
1980-
}
1981-
1982-
String networkDomain = null;
1983-
if (networkDomain == null) {
1984-
networkDomain = "v" + Long.toHexString(owner.getId()) + _defaultNetworkDomain;
1985-
}
1986-
19871967
String userData = cmd.getUserData();
19881968
byte [] decodedUserData = null;
19891969
if (userData != null) {
@@ -2140,7 +2120,7 @@ public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableExc
21402120
password = generateRandomPassword();
21412121
}
21422122

2143-
if (password == null || password.equals("") || (!validPassword(password))) {
2123+
if (!validPassword(password)) {
21442124
throw new InvalidParameterValueException("A valid password for this virtual machine was not provided.");
21452125
}
21462126

@@ -2150,7 +2130,7 @@ public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableExc
21502130
if (sshPublicKey != null && !sshPublicKey.equals("") && password != null && !password.equals("saved_password") ) {
21512131
String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey(sshPublicKey, password);
21522132
if (encryptedPasswd == null) {
2153-
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Error encrypting password");
2133+
throw new CloudRuntimeException("Error encrypting password");
21542134
}
21552135

21562136
vm.setDetail("Encrypted.Password", encryptedPasswd);
@@ -2183,14 +2163,22 @@ public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableExc
21832163

21842164
@Override
21852165
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<UserVmVO> profile, DeployDestination dest, ReservationContext context) {
2186-
UserVmVO vo = profile.getVirtualMachine();
2166+
UserVmVO vm = profile.getVirtualMachine();
2167+
Account owner = _accountDao.findById(vm.getAccountId());
2168+
2169+
if (owner == null || owner.getState() == Account.State.disabled) {
2170+
throw new PermissionDeniedException("The owner of " + vm + " either does not exist or is disabled: " + vm.getAccountId());
2171+
}
2172+
2173+
2174+
21872175
VirtualMachineTemplate template = profile.getTemplate();
2188-
if (vo.getIsoId() != null) {
2189-
template = _templateDao.findById(vo.getIsoId());
2176+
if (vm.getIsoId() != null) {
2177+
template = _templateDao.findById(vm.getIsoId());
21902178
}
2191-
if (template != null && template.getFormat() == ImageFormat.ISO && vo.getIsoId() != null) {
2179+
if (template != null && template.getFormat() == ImageFormat.ISO && vm.getIsoId() != null) {
21922180
String isoPath = null;
2193-
Pair<String, String> isoPathPair = _storageMgr.getAbsoluteIsoPath(template.getId(), vo.getDataCenterId());
2181+
Pair<String, String> isoPathPair = _storageMgr.getAbsoluteIsoPath(template.getId(), vm.getDataCenterId());
21942182
if (isoPathPair == null) {
21952183
s_logger.warn("Couldn't get absolute iso path");
21962184
return false;
@@ -2233,7 +2221,6 @@ public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<UserVmVO>
22332221
}
22342222
}
22352223
_vmDao.update(userVm.getId(), userVm);
2236-
22372224
return true;
22382225
}
22392226

‎server/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public <T extends VMInstanceVO> boolean advanceExpunge(T vm, User caller, Accoun
396396
//Clean up volumes based on the vm's instance id
397397
_storageMgr.cleanupVolumes(vm.getId());
398398

399-
VirtualMachineGuru<T> guru = (VirtualMachineGuru<T>)_vmGurus.get(vm.getType());
399+
VirtualMachineGuru<T> guru = getVmGuru(vm);
400400
guru.finalizeExpunge(vm);
401401

402402
if (s_logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)