Updated Branches:
  refs/heads/rbac 7b358ec0d -> ad6af49f0

Populate acl_group_account_map for existing accounts.

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ad6af49f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ad6af49f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ad6af49f

Branch: refs/heads/rbac
Commit: ad6af49f0397ae56c1921b7c01a7841c2170a424
Parents: 7b358ec
Author: Min Chen <[email protected]>
Authored: Thu Sep 19 10:26:59 2013 -0700
Committer: Min Chen <[email protected]>
Committed: Thu Sep 19 10:26:59 2013 -0700

----------------------------------------------------------------------
 .../com/cloud/upgrade/dao/Upgrade420to430.java  | 49 ++++++++++++++++++++
 setup/db/db/schema-420to430.sql                 | 16 +++++--
 2 files changed, 60 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad6af49f/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to430.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to430.java 
b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to430.java
index ab82cc9..0ea88b6 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to430.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to430.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,52 @@ public class Upgrade420to430 implements DbUpgrade {
 
     @Override
     public void performDataMigration(Connection conn) {
+        populateACLGroupAccountMap(conn);
+    }
+
+    // populate acl_group_account_map table for existing accounts
+    private void populateACLGroupAccountMap(Connection conn) {
+        PreparedStatement acctInsert = null;
+        PreparedStatement acctQuery = null;
+        ResultSet rs = null;
+
+        s_logger.debug("Populating acl_group_account_map table for existing 
accounts...");
+        try {
+            acctInsert = conn
+                    .prepareStatement("INSERT INTO 
`cloud`.`acl_group_account_map` (group_id, account_id) values(?, ?)");
+            acctQuery = conn
+                    .prepareStatement("select id, type from `cloud`.`account` 
where removed is null");
+            rs = acctQuery.executeQuery();
+
+            while (rs.next()) {
+                Long acct_id = rs.getLong("id");
+                short type = rs.getShort("type");
+
+                // insert entry in acl_group_account_map table
+                acctInsert.setLong(1, type + 1);
+                acctInsert.setLong(2, acct_id);
+                acctInsert.executeUpdate();
+            }
+        } catch (SQLException e) {
+            String msg = "Unable to populate acl_group_account_map for 
existing accounts." + e.getMessage();
+            s_logger.error(msg);
+            throw new CloudRuntimeException(msg, e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+
+                if (acctInsert != null) {
+                    acctInsert.close();
+                }
+                if (acctQuery != null) {
+                    acctQuery.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+        s_logger.debug("Completed populate acl_group_account_map for existing 
accounts.");
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad6af49f/setup/db/db/schema-420to430.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-420to430.sql b/setup/db/db/schema-420to430.sql
index 5a8566f..fb09369 100644
--- a/setup/db/db/schema-420to430.sql
+++ b/setup/db/db/schema-420to430.sql
@@ -315,11 +315,17 @@ CREATE TABLE `cloud`.`acl_role` (
 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
 
 
-INSERT IGNORE INTO `cloud`.`acl_role` (name, uuid, created) VALUES ('NORMAL', 
UUID(), Now());
-INSERT IGNORE INTO `cloud`.`acl_role` (name, uuid, created) VALUES ('ADMIN', 
UUID(), Now());
-INSERT IGNORE INTO `cloud`.`acl_role` (name, uuid, created) VALUES 
('DOMAIN_ADMIN', UUID(), Now());
-INSERT IGNORE INTO `cloud`.`acl_role` (name, uuid, created) VALUES 
('RESOURCE_DOMAIN_ADMIN', UUID(), Now());
-INSERT IGNORE INTO `cloud`.`acl_role` (name, uuid, created) VALUES 
('READ_ONLY_ADMIN', UUID(), Now());
+INSERT IGNORE INTO `cloud`.`acl_role` (id, name, uuid, created) VALUES 
(1,'NORMAL', UUID(), Now());
+INSERT IGNORE INTO `cloud`.`acl_role` (id, name, uuid, created) VALUES (2, 
'ADMIN', UUID(), Now());
+INSERT IGNORE INTO `cloud`.`acl_role` (id, name, uuid, created) VALUES (3, 
'DOMAIN_ADMIN', UUID(), Now());
+INSERT IGNORE INTO `cloud`.`acl_role` (id, name, uuid, created) VALUES (4, 
'RESOURCE_DOMAIN_ADMIN', UUID(), Now());
+INSERT IGNORE INTO `cloud`.`acl_role` (id, name, uuid, created) VALUES (5, 
'READ_ONLY_ADMIN', UUID(), Now());
+
+INSERT IGNORE INTO `cloud`.`acl_group` (id, name, uuid, created) VALUES (1, 
'NORMAL', UUID(), Now());
+INSERT IGNORE INTO `cloud`.`acl_group` (id, name, uuid, created) VALUES (2, 
'ADMIN', UUID(), Now());
+INSERT IGNORE INTO `cloud`.`acl_group` (id, name, uuid, created) VALUES (3, 
'DOMAIN_ADMIN', UUID(), Now());
+INSERT IGNORE INTO `cloud`.`acl_group` (id, name, uuid, created) VALUES (4, 
'RESOURCE_DOMAIN_ADMIN', UUID(), Now());
+INSERT IGNORE INTO `cloud`.`acl_group` (id, name, uuid, created) VALUES (5, 
'READ_ONLY_ADMIN', UUID(), Now());
 
 CREATE TABLE `cloud`.`acl_api_permission` (
   `id` bigint unsigned NOT NULL UNIQUE auto_increment,

Reply via email to