You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2014/11/14 09:29:54 UTC
[1/2] git commit: updated refs/heads/useraccount-refactoring to
eb8fba3
Repository: cloudstack
Updated Branches:
refs/heads/useraccount-refactoring [created] eb8fba3e0
Upgrade450to460: Add user_id column in vm_instance
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/cb018b84
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/cb018b84
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/cb018b84
Branch: refs/heads/useraccount-refactoring
Commit: cb018b840b08a7c43586895c02d74f1209403d8a
Parents: 92d4a41
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Fri Nov 14 13:57:04 2014 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Fri Nov 14 13:57:04 2014 +0530
----------------------------------------------------------------------
.../com/cloud/upgrade/dao/Upgrade450to460.java | 39 ++++++++++++++++++++
setup/db/db/schema-450to460.sql | 4 +-
2 files changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cb018b84/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to460.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to460.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to460.java
index 990371c..a0fdb54 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");
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cb018b84/setup/db/db/schema-450to460.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-450to460.sql b/setup/db/db/schema-450to460.sql
index 8480c85..21a747d 100644
--- a/setup/db/db/schema-450to460.sql
+++ b/setup/db/db/schema-450to460.sql
@@ -19,4 +19,6 @@
-- Schema upgrade from 4.5.0 to 4.6.0
--
-INSERT IGNORE INTO `cloud`.`configuration` VALUES ("Advanced", 'DEFAULT', 'management-server', "stats.output.uri", "", "URI to additionally send StatsCollector statistics to", "", NULL, NULL, 0);
\ No newline at end of file
+INSERT IGNORE INTO `cloud`.`configuration` VALUES ("Advanced", 'DEFAULT', 'management-server', "stats.output.uri", "", "URI to additionally send StatsCollector statistics to", "", NULL, NULL, 0);
+
+ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `user_id` bigint unsigned NOT NULL COMMENT 'user id of VM deployer';
[2/2] git commit: updated refs/heads/useraccount-refactoring to
eb8fba3
Posted by bh...@apache.org.
DeployVMCmd: Add userid param to deployVM API
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/eb8fba3e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/eb8fba3e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/eb8fba3e
Branch: refs/heads/useraccount-refactoring
Commit: eb8fba3e06fd7c0e7ef32ea2e73a5c251565462b
Parents: cb018b8
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Fri Nov 14 13:58:17 2014 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Fri Nov 14 13:58:17 2014 +0530
----------------------------------------------------------------------
.../cloudstack/api/command/user/vm/DeployVMCmd.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb8fba3e/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
index bb7b13c..31ab27e 100755
--- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
@@ -54,6 +54,7 @@ import org.apache.cloudstack.api.response.ProjectResponse;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.TemplateResponse;
+import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.context.CallContext;
@@ -95,10 +96,14 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd {
@Parameter(name = ApiConstants.DISPLAY_NAME, type = CommandType.STRING, description = "an optional user generated name for the virtual machine")
private String displayName;
- //Owner information
+ //Owner account information
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an optional account for the virtual machine. Must be used with domainId.")
private String accountName;
+ //Owner userId
+ @Parameter(name = ApiConstants.USER_ID, type = CommandType.UUID, entityType = UserResponse.class, required = true, description = "the user ID of the owner, optional to use with account and domainId. If not provided logged in user's ID is used.")
+ private Long userId;
+
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "an optional domainId for the virtual machine. If the account parameter is used, domainId must also be used.")
private Long domainId;
@@ -200,6 +205,13 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd {
return accountName;
}
+ public Long getUserId() {
+ if (this.userId == null) {
+ return CallContext.current().getCallingUserId();
+ }
+ return userId;
+ }
+
public Long getDiskOfferingId() {
return diskOfferingId;
}