Harmony among gurus

This commit is contained in:
Alex Huang 2010-11-03 16:31:51 -07:00
parent 8e54a40b46
commit e27bb550fe
80 changed files with 1221 additions and 987 deletions

View File

@ -20,8 +20,8 @@ package com.cloud.agent.api.to;
import java.util.Map;
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
public class VirtualMachineTO {
private long id;
@ -39,25 +39,25 @@ public class VirtualMachineTO {
String[] bootupScripts;
boolean rebootOnCrash;
Monitor monitor;
VolumeTO[] disks;
NicTO[] nics;
public VirtualMachineTO(VirtualMachineProfile profile, BootloaderType bootloader) {
this.id = profile.getId();
this.type = profile.getType();
this.cpus = profile.getCpus();
this.minRam = profile.getRam();
this.maxRam = profile.getRam();
this.speed = profile.getSpeed();
this.os = profile.getOs();
this.name = profile.getName();
public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader, String os) {
this.id = id;
this.name = instanceName;
this.type = type;
this.cpus = cpus;
this.speed = speed;
this.minRam = minRam;
this.maxRam = maxRam;
this.bootloader = bootloader;
this.os = os;
}
protected VirtualMachineTO() {
}
public long getId() {
return id;
}
@ -69,11 +69,11 @@ public class VirtualMachineTO {
public String getName() {
return name;
}
public Monitor getMonitor() {
return monitor;
}
public void setMonitor(Monitor monitor) {
this.monitor = monitor;
}
@ -81,7 +81,7 @@ public class VirtualMachineTO {
public void setName(String name) {
this.name = name;
}
public Type getType() {
return type;
}
@ -101,11 +101,11 @@ public class VirtualMachineTO {
public void setCpus(int cpus) {
this.cpus = cpus;
}
public Integer getSpeed() {
return speed;
}
public long getMinRam() {
return minRam;
}
@ -142,7 +142,7 @@ public class VirtualMachineTO {
public void setOs(String os) {
this.os = os;
}
public String getBootArgs() {
StringBuilder buf = new StringBuilder(bootArgs != null ? bootArgs : "");
buf.append(" ");
@ -155,9 +155,9 @@ public class VirtualMachineTO {
public void setBootArgs(String bootArgs) {
this.bootArgs = bootArgs;
}
public void setBootArgs(Map<String, String> bootParams) {
StringBuilder buf = new StringBuilder();
StringBuilder buf = new StringBuilder();
for (Map.Entry<String, String> entry : bootParams.entrySet()) {
buf.append(" ").append(entry.getKey()).append("=").append(entry.getValue());
}
@ -187,23 +187,23 @@ public class VirtualMachineTO {
public void setNics(NicTO[] nics) {
this.nics = nics;
}
public static interface Monitor {
}
public static class SshMonitor implements Monitor {
String ip;
int port;
public String getIp() {
return ip;
}
public int getPort() {
return port;
}
public SshMonitor(String ip, int port) {
this.ip = ip;
this.port = port;

View File

@ -19,19 +19,38 @@ package com.cloud.deploy;
public class DataCenterDeployment implements DeploymentPlan {
long _dcId;
int _count;
Long _podId;
Long _clusterId;
Long _poolId;
public DataCenterDeployment(long dataCenterId, int count) {
public DataCenterDeployment(long dataCenterId) {
this(dataCenterId, null, null, null);
}
public DataCenterDeployment(long dataCenterId, Long podId, Long clusterId, Long poolId) {
_dcId = dataCenterId;
_podId = podId;
_clusterId = clusterId;
_poolId = poolId;
}
@Override
public long getDataCenterId() {
return _dcId;
}
@Override
public Long getPodId() {
return _podId;
}
@Override
public Long getClusterId() {
return _clusterId;
}
@Override
public int getCount() {
return _count;
public Long getPoolId() {
return _poolId;
}
}

View File

@ -19,12 +19,29 @@ package com.cloud.deploy;
/**
* Describes how a VM should be deployed.
*
*/
public interface DeploymentPlan {
// TODO: This interface is not fully developed. It really
// should be more complicated than this and allow a
// number of parameters to be specified.
// number of parameters to be specified.
/**
* @return data center the VM should deploy in.
*/
public long getDataCenterId();
public int getCount();
/**
* @return pod the Vm should deploy in; null if no preference.
*/
public Long getPodId();
/**
* @return cluster the VM should deploy in; null if no preference.
*/
public Long getClusterId();
/**
* @return pool the VM should be created in; null if no preference.
*/
public Long getPoolId();
}

View File

@ -17,12 +17,20 @@
*/
package com.cloud.hypervisor;
import com.cloud.offering.ServiceOffering;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.component.Adapter;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
public interface HypervisorGuru extends Adapter {
VirtualMachineProfile design(VirtualMachine vm, ServiceOffering offering);
boolean check(VirtualMachineProfile profile);
HypervisorType getHypervisorType();
/**
* Convert from a virtual machine to the
* virtual machine that the hypervisor expects.
* @param vm
* @return
*/
<T extends VirtualMachine> VirtualMachineTO implement(VirtualMachineProfile<T> vm);
}

View File

@ -12,6 +12,7 @@ import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.utils.component.Adapter;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
/**
@ -21,14 +22,49 @@ import com.cloud.vm.VirtualMachineProfile;
*
*/
public interface NetworkGuru extends Adapter {
/**
* Design a network configuration given the information.
* @param offering network offering that contains the information.
* @param plan where is this network configuration will be deployed.
* @param userSpecified user specified parameters for this network configuration.
* @param owner owner of this network configuration.
* @return NetworkConfiguration
*/
NetworkConfiguration design(NetworkOffering offering, DeploymentPlan plan, NetworkConfiguration userSpecified, Account owner);
/**
* allocate a nic in this network. This method implementation cannot take a long time as
* it is meant to allocate for the DB.
* @param config configuration to allocate the nic in.
* @param nic user specified
* @param vm virtual machine the network configuraiton will be in.
* @return NicProfile.
* @throws InsufficientVirtualNetworkCapcityException
* @throws InsufficientAddressCapacityException
*/
NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException;
/**
* Fully implement the network configuration as specified.
* @param config network configuration
* @param offering offering that the network configuration was based on.
* @param destination where were deploying to.
* @return a fully implemented NetworkConfiguration.
*/
NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination);
NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException;
String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException;
/**
* reserve a nic for this VM in this network.
* @param nic
* @param config
* @param vm
* @param dest
* @return
* @throws InsufficientVirtualNetworkCapcityException
* @throws InsufficientAddressCapacityException
*/
String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException;
boolean release(String uniqueId);
void destroy(NetworkConfiguration config, NetworkOffering offering);

View File

@ -10,9 +10,10 @@ import com.cloud.exception.InsufficientNetworkCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.NetworkConfiguration;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.utils.component.Adapter;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
/**
@ -25,11 +26,11 @@ public interface NetworkElement extends Adapter {
* @param offering network offering that originated the network configuration.
* @return true if network configuration is now usable; false if not; null if not handled by this element.
*/
boolean implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination dest, Account user) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
boolean implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, DeployDestination dest, Account user) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientNetworkCapacityException;
boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientNetworkCapacityException;
boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) throws ConcurrentOperationException, ResourceUnavailableException;
boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException;
boolean shutdown(NetworkConfiguration config, NetworkOffering offering, Account user) throws ConcurrentOperationException, ResourceUnavailableException;
boolean shutdown(NetworkConfiguration config, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException;
}

View File

@ -18,6 +18,7 @@
package com.cloud.template;
import com.cloud.acl.ControlledEntity;
import com.cloud.storage.Storage.ImageFormat;
public interface VirtualMachineTemplate extends ControlledEntity {
@ -38,4 +39,7 @@ public interface VirtualMachineTemplate extends ControlledEntity {
*/
String getName();
ImageFormat getFormat();
boolean isRequiresHvm();
}

View File

@ -59,7 +59,7 @@ public interface VirtualMachine extends RunningOn, ControlledEntity {
/**
* @return the name of the virtual machine.
*/
public String getName();
public String getHostName();
/**
* @return the ip address of the virtual machine.
@ -95,7 +95,7 @@ public interface VirtualMachine extends RunningOn, ControlledEntity {
/**
* @return pod id.
*/
public long getPodId();
public Long getPodId();
/**
* @return data center id.
@ -111,7 +111,7 @@ public interface VirtualMachine extends RunningOn, ControlledEntity {
* @return should HA be enabled for this machine?
*/
public boolean isHaEnabled();
/**
* @return date when machine was created
*/

View File

@ -18,114 +18,103 @@
package com.cloud.vm;
import java.util.List;
import java.util.Map;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.offering.ServiceOffering;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
import com.cloud.user.Account;
public class VirtualMachineProfile {
VirtualMachine _vm;
Integer _cpus;
Integer _speed; // in mhz
long _ram; // in bytes
HypervisorType _hypervisorType;
VirtualMachine.Type _type;
Map<String, String> _params;
Long _templateId;
List<DiskProfile> _disks;
List<NicProfile> _nics;
String _os;
String _password;
String _userData;
/**
* VirtualMachineProfile describes one virtual machine. This object
* is passed to various adapters to be processed. Anything that is
* set in this object is transitional. It does not get persisted
* back to the database. This allows the adapters to process
* the information in the virtual machine and make determinations
* on what the virtual machin profile should look like before it is
* actually started on the hypervisor.
*
* @param <T> a VirtualMachine
*/
public interface VirtualMachineProfile<T extends VirtualMachine> {
public VirtualMachineProfile(VirtualMachine.Type type) {
this._type = type;
}
String getHostName();
public long getServiceOfferingId() {
return _vm.getServiceOfferingId();
}
String getInstanceName();
public String getPassword() {
return _password;
}
Account getOwner();
public String getUserData() {
return _userData;
}
/**
* @return the virtual machine that backs up this profile.
*/
T getVirtualMachine();
public String getName() {
return _vm.getInstanceName();
}
/**
* @return service offering for this virtual machine.
*/
ServiceOffering getServiceOffering();
public String getOs() {
return _os;
}
/**
* @return parameter specific for this type of virtual machine.
*/
Object getParameter(String name);
public long getId() {
return _vm.getId();
}
/**
* @return the hypervisor type needed for this virtual machine.
*/
HypervisorType getHypervisorType();
public VirtualMachine.Type getType() {
return _type;
}
/**
* @return os to be run on the virtual machine.
*/
String getGuestOs();
public Long getTemplateId() {
return _templateId;
}
/**
* @return template the virtual machine is based on.
*/
VirtualMachineTemplate getTemplate();
public Integer getCpus() {
return _cpus;
}
/**
* @return the template id
*/
long getTemplateId();
public Integer getSpeed() {
return _speed;
}
/**
* @return the service offering id
*/
long getServiceOfferingId();
public long getRam() {
return _ram;
}
/**
* @return virtual machine id.
*/
long getId();
public void setNics(List<NicProfile> profiles) {
this._nics = profiles;
}
List<NicProfile> getNics();
public List<NicProfile> getNics() {
return _nics;
}
List<VolumeTO> getDisks();
public void setDisks(List<DiskProfile> profiles) {
this._disks = profiles;
}
void addNic(int index, NicProfile nic);
public List<DiskProfile> getDisks() {
return _disks;
}
void addDisk(int index, VolumeTO disk);
public HypervisorType getHypervisorType() {
return _hypervisorType;
}
StringBuilder getBootArgsBuilder();
public VirtualMachine getVm() {
return _vm;
}
void addBootArgs(String... args);
public VirtualMachineProfile(VirtualMachine vm, ServiceOffering offering, String os, HypervisorType hypervisorType) {
this._cpus = offering.getCpu();
this._speed = offering.getSpeed();
this._ram = offering.getRamSize() * 1024l * 1024l;
this._templateId = vm.getTemplateId();
this._type = vm.getType();
this._vm = vm;
this._os = os;
this._hypervisorType = hypervisorType;
}
String getBootArgs();
protected VirtualMachineProfile() {
}
void addNic(NicProfile nic);
@Override
public String toString() {
return "VM-" + _type + "-" + _vm.getId();
}
void addDisk(VolumeTO disk);
void setBootloader(BootloaderType type);
BootloaderType getBootloader();
String getOs();
VirtualMachine.Type getType();
void setParameter(String name, Object value);
}

View File

@ -68,7 +68,7 @@ public class StartCommand extends AbstractStartCommand {
this.guestNetworkId = guestNetworkId;
guestMacAddress = vm.getGuestMacAddress();
vncPassword = vm.getVncPassword();
hostName = vm.getName();
hostName = vm.getHostName();
// networkRateMbps = offering.getRateMbps();
// networkRateMulticastMbps = offering.getMulticastRateMbps();
networkRateMbps = networkRate;

View File

@ -107,7 +107,7 @@ public class StartConsoleProxyCommand extends AbstractStartCommand {
String basic = " eth0ip=" + proxy.getGuestIpAddress() + " eth0mask=" + proxy.getGuestNetmask() + " eth1ip="
+ eth1Ip + " eth1mask=" + eth1NetMask + " eth2ip="
+ eth2Ip + " eth2mask=" + eth2NetMask + " gateway=" + gateWay
+ " dns1=" + proxy.getDns1() + " type=consoleproxy"+ " name=" + proxy.getName() + " template=domP";
+ " dns1=" + proxy.getDns1() + " type=consoleproxy"+ " name=" + proxy.getHostName() + " template=domP";
if (proxy.getDns2() != null) {
basic = basic + " dns2=" + proxy.getDns2();
}

View File

@ -78,7 +78,7 @@ public class StartRouterCommand extends AbstractStartCommand {
String eth2Ip = router.getPublicIpAddress()==null?"0.0.0.0":router.getPublicIpAddress();
String basic = " eth0ip=" + router.getGuestIpAddress() + " eth0mask=" + router.getGuestNetmask() + " eth1ip="
+ router.getPrivateIpAddress() + " eth1mask=" + router.getPrivateNetmask() + " gateway=" + router.getGateway()
+ " dns1=" + router.getDns1() + " name=" + router.getName() + " mgmtcidr=" + mgmt_host;
+ " dns1=" + router.getDns1() + " name=" + router.getHostName() + " mgmtcidr=" + mgmt_host;
if (!router.getPublicMacAddress().equalsIgnoreCase("FE:FF:FF:FF:FF:FF")) {
basic = basic + " eth2ip=" + eth2Ip + " eth2mask=" + router.getPublicNetmask();
}

View File

@ -98,7 +98,7 @@ public class StartSecStorageVmCommand extends AbstractStartCommand {
String basic = " eth0ip=" + secStorageVm.getGuestIpAddress() + " eth0mask=" + secStorageVm.getGuestNetmask() + " eth1ip="
+ eth1Ip + " eth1mask=" + eth1NetMask + " eth2ip="
+ eth2Ip + " eth2mask=" + eth2NetMask + " gateway=" + gateWay
+ " dns1=" + secStorageVm.getDns1() + " type=secstorage" + " name=" + secStorageVm.getName() + " template=domP";
+ " dns1=" + secStorageVm.getDns1() + " type=secstorage" + " name=" + secStorageVm.getHostName() + " template=domP";
if (secStorageVm.getDns2() != null) {
basic = basic + " dns2=" + secStorageVm.getDns2();
}

View File

@ -37,7 +37,7 @@ import com.cloud.vm.VirtualMachine;
@Entity
@Table(name="op_ha_work")
public class WorkVO {
public class HaWorkVO {
public enum WorkType {
Migration,
Stop,
@ -92,7 +92,7 @@ public class WorkVO {
@Column(name="tried")
int timesTried;
protected WorkVO() {
protected HaWorkVO() {
}
public Long getId() {
@ -183,7 +183,7 @@ public class WorkVO {
this.previousState = state;
}
public WorkVO(final long instanceId, final VirtualMachine.Type type, final WorkType workType, final Step step, final long hostId, final State previousState, final int timesTried, final long updated) {
public HaWorkVO(final long instanceId, final VirtualMachine.Type type, final WorkType workType, final Step step, final long hostId, final State previousState, final int timesTried, final long updated) {
this.workType = workType;
this.type = type;
this.instanceId = instanceId;

View File

@ -19,11 +19,11 @@ package com.cloud.ha.dao;
import java.util.List;
import com.cloud.ha.WorkVO;
import com.cloud.ha.WorkVO.WorkType;
import com.cloud.ha.HaWorkVO;
import com.cloud.ha.HaWorkVO.WorkType;
import com.cloud.utils.db.GenericDao;
public interface HighAvailabilityDao extends GenericDao<WorkVO, Long> {
public interface HighAvailabilityDao extends GenericDao<HaWorkVO, Long> {
/**
* Takes an available HA work item.
@ -31,7 +31,7 @@ public interface HighAvailabilityDao extends GenericDao<WorkVO, Long> {
* @param serverId server that is taking this.
* @return WorkVO if there's one to work on; null if none.
*/
WorkVO take(long serverId);
HaWorkVO take(long serverId);
/**
* Finds all the work items related to this instance.
@ -39,7 +39,7 @@ public interface HighAvailabilityDao extends GenericDao<WorkVO, Long> {
* @param instanceId
* @return list of WorkVO or empty list.
*/
List<WorkVO> findPreviousHA(long instanceId);
List<HaWorkVO> findPreviousHA(long instanceId);
boolean delete(long instanceId, WorkType type);
@ -53,7 +53,7 @@ public interface HighAvailabilityDao extends GenericDao<WorkVO, Long> {
void deleteMigrationWorkItems(final long hostId, final WorkType type, final long serverId);
List<WorkVO> findTakenWorkItems(WorkType type);
List<HaWorkVO> findTakenWorkItems(WorkType type);
/**
* finds out if a work item has been scheduled for this work type but has not been taken yet.

View File

@ -25,9 +25,9 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.ha.HighAvailabilityManager;
import com.cloud.ha.WorkVO;
import com.cloud.ha.HaWorkVO;
import com.cloud.ha.HighAvailabilityManager.Step;
import com.cloud.ha.WorkVO.WorkType;
import com.cloud.ha.HaWorkVO.WorkType;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
@ -36,15 +36,15 @@ import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
@Local(value={HighAvailabilityDao.class})
public class HighAvailabilityDaoImpl extends GenericDaoBase<WorkVO, Long> implements HighAvailabilityDao {
public class HighAvailabilityDaoImpl extends GenericDaoBase<HaWorkVO, Long> implements HighAvailabilityDao {
private static final Logger s_logger = Logger.getLogger(HighAvailabilityDaoImpl.class);
private final SearchBuilder<WorkVO> TBASearch;
private final SearchBuilder<WorkVO> PreviousInstanceSearch;
private final SearchBuilder<WorkVO> UntakenMigrationSearch;
private final SearchBuilder<WorkVO> CleanupSearch;
private final SearchBuilder<WorkVO> PreviousWorkSearch;
private final SearchBuilder<WorkVO> TakenWorkSearch;
private final SearchBuilder<HaWorkVO> TBASearch;
private final SearchBuilder<HaWorkVO> PreviousInstanceSearch;
private final SearchBuilder<HaWorkVO> UntakenMigrationSearch;
private final SearchBuilder<HaWorkVO> CleanupSearch;
private final SearchBuilder<HaWorkVO> PreviousWorkSearch;
private final SearchBuilder<HaWorkVO> TakenWorkSearch;
protected HighAvailabilityDaoImpl() {
super();
@ -86,22 +86,22 @@ public class HighAvailabilityDaoImpl extends GenericDaoBase<WorkVO, Long> implem
}
@Override
public WorkVO take(final long serverId) {
public HaWorkVO take(final long serverId) {
final Transaction txn = Transaction.currentTxn();
try {
final SearchCriteria<WorkVO> sc = TBASearch.create();
final SearchCriteria<HaWorkVO> sc = TBASearch.create();
sc.setParameters("time", System.currentTimeMillis() >> 10);
final Filter filter = new Filter(WorkVO.class, null, true, 0l, 1l);
final Filter filter = new Filter(HaWorkVO.class, null, true, 0l, 1l);
txn.start();
final List<WorkVO> vos = lockRows(sc, filter, true);
final List<HaWorkVO> vos = lockRows(sc, filter, true);
if (vos.size() == 0) {
txn.commit();
return null;
}
final WorkVO work = vos.get(0);
final HaWorkVO work = vos.get(0);
work.setServerId(serverId);
work.setDateTaken(new Date());
@ -117,15 +117,15 @@ public class HighAvailabilityDaoImpl extends GenericDaoBase<WorkVO, Long> implem
}
@Override
public List<WorkVO> findPreviousHA(final long instanceId) {
final SearchCriteria<WorkVO> sc = PreviousInstanceSearch.create();
public List<HaWorkVO> findPreviousHA(final long instanceId) {
final SearchCriteria<HaWorkVO> sc = PreviousInstanceSearch.create();
sc.setParameters("instance", instanceId);
return listIncludingRemovedBy(sc);
}
@Override
public void cleanup(final long time) {
final SearchCriteria<WorkVO> sc = CleanupSearch.create();
final SearchCriteria<HaWorkVO> sc = CleanupSearch.create();
sc.setParameters("time", time);
sc.setParameters("step", HighAvailabilityManager.Step.Done, HighAvailabilityManager.Step.Cancelled);
expunge(sc);
@ -133,11 +133,11 @@ public class HighAvailabilityDaoImpl extends GenericDaoBase<WorkVO, Long> implem
@Override
public void deleteMigrationWorkItems(final long hostId, final WorkType type, final long serverId) {
final SearchCriteria<WorkVO> sc = UntakenMigrationSearch.create();
final SearchCriteria<HaWorkVO> sc = UntakenMigrationSearch.create();
sc.setParameters("host", hostId);
sc.setParameters("type", type.toString());
WorkVO work = createForUpdate();
HaWorkVO work = createForUpdate();
Date date = new Date();
work.setDateTaken(date);
work.setServerId(serverId);
@ -147,8 +147,8 @@ public class HighAvailabilityDaoImpl extends GenericDaoBase<WorkVO, Long> implem
}
@Override
public List<WorkVO> findTakenWorkItems(WorkType type) {
SearchCriteria<WorkVO> sc = TakenWorkSearch.create();
public List<HaWorkVO> findTakenWorkItems(WorkType type) {
SearchCriteria<HaWorkVO> sc = TakenWorkSearch.create();
sc.setParameters("type", type);
sc.setParameters("step", Step.Done, Step.Cancelled, Step.Error);
@ -158,7 +158,7 @@ public class HighAvailabilityDaoImpl extends GenericDaoBase<WorkVO, Long> implem
@Override
public boolean delete(long instanceId, WorkType type) {
SearchCriteria<WorkVO> sc = PreviousWorkSearch.create();
SearchCriteria<HaWorkVO> sc = PreviousWorkSearch.create();
sc.setParameters("instance", instanceId);
sc.setParameters("type", type);
return expunge(sc) > 0;
@ -166,7 +166,7 @@ public class HighAvailabilityDaoImpl extends GenericDaoBase<WorkVO, Long> implem
@Override
public boolean hasBeenScheduled(long instanceId, WorkType type) {
SearchCriteria<WorkVO> sc = PreviousWorkSearch.create();
SearchCriteria<HaWorkVO> sc = PreviousWorkSearch.create();
sc.setParameters("instance", instanceId);
sc.setParameters("type", type);
return listBy(sc, null).size() > 0;

View File

@ -625,6 +625,8 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
return execute((RemoteAccessVpnCfgCommand)cmd);
} else if (cmd instanceof VpnUsersCfgCommand) {
return execute((VpnUsersCfgCommand)cmd);
} else if (cmd instanceof CheckSshCommand) {
return execute((CheckSshCommand)cmd);
} else {
return Answer.createUnsupportedCommandAnswer(cmd);
}
@ -881,6 +883,31 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
return cdromVBD;
}
protected CheckSshAnswer execute(CheckSshCommand cmd) {
String vmName = cmd.getName();
String privateIp = cmd.getIp();
int cmdPort = cmd.getPort();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort);
}
try {
String result = connect(cmd.getName(), privateIp, cmdPort);
if (result != null) {
return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + "due to:" + result);
}
} catch (Exception e) {
return new CheckSshAnswer(cmd, e);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Ping command port succeeded for vm " + vmName);
}
return new CheckSshAnswer(cmd);
}
protected Start2Answer execute(Start2Command cmd) {
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
String vmName = vmSpec.getName();

View File

@ -23,7 +23,7 @@ import java.util.List;
import javax.ejb.Local;
import com.cloud.ha.WorkVO;
import com.cloud.ha.HaWorkVO;
import com.cloud.network.security.NetworkGroupWorkVO;
import com.cloud.network.security.NetworkGroupWorkVO.Step;
import com.cloud.utils.db.Filter;
@ -142,7 +142,7 @@ public class NetworkGroupWorkDaoImpl extends GenericDaoBase<NetworkGroupWorkVO,
sc.setParameters("vmId", vmId);
sc.setParameters("seqno", logSequenceNumber);
final Filter filter = new Filter(WorkVO.class, null, true, 0l, 1l);
final Filter filter = new Filter(HaWorkVO.class, null, true, 0l, 1l);
final List<NetworkGroupWorkVO> vos = lockRows(sc, filter, true);
if (vos.size() == 0) {

View File

@ -29,6 +29,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -43,15 +44,14 @@ import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import com.cloud.exception.InternalErrorException;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageLayer;
import com.cloud.storage.StorageResource;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.template.Processor.FormatInfo;
import com.cloud.storage.template.TemplateDownloader.DownloadCompleteCallback;
import com.cloud.storage.template.TemplateDownloader.Status;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.UUID;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
@ -206,6 +206,7 @@ public class DownloadManagerImpl implements DownloadManager {
private int installTimeoutPerGig = 180 * 60 * 1000;
private boolean _sslCopy;
@Override
public String setRootDir(String rootDir, StorageResource storage) {
/*
* if (!storage.existPath(rootDir + templateDownloadDir)) { s_logger.info("Creating template download path: " +
@ -385,7 +386,7 @@ public class DownloadManagerImpl implements DownloadManager {
@Override
public String downloadPublicTemplate(long id, String url, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum, String installPathPrefix, String user, String password, long maxTemplateSizeInBytes) {
UUID uuid = new UUID();
UUID uuid = UUID.randomUUID();
String jobId = uuid.toString();
String tmpDir = installPathPrefix + File.separator + accountId + File.separator + id;
@ -438,6 +439,7 @@ public class DownloadManagerImpl implements DownloadManager {
}
}
@Override
public String getPublicTemplateRepo() {
return publicTemplateRepo;
}

View File

@ -8,10 +8,10 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import javax.naming.ConfigurationException;
@ -22,20 +22,18 @@ import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
import com.cloud.agent.api.storage.DeleteEntityDownloadURLAnswer;
import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
import com.cloud.agent.api.storage.UploadAnswer;
import com.cloud.agent.api.storage.UploadProgressCommand;
import com.cloud.agent.api.storage.UploadCommand;
import com.cloud.agent.api.storage.UploadProgressCommand;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageLayer;
import com.cloud.storage.StorageResource;
import com.cloud.storage.Upload;
import com.cloud.storage.UploadVO;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.template.TemplateUploader.UploadCompleteCallback;
import com.cloud.storage.template.TemplateUploader.Status;
import com.cloud.storage.template.TemplateUploader.UploadCompleteCallback;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.UUID;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
@ -174,7 +172,7 @@ public class UploadManagerImpl implements UploadManager {
String cksum, String installPathPrefix, String userName,
String passwd, long templateSizeInBytes) {
UUID uuid = new UUID();
UUID uuid = UUID.randomUUID();
String jobId = uuid.toString();
String completePath = parentDir + File.separator + installPathPrefix;

View File

@ -50,7 +50,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
private long id;
@Column(name="name", updatable=false, nullable=false, length=255)
private String name = null;
private String hostName = null;
@Column(name="vnc_password", updatable=true, nullable=false, length=255)
String vncPassword;
@ -91,7 +91,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
private Long lastHostId;
@Column(name="pod_id", updatable=true, nullable=false)
private long podId;
private Long podId;
@Column(name="private_mac_address", updatable=true, nullable=true)
String privateMacAddress;
@ -145,7 +145,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
long accountId,
boolean haEnabled) {
this.id = id;
this.name = name;
this.hostName = name;
if (vmTemplateId != null) {
this.templateId = vmTemplateId;
}
@ -180,7 +180,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
Long hostId) {
super();
this.id = id;
this.name = name;
this.hostName = name;
if (vmTemplateId > -1)
this.templateId = vmTemplateId;
else
@ -263,8 +263,8 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
}
@Override
public String getName() {
return name;
public String getHostName() {
return hostName;
}
@Override
@ -305,6 +305,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
return vncPassword;
}
@Override
public long getServiceOfferingId() {
return serviceOfferingId;
}
@ -379,7 +380,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
}
@Override
public long getPodId() {
public Long getPodId() {
return podId;
}

View File

@ -80,7 +80,7 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
HostRunningSearch.done();
NameSearch = createSearchBuilder();
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
NameSearch.and("name", NameSearch.entity().getHostName(), SearchCriteria.Op.EQ);
NameSearch.done();
RouterStateSearch = createSearchBuilder();

View File

@ -93,7 +93,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
ZoneTemplateNonExpungedSearch.done();
NameLikeSearch = createSearchBuilder();
NameLikeSearch.and("name", NameLikeSearch.entity().getName(), SearchCriteria.Op.LIKE);
NameLikeSearch.and("name", NameLikeSearch.entity().getHostName(), SearchCriteria.Op.LIKE);
NameLikeSearch.done();
StateChangeSearch = createSearchBuilder();

View File

@ -159,6 +159,7 @@ import com.cloud.utils.nio.Task;
import com.cloud.vm.State;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfileImpl;
import com.cloud.vm.dao.VMInstanceDao;
/**
@ -431,7 +432,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
public Host findHost(final Host.Type type, final DataCenterVO dc, final HostPodVO pod, final StoragePoolVO sp,
final ServiceOffering offering, final VMTemplateVO template, VMInstanceVO vm,
Host currentHost, final Set<Host> avoid) {
VirtualMachineProfile vmc = new VirtualMachineProfile(vm.getType());
VirtualMachineProfile<VMInstanceVO> vmc = new VirtualMachineProfileImpl<VMInstanceVO>(vm.getType());
Enumeration<HostAllocator> en = _hostAllocators.enumeration();
while (en.hasMoreElements()) {
final HostAllocator allocator = en.nextElement();

View File

@ -27,10 +27,11 @@ import com.cloud.offering.ServiceOffering;
import com.cloud.storage.VMTemplateVO;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.Adapter;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
public interface HostAllocator extends Adapter {
boolean isVirtualMachineUpgradable(final UserVm vm, final ServiceOffering offering);
Host allocateTo(VirtualMachineProfile vm, ServiceOffering offering, Type type, DataCenterVO dc, HostPodVO pod, Long clusterId, VMTemplateVO template, Set<Host> avoid);
Host allocateTo(VirtualMachineProfile<? extends VirtualMachine> vm, ServiceOffering offering, Type type, DataCenterVO dc, HostPodVO pod, Long clusterId, VMTemplateVO template, Set<Host> avoid);
}

View File

@ -54,6 +54,7 @@ import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.ConsoleProxyDao;
import com.cloud.vm.dao.DomainRouterDao;
@ -81,7 +82,7 @@ public class FirstFitAllocator implements HostAllocator {
protected String _allocationAlgorithm = "random";
@Override
public Host allocateTo(VirtualMachineProfile vm, ServiceOffering offering, Type type, DataCenterVO dc,
public Host allocateTo(VirtualMachineProfile<? extends VirtualMachine> vm, ServiceOffering offering, Type type, DataCenterVO dc,
HostPodVO pod, Long clusterId, VMTemplateVO template,
Set<Host> avoid) {

View File

@ -29,14 +29,14 @@ import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.host.Host;
import com.cloud.offering.ServiceOffering;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@Local(value={HostAllocator.class})
public class FirstFitRoutingAllocator extends FirstFitAllocator {
@Override
public Host allocateTo(VirtualMachineProfile vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
public Host allocateTo(VirtualMachineProfile<? extends VirtualMachine> vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
Long clusterId, VMTemplateVO template, Set<Host> avoid) {
try {
NDC.push("FirstFitRoutingAllocator");

View File

@ -32,10 +32,10 @@ import com.cloud.dc.HostPodVO;
import com.cloud.host.Host;
import com.cloud.host.dao.HostDao;
import com.cloud.offering.ServiceOffering;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@Local(value=HostAllocator.class)
@ -45,7 +45,7 @@ public class RandomAllocator implements HostAllocator {
private HostDao _hostDao;
@Override
public Host allocateTo(VirtualMachineProfile vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
public Host allocateTo(VirtualMachineProfile<? extends VirtualMachine> vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
Long clusterId, VMTemplateVO template, Set<Host> avoid) {
if (type == Host.Type.Storage) {
return null;

View File

@ -62,7 +62,7 @@ public class RecreateHostAllocator extends FirstFitRoutingAllocator {
boolean _isDirect;
@Override
public Host allocateTo(VirtualMachineProfile vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
public Host allocateTo(VirtualMachineProfile<? extends VirtualMachine> vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
Long clusterId, VMTemplateVO template, Set<Host> avoid) {
Host host = super.allocateTo(vm, offering, type, dc, pod, clusterId, template, avoid);
if (host != null) {

View File

@ -28,10 +28,10 @@ import com.cloud.dc.HostPodVO;
import com.cloud.host.Host;
import com.cloud.host.dao.HostDao;
import com.cloud.offering.ServiceOffering;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
/**
@ -47,7 +47,7 @@ public class TestingAllocator implements HostAllocator {
String _name;
@Override
public Host allocateTo(VirtualMachineProfile vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
public Host allocateTo(VirtualMachineProfile<? extends VirtualMachine> vm, ServiceOffering offering, Host.Type type, DataCenterVO dc, HostPodVO pod,
Long clusterId, VMTemplateVO template, Set<Host> avoid) {
if (type == Host.Type.Routing && _routingHost != null) {
return _hostDao.findById(_routingHost);

View File

@ -106,7 +106,7 @@ public class AttachIsoCmd extends BaseAsyncCmd {
response.setOsTypeId(iso.getGuestOSId());
response.setOsTypeName(ApiDBUtils.findGuestOSById(iso.getGuestOSId()).getName());
response.setVirtualMachineId(virtualMachineId);
response.setVirtualMachineName(vmInstance.getName());
response.setVirtualMachineName(vmInstance.getHostName());
response.setVirtualMachineState(vmInstance.getState().toString());
response.setResponseName(getName());
return response;

View File

@ -198,7 +198,7 @@ public class DeployVm2Cmd extends BaseAsyncCreateCmd {
UserVmResponse response = new UserVmResponse();
response.setId(userVm.getId());
response.setName(userVm.getName());
response.setName(userVm.getHostName());
response.setCreated(userVm.getCreated());
response.setZoneId(userVm.getDataCenterId());
response.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
@ -213,7 +213,7 @@ public class DeployVm2Cmd extends BaseAsyncCreateCmd {
}
if (userVm.getDisplayName() == null || userVm.getDisplayName().length() == 0) {
response.setDisplayName(userVm.getName());
response.setDisplayName(userVm.getHostName());
} else {
response.setDisplayName(userVm.getDisplayName());
}

View File

@ -64,7 +64,7 @@ public class RebootSystemVmCmd extends BaseAsyncCmd {
@Override
public long getAccountId() {
Account account = (Account)UserContext.current().getAccount();
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();
}

View File

@ -80,6 +80,7 @@ public class RebootVMCmd extends BaseAsyncCmd {
return "rebooting user vm: " + getId();
}
<<<<<<< HEAD
@Override @SuppressWarnings("unchecked")
public UserVmResponse getResponse() {
UserVm userVm = (UserVm)getResponseObject();
@ -87,4 +88,106 @@ public class RebootVMCmd extends BaseAsyncCmd {
recoverVmResponse.setResponseName(getName());
return recoverVmResponse;
}
=======
@Override @SuppressWarnings("unchecked")
public UserVmResponse getResponse() {
UserVm vm = (UserVm)getResponseObject();
UserVmResponse response = new UserVmResponse();
response.setId(vm.getId());
response.setName(vm.getHostName());
response.setCreated(vm.getCreated());
response.setZoneId(vm.getDataCenterId());
response.setZoneName(ApiDBUtils.findZoneById(vm.getDataCenterId()).getName());
response.setIpAddress(vm.getPrivateIpAddress());
response.setServiceOfferingId(vm.getServiceOfferingId());
response.setHaEnable(vm.isHaEnabled());
if (vm.getDisplayName() == null || vm.getDisplayName().length() == 0) {
response.setDisplayName(vm.getHostName());
} else {
response.setDisplayName(vm.getDisplayName());
}
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(vm.getId());
if (group != null) {
response.setGroup(group.getName());
response.setGroupId(group.getId());
}
if (vm.getState() != null) {
response.setState(vm.getState().toString());
}
Account acct = ApiDBUtils.findAccountById(vm.getAccountId());
if (acct != null) {
response.setAccountName(acct.getAccountName());
response.setDomainId(acct.getDomainId());
response.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
}
if (BaseCmd.isAdmin(acct.getType()) && (vm.getHostId() != null)) {
response.setHostName(ApiDBUtils.findHostById(vm.getHostId()).getName());
response.setHostId(vm.getHostId());
}
String templateName = "ISO Boot";
boolean templatePasswordEnabled = false;
String templateDisplayText = "ISO Boot";
VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
if (template != null) {
templateName = template.getName();
templatePasswordEnabled = template.getEnablePassword();
templateDisplayText = template.getDisplayText();
if (templateDisplayText == null) {
templateDisplayText = templateName;
}
}
response.setTemplateId(vm.getTemplateId());
response.setTemplateName(templateName);
response.setTemplateDisplayText(templateDisplayText);
response.setPasswordEnabled(templatePasswordEnabled);
if (templatePasswordEnabled) {
response.setPassword(null); // FIXME: Where should password come from? In the old framework, password was always passed
// in to composeResultObject() as null, so that behavior is preserved...
} else {
response.setPassword("");
}
String isoName = null;
if (vm.getIsoId() != null) {
VMTemplateVO iso = ApiDBUtils.findTemplateById(vm.getIsoId().longValue());
if (iso != null) {
isoName = iso.getName();
}
}
response.setIsoId(vm.getIsoId());
response.setIsoName(isoName);
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(vm.getServiceOfferingId());
response.setServiceOfferingId(vm.getServiceOfferingId());
response.setServiceOfferingName(offering.getName());
response.setCpuNumber(offering.getCpu());
response.setCpuSpeed(offering.getSpeed());
response.setMemory(offering.getRamSize());
VolumeVO rootVolume = ApiDBUtils.findRootVolume(vm.getId());
if (rootVolume != null) {
response.setRootDeviceId(rootVolume.getDeviceId());
StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId());
response.setRootDeviceType(storagePool.getPoolType().toString());
}
response.setGuestOsId(vm.getGuestOSId());
//Network groups
response.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(vm.getId()));
response.setResponseName(getName());
return response;
}
>>>>>>> Harmony among gurus
}

View File

@ -89,7 +89,52 @@ public class StartSystemVMCmd extends BaseAsyncCmd {
@Override @SuppressWarnings("unchecked")
public SystemVmResponse getResponse() {
VMInstanceVO instance = (VMInstanceVO)getResponseObject();
<<<<<<< HEAD
SystemVmResponse response = ApiResponseHelper.createSystemVmResponse(instance);
=======
SystemVmResponse response = new SystemVmResponse();
response.setId(instance.getId());
response.setName(instance.getHostName());
response.setZoneId(instance.getDataCenterId());
response.setZoneName(ApiDBUtils.findZoneById(instance.getDataCenterId()).getName());
response.setPodId(instance.getPodId());
response.setHostId(instance.getHostId());
if (response.getHostId() != null) {
response.setHostName(ApiDBUtils.findHostById(instance.getHostId()).getName());
}
response.setPrivateIp(instance.getPrivateIpAddress());
response.setPrivateMacAddress(instance.getPrivateMacAddress());
response.setPrivateNetmask(instance.getPrivateNetmask());
response.setTemplateId(instance.getTemplateId());
response.setCreated(instance.getCreated());
response.setState(instance.getState().toString());
if (instance instanceof SecondaryStorageVmVO) {
SecondaryStorageVmVO ssVm = (SecondaryStorageVmVO) instance;
response.setDns1(ssVm.getDns1());
response.setDns2(ssVm.getDns2());
response.setNetworkDomain(ssVm.getDomain());
response.setGateway(ssVm.getGateway());
response.setPublicIp(ssVm.getPublicIpAddress());
response.setPublicMacAddress(ssVm.getPublicMacAddress());
response.setPublicNetmask(ssVm.getPublicNetmask());
} else if (instance instanceof ConsoleProxyVO) {
ConsoleProxyVO proxy = (ConsoleProxyVO)instance;
response.setDns1(proxy.getDns1());
response.setDns2(proxy.getDns2());
response.setNetworkDomain(proxy.getDomain());
response.setGateway(proxy.getGateway());
response.setPublicIp(proxy.getPublicIpAddress());
response.setPublicMacAddress(proxy.getPublicMacAddress());
response.setPublicNetmask(proxy.getPublicNetmask());
response.setActiveViewerSessions(proxy.getActiveSession());
}
>>>>>>> Harmony among gurus
response.setResponseName(getName());
return response;
}

View File

@ -96,7 +96,7 @@ public class StartVm2Cmd extends BaseAsyncCmd {
UserVmResponse response = new UserVmResponse();
response.setId(vm.getId());
response.setName(vm.getName());
response.setName(vm.getHostName());
response.setCreated(vm.getCreated());
response.setZoneId(vm.getDataCenterId());
response.setZoneName(ApiDBUtils.findZoneById(vm.getDataCenterId()).getName());
@ -104,7 +104,7 @@ public class StartVm2Cmd extends BaseAsyncCmd {
response.setServiceOfferingId(vm.getServiceOfferingId());
response.setHaEnable(vm.isHaEnabled());
if (vm.getDisplayName() == null || vm.getDisplayName().length() == 0) {
response.setDisplayName(vm.getName());
response.setDisplayName(vm.getHostName());
} else {
response.setDisplayName(vm.getDisplayName());
}

View File

@ -85,8 +85,51 @@ public class StopRouterCmd extends BaseAsyncCmd {
@Override @SuppressWarnings("unchecked")
public DomainRouterResponse getResponse() {
<<<<<<< HEAD
DomainRouter router = (DomainRouter)getResponseObject();
DomainRouterResponse response =ApiResponseHelper.createDomainRouterResponse(router);
=======
DomainRouterVO router = (DomainRouterVO)getResponseObject();
DomainRouterResponse response = new DomainRouterResponse();
response.setId(router.getId());
response.setZoneId(router.getDataCenterId());
response.setZoneName(ApiDBUtils.findZoneById(router.getDataCenterId()).getName());
response.setDns1(router.getDns1());
response.setDns2(router.getDns2());
response.setNetworkDomain(router.getDomain());
response.setGateway(router.getGateway());
response.setName(router.getHostName());
response.setPodId(router.getPodId());
response.setPrivateIp(router.getPrivateIpAddress());
response.setPrivateMacAddress(router.getPrivateMacAddress());
response.setPrivateNetmask(router.getPrivateNetmask());
response.setPublicIp(router.getPublicIpAddress());
response.setPublicMacAddress(router.getPublicMacAddress());
response.setPublicNetmask(router.getPrivateNetmask());
response.setGuestIpAddress(router.getGuestIpAddress());
response.setGuestMacAddress(router.getGuestMacAddress());
response.setTemplateId(router.getTemplateId());
response.setCreated(router.getCreated());
response.setGuestNetmask(router.getGuestNetmask());
if (router.getHostId() != null) {
response.setHostName(ApiDBUtils.findHostById(router.getHostId()).getName());
response.setHostId(router.getHostId());
}
Account acct = ApiDBUtils.findAccountById(router.getAccountId());
if (acct != null) {
response.setAccountName(acct.getAccountName());
response.setDomainId(acct.getDomainId());
response.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
}
if (router.getState() != null) {
response.setState(router.getState());
}
>>>>>>> Harmony among gurus
response.setResponseName(getName());
return response;
}

View File

@ -90,7 +90,7 @@ public class StopSystemVmCmd extends BaseAsyncCmd {
SystemVmResponse response = new SystemVmResponse();
response.setId(instance.getId());
response.setName(instance.getName());
response.setName(instance.getHostName());
response.setZoneId(instance.getDataCenterId());
response.setZoneName(ApiDBUtils.findZoneById(instance.getDataCenterId()).getName());
response.setPodId(instance.getPodId());

View File

@ -26,7 +26,7 @@ public class ConsoleProxyExecutorHelper {
public static ConsoleProxyOperationResultObject composeResultObject(ManagementServer managementServer, ConsoleProxyVO proxy) {
ConsoleProxyOperationResultObject result = new ConsoleProxyOperationResultObject();
result.setId(proxy.getId());
result.setName(proxy.getName());
result.setName(proxy.getHostName());
result.setZoneId(proxy.getDataCenterId());
result.setZoneName(managementServer.findDataCenterById(proxy.getDataCenterId()).getName());
result.setDns1(proxy.getDns1());

View File

@ -145,7 +145,7 @@ public class DeployVMExecutor extends VMOperationExecutor {
return resultObject;
resultObject.setId(vm.getId());
resultObject.setName(vm.getName());
resultObject.setName(vm.getHostName());
resultObject.setCreated(vm.getCreated());
resultObject.setZoneId(vm.getDataCenterId());
resultObject.setZoneName(getAsyncJobMgr().getExecutorContext().getManagementServer().findDataCenterById(vm.getDataCenterId()).getName());
@ -153,7 +153,7 @@ public class DeployVMExecutor extends VMOperationExecutor {
resultObject.setServiceOfferingId(vm.getServiceOfferingId());
resultObject.setHaEnabled(vm.isHaEnabled());
if (vm.getDisplayName() == null || vm.getDisplayName().length() == 0) {
resultObject.setDisplayName(vm.getName());
resultObject.setDisplayName(vm.getHostName());
}
else {
resultObject.setDisplayName(vm.getDisplayName());

View File

@ -84,7 +84,7 @@ public class DestroyVMExecutor extends VMOperationExecutor {
VMOperationParam param = listener.getParam();
AsyncJobManager asyncMgr = getAsyncJobMgr();
ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer();
String params = "id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
String params = "id="+vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
if(s_logger.isDebugEnabled())
s_logger.debug("Execute asynchronize destroy VM command: received stop-VM answer, " + vm.getHostId() + "-" + seq);
@ -132,7 +132,7 @@ public class DestroyVMExecutor extends VMOperationExecutor {
} else {
asyncMgr.getExecutorContext().getVmDao().updateIf(vm, Event.OperationFailed, vm.getHostId());
asyncMgr.completeAsyncJob(getJob().getId(),
AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR, "Agent failed to stop VM: " + vm.getName());
AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR, "Agent failed to stop VM: " + vm.getHostName());
// managementServer.saveEvent(param.getUserId(), vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP,
// "failed to stop VM instance : " + vm.getName(), params, param.getChildEventId());
// managementServer.saveEvent(param.getUserId(), param.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_DESTROY,
@ -171,8 +171,8 @@ public class DestroyVMExecutor extends VMOperationExecutor {
event.setUserId(param.getUserId());
event.setAccountId(vm.getAccountId());
event.setType(EventTypes.EVENT_VM_DESTROY);
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
event.setDescription("failed to stop VM instance : " + vm.getName() + " due to " + resultMessage);
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
event.setDescription("failed to stop VM instance : " + vm.getHostName() + " due to " + resultMessage);
event.setLevel(EventVO.LEVEL_ERROR);
boolean jobStatusUpdated = false;

View File

@ -78,7 +78,7 @@ public class RebootVMExecutor extends VMOperationExecutor {
VMOperationParam param = listener.getParam();
AsyncJobManager asyncMgr = getAsyncJobMgr();
ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer();
String params = "id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
String params = "id="+vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
boolean jobStatusUpdated = false;
try {
@ -90,14 +90,14 @@ public class RebootVMExecutor extends VMOperationExecutor {
AsyncJobResult.STATUS_SUCCEEDED, 0, VMExecutorHelper.composeResultObject(asyncMgr.getExecutorContext().getManagementServer(), vm, null));
jobStatusUpdated = true;
EventUtils.saveEvent(param.getUserId(), param.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_REBOOT,
"Successfully rebooted VM instance : " + vm.getName(), params, param.getEventId());
"Successfully rebooted VM instance : " + vm.getHostName(), params, param.getEventId());
} else {
asyncMgr.completeAsyncJob(getJob().getId(),
AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR, "Agent is unable to execute the command");
jobStatusUpdated = true;
EventUtils.saveEvent(param.getUserId(), param.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_REBOOT,
"Failed to reboot VM instance : " + vm.getName(), params, param.getEventId());
"Failed to reboot VM instance : " + vm.getHostName(), params, param.getEventId());
}
@ -142,8 +142,8 @@ public class RebootVMExecutor extends VMOperationExecutor {
event.setUserId(param.getUserId());
event.setAccountId(vm.getAccountId());
event.setType(EventTypes.EVENT_VM_REBOOT);
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
event.setDescription("failed to reboot VM instance : " + vm.getName() + " due to " + resultMessage);
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
event.setDescription("failed to reboot VM instance : " + vm.getHostName() + " due to " + resultMessage);
event.setLevel(EventVO.LEVEL_ERROR);
boolean jobStatusUpdated = false;

View File

@ -32,7 +32,7 @@ public class RouterExecutorHelper {
resultObject.setDns2(router.getDns2());
resultObject.setNetworkDomain(router.getDomain());
resultObject.setGateway(router.getGateway());
resultObject.setName(router.getName());
resultObject.setName(router.getHostName());
resultObject.setPodId(router.getPodId());
resultObject.setPrivateIp(router.getPrivateIpAddress());
resultObject.setPrivateMacAddress(router.getPrivateMacAddress());

View File

@ -75,7 +75,7 @@ public class StopVMExecutor extends VMOperationExecutor {
VMOperationParam param = listener.getParam();
AsyncJobManager asyncMgr = getAsyncJobMgr();
ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer();
String params = "id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
String params = "id="+vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
if(s_logger.isDebugEnabled())
s_logger.debug("Execute asynchronize stop VM command: received answer, " + vm.getHostId() + "-" + seq);
@ -98,7 +98,7 @@ public class StopVMExecutor extends VMOperationExecutor {
jobStatusUpdated = true;
EventUtils.saveEvent(param.getUserId(), param.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP,
"Failed to stop VM instance : " + vm.getName(), params, param.getEventId());
"Failed to stop VM instance : " + vm.getHostName(), params, param.getEventId());
}
} catch(Exception e) {
s_logger.error("Unexpected exception " + e.getMessage(), e);
@ -110,7 +110,7 @@ public class StopVMExecutor extends VMOperationExecutor {
asyncMgr.completeAsyncJob(getJob().getId(),
AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR, "Agent failed to stop VM");
EventUtils.saveEvent(param.getUserId(), param.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP,
"Failed to stop VM instance : " + vm.getName(), params, param.getEventId());
"Failed to stop VM instance : " + vm.getHostName(), params, param.getEventId());
}
}
} finally {
@ -141,8 +141,8 @@ public class StopVMExecutor extends VMOperationExecutor {
event.setUserId(param.getUserId());
event.setAccountId(vm.getAccountId());
event.setType(EventTypes.EVENT_VM_STOP);
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
event.setDescription("failed to stop VM instance : " + vm.getName() + " due to " + resultMessage);
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
event.setDescription("failed to stop VM instance : " + vm.getHostName() + " due to " + resultMessage);
event.setLevel(EventVO.LEVEL_ERROR);
asyncMgr.completeAsyncJob(getJob().getId(),

View File

@ -110,7 +110,7 @@ public class SystemVmCmdExecutor extends VMOperationExecutor {
if (vm instanceof SecondaryStorageVmVO) {
SecondaryStorageVmVO ssVm = (SecondaryStorageVmVO)vm;
result.setId(ssVm.getId());
result.setName(vm.getName());
result.setName(vm.getHostName());
result.setZoneId(ssVm.getDataCenterId());
result.setZoneName(managementServer.findDataCenterById(ssVm.getDataCenterId()).getName());
result.setDns1(ssVm.getDns1());

View File

@ -77,7 +77,7 @@ public class UpdatePortForwardingRuleExecutor extends BaseAsyncJobExecutor {
if ((userVMs != null) && (userVMs.size() > 0)) {
UserVmVO userVM = userVMs.get(0);
resultObject.setVirtualMachineId(userVM.getId());
resultObject.setVirtualMachineName(userVM.getName());
resultObject.setVirtualMachineName(userVM.getHostName());
resultObject.setVirtualMachineDisplayName(userVM.getDisplayName());
}

View File

@ -30,7 +30,7 @@ public class VMExecutorHelper {
VMOperationResultObject resultObject = new VMOperationResultObject();
resultObject.setId(vm.getId());
resultObject.setName(vm.getName());
resultObject.setName(vm.getHostName());
resultObject.setCreated(vm.getCreated());
resultObject.setZoneId(vm.getDataCenterId());
resultObject.setZoneName(managementServer.findDataCenterById(vm.getDataCenterId()).getName());
@ -38,7 +38,7 @@ public class VMExecutorHelper {
resultObject.setServiceOfferingId(vm.getServiceOfferingId());
resultObject.setHaEnabled(vm.isHaEnabled());
if (vm.getDisplayName() == null || vm.getDisplayName().length() == 0) {
resultObject.setDisplayName(vm.getName());
resultObject.setDisplayName(vm.getHostName());
}
else {
resultObject.setDisplayName(vm.getDisplayName());

View File

@ -151,7 +151,7 @@ public class VolumeOperationExecutor extends BaseAsyncJobExecutor {
private AttachVolumeOperationResultObject composeAttachResultObject(UserVm instance, VolumeVO vol) {
AttachVolumeOperationResultObject resultObject = new AttachVolumeOperationResultObject();
resultObject.setVmName(instance.getName());
resultObject.setVmName(instance.getHostName());
resultObject.setVmDisplayName(instance.getDisplayName());
resultObject.setVirtualMachineId(instance.getId());
resultObject.setVmState(instance.getState().toString());

View File

@ -87,7 +87,7 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu
if (vm.getHostId() == null) {
return -1;
}
GetVncPortAnswer answer = (GetVncPortAnswer) _agentMgr.easySend(vm.getHostId(), new GetVncPortCommand(vm.getId(), vm.getName()));
GetVncPortAnswer answer = (GetVncPortAnswer) _agentMgr.easySend(vm.getHostId(), new GetVncPortCommand(vm.getId(), vm.getHostName()));
return answer == null ? -1 : answer.getPort();
}

View File

@ -52,18 +52,16 @@ import com.cloud.agent.api.ConsoleProxyLoadReportCommand;
import com.cloud.agent.api.MigrateCommand;
import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.RebootCommand;
import com.cloud.agent.api.Start2Command;
import com.cloud.agent.api.StartConsoleProxyAnswer;
import com.cloud.agent.api.StartConsoleProxyCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupProxyCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.StopCommand;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
import com.cloud.agent.api.proxy.UpdateCertificateCommand;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.api.to.VirtualMachineTO.SshMonitor;
import com.cloud.agent.manager.Commands;
import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException;
@ -86,7 +84,6 @@ import com.cloud.dc.dao.HostPodDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.domain.DomainVO;
import com.cloud.event.EventState;
import com.cloud.event.EventTypes;
@ -139,6 +136,7 @@ import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountVO;
import com.cloud.user.User;
import com.cloud.user.UserVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
@ -156,6 +154,7 @@ import com.cloud.utils.exception.ExecutionException;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.State;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
@ -389,7 +388,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
return null;
} else {
if (s_logger.isTraceEnabled())
s_logger.trace("Console proxy " + proxy.getName() + " is started");
s_logger.trace("Console proxy " + proxy.getHostName() + " is started");
// if it is a new assignment or a changed assignment,
// update the
@ -532,7 +531,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
@Override
public ConsoleProxyVO startProxy(long proxyVmId, long startEventId) {
try {
return start(proxyVmId, startEventId);
return start2(proxyVmId, startEventId);
} catch (StorageUnavailableException e) {
s_logger.warn("Exception while trying to start console proxy", e);
return null;
@ -550,9 +549,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
public ConsoleProxyVO start2(long proxyVmId, long startEventId) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
DeploymentPlan plan = new DataCenterDeployment(proxy.getDataCenterId(), 1);
AccountVO systemAcct = _accountMgr.getSystemAccount();
return _vmMgr.start(proxy, plan, systemAcct);
UserVO systemUser = _accountMgr.getSystemUser();
return _vmMgr.start(proxy, null, systemUser, systemAcct);
}
@Override
@ -609,7 +608,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
if (state == State.Running) {
if (s_logger.isTraceEnabled())
s_logger.trace("Console proxy is already started: " + proxy.getName());
s_logger.trace("Console proxy is already started: " + proxy.getHostName());
return proxy;
}
@ -637,7 +636,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
if (!_consoleProxyDao.updateIf(proxy, Event.StartRequested, routingHost.getId())) {
if (s_logger.isDebugEnabled()) {
ConsoleProxyVO temp = _consoleProxyDao.findById(proxyId);
s_logger.debug("Unable to start console proxy " + proxy.getName() + " because it is not in a startable state : "
s_logger.debug("Unable to start console proxy " + proxy.getHostName() + " because it is not in a startable state : "
+ ((temp != null) ? temp.getState().toString() : "null"));
}
continue;
@ -657,7 +656,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
String privateIpAddress = allocPrivateIpAddress(proxy.getDataCenterId(), routingHost.getPodId(), proxy.getId(),
proxy.getPrivateMacAddress());
if (privateIpAddress == null && (_IpAllocator != null && !_IpAllocator.exteralIpAddressAllocatorEnabled())) {
String msg = "Unable to allocate private ip addresses for " + proxy.getName() + " in pod " + pod.getId();
String msg = "Unable to allocate private ip addresses for " + proxy.getHostName() + " in pod " + pod.getId();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
@ -671,7 +670,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
List<VolumeVO> vols = _storageMgr.prepare(proxy, routingHost);
if (vols == null || vols.size() == 0) {
String msg = "Unable to prepare storage for " + proxy.getName() + " in pod " + pod.getId();
String msg = "Unable to prepare storage for " + proxy.getHostName() + " in pod " + pod.getId();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
@ -681,7 +680,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
GuestOSVO guestOS = _guestOSDao.findById(proxy.getGuestOSId());
if (guestOS == null) {
String msg = "Could not find guest OS description for OSId "
+ proxy.getGuestOSId() + " for vm: " + proxy.getName();
+ proxy.getGuestOSId() + " for vm: " + proxy.getHostName();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
} else {
@ -692,21 +691,21 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
// carry the console proxy port info over so that we don't
// need to configure agent on this
StartConsoleProxyCommand cmdStart = new StartConsoleProxyCommand(_networkRate, _multicastRate,
_proxyCmdPort, proxy, proxy.getName(), "", vols, Integer.toString(_consoleProxyPort),
_proxyCmdPort, proxy, proxy.getHostName(), "", vols, Integer.toString(_consoleProxyPort),
Integer.toString(_consoleProxyUrlPort), _mgmt_host, _mgmt_port, _sslEnabled, guestOSDescription);
if (s_logger.isDebugEnabled())
s_logger.debug("Sending start command for console proxy " + proxy.getName() + " to " + routingHost.getName());
s_logger.debug("Sending start command for console proxy " + proxy.getHostName() + " to " + routingHost.getName());
try {
answer = _agentMgr.send(routingHost.getId(), cmdStart);
s_logger.debug("StartConsoleProxy Answer: " + (answer != null ? answer : "null"));
if (s_logger.isDebugEnabled())
s_logger.debug("Received answer on starting console proxy " + proxy.getName() + " on " + routingHost.getName());
s_logger.debug("Received answer on starting console proxy " + proxy.getHostName() + " on " + routingHost.getName());
if (answer != null && answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console proxy " + proxy.getName() + " started on " + routingHost.getName());
s_logger.debug("Console proxy " + proxy.getHostName() + " started on " + routingHost.getName());
}
if (answer instanceof StartConsoleProxyAnswer) {
@ -725,7 +724,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
event.setType(EventTypes.EVENT_PROXY_START);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("Console proxy started - " + proxy.getName());
event.setDescription("Console proxy started - " + proxy.getHostName());
_eventDao.persist(event);
break;
}
@ -733,13 +732,13 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
+ answer.getDetails());
} catch (OperationTimedoutException e) {
if (e.isActive()) {
s_logger.debug("Unable to start vm " + proxy.getName()
s_logger.debug("Unable to start vm " + proxy.getHostName()
+ " due to operation timed out and it is active so scheduling a restart.");
_haMgr.scheduleRestart(proxy, true);
return null;
}
} catch (AgentUnavailableException e) {
s_logger.debug("Agent " + routingHost.toString() + " was unavailable to start VM " + proxy.getName());
s_logger.debug("Agent " + routingHost.toString() + " was unavailable to start VM " + proxy.getHostName());
}
avoid.add(routingHost);
@ -765,7 +764,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
event.setType(EventTypes.EVENT_PROXY_START);
event.setLevel(EventVO.LEVEL_ERROR);
event.setStartId(startEventId);
event.setDescription("Starting console proxy failed due to unable to find a host - " + proxy.getName());
event.setDescription("Starting console proxy failed due to unable to find a host - " + proxy.getHostName());
_eventDao.persist(event);
throw new ExecutionException("Couldn't find a routingHost to run console proxy");
}
@ -854,7 +853,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
if (s_logger.isTraceEnabled()) {
s_logger.trace("Running proxy pool size : " + runningList.size());
for (ConsoleProxyVO proxy : runningList)
s_logger.trace("Running proxy instance : " + proxy.getName());
s_logger.trace("Running proxy instance : " + proxy.getHostName());
}
List<Pair<Long, Integer>> l = _consoleProxyDao.getProxyLoadMatrix();
@ -888,7 +887,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
if (s_logger.isDebugEnabled())
s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId);
Map<String, Object> context = createProxyInstance(dataCenterId);
Map<String, Object> context = createProxyInstance2(dataCenterId);
long proxyVmId = (Long) context.get("proxyVmId");
if (proxyVmId == 0) {
@ -928,7 +927,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
if (s_logger.isDebugEnabled())
s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId);
Map<String, Object> context = createProxyInstance(dataCenterId);
Map<String, Object> context = createProxyInstance2(dataCenterId);
long proxyVmId = (Long) context.get("proxyVmId");
if (proxyVmId == 0) {
@ -1044,7 +1043,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_PROXY_CREATE);
event.setLevel(EventVO.LEVEL_INFO);
event.setDescription("New console proxy created - " + proxy.getName());
event.setDescription("New console proxy created - " + proxy.getHostName());
_eventDao.persist(event);
txn.commit();
@ -1065,7 +1064,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
DataCenterVO dc = _dcDao.findById(dataCenterId);
AccountVO systemAcct = _accountMgr.getSystemAccount();
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId, 1);
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
List<NetworkOfferingVO> defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmPublicNetwork);
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork, NetworkOfferingVO.SystemVmManagementNetwork);
@ -1078,9 +1077,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
networks.add(new Pair<NetworkConfigurationVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan).get(0), null));
}
ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, _template.getId(), _template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), 0);
proxy = _consoleProxyDao.persist(proxy);
try {
VirtualMachineProfile vmProfile = _vmMgr.allocate(proxy, _template, _serviceOffering, networks, plan, systemAcct);
VirtualMachineProfile<ConsoleProxyVO> vmProfile = _vmMgr.allocate(proxy, _template, _serviceOffering, networks, plan, systemAcct);
} catch (InsufficientCapacityException e) {
s_logger.warn("InsufficientCapacity", e);
throw new CloudRuntimeException("Insufficient capacity exception", e);
@ -1470,13 +1468,13 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
try {
if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
try {
readyProxy = start(readyProxy.getId(), 0);
readyProxy = start2(readyProxy.getId(), 0);
} finally {
proxyLock.unlock();
}
} else {
if (s_logger.isInfoEnabled())
s_logger.info("Unable to acquire synchronization lock to start console proxy : " + readyProxy.getName());
s_logger.info("Unable to acquire synchronization lock to start console proxy : " + readyProxy.getHostName());
}
} finally {
proxyLock.releaseRef();
@ -1675,7 +1673,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
destroyProxy(proxyVmId, 0);
} else {
if (s_logger.isInfoEnabled())
s_logger.info("Console proxy " + proxy.getName() + " is started");
s_logger.info("Console proxy " + proxy.getHostName() + " is started");
}
}
}
@ -1863,7 +1861,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
return stop(proxy, startEventId);
} catch (AgentUnavailableException e) {
if (s_logger.isDebugEnabled())
s_logger.debug("Stopping console proxy " + proxy.getName() + " failed : exception " + e.toString());
s_logger.debug("Stopping console proxy " + proxy.getHostName() + " failed : exception " + e.toString());
return false;
}
}
@ -1896,7 +1894,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
if (answer != null) {
if (s_logger.isDebugEnabled())
s_logger.debug("Successfully reboot console proxy " + proxy.getName());
s_logger.debug("Successfully reboot console proxy " + proxy.getHostName());
SubscriptionMgr.getInstance()
.notifySubscribers(
@ -1911,12 +1909,12 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
event.setType(EventTypes.EVENT_PROXY_REBOOT);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("Console proxy rebooted - " + proxy.getName());
event.setDescription("Console proxy rebooted - " + proxy.getHostName());
_eventDao.persist(event);
return true;
} else {
if (s_logger.isDebugEnabled())
s_logger.debug("failed to reboot console proxy : " + proxy.getName());
s_logger.debug("failed to reboot console proxy : " + proxy.getHostName());
final EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
@ -1924,7 +1922,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
event.setType(EventTypes.EVENT_PROXY_REBOOT);
event.setLevel(EventVO.LEVEL_ERROR);
event.setStartId(startEventId);
event.setDescription("Rebooting console proxy failed - " + proxy.getName());
event.setDescription("Rebooting console proxy failed - " + proxy.getHostName());
_eventDao.persist(event);
return false;
}
@ -1997,7 +1995,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
event.setType(EventTypes.EVENT_PROXY_DESTROY);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("Console proxy destroyed - " + vm.getName());
event.setDescription("Console proxy destroyed - " + vm.getHostName());
_eventDao.persist(event);
txn.commit();
@ -2006,7 +2004,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
txn.rollback();
return false;
} finally {
s_logger.debug("console proxy vm is destroyed : " + vm.getName());
s_logger.debug("console proxy vm is destroyed : " + vm.getHostName());
}
}
}
@ -2030,7 +2028,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_PROXY_DESTROY);
event.setLevel(EventVO.LEVEL_INFO);
event.setDescription("Console proxy destroyed - " + proxy.getName());
event.setDescription("Console proxy destroyed - " + proxy.getHostName());
_eventDao.persist(event);
}
@ -2078,7 +2076,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
event.setType(EventTypes.EVENT_PROXY_STOP);
event.setLevel(EventVO.LEVEL_ERROR);
event.setStartId(startEventId);
event.setDescription("Stopping console proxy failed due to negative answer from agent - " + proxy.getName());
event.setDescription("Stopping console proxy failed due to negative answer from agent - " + proxy.getHostName());
_eventDao.persist(event);
return false;
}
@ -2096,7 +2094,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
event.setType(EventTypes.EVENT_PROXY_STOP);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("Console proxy stopped - " + proxy.getName());
event.setDescription("Console proxy stopped - " + proxy.getHostName());
_eventDao.persist(event);
return true;
} catch (OperationTimedoutException e) {
@ -2106,7 +2104,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
event.setType(EventTypes.EVENT_PROXY_STOP);
event.setLevel(EventVO.LEVEL_ERROR);
event.setStartId(startEventId);
event.setDescription("Stopping console proxy failed due to operation time out - " + proxy.getName());
event.setDescription("Stopping console proxy failed due to operation time out - " + proxy.getHostName());
_eventDao.persist(event);
throw new AgentUnavailableException(proxy.getHostId());
}
@ -2184,7 +2182,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
storageIps[1] = vols.get(1).getHostIp();
}
PrepareForMigrationCommand cmd = new PrepareForMigrationCommand(proxy.getName(), null, storageIps, vols, mirroredVols);
PrepareForMigrationCommand cmd = new PrepareForMigrationCommand(proxy.getHostName(), null, storageIps, vols, mirroredVols);
HostVO routingHost = null;
HashSet<Host> avoid = new HashSet<Host>();
@ -2204,8 +2202,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
}
if (!_storageMgr.share(proxy, vols, routingHost, false)) {
s_logger.warn("Can not share " + proxy.getName());
throw new StorageUnavailableException("Can not share " + proxy.getName(), vol);
s_logger.warn("Can not share " + proxy.getHostName());
throw new StorageUnavailableException("Can not share " + proxy.getHostName(), vol);
}
Answer answer = _agentMgr.easySend(routingHost.getId(), cmd);
@ -2389,26 +2387,23 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
}
@Override
public boolean finalizeDeployment(Commands cmds, ConsoleProxyVO proxy, VirtualMachineProfile profile, DeployDestination dest) {
Start2Command cmd = cmds.getCommand(Start2Command.class);
VirtualMachineTO vm = cmd.getVirtualMachine();
StringBuilder buf = new StringBuilder();
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<ConsoleProxyVO> profile, DeployDestination dest, ReservationContext context) {
StringBuilder buf = profile.getBootArgsBuilder();
buf.append(" template=domP type=consoleproxy");
buf.append(" host=").append(_mgmt_host);
buf.append(" port=").append(_mgmt_port);
buf.append(" name=").append(vm.getName());
buf.append(" name=").append(profile.getVirtualMachine().getHostName());
if (_sslEnabled) {
buf.append(" premium=true");
}
buf.append(" zone=").append(dest.getDataCenter().getId());
buf.append(" pod=").append(dest.getPod().getId());
buf.append(" guid=Proxy.").append(vm.getId());
buf.append(" proxy_vm=").append(vm.getId());
NicTO controlNic = null;
for (NicTO nic : vm.getNics()) {
buf.append(" guid=Proxy.").append(profile.getId());
buf.append(" proxy_vm=").append(profile.getId());
NicProfile controlNic = null;
for (NicProfile nic : profile.getNics()) {
int deviceId = nic.getDeviceId();
buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp());
buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address());
buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
if (nic.isDefaultNic()) {
buf.append(" gateway=").append(nic.getGateway());
@ -2417,9 +2412,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
buf.append(" dns2=").append(nic.getDns2());
}
}
if (nic.getType() == TrafficType.Management) {
if (nic.getTrafficType() == TrafficType.Management) {
buf.append(" localgw=").append(dest.getPod().getGateway());
} else if (nic.getType() == TrafficType.Control) {
} else if (nic.getTrafficType() == TrafficType.Control) {
controlNic = nic;
}
@ -2427,22 +2422,33 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
String bootArgs = buf.toString();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Boot Args for " + vm + ": " + bootArgs);
s_logger.debug("Boot Args for " + profile + ": " + bootArgs);
}
vm.setBootArgs(bootArgs);
if (controlNic == null) {
throw new CloudRuntimeException("Didn't start a control port");
}
SshMonitor monitor = new SshMonitor(controlNic.getIp(), 3922);
vm.setMonitor(monitor);
profile.setParameter("control.nic", controlNic);
return true;
}
@Override
public boolean processDeploymentResult(Commands cmds, ConsoleProxyVO proxy, VirtualMachineProfile profile, DeployDestination dest) {
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<ConsoleProxyVO> profile, DeployDestination dest, ReservationContext context) {
NicProfile controlNic = (NicProfile)profile.getParameter("control.nic");
CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20);
cmds.addCommand("checkSsh", check);
return true;
}
@Override
public boolean processDeploymentResult(Commands cmds, VirtualMachineProfile<ConsoleProxyVO> profile, DeployDestination dest, ReservationContext context) {
CheckSshAnswer answer = (CheckSshAnswer)cmds.getAnswer("checkSsh");
if (!answer.getResult()) {
s_logger.warn("Unable to ssh to the VM: " + answer.getDetails());
return false;
}
return true;
}
@ -2458,7 +2464,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(proxyVmId);
//find corresponding host
if(consoleProxy!=null){
HostVO consoleProxyHost = _hostDao.findConsoleProxyHost(consoleProxy.getName(), Type.ConsoleProxy);
HostVO consoleProxyHost = _hostDao.findConsoleProxyHost(consoleProxy.getHostName(), Type.ConsoleProxy);
//now send a command to console proxy host
UpdateCertificateCommand certCmd = new UpdateCertificateCommand(certStr, true);
try {
@ -2502,4 +2508,17 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
public ConsoleProxyVO persist(ConsoleProxyVO proxy) {
return _consoleProxyDao.persist(proxy);
}
@Override
public ConsoleProxyVO findById(long id) {
return _consoleProxyDao.findById(id);
}
@Override
public ConsoleProxyVO findByName(String name) {
if (!VirtualMachineName.isValidConsoleProxyName(name)) {
return null;
}
return findById(VirtualMachineName.getConsoleProxyId(name));
}
}

View File

@ -48,7 +48,7 @@ import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.ha.WorkVO.WorkType;
import com.cloud.ha.HaWorkVO.WorkType;
import com.cloud.ha.dao.HighAvailabilityDao;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
@ -197,12 +197,12 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
// collect list of vm names for the alert email
VMInstanceVO vm = vms.get(0);
if (vm.isHaEnabled()) {
sb.append(" " + vm.getName());
sb.append(" " + vm.getHostName());
}
for (int i = 1; i < vms.size(); i++) {
vm = vms.get(i);
if (vm.isHaEnabled()) {
sb.append(" " + vm.getName());
sb.append(" " + vm.getHostName());
}
}
}
@ -215,7 +215,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
for (final VMInstanceVO vm : vms) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Notifying HA Mgr of to investigate vm " + vm.getId() + "-" + vm.getName());
s_logger.debug("Notifying HA Mgr of to investigate vm " + vm.getId() + "-" + vm.getHostName());
}
scheduleRestart(vm, true);
}
@ -229,7 +229,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
return;
}
final WorkVO work = new WorkVO(vm.getId(), vm.getType(), verifyHost ? WorkType.CheckStop : WorkType.Stop, Step.Scheduled, hostId, vm.getState(), 0, vm.getUpdated());
final HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), verifyHost ? WorkType.CheckStop : WorkType.Stop, Step.Scheduled, hostId, vm.getState(), 0, vm.getUpdated());
_haDao.persist(work);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Scheduled " + work.toString() + " verifyHost = " + verifyHost);
@ -256,7 +256,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
@Override
public boolean scheduleMigration(final VMInstanceVO vm) {
final WorkVO work = new WorkVO(vm.getId(), vm.getType(), WorkType.Migration, Step.Scheduled, vm.getHostId(), vm.getState(), 0, vm.getUpdated());
final HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), WorkType.Migration, Step.Scheduled, vm.getHostId(), vm.getState(), 0, vm.getUpdated());
_haDao.persist(work);
wakeupWorkers();
return true;
@ -282,8 +282,8 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
if (!(_forceHA || vm.isHaEnabled())) {
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "VM (name: "
+ vm.getName() + ", id: " + vm.getId() + ") stopped unexpectedly on host "
+ vm.getHostId(), "Virtual Machine " + vm.getName() + " (id: "
+ vm.getHostName() + ", id: " + vm.getId() + ") stopped unexpectedly on host "
+ vm.getHostId(), "Virtual Machine " + vm.getHostName() + " (id: "
+ vm.getId() + ") running on host [" + vm.getHostId()
+ "] stopped unexpectedly.");
@ -295,16 +295,16 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
mgr.completeStopCommand(vm);
}
final List<WorkVO> items = _haDao.findPreviousHA(vm.getId());
final List<HaWorkVO> items = _haDao.findPreviousHA(vm.getId());
int maxRetries = 0;
for (final WorkVO item : items) {
for (final HaWorkVO item : items) {
if (maxRetries < item.getTimesTried() && !item.canScheduleNew(_timeBetweenFailures)) {
maxRetries = item.getTimesTried();
break;
}
}
final WorkVO work = new WorkVO(vm.getId(), vm.getType(), WorkType.HA, investigate ? Step.Investigating : Step.Scheduled, hostId, vm.getState(),
final HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), WorkType.HA, investigate ? Step.Investigating : Step.Scheduled, hostId, vm.getState(),
maxRetries + 1, vm.getUpdated());
_haDao.persist(work);
@ -319,7 +319,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
return _handlers.get(type);
}
protected Long restart(final WorkVO work) {
protected Long restart(final HaWorkVO work) {
final long vmId = work.getInstanceId();
final VirtualMachineManager<VMInstanceVO> mgr = findManager(work.getType());
@ -369,12 +369,12 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
investigator = en.nextElement();
alive = investigator.isVmAlive(vm, host);
if (alive != null) {
s_logger.debug(investigator.getName() + " found VM " + vm.getName() + "to be alive? " + alive);
s_logger.debug(investigator.getName() + " found VM " + vm.getHostName() + "to be alive? " + alive);
break;
}
}
if (alive != null && alive) {
s_logger.debug("VM " + vm.getName() + " is found to be alive by " + investigator.getName());
s_logger.debug("VM " + vm.getHostName() + " is found to be alive by " + investigator.getName());
if (host.getStatus() == Status.Up) {
compareState(vm, new AgentVmInfo(vm.getInstanceName(), mgr, State.Running), false);
return null;
@ -400,7 +400,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
if (alive== null && !fenced) {
s_logger.debug("We were unable to fence off the VM " + vm.toString());
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getName() + " which was running on host " + hostDesc, "Insufficient capacity to restart VM, name: " + vm.getName() + ", id: " + vmId + " which was running on host " + hostDesc);
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getHostName() + " which was running on host " + hostDesc, "Insufficient capacity to restart VM, name: " + vm.getHostName() + ", id: " + vmId + " which was running on host " + hostDesc);
return (System.currentTimeMillis() >> 10) + _restartRetryInterval;
}
@ -412,8 +412,8 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
// send an alert for VMs that stop unexpectedly
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(),
"VM (name: " + vm.getName() + ", id: " + vmId + ") stopped unexpectedly on host "
+ hostDesc, "Virtual Machine " + vm.getName() + " (id: "
"VM (name: " + vm.getHostName() + ", id: " + vmId + ") stopped unexpectedly on host "
+ hostDesc, "Virtual Machine " + vm.getHostName() + " (id: "
+ vm.getId() + ") running on host [" + hostDesc + "] stopped unexpectedly.");
vm = mgr.get(vm.getId());
@ -453,19 +453,19 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
return (System.currentTimeMillis() >> 10) + _restartRetryInterval;
} catch (final InsufficientCapacityException e) {
s_logger.warn("Unable to restart " + vm.toString() + " due to " + e.getMessage());
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getName() + " which was running on host " + hostDesc, "Insufficient capacity to restart VM, name: " + vm.getName() + ", id: " + vmId + " which was running on host " + hostDesc);
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getHostName() + " which was running on host " + hostDesc, "Insufficient capacity to restart VM, name: " + vm.getHostName() + ", id: " + vmId + " which was running on host " + hostDesc);
return null;
} catch (final StorageUnavailableException e) {
s_logger.warn("Unable to restart " + vm.toString() + " due to " + e.getMessage());
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getName() + " which was running on host " + hostDesc, "The Storage is unavailable for trying to restart VM, name: " + vm.getName() + ", id: " + vmId + " which was running on host " + hostDesc);
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getHostName() + " which was running on host " + hostDesc, "The Storage is unavailable for trying to restart VM, name: " + vm.getHostName() + ", id: " + vmId + " which was running on host " + hostDesc);
return null;
} catch (ConcurrentOperationException e) {
s_logger.warn("Unable to restart " + vm.toString() + " due to " + e.getMessage());
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getName() + " which was running on host " + hostDesc, "The Storage is unavailable for trying to restart VM, name: " + vm.getName() + ", id: " + vmId + " which was running on host " + hostDesc);
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getHostName() + " which was running on host " + hostDesc, "The Storage is unavailable for trying to restart VM, name: " + vm.getHostName() + ", id: " + vmId + " which was running on host " + hostDesc);
return null;
} catch (ExecutionException e) {
s_logger.warn("Unable to restart " + vm.toString() + " due to " + e.getMessage());
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getName() + " which was running on host " + hostDesc, "The Storage is unavailable for trying to restart VM, name: " + vm.getName() + ", id: " + vmId + " which was running on host " + hostDesc);
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getHostName() + " which was running on host " + hostDesc, "The Storage is unavailable for trying to restart VM, name: " + vm.getHostName() + ", id: " + vmId + " which was running on host " + hostDesc);
return null;
}
}
@ -481,7 +481,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
State agentState = info.state;
final String agentName = info.name;
final State serverState = vm.getState();
final String serverName = vm.getName();
final String serverName = vm.getHostName();
Command command = null;
@ -505,7 +505,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
HostVO hostVO = _hostDao.findById(vm.getHostId());
String hostDesc = "name: " + hostVO.getName() + " (id:" + hostVO.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "VM (name: " + vm.getName() + ", id: " + vm.getId() + ") stopped on host " + hostDesc + " due to storage failure", "Virtual Machine " + vm.getName() + " (id: " + vm.getId() + ") running on host [" + vm.getHostId() + "] stopped due to storage failure.");
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "VM (name: " + vm.getHostName() + ", id: " + vm.getId() + ") stopped on host " + hostDesc + " due to storage failure", "Virtual Machine " + vm.getHostName() + " (id: " + vm.getId() + ") running on host [" + vm.getHostId() + "] stopped due to storage failure.");
}
if (serverState == State.Migrating) {
@ -543,10 +543,10 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
info.mgr.completeStopCommand(vm);
command = info.mgr.cleanup(vm, agentName);
} else {
s_logger.debug("Ignoring VM in stopping mode: " + vm.getName());
s_logger.debug("Ignoring VM in stopping mode: " + vm.getHostName());
}
} else if (serverState == State.Starting) {
s_logger.debug("Ignoring VM in starting mode: " + vm.getName());
s_logger.debug("Ignoring VM in starting mode: " + vm.getHostName());
} else {
s_logger.debug("Sending cleanup to a stopped vm: " + agentName);
_instanceDao.updateIf(vm, VirtualMachine.Event.AgentReportStopped, null);
@ -677,7 +677,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
return commands;
}
public Long migrate(final WorkVO work) {
public Long migrate(final HaWorkVO work) {
final long vmId = work.getInstanceId();
final VirtualMachineManager<VMInstanceVO> mgr = findManager(work.getType());
@ -719,14 +719,14 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to find a host for migrating vm " + vmId);
}
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHostName + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Unable to find a suitable host");
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to migrate vm " + vm.getHostName() + " from host " + fromHostName + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Unable to find a suitable host");
}
} catch(final InsufficientCapacityException e) {
s_logger.warn("Unable to mgirate due to insufficient capacity " + vm.toString());
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHostName + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Insufficient capacity");
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to migrate vm " + vm.getHostName() + " from host " + fromHostName + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Insufficient capacity");
} catch(final StorageUnavailableException e) {
s_logger.warn("Storage is unavailable: " + vm.toString());
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHostName + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Storage is gone.");
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to migrate vm " + vm.getHostName() + " from host " + fromHostName + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Storage is gone.");
}
if (toHost == null) {
@ -773,7 +773,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
DataCenterVO dcVO = _dcDao.findById(vm.getDataCenterId());
HostPodVO podVO = _podDao.findById(vm.getPodId());
_alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHost.getName() + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Migrate Command failed. Please check logs.");
_alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), "Unable to migrate vm " + vm.getHostName() + " from host " + fromHost.getName() + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Migrate Command failed. Please check logs.");
_instanceDao.updateIf(vm, Event.OperationFailed, vm.getHostId());
_agentMgr.maintenanceFailed(vm.getHostId());
@ -811,7 +811,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
@Override
public void scheduleDestroy(VMInstanceVO vm, long hostId) {
final WorkVO work = new WorkVO(vm.getId(), vm.getType(), WorkType.Destroy, Step.Scheduled, hostId, vm.getState(), 0, vm.getUpdated());
final HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), WorkType.Destroy, Step.Scheduled, hostId, vm.getState(), 0, vm.getUpdated());
_haDao.persist(work);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Scheduled " + work.toString());
@ -824,7 +824,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
_haDao.delete(vm.getId(), WorkType.Destroy);
}
protected Long destroyVM(WorkVO work) {
protected Long destroyVM(HaWorkVO work) {
final VirtualMachineManager<VMInstanceVO> mgr = findManager(work.getType());
final VMInstanceVO vm = mgr.get(work.getInstanceId());
s_logger.info("Destroying " + vm.toString());
@ -861,7 +861,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
return (System.currentTimeMillis() >> 10) + _stopRetryInterval;
}
protected Long stopVM(final WorkVO work) {
protected Long stopVM(final HaWorkVO work) {
final VirtualMachineManager<VMInstanceVO> mgr = findManager(work.getType());
final VMInstanceVO vm = mgr.get(work.getInstanceId());
s_logger.info("Stopping " + vm.toString());
@ -916,9 +916,9 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
@Override
public List<VMInstanceVO> findTakenMigrationWork() {
List<WorkVO> works = _haDao.findTakenWorkItems(WorkType.Migration);
List<HaWorkVO> works = _haDao.findTakenWorkItems(WorkType.Migration);
List<VMInstanceVO> vms = new ArrayList<VMInstanceVO>(works.size());
for (WorkVO work : works) {
for (HaWorkVO work : works) {
vms.add(_instanceDao.findById(work.getInstanceId()));
}
return vms;
@ -1088,7 +1088,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
while (!_stopped) {
try {
s_logger.trace("Checking the database");
final WorkVO work = _haDao.take(_serverId);
final HaWorkVO work = _haDao.take(_serverId);
if (work == null) {
try {
synchronized(this) {

View File

@ -197,7 +197,7 @@ public class InvestigatorImpl implements Investigator {
Answer pingTestAnswer = _agentMgr.send(otherHost.getId(), new PingTestCommand(routerPrivateIp, privateIp), 30 * 1000);
if (pingTestAnswer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("user vm " + vm.getName() + " has been successfully pinged, returning that it is alive");
s_logger.debug("user vm " + vm.getHostName() + " has been successfully pinged, returning that it is alive");
}
return Boolean.TRUE;
}
@ -214,7 +214,7 @@ public class InvestigatorImpl implements Investigator {
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("user vm " + vm.getName() + " could not be pinged, returning that it is unknown");
s_logger.debug("user vm " + vm.getHostName() + " could not be pinged, returning that it is unknown");
}
return null;

View File

@ -17,10 +17,59 @@
*/
package com.cloud.hypervisor;
import java.util.List;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.offering.ServiceOffering;
import com.cloud.utils.component.AdapterBase;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
public abstract class HypervisorGuruBase extends AdapterBase implements HypervisorGuru {
protected HypervisorGuruBase() {
super();
}
protected NicTO toNicTO(NicProfile profile) {
NicTO to = new NicTO();
to.setDeviceId(profile.getDeviceId());
to.setBroadcastType(profile.getBroadcastType());
to.setType(profile.getTrafficType());
to.setIp(profile.getIp4Address());
to.setNetmask(profile.getNetmask());
to.setMac(profile.getMacAddress());
to.setDns1(profile.getDns1());
to.setDns2(profile.getDns2());
to.setGateway(profile.getGateway());
to.setDefaultNic(profile.isDefaultNic());
to.setBroadcastUri(profile.getBroadCastUri());
to.setIsolationuri(profile.getIsolationUri());
return to;
}
protected <T extends VirtualMachine> VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile<T> vmProfile) {
ServiceOffering offering = vmProfile.getServiceOffering();
VirtualMachine vm = vmProfile.getVirtualMachine();
VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), offering.getRamSize(), null, vmProfile.getOs());
List<NicProfile> nicProfiles = vmProfile.getNics();
NicTO[] nics = new NicTO[nicProfiles.size()];
int i = 0;
for (NicProfile nicProfile : nicProfiles) {
nics[i++] = toNicTO(nicProfile);
}
to.setNics(nics);
to.setDisks(vmProfile.getDisks().toArray(new VolumeTO[vmProfile.getDisks().size()]));
return to;
}
}

View File

@ -19,7 +19,11 @@ package com.cloud.hypervisor;
import javax.ejb.Local;
import com.cloud.offering.ServiceOffering;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.Storage;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@ -31,13 +35,22 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
}
@Override
public VirtualMachineProfile design(VirtualMachine vm, ServiceOffering offering) {
return null;
public HypervisorType getHypervisorType() {
return HypervisorType.XenServer;
}
@Override
public boolean check(VirtualMachineProfile profile) {
return true;
public <T extends VirtualMachine> VirtualMachineTO implement(VirtualMachineProfile<T> vm) {
VirtualMachineTemplate template = vm.getTemplate();
BootloaderType bt = BootloaderType.PyGrub;
if (template.getFormat() == Storage.ImageFormat.ISO || template.isRequiresHvm()) {
bt = BootloaderType.HVM;
}
VirtualMachineTO to = toVirtualMachineTO(vm);
to.setBootloader(bt);
return to;
}
}

View File

@ -564,7 +564,7 @@ public class Db20to21MigrationUtil {
proxy.setGuestMacAddress(guestMacAddress);
if(proxy.getState() == State.Running || proxy.getState() == State.Starting) {
System.out.println("System VM " + proxy.getName() + " is in active state, mark it to Stopping state for migration");
System.out.println("System VM " + proxy.getHostName() + " is in active state, mark it to Stopping state for migration");
proxy.setState(State.Stopping);
}
@ -572,7 +572,7 @@ public class Db20to21MigrationUtil {
proxy.setGuestIpAddress(guestIpAddress);
proxy.setGuestNetmask("255.255.0.0");
System.out.println("Assign link loal address to proxy " + proxy.getName() + ", link local address: " + guestIpAddress);
System.out.println("Assign link loal address to proxy " + proxy.getHostName() + ", link local address: " + guestIpAddress);
_consoleProxyDao.update(proxy.getId(), proxy);
}
@ -591,7 +591,7 @@ public class Db20to21MigrationUtil {
secStorageVm.setGuestMacAddress(guestMacAddress);
if(secStorageVm.getState() == State.Running || secStorageVm.getState() == State.Starting) {
System.out.println("System VM " + secStorageVm.getName() + " is in active state, mark it to Stopping state for migration");
System.out.println("System VM " + secStorageVm.getHostName() + " is in active state, mark it to Stopping state for migration");
secStorageVm.setState(State.Stopping);
}
@ -599,7 +599,7 @@ public class Db20to21MigrationUtil {
secStorageVm.setGuestIpAddress(guestIpAddress);
secStorageVm.setGuestNetmask("255.255.0.0");
System.out.println("Assign link loal address to secondary storage VM " + secStorageVm.getName() + ", link local address: " + guestIpAddress);
System.out.println("Assign link loal address to secondary storage VM " + secStorageVm.getHostName() + ", link local address: " + guestIpAddress);
_secStorageVmDao.update(secStorageVm.getId(), secStorageVm);
}
@ -616,7 +616,7 @@ public class Db20to21MigrationUtil {
if(router.getState() == State.Running || router.getState() == State.Starting) {
router.setState(State.Stopping);
System.out.println("System VM " + router.getName() + " is in active state, mark it to Stopping state for migration");
System.out.println("System VM " + router.getHostName() + " is in active state, mark it to Stopping state for migration");
_routerDao.update(router.getId(), router);
}
}
@ -680,11 +680,11 @@ public class Db20to21MigrationUtil {
deviceId = 1; // reset for each VM iteration
for(VolumeVO vol : volumes) {
if(vol.getVolumeType() == VolumeType.ROOT) {
System.out.println("Setting root volume device id to zero, vol: " + vol.getName() + ", instance: " + vm.getName());
System.out.println("Setting root volume device id to zero, vol: " + vol.getName() + ", instance: " + vm.getHostName());
vol.setDeviceId(0L);
} else if(vol.getVolumeType() == VolumeType.DATADISK) {
System.out.println("Setting data volume device id, vol: " + vol.getName() + ", instance: " + vm.getName() + ", device id: " + deviceId);
System.out.println("Setting data volume device id, vol: " + vol.getName() + ", instance: " + vm.getHostName() + ", device id: " + deviceId);
vol.setDeviceId(deviceId);

View File

@ -20,7 +20,7 @@ package com.cloud.network;
import java.util.List;
import java.util.Map;
import com.cloud.agent.api.to.NicTO;
import com.cloud.api.commands.AddVpnUserCmd;
import com.cloud.api.commands.AssignToLoadBalancerRuleCmd;
import com.cloud.api.commands.AssociateIPAddrCmd;
import com.cloud.api.commands.CreateIPForwardingRuleCmd;
@ -38,7 +38,6 @@ import com.cloud.api.commands.StartRouterCmd;
import com.cloud.api.commands.StopRouterCmd;
import com.cloud.api.commands.UpdateLoadBalancerRuleCmd;
import com.cloud.api.commands.UpgradeRouterCmd;
import com.cloud.api.commands.AddVpnUserCmd;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
@ -302,13 +301,13 @@ public interface NetworkManager extends Manager {
List<NetworkOfferingVO> getSystemAccountNetworkOfferings(String... offeringNames);
List<NicProfile> allocate(VirtualMachineProfile vm, List<Pair<NetworkConfigurationVO, NicProfile>> networks) throws InsufficientCapacityException;
List<NicProfile> allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair<NetworkConfigurationVO, NicProfile>> networks) throws InsufficientCapacityException;
NicTO[] prepare(VirtualMachineProfile profile, DeployDestination dest, Account user) throws InsufficientNetworkCapacityException, ConcurrentOperationException, ResourceUnavailableException;
void release(VirtualMachineProfile vmProfile);
List<NicProfile> prepare(VirtualMachineProfile<? extends VMInstanceVO> profile, DeployDestination dest, ReservationContext context) throws InsufficientNetworkCapacityException, ConcurrentOperationException, ResourceUnavailableException;
void release(VirtualMachineProfile<? extends VMInstanceVO> vmProfile);
<K extends VMInstanceVO> List<NicVO> getNics(K vm);
DomainRouter upgradeRouter(UpgradeRouterCmd cmd);
List<NicVO> getNics(VMInstanceVO vm);
List<AccountVO> getAccountsUsingNetworkConfiguration(long configurationId);
AccountVO getNetworkConfigurationOwner(long configurationId);

View File

@ -153,6 +153,7 @@ import com.cloud.vm.DomainRouter;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.State;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO;
@ -330,7 +331,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
if (router != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Router is " + router.getName());
s_logger.debug("Router is " + router.getHostName());
}
return sourceNat;
}
@ -1174,9 +1175,9 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
if (accountId == 0) {
accountId = userVm.getAccountId();
} else if (accountId != userVm.getAccountId()) {
s_logger.warn("guest vm " + userVm.getName() + " (id:" + userVm.getId() + ") belongs to account " + userVm.getAccountId()
s_logger.warn("guest vm " + userVm.getHostName() + " (id:" + userVm.getId() + ") belongs to account " + userVm.getAccountId()
+ ", previous vm in list belongs to account " + accountId);
throw new InvalidParameterValueException("guest vm " + userVm.getName() + " (id:" + userVm.getId() + ") belongs to account " + userVm.getAccountId()
throw new InvalidParameterValueException("guest vm " + userVm.getHostName() + " (id:" + userVm.getId() + ") belongs to account " + userVm.getAccountId()
+ ", previous vm in list belongs to account " + accountId);
}
@ -1194,12 +1195,12 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
// Make sure owner of router is owner of load balancer. Since we are already checking that all VMs belong to the same router, by checking router
// ownership once we'll make sure all VMs belong to the owner of the load balancer.
if (router.getAccountId() != loadBalancer.getAccountId()) {
throw new InvalidParameterValueException("guest vm " + userVm.getName() + " (id:" + userVm.getId() + ") does not belong to the owner of load balancer " +
throw new InvalidParameterValueException("guest vm " + userVm.getHostName() + " (id:" + userVm.getId() + ") does not belong to the owner of load balancer " +
loadBalancer.getName() + " (owner is account id " + loadBalancer.getAccountId() + ")");
}
} else if (router.getId() != nextRouter.getId()) {
throw new InvalidParameterValueException("guest vm " + userVm.getName() + " (id:" + userVm.getId() + ") belongs to router " + nextRouter.getName()
+ ", previous vm in list belongs to router " + router.getName());
throw new InvalidParameterValueException("guest vm " + userVm.getHostName() + " (id:" + userVm.getId() + ") belongs to router " + nextRouter.getHostName()
+ ", previous vm in list belongs to router " + router.getHostName());
}
// check for ip address/port conflicts by checking exising forwarding and loadbalancing rules
@ -1217,7 +1218,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
if (fwRule.getPublicPort().equals(loadBalancer.getPublicPort())) {
throw new NetworkRuleConflictException("An existing port forwarding service rule for " + ipAddress + ":" + loadBalancer.getPublicPort()
+ " exists, found while trying to apply load balancer " + loadBalancer.getName() + " (id:" + loadBalancer.getId() + ") to instance "
+ userVm.getName() + ".");
+ userVm.getHostName() + ".");
}
} else if (fwRule.getPrivateIpAddress().equals(privateIpAddress) && fwRule.getPrivatePort().equals(loadBalancer.getPrivatePort()) && fwRule.isEnabled()) {
// for the current load balancer, don't add the same instance to the load balancer more than once
@ -1516,14 +1517,14 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
if ((router != null) && (router.getState() == State.Running)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Disassociate ip " + router.getName());
s_logger.debug("Disassociate ip " + router.getHostName());
}
if (associateIP(router, ipAddrs, false, 0)) {
_ipAddressDao.unassignIpAddress(ipAddress);
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to dissociate IP : " + ipAddress + " due to failing to dissociate with router: " + router.getName());
s_logger.debug("Unable to dissociate IP : " + ipAddress + " due to failing to dissociate with router: " + router.getHostName());
}
final EventVO event = new EventVO();
@ -1532,7 +1533,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
event.setType(EventTypes.EVENT_NET_IP_RELEASE);
event.setLevel(EventVO.LEVEL_ERROR);
event.setParameters("address=" + ipAddress + "\nsourceNat="+ip.isSourceNat());
event.setDescription("failed to released a public ip: " + ipAddress + " due to failure to disassociate with router " + router.getName());
event.setDescription("failed to released a public ip: " + ipAddress + " due to failure to disassociate with router " + router.getHostName());
_eventDao.persist(event);
return false;
@ -1758,7 +1759,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
}
@Override @DB
public List<NicProfile> allocate(VirtualMachineProfile vm, List<Pair<NetworkConfigurationVO, NicProfile>> networks) throws InsufficientCapacityException {
public List<NicProfile> allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair<NetworkConfigurationVO, NicProfile>> networks) throws InsufficientCapacityException {
List<NicProfile> nicProfiles = new ArrayList<NicProfile>(networks.size());
Transaction txn = Transaction.currentTxn();
@ -1878,7 +1879,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
}
@DB
protected Pair<NetworkGuru, NetworkConfigurationVO> implementNetworkConfiguration(long configId, DeployDestination dest, Account user) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientAddressCapacityException {
protected Pair<NetworkGuru, NetworkConfigurationVO> implementNetworkConfiguration(long configId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientAddressCapacityException {
Transaction.currentTxn();
Pair<NetworkGuru, NetworkConfigurationVO> implemented = new Pair<NetworkGuru, NetworkConfigurationVO>(null, null);
@ -1915,7 +1916,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
s_logger.debug("Asking " + element.getName() + " to implmenet " + config);
}
try {
element.implement(config, offering, dest, user);
element.implement(config, offering, dest, context);
} catch (InsufficientCapacityException e) {
throw new ResourceUnavailableException("Unable to start domain router for this VM", e);
}
@ -1932,12 +1933,10 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
}
@Override
public NicTO[] prepare(VirtualMachineProfile vmProfile, DeployDestination dest, Account user) throws InsufficientNetworkCapacityException, ConcurrentOperationException, ResourceUnavailableException {
public List<NicProfile> prepare(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, DeployDestination dest, ReservationContext context) throws InsufficientNetworkCapacityException, ConcurrentOperationException, ResourceUnavailableException {
List<NicVO> nics = _nicDao.listBy(vmProfile.getId());
NicTO[] nicTos = new NicTO[nics.size()];
int i = 0;
for (NicVO nic : nics) {
Pair<NetworkGuru, NetworkConfigurationVO> implemented = implementNetworkConfiguration(nic.getNetworkConfigurationId(), dest, user);
Pair<NetworkGuru, NetworkConfigurationVO> implemented = implementNetworkConfiguration(nic.getNetworkConfigurationId(), dest, context);
NetworkGuru concierge = implemented.first();
NetworkConfigurationVO config = implemented.second();
NicProfile profile = null;
@ -1962,18 +1961,17 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to prepare for " + nic);
}
element.prepare(config, profile, vmProfile, null, dest, user);
element.prepare(config, profile, vmProfile, dest, context);
}
}
nicTos[i++] = toNicTO(nic, profile, config);
vmProfile.addNic(profile);
}
return nicTos;
return vmProfile.getNics();
}
@Override
public void release(VirtualMachineProfile vmProfile) {
public void release(VirtualMachineProfile<? extends VMInstanceVO> vmProfile) {
List<NicVO> nics = _nicDao.listBy(vmProfile.getId());
for (NicVO nic : nics) {
NetworkConfigurationVO config = _networkConfigDao.findById(nic.getNetworkConfigurationId());
@ -2008,7 +2006,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
}
@Override
public <K extends VMInstanceVO> List<NicVO> getNics(K vm) {
public List<NicVO> getNics(VMInstanceVO vm) {
return _nicDao.listBy(vm.getId());
}

View File

@ -34,6 +34,7 @@ import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.NicDao;
@ -181,7 +182,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
}
@Override
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException,
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException {
assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? ";

View File

@ -31,6 +31,7 @@ import com.cloud.utils.Pair;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.Inject;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@Local(value={NetworkGuru.class})
@ -77,7 +78,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
}
@Override
public String reserve(NicProfile ch, NetworkConfiguration configuration, VirtualMachineProfile vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
public String reserve(NicProfile ch, NetworkConfiguration configuration, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
if (ch.getReservationId() != null) {
return ch.getReservationId();
}
@ -86,7 +87,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
long dcId = dc.getId();
if (ch.getIp4Address() != null) {
Pair<String, VlanVO> ipAndVlan = _vlanDao.assignIpAddress(dcId, vm.getVm().getAccountId(), vm.getVm().getDomainId(), VlanType.VirtualNetwork, true);
Pair<String, VlanVO> ipAndVlan = _vlanDao.assignIpAddress(dcId, vm.getVirtualMachine().getAccountId(), vm.getVirtualMachine().getDomainId(), VlanType.VirtualNetwork, true);
if (ipAndVlan == null) {
throw new InsufficientVirtualNetworkCapcityException("Unable to get public ip address in " + dcId);
}

View File

@ -33,12 +33,14 @@ import com.cloud.network.dao.NetworkConfigurationDao;
import com.cloud.network.router.DomainRouterManager;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.Inject;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
@ -57,13 +59,13 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
@Inject DomainRouterDao _routerDao;
@Override
public boolean implement(NetworkConfiguration guestConfig, NetworkOffering offering, DeployDestination dest, Account user) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException {
public boolean implement(NetworkConfiguration guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException {
if (offering.getGuestIpType() != GuestIpType.Virtualized) {
s_logger.trace("Not handling guest ip type = " + offering.getGuestIpType());
return false;
}
DomainRouterVO router = _routerMgr.deploy(guestConfig, offering, dest, user);
DomainRouterVO router = _routerMgr.deploy(guestConfig, offering, dest, context.getAccount());
if (router == null) {
throw new ResourceUnavailableException("Unable to deploy the router for " + guestConfig);
}
@ -72,17 +74,24 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
}
@Override
public boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, DeployDestination dest, Account user) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException {
public boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException {
if (config.getTrafficType() != TrafficType.Guest || vm.getType() != Type.User) {
s_logger.trace("Domain Router only cares about guest network and User VMs");
return false;
}
return _routerMgr.addVirtualMachineIntoNetwork(config, nic, vm, user) != null;
if (vm.getType() != VirtualMachine.Type.User) {
return false;
}
@SuppressWarnings("unchecked")
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
return _routerMgr.addVirtualMachineIntoNetwork(config, nic, uservm, context) != null;
}
@Override
public boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) {
public boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, ReservationContext context) {
if (config.getTrafficType() != TrafficType.Guest || vm.getType() != Type.User) {
s_logger.trace("Domain Router only cares about guest network and User VMs");
return false;
@ -93,7 +102,7 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
}
@Override
public boolean shutdown(NetworkConfiguration config, NetworkOffering offering, Account user) throws ConcurrentOperationException {
public boolean shutdown(NetworkConfiguration config, ReservationContext context) throws ConcurrentOperationException {
if (config.getTrafficType() != TrafficType.Guest) {
s_logger.trace("Domain Router only cares about guet network.");
return false;

View File

@ -40,10 +40,12 @@ import com.cloud.network.VpnUserVO;
import com.cloud.offering.NetworkOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.Manager;
import com.cloud.vm.DomainRouter;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VirtualMachineProfile;
@ -181,5 +183,5 @@ public interface DomainRouterManager extends Manager {
boolean deleteRemoteAccessVpn(RemoteAccessVpnVO vpnVO);
DomainRouterVO addVirtualMachineIntoNetwork(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, Account caller) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException;
DomainRouterVO addVirtualMachineIntoNetwork(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<UserVm> vm, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException;
}

View File

@ -46,18 +46,22 @@ import com.cloud.agent.api.NetworkUsageCommand;
import com.cloud.agent.api.PrepareForMigrationCommand;
import com.cloud.agent.api.RebootAnswer;
import com.cloud.agent.api.RebootRouterCommand;
import com.cloud.agent.api.Start2Command;
import com.cloud.agent.api.StartRouterAnswer;
import com.cloud.agent.api.StartRouterCommand;
import com.cloud.agent.api.StopCommand;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.routing.DhcpEntryCommand;
import com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand;
import com.cloud.agent.api.routing.SavePasswordCommand;
import com.cloud.agent.api.routing.VmDataCommand;
<<<<<<< HEAD
import com.cloud.agent.api.routing.VpnUsersCfgCommand;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.api.to.VirtualMachineTO.SshMonitor;
=======
>>>>>>> Harmony among gurus
import com.cloud.agent.manager.Commands;
import com.cloud.alert.AlertManager;
import com.cloud.api.commands.RebootRouterCmd;
@ -148,6 +152,7 @@ import com.cloud.user.UserStatisticsVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
import com.cloud.user.dao.UserStatisticsDao;
import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
@ -163,6 +168,7 @@ import com.cloud.vm.DomainRouter.Role;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.State;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VirtualMachine;
@ -372,16 +378,16 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
event.setType(EventTypes.EVENT_ROUTER_CREATE);
if (vols == null) {
event.setDescription("failed to create DHCP Server : " + router.getName());
event.setDescription("failed to create DHCP Server : " + router.getHostName());
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
throw new ExecutionException("Unable to create DHCP Server");
}
_routerDao.updateIf(router, Event.OperationSucceeded, null);
s_logger.info("DHCP server created: id=" + router.getId() + "; name=" + router.getName() + "; vlan=" + guestVlan.getVlanId() + "; pod=" + pod.getName());
s_logger.info("DHCP server created: id=" + router.getId() + "; name=" + router.getHostName() + "; vlan=" + guestVlan.getVlanId() + "; pod=" + pod.getName());
event.setDescription("successfully created DHCP Server : " + router.getName() + " with ip : " + router.getGuestIpAddress());
event.setDescription("successfully created DHCP Server : " + router.getHostName() + " with ip : " + router.getGuestIpAddress());
_eventDao.persist(event);
return router;
@ -547,14 +553,14 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
}
_routerDao.updateIf(router, Event.OperationSucceeded, null);
s_logger.debug("Router created: id=" + router.getId() + "; name=" + router.getName());
s_logger.debug("Router created: id=" + router.getId() + "; name=" + router.getHostName());
event = new EventVO();
event.setUserId(1L); // system user performed the action
event.setAccountId(accountId);
event.setType(EventTypes.EVENT_ROUTER_CREATE);
event.setStartId(startEventId);
event.setDescription("successfully created Domain Router : " + router.getName() + " with ip : " + publicIpAddress);
event.setDescription("successfully created Domain Router : " + router.getHostName() + " with ip : " + publicIpAddress);
_eventDao.persist(event);
success = true;
return router;
@ -609,7 +615,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
event.setType(EventTypes.EVENT_ROUTER_DESTROY);
event.setState(EventState.Started);
event.setParameters("id=" + routerId);
event.setDescription("Starting to destroy router : " + router.getName());
event.setDescription("Starting to destroy router : " + router.getHostName());
event = _eventDao.persist(event);
try {
@ -653,7 +659,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
completedEvent.setType(EventTypes.EVENT_ROUTER_DESTROY);
completedEvent.setStartId(event.getId());
completedEvent.setParameters("id=" + routerId);
completedEvent.setDescription("successfully destroyed router : " + router.getName());
completedEvent.setDescription("successfully destroyed router : " + router.getHostName());
_eventDao.persist(completedEvent);
return true;
@ -727,7 +733,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
final DomainRouterVO router = _routerDao.findById(routerId);
final String routerPrivateIpAddress = router.getPrivateIpAddress();
final String vmName = router.getName();
final String vmName = router.getHostName();
final String encodedPassword = rot13(password);
final SavePasswordCommand cmdSavePassword = new SavePasswordCommand(encodedPassword, vmIpAddress, routerPrivateIpAddress, vmName);
@ -866,9 +872,9 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
}
if (vnet != null) {
s_logger.debug("Router: " + router.getName() + " discovered vnet: " + vnet + " from existing VMs.");
s_logger.debug("Router: " + router.getHostName() + " discovered vnet: " + vnet + " from existing VMs.");
} else {
s_logger.debug("Router: " + router.getName() + " was unable to discover vnet from existing VMs. Acquiring new vnet.");
s_logger.debug("Router: " + router.getHostName() + " was unable to discover vnet from existing VMs. Acquiring new vnet.");
}
String routerMacAddress = null;
@ -894,10 +900,10 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
}
if (vnet == null) {
s_logger.error("Unable to get another vnet while starting router " + router.getName());
s_logger.error("Unable to get another vnet while starting router " + router.getHostName());
return null;
} else {
s_logger.debug("Router: " + router.getName() + " is using vnet: " + vnet);
s_logger.debug("Router: " + router.getHostName() + " is using vnet: " + vnet);
}
Answer answer = null;
@ -936,7 +942,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
/*Ram size can be changed by upgradeRouterCmd*/
router.setRamSize(offering.getRamSize());
final String name = VirtualMachineName.attachVnet(router.getName(), vnet);
final String name = VirtualMachineName.attachVnet(router.getHostName(), vnet);
router.setInstanceName(name);
long accountId = router.getAccountId();
// Use account level network domain if available
@ -973,7 +979,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
GuestOSVO guestOS = _guestOSDao.findById(router.getGuestOSId());
if (guestOS == null) {
String msg = "Could not find guest OS description for OSId "
+ router.getGuestOSId() + " for vm: " + router.getName();
+ router.getGuestOSId() + " for vm: " + router.getHostName();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
} else {
@ -995,13 +1001,13 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
}
if (resendRouterState(router)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Router " + router.getName() + " started on " + routingHost.getName());
s_logger.debug("Router " + router.getHostName() + " started on " + routingHost.getName());
}
started = true;
break;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Router " + router.getName() + " started on " + routingHost.getName() + " but failed to program rules");
s_logger.debug("Router " + router.getHostName() + " started on " + routingHost.getName() + " but failed to program rules");
}
sendStopCommand(router);
}
@ -1009,12 +1015,12 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
s_logger.debug("Unable to start " + router.toString() + " on host " + routingHost.toString() + " due to " + answer.getDetails());
} catch (OperationTimedoutException e) {
if (e.isActive()) {
s_logger.debug("Unable to start vm " + router.getName() + " due to operation timed out and it is active so scheduling a restart.");
s_logger.debug("Unable to start vm " + router.getHostName() + " due to operation timed out and it is active so scheduling a restart.");
_haMgr.scheduleRestart(router, true);
return null;
}
} catch (AgentUnavailableException e) {
s_logger.debug("Agent " + routingHost.toString() + " was unavailable to start VM " + router.getName());
s_logger.debug("Agent " + routingHost.toString() + " was unavailable to start VM " + router.getHostName());
}
avoid.add(routingHost);
@ -1038,7 +1044,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
s_logger.debug("Router " + router.toString() + " is now started on " + routingHost.toString());
}
event.setDescription("successfully started Domain Router: " + router.getName());
event.setDescription("successfully started Domain Router: " + router.getHostName());
_eventDao.persist(event);
return _routerDao.findById(routerId);
@ -1152,9 +1158,9 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
final List<UserVmVO> vms = _vmDao.listBy(router.getId(), State.Creating, State.Starting, State.Running, State.Stopping, State.Stopped, State.Migrating);
Commands cmds = new Commands(OnError.Continue);
for (UserVmVO vm: vms) {
if (vm.getGuestIpAddress() == null || vm.getGuestMacAddress() == null || vm.getName() == null)
if (vm.getGuestIpAddress() == null || vm.getGuestMacAddress() == null || vm.getHostName() == null)
continue;
DhcpEntryCommand decmd = new DhcpEntryCommand(vm.getGuestMacAddress(), vm.getGuestIpAddress(), router.getPrivateIpAddress(), vm.getName());
DhcpEntryCommand decmd = new DhcpEntryCommand(vm.getGuestMacAddress(), vm.getGuestIpAddress(), router.getPrivateIpAddress(), vm.getHostName());
cmds.addCommand(decmd);
}
if (cmds.size() > 0) {
@ -1374,11 +1380,11 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
if (answer != null && resendRouterState(router)) {
processStopOrRebootAnswer(router, answer);
event.setDescription("successfully rebooted Domain Router : " + router.getName());
event.setDescription("successfully rebooted Domain Router : " + router.getHostName());
_eventDao.persist(event);
return true;
} else {
event.setDescription("failed to reboot Domain Router : " + router.getName());
event.setDescription("failed to reboot Domain Router : " + router.getHostName());
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
return false;
@ -1674,7 +1680,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
answer = _agentMgr.send(hostId, stop);
if (!answer.getResult()) {
s_logger.error("Unable to stop router");
event.setDescription("failed to stop Domain Router : " + router.getName());
event.setDescription("failed to stop Domain Router : " + router.getHostName());
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
} else {
@ -1688,7 +1694,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
}
if (!stopped) {
event.setDescription("failed to stop Domain Router : " + router.getName());
event.setDescription("failed to stop Domain Router : " + router.getHostName());
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
_routerDao.updateIf(router, Event.OperationFailed, router.getHostId());
@ -1696,7 +1702,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
}
completeStopCommand(router, Event.OperationSucceeded);
event.setDescription("successfully stopped Domain Router : " + router.getName());
event.setDescription("successfully stopped Domain Router : " + router.getHostName());
_eventDao.persist(event);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Router " + router.toString() + " is stopped");
@ -1749,8 +1755,8 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
}
if( ! _storageMgr.share(router, vols, routingHost, false) ) {
s_logger.warn("Can not share " + vol.getPath() + " to " + router.getName() );
throw new StorageUnavailableException("Can not share " + vol.getPath() + " to " + router.getName(), vol);
s_logger.warn("Can not share " + vol.getPath() + " to " + router.getHostName() );
throw new StorageUnavailableException("Can not share " + vol.getPath() + " to " + router.getHostName(), vol);
}
final Answer answer = _agentMgr.easySend(routingHost.getId(), cmd);
@ -1846,7 +1852,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
try {
DomainRouterVO router = start(vm.getDomainRouterId(), 0);
if (router == null) {
s_logger.error("Can't find a domain router to start VM: " + vm.getName());
s_logger.error("Can't find a domain router to start VM: " + vm.getHostName());
return null;
}
@ -1873,10 +1879,10 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
int cmdIndex = 0;
int passwordIndex = -1;
int vmDataIndex = -1;
cmds.addCommand(new DhcpEntryCommand(vm.getGuestMacAddress(), vm.getGuestIpAddress(), router.getPrivateIpAddress(), vm.getName()));
cmds.addCommand(new DhcpEntryCommand(vm.getGuestMacAddress(), vm.getGuestIpAddress(), router.getPrivateIpAddress(), vm.getHostName()));
if (password != null) {
final String encodedPassword = rot13(password);
cmds.addCommand(new SavePasswordCommand(encodedPassword, vm.getPrivateIpAddress(), router.getPrivateIpAddress(), vm.getName()));
cmds.addCommand(new SavePasswordCommand(encodedPassword, vm.getPrivateIpAddress(), router.getPrivateIpAddress(), vm.getHostName()));
passwordIndex = cmdIndex;
}
@ -1885,22 +1891,22 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
String zoneName = _dcDao.findById(vm.getDataCenterId()).getName();
String routerPublicIpAddress = (router.getPublicIpAddress() != null) ? router.getPublicIpAddress() : vm.getGuestIpAddress();
cmds.addCommand(generateVmDataCommand(router.getPrivateIpAddress(), routerPublicIpAddress, vm.getPrivateIpAddress(), userData, serviceOffering, zoneName, vm.getGuestIpAddress(), vm.getName(), vm.getInstanceName(), vm.getId()));
cmds.addCommand(generateVmDataCommand(router.getPrivateIpAddress(), routerPublicIpAddress, vm.getPrivateIpAddress(), userData, serviceOffering, zoneName, vm.getGuestIpAddress(), vm.getHostName(), vm.getInstanceName(), vm.getId()));
vmDataIndex = cmdIndex;
Answer[] answers = _agentMgr.send(router.getHostId(), cmds);
if (!answers[0].getResult()) {
s_logger.error("Unable to set dhcp entry for " + vm.getId() + " - " + vm.getName() +" on domR: " + router.getName() + " due to " + answers[0].getDetails());
s_logger.error("Unable to set dhcp entry for " + vm.getId() + " - " + vm.getHostName() +" on domR: " + router.getHostName() + " due to " + answers[0].getDetails());
return null;
}
if (password != null && !answers[passwordIndex].getResult()) {
s_logger.error("Unable to set password for " + vm.getId() + " - " + vm.getName() + " due to " + answers[passwordIndex].getDetails());
s_logger.error("Unable to set password for " + vm.getId() + " - " + vm.getHostName() + " due to " + answers[passwordIndex].getDetails());
return null;
}
if (vmDataIndex > 0 && !answers[vmDataIndex].getResult()) {
s_logger.error("Unable to set VM data for " + vm.getId() + " - " + vm.getName() + " due to " + answers[vmDataIndex].getDetails());
s_logger.error("Unable to set VM data for " + vm.getId() + " - " + vm.getHostName() + " due to " + answers[vmDataIndex].getDetails());
return null;
}
return router;
@ -1908,10 +1914,10 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
s_logger.error("Unable to start router " + vm.getDomainRouterId() + " because storage is unavailable.");
return null;
} catch (AgentUnavailableException e) {
s_logger.error("Unable to setup the router " + vm.getDomainRouterId() + " for vm " + vm.getId() + " - " + vm.getName() + " because agent is unavailable");
s_logger.error("Unable to setup the router " + vm.getDomainRouterId() + " for vm " + vm.getId() + " - " + vm.getHostName() + " because agent is unavailable");
return null;
} catch (OperationTimedoutException e) {
s_logger.error("Unable to setup the router " + vm.getDomainRouterId() + " for vm " + vm.getId() + " - " + vm.getName() + " because agent is too busy");
s_logger.error("Unable to setup the router " + vm.getDomainRouterId() + " for vm " + vm.getId() + " - " + vm.getHostName() + " because agent is too busy");
return null;
}
}
@ -1947,7 +1953,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
final CreateZoneVlanCommand cmdCreateZoneVlan = new CreateZoneVlanCommand(router);
CreateZoneVlanAnswer answer = (CreateZoneVlanAnswer) _agentMgr.easySend(router.getHostId(), cmdCreateZoneVlan);
if(!answer.getResult()){
s_logger.error("Unable to create zone vlan for router: "+router.getName()+ " zoneVlan: "+zoneVlan);
s_logger.error("Unable to create zone vlan for router: "+router.getHostName()+ " zoneVlan: "+zoneVlan);
return null;
}
return zoneVlan;
@ -1966,7 +1972,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
for (DomainRouterVO router : routers) {
String privateIP = router.getPrivateIpAddress();
if(privateIP != null){
final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getName());
final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName());
final NetworkUsageAnswer answer = (NetworkUsageAnswer)_agentMgr.easySend(router.getHostId(), usageCmd);
if(answer != null){
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
@ -2016,7 +2022,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
(accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
}
@Override @DB
@Override
public DomainRouterVO deploy(NetworkConfiguration guestConfig, NetworkOffering offering, DeployDestination dest, Account owner) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException, ResourceUnavailableException {
long dcId = dest.getDataCenter().getId();
@ -2026,7 +2032,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
assert guestConfig.getState() == NetworkConfiguration.State.Implemented : "Network is not yet fully implemented: " + guestConfig;
assert offering.getGuestIpType() == GuestIpType.Virtualized;
DataCenterDeployment plan = new DataCenterDeployment(dcId, 1);
DataCenterDeployment plan = new DataCenterDeployment(dcId);
guestConfig = _networkConfigurationDao.lockRow(guestConfig.getId(), true);
if (guestConfig == null) {
@ -2064,31 +2070,22 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
networks.add(new Pair<NetworkConfigurationVO, NicProfile>((NetworkConfigurationVO)guestConfig, gatewayNic));
networks.add(new Pair<NetworkConfigurationVO, NicProfile>(controlConfig, null));
Transaction txn = Transaction.currentTxn();
txn.start();
router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), _template.getId(), _template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestConfig.getId(), _offering.getOfferHA());
router = _routerDao.persist(router);
_itMgr.allocate(router, _template, _offering, networks, plan, owner);
txn.commit();
}
return _itMgr.start(router, plan, owner);
return _itMgr.start(router, null, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
}
@Override
public boolean finalizeDeployment(Commands cmds, DomainRouterVO router, VirtualMachineProfile profile, DeployDestination dest) {
Start2Command cmd = cmds.getCommand(Start2Command.class);
VirtualMachineTO vm = cmd.getVirtualMachine();
@Override
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest, ReservationContext context) {
StringBuilder buf = new StringBuilder();
buf.append(" template=domP type=router");
buf.append(" name=").append(vm.getName());
NicTO controlNic = null;
for (NicTO nic : vm.getNics()) {
buf.append(" name=").append(profile.getHostName());
NicProfile controlNic = null;
for (NicProfile nic : profile.getNics()) {
int deviceId = nic.getDeviceId();
buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp());
buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address());
buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
if (nic.isDefaultNic()) {
buf.append(" gateway=").append(nic.getGateway());
@ -2097,31 +2094,40 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
buf.append(" dns2=").append(nic.getDns2());
}
}
if (nic.getType() == TrafficType.Management) {
if (nic.getTrafficType() == TrafficType.Management) {
buf.append(" localgw=").append(dest.getPod().getGateway());
} else if (nic.getType() == TrafficType.Control) {
} else if (nic.getTrafficType() == TrafficType.Control) {
controlNic = nic;
}
}
String bootArgs = buf.toString();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Boot Args for " + vm + ": " + bootArgs);
s_logger.debug("Boot Args for " + profile + ": " + buf.toString());
}
vm.setBootArgs(bootArgs);
if (controlNic == null) {
throw new CloudRuntimeException("Didn't start a control port");
}
SshMonitor monitor = new SshMonitor(controlNic.getIp(), 3922);
vm.setMonitor(monitor);
profile.setParameter("control.nic", controlNic);
return true;
}
@Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest, ReservationContext context) {
NicProfile controlNic = (NicProfile)profile.getParameter("control.nic");
cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20));
return true;
}
@Override
public boolean processDeploymentResult(Commands cmds, DomainRouterVO router, VirtualMachineProfile profile, DeployDestination dest) {
public boolean processDeploymentResult(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest, ReservationContext context) {
CheckSshAnswer answer = (CheckSshAnswer)cmds.getAnswer("checkSsh");
if (!answer.getResult()) {
s_logger.warn("Unable to ssh to the VM: " + answer.getDetails());
return false;
}
return true;
}
@ -2192,20 +2198,19 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
}
}
public DomainRouterVO start(long routerId, Account caller) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
return start(_routerDao.findById(routerId), caller);
public DomainRouterVO start(long routerId, User user, Account caller) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
return start(_routerDao.findById(routerId), user, caller);
}
public DomainRouterVO start(DomainRouterVO router, Account caller) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
DataCenterDeployment plan = new DataCenterDeployment(router.getDataCenterId(), 1);
return _itMgr.start(router, plan, caller);
public DomainRouterVO start(DomainRouterVO router, User user, Account caller) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
return _itMgr.start(router, null, user, caller);
}
@Override
public DomainRouterVO addVirtualMachineIntoNetwork(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, Account caller) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException {
public DomainRouterVO addVirtualMachineIntoNetwork(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<UserVm> profile, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException {
DomainRouterVO router = _routerDao.findByNetworkConfiguration(config.getId());
try {
router = start(router, caller);
router = start(router, context.getCaller(), context.getAccount());
} catch (InsufficientNetworkCapacityException e) {
throw e;
} catch (InsufficientCapacityException e) {
@ -2213,12 +2218,12 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
}
if (router == null) {
s_logger.error("Can't find a domain router to start VM: " + vm.getName());
throw new ResourceUnavailableException("Can't find a domain router to start " + vm + " in " + config);
s_logger.error("Can't find a domain router to start VM: " + profile);
throw new ResourceUnavailableException("Can't find a domain router to start " + profile + " in " + config);
}
String password = null;
String userData = vm.getUserData();
String userData = profile.getVirtualMachine().getUserData();
int cmdsLength = (password == null ? 0:1) + 1;
Commands cmds = new Commands(OnError.Stop);
String routerPublicIpAddress = nic.getIp4Address();
@ -2233,17 +2238,17 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
}
}
cmds.addCommand("dhcp", new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), routerControlIpAddress, vm.getName()));
cmds.addCommand("dhcp", new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), routerControlIpAddress, profile.getVirtualMachine().getHostName()));
if (password != null) {
final String encodedPassword = rot13(password);
cmds.addCommand("password", new SavePasswordCommand(encodedPassword, nic.getIp4Address(), routerControlIpAddress, vm.getName()));
cmds.addCommand("password", new SavePasswordCommand(encodedPassword, nic.getIp4Address(), routerControlIpAddress, profile.getVirtualMachine().getHostName()));
}
String serviceOffering = _serviceOfferingDao.findById(vm.getServiceOfferingId()).getDisplayText();
String serviceOffering = _serviceOfferingDao.findById(profile.getServiceOfferingId()).getDisplayText();
String zoneName = _dcDao.findById(config.getDataCenterId()).getName();
cmds.addCommand("vmdata", generateVmDataCommand(routerControlIpAddress, routerPublicIpAddress, nic.getIp4Address(), userData, serviceOffering, zoneName, nic.getIp4Address(), vm.getName(), vm.getName(), vm.getId()));
cmds.addCommand("vmdata", generateVmDataCommand(routerControlIpAddress, routerPublicIpAddress, nic.getIp4Address(), userData, serviceOffering, zoneName, nic.getIp4Address(), profile.getVirtualMachine().getHostName(), profile.getVirtualMachine().getHostName(), profile.getId()));
try {
_agentMgr.send(router.getHostId(), cmds);
@ -2255,19 +2260,19 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
Answer answer = cmds.getAnswer("dhcp");
if (!answer.getResult()) {
s_logger.error("Unable to set dhcp entry for " + vm.getId() + " - " + vm.getName() +" on domR: " + router.getName() + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to set dhcp entry for " + vm + " due to " + answer.getDetails());
s_logger.error("Unable to set dhcp entry for " + profile +" on domR: " + router.getHostName() + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to set dhcp entry for " + profile + " due to " + answer.getDetails());
}
answer = cmds.getAnswer("password");
if (answer != null && !answer.getResult()) {
s_logger.error("Unable to set password for " + vm.getId() + " - " + vm.getName() + " due to " + answer.getDetails());
s_logger.error("Unable to set password for " + profile + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to set password due to " + answer.getDetails());
}
answer = cmds.getAnswer("vmdata");
if (answer != null && !answer.getResult()) {
s_logger.error("Unable to set VM data for " + vm.getId() + " - " + vm.getName() + " due to " + answer.getDetails());
s_logger.error("Unable to set VM data for " + profile + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to set VM data due to " + answer.getDetails());
}
return router;
@ -2305,4 +2310,18 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
return false;
}
}
@Override
public DomainRouterVO findById(long id) {
return _routerDao.findById(id);
}
@Override
public DomainRouterVO findByName(String name) {
if (!VirtualMachineName.isValidRouterName(name)) {
return null;
}
return _routerDao.findById(VirtualMachineName.getRouterId(name));
}
}

View File

@ -1187,7 +1187,7 @@ public class ManagementServerImpl implements ManagementServer {
try {
success = (success && _vmMgr.stop(vm, 0));
} catch (AgentUnavailableException aue) {
s_logger.warn("Agent running on host " + vm.getHostId() + " is unavailable, unable to stop vm " + vm.getName());
s_logger.warn("Agent running on host " + vm.getHostId() + " is unavailable, unable to stop vm " + vm.getHostName());
success = false;
}
}
@ -1656,7 +1656,7 @@ public class ManagementServerImpl implements ManagementServer {
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("VM created: " + created.getId() + "-" + created.getName());
s_logger.debug("VM created: " + created.getId() + "-" + created.getHostName());
}
boolean executionExceptionFlag = false;
boolean storageUnavailableExceptionFlag = false;
@ -1738,7 +1738,7 @@ public class ManagementServerImpl implements ManagementServer {
throw new ConcurrentOperationException(concurrentOperationExceptionMsg);
}
else{
throw new CloudRuntimeException("Unable to start the VM " + created.getId() + "-" + created.getName());
throw new CloudRuntimeException("Unable to start the VM " + created.getId() + "-" + created.getHostName());
}
} else {
@ -1755,7 +1755,7 @@ public class ManagementServerImpl implements ManagementServer {
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("VM started: " + started.getId() + "-" + started.getName());
s_logger.debug("VM started: " + started.getId() + "-" + started.getHostName());
}
return started;
}
@ -3100,7 +3100,7 @@ public class ManagementServerImpl implements ManagementServer {
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("accountIdEQ", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
sb.and("accountIdIN", sb.entity().getAccountId(), SearchCriteria.Op.IN);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("name", sb.entity().getHostName(), SearchCriteria.Op.LIKE);
sb.and("stateEQ", sb.entity().getState(), SearchCriteria.Op.EQ);
sb.and("stateNEQ", sb.entity().getState(), SearchCriteria.Op.NEQ);
sb.and("stateNIN", sb.entity().getState(), SearchCriteria.Op.NIN);
@ -3466,7 +3466,7 @@ public class ManagementServerImpl implements ManagementServer {
Object keyword = cmd.getKeyword();
SearchBuilder<DomainRouterVO> sb = _routerDao.createSearchBuilder();
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("name", sb.entity().getHostName(), SearchCriteria.Op.LIKE);
sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.IN);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
@ -4036,18 +4036,18 @@ public class ManagementServerImpl implements ManagementServer {
@Override
public int getVncPort(VirtualMachine vm) {
if (vm.getHostId() == null) {
s_logger.warn("VM " + vm.getName() + " does not have host, return -1 for its VNC port");
s_logger.warn("VM " + vm.getHostName() + " does not have host, return -1 for its VNC port");
return -1;
}
if(s_logger.isTraceEnabled())
s_logger.trace("Trying to retrieve VNC port from agent about VM " + vm.getName());
s_logger.trace("Trying to retrieve VNC port from agent about VM " + vm.getHostName());
GetVncPortAnswer answer = (GetVncPortAnswer) _agentMgr.easySend(vm.getHostId(), new GetVncPortCommand(vm.getId(), vm.getInstanceName()));
int port = answer == null ? -1 : answer.getPort();
if(s_logger.isTraceEnabled())
s_logger.trace("Retrieved VNC port about VM " + vm.getName() + " is " + port);
s_logger.trace("Retrieved VNC port about VM " + vm.getHostName() + " is " + port);
return port;
}
@ -6048,7 +6048,7 @@ public class ManagementServerImpl implements ManagementServer {
}
for(ConsoleProxyVO cp : cpList)
{
Long cpHostId = hostNameToHostIdMap.get(cp.getName());
Long cpHostId = hostNameToHostIdMap.get(cp.getHostName());
//now send a command to each console proxy host
UpdateCertificateCommand certCmd = new UpdateCertificateCommand(_certDao.findById(certVOId).getCertificate(), false);
try {

View File

@ -213,7 +213,7 @@ public class ConsoleProxyServlet extends HttpServlet {
return;
}
String vmName = vm.getName();
String vmName = vm.getHostName();
if(vmName == null)
vmName = vm.getInstanceName();

View File

@ -22,7 +22,6 @@ import java.util.List;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.agent.manager.Commands;
import com.cloud.api.commands.CancelPrimaryStorageMaintenanceCmd;
import com.cloud.api.commands.CreateStoragePoolCmd;
@ -52,6 +51,7 @@ import com.cloud.utils.component.Manager;
import com.cloud.utils.exception.ExecutionException;
import com.cloud.vm.DiskProfile;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
public interface StorageManager extends Manager {
@ -344,6 +344,6 @@ public interface StorageManager extends Manager {
void createCapacityEntry(StoragePoolVO storagePool, long allocated);
VolumeTO[] prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException;
void release(VirtualMachineProfile vm);
void prepare(VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException;
void release(VirtualMachineProfile<? extends VirtualMachine> vm);
}

View File

@ -902,7 +902,7 @@ public class StorageManagerImpl implements StorageManager {
List<StoragePoolVO> avoids, long size) {
List<VolumeVO> volumes = create(account, vm, template, dc, pod, offering, diskOffering, avoids, size);
if( volumes == null || volumes.size() == 0) {
throw new CloudRuntimeException("Unable to create volume for " + vm.getName());
throw new CloudRuntimeException("Unable to create volume for " + vm.getHostName());
}
for (VolumeVO v : volumes) {
@ -2601,14 +2601,13 @@ public class StorageManagerImpl implements StorageManager {
}
@Override
public VolumeTO[] prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException {
public void prepare(VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException {
List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Preparing " + vols.size() + " volumes for " + vm);
}
List<VolumeVO> recreateVols = new ArrayList<VolumeVO>(vols.size());
VolumeTO[] disks = new VolumeTO[vols.size()];
int i = 0;
for (VolumeVO vol : vols) {
@ -2628,7 +2627,7 @@ public class StorageManagerImpl implements StorageManager {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Volume " + vol + " is ready.");
}
disks[i++] = new VolumeTO(vol, pool);
vm.addDisk(new VolumeTO(vol, pool));
}
} else if (state == Volume.State.Allocated) {
if (s_logger.isDebugEnabled()) {
@ -2680,10 +2679,9 @@ public class StorageManagerImpl implements StorageManager {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Volume " + newVol + " is created on " + created.second());
}
disks[i++] = created.first();
vm.addDisk(created.first());
}
return disks;
}
@DB
@ -2700,7 +2698,7 @@ public class StorageManagerImpl implements StorageManager {
}
}
public Pair<VolumeTO, StoragePool> createVolume(VolumeVO toBeCreated, DiskOfferingVO offering, VirtualMachineProfile vm, List<? extends Volume> alreadyCreated, DeployDestination dest) {
public Pair<VolumeTO, StoragePool> createVolume(VolumeVO toBeCreated, DiskOfferingVO offering, VirtualMachineProfile<? extends VirtualMachine> vm, List<? extends Volume> alreadyCreated, DeployDestination dest) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating volume: " + toBeCreated);
}

View File

@ -28,11 +28,11 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.deploy.DeployDestination;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.server.StatsCollector;
@ -241,11 +241,11 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement
}
@Override
public StoragePool allocateTo(DiskProfile dskCh, VirtualMachineProfile vm, DeployDestination dest, List<? extends Volume> disks, Set<? extends StoragePool> avoids) {
public StoragePool allocateTo(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, List<? extends Volume> disks, Set<? extends StoragePool> avoids) {
VMInstanceVO instance = (VMInstanceVO)(vm.getVm());
VMInstanceVO instance = (VMInstanceVO)(vm.getVirtualMachine());
VMTemplateVO template = vm.getTemplateId() != null ? _templateDao.findById(vm.getTemplateId()) : null;
VMTemplateVO template = _templateDao.findById(instance.getTemplateId());
return allocateToPool(dskCh, (DataCenterVO)dest.getDataCenter(), (HostPodVO)dest.getPod(), dest.getCluster().getId(), instance, template, avoids);
}
}

View File

@ -55,6 +55,7 @@ import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfileImpl;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
@ -103,7 +104,7 @@ public class LocalStoragePoolAllocator extends FirstFitStoragePoolAllocator {
}
Set<StoragePool> myAvoids = new HashSet<StoragePool>(avoid);
VirtualMachineProfile vmc = new VirtualMachineProfile(vm.getType());
VirtualMachineProfile<VMInstanceVO> vmc = new VirtualMachineProfileImpl<VMInstanceVO>(vm.getType());
StoragePool pool = null;
while ((pool = super.allocateToPool(dskCh, dc, pod, clusterId, vm, template, myAvoids)) != null) {
myAvoids.add(pool);

View File

@ -43,5 +43,5 @@ public interface StoragePoolAllocator extends Adapter {
String chooseStorageIp(VirtualMachine vm, Host host, Host storage);
StoragePool allocateTo(DiskProfile dskCh, VirtualMachineProfile vm, DeployDestination dest, List<? extends Volume> disks, Set<? extends StoragePool> avoids);
StoragePool allocateTo(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, List<? extends Volume> disks, Set<? extends StoragePool> avoids);
}

View File

@ -309,7 +309,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
if (state == State.Running) {
if (s_logger.isTraceEnabled())
s_logger.trace("Secondary storage vm is already started: "
+ secStorageVm.getName());
+ secStorageVm.getHostName());
saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "Secondary storage vm is already started", startEventId);
return secStorageVm;
}
@ -334,7 +334,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
if (s_logger.isDebugEnabled()) {
SecondaryStorageVmVO temp = _secStorageVmDao.findById(secStorageVmId);
s_logger.debug("Unable to start secondary storage vm "
+ secStorageVm.getName()
+ secStorageVm.getHostName()
+ " because it is not in a startable state : "
+ ((temp != null) ? temp.getState().toString() : "null"));
}
@ -357,7 +357,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
secStorageVm.getDataCenterId(), routingHost.getPodId(),
secStorageVm.getId(), secStorageVm.getPrivateMacAddress());
if (privateIpAddress == null && (_IpAllocator != null && !_IpAllocator.exteralIpAddressAllocatorEnabled())) {
String msg = "Unable to allocate private ip addresses for " + secStorageVm.getName() + " in pod " + pod.getId();
String msg = "Unable to allocate private ip addresses for " + secStorageVm.getHostName() + " in pod " + pod.getId();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
@ -370,7 +370,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
List<VolumeVO> vols = _storageMgr.prepare(secStorageVm, routingHost);
if (vols == null || vols.size() == 0) {
String msg = "Unable to prepare storage for " + secStorageVm.getName() + " in pod " + pod.getId();
String msg = "Unable to prepare storage for " + secStorageVm.getHostName() + " in pod " + pod.getId();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
@ -381,7 +381,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
GuestOSVO guestOS = _guestOSDao.findById(secStorageVm.getGuestOSId());
if (guestOS == null) {
String msg = "Could not find guest OS description for OSId "
+ secStorageVm.getGuestOSId() + " for vm: " + secStorageVm.getName();
+ secStorageVm.getGuestOSId() + " for vm: " + secStorageVm.getHostName();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
} else {
@ -392,11 +392,11 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
// need to configure agent on this
StartSecStorageVmCommand cmdStart = new StartSecStorageVmCommand(_networkRate,
_multicastRate, _secStorageVmCmdPort, secStorageVm,
secStorageVm.getName(), "", vols, _mgmt_host, _mgmt_port, _useSSlCopy, guestOSDescription);
secStorageVm.getHostName(), "", vols, _mgmt_host, _mgmt_port, _useSSlCopy, guestOSDescription);
if (s_logger.isDebugEnabled())
s_logger.debug("Sending start command for secondary storage vm "
+ secStorageVm.getName()
+ secStorageVm.getHostName()
+ " to "
+ routingHost.getName());
@ -406,13 +406,13 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
if (s_logger.isDebugEnabled())
s_logger.debug("Received answer on starting secondary storage vm "
+ secStorageVm.getName()
+ secStorageVm.getHostName()
+ " on "
+ routingHost.getName());
if ( answer != null && answer.getResult() ) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary storage vm " + secStorageVm.getName()
s_logger.debug("Secondary storage vm " + secStorageVm.getHostName()
+ " started on " + routingHost.getName());
}
@ -430,7 +430,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
event.setType(EventTypes.EVENT_SSVM_START);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("Secondary Storage VM started - " + secStorageVm.getName());
event.setDescription("Secondary Storage VM started - " + secStorageVm.getHostName());
_eventDao.persist(event);
}
break;
@ -438,13 +438,13 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
s_logger.debug("Unable to start " + secStorageVm.toString() + " on host " + routingHost.toString() + " due to " + answer.getDetails());
} catch (OperationTimedoutException e) {
if (e.isActive()) {
s_logger.debug("Unable to start vm " + secStorageVm.getName() + " due to operation timed out and it is active so scheduling a restart.");
s_logger.debug("Unable to start vm " + secStorageVm.getHostName() + " due to operation timed out and it is active so scheduling a restart.");
saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "Unable to start vm due to operation timed out", startEventId);
_haMgr.scheduleRestart(secStorageVm, true);
return null;
}
} catch (AgentUnavailableException e) {
s_logger.debug("Agent " + routingHost.toString() + " was unavailable to start VM " + secStorageVm.getName());
s_logger.debug("Agent " + routingHost.toString() + " was unavailable to start VM " + secStorageVm.getHostName());
}
avoid.add(routingHost);
@ -472,7 +472,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
event.setType(EventTypes.EVENT_SSVM_START);
event.setLevel(EventVO.LEVEL_ERROR);
event.setStartId(startEventId);
event.setDescription("Starting secondary storage vm failed due to unable to find a host - " + secStorageVm.getName());
event.setDescription("Starting secondary storage vm failed due to unable to find a host - " + secStorageVm.getHostName());
_eventDao.persist(event);
throw new ExecutionException(
"Couldn't find a routingHost to run secondary storage vm");
@ -507,7 +507,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
event.setType(EventTypes.EVENT_SSVM_START);
event.setLevel(EventVO.LEVEL_ERROR);
event.setStartId(startEventId);
event.setDescription("Starting secondary storage vm failed due to unhandled exception - " + secStorageVm.getName());
event.setDescription("Starting secondary storage vm failed due to unhandled exception - " + secStorageVm.getHostName());
_eventDao.persist(event);
Transaction txn = Transaction.currentTxn();
@ -593,11 +593,11 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
Answer answer = _agentMgr.easySend(storageHost.getId(), setupCmd);
if (answer != null) {
if (s_logger.isDebugEnabled())
s_logger.debug("Successfully programmed http auth into " + secStorageVm.getName());
s_logger.debug("Successfully programmed http auth into " + secStorageVm.getHostName());
return true;
} else {
if (s_logger.isDebugEnabled())
s_logger.debug("failed to program http auth into secondary storage vm : " + secStorageVm.getName());
s_logger.debug("failed to program http auth into secondary storage vm : " + secStorageVm.getHostName());
return false;
}
}
@ -634,11 +634,11 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
Answer answer = _agentMgr.easySend(storageHost.getId(), cpc);
if (answer != null) {
if (s_logger.isDebugEnabled())
s_logger.debug("Successfully programmed firewall rules into " + secStorageVm.getName());
s_logger.debug("Successfully programmed firewall rules into " + secStorageVm.getHostName());
return true;
} else {
if (s_logger.isDebugEnabled())
s_logger.debug("failed to program firewall rules into secondary storage vm : " + secStorageVm.getName());
s_logger.debug("failed to program firewall rules into secondary storage vm : " + secStorageVm.getHostName());
return false;
}
@ -777,7 +777,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
event.setType(EventTypes.EVENT_SSVM_CREATE);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("New Secondary Storage VM created - " + secStorageVm.getName());
event.setDescription("New Secondary Storage VM created - " + secStorageVm.getHostName());
_eventDao.persist(event);
txn.commit();
success = true;
@ -915,7 +915,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
}
} else {
if (s_logger.isInfoEnabled())
s_logger.info("Unable to acquire synchronization lock to start secondary storage vm : " + readysecStorageVm.getName());
s_logger.info("Unable to acquire synchronization lock to start secondary storage vm : " + readysecStorageVm.getHostName());
}
} finally {
secStorageVmLock.releaseRef();
@ -1026,7 +1026,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
if (s_logger.isTraceEnabled()) {
s_logger.trace("Running secondary storage vm pool size : " + runningList.size());
for (SecondaryStorageVmVO secStorageVm : runningList)
s_logger.trace("Running secStorageVm instance : " + secStorageVm.getName());
s_logger.trace("Running secStorageVm instance : " + secStorageVm.getHostName());
}
Map<Long, Integer> loadInfo = new HashMap<Long, Integer>();
@ -1105,7 +1105,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
destroySecStorageVm(secStorageVmId, 0);
} else {
if (s_logger.isInfoEnabled())
s_logger.info("Secondary storage vm " + secStorageVm.getName() + " is started");
s_logger.info("Secondary storage vm " + secStorageVm.getHostName() + " is started");
}
}
}
@ -1503,7 +1503,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
return stop(secStorageVm, startEventId);
} catch (AgentUnavailableException e) {
if (s_logger.isDebugEnabled())
s_logger.debug("Stopping secondary storage vm " + secStorageVm.getName() + " faled : exception " + e.toString());
s_logger.debug("Stopping secondary storage vm " + secStorageVm.getHostName() + " faled : exception " + e.toString());
return false;
}
}
@ -1537,7 +1537,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
if (answer != null) {
if (s_logger.isDebugEnabled())
s_logger.debug("Successfully reboot secondary storage vm " + secStorageVm.getName());
s_logger.debug("Successfully reboot secondary storage vm " + secStorageVm.getHostName());
SubscriptionMgr.getInstance().notifySubscribers(
ALERT_SUBJECT, this,
@ -1552,11 +1552,11 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
event.setType(EventTypes.EVENT_SSVM_REBOOT);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("Secondary Storage Vm rebooted - " + secStorageVm.getName());
event.setDescription("Secondary Storage Vm rebooted - " + secStorageVm.getHostName());
_eventDao.persist(event);
return true;
} else {
String msg = "Rebooting Secondary Storage VM failed - " + secStorageVm.getName();
String msg = "Rebooting Secondary Storage VM failed - " + secStorageVm.getHostName();
saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_REBOOT, msg, startEventId);
if (s_logger.isDebugEnabled())
s_logger.debug(msg);
@ -1638,7 +1638,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
event.setType(EventTypes.EVENT_SSVM_DESTROY);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("Secondary Storage Vm destroyed - " + vm.getName());
event.setDescription("Secondary Storage Vm destroyed - " + vm.getHostName());
_eventDao.persist(event);
txn.commit();
} catch (Exception e) {
@ -1647,7 +1647,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
return false;
} finally {
s_logger.debug("secondary storage vm vm is destroyed : "
+ vm.getName());
+ vm.getHostName());
}
}
}
@ -1670,7 +1670,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_SSVM_DESTROY);
event.setLevel(EventVO.LEVEL_INFO);
event.setDescription("Secondary Storage Vm destroyed - " + secStorageVm.getName());
event.setDescription("Secondary Storage Vm destroyed - " + secStorageVm.getHostName());
_eventDao.persist(event);
}
txn.commit();
@ -1727,12 +1727,12 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
event.setType(EventTypes.EVENT_SSVM_STOP);
event.setLevel(EventVO.LEVEL_INFO);
event.setStartId(startEventId);
event.setDescription("Secondary Storage Vm stopped - " + secStorageVm.getName());
event.setDescription("Secondary Storage Vm stopped - " + secStorageVm.getHostName());
_eventDao.persist(event);
return true;
} catch (OperationTimedoutException e) {
saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP,
"Stopping secondary storage vm failed due to operation time out - " + secStorageVm.getName(), startEventId);
"Stopping secondary storage vm failed due to operation time out - " + secStorageVm.getHostName(), startEventId);
throw new AgentUnavailableException(secStorageVm.getHostId());
}
} finally {
@ -1816,7 +1816,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
storageIps[1] = vols.get(1).getHostIp();
}
PrepareForMigrationCommand cmd = new PrepareForMigrationCommand(secStorageVm.getName(), null, storageIps, vols, mirroredVols);
PrepareForMigrationCommand cmd = new PrepareForMigrationCommand(secStorageVm.getHostName(), null, storageIps, vols, mirroredVols);
HostVO routingHost = null;
HashSet<Host> avoid = new HashSet<Host>();
@ -1836,8 +1836,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
}
if( !_storageMgr.share(secStorageVm, vols, routingHost, false) ) {
s_logger.warn("Can not share " + vol.getPath() + " to " + secStorageVm.getName());
throw new StorageUnavailableException("Can not share " + vol.getPath() + " to " + secStorageVm.getName(), vol);
s_logger.warn("Can not share " + vol.getPath() + " to " + secStorageVm.getHostName());
throw new StorageUnavailableException("Can not share " + vol.getPath() + " to " + secStorageVm.getHostName(), vol);
}
Answer answer = _agentMgr.easySend(routingHost.getId(), cmd);

View File

@ -259,7 +259,7 @@ public class SnapshotManagerImpl implements SnapshotManager {
VMInstanceVO vmInstance = _vmDao.findById(volume.getInstanceId());
String vmDisplayName = "detached";
if (vmInstance != null) {
vmDisplayName = vmInstance.getName();
vmDisplayName = vmInstance.getHostName();
}
String snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString;

View File

@ -121,4 +121,6 @@ public interface AccountManager extends Manager {
void checkAccess(Account account, ControlledEntity... entities) throws PermissionDeniedException;
AccountVO getSystemAccount();
UserVO getSystemUser();
}

View File

@ -44,6 +44,7 @@ import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.server.Criteria;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.Filter;
@ -60,8 +61,10 @@ public class AccountManagerImpl implements AccountManager, AccountService {
@Inject private DomainDao _domainDao;
@Inject private ResourceLimitDao _resourceLimitDao;
@Inject private ResourceCountDao _resourceCountDao;
@Inject private UserDao _userDao;
private final GlobalLock m_resourceCountLock = GlobalLock.getInternLock("resource.count");
UserVO _systemUser;
AccountVO _systemAccount;
@Inject(adapter=SecurityChecker.class)
Adapters<SecurityChecker> _securityCheckers;
@ -72,11 +75,21 @@ public class AccountManagerImpl implements AccountManager, AccountService {
_systemAccount = _accountDao.findById(AccountVO.ACCOUNT_ID_SYSTEM);
if (_systemAccount == null) {
throw new ConfigurationException("Unable to find the system account using " + AccountVO.ACCOUNT_ID_SYSTEM);
throw new ConfigurationException("Unable to find the system account using " + Account.ACCOUNT_ID_SYSTEM);
}
_systemUser = _userDao.findById(UserVO.UID_SYSTEM);
if (_systemUser == null) {
throw new ConfigurationException("Unable to find the system user using " + User.UID_SYSTEM);
}
return true;
}
@Override
public UserVO getSystemUser() {
return _systemUser;
}
@Override
public String getName() {
return _name;
@ -413,7 +426,7 @@ public class AccountManagerImpl implements AccountManager, AccountService {
}
@Override
public ResourceLimitVO updateResourceLimit(UpdateResourceLimitCmd cmd) throws InvalidParameterValueException {
public ResourceLimitVO updateResourceLimit(UpdateResourceLimitCmd cmd) {
Account account = UserContext.current().getAccount();
String accountName = cmd.getAccountName();

View File

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
@ -31,16 +32,19 @@ import com.cloud.agent.AgentManager;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Start2Command;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.agent.manager.Commands;
import com.cloud.cluster.ClusterManager;
import com.cloud.cluster.ClusterManagerListener;
import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.deploy.DeploymentPlanner;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
@ -48,22 +52,24 @@ import com.cloud.exception.InsufficientServerCapacityException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.HypervisorGuru;
import com.cloud.network.NetworkConfigurationVO;
import com.cloud.network.NetworkManager;
import com.cloud.offering.ServiceOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageManager;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Volume.VolumeType;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.Journal;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
@ -77,7 +83,7 @@ import com.cloud.vm.VirtualMachine.Event;
import com.cloud.vm.dao.VMInstanceDao;
@Local(value=VmManager.class)
public class MauriceMoss implements VmManager {
public class MauriceMoss implements VmManager, ClusterManagerListener {
private static final Logger s_logger = Logger.getLogger(MauriceMoss.class);
String _name;
@ -88,13 +94,20 @@ public class MauriceMoss implements VmManager {
@Inject private ServiceOfferingDao _offeringDao;
@Inject private GuestOSDao _guestOsDao;
@Inject private VMTemplateDao _templateDao;
@Inject private UserDao _userDao;
@Inject private AccountDao _accountDao;
@Inject private DomainDao _domainDao;
@Inject private ClusterManager _clusterMgr;
@Inject private StartWorkDao _workDao;
@Inject(adapter=DeploymentPlanner.class)
private Adapters<DeploymentPlanner> _planners;
Map<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>> _vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>>();
Map<HypervisorType, HypervisorGuru> _hvGurus = new HashMap<HypervisorType, HypervisorGuru>();
private int _retry;
private long _nodeId;
@Override
public <T extends VMInstanceVO> void registerGuru(VirtualMachine.Type type, VirtualMachineGuru<T> guru) {
@ -104,12 +117,13 @@ public class MauriceMoss implements VmManager {
}
@Override @DB
public <T extends VMInstanceVO> VirtualMachineProfile allocate(T vm,
public <T extends VMInstanceVO> VirtualMachineProfile<T> allocate(T vm,
VMTemplateVO template,
ServiceOfferingVO serviceOffering,
Pair<? extends DiskOfferingVO, Long> rootDiskOffering,
List<Pair<DiskOfferingVO, Long>> dataDiskOfferings,
List<Pair<NetworkConfigurationVO, NicProfile>> networks,
List<Pair<NetworkConfigurationVO, NicProfile>> networks,
Map<String, Object> params,
DeploymentPlan plan,
Account owner) throws InsufficientCapacityException {
if (s_logger.isDebugEnabled()) {
@ -118,17 +132,24 @@ public class MauriceMoss implements VmManager {
// Determine the VM's OS description
GuestOSVO guestOS = _guestOsDao.findById(vm.getGuestOSId());
if (guestOS == null) {
throw new CloudRuntimeException("Guest OS is not set");
}
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, guestOS.getDisplayName(), template, serviceOffering, owner, params);
VirtualMachineProfile vmProfile = new VirtualMachineProfile(vm, serviceOffering, guestOS.getDisplayName(), template.getHypervisorType());
vm.setDataCenterId(plan.getDataCenterId());
if (plan.getPodId() != null) {
vm.setPodId(plan.getPodId());
}
assert (plan.getClusterId() == null && plan.getPoolId() == null) : "We currently don't support cluster and pool preset yet";
@SuppressWarnings("unchecked")
VirtualMachineGuru<T> guru = (VirtualMachineGuru<T>)_vmGurus.get(vm.getType());
Transaction txn = Transaction.currentTxn();
txn.start();
vm.setDataCenterId(plan.getDataCenterId());
_vmDao.update(vm.getId(), vm);
vm = guru.persist(vm);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Allocating nics for " + vm);
}
List<NicProfile> nics = _networkMgr.allocate(vmProfile, networks);
vmProfile.setNics(nics);
@ -136,6 +157,10 @@ public class MauriceMoss implements VmManager {
dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO, Long>>(0);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Allocaing disks for " + vm);
}
List<DiskProfile> disks = new ArrayList<DiskProfile>(dataDiskOfferings.size() + 1);
if (template.getFormat() == ImageFormat.ISO) {
disks.add(_storageMgr.allocateRawVolume(VolumeType.ROOT, "ROOT-" + vm.getId(), rootDiskOffering.first(), rootDiskOffering.second(), vm, owner));
@ -145,7 +170,6 @@ public class MauriceMoss implements VmManager {
for (Pair<DiskOfferingVO, Long> offering : dataDiskOfferings) {
disks.add(_storageMgr.allocateRawVolume(VolumeType.DATADISK, "DATA-" + vm.getId(), offering.first(), offering.second(), vm, owner));
}
vmProfile.setDisks(disks);
_vmDao.updateIf(vm, Event.OperationSucceeded, null);
txn.commit();
@ -157,7 +181,7 @@ public class MauriceMoss implements VmManager {
}
@Override
public <T extends VMInstanceVO> VirtualMachineProfile allocate(T vm,
public <T extends VMInstanceVO> VirtualMachineProfile<T> allocate(T vm,
VMTemplateVO template,
ServiceOfferingVO serviceOffering,
Long rootSize,
@ -169,17 +193,17 @@ public class MauriceMoss implements VmManager {
if (dataDiskOffering != null) {
diskOfferings.add(dataDiskOffering);
}
return allocate(vm, template, serviceOffering, new Pair<DiskOfferingVO, Long>(serviceOffering, rootSize), diskOfferings, networks, plan, owner);
return allocate(vm, template, serviceOffering, new Pair<DiskOfferingVO, Long>(serviceOffering, rootSize), diskOfferings, networks, null, plan, owner);
}
@Override
public <T extends VMInstanceVO> VirtualMachineProfile allocate(T vm,
public <T extends VMInstanceVO> VirtualMachineProfile<T> allocate(T vm,
VMTemplateVO template,
ServiceOfferingVO serviceOffering,
List<Pair<NetworkConfigurationVO, NicProfile>> networks,
DeploymentPlan plan,
Account owner) throws InsufficientCapacityException {
return allocate(vm, template, serviceOffering, new Pair<DiskOfferingVO, Long>(serviceOffering, null), null, networks, plan, owner);
return allocate(vm, template, serviceOffering, new Pair<DiskOfferingVO, Long>(serviceOffering, null), null, networks, null, plan, owner);
}
@Override
@ -206,9 +230,19 @@ public class MauriceMoss implements VmManager {
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> params = configDao.getConfiguration(xmlParams);
_planners = locator.getAdapters(DeploymentPlanner.class);
_retry = NumbersUtil.parseInt(params.get(Config.StartRetry.key()), 2);
ReservationContextImpl.setComponents(_userDao, _domainDao, _accountDao);
VirtualMachineProfileImpl.setComponents(_offeringDao, _templateDao, _accountDao);
Adapters<HypervisorGuru> hvGurus = locator.getAdapters(HypervisorGuru.class);
for (HypervisorGuru guru : hvGurus) {
_hvGurus.put(guru.getHypervisorType(), guru);
}
_nodeId = _clusterMgr.getId();
_clusterMgr.registerListener(this);
return true;
}
@ -221,7 +255,7 @@ public class MauriceMoss implements VmManager {
}
@Override
public <T extends VMInstanceVO> T start(T vm, DeploymentPlan plan, Account acct) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
public <T extends VMInstanceVO> T start(T vm, Map<String, Object> params, User caller, Account account) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
State state = vm.getState();
if (state == State.Starting || state == State.Running) {
s_logger.debug("VM is already started: " + vm);
@ -239,20 +273,21 @@ public class MauriceMoss implements VmManager {
Journal journal = new Journal.LogJournal("Creating " + vm, s_logger);
ServiceOffering offering = _offeringDao.findById(vm.getServiceOfferingId());
ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, ItWorkVO.Type.Start);
work = _workDao.persist(work);
ReservationContextImpl context = new ReservationContextImpl(work.getId(), journal, caller, account);
ServiceOfferingVO offering = _offeringDao.findById(vm.getServiceOfferingId());
VMTemplateVO template = _templateDao.findById(vm.getTemplateId());
BootloaderType bt = BootloaderType.PyGrub;
if (template.getFormat() == Storage.ImageFormat.ISO || template.isRequiresHvm()) {
bt = BootloaderType.HVM;
}
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodId(), null, null);
HypervisorGuru hvGuru = _hvGurus.get(template.getHypervisorType());
// Determine the VM's OS description
GuestOSVO guestOS = _guestOsDao.findById(vm.getGuestOSId());
if (guestOS == null) {
throw new CloudRuntimeException("Guest OS is not set");
}
VirtualMachineProfile vmProfile = new VirtualMachineProfile(vm, offering, guestOS.getDisplayName(), template.getHypervisorType());
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, guestOS.getDisplayName(), template, offering, null, params);
if (!_vmDao.updateIf(vm, Event.StartRequested, null)) {
throw new ConcurrentOperationException("Unable to start vm " + vm + " due to concurrent operations");
}
@ -278,33 +313,29 @@ public class MauriceMoss implements VmManager {
vm.setPodId(dest.getPod().getId());
_vmDao.updateIf(vm, Event.OperationRetry, dest.getHost().getId());
VirtualMachineTO vmTO = new VirtualMachineTO(vmProfile, bt);
VolumeTO[] volumes = null;
try {
volumes = _storageMgr.prepare(vmProfile, dest);
_storageMgr.prepare(vmProfile, dest);
} catch (ConcurrentOperationException e) {
throw e;
} catch (StorageUnavailableException e) {
s_logger.warn("Unable to contact storage.", e);
continue;
}
NicTO[] nics = _networkMgr.prepare(vmProfile, dest, acct);
_networkMgr.prepare(vmProfile, dest, context);
vmTO.setNics(nics);
vmTO.setDisks(volumes);
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
Commands cmds = new Commands(OnError.Revert);
cmds.addCommand(new Start2Command(vmTO));
@SuppressWarnings("unchecked")
VirtualMachineGuru<T> guru = (VirtualMachineGuru<T>)_vmGurus.get(vm.getType());
VirtualMachineGuru<T> vmGuru = (VirtualMachineGuru<T>)_vmGurus.get(vm.getType());
if (guru != null) {
guru.finalizeDeployment(cmds, vm, vmProfile, dest);
}
vmGuru.finalizeDeployment(cmds, vmProfile, dest, context);
try {
Answer[] answers = _agentMgr.send(dest.getHost().getId(), cmds);
if (answers[0].getResult()) {
if (answers[0].getResult() && vmGuru.processDeploymentResult(cmds, vmProfile, dest, context)) {
if (!_vmDao.updateIf(vm, Event.OperationSucceeded, dest.getHost().getId())) {
throw new CloudRuntimeException("Unable to transition to a new state.");
}
@ -328,9 +359,18 @@ public class MauriceMoss implements VmManager {
}
@Override
public <T extends VMInstanceVO> T stop(T vm) throws AgentUnavailableException {
public <T extends VMInstanceVO> T stop(T vm, User user, Account account) throws AgentUnavailableException {
// TODO Auto-generated method stub
return null;
}
@Override
public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) {
}
@Override
public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long selfNodeId) {
}
}

View File

@ -290,9 +290,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
UserVmVO userVm = _vmDao.findById(cmd.getId());
if (userVm != null) {
if (result) {
EventUtils.saveEvent(userId, userVm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_RESETPASSWORD, "successfully reset password for VM : " + userVm.getName(), null);
EventUtils.saveEvent(userId, userVm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_RESETPASSWORD, "successfully reset password for VM : " + userVm.getHostName(), null);
} else {
EventUtils.saveEvent(userId, userVm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_RESETPASSWORD, "unable to reset password for VM : " + userVm.getName(), null);
EventUtils.saveEvent(userId, userVm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_RESETPASSWORD, "unable to reset password for VM : " + userVm.getHostName(), null);
}
} else {
s_logger.warn("Unable to find vm = " + cmd.getId()+ " to reset password");
@ -448,7 +448,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
VolumeVO rootVolumeOfVm = null;
List<VolumeVO> rootVolumesOfVm = _volsDao.findByInstanceAndType(vmId, VolumeType.ROOT);
if (rootVolumesOfVm.size() != 1) {
throw new CloudRuntimeException("The VM " + vm.getName() + " has more than one ROOT volume and is in an invalid state. Please contact Cloud Support.");
throw new CloudRuntimeException("The VM " + vm.getHostName() + " has more than one ROOT volume and is in an invalid state. Please contact Cloud Support.");
} else {
rootVolumeOfVm = rootVolumesOfVm.get(0);
}
@ -467,7 +467,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
volume = _storageMgr.createVolume(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType);
if (volume == null) {
throw new CloudRuntimeException("Failed to create volume when attaching it to VM: " + vm.getName());
throw new CloudRuntimeException("Failed to create volume when attaching it to VM: " + vm.getHostName());
}
}
@ -483,7 +483,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
}
for (VolumeVO vol : vols) {
if (vol.getDeviceId().equals(deviceId)) {
throw new RuntimeException("deviceId " + deviceId + " is used by VM " + vm.getName());
throw new RuntimeException("deviceId " + deviceId + " is used by VM " + vm.getHostName());
}
}
} else {
@ -548,7 +548,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
_asyncMgr.updateAsyncJobStatus(job.getId(), BaseCmd.PROGRESS_INSTANCE_CREATED, volumeId);
}
String errorMsg = "Failed to attach volume: " + volume.getName() + " to VM: " + vm.getName();
String errorMsg = "Failed to attach volume: " + volume.getName() + " to VM: " + vm.getHostName();
boolean sendCommand = (vm.getState() == State.Running);
AttachVolumeAnswer answer = null;
Long hostId = vm.getHostId();
@ -577,10 +577,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
} else {
_volsDao.attachVolume(volume.getId(), vmId, deviceId);
}
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("Volume: " +volume.getName()+ " successfully attached to VM: "+vm.getName()+"("+vm.getDisplayName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("Volume: " +volume.getName()+ " successfully attached to VM: "+vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("Volume: " +volume.getName()+ " successfully attached to VM: "+vm.getName());
event.setDescription("Volume: " +volume.getName()+ " successfully attached to VM: "+vm.getHostName());
event.setLevel(EventVO.LEVEL_INFO);
_eventDao.persist(event);
return _volsDao.findById(volumeId);
@ -677,7 +677,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
_asyncMgr.updateAsyncJobStatus(job.getId(), BaseCmd.PROGRESS_INSTANCE_CREATED, volumeId);
}
String errorMsg = "Failed to detach volume: " + volume.getName() + " from VM: " + vm.getName();
String errorMsg = "Failed to detach volume: " + volume.getName() + " from VM: " + vm.getHostName();
boolean sendCommand = (vm.getState() == State.Running);
Answer answer = null;
@ -703,14 +703,31 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
if (!sendCommand || (answer != null && answer.getResult())) {
// Mark the volume as detached
_volsDao.detachVolume(volume.getId());
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getName()+"("+vm.getDisplayName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getName());
event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getHostName());
event.setLevel(EventVO.LEVEL_INFO);
_eventDao.persist(event);
<<<<<<< HEAD
return _volsDao.findById(volumeId);
=======
// Prepare the response object
VolumeResponse response = new VolumeResponse();
response.setVirtualMachineName(vm.getHostName());
response.setVirtualMachineDisplayName(vm.getDisplayName());
response.setVirtualMachineId(vm.getId());
response.setVirtualMachineState(vm.getState().toString());
response.setStorageType("shared"); // NOTE: You can never attach a local disk volume but if that changes, we need to change this
response.setId(volume.getId());
response.setName(volume.getName());
response.setVolumeType(volume.getVolumeType().toString());
response.setResponseName(cmmd.getName());
if(volume.getDeviceId() != null)
response.setDeviceId(volume.getDeviceId());
return response;
>>>>>>> Harmony among gurus
} else {
if (answer != null) {
@ -844,11 +861,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
State state = vm.getState();
if (state == State.Running) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Starting an already started VM: " + vm.getId() + " - " + vm.getName() + "; state = " + vm.getState().toString());
s_logger.debug("Starting an already started VM: " + vm.getId() + " - " + vm.getHostName() + "; state = " + vm.getState().toString());
}
return vm;
}
String eventParams = "id=" + vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
String eventParams = "id=" + vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
event = new EventVO();
event.setType(EventTypes.EVENT_VM_START);
event.setUserId(userId);
@ -857,7 +874,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
event.setState(EventState.Completed);
event.setStartId(startEventId);
if (state.isTransitional()) {
String description = "Concurrent operations on the vm " + vm.getId() + " - " + vm.getName() + "; state = " + state.toString();
String description = "Concurrent operations on the vm " + vm.getId() + " - " + vm.getHostName() + "; state = " + state.toString();
event.setDescription(description);
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
@ -889,7 +906,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
GuestOSVO guestOS = _guestOSDao.findById(vm.getGuestOSId());
if (guestOS == null) {
String msg = "Could not find guest OS description for OSId "
+ vm.getGuestOSId() + " for vm: " + vm.getName();
+ vm.getGuestOSId() + " for vm: " + vm.getHostName();
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
} else {
@ -929,12 +946,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
if (vm.getDomainRouterId() != null) {
router = _networkMgr.addVirtualMachineToGuestNetwork(vm, password, startEventId);
if (router == null) {
s_logger.error("Unable to add vm " + vm.getId() + " - " + vm.getName());
s_logger.error("Unable to add vm " + vm.getId() + " - " + vm.getHostName());
_vmDao.updateIf(vm, Event.OperationFailed, null);
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("Unable to start VM: " + vm.getName()+"("+vm.getDisplayName()+")" + "; Unable to add VM to guest network");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("Unable to start VM: " + vm.getHostName()+"("+vm.getDisplayName()+")" + "; Unable to add VM to guest network");
else
event.setDescription("Unable to start VM: " + vm.getName() + "; Unable to add VM to guest network");
event.setDescription("Unable to start VM: " + vm.getHostName() + "; Unable to add VM to guest network");
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
@ -942,7 +959,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
}
vnet = router.getVnet();
s_logger.debug("VM: " + vm.getName() + " discovered vnet: " + vnet + " from router: " + router.getName());
s_logger.debug("VM: " + vm.getHostName() + " discovered vnet: " + vnet + " from router: " + router.getHostName());
if(NetworkManager.USE_POD_VLAN){
if(vm.getPodId() != router.getPodId()){
@ -951,7 +968,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
//Create Zone Vlan if not created already
vnet = _networkMgr.createZoneVlan(router);
if (vnet == null) {
s_logger.error("Vlan creation failed. Unable to add vm " + vm.getId() + " - " + vm.getName());
s_logger.error("Vlan creation failed. Unable to add vm " + vm.getId() + " - " + vm.getHostName());
return null;
}
} else {
@ -983,7 +1000,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
do {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Trying to start vm " + vm.getName() + " on host " + host.toString());
s_logger.debug("Trying to start vm " + vm.getHostName() + " on host " + host.toString());
}
txn.start();
@ -1047,7 +1064,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
answer = _agentMgr.send(host.getId(), cmdStart);
if (answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Started vm " + vm.getName() + " on host " + host.toString());
s_logger.debug("Started vm " + vm.getHostName() + " on host " + host.toString());
}
started = true;
break;
@ -1056,7 +1073,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
s_logger.debug("Unable to start " + vm.toString() + " on host " + host.toString() + " due to " + answer.getDetails());
} catch (OperationTimedoutException e) {
if (e.isActive()) {
String description = "Unable to start vm " + vm.getName() + " due to operation timed out and it is active so scheduling a restart.";
String description = "Unable to start vm " + vm.getHostName() + " due to operation timed out and it is active so scheduling a restart.";
_haMgr.scheduleRestart(vm, true);
host = null;
s_logger.debug(description);
@ -1066,7 +1083,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
return null;
}
} catch (AgentUnavailableException e) {
s_logger.debug("Agent " + host.toString() + " was unavailable to start VM " + vm.getName());
s_logger.debug("Agent " + host.toString() + " was unavailable to start VM " + vm.getHostName());
}
avoid.add(host);
@ -1075,34 +1092,34 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
} while (--retry > 0 && (host = (HostVO)_agentMgr.findHost(Host.Type.Routing, dc, pod, sp, offering, template, vm, null, avoid)) != null);
if (host == null || retry <= 0) {
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("Unable to start VM: " + vm.getName()+"("+vm.getDisplayName()+")"+ " Reason: "+answer.getDetails());
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("Unable to start VM: " + vm.getHostName()+"("+vm.getDisplayName()+")"+ " Reason: "+answer.getDetails());
else
event.setDescription("Unable to start VM: " + vm.getName()+ " Reason: "+answer.getDetails());
event.setDescription("Unable to start VM: " + vm.getHostName()+ " Reason: "+answer.getDetails());
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
throw new ExecutionException("Unable to start VM: " + vm.getName()+ " Reason: "+answer.getDetails());
throw new ExecutionException("Unable to start VM: " + vm.getHostName()+ " Reason: "+answer.getDetails());
}
if (!_vmDao.updateIf(vm, Event.OperationSucceeded, host.getId())) {
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("unable to start VM: " + vm.getName()+"("+vm.getDisplayName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("unable to start VM: " + vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("unable to start VM: " + vm.getName());
event.setDescription("unable to start VM: " + vm.getHostName());
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
throw new ConcurrentOperationException("Starting vm " + vm.getName() + " didn't work.");
throw new ConcurrentOperationException("Starting vm " + vm.getHostName() + " didn't work.");
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Started vm " + vm.getName());
s_logger.debug("Started vm " + vm.getHostName());
}
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("successfully started VM: " + vm.getName()+"("+vm.getDisplayName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("successfully started VM: " + vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("successfully started VM: " + vm.getName());
event.setDescription("successfully started VM: " + vm.getHostName());
_eventDao.persist(event);
_networkGroupMgr.handleVmStateTransition(vm, State.Running);
@ -1110,7 +1127,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
return _vmDao.findById(vm.getId());
} catch (Throwable th) {
txn.rollback();
s_logger.error("While starting vm " + vm.getName() + ", caught throwable: ", th);
s_logger.error("While starting vm " + vm.getHostName() + ", caught throwable: ", th);
if (!started) {
vm.setVnet(null);
@ -1131,7 +1148,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
s_logger.warn(th.getMessage());
throw (ExecutionException)th;
}
String description = "Unable to start VM " + vm.getName() + " because of an unknown exception";
String description = "Unable to start VM " + vm.getHostName() + " because of an unknown exception";
event.setDescription(description);
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
@ -1267,24 +1284,24 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
event.setUserId(userId);
event.setAccountId(vm.getAccountId());
event.setType(EventTypes.EVENT_VM_REBOOT);
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
if (vm.getState() == State.Running && vm.getHostId() != null) {
RebootCommand cmd = new RebootCommand(vm.getInstanceName());
RebootAnswer answer = (RebootAnswer)_agentMgr.easySend(vm.getHostId(), cmd);
if (answer != null) {
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("Successfully rebooted VM instance : " + vm.getName()+"("+vm.getDisplayName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("Successfully rebooted VM instance : " + vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("Successfully rebooted VM instance : " + vm.getName());
event.setDescription("Successfully rebooted VM instance : " + vm.getHostName());
_eventDao.persist(event);
return true;
} else {
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("failed to reboot VM instance : " + vm.getName()+"("+vm.getDisplayName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("failed to reboot VM instance : " + vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("failed to reboot VM instance : " + vm.getName());
event.setDescription("failed to reboot VM instance : " + vm.getHostName());
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
return false;
@ -1520,13 +1537,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
IPAddressVO guestIP = (userVm.getGuestIpAddress() == null) ? null : _ipAddressDao.findById(userVm.getGuestIpAddress());
if (guestIP != null && guestIP.getAllocated() != null) {
_ipAddressDao.unassignIpAddress(userVm.getGuestIpAddress());
s_logger.debug("Released guest IP address=" + userVm.getGuestIpAddress() + " vmName=" + userVm.getName() + " dcId=" + userVm.getDataCenterId());
s_logger.debug("Released guest IP address=" + userVm.getGuestIpAddress() + " vmName=" + userVm.getHostName() + " dcId=" + userVm.getDataCenterId());
EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(userVm.getAccountId());
event.setType(EventTypes.EVENT_NET_IP_RELEASE);
event.setParameters("guestIPaddress=" + userVm.getGuestIpAddress() + "\nvmName=" + userVm.getName() + "\ndcId=" + userVm.getDataCenterId());
event.setParameters("guestIPaddress=" + userVm.getGuestIpAddress() + "\nvmName=" + userVm.getHostName() + "\ndcId=" + userVm.getDataCenterId());
event.setDescription("released a public ip: " + userVm.getGuestIpAddress());
_eventDao.persist(event);
} else {
@ -1667,12 +1684,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
}
txn.start();
if(vm != null && vm.getName() != null && vm.getDisplayName() != null)
if(vm != null && vm.getHostName() != null && vm.getDisplayName() != null)
{
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("successfully created VM instance : " + vm.getName()+"("+vm.getDisplayName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("successfully created VM instance : " + vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("successfully created VM instance : " + vm.getName());
event.setDescription("successfully created VM instance : " + vm.getHostName());
}
else
{
@ -1700,8 +1717,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
if (vm == null) {
eventDescription += "new instance";
} else {
eventDescription += vm.getName();
if (!vm.getName().equals(vm.getDisplayName())) {
eventDescription += vm.getHostName();
if (!vm.getHostName().equals(vm.getDisplayName())) {
eventDescription += " (" + vm.getDisplayName() + ")";
}
}
@ -1739,11 +1756,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
event.setUserId(userId);
event.setAccountId(vm.getAccountId());
event.setType(EventTypes.EVENT_VM_DESTROY);
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("Successfully destroyed VM instance : " + vm.getName()+"("+vm.getDisplayName()+")");
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("Successfully destroyed VM instance : " + vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("Successfully destroyed VM instance : " + vm.getName());
event.setDescription("Successfully destroyed VM instance : " + vm.getHostName());
_eventDao.persist(event);
_accountMgr.decrementResourceCount(vm.getAccountId(), ResourceType.user_vm);
@ -1915,7 +1932,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
event.setUserId(1L);
event.setAccountId(vm.getAccountId());
event.setType(EventTypes.EVENT_VM_CREATE);
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
Transaction txn = Transaction.currentTxn();
AccountVO account = null;
@ -1932,10 +1949,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
ResourceAllocationException rae = new ResourceAllocationException("Maximum number of virtual machines for account: " + account.getAccountName() + " has been exceeded.");
rae.setResourceType("vm");
event.setLevel(EventVO.LEVEL_ERROR);
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("Failed to recover VM instance : " + vm.getName()+"("+vm.getDisplayName()+")" + "; the resource limit for account: " + account.getAccountName() + " has been exceeded.");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("Failed to recover VM instance : " + vm.getHostName()+"("+vm.getDisplayName()+")" + "; the resource limit for account: " + account.getAccountName() + " has been exceeded.");
else
event.setDescription("Failed to recover VM instance : " + vm.getName() + "; the resource limit for account: " + account.getAccountName() + " has been exceeded.");
event.setDescription("Failed to recover VM instance : " + vm.getHostName() + "; the resource limit for account: " + account.getAccountName() + " has been exceeded.");
_eventDao.persist(event);
txn.commit();
throw rae;
@ -1976,10 +1993,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
_accountMgr.incrementResourceCount(account.getId(), ResourceType.volume, new Long(volumes.size()));
event.setLevel(EventVO.LEVEL_INFO);
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("successfully recovered VM instance : " + vm.getName()+"("+vm.getDisplayName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("successfully recovered VM instance : " + vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("successfully recovered VM instance : " + vm.getName());
event.setDescription("successfully recovered VM instance : " + vm.getHostName());
_eventDao.persist(event);
txn.commit();
@ -2123,11 +2140,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
event.setType(EventTypes.EVENT_VM_STOP);
event.setState(EventState.Completed);
event.setStartId(startEventId);
event.setParameters("id="+vm.getId() + "\n" + "vmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("Successfully stopped VM instance : " + vm.getName()+"("+vm.getDisplayName()+")");
event.setParameters("id="+vm.getId() + "\n" + "vmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("Successfully stopped VM instance : " + vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("Successfully stopped VM instance : " + vm.getName());
event.setDescription("Successfully stopped VM instance : " + vm.getHostName());
_eventDao.persist(event);
if (_storageMgr.unshare(vm, null) == null) {
@ -2191,7 +2208,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
event.setAccountId(vm.getAccountId());
event.setType(EventTypes.EVENT_VM_STOP);
event.setStartId(startEventId);
event.setParameters("id="+vm.getId() + "\n" + "vmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
event.setParameters("id="+vm.getId() + "\n" + "vmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId());
StopCommand stop = new StopCommand(vm, vm.getInstanceName(), vm.getVnet());
@ -2199,7 +2216,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
try {
Answer answer = _agentMgr.send(vm.getHostId(), stop);
if (!answer.getResult()) {
s_logger.warn("Unable to stop vm " + vm.getName() + " due to " + answer.getDetails());
s_logger.warn("Unable to stop vm " + vm.getHostName() + " due to " + answer.getDetails());
} else {
stopped = true;
}
@ -2213,14 +2230,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
completeStopCommand(userId, vm, Event.OperationSucceeded, 0);
} else
{
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("failed to stop VM instance : " + vm.getName()+"("+vm.getDisplayName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("failed to stop VM instance : " + vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("failed to stop VM instance : " + vm.getName());
event.setDescription("failed to stop VM instance : " + vm.getHostName());
event.setLevel(EventVO.LEVEL_ERROR);
_eventDao.persist(event);
_vmDao.updateIf(vm, Event.OperationFailed, vm.getHostId());
s_logger.error("Unable to stop vm " + vm.getName());
s_logger.error("Unable to stop vm " + vm.getHostName());
}
return stopped;
@ -2672,7 +2689,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
VMInstanceVO vm = _vmDao.findById(instanceId);
State vmState = vm.getState();
if( !vmState.equals(State.Stopped) && !vmState.equals(State.Destroyed)) {
throw new CloudRuntimeException("Please put VM " + vm.getName() + " into Stopped state first");
throw new CloudRuntimeException("Please put VM " + vm.getHostName() + " into Stopped state first");
}
cmd = new CreatePrivateTemplateFromVolumeCommand(secondaryStorageURL, templateId, volume.getAccountId(),
@ -2939,7 +2956,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
event.setUserId(userId);
event.setAccountId(accountId);
event.setType(EventTypes.EVENT_NET_IP_ASSIGN);
event.setParameters("guestIPaddress=" + guestIp + "\nvmName=" + vm.getName() + "\ndcId=" + vm.getDataCenterId());
event.setParameters("guestIPaddress=" + guestIp + "\nvmName=" + vm.getHostName() + "\ndcId=" + vm.getDataCenterId());
event.setDescription("acquired a public ip: " + guestIp);
_eventDao.persist(event);
@ -2947,9 +2964,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
}
if (poolId == 0) {
if(vm != null && vm.getName()!=null && vm.getDisplayName() != null)
if(vm != null && vm.getHostName()!=null && vm.getDisplayName() != null)
{
if(!vm.getName().equals(vm.getDisplayName()))
if(!vm.getHostName().equals(vm.getDisplayName()))
s_logger.debug("failed to create VM instance : " + name+"("+vm.getInstanceName()+")");
else
s_logger.debug("failed to create VM instance : " + name);
@ -2973,12 +2990,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
event.setStartId(startEventId);
event.setState(EventState.Completed);
String diskOfferingIdentifier = (diskOffering != null) ? String.valueOf(diskOffering.getId()) : "-1";
String eventParams = "id=" + vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ndoId=" + diskOfferingIdentifier + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
String eventParams = "id=" + vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ndoId=" + diskOfferingIdentifier + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
event.setParameters(eventParams);
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("successfully created VM instance : " + vm.getName()+"("+vm.getInstanceName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("successfully created VM instance : " + vm.getHostName()+"("+vm.getInstanceName()+")");
else
event.setDescription("successfully created VM instance : " + vm.getName());
event.setDescription("successfully created VM instance : " + vm.getHostName());
_eventDao.persist(event);
_vmDao.updateIf(vm, Event.OperationSucceeded, null);
@ -3101,9 +3118,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
}
if (poolId == 0) {
if(vm != null && vm.getName()!=null && vm.getDisplayName() != null)
if(vm != null && vm.getHostName()!=null && vm.getDisplayName() != null)
{
if(!vm.getName().equals(vm.getDisplayName()))
if(!vm.getHostName().equals(vm.getDisplayName()))
s_logger.debug("failed to create VM instance : " + name+"("+vm.getDisplayName()+")");
else
s_logger.debug("failed to create VM instance : " + name);
@ -3127,12 +3144,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
event.setStartId(startEventId);
event.setState(EventState.Completed);
String diskOfferingIdentifier = (diskOffering != null) ? String.valueOf(diskOffering.getId()) : "-1";
String eventParams = "id=" + vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ndoId=" + diskOfferingIdentifier + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
String eventParams = "id=" + vm.getId() + "\nvmName=" + vm.getHostName() + "\nsoId=" + vm.getServiceOfferingId() + "\ndoId=" + diskOfferingIdentifier + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
event.setParameters(eventParams);
if(!vm.getName().equals(vm.getDisplayName()))
event.setDescription("successfully created VM instance : " + vm.getName()+"("+vm.getDisplayName()+")");
if(!vm.getHostName().equals(vm.getDisplayName()))
event.setDescription("successfully created VM instance : " + vm.getHostName()+"("+vm.getDisplayName()+")");
else
event.setDescription("successfully created VM instance : " + vm.getName());
event.setDescription("successfully created VM instance : " + vm.getHostName());
_eventDao.persist(event);
_vmDao.updateIf(vm, Event.OperationSucceeded, null);
@ -3244,10 +3261,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
String description = null;
String type = null;
if (ha) {
description = "Successfully enabled HA for virtual machine " + vm.getName();
description = "Successfully enabled HA for virtual machine " + vm.getHostName();
type = EventTypes.EVENT_VM_ENABLE_HA;
} else {
description = "Successfully disabled HA for virtual machine " + vm.getName();
description = "Successfully disabled HA for virtual machine " + vm.getHostName();
type = EventTypes.EVENT_VM_DISABLE_HA;
}
// create a event for the change in HA Enabled flag
@ -3674,12 +3691,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
_accountMgr.checkAccess(caller, template);
DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), 1);
long id = _vmDao.getNextInSequence(Long.class, "id");
UserVmVO vm = new UserVmVO(id, VirtualMachineName.getVmName(id, owner.getId(), _instance), cmd.getDisplayName(),
template.getId(), template.getGuestOSId(), offering.getOfferHA(), domain.getId(), owner.getId(), offering.getId(), userData);
DataCenterDeployment plan = new DataCenterDeployment(dc.getId());
s_logger.debug("Allocating in the DB for vm");
@ -3689,16 +3701,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
networks.add(new Pair<NetworkConfigurationVO, NicProfile>(config, null));
}
Transaction txn = Transaction.currentTxn();
txn.start();
vm = _vmDao.persist(vm);
if (_itMgr.allocate(vm, template, offering, rootDiskOffering, dataDiskOfferings, networks, plan, owner) == null) {
long id = _vmDao.getNextInSequence(Long.class, "id");
UserVmVO vm = new UserVmVO(id, VirtualMachineName.getVmName(id, owner.getId(), _instance), cmd.getDisplayName(),
template.getId(), template.getGuestOSId(), offering.getOfferHA(), domain.getId(), owner.getId(), offering.getId(), userData);
if (_itMgr.allocate(vm, template, offering, rootDiskOffering, dataDiskOfferings, networks, null, plan, owner) == null) {
return null;
}
txn.commit();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Successfully allocated DB entry for " + vm);
}
@ -3711,20 +3722,26 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
UserVmVO vm = _vmDao.findById(vmId);
long dcId = cmd.getZoneId();
DataCenterDeployment plan = new DataCenterDeployment(dcId, 1);
long userId = UserContext.current().getUserId();
UserVO caller = _userDao.findById(userId);
AccountVO owner = _accountDao.findById(vm.getAccountId());
return _itMgr.start(vm, plan, owner);
return _itMgr.start(vm, null, caller, owner);
}
@Override
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<UserVmVO> profile, DeployDestination dest, ReservationContext context) {
return true;
}
@Override
public boolean finalizeDeployment(Commands cmds, UserVmVO vm, VirtualMachineProfile profile, DeployDestination dest) {
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<UserVmVO> profile, DeployDestination dest, ReservationContext context) {
return true;
}
@Override
public boolean processDeploymentResult(Commands cmds, UserVmVO vm, VirtualMachineProfile profile, DeployDestination dest) {
public boolean processDeploymentResult(Commands cmds, VirtualMachineProfile<UserVmVO> profile, DeployDestination dest, ReservationContext context) {
return true;
}
@ -3732,4 +3749,17 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
public UserVmVO persist(UserVmVO vm) {
return _vmDao.persist(vm);
}
@Override
public UserVmVO findById(long id) {
return _vmDao.findById(id);
}
@Override
public UserVmVO findByName(String name) {
if (!VirtualMachineName.isValidVmName(name)) {
return null;
}
return findById(VirtualMachineName.getVmId(name));
}
}

View File

@ -24,9 +24,20 @@ import com.cloud.deploy.DeployDestination;
* A VirtualMachineGuru knows how to process a certain type of virtual machine.
*
*/
public interface VirtualMachineGuru<T extends VMInstanceVO> {
public interface VirtualMachineGuru<T extends VirtualMachine> {
/**
* Find the virtual machine by name.
* @param name
* @return virtual machine.
*/
T findByName(String name);
T findById(long id);
T persist(T vm);
boolean finalizeVirtualMachineProfile(VirtualMachineProfile<T> profile, DeployDestination dest, ReservationContext context);
/**
* finalize the virtual machine deployment.
* @param cmds commands that were created.
@ -34,7 +45,7 @@ public interface VirtualMachineGuru<T extends VMInstanceVO> {
* @param dest destination to send the command.
* @return true if everything checks out. false if not and we should try again.
*/
boolean finalizeDeployment(Commands cmds, T vm, VirtualMachineProfile profile, DeployDestination dest);
boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<T> profile, DeployDestination dest, ReservationContext context);
/**
@ -44,5 +55,5 @@ public interface VirtualMachineGuru<T extends VMInstanceVO> {
* @param dest destination it was sent to.
* @return true if deployment was fine; false if it didn't go well.
*/
boolean processDeploymentResult(Commands cmds, T vm, VirtualMachineProfile profile, DeployDestination dest);
boolean processDeploymentResult(Commands cmds, VirtualMachineProfile<T> profile, DeployDestination dest, ReservationContext context);
}

View File

@ -18,6 +18,7 @@
package com.cloud.vm;
import java.util.List;
import java.util.Map;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.AgentUnavailableException;
@ -30,6 +31,7 @@ import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Manager;
@ -38,16 +40,17 @@ import com.cloud.utils.component.Manager;
*/
public interface VmManager extends Manager {
<T extends VMInstanceVO> VirtualMachineProfile allocate(T vm,
<T extends VMInstanceVO> VirtualMachineProfile<T> allocate(T vm,
VMTemplateVO template,
ServiceOfferingVO serviceOffering,
Pair<? extends DiskOfferingVO, Long> rootDiskOffering,
List<Pair<DiskOfferingVO, Long>> dataDiskOfferings,
List<Pair<NetworkConfigurationVO, NicProfile>> networks,
List<Pair<NetworkConfigurationVO, NicProfile>> networks,
Map<String, Object> params,
DeploymentPlan plan,
Account owner) throws InsufficientCapacityException, StorageUnavailableException;
<T extends VMInstanceVO> VirtualMachineProfile allocate(T vm,
<T extends VMInstanceVO> VirtualMachineProfile<T> allocate(T vm,
VMTemplateVO template,
ServiceOfferingVO serviceOffering,
Long rootSize,
@ -56,16 +59,16 @@ public interface VmManager extends Manager {
DeploymentPlan plan,
Account owner) throws InsufficientCapacityException, StorageUnavailableException;
<T extends VMInstanceVO> VirtualMachineProfile allocate(T vm,
<T extends VMInstanceVO> VirtualMachineProfile<T> allocate(T vm,
VMTemplateVO template,
ServiceOfferingVO serviceOffering,
List<Pair<NetworkConfigurationVO, NicProfile>> networkProfiles,
DeploymentPlan plan,
Account owner) throws InsufficientCapacityException, StorageUnavailableException;
<T extends VMInstanceVO> T start(T vm, DeploymentPlan plan, Account user) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException, ResourceUnavailableException;
<T extends VMInstanceVO> T start(T vm, Map<String, Object> params, User caller, Account account) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException, ResourceUnavailableException;
<T extends VMInstanceVO> T stop(T vm) throws AgentUnavailableException, ConcurrentOperationException;
<T extends VMInstanceVO> T stop(T vm, User caller, Account account) throws AgentUnavailableException, ConcurrentOperationException;
void destroy();

View File

@ -83,6 +83,18 @@ DROP TABLE IF EXISTS `cloud`.`account_network_ref`;
DROP TABLE IF EXISTS `cloud`.`instance_group`;
DROP TABLE IF EXISTS `cloud`.`instance_group_vm_map`;
DROP TABLE IF EXISTS `cloud`.`certificate`;
DROP TABLE IF EXISTS `cloud`.`op_it_work`;
CREATE TABLE `cloud`.`op_it_work` (
`id` char(40) COMMENT 'id',
`mgmt_server_id` bigint unsigned COMMENT 'management server id',
`created` timestamp NOT NULL COMMENT 'when was this work detail created',
`thread` varchar(255) NOT NULL COMMENT 'thread name',
`type` char(32) NOT NULL COMMENT 'type of work',
`state` char(32) NOT NULL COMMENT 'state',
`cancel_taken` timestamp COMMENT 'time it was taken over',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`hypervsior_properties` (
`hypervisor` varchar(32) NOT NULL UNIQUE COMMENT 'hypervisor type',
@ -95,7 +107,6 @@ CREATE TABLE `cloud`.`op_network_configurations`(
`id` bigint unsigned NOT NULL UNIQUE KEY,
`mac_address_seq` bigint unsigned NOT NULL DEFAULT 1 COMMENT 'mac address',
PRIMARY KEY(`id`)
# CONSTRAINT `fk__op_network_configurations__id` FOREIGN KEY `fk_op_network_configurations__id`(`id`) REFERENCES `network_configurations`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`network_configurations` (
@ -588,7 +599,7 @@ CREATE TABLE `cloud`.`vm_instance` (
`private_mac_address` varchar(17),
`private_ip_address` varchar(15),
`private_netmask` varchar(15),
`pod_id` bigint unsigned NOT NULL,
`pod_id` bigint unsigned,
`data_center_id` bigint unsigned NOT NULL COMMENT 'Data Center the instance belongs to',
`host_id` bigint unsigned,
`last_host_id` bigint unsigned COMMENT 'tentative host for first run or last host that it has been running on',

View File

@ -1,282 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.utils;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;
import com.cloud.utils.encoding.Base64;
import com.cloud.utils.net.MacAddress;
/**
* UUID creates a globally unique id. The format it uses is as follows.
* The first byte contains a 2 bit version number and a 2 bit jvm
* instance id. The next 6 bytes contain the mac address. The next 5 bytes
* contain the a snapshot of System.currentTimeMillis() >> 10 & 0xFFFFFFFFFF.
* The last 4 bytes contain an ever increasing counter. If the the counter
* overflows, it resets and another snapshot of
* System.currentTimeMillis() >> 10 & 0xFFFFFFFFFF is taken.
*
* There are several advantages to this implementation:
* 1. There's no need to save a system wide number if the system restarts.
* The MAC address and currentTimeMillis() together guarantees that the
* counter portion will be unique.
* 2. It allows you to deploy four jvms using the same UUID to generate
* unique ids. The instance id is retrieved from server.properties
* using the key server.instance. Each jvm will need to specify a
* different value (0-3).
* 3. The UUID is guaranteed to be unique for roughly 35,000 years.
*
* Note: Why do we do System.currentTimeMillis() >> 10 & 0xFFFFFFFFFF?
* 1. >> 10 loses the milliseconds portion of the time. Well, a little
* more than 1000 ms (actually 1024). This does mean that you can
* not restart a server in less than a second or else the old
* instance and the new instance can collide.
* 2. & 0xFFFFFFFFFF reduces the overall size to fit it into 5 bytes. This
* does impose the roughly 35000 years limitation because by then the
* value will overflow. Arithmetic for arriving at that limitation
* is posted here for your review.
*
* 2^(5*8) / 60 (s/m) / 60 (m/h) / 60 (h/d) / 365 (d/y) = 34865 years
**/
public class UUID {
static final long serialVersionUID = SerialVersionUID.UUID;
static byte[] s_addr;
static long s_currentTime = System.currentTimeMillis() >> 10;
static int s_counter = 0;
static {
byte[] addr = MacAddress.getMacAddress().toByteArray();
byte version = (byte)0x80;
byte instance = (byte)0x1;
version |= instance;
s_addr = new byte[7];
s_addr[0] = version;
for (int i = 0; i < addr.length; i++) {
s_addr[i + 1] = addr[i];
}
}
private byte[] _uuid;
public UUID() {
int counter;
long currentTime;
synchronized(UUID.class) {
currentTime = s_currentTime;
counter = ++s_counter;
if (s_counter == Integer.MAX_VALUE) {
s_counter = 0;
s_currentTime = System.currentTimeMillis() >> 10;
}
}
_uuid = new byte[16];
System.arraycopy(s_addr, 0, _uuid, 0, s_addr.length);
_uuid[7] = (byte)((currentTime >> 32) & 0xFF);
_uuid[8] = (byte)((currentTime >> 24) & 0xFF);
_uuid[9] = (byte)((currentTime >> 16) & 0xFF);
_uuid[10] = (byte)((currentTime >> 8) & 0xFF);
_uuid[11] = (byte)((currentTime >> 0) & 0xFF);
_uuid[12] = (byte)((counter >> 24) & 0xFF);
_uuid[13] = (byte)((counter >> 16) & 0xFF);
_uuid[14] = (byte)((counter >> 8) & 0xFF);
_uuid[15] = (byte)((counter >> 0) & 0xFF);
}
/**
* Copy constructor for UUID. Values of the given UUID are copied.
*
* @param u the UUID, may not be <code>null</code>
*/
public UUID(UUID u) {
_uuid = new byte[u._uuid.length];
System.arraycopy(u._uuid, 0, _uuid, 0, u._uuid.length);
}
// This is really for testing purposes only.
protected UUID(int counter) {
long currentTime;
synchronized(UUID.class) {
s_counter = counter;
s_counter++;
currentTime = s_currentTime;
if (s_counter == Integer.MAX_VALUE) {
s_counter = 0;
s_currentTime = System.currentTimeMillis() >> 10;
}
}
_uuid = new byte[16];
System.arraycopy(s_addr, 0, _uuid, 0, s_addr.length);
_uuid[7] = (byte)((currentTime >> 32) & 0xFF);
_uuid[8] = (byte)((currentTime >> 24) & 0xFF);
_uuid[9] = (byte)((currentTime >> 16) & 0xFF);
_uuid[10] = (byte)((currentTime >> 8) & 0xFF);
_uuid[11] = (byte)((currentTime >> 0) & 0xFF);
_uuid[12] = (byte)((counter >> 24) & 0xFF);
_uuid[13] = (byte)((counter >> 16) & 0xFF);
_uuid[14] = (byte)((counter >> 8) & 0xFF);
_uuid[15] = (byte)((counter >> 0) & 0xFF);
}
public final byte[] getBytes() {
return _uuid;
}
public final void writeTo(ByteBuffer buff) {
buff.put(_uuid);
}
/**
* Return an encoded string.
* @param options the string should be encoded using this option.
**/
public String toString(int options) {
return Base64.encodeBytes(getBytes(), options);
}
/**
* Return an encoded string that is url safe.
**/
public String toUrlSafeString() {
return Base64.encodeBytes(getBytes(), Base64.URL_SAFE);
}
/**
* To override the toString() method.
**/
@Override
public String toString() {
return toUrlSafeString();
}
public int compareTo(Object o) {
if (this == o) {
return 0;
}
if (!(o instanceof UUID)) {
throw new ClassCastException(
"The argument must be of type '" + getClass().getName() + "'.");
}
long time = NumbersUtil.bytesToLong(_uuid, 12);
UUID t = (UUID) o;
long ttime = NumbersUtil.bytesToLong(t._uuid, 12);
if (time > ttime) {
return 1;
}
if (time < ttime) {
return -1;
}
return 0;
}
/**
* Tweaked Serialization routine.
*
* @param out the ObjectOutputStream
* @throws IOException
*/
private void writeObject(ObjectOutputStream out) throws IOException {
out.write(_uuid);
}
/**
* Tweaked Serialization routine.
*
* @param in the ObjectInputStream
* @throws IOException
* @throws ClassNotFoundException
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
_uuid = new byte[16];
in.read(_uuid, 0, _uuid.length);
}
/**
* Appends a String representation of this to the given {@link StringBuffer} or
* creates a new one if none is given.
*
* @param in the StringBuffer to append to, may be <code>null</code>
* @return a StringBuffer
*/
public StringBuffer toStringBuffer(StringBuffer in) {
return in.append(toString());
}
/**
* Returns a hash code of this UUID. The hash code is calculated by XOR'ing the
* upper 32 bits of the time and clockSeqAndNode fields and the lower 32 bits of
* the time and clockSeqAndNode fields.
*
* @return an <code>int</code> representing the hash code
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return (int)NumbersUtil.bytesToLong(_uuid, 12);
}
/**
* Clones this UUID.
*
* @return a new UUID with identical values, never <code>null</code>
*/
@Override
public Object clone() {
return new UUID(this);
}
/**
* Compares two Objects for equality.
*
* @see java.lang.Object#equals(Object)
* @param obj the Object to compare this UUID with, may be <code>null</code>
* @return <code>true</code> if the other Object is equal to this UUID,
* <code>false</code> if not
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof UUID)) {
return false;
}
return compareTo(obj) == 0;
}
public static void main(String[] args) {
UUID uuid1 = new UUID();
System.out.println("1 = " + NumbersUtil.bytesToString(uuid1.getBytes(), 0, uuid1.getBytes().length));
UUID uuid2 = new UUID();
System.out.println("2 = " + NumbersUtil.bytesToString(uuid2.getBytes(), 0, uuid1.getBytes().length));
long start = System.currentTimeMillis();
for (int i = 0; i < Integer.MAX_VALUE; i++) {
UUID uuid = new UUID();
}
long end = System.currentTimeMillis();
System.out.println("That took " + (end - start));
uuid1 = new UUID();
System.out.println("1 now = " + NumbersUtil.bytesToString(uuid1.getBytes(), 0, uuid1.getBytes().length));
}
}

View File

@ -28,6 +28,7 @@ public class Ip4Address {
_addr = NetUtils.long2Ip(addr);
}
@Override
public String toString() {
return _addr;
}