You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/01/10 23:47:19 UTC

[24/25] Keep removing

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f922c6fc/server/src/com/cloud/storage/s3/S3ManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/s3/S3ManagerImpl.java b/server/src/com/cloud/storage/s3/S3ManagerImpl.java
index 8a1354c..62db0bb 100644
--- a/server/src/com/cloud/storage/s3/S3ManagerImpl.java
+++ b/server/src/com/cloud/storage/s3/S3ManagerImpl.java
@@ -42,10 +42,13 @@ import java.util.UUID;
 import java.util.concurrent.Callable;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd;
+import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd;
 import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
@@ -53,9 +56,6 @@ import com.cloud.agent.api.DeleteTemplateFromS3Command;
 import com.cloud.agent.api.DownloadTemplateFromS3ToSecondaryStorageCommand;
 import com.cloud.agent.api.UploadTemplateToS3FromSecondaryStorageCommand;
 import com.cloud.agent.api.to.S3TO;
-import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd;
-import org.springframework.stereotype.Component;
-
 import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.DataCenterVO;
@@ -77,7 +77,6 @@ import com.cloud.storage.dao.VMTemplateS3Dao;
 import com.cloud.storage.dao.VMTemplateZoneDao;
 import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.utils.S3Utils.ClientOptions;
-
 import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.exception.CloudRuntimeException;
@@ -90,7 +89,7 @@ public class S3ManagerImpl implements S3Manager {
 
     private String name;
 
-    @Inject
+    @Inject 
     private AgentManager agentManager;
 
     @Inject
@@ -288,32 +287,32 @@ public class S3ManagerImpl implements S3Manager {
             executeWithNoWaitLock(determineLockId(accountId, templateId),
                     new Callable<Void>() {
 
-                        @Override
-                        public Void call() throws Exception {
-
-                            final Answer answer = agentManager.sendToSSVM(null,
-                                    new DeleteTemplateFromS3Command(s3,
-                                            accountId, templateId));
-                            if (answer == null || !answer.getResult()) {
-                                final String errorMessage = format(
-                                        "Delete Template Failed: Unable to delete template id %1$s from S3 due to following error: %2$s",
-                                        templateId,
-                                        ((answer == null) ? "answer is null"
-                                                : answer.getDetails()));
-                                LOGGER.error(errorMessage);
-                                throw new CloudRuntimeException(errorMessage);
-                            }
-
-                            vmTemplateS3Dao.remove(vmTemplateS3VO.getId());
-                            LOGGER.debug(format(
-                                    "Deleted template %1$s from S3.",
-                                    templateId));
+                @Override
+                public Void call() throws Exception {
+
+                    final Answer answer = agentManager.sendToSSVM(null,
+                            new DeleteTemplateFromS3Command(s3,
+                                    accountId, templateId));
+                    if (answer == null || !answer.getResult()) {
+                        final String errorMessage = format(
+                                "Delete Template Failed: Unable to delete template id %1$s from S3 due to following error: %2$s",
+                                templateId,
+                                ((answer == null) ? "answer is null"
+                                        : answer.getDetails()));
+                        LOGGER.error(errorMessage);
+                        throw new CloudRuntimeException(errorMessage);
+                    }
+
+                    vmTemplateS3Dao.remove(vmTemplateS3VO.getId());
+                    LOGGER.debug(format(
+                            "Deleted template %1$s from S3.",
+                            templateId));
 
-                            return null;
+                    return null;
 
-                        }
+                }
 
-                    });
+            });
 
         } catch (Exception e) {
 
@@ -384,38 +383,38 @@ public class S3ManagerImpl implements S3Manager {
             executeWithNoWaitLock(determineLockId(accountId, templateId),
                     new Callable<Void>() {
 
-                        @Override
-                        public Void call() throws Exception {
-
-                            final Answer answer = agentManager.sendToSSVM(
-                                    dataCenterId, cmd);
+                @Override
+                public Void call() throws Exception {
 
-                            if (answer == null || !answer.getResult()) {
-                                final String errMsg = String
-                                        .format("Failed to download template from S3 to secondary storage due to %1$s",
-                                                (answer == null ? "answer is null"
-                                                        : answer.getDetails()));
-                                LOGGER.error(errMsg);
-                                throw new CloudRuntimeException(errMsg);
-                            }
+                    final Answer answer = agentManager.sendToSSVM(
+                            dataCenterId, cmd);
 
-                            final String installPath = join(
-                                    asList("template", "tmpl", accountId,
-                                            templateId), File.separator);
-                            final VMTemplateHostVO tmpltHost = new VMTemplateHostVO(
-                                    secondaryStorageHost.getId(), templateId,
-                                    now(), 100, Status.DOWNLOADED, null, null,
-                                    null, installPath, template.getUrl());
-                            tmpltHost.setSize(templateS3VO.getSize());
-                            tmpltHost.setPhysicalSize(templateS3VO
-                                    .getPhysicalSize());
-                            vmTemplateHostDao.persist(tmpltHost);
-
-                            return null;
+                    if (answer == null || !answer.getResult()) {
+                        final String errMsg = String
+                                .format("Failed to download template from S3 to secondary storage due to %1$s",
+                                        (answer == null ? "answer is null"
+                                                : answer.getDetails()));
+                        LOGGER.error(errMsg);
+                        throw new CloudRuntimeException(errMsg);
+                    }
+
+                    final String installPath = join(
+                            asList("template", "tmpl", accountId,
+                                    templateId), File.separator);
+                    final VMTemplateHostVO tmpltHost = new VMTemplateHostVO(
+                            secondaryStorageHost.getId(), templateId,
+                            now(), 100, Status.DOWNLOADED, null, null,
+                            null, installPath, template.getUrl());
+                    tmpltHost.setSize(templateS3VO.getSize());
+                    tmpltHost.setPhysicalSize(templateS3VO
+                            .getPhysicalSize());
+                    vmTemplateHostDao.persist(tmpltHost);
+
+                    return null;
 
-                        }
+                }
 
-                    });
+            });
 
         } catch (Exception e) {
             final String errMsg = "Failed to download template from S3 to secondary storage due to "
@@ -608,50 +607,50 @@ public class S3ManagerImpl implements S3Manager {
             executeWithNoWaitLock(determineLockId(accountId, templateId),
                     new Callable<Void>() {
 
-                        @Override
-                        public Void call() throws Exception {
+                @Override
+                public Void call() throws Exception {
 
-                            final UploadTemplateToS3FromSecondaryStorageCommand cmd = new UploadTemplateToS3FromSecondaryStorageCommand(
-                                    s3, secondaryHost.getStorageUrl(),
-                                    dataCenterId, accountId, templateId);
+                    final UploadTemplateToS3FromSecondaryStorageCommand cmd = new UploadTemplateToS3FromSecondaryStorageCommand(
+                            s3, secondaryHost.getStorageUrl(),
+                            dataCenterId, accountId, templateId);
 
-                            final Answer answer = agentManager.sendToSSVM(
-                                    dataCenterId, cmd);
-                            if (answer == null || !answer.getResult()) {
+                    final Answer answer = agentManager.sendToSSVM(
+                            dataCenterId, cmd);
+                    if (answer == null || !answer.getResult()) {
 
-                                final String reason = answer != null ? answer
-                                        .getDetails()
-                                        : "S3 template sync failed due to an unspecified error.";
+                        final String reason = answer != null ? answer
+                                .getDetails()
+                                : "S3 template sync failed due to an unspecified error.";
                                 throw new CloudRuntimeException(
                                         format("Failed to upload template id %1$s to S3 from secondary storage due to %2$s.",
                                                 templateId, reason));
 
-                            }
+                    }
 
-                            if (LOGGER.isDebugEnabled()) {
-                                LOGGER.debug(format(
-                                        "Creating VMTemplateS3VO instance using template id %1s.",
-                                        templateId));
-                            }
+                    if (LOGGER.isDebugEnabled()) {
+                        LOGGER.debug(format(
+                                "Creating VMTemplateS3VO instance using template id %1s.",
+                                templateId));
+                    }
 
-                            final VMTemplateS3VO vmTemplateS3VO = new VMTemplateS3VO(
-                                    s3.getId(), templateId, now(),
-                                    templateHostRef.getSize(), templateHostRef
-                                            .getPhysicalSize());
+                    final VMTemplateS3VO vmTemplateS3VO = new VMTemplateS3VO(
+                            s3.getId(), templateId, now(),
+                            templateHostRef.getSize(), templateHostRef
+                            .getPhysicalSize());
 
-                            if (LOGGER.isDebugEnabled()) {
-                                LOGGER.debug(format("Persisting %1$s",
-                                        vmTemplateS3VO));
-                            }
+                    if (LOGGER.isDebugEnabled()) {
+                        LOGGER.debug(format("Persisting %1$s",
+                                vmTemplateS3VO));
+                    }
 
-                            vmTemplateS3Dao.persist(vmTemplateS3VO);
-                            propagateTemplateToAllZones(vmTemplateS3VO);
+                    vmTemplateS3Dao.persist(vmTemplateS3VO);
+                    propagateTemplateToAllZones(vmTemplateS3VO);
 
-                            return null;
+                    return null;
 
-                        }
+                }
 
-                    });
+            });
 
         } catch (Exception e) {
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f922c6fc/usage/src/com/cloud/usage/UsageServer.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/UsageServer.java b/usage/src/com/cloud/usage/UsageServer.java
index aedbe76..5fe46e6 100644
--- a/usage/src/com/cloud/usage/UsageServer.java
+++ b/usage/src/com/cloud/usage/UsageServer.java
@@ -38,8 +38,7 @@ public class UsageServer {
     }
 
     public void start() {
-        final ComponentLocator _locator = ComponentLocator.getLocator(UsageServer.Name, "usage-components.xml", "log4j-cloud_usage");
-        UsageManager mgr = _locator.getManager(UsageManager.class);
+        UsageManager mgr = new UsageManager();
         if (mgr != null) {
             if (s_logger.isInfoEnabled()) {
                 s_logger.info("UsageServer ready...");

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f922c6fc/utils/test/com/cloud/utils/db/TransactionTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/db/TransactionTest.java b/utils/test/com/cloud/utils/db/TransactionTest.java
index 5bd1e9a..b952be2 100644
--- a/utils/test/com/cloud/utils/db/TransactionTest.java
+++ b/utils/test/com/cloud/utils/db/TransactionTest.java
@@ -26,7 +26,7 @@ import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.exception.CloudRuntimeException;
 
 /**
@@ -34,7 +34,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
  * all its testcases to set up a test db table, and then tear down these test db artifacts after all testcases are run.
  * 
  * @author Min Chen
- *
+ * 
  */
 public class TransactionTest {
 
@@ -76,7 +76,7 @@ public class TransactionTest {
      * that the same db connection is reused rather than acquiring a new one each time in typical transaction model.
      */
     public void testUserManagedConnection() {        
-        DbTestDao testDao = ComponentLocator.inject(DbTestDao.class);
+        DbTestDao testDao = ComponentContext.inject(DbTestDao.class);
         Transaction txn = Transaction.open("SingleConnectionThread");
         Connection conn = null;
         try {
@@ -115,7 +115,7 @@ public class TransactionTest {
      * This test is simulating ClusterHeartBeat process, where the same transaction and db connection is reused.
      */
     public void testTransactionReuse() {
-        DbTestDao testDao = ComponentLocator.inject(DbTestDao.class);
+        DbTestDao testDao = ComponentContext.inject(DbTestDao.class);
         // acquire a db connection and keep it
         Connection conn = null;
         try {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f922c6fc/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java b/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java
index 13e396d..bf917de 100644
--- a/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java
+++ b/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java
@@ -20,7 +20,7 @@ import junit.framework.TestCase;
 
 import org.apache.log4j.Logger;
 
-
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.exception.CloudRuntimeException;
 
@@ -48,9 +48,9 @@ public class CglibThrowableRendererTest extends TestCase {
             }
         }
     }
-    
+
     public void testException() {
-        Test test = ComponentLocator.inject(Test.class);
+        Test test = ComponentContext.inject(Test.class);
         try {
             test.exception();
         } catch (Exception e) {