Permalink
Browse files

Merge branch 'maint/3.2/testing' into testing

Conflicts:
	console/eucaconsole/botojsonencoder.py
	console/static/js/dashboard.js
	console/static/js/instance.js
  • Loading branch information...
2 parents 2fc28d6 + 9a0f326 commit df6edd6eef75eb40692053e3ff8673b8e719ff52 @mspaulding06 mspaulding06 committed Feb 26, 2013
@@ -67,9 +67,11 @@ public void createOrUpdateAccount(String id, String name)
return;
} else if (oldAccount!=null) {
updateInDb(account);
+ ReportingAccountDao.getInstance().putCache(account);
} else {
try {
addToDb(account);
+ ReportingAccountDao.getInstance().putCache(account);
} catch (RuntimeException e) {
LOG.error(e);
}
@@ -19,63 +19,77 @@
************************************************************************/
package com.eucalyptus.reporting.domain;
-import java.util.List;
-
-import javax.persistence.EntityTransaction;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.log4j.Logger;
-import com.eucalyptus.entities.Entities;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
+import com.eucalyptus.entities.EntityWrapper;
/**
- * <p>
- * ReportingAccountDao is an object for reading ReportingAccount objects from
- * the database.
+ * <p>ReportingAccountDao is an object for reading ReportingAccount objects from the
+ * database.
*/
-public class ReportingAccountDao {
- private static Logger LOG = Logger.getLogger(ReportingAccountDao.class);
-
- private static ReportingAccountDao instance = null;
+public class ReportingAccountDao
+{
+ private static Logger LOG = Logger.getLogger( ReportingAccountDao.class );
- public static ReportingAccountDao getInstance() {
- if (instance == null) {
- instance = new ReportingAccountDao();
+ private static ReportingAccountDao instance = null;
+
+ public static synchronized ReportingAccountDao getInstance()
+ {
+ if (instance == null) {
+ instance = new ReportingAccountDao();
+ instance.loadFromDb();
+ }
+ return instance;
}
- return instance;
- }
-
- private ReportingAccountDao() {}
-
- public ReportingAccount getReportingAccount(String accountId) {
+
+ private final Map<String,ReportingAccount> accounts =
+ new ConcurrentHashMap<String,ReportingAccount>();
- ReportingAccount searchAccount = new ReportingAccount();
- searchAccount.setId(accountId);
- List<ReportingAccount> foundAccountList = Lists.newArrayList();
+ private ReportingAccountDao()
+ {
+
+ }
- EntityTransaction db = Entities.get(ReportingAccount.class);
- try {
+ public ReportingAccount getReportingAccount(String accountId)
+ {
+ return accounts.get(accountId);
+ }
+
+ private void loadFromDb()
+ {
+ LOG.debug("Load accounts from db");
+
+ EntityWrapper<ReportingAccount> entityWrapper =
+ EntityWrapper.get(ReportingAccount.class);
- foundAccountList = (List<ReportingAccount>) Entities.query(
- searchAccount, true);
+ try {
+ @SuppressWarnings("rawtypes")
+ List reportingAccounts = (List)
+ entityWrapper.createQuery("from ReportingAccount")
+ .list();
- db.commit();
- } catch (Exception ex) {
- LOG.error(ex, ex);
- foundAccountList.clear();
- } finally {
- if (db.isActive())
- db.rollback();
+ for (Object obj: reportingAccounts) {
+ ReportingAccount account = (ReportingAccount) obj;
+ accounts.put(account.getId(), account);
+ LOG.debug("load account from db, id:" + account.getId() + " name:" + account.getName());
+ }
+
+ entityWrapper.commit();
+ } catch (Exception ex) {
+ LOG.error(ex);
+ entityWrapper.rollback();
+ throw new RuntimeException(ex);
+ }
}
-
- if (foundAccountList.isEmpty()) {
- return null;
+
+ void putCache(ReportingAccount account)
+ {
+ accounts.put(account.getId(), account);
}
- Iterables.removeIf(foundAccountList, Predicates.isNull());
- return foundAccountList.get(0);
- }
}
+
@@ -67,9 +67,11 @@ public void createOrUpdateUser(String id, String accountId, String name)
return;
} else if (oldUser!=null) {
updateInDb(id, name);
+ ReportingUserDao.getInstance().putCache(user);
} else {
try {
addToDb(id, accountId, name);
+ ReportingUserDao.getInstance().putCache(user);
} catch (RuntimeException e) {
LOG.error(e);
}
@@ -19,77 +19,85 @@
************************************************************************/
package com.eucalyptus.reporting.domain;
-import java.util.List;
-
-import javax.persistence.EntityTransaction;
+import java.util.*;
import org.apache.log4j.Logger;
-import com.eucalyptus.entities.Entities;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
+import com.eucalyptus.entities.EntityWrapper;
/**
- * <p>
- * ReportingUserDao is an object for reading ReportingUser objects from the
+ * <p>ReportingUserDao is an object for reading ReportingUser objects from the
* database.
*/
-public class ReportingUserDao {
- private static Logger LOG = Logger.getLogger(ReportingUserDao.class);
-
- private static ReportingUserDao instance = null;
+public class ReportingUserDao
+{
+ private static Logger LOG = Logger.getLogger( ReportingUserDao.class );
- public static ReportingUserDao getInstance() {
- if (instance == null) {
- instance = new ReportingUserDao();
+ private static ReportingUserDao instance = null;
+
+ public static synchronized ReportingUserDao getInstance()
+ {
+ if (instance == null) {
+ instance = new ReportingUserDao();
+ instance.loadFromDb();
+ }
+ return instance;
+ }
+
+ private ReportingUserDao()
+ {
+
}
- return instance;
- }
- private ReportingUserDao() {
- }
+ private final Map<String,ReportingUser> users = new HashMap<String,ReportingUser>();
- public ReportingUser getReportingUser(String userId) {
- ReportingUser searchUser = new ReportingUser();
- searchUser.setId(userId);
- try {
- return searchReportingUser(searchUser).get(0);
- } catch (Exception ex) {
- LOG.debug(ex, ex);
- return null;
+ public ReportingUser getReportingUser(String userId)
+ {
+ return users.get(userId);
+ }
+
+ public List<ReportingUser> getReportingUsersByAccount(String accountId)
+ {
+ List<ReportingUser> rv = new ArrayList<ReportingUser>();
+ for (ReportingUser user: users.values()) {
+ if (user.getAccountId().equals(accountId)) {
+ rv.add(user);
+ }
+ }
+ return rv;
}
- }
+
+ private void loadFromDb()
+ {
+ LOG.debug("Load users from db");
- public List<ReportingUser> getReportingUsersByAccount(String accountId) {
- ReportingUser searchUser = new ReportingUser();
- searchUser.setAccountId(accountId);
- return searchReportingUser(searchUser);
- }
+ EntityWrapper<ReportingUser> entityWrapper =
+ EntityWrapper.get(ReportingUser.class);
- private List<ReportingUser> searchReportingUser(
- final ReportingUser searchUser) {
+ try {
+ @SuppressWarnings("rawtypes")
+ List reportingUsers = (List)
+ entityWrapper.createQuery("from ReportingUser")
+ .list();
- List<ReportingUser> reportingUserList = Lists.newArrayList();
- EntityTransaction db = Entities.get(ReportingUser.class);
+ for (Object obj: reportingUsers) {
+ ReportingUser user = (ReportingUser) obj;
+ users.put(user.getId(), user);
+ LOG.debug("load user from db, id:" + user.getId() + " name:" + user.getName());
+ }
- try {
- reportingUserList = (List<ReportingUser>) Entities.query(
- searchUser, true);
- db.commit();
- } catch (Exception ex) {
- LOG.error(ex, ex);
- reportingUserList.clear();
- } finally {
- if (db.isActive())
- db.rollback();
+ entityWrapper.commit();
+ } catch (Exception ex) {
+ LOG.error(ex);
+ entityWrapper.rollback();
+ throw new RuntimeException(ex);
+ }
}
-
- Iterables.removeIf(reportingUserList, Predicates.isNull());
- if (!reportingUserList.isEmpty()) {
- return reportingUserList;
- } else {
- return null;
+
+ void putCache(ReportingUser user)
+ {
+ users.put(user.getId(), user);
}
- }
+
}
+
@@ -333,12 +333,8 @@ public void configure() throws EucalyptusCloudException {
}
public void startupChecks() {
- /* zhill: removed because now we only export volumes on 'attach', so no reload needed.
- * It is assumed that if the service goes down the exports are unaffected. If a reboot
- * of the machine is done then it is admin responsibility to ensure that volumes are
- * detached.
- */
- //reload();
+ //Reload the volumes that were exported on last shutdown (of the service)
+ reload();
}
private void checkVolumesDir() {
@@ -1004,51 +1000,71 @@ public void loadSnapshots(List<String> snapshotSet, List<String> snapshotFileNam
/**
* Called on service start to load and export any volumes that should be available to clients immediately.
- * This is a legacy call from the old OverlayManager that always exported volumes on creation rather than
- * attach.
+ * Bases that decision on the lodevName field in the DB.
*
- * TODO: For the new version, don't export volumes unless they were in an exported state when the service terminated
- * and are not exported currently. (i.e. machine reboot)
- * TODO: this is currently *NOT* called during startup.
*/
public void reload() {
+ LOG.info("Initiating SC Reload of iSCSI targets");
VolumeEntityWrapperManager volumeManager = new VolumeEntityWrapperManager();
List<LVMVolumeInfo> volumeInfos = volumeManager.getAllVolumeInfos();
+ LOG.info("SC Reload found " + volumeInfos.size() + " volumes in the DB");
+
+ //Ensure that all loopbacks are properly setup.
for(LVMVolumeInfo foundVolumeInfo : volumeInfos) {
String loDevName = foundVolumeInfo.getLoDevName();
if(loDevName != null) {
String loFileName = foundVolumeInfo.getVolumeId();
+ LOG.info("SC Reload: found volume " + loFileName + " was exported at last shutdown. Ensuring export restored");
String absoluteLoFileName = DirectStorageInfo.getStorageInfo().getVolumesDir() + PATH_SEPARATOR + loFileName;
if(!new File(absoluteLoFileName).exists()) {
- LOG.error("Backing volume: " + absoluteLoFileName + " not found. Invalidating volume.");
+ LOG.error("SC Reload: Backing volume: " + absoluteLoFileName + " not found. Invalidating volume.");
foundVolumeInfo.setStatus(StorageProperties.Status.failed.toString());
continue;
}
try {
+ //Ensure the loopback isn't used
String returnValue = getLoopback(loDevName);
if(returnValue.length() <= 0) {
+ LOG.info("SC Reload: volume " + loFileName + " previously used loopback " + loDevName + ". No conflict detected, reusing same loopback");
createLoopback(absoluteLoFileName, loDevName);
+ } else {
+ if(!returnValue.contains(loFileName)) {
+ //Use a new loopback since the old one is used by something else
+ String newLoDev = createLoopback(absoluteLoFileName);
+ foundVolumeInfo.setLoDevName(newLoDev);
+ LOG.info("SC Reload: volume " + loFileName + " previously used loopback " + loDevName + ", but loopback already in used by something else. Using new loopback: " + newLoDev);
+ } else {
+ LOG.info("SC Reload: Detection of loopback for volume " + loFileName + " got " + returnValue + ". Appears that loopback is already in-place. No losetup needed for this volume.");
+ }
}
} catch(EucalyptusCloudException ex) {
String error = "Unable to run command: " + ex.getMessage();
LOG.error(error);
}
}
}
+
//now enable them
try {
- LOG.info("Scanning volume groups. This might take a little while...");
+ LOG.info("SC Reload: Scanning volume groups. This might take a little while...");
scanVolumeGroups();
} catch (EucalyptusCloudException e) {
LOG.error(e);
}
+
+ //Export volumes
+ LOG.info("SC Reload: ensuring configured volumes are exported via iSCSI targets");
for(LVMVolumeInfo foundVolumeInfo : volumeInfos) {
try {
- if (foundVolumeInfo.getVgName() != null) {
+ //Only try to export volumes that have both a lodev and a vgname
+ if (foundVolumeInfo.getLoDevName() != null && foundVolumeInfo.getVgName() != null) {
+ LOG.info("SC Reload: exporting " + foundVolumeInfo.getVolumeId() + " in VG: " + foundVolumeInfo.getVgName());
volumeManager.exportVolume(foundVolumeInfo);
+ } else {
+ LOG.info("SC Reload: no loopback configured for " + foundVolumeInfo.getVolumeId() + ". Skipping export for this volume.");
}
} catch(EucalyptusCloudException ex) {
- LOG.error("Unable to reload volume: " + foundVolumeInfo.getVolumeId() + ex);
+ LOG.error("SC Reload: Unable to reload volume: " + foundVolumeInfo.getVolumeId() + ex.getMessage());
}
}
volumeManager.finish();
@@ -43,7 +43,7 @@ def waitForState (client, instanceid, state):
if __name__ == "__main__":
# make some calls to proxy class to test things out
client = UIProxyClient()
- client.login('localhost', '8888', 'testuser1', 'admin', 'euca123')
+ client.login('localhost', '8888', 'ui-test-acct-03', 'admin', 'mypassword6')
print
print "=== listing images ==="
print

0 comments on commit df6edd6

Please sign in to comment.