diff --git a/api/src/com/cloud/user/User.java b/api/src/com/cloud/user/User.java index 36e90284118..a2dcd1f43f8 100644 --- a/api/src/com/cloud/user/User.java +++ b/api/src/com/cloud/user/User.java @@ -22,6 +22,7 @@ import org.apache.cloudstack.api.InternalIdentity; public interface User extends OwnedBy, InternalIdentity { public static final long UID_SYSTEM = 1; + public static final long UID_ADMIN = 2; @Override public long getId(); diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java index 3d50fbe5551..6f206d270d6 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.List; +import org.apache.cloudstack.api.response.UserResponse; import org.apache.log4j.Logger; 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}) 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 /////////////////////// ///////////////////////////////////////////////////// @@ -145,6 +149,10 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd { return ids; } + public Long getUserId() { + return userId; + } + public String getName() { return name; } diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to460.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to460.java index 990371c0634..a0fdb54f756 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to460.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to460.java @@ -19,6 +19,9 @@ package com.cloud.upgrade.dao; import java.io.File; import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import org.apache.log4j.Logger; @@ -55,6 +58,42 @@ public class Upgrade450to460 implements DbUpgrade { @Override 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"); } diff --git a/engine/schema/src/com/cloud/vm/ConsoleProxyVO.java b/engine/schema/src/com/cloud/vm/ConsoleProxyVO.java index 670bc6ac0df..9d79193429b 100644 --- a/engine/schema/src/com/cloud/vm/ConsoleProxyVO.java +++ b/engine/schema/src/com/cloud/vm/ConsoleProxyVO.java @@ -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, - long accountId, int activeSession, boolean haEnabled) { - super(id, serviceOfferingId, name, name, Type.ConsoleProxy, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); + long accountId, long userId, int activeSession, boolean haEnabled) { + super(id, serviceOfferingId, name, name, Type.ConsoleProxy, templateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled); this.activeSession = activeSession; } diff --git a/engine/schema/src/com/cloud/vm/DomainRouterVO.java b/engine/schema/src/com/cloud/vm/DomainRouterVO.java index b7d9d8eb435..f08177cb605 100644 --- a/engine/schema/src/com/cloud/vm/DomainRouterVO.java +++ b/engine/schema/src/com/cloud/vm/DomainRouterVO.java @@ -76,9 +76,9 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { private Long vpcId; 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 vpcId) { - super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); + long accountId, long userId, boolean isRedundantRouter, int priority, boolean isPriorityBumpUp, RedundantState redundantState, boolean haEnabled, boolean stopPending, + Long vpcId) { + super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled); this.elementId = elementId; this.isRedundantRouter = isRedundantRouter; 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, - long accountId, boolean isRedundantRouter, int priority, boolean isPriorityBumpUp, RedundantState redundantState, boolean haEnabled, boolean stopPending, - VirtualMachine.Type vmType, Long vpcId) { - super(id, serviceOfferingId, name, name, vmType, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); + long accountId, long userId, boolean isRedundantRouter, int priority, boolean isPriorityBumpUp, RedundantState redundantState, boolean haEnabled, boolean stopPending, + Type vmType, Long vpcId) { + super(id, serviceOfferingId, name, name, vmType, templateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled); this.elementId = elementId; this.isRedundantRouter = isRedundantRouter; this.priority = priority; diff --git a/engine/schema/src/com/cloud/vm/SecondaryStorageVmVO.java b/engine/schema/src/com/cloud/vm/SecondaryStorageVmVO.java index 042ac83c7b4..98b17253a59 100644 --- a/engine/schema/src/com/cloud/vm/SecondaryStorageVmVO.java +++ b/engine/schema/src/com/cloud/vm/SecondaryStorageVmVO.java @@ -64,8 +64,8 @@ public class SecondaryStorageVmVO extends VMInstanceVO implements SecondaryStora private Date lastUpdateTime; public SecondaryStorageVmVO(long id, long serviceOfferingId, String name, long templateId, HypervisorType hypervisorType, long guestOSId, long dataCenterId, - long domainId, long accountId, Role role, boolean haEnabled) { - super(id, serviceOfferingId, name, name, Type.SecondaryStorageVm, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); + long domainId, long accountId, long userId, Role role, boolean haEnabled) { + super(id, serviceOfferingId, name, name, Type.SecondaryStorageVm, templateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled); this.role = role; } diff --git a/engine/schema/src/com/cloud/vm/UserVmVO.java b/engine/schema/src/com/cloud/vm/UserVmVO.java index 81308afc75e..f6740f84c9a 100644 --- a/engine/schema/src/com/cloud/vm/UserVmVO.java +++ b/engine/schema/src/com/cloud/vm/UserVmVO.java @@ -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, - boolean limitCpuUse, long domainId, long accountId, long serviceOfferingId, String userData, String name, Long diskOfferingId) { - super(id, serviceOfferingId, name, instanceName, Type.User, templateId, hypervisorType, guestOsId, domainId, accountId, haEnabled, limitCpuUse, 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, userId, haEnabled, limitCpuUse, diskOfferingId); this.userData = userData; this.displayName = displayName; this.details = new HashMap(); diff --git a/engine/schema/src/com/cloud/vm/VMInstanceVO.java b/engine/schema/src/com/cloud/vm/VMInstanceVO.java index d542f332370..8f42a4307db 100644 --- a/engine/schema/src/com/cloud/vm/VMInstanceVO.java +++ b/engine/schema/src/com/cloud/vm/VMInstanceVO.java @@ -141,6 +141,9 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject - + + + + + diff --git a/plugins/network-elements/internal-loadbalancer/test/resources/lb_svc.xml b/plugins/network-elements/internal-loadbalancer/test/resources/lb_svc.xml index fa822f35302..73054f593a1 100644 --- a/plugins/network-elements/internal-loadbalancer/test/resources/lb_svc.xml +++ b/plugins/network-elements/internal-loadbalancer/test/resources/lb_svc.xml @@ -40,6 +40,10 @@ + + + + diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java index f34eaccbb06..1927a70a87e 100644 --- a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java +++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java @@ -109,9 +109,15 @@ public class ServiceManagerImpl implements ServiceManager { networks.put((NetworkVO)left, new ArrayList()); networks.put((NetworkVO)right, new ArrayList()); 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 = 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. Map kvmap = new HashMap(); diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceVirtualMachine.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceVirtualMachine.java index 8985bc1bf32..676afc9ae8a 100644 --- a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceVirtualMachine.java +++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceVirtualMachine.java @@ -22,7 +22,7 @@ import com.cloud.vm.UserVmVO; public class ServiceVirtualMachine extends UserVmVO { public ServiceVirtualMachine(long id, String instanceName, String name, long templateId, long serviceOfferingId, HypervisorType hypervisorType, long guestOSId, - long dataCenterId, long domainId, long accountId, boolean haEnabled) { - super(id, instanceName, name, templateId, hypervisorType, guestOSId, false, false, domainId, accountId, serviceOfferingId, null, name, null); + long dataCenterId, long domainId, long accountId, long userId, boolean haEnabled) { + super(id, instanceName, name, templateId, hypervisorType, guestOSId, false, false, domainId, accountId, userId, serviceOfferingId, null, name, null); } } diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java index 50419ea1b36..3dfcc0f93aa 100644 --- a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java +++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java @@ -239,7 +239,7 @@ public class ManagementServerMock { long id = _userVmDao.getNextInSequence(Long.class, "id"); UserVmVO vm = 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.setHostId(_hostId); vm.setDataCenterId(network.getDataCenterId()); diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index a90be504c83..12092eef48f 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -780,6 +780,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { boolean listAll = cmd.listAll(); Long id = cmd.getId(); + Long userId = cmd.getUserId(); Map tags = cmd.getTags(); Boolean display = cmd.getDisplay(); Ternary domainIdRecursiveListProject = new Ternary( @@ -871,6 +872,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.and("instanceGroupId", sb.entity().getInstanceGroupId(), SearchCriteria.Op.EQ); } + if (userId != null) { + sb.and("userId", sb.entity().getUserId(), SearchCriteria.Op.EQ); + } + if (networkId != null) { sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ); } @@ -946,6 +951,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.setParameters("isoId", isoId); } + if (userId != null) { + sc.setParameters("userId", userId); + } + if (networkId != null) { sc.setParameters("networkId", networkId); } diff --git a/server/src/com/cloud/api/query/vo/UserVmJoinVO.java b/server/src/com/cloud/api/query/vo/UserVmJoinVO.java index ac9284c8edb..633d01b6f47 100644 --- a/server/src/com/cloud/api/query/vo/UserVmJoinVO.java +++ b/server/src/com/cloud/api/query/vo/UserVmJoinVO.java @@ -52,6 +52,9 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity { @Column(name = "display_name", updatable = false, nullable = false, length = 255) private String displayName = null; + @Column(name = "user_id") + private long userId; + @Column(name = "account_id") private long accountId; @@ -439,6 +442,10 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity { return displayName; } + public long getUserId() { + return userId; + } + @Override public long getAccountId() { return accountId; diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index bb64fa3a12c..0851a686dc5 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -715,7 +715,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy ConsoleProxyVO proxy = 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 = _consoleProxyDao.persist(proxy); try { diff --git a/server/src/com/cloud/network/router/NetworkHelperImpl.java b/server/src/com/cloud/network/router/NetworkHelperImpl.java index eb6a609efe5..2cec4c8a475 100644 --- a/server/src/com/cloud/network/router/NetworkHelperImpl.java +++ b/server/src/com/cloud/network/router/NetworkHelperImpl.java @@ -28,6 +28,8 @@ import javax.annotation.PostConstruct; import javax.ejb.Local; 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.framework.config.ConfigKey; import org.apache.log4j.Logger; @@ -146,6 +148,8 @@ public class NetworkHelperImpl implements NetworkHelper { private RouterControlHelper _routerControlHelper; @Inject protected NetworkOrchestrationService _networkMgr; + @Inject + private UserDao _userDao; protected final Map> hypervisorsMap = new HashMap<>(); @@ -513,9 +517,14 @@ public class NetworkHelperImpl implements NetworkHelper { // VPC because it is not a VPC offering. 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, 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.setRole(Role.VIRTUAL_ROUTER); diff --git a/server/src/com/cloud/network/security/SecurityManagerMBeanImpl.java b/server/src/com/cloud/network/security/SecurityManagerMBeanImpl.java index 4c64fca62c1..7b768ab9332 100644 --- a/server/src/com/cloud/network/security/SecurityManagerMBeanImpl.java +++ b/server/src/com/cloud/network/security/SecurityManagerMBeanImpl.java @@ -128,7 +128,7 @@ public class SecurityManagerMBeanImpl extends StandardMBean implements SecurityG @Override public void simulateVmStart(Long 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); } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 170c612a7de..e81dd2b8393 100644 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2969,7 +2969,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir 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); // Assign instance to the group @@ -3027,14 +3032,14 @@ 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, - 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 networkNicMap, - final long id, final String instanceName, final String uuidName, final HypervisorType hypervisorType, final Map customParameters) throws InsufficientCapacityException { + final Long diskOfferingId, final Long diskSize, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard, + final long accountId, final long userId, final ServiceOfferingVO offering, final boolean isIso, final String sshPublicKey, final LinkedHashMap networkNicMap, + final long id, final String instanceName, final String uuidName, final HypervisorType hypervisorType, final Map customParameters) throws InsufficientCapacityException { return Transaction.execute(new TransactionCallbackWithException() { @Override public UserVmVO doInTransaction(TransactionStatus status) throws InsufficientCapacityException { 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.setDynamicallyScalable(template.isDynamicallyScalable()); diff --git a/server/test/com/cloud/network/element/VirtualRouterElementTest.java b/server/test/com/cloud/network/element/VirtualRouterElementTest.java index f1d9ce0e64f..f2403caf8c7 100644 --- a/server/test/com/cloud/network/element/VirtualRouterElementTest.java +++ b/server/test/com/cloud/network/element/VirtualRouterElementTest.java @@ -285,6 +285,7 @@ public class VirtualRouterElementTest { /* guestOSId */ 0L, /* domainId */ 0L, /* accountId */ 1L, + /* userId */ 1L, /* isRedundantRouter */ false, /* priority */ 0, /* isPriorityBumpUp */ false, diff --git a/server/test/com/cloud/storage/VolumeApiServiceImplTest.java b/server/test/com/cloud/storage/VolumeApiServiceImplTest.java index c60aa503451..07860597311 100644 --- a/server/test/com/cloud/storage/VolumeApiServiceImplTest.java +++ b/server/test/com/cloud/storage/VolumeApiServiceImplTest.java @@ -122,7 +122,7 @@ public class VolumeApiServiceImplTest { when(_svc._volsDao.findById(1L)).thenReturn(volumeOfRunningVm); 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.setDataCenterId(1L); when(_svc._userVmDao.findById(1L)).thenReturn(runningVm); @@ -134,7 +134,7 @@ public class VolumeApiServiceImplTest { when(_svc._volsDao.findById(2L)).thenReturn(volumeOfStoppedVm); 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.setDataCenterId(1L); when(_svc._userVmDao.findById(2L)).thenReturn(stoppedVm); @@ -142,7 +142,7 @@ public class VolumeApiServiceImplTest { // volume of hyperV vm id=3 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.setDataCenterId(1L); when(_svc._userVmDao.findById(3L)).thenReturn(hyperVVm); @@ -199,7 +199,7 @@ public class VolumeApiServiceImplTest { // vm having root volume 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.setDataCenterId(1L); when(_svc._userVmDao.findById(4L)).thenReturn(vmHavingRootVolume); diff --git a/server/test/com/cloud/vm/UserVmManagerTest.java b/server/test/com/cloud/vm/UserVmManagerTest.java index d86e55ee49b..af76d17e070 100644 --- a/server/test/com/cloud/vm/UserVmManagerTest.java +++ b/server/test/com/cloud/vm/UserVmManagerTest.java @@ -625,7 +625,7 @@ public class UserVmManagerTest { Account oldAccount = new AccountVO("testaccount", 1, "networkdomain", (short)0, 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); when(_vmDao.findById(anyLong())).thenReturn(vm); diff --git a/server/test/com/cloud/vm/dao/UserVmDaoImplTest.java b/server/test/com/cloud/vm/dao/UserVmDaoImplTest.java index b46ac7d4930..49de99ad803 100644 --- a/server/test/com/cloud/vm/dao/UserVmDaoImplTest.java +++ b/server/test/com/cloud/vm/dao/UserVmDaoImplTest.java @@ -47,7 +47,7 @@ public class UserVmDaoImplTest extends TestCase { // Persist the data. 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); dao.persist(vo); diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java index 7bfe3519740..b12dbaa7ced 100644 --- a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java +++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java @@ -203,7 +203,7 @@ public class AffinityApiUnitTest { @Test(expected = InvalidParameterValueException.class) 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); when(_vmDao.findById(10L)).thenReturn(vm); diff --git a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java index f9a343ade13..8d4454f270a 100644 --- a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java +++ b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java @@ -575,7 +575,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar SecondaryStorageVmVO secStorageVm = 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 = _secStorageVmDao.persist(secStorageVm); try { diff --git a/setup/db/db/schema-450to460.sql b/setup/db/db/schema-450to460.sql index 95d6532c1a2..4a5ea936228 100644 --- a/setup/db/db/schema-450to460.sql +++ b/setup/db/db/schema-450to460.sql @@ -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.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')));