cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject git commit: updated refs/heads/object_store to 9be9902
Date Tue, 09 Apr 2013 21:49:31 GMT
Updated Branches:
  refs/heads/object_store 74880fa26 -> 9be9902ed


Fix applicationContext.xml to properly load all new refactored image
store related classes, also add enableImageStore api.

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

Branch: refs/heads/object_store
Commit: 9be9902ed5ea8e1e3f459b783b485f4ecbc89da1
Parents: 74880fa
Author: Min Chen <min.chen@citrix.com>
Authored: Tue Apr 9 14:49:09 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Tue Apr 9 14:49:09 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/storage/StorageService.java      |    2 +
 .../command/admin/storage/EnableImageStoreCmd.java |   89 +++++++++++++++
 client/pom.xml                                     |   15 +++
 client/tomcatconf/applicationContext.xml.in        |   17 ++-
 .../storage/datastore/db/ImageStoreDao.java        |    2 +
 .../storage/image/db/ImageStoreDaoImpl.java        |   47 +++++++-
 .../storage/image/db/SnapshotDataStoreDaoImpl.java |    6 +-
 .../storage/image/db/TemplateDataStoreDaoImpl.java |    6 +-
 .../storage/image/db/VolumeDataStoreDaoImpl.java   |   11 ++-
 .../src/com/cloud/storage/StorageManagerImpl.java  |   37 ++++++
 10 files changed, 215 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9be9902e/api/src/com/cloud/storage/StorageService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/storage/StorageService.java b/api/src/com/cloud/storage/StorageService.java
index ee1a956..665abcb 100644
--- a/api/src/com/cloud/storage/StorageService.java
+++ b/api/src/com/cloud/storage/StorageService.java
@@ -23,6 +23,7 @@ import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaint
 import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
 import org.apache.cloudstack.api.command.admin.storage.DeleteImageStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
+import org.apache.cloudstack.api.command.admin.storage.EnableImageStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
 
 import com.cloud.exception.DiscoveryException;
@@ -91,4 +92,5 @@ public interface StorageService{
 
     ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException,
DiscoveryException, InvalidParameterValueException;
 
+    ImageStore enableImageStore(EnableImageStoreCmd cmd);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9be9902e/api/src/org/apache/cloudstack/api/command/admin/storage/EnableImageStoreCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/EnableImageStoreCmd.java
b/api/src/org/apache/cloudstack/api/command/admin/storage/EnableImageStoreCmd.java
new file mode 100644
index 0000000..7586fa9
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/storage/EnableImageStoreCmd.java
@@ -0,0 +1,89 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.storage;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.ImageStoreResponse;
+import org.apache.cloudstack.region.RegionService;
+import org.apache.log4j.Logger;
+
+import com.cloud.storage.ImageStore;
+import com.cloud.user.Account;
+
+@APICommand(name = "enableImageStore", description="Enable an image store", responseObject=ImageStoreResponse.class)
+public class EnableImageStoreCmd extends BaseCmd {
+    public static final Logger s_logger = Logger.getLogger(EnableImageStoreCmd.class.getName());
+    private static final String s_name = "enableimagestoreresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+    @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=ImageStoreResponse.class,
+            description="Image Store id")
+    private Long id;
+
+    @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="Enables specified
image store.")
+    private String storeName;
+
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    public String getStoreName() {
+        return storeName;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public void execute(){
+        ImageStore result = _storageService.enableImageStore(this);
+        if (result != null){
+            ImageStoreResponse response = _responseGenerator.createImageStoreResponse(result);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable image
store");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9be9902e/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index 9323d0f..39f1cb0 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -225,6 +225,21 @@
         <version>${project.version}</version>
     </dependency>
     <dependency>
+        <groupId>org.apache.cloudstack</groupId>
+        <artifactId>cloud-plugin-storage-image-default</artifactId>
+        <version>${project.version}</version>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.cloudstack</groupId>
+        <artifactId>cloud-plugin-storage-image-s3</artifactId>
+        <version>${project.version}</version>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.cloudstack</groupId>
+        <artifactId>cloud-plugin-storage-image-swift</artifactId>
+        <version>${project.version}</version>
+    </dependency>            
+    <dependency>
       <groupId>org.apache.cloudstack</groupId>
       <artifactId>cloud-plugin-syslog-alerts</artifactId>
       <version>${project.version}</version>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9be9902e/client/tomcatconf/applicationContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in
index 7bf45a2..d8bb30a 100644
--- a/client/tomcatconf/applicationContext.xml.in
+++ b/client/tomcatconf/applicationContext.xml.in
@@ -190,7 +190,7 @@
   <bean id="dataCenterJoinDaoImpl" class="com.cloud.api.query.dao.DataCenterJoinDaoImpl"
/>
   <bean id="dataCenterLinkLocalIpAddressDaoImpl" class="com.cloud.dc.dao.DataCenterLinkLocalIpAddressDaoImpl"
/>
   <bean id="dataCenterVnetDaoImpl" class="com.cloud.dc.dao.DataCenterVnetDaoImpl" />
-  <bean id="dataStoreProviderDaoImpl" class="org.apache.cloudstack.storage.datastore.db.DataStoreProviderDaoImpl"
/>
+  <bean id="dataStoreProviderDaoImpl" class="org.apache.cloudstack.storage.db.DataStoreProviderDaoImpl"
/>
   <bean id="dcDetailsDaoImpl" class="com.cloud.dc.dao.DcDetailsDaoImpl" />
   <bean id="engineDcDetailsDaoImpl" class="org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DcDetailsDaoImpl"
/>
   <bean id="diskOfferingJoinDaoImpl" class="com.cloud.api.query.dao.DiskOfferingJoinDaoImpl"
/>
@@ -223,8 +223,12 @@
   <bean id="hostTransferMapDaoImpl" class="com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl"
/>
   <bean id="iPAddressDaoImpl" class="com.cloud.network.dao.IPAddressDaoImpl" />
   <bean id="identityDaoImpl" class="com.cloud.uuididentity.dao.IdentityDaoImpl" />
-  <bean id="imageDaoStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageDaoStoreDaoImpl"
/>
-  <bean id="imageDataStoreProviderDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageDataStoreProviderDaoImpl"
/>
+  <bean id="imageStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageStoreDaoImpl"
/>
+  <bean id="imageStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageStoreDetailsDaoImpl"
/> 
+  <bean id="imageStoreJoinDaoImpl" class="com.cloud.api.query.dao.ImageStoreJoinDaoImpl"
/>   
+  <bean id="snapshotDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.SnapshotDataStoreDaoImpl"
/> 
+  <bean id="templateDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.TemplateDataStoreDaoImpl"
/> 
+  <bean id="volumeDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.VolumeDataStoreDaoImpl"
/>       
   <bean id="inlineLoadBalancerNicMapDaoImpl" class="com.cloud.network.dao.InlineLoadBalancerNicMapDaoImpl"
/>
   <bean id="instanceGroupDaoImpl" class="com.cloud.vm.dao.InstanceGroupDaoImpl" />
   <bean id="instanceGroupJoinDaoImpl" class="com.cloud.api.query.dao.InstanceGroupJoinDaoImpl"
/>
@@ -270,7 +274,7 @@
   <bean id="portForwardingRulesDaoImpl" class="com.cloud.network.rules.dao.PortForwardingRulesDaoImpl"
/>
   <bean id="portProfileDaoImpl" class="com.cloud.network.dao.PortProfileDaoImpl" />
   <bean id="primaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl"
/>
-  <bean id="primaryDataStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDetailsDaoImpl"
/>
+  <bean id="primaryDataStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.volume.db.PrimaryDataStoreDetailsDaoImpl"
/>
   <bean id="privateIpDaoImpl" class="com.cloud.network.vpc.dao.PrivateIpDaoImpl" />
   <bean id="projectAccountDaoImpl" class="com.cloud.projects.dao.ProjectAccountDaoImpl"
/>
   <bean id="projectAccountJoinDaoImpl" class="com.cloud.api.query.dao.ProjectAccountJoinDaoImpl"
/>
@@ -713,7 +717,6 @@
   <bean id="agentMonitor" class="com.cloud.agent.manager.AgentMonitor" />
   <bean id="alertGenerator" class="com.cloud.event.AlertGenerator" />
   <bean id="ancientDataMotionStrategy" class="org.apache.cloudstack.storage.motion.AncientDataMotionStrategy"
/>
-  <bean id="ancientImageDataStoreProvider" class="org.apache.cloudstack.storage.image.store.AncientImageDataStoreProvider"
/>
   <bean id="ancientSnapshotStrategy" class="org.apache.cloudstack.storage.snapshot.strategy.AncientSnapshotStrategy"
/>
   <bean id="apiDBUtils" class="com.cloud.api.ApiDBUtils" />
   <bean id="apiDiscoveryServiceImpl" class="org.apache.cloudstack.discovery.ApiDiscoveryServiceImpl"
/>
@@ -732,6 +735,7 @@
   <bean id="dataStoreManagerImpl" class="org.apache.cloudstack.storage.datastore.DataStoreManagerImpl"
/>
   <bean id="defaultEndPointSelector" class="org.apache.cloudstack.storage.endpoint.DefaultEndPointSelector"
/>
   <bean id="primaryDataStoreProviderManagerImpl" class="org.apache.cloudstack.storage.datastore.manager.PrimaryDataStoreProviderManagerImpl"
/>
+  <bean id="imageStoreProviderManagerImpl" class="org.apache.cloudstack.storage.image.manager.ImageStoreProviderManagerImpl"
/>  
   <bean id="eventUtils" class="com.cloud.event.EventUtils" />
   <bean id="globalLoadBalancingRulesServiceImpl" class="org.apache.cloudstack.region.gslb.GlobalLoadBalancingRulesServiceImpl"
/>
   <bean id="hypervsiorHostEndPointRpcServer" class="org.apache.cloudstack.storage.HypervsiorHostEndPointRpcServer"
/>
@@ -739,8 +743,7 @@
   <bean id="ISO" class="org.apache.cloudstack.storage.image.format.ISO" />
   <bean id="imageDataFactoryImpl" class="org.apache.cloudstack.storage.image.ImageDataFactoryImpl"
/>
   <bean id="imageDataManagerImpl" class="org.apache.cloudstack.storage.image.manager.ImageDataManagerImpl"
/>
-  <bean id="imageDataStoreHelper" class="org.apache.cloudstack.storage.image.datastore.ImageDataStoreHelper"
/>
-  <bean id="imageDataStoreManagerImpl" class="org.apache.cloudstack.storage.image.manager.ImageDataStoreManagerImpl"
/>
+  <bean id="imageStoreHelper" class="org.apache.cloudstack.storage.image.datastore.ImageStoreHelper"
/>
   <bean id="imageFormatHelper" class="org.apache.cloudstack.storage.image.format.ImageFormatHelper"
/>
   <bean id="imageServiceImpl" class="org.apache.cloudstack.storage.image.ImageServiceImpl"
/>
   <bean id="iso" class="org.apache.cloudstack.engine.subsystem.api.storage.type.Iso" />

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9be9902e/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
index a81fa9c..1c30766 100644
--- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
@@ -22,4 +22,6 @@ import com.cloud.utils.db.GenericDao;
 
 public interface ImageStoreDao extends GenericDao<ImageStoreVO, Long> {
     public ImageStoreVO findByName(String name);
+
+    public ImageStoreVO findEnabledStore();
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9be9902e/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
index 2becada..8aa5079 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
@@ -18,11 +18,22 @@
  */
 package org.apache.cloudstack.storage.image.db;
 
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
 import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
+import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
+import com.cloud.storage.ImageStore;
+import com.cloud.user.AccountVO;
+import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria2;
 import com.cloud.utils.db.SearchCriteriaService;
 import com.cloud.utils.db.SearchCriteria.Op;
@@ -30,11 +41,41 @@ import com.cloud.utils.db.SearchCriteria.Op;
 @Component
 public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implements
ImageStoreDao {
 
+    private static final Logger s_logger = Logger.getLogger(ImageStoreDaoImpl.class);
+    private SearchBuilder<ImageStoreVO> nameSearch;
+    private SearchBuilder<ImageStoreVO> enableSearch;
+
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException
{
+        super.configure(name, params);
+
+        nameSearch = createSearchBuilder();
+        nameSearch.and("name", nameSearch.entity().getName(), SearchCriteria.Op.EQ);
+        nameSearch.done();
+
+
+        enableSearch = createSearchBuilder();
+        enableSearch.and("state", enableSearch.entity().getState(), SearchCriteria.Op.EQ);
+        enableSearch.done();
+
+        return true;
+    }
+
     @Override
     public ImageStoreVO findByName(String name) {
-        SearchCriteriaService<ImageStoreVO, ImageStoreVO> sc =  SearchCriteria2.create(ImageStoreVO.class);
-        sc.addAnd(sc.getEntity().getName(), Op.EQ, name);
-        return sc.find();
+        SearchCriteria<ImageStoreVO> sc = nameSearch.create();
+        sc.setParameters("name", name);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public ImageStoreVO findEnabledStore() {
+        SearchCriteria<ImageStoreVO> sc = nameSearch.create();
+        sc.setParameters("state", ImageStore.State.Enabled); // only one image store is enabled
at one time.
+        return findOneBy(sc);
     }
 
+
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9be9902e/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
index 1fed791..a1c4871 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
@@ -52,8 +52,8 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
         storeSearch.done();
 
         liveStoreSearch = createSearchBuilder();
-        liveStoreSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
-        liveStoreSearch.and("destroyed", storeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
+        liveStoreSearch.and("store_id", liveStoreSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
+        liveStoreSearch.and("destroyed", liveStoreSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
         liveStoreSearch.done();
 
         updateStateSearch = this.createSearchBuilder();
@@ -109,7 +109,7 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
 
     @Override
     public List<SnapshotDataStoreVO> listLiveByStoreId(long id) {
-        SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
+        SearchCriteria<SnapshotDataStoreVO> sc = liveStoreSearch.create();
         sc.setParameters("store_id", id);
         sc.setParameters("destroyed", false);
         return listIncludingRemovedBy(sc);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9be9902e/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
index 2066c5d..d7019d2 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
@@ -53,8 +53,8 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
         storeSearch.done();
 
         liveStoreSearch = createSearchBuilder();
-        liveStoreSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
-        liveStoreSearch.and("destroyed", storeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
+        liveStoreSearch.and("store_id", liveStoreSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
+        liveStoreSearch.and("destroyed", liveStoreSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
         liveStoreSearch.done();
 
     	updateStateSearch = this.createSearchBuilder();
@@ -109,7 +109,7 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
     }
     @Override
     public List<TemplateDataStoreVO> listLiveByStoreId(long id) {
-        SearchCriteria<TemplateDataStoreVO> sc = storeSearch.create();
+        SearchCriteria<TemplateDataStoreVO> sc = liveStoreSearch.create();
         sc.setParameters("store_id", id);
         sc.setParameters("destroyed", false);
         return listIncludingRemovedBy(sc);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9be9902e/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
index 34de3f2..b8127ee 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
@@ -49,6 +49,15 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO,
Lo
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException
{
     	super.configure(name, params);
 
+        storeSearch = createSearchBuilder();
+        storeSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
+        storeSearch.done();
+
+        liveStoreSearch = createSearchBuilder();
+        liveStoreSearch.and("store_id", liveStoreSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
+        liveStoreSearch.and("destroyed", liveStoreSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
+        liveStoreSearch.done();
+
         updateStateSearch = this.createSearchBuilder();
         updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
         updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
@@ -100,7 +109,7 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO,
Lo
     }
     @Override
     public List<VolumeDataStoreVO> listLiveByStoreId(long id) {
-        SearchCriteria<VolumeDataStoreVO> sc = storeSearch.create();
+        SearchCriteria<VolumeDataStoreVO> sc = liveStoreSearch.create();
         sc.setParameters("store_id", id);
         sc.setParameters("destroyed", false);
         return listIncludingRemovedBy(sc);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9be9902e/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index c9f97be..162df1a 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -45,6 +45,7 @@ import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaint
 import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
 import org.apache.cloudstack.api.command.admin.storage.DeleteImageStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
+import org.apache.cloudstack.api.command.admin.storage.EnableImageStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
 import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
@@ -165,6 +166,7 @@ import com.cloud.tags.dao.ResourceTagDao;
 import com.cloud.template.TemplateManager;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
+import com.cloud.user.AccountVO;
 import com.cloud.user.ResourceLimitService;
 import com.cloud.user.User;
 import com.cloud.user.UserContext;
@@ -2011,5 +2013,40 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
         return true;
     }
 
+    @Override
+    public ImageStore enableImageStore(EnableImageStoreCmd cmd) {
+        Long storeId = cmd.getId();
+        String storeName = cmd.getStoreName();
+
+        ImageStore store = null;
+        if ( storeId != null ){
+            store = _imageStoreDao.findById(storeId);
+        } else if ( storeName != null ){
+            store = _imageStoreDao.findByName(storeName);
+        } else {
+            throw new InvalidParameterValueException("Either image store id or name has to
be specified!");
+        }
+
+        if (store == null) {
+            throw new InvalidParameterValueException("Unable to find image store by id: "
+ storeId + " OR by name: " + storeName);
+        }
+        // disable currently active store
+        ImageStoreVO activeStore = _imageStoreDao.findEnabledStore();
+        ImageStoreVO activeStoreForUpdate = _imageStoreDao.createForUpdate();
+        activeStoreForUpdate.setState(ImageStore.State.Disabled);
+        if ( !_imageStoreDao.update(activeStore.getId(), activeStoreForUpdate)){
+            throw new CloudRuntimeException("Failed to disable current active image store
" + activeStore.getName());
+        }
+
+        ImageStoreVO storeForUpdate = _imageStoreDao.createForUpdate();
+        storeForUpdate.setState(ImageStore.State.Enabled);
+        if (_imageStoreDao.update(store.getId(), storeForUpdate)){
+            return _imageStoreDao.findById(store.getId());
+        }
+        else{
+            throw new CloudRuntimeException("Failed to enable image store by id: " + storeId
+ " OR by name: " + storeName);
+        }
+    }
+
 
 }


Mime
View raw message