mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-7908: Add user_id column to vm_instance table
Design Document: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Allow+VM+listing+by+User+ID - Adds column to VMInstance DAO - Adds column in vm_instance table - Adds column in the UserVMJoinVO - Adds default admin user which has UID = 2 - Adds migration path that sets user_id to first user of the accountId that owns the vm in vm_instance table - Add arg on list VMs API to query by userId, add support in query layer - Refactor VMInstanceVO and child classes to accept userId - Add code to let service layer pass userId if loggedIn user belongs to same account as the owner executing an API call or use first user from owner account - In case of CPVM and SSVM use system user ID - Fix unit tests and spring injections Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
67268d9db3
commit
1a6df6f978
@ -22,6 +22,7 @@ import org.apache.cloudstack.api.InternalIdentity;
|
|||||||
|
|
||||||
public interface User extends OwnedBy, InternalIdentity {
|
public interface User extends OwnedBy, InternalIdentity {
|
||||||
public static final long UID_SYSTEM = 1;
|
public static final long UID_SYSTEM = 1;
|
||||||
|
public static final long UID_ADMIN = 2;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getId();
|
public long getId();
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.api.response.UserResponse;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import org.apache.cloudstack.acl.RoleType;
|
import org.apache.cloudstack.acl.RoleType;
|
||||||
@ -129,6 +130,9 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
|
|||||||
@Parameter(name = ApiConstants.DISPLAY_VM, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {RoleType.Admin})
|
@Parameter(name = ApiConstants.DISPLAY_VM, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {RoleType.Admin})
|
||||||
private Boolean display;
|
private Boolean display;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.USER_ID, type = CommandType.UUID, entityType = UserResponse.class, required = false, description = "the user ID that created the VM and is under the account that owns the VM")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
/////////////////// Accessors ///////////////////////
|
/////////////////// Accessors ///////////////////////
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
@ -145,6 +149,10 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,9 @@ package com.cloud.upgrade.dao;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
@ -55,6 +58,42 @@ public class Upgrade450to460 implements DbUpgrade {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performDataMigration(Connection conn) {
|
public void performDataMigration(Connection conn) {
|
||||||
|
updateVMInstanceUserId(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateVMInstanceUserId(Connection conn) {
|
||||||
|
// For schemas before this, copy first user from an account_id which deployed already running VMs
|
||||||
|
s_logger.debug("Updating vm_instance column user_id using first user in vm_instance's account_id");
|
||||||
|
String vmInstanceSql = "SELECT id, account_id FROM `cloud`.`vm_instance`";
|
||||||
|
String userSql = "SELECT id FROM `cloud`.`user` where account_id=?";
|
||||||
|
String userIdUpdateSql = "update `cloud`.`vm_instance` set user_id=? where id=?";
|
||||||
|
try(PreparedStatement selectStatement = conn.prepareStatement(vmInstanceSql)) {
|
||||||
|
ResultSet results = selectStatement.executeQuery();
|
||||||
|
while (results.next()) {
|
||||||
|
long vmId = results.getLong(1);
|
||||||
|
long accountId = results.getLong(2);
|
||||||
|
try (PreparedStatement selectUserStatement = conn.prepareStatement(userSql)) {
|
||||||
|
selectUserStatement.setLong(1, accountId);
|
||||||
|
ResultSet userResults = selectUserStatement.executeQuery();
|
||||||
|
if (userResults.next()) {
|
||||||
|
long userId = userResults.getLong(1);
|
||||||
|
try (PreparedStatement updateStatement = conn.prepareStatement(userIdUpdateSql)) {
|
||||||
|
updateStatement.setLong(1, userId);
|
||||||
|
updateStatement.setLong(2, vmId);
|
||||||
|
updateStatement.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new CloudRuntimeException("Unable to update user ID " + userId + " on vm_instance id=" + vmId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new CloudRuntimeException("Unable to update user ID using accountId " + accountId + " on vm_instance id=" + vmId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new CloudRuntimeException("Unable to update user Ids for previously deployed VMs", e);
|
||||||
|
}
|
||||||
|
s_logger.debug("Done updating user Ids for previously deployed VMs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -144,8 +144,8 @@ public class ConsoleProxyVO extends VMInstanceVO implements ConsoleProxy {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public ConsoleProxyVO(long id, long serviceOfferingId, String name, long templateId, HypervisorType hypervisorType, long guestOSId, long dataCenterId, long domainId,
|
public ConsoleProxyVO(long id, long serviceOfferingId, String name, long templateId, HypervisorType hypervisorType, long guestOSId, long dataCenterId, long domainId,
|
||||||
long accountId, int activeSession, boolean haEnabled) {
|
long accountId, long userId, int activeSession, boolean haEnabled) {
|
||||||
super(id, serviceOfferingId, name, name, Type.ConsoleProxy, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
|
super(id, serviceOfferingId, name, name, Type.ConsoleProxy, templateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled);
|
||||||
this.activeSession = activeSession;
|
this.activeSession = activeSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -76,9 +76,9 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
|
|||||||
private Long vpcId;
|
private Long vpcId;
|
||||||
|
|
||||||
public DomainRouterVO(long id, long serviceOfferingId, long elementId, String name, long templateId, HypervisorType hypervisorType, long guestOSId, long domainId,
|
public DomainRouterVO(long id, long serviceOfferingId, long elementId, String name, long templateId, HypervisorType hypervisorType, long guestOSId, long domainId,
|
||||||
long accountId, boolean isRedundantRouter, int priority, boolean isPriorityBumpUp, RedundantState redundantState, boolean haEnabled, boolean stopPending,
|
long accountId, long userId, boolean isRedundantRouter, int priority, boolean isPriorityBumpUp, RedundantState redundantState, boolean haEnabled, boolean stopPending,
|
||||||
Long vpcId) {
|
Long vpcId) {
|
||||||
super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
|
super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled);
|
||||||
this.elementId = elementId;
|
this.elementId = elementId;
|
||||||
this.isRedundantRouter = isRedundantRouter;
|
this.isRedundantRouter = isRedundantRouter;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
@ -89,9 +89,9 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DomainRouterVO(long id, long serviceOfferingId, long elementId, String name, long templateId, HypervisorType hypervisorType, long guestOSId, long domainId,
|
public DomainRouterVO(long id, long serviceOfferingId, long elementId, String name, long templateId, HypervisorType hypervisorType, long guestOSId, long domainId,
|
||||||
long accountId, boolean isRedundantRouter, int priority, boolean isPriorityBumpUp, RedundantState redundantState, boolean haEnabled, boolean stopPending,
|
long accountId, long userId, boolean isRedundantRouter, int priority, boolean isPriorityBumpUp, RedundantState redundantState, boolean haEnabled, boolean stopPending,
|
||||||
VirtualMachine.Type vmType, Long vpcId) {
|
Type vmType, Long vpcId) {
|
||||||
super(id, serviceOfferingId, name, name, vmType, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
|
super(id, serviceOfferingId, name, name, vmType, templateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled);
|
||||||
this.elementId = elementId;
|
this.elementId = elementId;
|
||||||
this.isRedundantRouter = isRedundantRouter;
|
this.isRedundantRouter = isRedundantRouter;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
|
|||||||
@ -64,8 +64,8 @@ public class SecondaryStorageVmVO extends VMInstanceVO implements SecondaryStora
|
|||||||
private Date lastUpdateTime;
|
private Date lastUpdateTime;
|
||||||
|
|
||||||
public SecondaryStorageVmVO(long id, long serviceOfferingId, String name, long templateId, HypervisorType hypervisorType, long guestOSId, long dataCenterId,
|
public SecondaryStorageVmVO(long id, long serviceOfferingId, String name, long templateId, HypervisorType hypervisorType, long guestOSId, long dataCenterId,
|
||||||
long domainId, long accountId, Role role, boolean haEnabled) {
|
long domainId, long accountId, long userId, Role role, boolean haEnabled) {
|
||||||
super(id, serviceOfferingId, name, name, Type.SecondaryStorageVm, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
|
super(id, serviceOfferingId, name, name, Type.SecondaryStorageVm, templateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled);
|
||||||
this.role = role;
|
this.role = role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -70,8 +70,8 @@ public class UserVmVO extends VMInstanceVO implements UserVm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public UserVmVO(long id, String instanceName, String displayName, long templateId, HypervisorType hypervisorType, long guestOsId, boolean haEnabled,
|
public UserVmVO(long id, String instanceName, String displayName, long templateId, HypervisorType hypervisorType, long guestOsId, boolean haEnabled,
|
||||||
boolean limitCpuUse, long domainId, long accountId, long serviceOfferingId, String userData, String name, Long diskOfferingId) {
|
boolean limitCpuUse, long domainId, long accountId, long userId, long serviceOfferingId, String userData, String name, Long diskOfferingId) {
|
||||||
super(id, serviceOfferingId, name, instanceName, Type.User, templateId, hypervisorType, guestOsId, domainId, accountId, haEnabled, limitCpuUse, diskOfferingId);
|
super(id, serviceOfferingId, name, instanceName, Type.User, templateId, hypervisorType, guestOsId, domainId, accountId, userId, haEnabled, limitCpuUse, diskOfferingId);
|
||||||
this.userData = userData;
|
this.userData = userData;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
this.details = new HashMap<String, String>();
|
this.details = new HashMap<String, String>();
|
||||||
|
|||||||
@ -141,6 +141,9 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
|
|||||||
@Column(name = "account_id")
|
@Column(name = "account_id")
|
||||||
protected long accountId;
|
protected long accountId;
|
||||||
|
|
||||||
|
@Column(name = "user_id")
|
||||||
|
protected long userId;
|
||||||
|
|
||||||
@Column(name = "service_offering_id")
|
@Column(name = "service_offering_id")
|
||||||
protected long serviceOfferingId;
|
protected long serviceOfferingId;
|
||||||
|
|
||||||
@ -186,7 +189,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
|
|||||||
protected Long powerHostId;
|
protected Long powerHostId;
|
||||||
|
|
||||||
public VMInstanceVO(long id, long serviceOfferingId, String name, String instanceName, Type type, Long vmTemplateId, HypervisorType hypervisorType, long guestOSId,
|
public VMInstanceVO(long id, long serviceOfferingId, String name, String instanceName, Type type, Long vmTemplateId, HypervisorType hypervisorType, long guestOSId,
|
||||||
long domainId, long accountId, boolean haEnabled) {
|
long domainId, long accountId, long userId, boolean haEnabled) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
hostName = name != null ? name : uuid;
|
hostName = name != null ? name : uuid;
|
||||||
if (vmTemplateId != null) {
|
if (vmTemplateId != null) {
|
||||||
@ -201,6 +204,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
|
|||||||
this.domainId = domainId;
|
this.domainId = domainId;
|
||||||
this.serviceOfferingId = serviceOfferingId;
|
this.serviceOfferingId = serviceOfferingId;
|
||||||
this.hypervisorType = hypervisorType;
|
this.hypervisorType = hypervisorType;
|
||||||
|
this.userId = userId;
|
||||||
limitCpuUse = false;
|
limitCpuUse = false;
|
||||||
try {
|
try {
|
||||||
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
|
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
|
||||||
@ -213,8 +217,8 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
|
|||||||
}
|
}
|
||||||
|
|
||||||
public VMInstanceVO(long id, long serviceOfferingId, String name, String instanceName, Type type, Long vmTemplateId, HypervisorType hypervisorType, long guestOSId,
|
public VMInstanceVO(long id, long serviceOfferingId, String name, String instanceName, Type type, Long vmTemplateId, HypervisorType hypervisorType, long guestOSId,
|
||||||
long domainId, long accountId, boolean haEnabled, boolean limitResourceUse, Long diskOfferingId) {
|
long domainId, long accountId, long userId, boolean haEnabled, boolean limitResourceUse, Long diskOfferingId) {
|
||||||
this(id, serviceOfferingId, name, instanceName, type, vmTemplateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
|
this(id, serviceOfferingId, name, instanceName, type, vmTemplateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled);
|
||||||
limitCpuUse = limitResourceUse;
|
limitCpuUse = limitResourceUse;
|
||||||
this.diskOfferingId = diskOfferingId;
|
this.diskOfferingId = diskOfferingId;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import com.cloud.user.dao.UserDao;
|
||||||
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
|
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
|
||||||
import org.apache.cloudstack.context.CallContext;
|
import org.apache.cloudstack.context.CallContext;
|
||||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||||
@ -140,6 +141,8 @@ public class LoadBalanceRuleHandler {
|
|||||||
private PhysicalNetworkServiceProviderDao _physicalProviderDao;
|
private PhysicalNetworkServiceProviderDao _physicalProviderDao;
|
||||||
@Inject
|
@Inject
|
||||||
private VirtualRouterProviderDao _vrProviderDao;
|
private VirtualRouterProviderDao _vrProviderDao;
|
||||||
|
@Inject
|
||||||
|
private UserDao _userDao;
|
||||||
|
|
||||||
static final private String ELB_VM_NAME_PREFIX = "l";
|
static final private String ELB_VM_NAME_PREFIX = "l";
|
||||||
|
|
||||||
@ -272,8 +275,13 @@ public class LoadBalanceRuleHandler {
|
|||||||
throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId());
|
throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long userId = CallContext.current().getCallingUserId();
|
||||||
|
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
|
||||||
|
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
|
||||||
|
}
|
||||||
|
|
||||||
elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, ELB_VM_NAME_PREFIX),
|
elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, ELB_VM_NAME_PREFIX),
|
||||||
template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN,
|
template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, false, 0, false, RedundantState.UNKNOWN,
|
||||||
_elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null);
|
_elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null);
|
||||||
elbVm.setRole(Role.LB);
|
elbVm.setRole(Role.LB);
|
||||||
elbVm = _routerDao.persist(elbVm);
|
elbVm = _routerDao.persist(elbVm);
|
||||||
|
|||||||
@ -27,6 +27,8 @@ import javax.ejb.Local;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
|
import com.cloud.user.dao.UserDao;
|
||||||
|
import org.apache.cloudstack.context.CallContext;
|
||||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||||
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
|
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
|
||||||
@ -164,6 +166,8 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
|
|||||||
VMTemplateDao _templateDao;
|
VMTemplateDao _templateDao;
|
||||||
@Inject
|
@Inject
|
||||||
ResourceManager _resourceMgr;
|
ResourceManager _resourceMgr;
|
||||||
|
@Inject
|
||||||
|
UserDao _userDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
|
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
|
||||||
@ -760,9 +764,14 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long userId = CallContext.current().getCallingUserId();
|
||||||
|
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
|
||||||
|
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
|
||||||
|
}
|
||||||
|
|
||||||
internalLbVm =
|
internalLbVm =
|
||||||
new DomainRouterVO(id, routerOffering.getId(), internalLbProviderId, VirtualMachineName.getSystemVmName(id, _instance, InternalLbVmNamePrefix),
|
new DomainRouterVO(id, routerOffering.getId(), internalLbProviderId, VirtualMachineName.getSystemVmName(id, _instance, InternalLbVmNamePrefix),
|
||||||
template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false,
|
template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, false, 0, false,
|
||||||
RedundantState.UNKNOWN, false, false, VirtualMachine.Type.InternalLoadBalancerVm, vpcId);
|
RedundantState.UNKNOWN, false, false, VirtualMachine.Type.InternalLoadBalancerVm, vpcId);
|
||||||
internalLbVm.setRole(Role.INTERNAL_LB_VM);
|
internalLbVm.setRole(Role.INTERNAL_LB_VM);
|
||||||
internalLbVm = _internalLbVmDao.persist(internalLbVm);
|
internalLbVm = _internalLbVmDao.persist(internalLbVm);
|
||||||
|
|||||||
@ -126,7 +126,7 @@ public class InternalLBVMManagerTest extends TestCase {
|
|||||||
ComponentContext.initComponentsLifeCycle();
|
ComponentContext.initComponentsLifeCycle();
|
||||||
|
|
||||||
vm =
|
vm =
|
||||||
new DomainRouterVO(1L, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, false, 0, false, null, false, false,
|
new DomainRouterVO(1L, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, 0, false, null, false, false,
|
||||||
VirtualMachine.Type.InternalLoadBalancerVm, null);
|
VirtualMachine.Type.InternalLoadBalancerVm, null);
|
||||||
vm.setRole(Role.INTERNAL_LB_VM);
|
vm.setRole(Role.INTERNAL_LB_VM);
|
||||||
vm = setId(vm, 1);
|
vm = setId(vm, 1);
|
||||||
|
|||||||
@ -101,11 +101,11 @@ public class InternalLBVMServiceTest extends TestCase {
|
|||||||
CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||||
|
|
||||||
DomainRouterVO validVm =
|
DomainRouterVO validVm =
|
||||||
new DomainRouterVO(validVmId, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, false, 0, false, null, false, false,
|
new DomainRouterVO(validVmId, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, 0, false, null, false, false,
|
||||||
VirtualMachine.Type.InternalLoadBalancerVm, null);
|
VirtualMachine.Type.InternalLoadBalancerVm, null);
|
||||||
validVm.setRole(Role.INTERNAL_LB_VM);
|
validVm.setRole(Role.INTERNAL_LB_VM);
|
||||||
DomainRouterVO nonInternalLbVm =
|
DomainRouterVO nonInternalLbVm =
|
||||||
new DomainRouterVO(validVmId, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, false, 0, false, null, false, false,
|
new DomainRouterVO(validVmId, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, 0, false, null, false, false,
|
||||||
VirtualMachine.Type.DomainRouter, null);
|
VirtualMachine.Type.DomainRouter, null);
|
||||||
nonInternalLbVm.setRole(Role.VIRTUAL_ROUTER);
|
nonInternalLbVm.setRole(Role.VIRTUAL_ROUTER);
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,10 @@
|
|||||||
<property name="name" value="InternalLoadBalancerVMManager"/>
|
<property name="name" value="InternalLoadBalancerVMManager"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="UserDao" class="com.cloud.user.dao.UserDaoImpl">
|
||||||
|
<property name="name" value="UserDao"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean class="org.apache.cloudstack.internallbvmmgr.LbChildTestConfiguration" />
|
<bean class="org.apache.cloudstack.internallbvmmgr.LbChildTestConfiguration" />
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|||||||
@ -41,6 +41,10 @@
|
|||||||
<property name="name" value="InternalLoadBalancerVMService"/>
|
<property name="name" value="InternalLoadBalancerVMService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="UserDao" class="com.cloud.user.dao.UserDaoImpl">
|
||||||
|
<property name="name" value="UserDao"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean class="org.apache.cloudstack.internallbvmmgr.LbChildTestConfiguration" />
|
<bean class="org.apache.cloudstack.internallbvmmgr.LbChildTestConfiguration" />
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|||||||
@ -109,9 +109,15 @@ public class ServiceManagerImpl implements ServiceManager {
|
|||||||
networks.put((NetworkVO)left, new ArrayList<NicProfile>());
|
networks.put((NetworkVO)left, new ArrayList<NicProfile>());
|
||||||
networks.put((NetworkVO)right, new ArrayList<NicProfile>());
|
networks.put((NetworkVO)right, new ArrayList<NicProfile>());
|
||||||
String instanceName = VirtualMachineName.getVmName(id, owner.getId(), "SRV");
|
String instanceName = VirtualMachineName.getVmName(id, owner.getId(), "SRV");
|
||||||
|
|
||||||
|
long userId = CallContext.current().getCallingUserId();
|
||||||
|
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
|
||||||
|
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
|
||||||
|
}
|
||||||
|
|
||||||
ServiceVirtualMachine svm =
|
ServiceVirtualMachine svm =
|
||||||
new ServiceVirtualMachine(id, instanceName, name, template.getId(), serviceOffering.getId(), template.getHypervisorType(), template.getGuestOSId(),
|
new ServiceVirtualMachine(id, instanceName, name, template.getId(), serviceOffering.getId(), template.getHypervisorType(), template.getGuestOSId(),
|
||||||
zone.getId(), owner.getDomainId(), owner.getAccountId(), false);
|
zone.getId(), owner.getDomainId(), owner.getAccountId(), userId, false);
|
||||||
|
|
||||||
// database synchronization code must be able to distinguish service instance VMs.
|
// database synchronization code must be able to distinguish service instance VMs.
|
||||||
Map<String, String> kvmap = new HashMap<String, String>();
|
Map<String, String> kvmap = new HashMap<String, String>();
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import com.cloud.vm.UserVmVO;
|
|||||||
|
|
||||||
public class ServiceVirtualMachine extends UserVmVO {
|
public class ServiceVirtualMachine extends UserVmVO {
|
||||||
public ServiceVirtualMachine(long id, String instanceName, String name, long templateId, long serviceOfferingId, HypervisorType hypervisorType, long guestOSId,
|
public ServiceVirtualMachine(long id, String instanceName, String name, long templateId, long serviceOfferingId, HypervisorType hypervisorType, long guestOSId,
|
||||||
long dataCenterId, long domainId, long accountId, boolean haEnabled) {
|
long dataCenterId, long domainId, long accountId, long userId, boolean haEnabled) {
|
||||||
super(id, instanceName, name, templateId, hypervisorType, guestOSId, false, false, domainId, accountId, serviceOfferingId, null, name, null);
|
super(id, instanceName, name, templateId, hypervisorType, guestOSId, false, false, domainId, accountId, userId, serviceOfferingId, null, name, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -239,7 +239,7 @@ public class ManagementServerMock {
|
|||||||
long id = _userVmDao.getNextInSequence(Long.class, "id");
|
long id = _userVmDao.getNextInSequence(Long.class, "id");
|
||||||
UserVmVO vm =
|
UserVmVO vm =
|
||||||
new UserVmVO(id, name, name, tmpl.getId(), HypervisorType.XenServer, tmpl.getGuestOSId(), false, false, _zone.getDomainId(), Account.ACCOUNT_ID_SYSTEM,
|
new UserVmVO(id, name, name, tmpl.getId(), HypervisorType.XenServer, tmpl.getGuestOSId(), false, false, _zone.getDomainId(), Account.ACCOUNT_ID_SYSTEM,
|
||||||
small.getId(), null, name, null);
|
1, small.getId(), null, name, null);
|
||||||
vm.setState(com.cloud.vm.VirtualMachine.State.Running);
|
vm.setState(com.cloud.vm.VirtualMachine.State.Running);
|
||||||
vm.setHostId(_hostId);
|
vm.setHostId(_hostId);
|
||||||
vm.setDataCenterId(network.getDataCenterId());
|
vm.setDataCenterId(network.getDataCenterId());
|
||||||
|
|||||||
@ -780,6 +780,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
|||||||
|
|
||||||
boolean listAll = cmd.listAll();
|
boolean listAll = cmd.listAll();
|
||||||
Long id = cmd.getId();
|
Long id = cmd.getId();
|
||||||
|
Long userId = cmd.getUserId();
|
||||||
Map<String, String> tags = cmd.getTags();
|
Map<String, String> tags = cmd.getTags();
|
||||||
Boolean display = cmd.getDisplay();
|
Boolean display = cmd.getDisplay();
|
||||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||||
@ -871,6 +872,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
|||||||
sb.and("instanceGroupId", sb.entity().getInstanceGroupId(), SearchCriteria.Op.EQ);
|
sb.and("instanceGroupId", sb.entity().getInstanceGroupId(), SearchCriteria.Op.EQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userId != null) {
|
||||||
|
sb.and("userId", sb.entity().getUserId(), SearchCriteria.Op.EQ);
|
||||||
|
}
|
||||||
|
|
||||||
if (networkId != null) {
|
if (networkId != null) {
|
||||||
sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ);
|
sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ);
|
||||||
}
|
}
|
||||||
@ -946,6 +951,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
|||||||
sc.setParameters("isoId", isoId);
|
sc.setParameters("isoId", isoId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userId != null) {
|
||||||
|
sc.setParameters("userId", userId);
|
||||||
|
}
|
||||||
|
|
||||||
if (networkId != null) {
|
if (networkId != null) {
|
||||||
sc.setParameters("networkId", networkId);
|
sc.setParameters("networkId", networkId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,9 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
|
|||||||
@Column(name = "display_name", updatable = false, nullable = false, length = 255)
|
@Column(name = "display_name", updatable = false, nullable = false, length = 255)
|
||||||
private String displayName = null;
|
private String displayName = null;
|
||||||
|
|
||||||
|
@Column(name = "user_id")
|
||||||
|
private long userId;
|
||||||
|
|
||||||
@Column(name = "account_id")
|
@Column(name = "account_id")
|
||||||
private long accountId;
|
private long accountId;
|
||||||
|
|
||||||
@ -439,6 +442,10 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
|
|||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
return accountId;
|
return accountId;
|
||||||
|
|||||||
@ -715,7 +715,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
|
|||||||
|
|
||||||
ConsoleProxyVO proxy =
|
ConsoleProxyVO proxy =
|
||||||
new ConsoleProxyVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,
|
new ConsoleProxyVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,
|
||||||
systemAcct.getDomainId(), systemAcct.getId(), 0, _serviceOffering.getOfferHA());
|
systemAcct.getDomainId(), systemAcct.getId(), _accountMgr.getSystemUser().getId(), 0, _serviceOffering.getOfferHA());
|
||||||
proxy.setDynamicallyScalable(template.isDynamicallyScalable());
|
proxy.setDynamicallyScalable(template.isDynamicallyScalable());
|
||||||
proxy = _consoleProxyDao.persist(proxy);
|
proxy = _consoleProxyDao.persist(proxy);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -28,6 +28,8 @@ import javax.annotation.PostConstruct;
|
|||||||
import javax.ejb.Local;
|
import javax.ejb.Local;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import com.cloud.user.dao.UserDao;
|
||||||
|
import org.apache.cloudstack.context.CallContext;
|
||||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@ -146,6 +148,8 @@ public class NetworkHelperImpl implements NetworkHelper {
|
|||||||
private RouterControlHelper _routerControlHelper;
|
private RouterControlHelper _routerControlHelper;
|
||||||
@Inject
|
@Inject
|
||||||
protected NetworkOrchestrationService _networkMgr;
|
protected NetworkOrchestrationService _networkMgr;
|
||||||
|
@Inject
|
||||||
|
private UserDao _userDao;
|
||||||
|
|
||||||
protected final Map<HypervisorType, ConfigKey<String>> hypervisorsMap = new HashMap<>();
|
protected final Map<HypervisorType, ConfigKey<String>> hypervisorsMap = new HashMap<>();
|
||||||
|
|
||||||
@ -513,9 +517,14 @@ public class NetworkHelperImpl implements NetworkHelper {
|
|||||||
// VPC because it is not a VPC offering.
|
// VPC because it is not a VPC offering.
|
||||||
Long vpcId = routerDeploymentDefinition.getVpc() != null ? routerDeploymentDefinition.getVpc().getId() : null;
|
Long vpcId = routerDeploymentDefinition.getVpc() != null ? routerDeploymentDefinition.getVpc().getId() : null;
|
||||||
|
|
||||||
|
long userId = CallContext.current().getCallingUserId();
|
||||||
|
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
|
||||||
|
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
|
||||||
|
}
|
||||||
|
|
||||||
router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id,
|
router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id,
|
||||||
s_vmInstanceName), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(),
|
s_vmInstanceName), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(),
|
||||||
routerDeploymentDefinition.isRedundant(), 0, false, RedundantState.UNKNOWN, offerHA, false, vpcId);
|
userId, routerDeploymentDefinition.isRedundant(), 0, false, RedundantState.UNKNOWN, offerHA, false, vpcId);
|
||||||
|
|
||||||
router.setDynamicallyScalable(template.isDynamicallyScalable());
|
router.setDynamicallyScalable(template.isDynamicallyScalable());
|
||||||
router.setRole(Role.VIRTUAL_ROUTER);
|
router.setRole(Role.VIRTUAL_ROUTER);
|
||||||
|
|||||||
@ -128,7 +128,7 @@ public class SecurityManagerMBeanImpl extends StandardMBean implements SecurityG
|
|||||||
@Override
|
@Override
|
||||||
public void simulateVmStart(Long vmId) {
|
public void simulateVmStart(Long vmId) {
|
||||||
//all we need is the vmId
|
//all we need is the vmId
|
||||||
VMInstanceVO vm = new VMInstanceVO(vmId, 5, "foo", "foo", Type.User, null, HypervisorType.Any, 8, 1, 1, false, false, null);
|
VMInstanceVO vm = new VMInstanceVO(vmId, 5, "foo", "foo", Type.User, null, HypervisorType.Any, 8, 1, 1, 1, false, false, null);
|
||||||
_sgMgr.handleVmStarted(vm);
|
_sgMgr.handleVmStarted(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2969,7 +2969,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
|
|
||||||
checkIfHostNameUniqueInNtwkDomain(hostName, networkList);
|
checkIfHostNameUniqueInNtwkDomain(hostName, networkList);
|
||||||
|
|
||||||
UserVmVO vm = commitUserVm(zone, template, hostName, displayName, owner, diskOfferingId, diskSize, userData, caller, isDisplayVm, keyboard, accountId, offering,
|
long userId = CallContext.current().getCallingUserId();
|
||||||
|
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
|
||||||
|
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
UserVmVO vm = commitUserVm(zone, template, hostName, displayName, owner, diskOfferingId, diskSize, userData, caller, isDisplayVm, keyboard, accountId, userId, offering,
|
||||||
isIso, sshPublicKey, networkNicMap, id, instanceName, uuidName, hypervisorType, customParameters);
|
isIso, sshPublicKey, networkNicMap, id, instanceName, uuidName, hypervisorType, customParameters);
|
||||||
|
|
||||||
// Assign instance to the group
|
// Assign instance to the group
|
||||||
@ -3028,13 +3033,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
|
|
||||||
private UserVmVO commitUserVm(final DataCenter zone, final VirtualMachineTemplate template, final String hostName, final String displayName, final Account owner,
|
private UserVmVO commitUserVm(final DataCenter zone, final VirtualMachineTemplate template, final String hostName, final String displayName, final Account owner,
|
||||||
final Long diskOfferingId, final Long diskSize, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
|
final Long diskOfferingId, final Long diskSize, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
|
||||||
final long accountId, final ServiceOfferingVO offering, final boolean isIso, final String sshPublicKey, final LinkedHashMap<String, NicProfile> networkNicMap,
|
final long accountId, final long userId, final ServiceOfferingVO offering, final boolean isIso, final String sshPublicKey, final LinkedHashMap<String, NicProfile> networkNicMap,
|
||||||
final long id, final String instanceName, final String uuidName, final HypervisorType hypervisorType, final Map<String, String> customParameters) throws InsufficientCapacityException {
|
final long id, final String instanceName, final String uuidName, final HypervisorType hypervisorType, final Map<String, String> customParameters) throws InsufficientCapacityException {
|
||||||
return Transaction.execute(new TransactionCallbackWithException<UserVmVO, InsufficientCapacityException>() {
|
return Transaction.execute(new TransactionCallbackWithException<UserVmVO, InsufficientCapacityException>() {
|
||||||
@Override
|
@Override
|
||||||
public UserVmVO doInTransaction(TransactionStatus status) throws InsufficientCapacityException {
|
public UserVmVO doInTransaction(TransactionStatus status) throws InsufficientCapacityException {
|
||||||
UserVmVO vm = new UserVmVO(id, instanceName, displayName, template.getId(), hypervisorType, template.getGuestOSId(), offering.getOfferHA(), offering
|
UserVmVO vm = new UserVmVO(id, instanceName, displayName, template.getId(), hypervisorType, template.getGuestOSId(), offering.getOfferHA(), offering
|
||||||
.getLimitCpuUse(), owner.getDomainId(), owner.getId(), offering.getId(), userData, hostName, diskOfferingId);
|
.getLimitCpuUse(), owner.getDomainId(), owner.getId(), userId, offering.getId(), userData, hostName, diskOfferingId);
|
||||||
vm.setUuid(uuidName);
|
vm.setUuid(uuidName);
|
||||||
vm.setDynamicallyScalable(template.isDynamicallyScalable());
|
vm.setDynamicallyScalable(template.isDynamicallyScalable());
|
||||||
|
|
||||||
|
|||||||
@ -285,6 +285,7 @@ public class VirtualRouterElementTest {
|
|||||||
/* guestOSId */ 0L,
|
/* guestOSId */ 0L,
|
||||||
/* domainId */ 0L,
|
/* domainId */ 0L,
|
||||||
/* accountId */ 1L,
|
/* accountId */ 1L,
|
||||||
|
/* userId */ 1L,
|
||||||
/* isRedundantRouter */ false,
|
/* isRedundantRouter */ false,
|
||||||
/* priority */ 0,
|
/* priority */ 0,
|
||||||
/* isPriorityBumpUp */ false,
|
/* isPriorityBumpUp */ false,
|
||||||
|
|||||||
@ -122,7 +122,7 @@ public class VolumeApiServiceImplTest {
|
|||||||
when(_svc._volsDao.findById(1L)).thenReturn(volumeOfRunningVm);
|
when(_svc._volsDao.findById(1L)).thenReturn(volumeOfRunningVm);
|
||||||
|
|
||||||
UserVmVO runningVm = new UserVmVO(1L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false,
|
UserVmVO runningVm = new UserVmVO(1L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false,
|
||||||
false, 1L, 1L, 1L, null, "vm", null);
|
false, 1L, 1L, 1, 1L, null, "vm", null);
|
||||||
runningVm.setState(State.Running);
|
runningVm.setState(State.Running);
|
||||||
runningVm.setDataCenterId(1L);
|
runningVm.setDataCenterId(1L);
|
||||||
when(_svc._userVmDao.findById(1L)).thenReturn(runningVm);
|
when(_svc._userVmDao.findById(1L)).thenReturn(runningVm);
|
||||||
@ -134,7 +134,7 @@ public class VolumeApiServiceImplTest {
|
|||||||
when(_svc._volsDao.findById(2L)).thenReturn(volumeOfStoppedVm);
|
when(_svc._volsDao.findById(2L)).thenReturn(volumeOfStoppedVm);
|
||||||
|
|
||||||
UserVmVO stoppedVm = new UserVmVO(2L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false,
|
UserVmVO stoppedVm = new UserVmVO(2L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false,
|
||||||
false, 1L, 1L, 1L, null, "vm", null);
|
false, 1L, 1L, 1, 1L, null, "vm", null);
|
||||||
stoppedVm.setState(State.Stopped);
|
stoppedVm.setState(State.Stopped);
|
||||||
stoppedVm.setDataCenterId(1L);
|
stoppedVm.setDataCenterId(1L);
|
||||||
when(_svc._userVmDao.findById(2L)).thenReturn(stoppedVm);
|
when(_svc._userVmDao.findById(2L)).thenReturn(stoppedVm);
|
||||||
@ -142,7 +142,7 @@ public class VolumeApiServiceImplTest {
|
|||||||
|
|
||||||
// volume of hyperV vm id=3
|
// volume of hyperV vm id=3
|
||||||
UserVmVO hyperVVm = new UserVmVO(3L, "vm", "vm", 1, HypervisorType.Hyperv, 1L, false,
|
UserVmVO hyperVVm = new UserVmVO(3L, "vm", "vm", 1, HypervisorType.Hyperv, 1L, false,
|
||||||
false, 1L, 1L, 1L, null, "vm", null);
|
false, 1L, 1L, 1, 1L, null, "vm", null);
|
||||||
hyperVVm.setState(State.Stopped);
|
hyperVVm.setState(State.Stopped);
|
||||||
hyperVVm.setDataCenterId(1L);
|
hyperVVm.setDataCenterId(1L);
|
||||||
when(_svc._userVmDao.findById(3L)).thenReturn(hyperVVm);
|
when(_svc._userVmDao.findById(3L)).thenReturn(hyperVVm);
|
||||||
@ -199,7 +199,7 @@ public class VolumeApiServiceImplTest {
|
|||||||
|
|
||||||
// vm having root volume
|
// vm having root volume
|
||||||
UserVmVO vmHavingRootVolume = new UserVmVO(4L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false,
|
UserVmVO vmHavingRootVolume = new UserVmVO(4L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false,
|
||||||
false, 1L, 1L, 1L, null, "vm", null);
|
false, 1L, 1L, 1, 1L, null, "vm", null);
|
||||||
vmHavingRootVolume.setState(State.Stopped);
|
vmHavingRootVolume.setState(State.Stopped);
|
||||||
vmHavingRootVolume.setDataCenterId(1L);
|
vmHavingRootVolume.setDataCenterId(1L);
|
||||||
when(_svc._userVmDao.findById(4L)).thenReturn(vmHavingRootVolume);
|
when(_svc._userVmDao.findById(4L)).thenReturn(vmHavingRootVolume);
|
||||||
|
|||||||
@ -625,7 +625,7 @@ public class UserVmManagerTest {
|
|||||||
Account oldAccount = new AccountVO("testaccount", 1, "networkdomain", (short)0, UUID.randomUUID().toString());
|
Account oldAccount = new AccountVO("testaccount", 1, "networkdomain", (short)0, UUID.randomUUID().toString());
|
||||||
Account newAccount = new AccountVO("testaccount", 1, "networkdomain", (short)1, UUID.randomUUID().toString());
|
Account newAccount = new AccountVO("testaccount", 1, "networkdomain", (short)1, UUID.randomUUID().toString());
|
||||||
|
|
||||||
UserVmVO vm = new UserVmVO(10L, "test", "test", 1L, HypervisorType.Any, 1L, false, false, 1L, 1L, 5L, "test", "test", 1L);
|
UserVmVO vm = new UserVmVO(10L, "test", "test", 1L, HypervisorType.Any, 1L, false, false, 1L, 1L, 1, 5L, "test", "test", 1L);
|
||||||
vm.setState(VirtualMachine.State.Stopped);
|
vm.setState(VirtualMachine.State.Stopped);
|
||||||
when(_vmDao.findById(anyLong())).thenReturn(vm);
|
when(_vmDao.findById(anyLong())).thenReturn(vm);
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@ public class UserVmDaoImplTest extends TestCase {
|
|||||||
|
|
||||||
// Persist the data.
|
// Persist the data.
|
||||||
UserVmVO vo =
|
UserVmVO vo =
|
||||||
new UserVmVO(vmId, instanceName, displayName, templateId, hypervisor, guestOsId, haEnabled, limitCpuUse, domainId, accountId, serviceOfferingId, userdata,
|
new UserVmVO(vmId, instanceName, displayName, templateId, hypervisor, guestOsId, haEnabled, limitCpuUse, domainId, accountId, 1, serviceOfferingId, userdata,
|
||||||
name, diskOfferingId);
|
name, diskOfferingId);
|
||||||
dao.persist(vo);
|
dao.persist(vo);
|
||||||
|
|
||||||
|
|||||||
@ -203,7 +203,7 @@ public class AffinityApiUnitTest {
|
|||||||
@Test(expected = InvalidParameterValueException.class)
|
@Test(expected = InvalidParameterValueException.class)
|
||||||
public void updateAffinityGroupVMRunning() throws ResourceInUseException {
|
public void updateAffinityGroupVMRunning() throws ResourceInUseException {
|
||||||
|
|
||||||
UserVmVO vm = new UserVmVO(10L, "test", "test", 101L, HypervisorType.Any, 21L, false, false, domainId, 200L, 5L, "", "test", 1L);
|
UserVmVO vm = new UserVmVO(10L, "test", "test", 101L, HypervisorType.Any, 21L, false, false, domainId, 200L, 1, 5L, "", "test", 1L);
|
||||||
vm.setState(VirtualMachine.State.Running);
|
vm.setState(VirtualMachine.State.Running);
|
||||||
when(_vmDao.findById(10L)).thenReturn(vm);
|
when(_vmDao.findById(10L)).thenReturn(vm);
|
||||||
|
|
||||||
|
|||||||
@ -575,7 +575,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
|||||||
|
|
||||||
SecondaryStorageVmVO secStorageVm =
|
SecondaryStorageVmVO secStorageVm =
|
||||||
new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,
|
new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,
|
||||||
systemAcct.getDomainId(), systemAcct.getId(), role, _serviceOffering.getOfferHA());
|
systemAcct.getDomainId(), systemAcct.getId(), _accountMgr.getSystemUser().getId(), role, _serviceOffering.getOfferHA());
|
||||||
secStorageVm.setDynamicallyScalable(template.isDynamicallyScalable());
|
secStorageVm.setDynamicallyScalable(template.isDynamicallyScalable());
|
||||||
secStorageVm = _secStorageVmDao.persist(secStorageVm);
|
secStorageVm = _secStorageVmDao.persist(secStorageVm);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -151,3 +151,205 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Domain Defaults', 'DEFAULT',
|
|||||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Domain Defaults', 'DEFAULT', 'management-server', 'max.domain.primary.storage', '-1', 'The default maximum primary storage space (in GiB) that can be used for a domain', '-1', NULL, NULL, 0);
|
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Domain Defaults', 'DEFAULT', 'management-server', 'max.domain.primary.storage', '-1', 'The default maximum primary storage space (in GiB) that can be used for a domain', '-1', NULL, NULL, 0);
|
||||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Domain Defaults', 'DEFAULT', 'management-server', 'max.domain.secondary.storage', '-1', 'The default maximum secondary storage space (in GiB) that can be used for a domain', '-1', NULL, NULL, 0);
|
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Domain Defaults', 'DEFAULT', 'management-server', 'max.domain.secondary.storage', '-1', 'The default maximum secondary storage space (in GiB) that can be used for a domain', '-1', NULL, NULL, 0);
|
||||||
|
|
||||||
|
ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `user_id` bigint unsigned NOT NULL DEFAULT 1 COMMENT 'user id of VM deployer';
|
||||||
|
|
||||||
|
DROP VIEW IF EXISTS `cloud`.`user_vm_view`;
|
||||||
|
CREATE VIEW `cloud`.`user_vm_view` AS
|
||||||
|
select
|
||||||
|
vm_instance.id id,
|
||||||
|
vm_instance.name name,
|
||||||
|
user_vm.display_name display_name,
|
||||||
|
user_vm.user_data user_data,
|
||||||
|
account.id account_id,
|
||||||
|
account.uuid account_uuid,
|
||||||
|
account.account_name account_name,
|
||||||
|
account.type account_type,
|
||||||
|
domain.id domain_id,
|
||||||
|
domain.uuid domain_uuid,
|
||||||
|
domain.name domain_name,
|
||||||
|
domain.path domain_path,
|
||||||
|
projects.id project_id,
|
||||||
|
projects.uuid project_uuid,
|
||||||
|
projects.name project_name,
|
||||||
|
instance_group.id instance_group_id,
|
||||||
|
instance_group.uuid instance_group_uuid,
|
||||||
|
instance_group.name instance_group_name,
|
||||||
|
vm_instance.uuid uuid,
|
||||||
|
vm_instance.user_id user_id,
|
||||||
|
vm_instance.last_host_id last_host_id,
|
||||||
|
vm_instance.vm_type type,
|
||||||
|
vm_instance.limit_cpu_use limit_cpu_use,
|
||||||
|
vm_instance.created created,
|
||||||
|
vm_instance.state state,
|
||||||
|
vm_instance.removed removed,
|
||||||
|
vm_instance.ha_enabled ha_enabled,
|
||||||
|
vm_instance.hypervisor_type hypervisor_type,
|
||||||
|
vm_instance.instance_name instance_name,
|
||||||
|
vm_instance.guest_os_id guest_os_id,
|
||||||
|
vm_instance.display_vm display_vm,
|
||||||
|
guest_os.uuid guest_os_uuid,
|
||||||
|
vm_instance.pod_id pod_id,
|
||||||
|
host_pod_ref.uuid pod_uuid,
|
||||||
|
vm_instance.private_ip_address private_ip_address,
|
||||||
|
vm_instance.private_mac_address private_mac_address,
|
||||||
|
vm_instance.vm_type vm_type,
|
||||||
|
data_center.id data_center_id,
|
||||||
|
data_center.uuid data_center_uuid,
|
||||||
|
data_center.name data_center_name,
|
||||||
|
data_center.is_security_group_enabled security_group_enabled,
|
||||||
|
data_center.networktype data_center_type,
|
||||||
|
host.id host_id,
|
||||||
|
host.uuid host_uuid,
|
||||||
|
host.name host_name,
|
||||||
|
vm_template.id template_id,
|
||||||
|
vm_template.uuid template_uuid,
|
||||||
|
vm_template.name template_name,
|
||||||
|
vm_template.display_text template_display_text,
|
||||||
|
vm_template.enable_password password_enabled,
|
||||||
|
iso.id iso_id,
|
||||||
|
iso.uuid iso_uuid,
|
||||||
|
iso.name iso_name,
|
||||||
|
iso.display_text iso_display_text,
|
||||||
|
service_offering.id service_offering_id,
|
||||||
|
svc_disk_offering.uuid service_offering_uuid,
|
||||||
|
disk_offering.uuid disk_offering_uuid,
|
||||||
|
disk_offering.id disk_offering_id,
|
||||||
|
Case
|
||||||
|
When (`cloud`.`service_offering`.`cpu` is null) then (`custom_cpu`.`value`)
|
||||||
|
Else ( `cloud`.`service_offering`.`cpu`)
|
||||||
|
End as `cpu`,
|
||||||
|
Case
|
||||||
|
When (`cloud`.`service_offering`.`speed` is null) then (`custom_speed`.`value`)
|
||||||
|
Else ( `cloud`.`service_offering`.`speed`)
|
||||||
|
End as `speed`,
|
||||||
|
Case
|
||||||
|
When (`cloud`.`service_offering`.`ram_size` is null) then (`custom_ram_size`.`value`)
|
||||||
|
Else ( `cloud`.`service_offering`.`ram_size`)
|
||||||
|
END as `ram_size`,
|
||||||
|
svc_disk_offering.name service_offering_name,
|
||||||
|
disk_offering.name disk_offering_name,
|
||||||
|
storage_pool.id pool_id,
|
||||||
|
storage_pool.uuid pool_uuid,
|
||||||
|
storage_pool.pool_type pool_type,
|
||||||
|
volumes.id volume_id,
|
||||||
|
volumes.uuid volume_uuid,
|
||||||
|
volumes.device_id volume_device_id,
|
||||||
|
volumes.volume_type volume_type,
|
||||||
|
security_group.id security_group_id,
|
||||||
|
security_group.uuid security_group_uuid,
|
||||||
|
security_group.name security_group_name,
|
||||||
|
security_group.description security_group_description,
|
||||||
|
nics.id nic_id,
|
||||||
|
nics.uuid nic_uuid,
|
||||||
|
nics.network_id network_id,
|
||||||
|
nics.ip4_address ip_address,
|
||||||
|
nics.ip6_address ip6_address,
|
||||||
|
nics.ip6_gateway ip6_gateway,
|
||||||
|
nics.ip6_cidr ip6_cidr,
|
||||||
|
nics.default_nic is_default_nic,
|
||||||
|
nics.gateway gateway,
|
||||||
|
nics.netmask netmask,
|
||||||
|
nics.mac_address mac_address,
|
||||||
|
nics.broadcast_uri broadcast_uri,
|
||||||
|
nics.isolation_uri isolation_uri,
|
||||||
|
vpc.id vpc_id,
|
||||||
|
vpc.uuid vpc_uuid,
|
||||||
|
networks.uuid network_uuid,
|
||||||
|
networks.name network_name,
|
||||||
|
networks.traffic_type traffic_type,
|
||||||
|
networks.guest_type guest_type,
|
||||||
|
user_ip_address.id public_ip_id,
|
||||||
|
user_ip_address.uuid public_ip_uuid,
|
||||||
|
user_ip_address.public_ip_address public_ip_address,
|
||||||
|
ssh_keypairs.keypair_name keypair_name,
|
||||||
|
resource_tags.id tag_id,
|
||||||
|
resource_tags.uuid tag_uuid,
|
||||||
|
resource_tags.key tag_key,
|
||||||
|
resource_tags.value tag_value,
|
||||||
|
resource_tags.domain_id tag_domain_id,
|
||||||
|
resource_tags.account_id tag_account_id,
|
||||||
|
resource_tags.resource_id tag_resource_id,
|
||||||
|
resource_tags.resource_uuid tag_resource_uuid,
|
||||||
|
resource_tags.resource_type tag_resource_type,
|
||||||
|
resource_tags.customer tag_customer,
|
||||||
|
async_job.id job_id,
|
||||||
|
async_job.uuid job_uuid,
|
||||||
|
async_job.job_status job_status,
|
||||||
|
async_job.account_id job_account_id,
|
||||||
|
affinity_group.id affinity_group_id,
|
||||||
|
affinity_group.uuid affinity_group_uuid,
|
||||||
|
affinity_group.name affinity_group_name,
|
||||||
|
affinity_group.description affinity_group_description,
|
||||||
|
vm_instance.dynamically_scalable dynamically_scalable
|
||||||
|
|
||||||
|
from
|
||||||
|
`cloud`.`user_vm`
|
||||||
|
inner join
|
||||||
|
`cloud`.`vm_instance` ON vm_instance.id = user_vm.id
|
||||||
|
and vm_instance.removed is NULL
|
||||||
|
inner join
|
||||||
|
`cloud`.`account` ON vm_instance.account_id = account.id
|
||||||
|
inner join
|
||||||
|
`cloud`.`domain` ON vm_instance.domain_id = domain.id
|
||||||
|
left join
|
||||||
|
`cloud`.`guest_os` ON vm_instance.guest_os_id = guest_os.id
|
||||||
|
left join
|
||||||
|
`cloud`.`host_pod_ref` ON vm_instance.pod_id = host_pod_ref.id
|
||||||
|
left join
|
||||||
|
`cloud`.`projects` ON projects.project_account_id = account.id
|
||||||
|
left join
|
||||||
|
`cloud`.`instance_group_vm_map` ON vm_instance.id = instance_group_vm_map.instance_id
|
||||||
|
left join
|
||||||
|
`cloud`.`instance_group` ON instance_group_vm_map.group_id = instance_group.id
|
||||||
|
left join
|
||||||
|
`cloud`.`data_center` ON vm_instance.data_center_id = data_center.id
|
||||||
|
left join
|
||||||
|
`cloud`.`host` ON vm_instance.host_id = host.id
|
||||||
|
left join
|
||||||
|
`cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id
|
||||||
|
left join
|
||||||
|
`cloud`.`vm_template` iso ON iso.id = user_vm.iso_id
|
||||||
|
left join
|
||||||
|
`cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id
|
||||||
|
left join
|
||||||
|
`cloud`.`disk_offering` svc_disk_offering ON vm_instance.service_offering_id = svc_disk_offering.id
|
||||||
|
left join
|
||||||
|
`cloud`.`disk_offering` ON vm_instance.disk_offering_id = disk_offering.id
|
||||||
|
left join
|
||||||
|
`cloud`.`volumes` ON vm_instance.id = volumes.instance_id
|
||||||
|
left join
|
||||||
|
`cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id
|
||||||
|
left join
|
||||||
|
`cloud`.`security_group_vm_map` ON vm_instance.id = security_group_vm_map.instance_id
|
||||||
|
left join
|
||||||
|
`cloud`.`security_group` ON security_group_vm_map.security_group_id = security_group.id
|
||||||
|
left join
|
||||||
|
`cloud`.`nics` ON vm_instance.id = nics.instance_id and nics.removed is null
|
||||||
|
left join
|
||||||
|
`cloud`.`networks` ON nics.network_id = networks.id
|
||||||
|
left join
|
||||||
|
`cloud`.`vpc` ON networks.vpc_id = vpc.id and vpc.removed is null
|
||||||
|
left join
|
||||||
|
`cloud`.`user_ip_address` ON user_ip_address.vm_id = vm_instance.id
|
||||||
|
left join
|
||||||
|
`cloud`.`user_vm_details` as ssh_details ON ssh_details.vm_id = vm_instance.id
|
||||||
|
and ssh_details.name = 'SSH.PublicKey'
|
||||||
|
left join
|
||||||
|
`cloud`.`ssh_keypairs` ON ssh_keypairs.public_key = ssh_details.value
|
||||||
|
left join
|
||||||
|
`cloud`.`resource_tags` ON resource_tags.resource_id = vm_instance.id
|
||||||
|
and resource_tags.resource_type = 'UserVm'
|
||||||
|
left join
|
||||||
|
`cloud`.`async_job` ON async_job.instance_id = vm_instance.id
|
||||||
|
and async_job.instance_type = 'VirtualMachine'
|
||||||
|
and async_job.job_status = 0
|
||||||
|
left join
|
||||||
|
`cloud`.`affinity_group_vm_map` ON vm_instance.id = affinity_group_vm_map.instance_id
|
||||||
|
left join
|
||||||
|
`cloud`.`affinity_group` ON affinity_group_vm_map.affinity_group_id = affinity_group.id
|
||||||
|
left join
|
||||||
|
`cloud`.`user_vm_details` `custom_cpu` ON (((`custom_cpu`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_cpu`.`name` = 'CpuNumber')))
|
||||||
|
left join
|
||||||
|
`cloud`.`user_vm_details` `custom_speed` ON (((`custom_speed`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_speed`.`name` = 'CpuSpeed')))
|
||||||
|
left join
|
||||||
|
`cloud`.`user_vm_details` `custom_ram_size` ON (((`custom_ram_size`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_ram_size`.`name` = 'memory')));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user