mirror of https://github.com/apache/cloudstack.git
CS-15217: Security: Malicious user is able to get the size of the cloud by enumerating IDs
Description: 1) With this commit in the series for this bug, removed all occurrances of db IDs being passed when raising InvalidParameterValueException. 2) Renamed HyervisorTemplateAdapter.java to HypervisorTemplateAdapter.java.
This commit is contained in:
parent
57b1783764
commit
62c11df4e9
|
|
@ -25,10 +25,6 @@ public class InvalidParameterValueException extends CloudRuntimeException {
|
|||
|
||||
private static final long serialVersionUID = -2232066904895010203L;
|
||||
|
||||
public InvalidParameterValueException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidParameterValueException(String message, List<IdentityProxy> idProxyList) {
|
||||
super(message);
|
||||
if (idProxyList != null) {
|
||||
|
|
|
|||
|
|
@ -35,108 +35,108 @@ public class CreateVolumeOnFilerCmd extends BaseCmd {
|
|||
private static final String s_name = "createvolumeresponse";
|
||||
|
||||
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, required = true, description="ip address.")
|
||||
private String ipAddress;
|
||||
|
||||
private String ipAddress;
|
||||
|
||||
@Parameter(name=ApiConstants.AGGREGATE_NAME, type=CommandType.STRING, required = true, description="aggregate name.")
|
||||
private String aggrName;
|
||||
private String aggrName;
|
||||
|
||||
@Parameter(name=ApiConstants.POOL_NAME, type=CommandType.STRING, required = true, description="pool name.")
|
||||
private String poolName;
|
||||
|
||||
private String poolName;
|
||||
|
||||
@Parameter(name=ApiConstants.VOLUME_NAME, type=CommandType.STRING, required = true, description="volume name.")
|
||||
private String volName;
|
||||
|
||||
private String volName;
|
||||
|
||||
@Parameter(name=ApiConstants.SIZE, type=CommandType.INTEGER, required = true, description="volume size.")
|
||||
private Integer volSize;
|
||||
|
||||
private Integer volSize;
|
||||
|
||||
@Parameter(name=ApiConstants.SNAPSHOT_POLICY, type=CommandType.STRING, required = false, description="snapshot policy.")
|
||||
private String snapshotPolicy;
|
||||
|
||||
private String snapshotPolicy;
|
||||
|
||||
@Parameter(name=ApiConstants.SNAPSHOT_RESERVATION, type=CommandType.INTEGER, required = false, description="snapshot reservation.")
|
||||
private Integer snapshotReservation;
|
||||
|
||||
private Integer snapshotReservation;
|
||||
|
||||
@Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="user name.")
|
||||
private String userName;
|
||||
|
||||
private String userName;
|
||||
|
||||
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="password.")
|
||||
private String password;
|
||||
|
||||
private String password;
|
||||
|
||||
|
||||
public String getIpAddress() {
|
||||
return ipAddress;
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
|
||||
public String getAggrName() {
|
||||
return aggrName;
|
||||
return aggrName;
|
||||
}
|
||||
|
||||
|
||||
public String getPoolName() {
|
||||
return poolName;
|
||||
return poolName;
|
||||
}
|
||||
|
||||
|
||||
public String volName() {
|
||||
return volName;
|
||||
return volName;
|
||||
}
|
||||
|
||||
|
||||
public Integer getVolSize() {
|
||||
return volSize;
|
||||
return volSize;
|
||||
}
|
||||
|
||||
|
||||
public String getSnapshotPolicy() {
|
||||
return snapshotPolicy;
|
||||
return snapshotPolicy;
|
||||
}
|
||||
|
||||
|
||||
public Integer getSnapshotReservation() {
|
||||
return snapshotReservation;
|
||||
return snapshotReservation;
|
||||
}
|
||||
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
return userName;
|
||||
}
|
||||
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
return password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException,
|
||||
InsufficientCapacityException, ServerApiException,
|
||||
ConcurrentOperationException, ResourceAllocationException {
|
||||
//param checks
|
||||
if(snapshotReservation != null && (snapshotReservation<0 || snapshotReservation>100))
|
||||
throw new InvalidParameterValueException("Invalid snapshot reservation");
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
|
||||
NetappManager netappMgr = locator.getManager(NetappManager.class);
|
||||
|
||||
StringBuilder s = new StringBuilder(getVolSize().toString());
|
||||
s.append("g");
|
||||
|
||||
try {
|
||||
netappMgr.createVolumeOnFiler(ipAddress, aggrName, poolName, volName, s.toString(), snapshotPolicy, snapshotReservation, userName, password);
|
||||
CreateVolumeOnFilerCmdResponse response = new CreateVolumeOnFilerCmdResponse();
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} catch (ServerException e) {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.toString());
|
||||
} catch (InvalidParameterValueException e) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString());
|
||||
} catch (UnknownHostException e) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException,
|
||||
InsufficientCapacityException, ServerApiException,
|
||||
ConcurrentOperationException, ResourceAllocationException {
|
||||
//param checks
|
||||
if(snapshotReservation != null && (snapshotReservation<0 || snapshotReservation>100))
|
||||
throw new InvalidParameterValueException("Invalid snapshot reservation", null);
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
// TODO Auto-generated method stub
|
||||
return s_name;
|
||||
}
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
|
||||
NetappManager netappMgr = locator.getManager(NetappManager.class);
|
||||
|
||||
StringBuilder s = new StringBuilder(getVolSize().toString());
|
||||
s.append("g");
|
||||
|
||||
try {
|
||||
netappMgr.createVolumeOnFiler(ipAddress, aggrName, poolName, volName, s.toString(), snapshotPolicy, snapshotReservation, userName, password);
|
||||
CreateVolumeOnFilerCmdResponse response = new CreateVolumeOnFilerCmdResponse();
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} catch (ServerException e) {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.toString());
|
||||
} catch (InvalidParameterValueException e) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString());
|
||||
} catch (UnknownHostException e) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
// TODO Auto-generated method stub
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ import com.cloud.network.as.dao.AutoScalePolicyConditionMapDaoImpl;
|
|||
import com.cloud.network.as.dao.AutoScalePolicyDaoImpl;
|
||||
import com.cloud.network.as.dao.AutoScaleVmGroupDaoImpl;
|
||||
import com.cloud.network.as.dao.AutoScaleVmGroupPolicyMapDaoImpl;
|
||||
import com.cloud.network.as.dao.AutoScaleVmProfileDaoImpl;
|
||||
import com.cloud.network.as.dao.ConditionDaoImpl;
|
||||
import com.cloud.network.as.dao.CounterDaoImpl;
|
||||
import com.cloud.network.dao.CiscoNexusVSMDeviceDaoImpl;
|
||||
|
|
@ -86,7 +87,6 @@ import com.cloud.network.dao.FirewallRulesDaoImpl;
|
|||
import com.cloud.network.dao.IPAddressDaoImpl;
|
||||
import com.cloud.network.dao.InlineLoadBalancerNicMapDaoImpl;
|
||||
import com.cloud.network.dao.LBStickinessPolicyDaoImpl;
|
||||
import com.cloud.network.as.dao.AutoScaleVmProfileDaoImpl;
|
||||
import com.cloud.network.dao.LoadBalancerDaoImpl;
|
||||
import com.cloud.network.dao.LoadBalancerVMMapDaoImpl;
|
||||
import com.cloud.network.dao.NetworkDaoImpl;
|
||||
|
|
@ -182,7 +182,7 @@ import com.cloud.storage.swift.SwiftManagerImpl;
|
|||
import com.cloud.storage.upload.UploadMonitorImpl;
|
||||
import com.cloud.tags.TaggedResourceManagerImpl;
|
||||
import com.cloud.tags.dao.ResourceTagsDaoImpl;
|
||||
import com.cloud.template.HyervisorTemplateAdapter;
|
||||
import com.cloud.template.HypervisorTemplateAdapter;
|
||||
import com.cloud.template.TemplateAdapter;
|
||||
import com.cloud.template.TemplateAdapter.TemplateAdapterType;
|
||||
import com.cloud.template.TemplateManagerImpl;
|
||||
|
|
@ -439,7 +439,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
|
|||
}
|
||||
|
||||
protected void populateAdapters() {
|
||||
addAdapter(TemplateAdapter.class, TemplateAdapterType.Hypervisor.getName(), HyervisorTemplateAdapter.class);
|
||||
addAdapter(TemplateAdapter.class, TemplateAdapterType.Hypervisor.getName(), HypervisorTemplateAdapter.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ import com.cloud.network.rules.FirewallRule;
|
|||
import com.cloud.network.rules.PortForwardingRule;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.server.api.response.ExternalFirewallResponse;
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
|
@ -86,7 +86,7 @@ import com.cloud.vm.VirtualMachineProfile;
|
|||
|
||||
@Local(value = NetworkElement.class)
|
||||
public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceManagerImpl implements SourceNatServiceProvider, FirewallServiceProvider,
|
||||
PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, JuniperSRXFirewallElementService {
|
||||
PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, JuniperSRXFirewallElementService {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(JuniperSRXExternalFirewallElement.class);
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
|
||||
@Override
|
||||
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
|
||||
InsufficientNetworkCapacityException {
|
||||
InsufficientNetworkCapacityException {
|
||||
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
|
||||
|
||||
// don't have to implement network is Basic zone
|
||||
|
|
@ -168,7 +168,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
|
||||
@Override
|
||||
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
|
||||
InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +317,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
|
||||
@Override
|
||||
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException,
|
||||
ResourceUnavailableException {
|
||||
ResourceUnavailableException {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
|
@ -338,18 +338,21 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
|
||||
zone = _dcDao.findById(zoneId);
|
||||
if (zone == null) {
|
||||
throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
|
||||
throw new InvalidParameterValueException("Could not find zone by id", null);
|
||||
}
|
||||
|
||||
List<PhysicalNetworkVO> physicalNetworks = _physicalNetworkDao.listByZone(zoneId);
|
||||
if ((physicalNetworks == null) || (physicalNetworks.size() > 1)) {
|
||||
throw new InvalidParameterValueException("There are no physical networks or multiple physical networks configured in zone with ID: "
|
||||
+ zoneId + " to add this device.");
|
||||
List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
|
||||
idList.add(new IdentityProxy(zone, zoneId, "zoneId"));
|
||||
throw new InvalidParameterValueException("There are no physical networks or multiple " +
|
||||
"physical networks configured in zone with specified zoneId" +
|
||||
" to add this device.", idList);
|
||||
}
|
||||
pNetwork = physicalNetworks.get(0);
|
||||
|
||||
String deviceType = NetworkDevice.JuniperSRXFirewall.getName();
|
||||
ExternalFirewallDeviceVO fwDeviceVO = addExternalFirewall(pNetwork.getId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceType, (ServerResource) new JuniperSrxResource());
|
||||
ExternalFirewallDeviceVO fwDeviceVO = addExternalFirewall(pNetwork.getId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceType, new JuniperSrxResource());
|
||||
if (fwDeviceVO != null) {
|
||||
fwHost = _hostDao.findById(fwDeviceVO.getHostId());
|
||||
}
|
||||
|
|
@ -374,13 +377,16 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
if (zoneId != null) {
|
||||
zone = _dcDao.findById(zoneId);
|
||||
if (zone == null) {
|
||||
throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
|
||||
throw new InvalidParameterValueException("Could not find zone by id", null);
|
||||
}
|
||||
|
||||
List<PhysicalNetworkVO> physicalNetworks = _physicalNetworkDao.listByZone(zoneId);
|
||||
if ((physicalNetworks == null) || (physicalNetworks.size() > 1)) {
|
||||
throw new InvalidParameterValueException("There are no physical networks or multiple physical networks configured in zone with ID: "
|
||||
+ zoneId + " to add this device.");
|
||||
List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
|
||||
idList.add(new IdentityProxy(zone, zoneId, "zoneId"));
|
||||
throw new InvalidParameterValueException("There are no physical networks or multiple " +
|
||||
"physical networks configured in zone with specified zoneId " +
|
||||
"to add this device.", idList);
|
||||
}
|
||||
pNetwork = physicalNetworks.get(0);
|
||||
}
|
||||
|
|
@ -389,6 +395,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
return firewallHosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalFirewallResponse createExternalFirewallResponse(Host externalFirewall) {
|
||||
return super.createExternalFirewallResponse(externalFirewall);
|
||||
}
|
||||
|
|
@ -402,10 +409,10 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
public ExternalFirewallDeviceVO addSrxFirewall(AddSrxFirewallCmd cmd) {
|
||||
String deviceName = cmd.getDeviceType();
|
||||
if (!deviceName.equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) {
|
||||
throw new InvalidParameterValueException("Invalid SRX firewall device type");
|
||||
throw new InvalidParameterValueException("Invalid SRX firewall device type", null);
|
||||
}
|
||||
return addExternalFirewall(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName,
|
||||
(ServerResource) new JuniperSrxResource());
|
||||
new JuniperSrxResource());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -414,7 +421,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
|
||||
ExternalFirewallDeviceVO fwDeviceVO = _fwDevicesDao.findById(fwDeviceId);
|
||||
if (fwDeviceVO == null || !fwDeviceVO.getDeviceName().equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) {
|
||||
throw new InvalidParameterValueException("No SRX firewall device found with ID: " + fwDeviceId);
|
||||
throw new InvalidParameterValueException("No SRX firewall device found by ID", null);
|
||||
}
|
||||
return deleteExternalFirewall(fwDeviceVO.getHostId());
|
||||
}
|
||||
|
|
@ -426,7 +433,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
|
||||
ExternalFirewallDeviceVO fwDeviceVO = _fwDevicesDao.findById(fwDeviceId);
|
||||
if (fwDeviceVO == null || !fwDeviceVO.getDeviceName().equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) {
|
||||
throw new InvalidParameterValueException("No SRX firewall device found with ID: " + fwDeviceId);
|
||||
throw new InvalidParameterValueException("No SRX firewall device found by ID", null);
|
||||
}
|
||||
|
||||
if (deviceCapacity != null) {
|
||||
|
|
@ -455,13 +462,13 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
List<ExternalFirewallDeviceVO> fwDevices = new ArrayList<ExternalFirewallDeviceVO>();
|
||||
|
||||
if (physcialNetworkId == null && fwDeviceId == null) {
|
||||
throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified");
|
||||
throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified", null);
|
||||
}
|
||||
|
||||
if (fwDeviceId != null) {
|
||||
ExternalFirewallDeviceVO fwDeviceVo = _fwDevicesDao.findById(fwDeviceId);
|
||||
if (fwDeviceVo == null || !fwDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) {
|
||||
throw new InvalidParameterValueException("Could not find SRX firewall device with ID: " + fwDeviceId);
|
||||
throw new InvalidParameterValueException("Could not find SRX firewall device by ID", null);
|
||||
}
|
||||
fwDevices.add(fwDeviceVo);
|
||||
}
|
||||
|
|
@ -469,7 +476,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
if (physcialNetworkId != null) {
|
||||
pNetwork = _physicalNetworkDao.findById(physcialNetworkId);
|
||||
if (pNetwork == null) {
|
||||
throw new InvalidParameterValueException("Could not find phyical network with ID: " + physcialNetworkId);
|
||||
throw new InvalidParameterValueException("Could not find phyical network by ID", null);
|
||||
}
|
||||
fwDevices = _fwDevicesDao.listByPhysicalNetworkAndProvider(physcialNetworkId, Provider.JuniperSRX.getName());
|
||||
}
|
||||
|
|
@ -484,7 +491,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
|
||||
ExternalFirewallDeviceVO fwDeviceVo = _fwDevicesDao.findById(fwDeviceId);
|
||||
if (fwDeviceVo == null || !fwDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) {
|
||||
throw new InvalidParameterValueException("Could not find SRX firewall device with ID " + fwDeviceId);
|
||||
throw new InvalidParameterValueException("Could not find SRX firewall device by ID", null);
|
||||
}
|
||||
|
||||
List<NetworkExternalFirewallVO> networkFirewallMaps = _networkFirewallDao.listByFirewallDeviceId(fwDeviceId);
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ StaticNatServiceProvider {
|
|||
String deviceName = cmd.getDeviceType();
|
||||
|
||||
if (!isNetscalerDevice(deviceName)) {
|
||||
throw new InvalidParameterValueException("Invalid Netscaler device type");
|
||||
throw new InvalidParameterValueException("Invalid Netscaler device type", null);
|
||||
}
|
||||
|
||||
URI uri;
|
||||
|
|
@ -291,7 +291,7 @@ StaticNatServiceProvider {
|
|||
} catch (Exception e) {
|
||||
String msg = "Error parsing the url parameter specified in addNetscalerLoadBalancer command due to " + e.getMessage();
|
||||
s_logger.debug(msg);
|
||||
throw new InvalidParameterValueException(msg);
|
||||
throw new InvalidParameterValueException(msg, null);
|
||||
}
|
||||
Map<String, String> configParams = new HashMap<String, String>();
|
||||
UrlUtil.parseQueryParameters(uri.getQuery(), false, configParams);
|
||||
|
|
@ -300,7 +300,7 @@ StaticNatServiceProvider {
|
|||
if (dedicatedUse && !deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())) {
|
||||
String msg = "Only Netscaler VPX load balancers can be specified for dedicated use";
|
||||
s_logger.debug(msg);
|
||||
throw new InvalidParameterValueException(msg);
|
||||
throw new InvalidParameterValueException(msg, null);
|
||||
}
|
||||
|
||||
ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource());
|
||||
|
|
@ -313,7 +313,7 @@ StaticNatServiceProvider {
|
|||
|
||||
ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
|
||||
if ((lbDeviceVo == null) || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
|
||||
throw new InvalidParameterValueException("No netscaler device found with ID: " + lbDeviceId);
|
||||
throw new InvalidParameterValueException("No netscaler device found by ID", null);
|
||||
}
|
||||
|
||||
return deleteExternalLoadBalancer(lbDeviceVo.getHostId());
|
||||
|
|
@ -339,7 +339,7 @@ StaticNatServiceProvider {
|
|||
Map<String, String> lbDetails = _detailsDao.findDetails(lbDeviceVo.getHostId());
|
||||
|
||||
if ((lbDeviceVo == null) || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
|
||||
throw new InvalidParameterValueException("No netscaler device found with ID: " + lbDeviceId);
|
||||
throw new InvalidParameterValueException("No netscaler device found by ID", null);
|
||||
}
|
||||
|
||||
String deviceName = lbDeviceVo.getDeviceName();
|
||||
|
|
@ -347,7 +347,7 @@ StaticNatServiceProvider {
|
|||
if (NetworkDevice.NetscalerSDXLoadBalancer.getName().equalsIgnoreCase(deviceName) ||
|
||||
NetworkDevice.NetscalerMPXLoadBalancer.getName().equalsIgnoreCase(deviceName)) {
|
||||
if (dedicatedUse != null && dedicatedUse == true) {
|
||||
throw new InvalidParameterValueException("Netscaler MPX and SDX device should be shared and can not be dedicated to a single account.");
|
||||
throw new InvalidParameterValueException("Netscaler MPX and SDX device should be shared and can not be dedicated to a single account.", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -417,7 +417,7 @@ StaticNatServiceProvider {
|
|||
|
||||
ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
|
||||
if (lbDeviceVo == null || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
|
||||
throw new InvalidParameterValueException("Could not find Netscaler load balancer device with ID " + lbDeviceId);
|
||||
throw new InvalidParameterValueException("Could not find Netscaler load balancer device by ID", null);
|
||||
}
|
||||
|
||||
List<NetworkExternalLoadBalancerVO> networkLbMaps = _networkLBDao.listByLoadBalancerDeviceId(lbDeviceId);
|
||||
|
|
@ -439,13 +439,13 @@ StaticNatServiceProvider {
|
|||
List<ExternalLoadBalancerDeviceVO> lbDevices = new ArrayList<ExternalLoadBalancerDeviceVO>();
|
||||
|
||||
if (physcialNetworkId == null && lbDeviceId == null) {
|
||||
throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified");
|
||||
throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified", null);
|
||||
}
|
||||
|
||||
if (lbDeviceId != null) {
|
||||
ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
|
||||
if (lbDeviceVo == null || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
|
||||
throw new InvalidParameterValueException("Could not find Netscaler load balancer device with ID: " + lbDeviceId);
|
||||
throw new InvalidParameterValueException("Could not find Netscaler load balancer device by ID", null);
|
||||
}
|
||||
lbDevices.add(lbDeviceVo);
|
||||
return lbDevices;
|
||||
|
|
@ -454,7 +454,7 @@ StaticNatServiceProvider {
|
|||
if (physcialNetworkId != null) {
|
||||
pNetwork = _physicalNetworkDao.findById(physcialNetworkId);
|
||||
if (pNetwork == null) {
|
||||
throw new InvalidParameterValueException("Could not find phyical network with ID: " + physcialNetworkId);
|
||||
throw new InvalidParameterValueException("Could not find phyical network by ID", null);
|
||||
}
|
||||
lbDevices = _lbDeviceDao.listByPhysicalNetworkAndProvider(physcialNetworkId, Provider.Netscaler.getName());
|
||||
return lbDevices;
|
||||
|
|
|
|||
|
|
@ -134,10 +134,10 @@ import com.cloud.vm.dao.NicDao;
|
|||
|
||||
@Local(value = { ElasticLoadBalancerManager.class })
|
||||
public class ElasticLoadBalancerManagerImpl implements
|
||||
ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
|
||||
ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(ElasticLoadBalancerManagerImpl.class);
|
||||
|
||||
|
||||
@Inject
|
||||
IPAddressDao _ipAddressDao;
|
||||
@Inject
|
||||
|
|
@ -196,7 +196,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
String _instance;
|
||||
static final private String _elbVmNamePrefix = "l";
|
||||
static final private String _systemVmType = "elbvm";
|
||||
|
||||
|
||||
boolean _enabled;
|
||||
TrafficType _frontendTrafficType = TrafficType.Guest;
|
||||
|
||||
|
|
@ -205,13 +205,13 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
ScheduledExecutorService _gcThreadPool;
|
||||
String _mgmtCidr;
|
||||
String _mgmtHost;
|
||||
|
||||
|
||||
Set<Long> _gcCandidateElbVmIds = Collections.newSetFromMap(new ConcurrentHashMap<Long,Boolean>());
|
||||
|
||||
|
||||
int _elasticLbVmRamSize;
|
||||
int _elasticLbvmCpuMHz;
|
||||
int _elasticLbvmNumCpu;
|
||||
|
||||
|
||||
private Long getPodIdForDirectIp(IPAddressVO ipAddr) {
|
||||
PodVlanMapVO podVlanMaps = _podVlanMapDao.listPodVlanMapsByVlan(ipAddr.getVlanId());
|
||||
if (podVlanMaps == null) {
|
||||
|
|
@ -237,19 +237,19 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
try {
|
||||
DomainRouterVO elbVm = deployELBVm(network, dest, owner, params);
|
||||
if (elbVm == null) {
|
||||
throw new InvalidParameterValueException("Could not deploy or find existing ELB VM");
|
||||
throw new InvalidParameterValueException("Could not deploy or find existing ELB VM", null);
|
||||
}
|
||||
s_logger.debug("Deployed ELB vm = " + elbVm);
|
||||
|
||||
return elbVm;
|
||||
|
||||
|
||||
} catch (Throwable t) {
|
||||
s_logger.warn("Error while deploying ELB VM: ", t);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private boolean sendCommandsToRouter(final DomainRouterVO elbVm,
|
||||
Commands cmds) throws AgentUnavailableException {
|
||||
Answer[] answers = null;
|
||||
|
|
@ -310,7 +310,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
|
||||
cmd.lbStatsAuth = _configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key());
|
||||
cmd.lbStatsPort = _configDao.getValue(Config.NetworkLBHaproxyStatsPort.key());
|
||||
|
||||
|
||||
cmds.addCommand(cmd);
|
||||
|
||||
}
|
||||
|
|
@ -322,7 +322,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
// Send commands to elbVm
|
||||
return sendCommandsToRouter(elbVm, cmds);
|
||||
}
|
||||
|
||||
|
||||
protected DomainRouterVO findElbVmForLb(FirewallRule lb) {//TODO: use a table to lookup
|
||||
ElasticLbVmMapVO map = _elbVmMapDao.findOneByIp(lb.getSourceIpAddressId());
|
||||
if (map == null) {
|
||||
|
|
@ -332,9 +332,10 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
return elbVm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyLoadBalancerRules(Network network,
|
||||
List<? extends FirewallRule> rules)
|
||||
throws ResourceUnavailableException {
|
||||
throws ResourceUnavailableException {
|
||||
if (rules == null || rules.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -342,9 +343,9 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
s_logger.warn("ELB: Not handling non-LB firewall rules");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
DomainRouterVO elbVm = findElbVmForLb(rules.get(0));
|
||||
|
||||
|
||||
if (elbVm == null) {
|
||||
s_logger.warn("Unable to apply lb rules, ELB vm doesn't exist in the network "
|
||||
+ network.getId());
|
||||
|
|
@ -391,7 +392,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
}
|
||||
_mgmtCidr = _configDao.getValue(Config.ManagementNetwork.key());
|
||||
_mgmtHost = _configDao.getValue(Config.ManagementHostIPAdr.key());
|
||||
|
||||
|
||||
boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
|
||||
|
||||
_elasticLbVmRamSize = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmMemory.key()), DEFAULT_ELB_VM_RAMSIZE);
|
||||
|
|
@ -402,9 +403,9 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
true, null, true, VirtualMachine.Type.ElasticLoadBalancerVm, true);
|
||||
_elasticLbVmOffering.setUniqueName(ServiceOffering.elbVmDefaultOffUniqueName);
|
||||
_elasticLbVmOffering = _serviceOfferingDao.persistSystemServiceOffering(_elasticLbVmOffering);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
String enabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
|
||||
_enabled = (enabled == null) ? false: Boolean.parseBoolean(enabled);
|
||||
s_logger.info("Elastic Load balancer enabled: " + _enabled);
|
||||
|
|
@ -425,7 +426,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
_gcThreadPool.scheduleAtFixedRate(new CleanupThread(), gcIntervalMinutes, gcIntervalMinutes, TimeUnit.MINUTES);
|
||||
_itMgr.registerGuru(VirtualMachine.Type.ElasticLoadBalancerVm, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -457,9 +458,9 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public DomainRouterVO deployELBVm(Network guestNetwork, DeployDestination dest, Account owner, Map<Param, Object> params) throws
|
||||
ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
long dcId = dest.getDataCenter().getId();
|
||||
|
||||
// lock guest network
|
||||
|
|
@ -480,13 +481,13 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
s_logger.debug("Starting a ELB vm for network configurations: " + guestNetwork + " in " + dest);
|
||||
}
|
||||
assert guestNetwork.getState() == Network.State.Implemented
|
||||
|| guestNetwork.getState() == Network.State.Setup
|
||||
|| guestNetwork.getState() == Network.State.Implementing
|
||||
: "Network is not yet fully implemented: "+ guestNetwork;
|
||||
|| guestNetwork.getState() == Network.State.Setup
|
||||
|| guestNetwork.getState() == Network.State.Implementing
|
||||
: "Network is not yet fully implemented: "+ guestNetwork;
|
||||
|
||||
DataCenterDeployment plan = null;
|
||||
DomainRouterVO elbVm = null;
|
||||
|
||||
|
||||
plan = new DataCenterDeployment(dcId, dest.getPod().getId(), null, null, null, null);
|
||||
|
||||
if (elbVm == null) {
|
||||
|
|
@ -494,7 +495,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Creating the ELB vm " + id);
|
||||
}
|
||||
|
||||
|
||||
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork);
|
||||
NetworkOfferingVO controlOffering = offerings.get(0);
|
||||
NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
|
||||
|
|
@ -505,7 +506,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
networks.add(new Pair<NetworkVO, NicProfile>(controlConfig, null));
|
||||
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, guestNic));
|
||||
|
||||
|
||||
|
||||
VMTemplateVO template = _templateDao.findSystemVMTemplate(dcId);
|
||||
|
||||
String typeString = "ElasticLoadBalancerVm";
|
||||
|
|
@ -518,7 +519,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
if (vrProvider == null) {
|
||||
throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId());
|
||||
}
|
||||
|
||||
|
||||
elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(),
|
||||
VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(),
|
||||
template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN,
|
||||
|
|
@ -539,7 +540,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
_networkDao.releaseFromLockTable(guestNetworkId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DomainRouterVO start(DomainRouterVO elbVm, User user, Account caller, Map<Param, Object> params) throws StorageUnavailableException, InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
s_logger.debug("Starting ELB VM " + elbVm);
|
||||
|
|
@ -549,8 +550,8 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private DomainRouterVO stop(DomainRouterVO elbVm, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
s_logger.debug("Stopping ELB vm " + elbVm);
|
||||
try {
|
||||
|
|
@ -563,7 +564,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
throw new CloudRuntimeException("Unable to stop " + elbVm, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected List<LoadBalancerVO> findExistingLoadBalancers(String lbName, Long ipId, Long accountId, Long domainId, Integer publicPort) {
|
||||
SearchBuilder<LoadBalancerVO> sb = _lbDao.createSearchBuilder();
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -591,16 +592,16 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
sc.setParameters("publicPort", publicPort);
|
||||
}
|
||||
List<LoadBalancerVO> lbs = _lbDao.search(sc, null);
|
||||
|
||||
|
||||
return lbs == null || lbs.size()==0 ? null: lbs;
|
||||
}
|
||||
|
||||
|
||||
@DB
|
||||
public PublicIp allocDirectIp(Account account, long guestNetworkId) throws InsufficientAddressCapacityException {
|
||||
Network frontEndNetwork = _networkMgr.getNetwork(guestNetworkId);
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
|
||||
PublicIp ip = _networkMgr.assignPublicIpAddress(frontEndNetwork.getDataCenterId(), null, account, VlanType.DirectAttached, frontEndNetwork.getId(), null, true);
|
||||
IPAddressVO ipvo = _ipAddressDao.findById(ip.getId());
|
||||
ipvo.setAssociatedWithNetworkId(frontEndNetwork.getId());
|
||||
|
|
@ -610,25 +611,25 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
|
||||
return ip;
|
||||
}
|
||||
|
||||
|
||||
public void releaseIp(long ipId, long userId, Account caller) {
|
||||
s_logger.info("ELB: Release public IP for loadbalancing " + ipId);
|
||||
IPAddressVO ipvo = _ipAddressDao.findById(ipId);
|
||||
ipvo.setAssociatedWithNetworkId(null);
|
||||
_ipAddressDao.update(ipvo.getId(), ipvo);
|
||||
_networkMgr.disassociatePublicIpAddress(ipId, userId, caller);
|
||||
_ipAddressDao.unassignIpAddress(ipId);
|
||||
_networkMgr.disassociatePublicIpAddress(ipId, userId, caller);
|
||||
_ipAddressDao.unassignIpAddress(ipId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public LoadBalancer handleCreateLoadBalancerRule(CreateLoadBalancerRuleCmd lb, Account account, long networkId) throws InsufficientAddressCapacityException, NetworkRuleConflictException {
|
||||
//this part of code is executed when the LB provider is Elastic Load Balancer vm
|
||||
if (!_networkMgr.isProviderSupportServiceInNetwork(lb.getNetworkId(), Service.Lb, Provider.ElasticLoadBalancerVm)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long ipId = lb.getSourceIpAddressId();
|
||||
if (!_networkMgr.isProviderSupportServiceInNetwork(lb.getNetworkId(), Service.Lb, Provider.ElasticLoadBalancerVm)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long ipId = lb.getSourceIpAddressId();
|
||||
if (ipId != null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -646,7 +647,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
if (lb.getSourceIpAddressId() != null) {
|
||||
existingLbs = findExistingLoadBalancers(lb.getName(), null, lb.getAccountId(), lb.getDomainId(), null);
|
||||
if (existingLbs != null) {
|
||||
throw new InvalidParameterValueException("Supplied LB name " + lb.getName() + " is not associated with IP " + lb.getSourceIpAddressId() );
|
||||
throw new InvalidParameterValueException("Supplied LB name " + lb.getName() + " is not associated with IP " + lb.getSourceIpAddressId(), null);
|
||||
}
|
||||
} else {
|
||||
s_logger.debug("Could not find any existing frontend ips for this account for this LB rule, acquiring a new frontent IP for ELB");
|
||||
|
|
@ -665,7 +666,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
|
||||
Network network = _networkMgr.getNetwork(networkId);
|
||||
IPAddressVO ipAddr = _ipAddressDao.findById(ipId);
|
||||
|
||||
|
||||
LoadBalancer result = null;
|
||||
try {
|
||||
lb.setSourceIpAddressId(ipId);
|
||||
|
|
@ -698,26 +699,26 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
elbVm = _routerDao.findById(elbVmMap.getElbVmId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (elbVm == null) {
|
||||
s_logger.warn("No ELB VM can be found or deployed");
|
||||
s_logger.warn("Deleting LB since we failed to deploy ELB VM");
|
||||
_lbDao.remove(result.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
ElasticLbVmMapVO mapping = new ElasticLbVmMapVO(ipId, elbVm.getId(), result.getId());
|
||||
_elbVmMapDao.persist(mapping);
|
||||
return result;
|
||||
|
||||
|
||||
} finally {
|
||||
if (account != null) {
|
||||
_accountDao.releaseFromLockTable(account.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void garbageCollectUnusedElbVms() {
|
||||
List<DomainRouterVO> unusedElbVms = _elbVmMapDao.listUnusedElbVms();
|
||||
if (unusedElbVms != null && unusedElbVms.size() > 0)
|
||||
|
|
@ -759,12 +760,12 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
}
|
||||
_gcCandidateElbVmIds = currentGcCandidates;
|
||||
}
|
||||
|
||||
|
||||
public class CleanupThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
garbageCollectUnusedElbVms();
|
||||
|
||||
|
||||
}
|
||||
|
||||
CleanupThread() {
|
||||
|
|
@ -784,7 +785,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public DomainRouterVO findByName(String name) {
|
||||
if (!VirtualMachineName.isValidSystemVmName(name, _instance, _elbVmNamePrefix)) {
|
||||
|
|
@ -810,7 +811,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
@Override
|
||||
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest, ReservationContext context) {
|
||||
DomainRouterVO elbVm = profile.getVirtualMachine();
|
||||
|
||||
|
||||
List<NicProfile> elbNics = profile.getNics();
|
||||
Long guestNtwkId = null;
|
||||
for (NicProfile routerNic : elbNics) {
|
||||
|
|
@ -819,7 +820,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NetworkVO guestNetwork = _networkDao.findById(guestNtwkId);
|
||||
|
||||
DataCenter dc = dest.getDataCenter();
|
||||
|
|
@ -876,7 +877,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
if (defaultDns2 != null) {
|
||||
buf.append(" dns2=").append(defaultDns2);
|
||||
}
|
||||
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Boot Args for " + profile + ": " + buf.toString());
|
||||
}
|
||||
|
|
@ -930,7 +931,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
|
||||
NicProfile controlNic = null;
|
||||
Long guestNetworkId = null;
|
||||
|
||||
|
||||
if(profile.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic) {
|
||||
// TODO this is a ugly to test hypervisor type here
|
||||
// for basic network mode, we will use the guest NIC for control NIC
|
||||
|
|
@ -984,7 +985,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
processStopOrRebootAnswer(elbVm, answer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void processStopOrRebootAnswer(final DomainRouterVO elbVm, Answer answer) {
|
||||
//TODO: process network usage stats
|
||||
}
|
||||
|
|
@ -993,7 +994,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
@Override
|
||||
public void finalizeExpunge(DomainRouterVO vm) {
|
||||
// no-op
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1004,7 +1005,7 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
|
||||
return VirtualMachineName.getSystemVmId(vmName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
|
||||
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
|
||||
|
|
@ -1022,17 +1023,17 @@ public class ElasticLoadBalancerManagerImpl implements
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void prepareStop(VirtualMachineProfile<DomainRouterVO> profile) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void prepareStop(VirtualMachineProfile<DomainRouterVO> profile) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean recreateNeeded(
|
||||
VirtualMachineProfile<DomainRouterVO> profile, long hostId,
|
||||
Commands cmds, ReservationContext context) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean recreateNeeded(
|
||||
VirtualMachineProfile<DomainRouterVO> profile, long hostId,
|
||||
Commands cmds, ReservationContext context) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
|||
serviceResponse.setName(service.getName());
|
||||
if ("Lb".equalsIgnoreCase(service.getName())) {
|
||||
Map<Capability, String> serviceCapabilities = serviceCapabilitiesMap
|
||||
.get(service);
|
||||
.get(service);
|
||||
if (serviceCapabilities != null) {
|
||||
for (Capability capability : serviceCapabilities
|
||||
.keySet()) {
|
||||
|
|
@ -260,15 +260,15 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
|||
String csUrl = _configDao.getValue(Config.EndpointeUrl.key());
|
||||
|
||||
if(apiKey == null) {
|
||||
throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it");
|
||||
throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it", null);
|
||||
}
|
||||
|
||||
if(secretKey == null) {
|
||||
throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it");
|
||||
throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it", null);
|
||||
}
|
||||
|
||||
if(csUrl == null || csUrl.contains("localhost")) {
|
||||
throw new InvalidParameterValueException("Global setting endpointe.url has to be set to the Management Server's API end point");
|
||||
throw new InvalidParameterValueException("Global setting endpointe.url has to be set to the Management Server's API end point", null);
|
||||
}
|
||||
|
||||
LbAutoScaleVmProfile lbAutoScaleVmProfile = new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl);
|
||||
|
|
@ -922,7 +922,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
|||
try {
|
||||
if (ipVO.getAssociatedWithNetworkId() == null) {
|
||||
boolean assignToVpcNtwk = network.getVpcId() != null
|
||||
&& ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
|
||||
&& ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
|
||||
if (assignToVpcNtwk) {
|
||||
// set networkId just for verification purposes
|
||||
_networkMgr.checkIpForService(ipVO, Service.Lb, lb.getNetworkId());
|
||||
|
|
@ -936,7 +936,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
|||
}
|
||||
|
||||
if (ipVO.getAssociatedWithNetworkId() == null) {
|
||||
throw new InvalidParameterValueException("Ip address " + ipVO + " is not assigned to the network " + network);
|
||||
throw new InvalidParameterValueException("Ip address " + ipVO + " is not assigned to the network " + network, null);
|
||||
}
|
||||
|
||||
if (lb.getSourceIpAddressId() == null) {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -209,9 +209,9 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
|||
} else {
|
||||
_networkMgr.checkIpForService(ipAddress, Service.PortForwarding, null);
|
||||
}
|
||||
|
||||
|
||||
if (ipAddress.getAssociatedWithNetworkId() == null) {
|
||||
throw new InvalidParameterValueException("Ip address " + ipAddress + " is not assigned to the network " + network);
|
||||
throw new InvalidParameterValueException("Ip address " + ipAddress + " is not assigned to the network " + network, null);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -295,9 +295,9 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
|||
//if the rule is the last one for the ip address assigned to VPC, unassign it from the network
|
||||
IpAddress ip = _ipAddressDao.findById(ipAddress.getId());
|
||||
_networkMgr.unassignIPFromVpcNetwork(ip.getId(), networkId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
|
|
@ -418,7 +418,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
|||
if (network == null) {
|
||||
throw new InvalidParameterValueException("Unable to find network by id", null);
|
||||
}
|
||||
|
||||
|
||||
// Check that vm has a nic in the network
|
||||
Nic guestNic = _networkMgr.getNicInNetwork(vmId, networkId);
|
||||
if (guestNic == null) {
|
||||
|
|
@ -433,7 +433,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
|||
throw new InvalidParameterValueException("Unable to create static nat rule; StaticNat service is not " +
|
||||
"supported in network with specified id", idList);
|
||||
}
|
||||
|
||||
|
||||
if (!isSystemVm) {
|
||||
//associate ip address to network (if needed)
|
||||
if (ipAddress.getAssociatedWithNetworkId() == null) {
|
||||
|
|
@ -441,7 +441,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
|||
&& ipAddress.getVpcId() != null && ipAddress.getVpcId().longValue() == network.getVpcId();
|
||||
if (assignToVpcNtwk) {
|
||||
_networkMgr.checkIpForService(ipAddress, Service.StaticNat, networkId);
|
||||
|
||||
|
||||
s_logger.debug("The ip is not associated with the VPC network id="+ networkId + ", so assigning");
|
||||
try {
|
||||
ipAddress = _networkMgr.associateIPToGuestNetwork(ipId, networkId, false);
|
||||
|
|
@ -455,18 +455,18 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
|||
} else {
|
||||
_networkMgr.checkIpForService(ipAddress, Service.StaticNat, null);
|
||||
}
|
||||
|
||||
|
||||
if (ipAddress.getAssociatedWithNetworkId() == null) {
|
||||
throw new InvalidParameterValueException("Ip address " + ipAddress + " is not assigned to the network " + network);
|
||||
throw new InvalidParameterValueException("Ip address " + ipAddress + " is not assigned to the network " + network, null);
|
||||
}
|
||||
|
||||
// Check permissions
|
||||
checkIpAndUserVm(ipAddress, vm, caller);
|
||||
|
||||
|
||||
// Verify ip address parameter
|
||||
isIpReadyForStaticNat(vmId, ipAddress, caller, ctx.getCallerUserId());
|
||||
}
|
||||
|
||||
|
||||
ipAddress.setOneToOneNat(true);
|
||||
ipAddress.setAssociatedWithVmId(vmId);
|
||||
|
||||
|
|
@ -480,21 +480,21 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
|||
}
|
||||
} else {
|
||||
s_logger.warn("Failed to update ip address " + ipAddress + " in the DB as a part of enableStaticNat");
|
||||
|
||||
|
||||
}
|
||||
} finally {
|
||||
if (!result) {
|
||||
ipAddress.setOneToOneNat(false);
|
||||
ipAddress.setAssociatedWithVmId(null);
|
||||
_ipAddressDao.update(ipAddress.getId(), ipAddress);
|
||||
|
||||
|
||||
if (performedIpAssoc) {
|
||||
//if the rule is the last one for the ip address assigned to VPC, unassign it from the network
|
||||
IpAddress ip = _ipAddressDao.findById(ipAddress.getId());
|
||||
_networkMgr.unassignIPFromVpcNetwork(ip.getId(), networkId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -1395,9 +1395,9 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
|||
}
|
||||
|
||||
protected void removePFRule(PortForwardingRuleVO rule) {
|
||||
|
||||
|
||||
_portForwardingDao.remove(rule.getId());
|
||||
|
||||
|
||||
//if the rule is the last one for the ip address assigned to VPC, unassign it from the network
|
||||
IpAddress ip = _ipAddressDao.findById(rule.getSourceIpAddressId());
|
||||
_networkMgr.unassignIPFromVpcNetwork(ip.getId(), rule.getNetworkId());
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
Map<String, String> configs = configDao.getConfiguration(params);
|
||||
String value = configs.get(Config.VpcCleanupInterval.key());
|
||||
_cleanupInterval = NumbersUtil.parseInt(value, 60 * 60); // 1 hour
|
||||
|
||||
|
||||
String maxNtwks = configs.get(Config.VpcMaxNetworks.key());
|
||||
_maxNetworks = NumbersUtil.parseInt(maxNtwks, 3); // max=3 is default
|
||||
return true;
|
||||
|
|
@ -978,8 +978,8 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
throw new CloudRuntimeException("Number of networks per VPC can't extend "
|
||||
+ _maxNetworks + "; increase it using global config " + Config.VpcMaxNetworks);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//1) CIDR is required
|
||||
if (cidr == null) {
|
||||
throw new InvalidParameterValueException("Gateway/netmask are required when create network for VPC", null);
|
||||
|
|
@ -1021,17 +1021,17 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
throw new InvalidParameterValueException("Network domain of the new network should match network" +
|
||||
" domain of vpc with specified vpcId", idList);
|
||||
}
|
||||
|
||||
|
||||
//6) gateway should never be equal to the cidr subnet
|
||||
if (NetUtils.getCidrSubNet(cidr).equalsIgnoreCase(gateway)) {
|
||||
throw new InvalidParameterValueException("Invalid gateway specified. It should never be equal to the cidr subnet value");
|
||||
throw new InvalidParameterValueException("Invalid gateway specified. It should never be equal to the cidr subnet value", null);
|
||||
}
|
||||
//7) gateway should never be equal to the cidr broadcast ip
|
||||
if (NetUtils.getCidrBroadcastIp(cidr).equalsIgnoreCase(gateway)) {
|
||||
throw new InvalidParameterValueException("Invalid gateway specified. It should never be equal to the cidr broadcast ip");
|
||||
throw new InvalidParameterValueException("Invalid gateway specified. It should never be equal to the cidr broadcast ip", null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} finally {
|
||||
s_logger.debug("Releasing lock for " + locked);
|
||||
_vpcDao.releaseFromLockTable(locked.getId());
|
||||
|
|
@ -1062,7 +1062,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
_s2sVpnMgr.cleanupVpnConnectionByVpc(vpcId);
|
||||
s_logger.debug("Cleaning up existed site to site VPN gateways");
|
||||
_s2sVpnMgr.cleanupVpnGatewayByVpc(vpcId);
|
||||
|
||||
|
||||
//2) release all ip addresses
|
||||
List<IPAddressVO> ipsToRelease = _ipAddressDao.listByAssociatedVpc(vpcId, null);
|
||||
s_logger.debug("Releasing ips for vpc id=" + vpcId + " as a part of vpc cleanup");
|
||||
|
|
@ -1680,9 +1680,10 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
public VpcGateway getPrivateGatewayForVpc(long vpcId) {
|
||||
return _vpcGatewayDao.getPrivateGatewayForVpc(vpcId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMaxNetworksPerVpc() {
|
||||
return _maxNetworks;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import com.cloud.user.Account;
|
|||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.utils.IdentityProxy;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
|
@ -96,21 +97,21 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
|||
Long domainId = cmd.getDomainId();
|
||||
String accountName = cmd.getAccountName();
|
||||
Account userAccount = null;
|
||||
Account caller = (Account)UserContext.current().getCaller();
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Long usageType = cmd.getUsageType();
|
||||
Long projectId = cmd.getProjectId();
|
||||
|
||||
|
||||
if (projectId != null) {
|
||||
if (accountId != null) {
|
||||
throw new InvalidParameterValueException("Projectid and accountId can't be specified together");
|
||||
throw new InvalidParameterValueException("Projectid and accountId can't be specified together", null);
|
||||
}
|
||||
Project project = _projectMgr.getProject(projectId);
|
||||
if (project == null) {
|
||||
throw new InvalidParameterValueException("Unable to find project by id " + projectId);
|
||||
throw new InvalidParameterValueException("Unable to find project by id", null);
|
||||
}
|
||||
accountId = project.getProjectAccountId();
|
||||
}
|
||||
|
||||
|
||||
//if accountId is not specified, use accountName and domainId
|
||||
if ((accountId == null) && (accountName != null) && (domainId != null)) {
|
||||
if (_domainDao.isChildDomain(caller.getDomainId(), domainId)) {
|
||||
|
|
@ -121,8 +122,10 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
|||
}
|
||||
if (userAccount != null) {
|
||||
accountId = userAccount.getId();
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
|
||||
} else {
|
||||
List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
|
||||
idList.add(new IdentityProxy("domain", domainId, "domainId"));
|
||||
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId, idList);
|
||||
}
|
||||
} else {
|
||||
throw new PermissionDeniedException("Invalid Domain Id or Account");
|
||||
|
|
@ -130,7 +133,7 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
|||
}
|
||||
|
||||
boolean isAdmin = false;
|
||||
|
||||
|
||||
//If accountId couldn't be found using accountName and domainId, get it from userContext
|
||||
if(accountId == null){
|
||||
accountId = caller.getId();
|
||||
|
|
@ -145,7 +148,7 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
|||
Date startDate = cmd.getStartDate();
|
||||
Date endDate = cmd.getEndDate();
|
||||
if(startDate.after(endDate)){
|
||||
throw new InvalidParameterValueException("Incorrect Date Range. Start date: "+startDate+" is after end date:"+endDate);
|
||||
throw new InvalidParameterValueException("Incorrect Date Range. Start date: "+startDate+" is after end date:"+endDate, null);
|
||||
}
|
||||
TimeZone usageTZ = getUsageTimezone();
|
||||
Date adjustedStartDate = computeAdjustedTime(startDate, usageTZ, true);
|
||||
|
|
@ -156,7 +159,7 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
|||
}
|
||||
|
||||
Filter usageFilter = new Filter(UsageVO.class, "startDate", false, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
|
||||
|
||||
SearchCriteria<UsageVO> sc = _usageDao.createSearchCriteria();
|
||||
|
||||
if (accountId != -1 && accountId != Account.ACCOUNT_ID_SYSTEM && !isAdmin) {
|
||||
|
|
@ -166,7 +169,7 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
|||
if (domainId != null) {
|
||||
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
|
||||
}
|
||||
|
||||
|
||||
if (usageType != null) {
|
||||
sc.addAnd("usageType", SearchCriteria.Op.EQ, usageType);
|
||||
}
|
||||
|
|
@ -241,8 +244,8 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
|||
return calTS.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UsageTypeResponse> listUsageTypes() {
|
||||
return UsageTypes.listUsageTypes();
|
||||
}
|
||||
@Override
|
||||
public List<UsageTypeResponse> listUsageTypes() {
|
||||
return UsageTypes.listUsageTypes();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,290 +0,0 @@
|
|||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by the License.
|
||||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.template;
|
||||
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.storage.DeleteTemplateCommand;
|
||||
import com.cloud.api.commands.DeleteIsoCmd;
|
||||
import com.cloud.api.commands.DeleteTemplateCmd;
|
||||
import com.cloud.api.commands.RegisterIsoCmd;
|
||||
import com.cloud.api.commands.RegisterTemplateCmd;
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.UsageEventVO;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VMTemplateZoneVO;
|
||||
import com.cloud.storage.download.DownloadMonitor;
|
||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Local(value=TemplateAdapter.class)
|
||||
public class HyervisorTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter {
|
||||
private final static Logger s_logger = Logger.getLogger(HyervisorTemplateAdapter.class);
|
||||
@Inject DownloadMonitor _downloadMonitor;
|
||||
@Inject SecondaryStorageVmManager _ssvmMgr;
|
||||
@Inject AgentManager _agentMgr;
|
||||
|
||||
private String validateUrl(String url) {
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("http")
|
||||
&& !uri.getScheme().equalsIgnoreCase("https") && !uri.getScheme().equalsIgnoreCase("file"))) {
|
||||
throw new IllegalArgumentException("Unsupported scheme for url: " + url);
|
||||
}
|
||||
|
||||
int port = uri.getPort();
|
||||
if (!(port == 80 || port == 443 || port == -1)) {
|
||||
throw new IllegalArgumentException("Only ports 80 and 443 are allowed");
|
||||
}
|
||||
String host = uri.getHost();
|
||||
try {
|
||||
InetAddress hostAddr = InetAddress.getByName(host);
|
||||
if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() || hostAddr.isMulticastAddress()) {
|
||||
throw new IllegalArgumentException("Illegal host specified in url");
|
||||
}
|
||||
if (hostAddr instanceof Inet6Address) {
|
||||
throw new IllegalArgumentException("IPV6 addresses not supported (" + hostAddr.getHostAddress() + ")");
|
||||
}
|
||||
} catch (UnknownHostException uhe) {
|
||||
throw new IllegalArgumentException("Unable to resolve " + host);
|
||||
}
|
||||
|
||||
return uri.toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid URL " + url);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException {
|
||||
TemplateProfile profile = super.prepare(cmd);
|
||||
String url = profile.getUrl();
|
||||
|
||||
if((!url.toLowerCase().endsWith("iso"))&&(!url.toLowerCase().endsWith("iso.zip"))&&(!url.toLowerCase().endsWith("iso.bz2"))
|
||||
&&(!url.toLowerCase().endsWith("iso.gz"))){
|
||||
throw new InvalidParameterValueException("Please specify a valid iso");
|
||||
}
|
||||
|
||||
profile.setUrl(validateUrl(url));
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
|
||||
TemplateProfile profile = super.prepare(cmd);
|
||||
String url = profile.getUrl();
|
||||
|
||||
if((!url.toLowerCase().endsWith("vhd"))&&(!url.toLowerCase().endsWith("vhd.zip"))
|
||||
&&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2"))&&(!url.toLowerCase().endsWith("qcow2.zip"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2.bz2"))&&(!url.toLowerCase().endsWith("qcow2.gz"))
|
||||
&&(!url.toLowerCase().endsWith("ova"))&&(!url.toLowerCase().endsWith("ova.zip"))
|
||||
&&(!url.toLowerCase().endsWith("ova.bz2"))&&(!url.toLowerCase().endsWith("ova.gz"))
|
||||
&&(!url.toLowerCase().endsWith("img"))&&(!url.toLowerCase().endsWith("raw"))){
|
||||
throw new InvalidParameterValueException("Please specify a valid "+ cmd.getFormat().toLowerCase());
|
||||
}
|
||||
|
||||
if ((cmd.getFormat().equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith("vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith("vhd.gz") ))
|
||||
|| (cmd.getFormat().equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url.toLowerCase().endsWith("qcow2.gz") ))
|
||||
|| (cmd.getFormat().equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase().endsWith("ova.gz")))
|
||||
|| (cmd.getFormat().equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase().endsWith("raw")))) {
|
||||
throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + cmd.getFormat().toLowerCase());
|
||||
}
|
||||
|
||||
profile.setUrl(validateUrl(url));
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMTemplateVO create(TemplateProfile profile) {
|
||||
VMTemplateVO template = persistTemplate(profile);
|
||||
|
||||
if (template == null) {
|
||||
throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate());
|
||||
}
|
||||
|
||||
_downloadMonitor.downloadTemplateToStorage(template, profile.getZoneId());
|
||||
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public boolean delete(TemplateProfile profile) {
|
||||
boolean success = true;
|
||||
|
||||
VMTemplateVO template = profile.getTemplate();
|
||||
Long zoneId = profile.getZoneId();
|
||||
Long templateId = template.getId();
|
||||
|
||||
String zoneName;
|
||||
List<HostVO> secondaryStorageHosts;
|
||||
if (!template.isCrossZones() && zoneId != null) {
|
||||
DataCenterVO zone = _dcDao.findById(zoneId);
|
||||
zoneName = zone.getName();
|
||||
secondaryStorageHosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(zoneId);
|
||||
} else {
|
||||
zoneName = "(all zones)";
|
||||
secondaryStorageHosts = _ssvmMgr.listSecondaryStorageHostsInAllZones();
|
||||
}
|
||||
|
||||
s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
|
||||
|
||||
// Make sure the template is downloaded to all the necessary secondary storage hosts
|
||||
for (HostVO secondaryStorageHost : secondaryStorageHosts) {
|
||||
long hostId = secondaryStorageHost.getId();
|
||||
List<VMTemplateHostVO> templateHostVOs = _tmpltHostDao.listByHostTemplate(hostId, templateId);
|
||||
for (VMTemplateHostVO templateHostVO : templateHostVOs) {
|
||||
if (templateHostVO.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
|
||||
String errorMsg = "Please specify a template that is not currently being downloaded.";
|
||||
s_logger.debug("Template: " + template.getName() + " is currently being downloaded to secondary storage host: " + secondaryStorageHost.getName() + "; cant' delete it.");
|
||||
throw new CloudRuntimeException(errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
|
||||
String eventType = "";
|
||||
|
||||
if (template.getFormat().equals(ImageFormat.ISO)){
|
||||
eventType = EventTypes.EVENT_ISO_DELETE;
|
||||
} else {
|
||||
eventType = EventTypes.EVENT_TEMPLATE_DELETE;
|
||||
}
|
||||
|
||||
// Iterate through all necessary secondary storage hosts and mark the template on each host as destroyed
|
||||
for (HostVO secondaryStorageHost : secondaryStorageHosts) {
|
||||
long hostId = secondaryStorageHost.getId();
|
||||
long sZoneId = secondaryStorageHost.getDataCenterId();
|
||||
List<VMTemplateHostVO> templateHostVOs = _tmpltHostDao.listByHostTemplate(hostId, templateId);
|
||||
for (VMTemplateHostVO templateHostVO : templateHostVOs) {
|
||||
VMTemplateHostVO lock = _tmpltHostDao.acquireInLockTable(templateHostVO.getId());
|
||||
try {
|
||||
if (lock == null) {
|
||||
s_logger.debug("Failed to acquire lock when deleting templateHostVO with ID: " + templateHostVO.getId());
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), sZoneId, templateId, null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
templateHostVO.setDestroyed(true);
|
||||
_tmpltHostDao.update(templateHostVO.getId(), templateHostVO);
|
||||
String installPath = templateHostVO.getInstallPath();
|
||||
if (installPath != null) {
|
||||
Answer answer = _agentMgr.sendToSecStorage(secondaryStorageHost, new DeleteTemplateCommand(secondaryStorageHost.getStorageUrl(), installPath));
|
||||
|
||||
if (answer == null || !answer.getResult()) {
|
||||
s_logger.debug("Failed to delete " + templateHostVO + " due to " + ((answer == null) ? "answer is null" : answer.getDetails()));
|
||||
} else {
|
||||
_tmpltHostDao.remove(templateHostVO.getId());
|
||||
s_logger.debug("Deleted template at: " + installPath);
|
||||
}
|
||||
} else {
|
||||
_tmpltHostDao.remove(templateHostVO.getId());
|
||||
}
|
||||
VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(sZoneId, templateId);
|
||||
|
||||
if (templateZone != null) {
|
||||
_tmpltZoneDao.remove(templateZone.getId());
|
||||
}
|
||||
} finally {
|
||||
if (lock != null) {
|
||||
_tmpltHostDao.releaseFromLockTable(lock.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
|
||||
|
||||
// If there are no more non-destroyed template host entries for this template, delete it
|
||||
if (success && (_tmpltHostDao.listByTemplateId(templateId).size() == 0)) {
|
||||
long accountId = template.getAccountId();
|
||||
|
||||
VMTemplateVO lock = _tmpltDao.acquireInLockTable(templateId);
|
||||
|
||||
try {
|
||||
if (lock == null) {
|
||||
s_logger.debug("Failed to acquire lock when deleting template with ID: " + templateId);
|
||||
success = false;
|
||||
} else if (_tmpltDao.remove(templateId)) {
|
||||
// Decrement the number of templates
|
||||
_resourceLimitMgr.decrementResourceCount(accountId, ResourceType.template);
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (lock != null) {
|
||||
_tmpltDao.releaseFromLockTable(lock.getId());
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed.");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) {
|
||||
TemplateProfile profile = super.prepareDelete(cmd);
|
||||
VMTemplateVO template = profile.getTemplate();
|
||||
Long zoneId = profile.getZoneId();
|
||||
|
||||
if (template.getTemplateType() == TemplateType.SYSTEM) {
|
||||
throw new InvalidParameterValueException("The DomR template cannot be deleted.");
|
||||
}
|
||||
|
||||
if (zoneId != null && (_ssvmMgr.findSecondaryStorageHost(zoneId) == null)) {
|
||||
throw new InvalidParameterValueException("Failed to find a secondary storage host in the specified zone.");
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
|
||||
TemplateProfile profile = super.prepareDelete(cmd);
|
||||
Long zoneId = profile.getZoneId();
|
||||
|
||||
if (zoneId != null && (_ssvmMgr.findSecondaryStorageHost(zoneId) == null)) {
|
||||
throw new InvalidParameterValueException("Failed to find a secondary storage host in the specified zone.");
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,292 @@
|
|||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by the License.
|
||||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.template;
|
||||
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.storage.DeleteTemplateCommand;
|
||||
import com.cloud.api.commands.DeleteIsoCmd;
|
||||
import com.cloud.api.commands.DeleteTemplateCmd;
|
||||
import com.cloud.api.commands.RegisterIsoCmd;
|
||||
import com.cloud.api.commands.RegisterTemplateCmd;
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.UsageEventVO;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VMTemplateZoneVO;
|
||||
import com.cloud.storage.download.DownloadMonitor;
|
||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Local(value=TemplateAdapter.class)
|
||||
public class HypervisorTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter {
|
||||
private final static Logger s_logger = Logger.getLogger(HypervisorTemplateAdapter.class);
|
||||
@Inject DownloadMonitor _downloadMonitor;
|
||||
@Inject SecondaryStorageVmManager _ssvmMgr;
|
||||
@Inject AgentManager _agentMgr;
|
||||
|
||||
private String validateUrl(String url) {
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("http")
|
||||
&& !uri.getScheme().equalsIgnoreCase("https") && !uri.getScheme().equalsIgnoreCase("file"))) {
|
||||
throw new IllegalArgumentException("Unsupported scheme for url: " + url);
|
||||
}
|
||||
|
||||
int port = uri.getPort();
|
||||
if (!(port == 80 || port == 443 || port == -1)) {
|
||||
throw new IllegalArgumentException("Only ports 80 and 443 are allowed");
|
||||
}
|
||||
String host = uri.getHost();
|
||||
try {
|
||||
InetAddress hostAddr = InetAddress.getByName(host);
|
||||
if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() || hostAddr.isMulticastAddress()) {
|
||||
throw new IllegalArgumentException("Illegal host specified in url");
|
||||
}
|
||||
if (hostAddr instanceof Inet6Address) {
|
||||
throw new IllegalArgumentException("IPV6 addresses not supported (" + hostAddr.getHostAddress() + ")");
|
||||
}
|
||||
} catch (UnknownHostException uhe) {
|
||||
throw new IllegalArgumentException("Unable to resolve " + host);
|
||||
}
|
||||
|
||||
return uri.toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid URL " + url);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException {
|
||||
TemplateProfile profile = super.prepare(cmd);
|
||||
String url = profile.getUrl();
|
||||
|
||||
if((!url.toLowerCase().endsWith("iso"))&&(!url.toLowerCase().endsWith("iso.zip"))&&(!url.toLowerCase().endsWith("iso.bz2"))
|
||||
&&(!url.toLowerCase().endsWith("iso.gz"))){
|
||||
throw new InvalidParameterValueException("Please specify a valid iso", null);
|
||||
}
|
||||
|
||||
profile.setUrl(validateUrl(url));
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
|
||||
TemplateProfile profile = super.prepare(cmd);
|
||||
String url = profile.getUrl();
|
||||
|
||||
if((!url.toLowerCase().endsWith("vhd"))&&(!url.toLowerCase().endsWith("vhd.zip"))
|
||||
&&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2"))&&(!url.toLowerCase().endsWith("qcow2.zip"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2.bz2"))&&(!url.toLowerCase().endsWith("qcow2.gz"))
|
||||
&&(!url.toLowerCase().endsWith("ova"))&&(!url.toLowerCase().endsWith("ova.zip"))
|
||||
&&(!url.toLowerCase().endsWith("ova.bz2"))&&(!url.toLowerCase().endsWith("ova.gz"))
|
||||
&&(!url.toLowerCase().endsWith("img"))&&(!url.toLowerCase().endsWith("raw"))){
|
||||
throw new InvalidParameterValueException("Please specify a valid "+ cmd.getFormat().toLowerCase(), null);
|
||||
}
|
||||
|
||||
if ((cmd.getFormat().equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith("vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith("vhd.gz") ))
|
||||
|| (cmd.getFormat().equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url.toLowerCase().endsWith("qcow2.gz") ))
|
||||
|| (cmd.getFormat().equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase().endsWith("ova.gz")))
|
||||
|| (cmd.getFormat().equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase().endsWith("raw")))) {
|
||||
throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + cmd.getFormat().toLowerCase(), null);
|
||||
}
|
||||
|
||||
profile.setUrl(validateUrl(url));
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMTemplateVO create(TemplateProfile profile) {
|
||||
VMTemplateVO template = persistTemplate(profile);
|
||||
|
||||
if (template == null) {
|
||||
throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate());
|
||||
}
|
||||
|
||||
_downloadMonitor.downloadTemplateToStorage(template, profile.getZoneId());
|
||||
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public boolean delete(TemplateProfile profile) {
|
||||
boolean success = true;
|
||||
|
||||
VMTemplateVO template = profile.getTemplate();
|
||||
Long zoneId = profile.getZoneId();
|
||||
Long templateId = template.getId();
|
||||
|
||||
String zoneName;
|
||||
List<HostVO> secondaryStorageHosts;
|
||||
if (!template.isCrossZones() && zoneId != null) {
|
||||
DataCenterVO zone = _dcDao.findById(zoneId);
|
||||
zoneName = zone.getName();
|
||||
secondaryStorageHosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(zoneId);
|
||||
} else {
|
||||
zoneName = "(all zones)";
|
||||
secondaryStorageHosts = _ssvmMgr.listSecondaryStorageHostsInAllZones();
|
||||
}
|
||||
|
||||
s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
|
||||
|
||||
// Make sure the template is downloaded to all the necessary secondary storage hosts
|
||||
for (HostVO secondaryStorageHost : secondaryStorageHosts) {
|
||||
long hostId = secondaryStorageHost.getId();
|
||||
List<VMTemplateHostVO> templateHostVOs = _tmpltHostDao.listByHostTemplate(hostId, templateId);
|
||||
for (VMTemplateHostVO templateHostVO : templateHostVOs) {
|
||||
if (templateHostVO.getDownloadState() == Status.DOWNLOAD_IN_PROGRESS) {
|
||||
String errorMsg = "Please specify a template that is not currently being downloaded.";
|
||||
s_logger.debug("Template: " + template.getName() + " is currently being downloaded to secondary storage host: " + secondaryStorageHost.getName() + "; cant' delete it.");
|
||||
throw new CloudRuntimeException(errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
|
||||
String eventType = "";
|
||||
|
||||
if (template.getFormat().equals(ImageFormat.ISO)){
|
||||
eventType = EventTypes.EVENT_ISO_DELETE;
|
||||
} else {
|
||||
eventType = EventTypes.EVENT_TEMPLATE_DELETE;
|
||||
}
|
||||
|
||||
// Iterate through all necessary secondary storage hosts and mark the template on each host as destroyed
|
||||
for (HostVO secondaryStorageHost : secondaryStorageHosts) {
|
||||
long hostId = secondaryStorageHost.getId();
|
||||
long sZoneId = secondaryStorageHost.getDataCenterId();
|
||||
List<VMTemplateHostVO> templateHostVOs = _tmpltHostDao.listByHostTemplate(hostId, templateId);
|
||||
for (VMTemplateHostVO templateHostVO : templateHostVOs) {
|
||||
VMTemplateHostVO lock = _tmpltHostDao.acquireInLockTable(templateHostVO.getId());
|
||||
try {
|
||||
if (lock == null) {
|
||||
s_logger.debug("Failed to acquire lock when deleting templateHostVO with ID: " + templateHostVO.getId());
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), sZoneId, templateId, null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
templateHostVO.setDestroyed(true);
|
||||
_tmpltHostDao.update(templateHostVO.getId(), templateHostVO);
|
||||
String installPath = templateHostVO.getInstallPath();
|
||||
if (installPath != null) {
|
||||
Answer answer = _agentMgr.sendToSecStorage(secondaryStorageHost, new DeleteTemplateCommand(secondaryStorageHost.getStorageUrl(), installPath));
|
||||
|
||||
if (answer == null || !answer.getResult()) {
|
||||
s_logger.debug("Failed to delete " + templateHostVO + " due to " + ((answer == null) ? "answer is null" : answer.getDetails()));
|
||||
} else {
|
||||
_tmpltHostDao.remove(templateHostVO.getId());
|
||||
s_logger.debug("Deleted template at: " + installPath);
|
||||
}
|
||||
} else {
|
||||
_tmpltHostDao.remove(templateHostVO.getId());
|
||||
}
|
||||
VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(sZoneId, templateId);
|
||||
|
||||
if (templateZone != null) {
|
||||
_tmpltZoneDao.remove(templateZone.getId());
|
||||
}
|
||||
} finally {
|
||||
if (lock != null) {
|
||||
_tmpltHostDao.releaseFromLockTable(lock.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
|
||||
|
||||
// If there are no more non-destroyed template host entries for this template, delete it
|
||||
if (success && (_tmpltHostDao.listByTemplateId(templateId).size() == 0)) {
|
||||
long accountId = template.getAccountId();
|
||||
|
||||
VMTemplateVO lock = _tmpltDao.acquireInLockTable(templateId);
|
||||
|
||||
try {
|
||||
if (lock == null) {
|
||||
s_logger.debug("Failed to acquire lock when deleting template with ID: " + templateId);
|
||||
success = false;
|
||||
} else if (_tmpltDao.remove(templateId)) {
|
||||
// Decrement the number of templates
|
||||
_resourceLimitMgr.decrementResourceCount(accountId, ResourceType.template);
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (lock != null) {
|
||||
_tmpltDao.releaseFromLockTable(lock.getId());
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed.");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) {
|
||||
TemplateProfile profile = super.prepareDelete(cmd);
|
||||
VMTemplateVO template = profile.getTemplate();
|
||||
Long zoneId = profile.getZoneId();
|
||||
|
||||
if (template.getTemplateType() == TemplateType.SYSTEM) {
|
||||
throw new InvalidParameterValueException("The DomR template cannot be deleted.", null);
|
||||
}
|
||||
|
||||
if (zoneId != null && (_ssvmMgr.findSecondaryStorageHost(zoneId) == null)) {
|
||||
throw new InvalidParameterValueException("Failed to find a secondary storage host in the specified zone.", null);
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
|
||||
TemplateProfile profile = super.prepareDelete(cmd);
|
||||
Long zoneId = profile.getZoneId();
|
||||
|
||||
if (zoneId != null && (_ssvmMgr.findSecondaryStorageHost(zoneId) == null)) {
|
||||
throw new InvalidParameterValueException("Failed to find a secondary storage host in the specified zone.", null);
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -133,7 +133,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager
|
|||
|
||||
DomainVO parentDomain = _domainDao.findById(parentId);
|
||||
if (parentDomain == null) {
|
||||
throw new InvalidParameterValueException("Unable to create domain " + name + ", parent domain " + parentId + " not found.");
|
||||
throw new InvalidParameterValueException("Unable to create domain " + name + ", parent domain not found.", null);
|
||||
}
|
||||
|
||||
if (parentDomain.getState().equals(Domain.State.Inactive)) {
|
||||
|
|
@ -154,7 +154,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager
|
|||
if (!NetUtils.verifyDomainName(networkDomain)) {
|
||||
throw new InvalidParameterValueException(
|
||||
"Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', "
|
||||
+ "and the hyphen ('-'); can't start or end with \"-\"");
|
||||
+ "and the hyphen ('-'); can't start or end with \"-\"", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager
|
|||
List<DomainVO> domains = _domainDao.search(sc, null);
|
||||
|
||||
if (!domains.isEmpty()) {
|
||||
throw new InvalidParameterValueException("Domain with name " + name + " already exists for the parent id=" + parentId);
|
||||
throw new InvalidParameterValueException("Domain with name " + name + " already exists for the parent id=" + parentId, null);
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
|
@ -206,7 +206,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager
|
|||
DomainVO domain = _domainDao.findById(domainId);
|
||||
|
||||
if (domain == null) {
|
||||
throw new InvalidParameterValueException("Failed to delete domain " + domainId + ", domain not found");
|
||||
throw new InvalidParameterValueException("Failed to delete domain: domain not found", null);
|
||||
} else if (domainId == DomainVO.ROOT_DOMAIN) {
|
||||
throw new PermissionDeniedException("Can't delete ROOT domain");
|
||||
}
|
||||
|
|
@ -354,7 +354,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager
|
|||
if (domainId != null) {
|
||||
Domain domain = getDomain(domainId);
|
||||
if (domain == null) {
|
||||
throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
|
||||
throw new InvalidParameterValueException("Domain doesn't exist", null);
|
||||
}
|
||||
_accountMgr.checkAccess(caller, domain);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -34,73 +34,75 @@ import com.cloud.utils.db.Transaction;
|
|||
@Local(value={IdentityDao.class})
|
||||
public class IdentityDaoImpl extends GenericDaoBase<IdentityVO, Long> implements IdentityDao {
|
||||
private static final Logger s_logger = Logger.getLogger(IdentityDaoImpl.class);
|
||||
|
||||
|
||||
public IdentityDaoImpl() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public Long getIdentityId(IdentityMapper mapper, String identityString) {
|
||||
assert(mapper.entityTableName() != null);
|
||||
return getIdentityId(mapper.entityTableName(), identityString);
|
||||
}
|
||||
|
||||
public Long getIdentityId(IdentityMapper mapper, String identityString) {
|
||||
assert(mapper.entityTableName() != null);
|
||||
return getIdentityId(mapper.entityTableName(), identityString);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public Long getIdentityId(String tableName, String identityString) {
|
||||
assert(tableName != null);
|
||||
assert(identityString != null);
|
||||
assert(tableName != null);
|
||||
assert(identityString != null);
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
try {
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(String.format("SELECT uuid FROM `%s`", tableName));
|
||||
pstmt.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
throw new InvalidParameterValueException("uuid field doesn't exist in table " + tableName);
|
||||
}
|
||||
|
||||
pstmt = txn.prepareAutoCloseStatement(
|
||||
String.format("SELECT id FROM `%s` WHERE id=? OR uuid=?", tableName)
|
||||
|
||||
// TODO : after graceful period, use following line turn on more secure check
|
||||
// String.format("SELECT id FROM %s WHERE (id=? AND uuid IS NULL) OR uuid=?", mapper.entityTableName())
|
||||
);
|
||||
|
||||
long id = 0;
|
||||
try {
|
||||
// TODO : use regular expression to determine
|
||||
id = Long.parseLong(identityString);
|
||||
} catch(NumberFormatException e) {
|
||||
// this could happen when it is a uuid string, so catch and ignore it
|
||||
}
|
||||
|
||||
pstmt.setLong(1, id);
|
||||
pstmt.setString(2, identityString);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if(rs.next()) {
|
||||
return rs.getLong(1);
|
||||
} else {
|
||||
if(id == -1L)
|
||||
return id;
|
||||
|
||||
throw new InvalidParameterValueException("Object " + tableName + "(uuid: " + identityString + ") does not exist.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
s_logger.error("Unexpected exception ", e);
|
||||
}
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
return null;
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
try {
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(String.format("SELECT uuid FROM `%s`", tableName));
|
||||
pstmt.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
throw new InvalidParameterValueException("uuid field doesn't exist in table " + tableName, null);
|
||||
}
|
||||
|
||||
pstmt = txn.prepareAutoCloseStatement(
|
||||
String.format("SELECT id FROM `%s` WHERE id=? OR uuid=?", tableName)
|
||||
|
||||
// TODO : after graceful period, use following line turn on more secure check
|
||||
// String.format("SELECT id FROM %s WHERE (id=? AND uuid IS NULL) OR uuid=?", mapper.entityTableName())
|
||||
);
|
||||
|
||||
long id = 0;
|
||||
try {
|
||||
// TODO : use regular expression to determine
|
||||
id = Long.parseLong(identityString);
|
||||
} catch(NumberFormatException e) {
|
||||
// this could happen when it is a uuid string, so catch and ignore it
|
||||
}
|
||||
|
||||
pstmt.setLong(1, id);
|
||||
pstmt.setString(2, identityString);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if(rs.next()) {
|
||||
return rs.getLong(1);
|
||||
} else {
|
||||
if(id == -1L)
|
||||
return id;
|
||||
|
||||
throw new InvalidParameterValueException("Object " + tableName + "(uuid: " + identityString + ") does not exist.", null);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
s_logger.error("Unexpected exception ", e);
|
||||
}
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@DB
|
||||
@Override
|
||||
public Pair<Long, Long> getAccountDomainInfo(String tableName, Long identityId, TaggedResourceType resourceType) {
|
||||
assert(tableName != null);
|
||||
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
|
|
@ -116,7 +118,7 @@ public class IdentityDaoImpl extends GenericDaoBase<IdentityVO, Long> implements
|
|||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
|
||||
|
||||
//get accountId
|
||||
try {
|
||||
String account = "account_id";
|
||||
|
|
@ -136,55 +138,56 @@ public class IdentityDaoImpl extends GenericDaoBase<IdentityVO, Long> implements
|
|||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DB
|
||||
@Override
|
||||
public String getIdentityUuid(String tableName, String identityString) {
|
||||
assert(tableName != null);
|
||||
assert(identityString != null);
|
||||
|
||||
public String getIdentityUuid(String tableName, String identityString) {
|
||||
assert(tableName != null);
|
||||
assert(identityString != null);
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(
|
||||
String.format("SELECT uuid FROM `%s` WHERE id=? OR uuid=?", tableName)
|
||||
// String.format("SELECT uuid FROM %s WHERE (id=? AND uuid IS NULL) OR uuid=?", tableName)
|
||||
);
|
||||
|
||||
long id = 0;
|
||||
try {
|
||||
// TODO : use regular expression to determine
|
||||
id = Long.parseLong(identityString);
|
||||
} catch(NumberFormatException e) {
|
||||
// this could happen when it is a uuid string, so catch and ignore it
|
||||
}
|
||||
|
||||
pstmt.setLong(1, id);
|
||||
pstmt.setString(2, identityString);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if(rs.next()) {
|
||||
String uuid = rs.getString(1);
|
||||
if(uuid != null && !uuid.isEmpty())
|
||||
return uuid;
|
||||
return identityString;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
s_logger.error("Unexpected exception ", e);
|
||||
}
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
|
||||
return identityString;
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(
|
||||
String.format("SELECT uuid FROM `%s` WHERE id=? OR uuid=?", tableName)
|
||||
// String.format("SELECT uuid FROM %s WHERE (id=? AND uuid IS NULL) OR uuid=?", tableName)
|
||||
);
|
||||
|
||||
long id = 0;
|
||||
try {
|
||||
// TODO : use regular expression to determine
|
||||
id = Long.parseLong(identityString);
|
||||
} catch(NumberFormatException e) {
|
||||
// this could happen when it is a uuid string, so catch and ignore it
|
||||
}
|
||||
|
||||
pstmt.setLong(1, id);
|
||||
pstmt.setString(2, identityString);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if(rs.next()) {
|
||||
String uuid = rs.getString(1);
|
||||
if(uuid != null && !uuid.isEmpty())
|
||||
return uuid;
|
||||
return identityString;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
s_logger.error("Unexpected exception ", e);
|
||||
}
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
|
||||
return identityString;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public void initializeDefaultUuid(String tableName) {
|
||||
assert(tableName != null);
|
||||
List<Long> l = getNullUuidRecords(tableName);
|
||||
|
||||
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
try {
|
||||
|
|
@ -201,19 +204,19 @@ public class IdentityDaoImpl extends GenericDaoBase<IdentityVO, Long> implements
|
|||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DB
|
||||
List<Long> getNullUuidRecords(String tableName) {
|
||||
List<Long> l = new ArrayList<Long>();
|
||||
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(
|
||||
String.format("SELECT id FROM `%s` WHERE uuid IS NULL", tableName)
|
||||
);
|
||||
|
||||
String.format("SELECT id FROM `%s` WHERE uuid IS NULL", tableName)
|
||||
);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while(rs.next()) {
|
||||
l.add(rs.getLong(1));
|
||||
|
|
@ -226,16 +229,16 @@ public class IdentityDaoImpl extends GenericDaoBase<IdentityVO, Long> implements
|
|||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
@DB
|
||||
void setInitialUuid(String tableName, long id) throws SQLException {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
|
||||
PreparedStatement pstmtUpdate = null;
|
||||
pstmtUpdate = txn.prepareAutoCloseStatement(
|
||||
String.format("UPDATE `%s` SET uuid=? WHERE id=?", tableName)
|
||||
);
|
||||
|
||||
String.format("UPDATE `%s` SET uuid=? WHERE id=?", tableName)
|
||||
);
|
||||
|
||||
pstmtUpdate.setString(1, UUID.randomUUID().toString());
|
||||
pstmtUpdate.setLong(2, id);
|
||||
pstmtUpdate.executeUpdate();
|
||||
|
|
|
|||
|
|
@ -3590,7 +3590,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
// Validate physical network
|
||||
PhysicalNetwork physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
|
||||
if (physicalNetwork == null) {
|
||||
throw new InvalidParameterValueException("Unable to find physical network with id: "+physicalNetworkId + " and tag: " +requiredOfferings.get(0).getTags());
|
||||
throw new InvalidParameterValueException("Unable to find physical network by id and tag: " +requiredOfferings.get(0).getTags(), null);
|
||||
}
|
||||
|
||||
s_logger.debug("Creating network for account " + newAccount + " from the network offering id=" +
|
||||
|
|
|
|||
|
|
@ -281,7 +281,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Allocating nics for " + vm);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
_networkMgr.allocate(vmProfile, networks);
|
||||
} catch (ConcurrentOperationException e) {
|
||||
|
|
@ -669,7 +669,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
|
||||
if (!pool.isInMaintenance()) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
|
|
@ -703,7 +703,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, template, offering, account, params);
|
||||
DeployDestination dest = null;
|
||||
for (DeploymentPlanner planner : _planners) {
|
||||
|
|
@ -754,7 +754,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
if(!reuseVolume){
|
||||
reuseVolume = true;
|
||||
}
|
||||
|
||||
|
||||
Commands cmds = null;
|
||||
vmGuru.finalizeVirtualMachineProfile(vmProfile, dest, ctx);
|
||||
|
||||
|
|
@ -773,10 +773,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
_workDao.updateStep(work, Step.Starting);
|
||||
|
||||
_agentMgr.send(destHostId, cmds);
|
||||
|
||||
|
||||
_workDao.updateStep(work, Step.Started);
|
||||
|
||||
|
||||
|
||||
|
||||
StartAnswer startAnswer = cmds.getAnswer(StartAnswer.class);
|
||||
if (startAnswer != null && startAnswer.getResult()) {
|
||||
String host_guid = startAnswer.getHost_guid();
|
||||
|
|
@ -800,7 +800,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.info("The guru did not like the answers so stopping " + vm);
|
||||
}
|
||||
|
||||
|
||||
StopCommand cmd = new StopCommand(vm.getInstanceName());
|
||||
StopAnswer answer = (StopAnswer) _agentMgr.easySend(destHostId, cmd);
|
||||
if (answer == null || !answer.getResult()) {
|
||||
|
|
@ -809,14 +809,14 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
throw new ExecutionException("Unable to stop " + vm + " so we are unable to retry the start operation");
|
||||
}
|
||||
if (vmGuru.recreateNeeded(vmProfile, destHostId, cmds, ctx)) {
|
||||
recreate = true;
|
||||
recreate = true;
|
||||
} else {
|
||||
throw new ExecutionException("Unable to start " + vm + " due to error in finalizeStart, not retrying");
|
||||
throw new ExecutionException("Unable to start " + vm + " due to error in finalizeStart, not retrying");
|
||||
}
|
||||
}
|
||||
}
|
||||
s_logger.info("Unable to start VM on " + dest.getHost() + " due to " + (startAnswer == null ? " no start answer" : startAnswer.getDetails()));
|
||||
|
||||
|
||||
} catch (OperationTimedoutException e) {
|
||||
s_logger.debug("Unable to send the start command to host " + dest.getHost());
|
||||
if (e.isActive()) {
|
||||
|
|
@ -1073,7 +1073,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
|
||||
vmGuru.prepareStop(profile);
|
||||
|
||||
|
||||
StopCommand stop = new StopCommand(vm, vm.getInstanceName(), null);
|
||||
boolean stopped = false;
|
||||
StopAnswer answer = null;
|
||||
|
|
@ -1644,7 +1644,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
commands.addCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (final AgentVmInfo left : infos.values()) {
|
||||
boolean found = false;
|
||||
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : _vmGurus.values()) {
|
||||
|
|
@ -1740,7 +1740,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
|
||||
public void fullSync(final long clusterId, Map<String, Pair<String, State>> newStates) {
|
||||
if (newStates==null)return;
|
||||
if (newStates==null)return;
|
||||
Map<Long, AgentVmInfo> infos = convertToInfos(newStates);
|
||||
Set<VMInstanceVO> set_vms = Collections.synchronizedSet(new HashSet<VMInstanceVO>());
|
||||
set_vms.addAll(_vmDao.listByClusterId(clusterId));
|
||||
|
|
@ -1751,11 +1751,11 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
AgentVmInfo info = infos.remove(vm.getId());
|
||||
VMInstanceVO castedVm = null;
|
||||
if ((info == null && (vm.getState() == State.Running || vm.getState() == State.Starting))
|
||||
|| (info != null && (info.state == State.Running && vm.getState() == State.Starting)))
|
||||
|| (info != null && (info.state == State.Running && vm.getState() == State.Starting)))
|
||||
{
|
||||
s_logger.info("Found vm " + vm.getInstanceName() + " in inconsistent state. " + vm.getState() + " on CS while " + (info == null ? "Stopped" : "Running") + " on agent");
|
||||
s_logger.info("Found vm " + vm.getInstanceName() + " in inconsistent state. " + vm.getState() + " on CS while " + (info == null ? "Stopped" : "Running") + " on agent");
|
||||
info = new AgentVmInfo(vm.getInstanceName(), getVmGuru(vm), vm, State.Stopped);
|
||||
|
||||
|
||||
// Bug 13850- grab outstanding work item if any for this VM state so that we mark it as DONE after we change VM state, else it will remain pending
|
||||
ItWorkVO work = _workDao.findByOutstandingWork(vm.getId(), vm.getState());
|
||||
if (work != null) {
|
||||
|
|
@ -1764,8 +1764,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
}
|
||||
vm.setState(State.Running); // set it as running and let HA take care of it
|
||||
_vmDao.persist(vm);
|
||||
|
||||
_vmDao.persist(vm);
|
||||
|
||||
if (work != null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Updating outstanding work item to Done, id:" + work.getId());
|
||||
|
|
@ -1773,7 +1773,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
work.setStep(Step.Done);
|
||||
_workDao.update(work.getId(), work);
|
||||
}
|
||||
|
||||
|
||||
castedVm = info.guru.findById(vm.getId());
|
||||
try {
|
||||
Host host = _hostDao.findByGuid(info.getHostUuid());
|
||||
|
|
@ -1792,38 +1792,38 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
}
|
||||
else if (info != null && (vm.getState() == State.Stopped || vm.getState() == State.Stopping)) {
|
||||
Host host = _hostDao.findByGuid(info.getHostUuid());
|
||||
if (host != null){
|
||||
Host host = _hostDao.findByGuid(info.getHostUuid());
|
||||
if (host != null){
|
||||
s_logger.warn("Stopping a VM which is stopped/stopping " + info.name);
|
||||
vm.setState(State.Stopped); // set it as stop and clear it from host
|
||||
vm.setHostId(null);
|
||||
_vmDao.persist(vm);
|
||||
try {
|
||||
Answer answer = _agentMgr.send(host.getId(), cleanup(info.name));
|
||||
if (!answer.getResult()) {
|
||||
s_logger.warn("Unable to stop a VM due to " + answer.getDetails());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
s_logger.warn("Unable to stop a VM due to " + e.getMessage());
|
||||
}
|
||||
}
|
||||
try {
|
||||
Answer answer = _agentMgr.send(host.getId(), cleanup(info.name));
|
||||
if (!answer.getResult()) {
|
||||
s_logger.warn("Unable to stop a VM due to " + answer.getDetails());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
s_logger.warn("Unable to stop a VM due to " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
// host id can change
|
||||
if (info != null && vm.getState() == State.Running){
|
||||
// check for host id changes
|
||||
Host host = _hostDao.findByGuid(info.getHostUuid());
|
||||
if (host != null && (vm.getHostId() == null || host.getId() != vm.getHostId())){
|
||||
s_logger.info("Found vm " + vm.getInstanceName() + " with inconsistent host in db, new host is " + host.getId());
|
||||
try {
|
||||
stateTransitTo(vm, VirtualMachine.Event.AgentReportMigrated, host.getId());
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.warn(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
/* else if(info == null && vm.getState() == State.Stopping) { //Handling CS-13376
|
||||
// host id can change
|
||||
if (info != null && vm.getState() == State.Running){
|
||||
// check for host id changes
|
||||
Host host = _hostDao.findByGuid(info.getHostUuid());
|
||||
if (host != null && (vm.getHostId() == null || host.getId() != vm.getHostId())){
|
||||
s_logger.info("Found vm " + vm.getInstanceName() + " with inconsistent host in db, new host is " + host.getId());
|
||||
try {
|
||||
stateTransitTo(vm, VirtualMachine.Event.AgentReportMigrated, host.getId());
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.warn(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
/* else if(info == null && vm.getState() == State.Stopping) { //Handling CS-13376
|
||||
s_logger.warn("Marking the VM as Stopped as it was still stopping on the CS" +vm.getName());
|
||||
vm.setState(State.Stopped); // Setting the VM as stopped on the DB and clearing it from the host
|
||||
vm.setLastHostId(vm.getHostId());
|
||||
|
|
@ -1833,7 +1833,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
|
||||
for (final AgentVmInfo left : infos.values()) {
|
||||
if (VirtualMachineName.isValidVmName(left.name)) continue; // if the vm follows cloudstack naming ignore it for stopping
|
||||
if (VirtualMachineName.isValidVmName(left.name)) continue; // if the vm follows cloudstack naming ignore it for stopping
|
||||
try {
|
||||
Host host = _hostDao.findByGuid(left.getHostUuid());
|
||||
if (host != null){
|
||||
|
|
@ -1861,7 +1861,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
boolean is_alien_vm = true;
|
||||
long alien_vm_count = -1;
|
||||
for (Map.Entry<String, Pair<String, State>> entry : newStates.entrySet()) {
|
||||
is_alien_vm = true;
|
||||
is_alien_vm = true;
|
||||
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : vmGurus) {
|
||||
String name = entry.getKey();
|
||||
VMInstanceVO vm = vmGuru.findByName(name);
|
||||
|
|
@ -1879,8 +1879,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
// alien VMs
|
||||
if (is_alien_vm){
|
||||
map.put(alien_vm_count--, new AgentVmInfo(entry.getKey(), null, null, entry.getValue().second(), entry.getValue().first()));
|
||||
s_logger.warn("Found an alien VM " + entry.getKey());
|
||||
map.put(alien_vm_count--, new AgentVmInfo(entry.getKey(), null, null, entry.getValue().second(), entry.getValue().first()));
|
||||
s_logger.warn("Found an alien VM " + entry.getKey());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
|
|
@ -2262,13 +2262,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
Long clusterId = agent.getClusterId();
|
||||
long agentId = agent.getId();
|
||||
if (agent.getHypervisorType() == HypervisorType.XenServer) { // only for Xen
|
||||
StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
|
||||
HashMap<String, Pair<String, State>> allStates = startup.getClusterVMStateChanges();
|
||||
if (allStates != null){
|
||||
this.fullSync(clusterId, allStates);
|
||||
}
|
||||
|
||||
// initiate the cron job
|
||||
StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
|
||||
HashMap<String, Pair<String, State>> allStates = startup.getClusterVMStateChanges();
|
||||
if (allStates != null){
|
||||
this.fullSync(clusterId, allStates);
|
||||
}
|
||||
|
||||
// initiate the cron job
|
||||
ClusterSyncCommand syncCmd = new ClusterSyncCommand(Integer.parseInt(Config.ClusterDeltaSyncInterval.getDefaultValue()), clusterId);
|
||||
try {
|
||||
long seq_no = _agentMgr.send(agentId, new Commands(syncCmd), this);
|
||||
|
|
@ -2370,31 +2370,31 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
public VMInstanceVO findById(long vmId) {
|
||||
return _vmDao.findById(vmId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void checkIfCanUpgrade(VirtualMachine vmInstance, long newServiceOfferingId) {
|
||||
ServiceOfferingVO newServiceOffering = _offeringDao.findById(newServiceOfferingId);
|
||||
if (newServiceOffering == null) {
|
||||
throw new InvalidParameterValueException("Unable to find a service offering with id " + newServiceOfferingId);
|
||||
throw new InvalidParameterValueException("Unable to find a service offering by id", null);
|
||||
}
|
||||
|
||||
// Check that the VM is stopped
|
||||
if (!vmInstance.getState().equals(State.Stopped)) {
|
||||
s_logger.warn("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState());
|
||||
throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + " " +
|
||||
"in state " + vmInstance.getState()
|
||||
+ "; make sure the virtual machine is stopped and not in an error state before upgrading.");
|
||||
"in state " + vmInstance.getState()
|
||||
+ "; make sure the virtual machine is stopped and not in an error state before upgrading.", null);
|
||||
}
|
||||
|
||||
// Check if the service offering being upgraded to is what the VM is already running with
|
||||
if (vmInstance.getServiceOfferingId() == newServiceOffering.getId()) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Not upgrading vm " + vmInstance.toString() + " since it already has the requested " +
|
||||
"service offering (" + newServiceOffering.getName() + ")");
|
||||
"service offering (" + newServiceOffering.getName() + ")");
|
||||
}
|
||||
|
||||
throw new InvalidParameterValueException("Not upgrading vm " + vmInstance.toString() + " since it already " +
|
||||
"has the requested service offering (" + newServiceOffering.getName() + ")");
|
||||
"has the requested service offering (" + newServiceOffering.getName() + ")", null);
|
||||
}
|
||||
|
||||
ServiceOfferingVO currentServiceOffering = _offeringDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
|
||||
|
|
@ -2414,19 +2414,19 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString()
|
||||
+ ", cannot switch between local storage and shared storage service offerings. Current offering " +
|
||||
"useLocalStorage=" + currentServiceOffering.getUseLocalStorage()
|
||||
+ ", target offering useLocalStorage=" + newServiceOffering.getUseLocalStorage());
|
||||
+ ", target offering useLocalStorage=" + newServiceOffering.getUseLocalStorage(), null);
|
||||
}
|
||||
|
||||
|
||||
// if vm is a system vm, check if it is a system service offering, if yes return with error as it cannot be used for user vms
|
||||
if (currentServiceOffering.getSystemUse() != newServiceOffering.getSystemUse()) {
|
||||
throw new InvalidParameterValueException("isSystem property is different for current service offering and new service offering");
|
||||
throw new InvalidParameterValueException("isSystem property is different for current service offering and new service offering", null);
|
||||
}
|
||||
|
||||
// Check that there are enough resources to upgrade the service offering
|
||||
if (!isVirtualMachineUpgradable(vmInstance, newServiceOffering)) {
|
||||
throw new InvalidParameterValueException("Unable to upgrade virtual machine, not enough resources available " +
|
||||
"for an offering of " + newServiceOffering.getCpu() + " cpu(s) at "
|
||||
+ newServiceOffering.getSpeed() + " Mhz, and " + newServiceOffering.getRamSize() + " MB of memory");
|
||||
"for an offering of " + newServiceOffering.getCpu() + " cpu(s) at "
|
||||
+ newServiceOffering.getSpeed() + " Mhz, and " + newServiceOffering.getRamSize() + " MB of memory", null);
|
||||
}
|
||||
|
||||
// Check that the service offering being upgraded to has all the tags of the current service offering
|
||||
|
|
@ -2434,12 +2434,12 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
List<String> newTags = _configMgr.csvTagsToList(newServiceOffering.getTags());
|
||||
if (!newTags.containsAll(currentTags)) {
|
||||
throw new InvalidParameterValueException("Unable to upgrade virtual machine; the new service offering " +
|
||||
"does not have all the tags of the "
|
||||
"does not have all the tags of the "
|
||||
+ "current service offering. Current service offering tags: " + currentTags + "; " + "new service " +
|
||||
"offering tags: " + newTags);
|
||||
"offering tags: " + newTags, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean upgradeVmDb(long vmId, long serviceOfferingId) {
|
||||
VMInstanceVO vmForUpdate = _vmDao.createForUpdate();
|
||||
|
|
@ -2450,38 +2450,38 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
vmForUpdate.setServiceOfferingId(newSvcOff.getId());
|
||||
return _vmDao.update(vmId, vmForUpdate);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
|
||||
ResourceUnavailableException, InsufficientCapacityException {
|
||||
|
||||
ResourceUnavailableException, InsufficientCapacityException {
|
||||
|
||||
s_logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested);
|
||||
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
|
||||
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
|
||||
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
|
||||
|
||||
|
||||
VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null,
|
||||
null, null, null);
|
||||
|
||||
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
Host host = _hostDao.findById(vm.getHostId());
|
||||
DeployDestination dest = new DeployDestination(dc, null, null, host);
|
||||
|
||||
|
||||
//check vm state
|
||||
if (vm.getState() == State.Running) {
|
||||
//1) allocate and prepare nic
|
||||
NicProfile nic = _networkMgr.createNicForVm(network, requested, context, vmProfile, true);
|
||||
|
||||
|
||||
//2) Convert vmProfile to vmTO
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
|
||||
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
|
||||
|
||||
|
||||
//3) Convert nicProfile to NicTO
|
||||
NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
|
||||
|
||||
|
||||
//4) plug the nic to the vm
|
||||
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
|
||||
|
||||
|
||||
s_logger.debug("Plugging nic for vm " + vm + " in network " + network);
|
||||
if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) {
|
||||
s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now");
|
||||
|
|
@ -2504,40 +2504,40 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
@Override
|
||||
public NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType) {
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(hypervisorType);
|
||||
|
||||
|
||||
NicTO nicTO = hvGuru.toNicTO(nic);
|
||||
return nicTO;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
|
||||
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
|
||||
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
|
||||
|
||||
|
||||
VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null,
|
||||
null, null, null);
|
||||
|
||||
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
Host host = _hostDao.findById(vm.getHostId());
|
||||
DeployDestination dest = new DeployDestination(dc, null, null, host);
|
||||
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
|
||||
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
|
||||
|
||||
|
||||
Nic nic = null;
|
||||
|
||||
|
||||
if (broadcastUri != null) {
|
||||
nic = _nicsDao.findByNetworkIdInstanceIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri.toString());
|
||||
} else {
|
||||
nic = _networkMgr.getNicInNetwork(vm.getId(), network.getId());
|
||||
}
|
||||
|
||||
|
||||
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
|
||||
_networkMgr.getNetworkRate(network.getId(), vm.getId()),
|
||||
_networkMgr.isSecurityGroupSupportedInNetwork(network),
|
||||
_networkMgr.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
|
||||
|
||||
|
||||
//1) Unplug the nic
|
||||
NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
|
||||
s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network);
|
||||
|
|
@ -2548,14 +2548,14 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//2) Release the nic
|
||||
_networkMgr.releaseNic(vmProfile, nic);
|
||||
s_logger.debug("Successfully released nic " + nic + "for vm " + vm);
|
||||
|
||||
|
||||
//3) Remove the nic
|
||||
_networkMgr.removeNic(vmProfile, nic);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue