You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2014/01/09 01:51:00 UTC

[2/3] git commit: updated refs/heads/4.3 to 693f0c2

CLOUDSTACK-5840:Migration from NFS to S3 should be done in one API
(updateCloudToUseObjectStore) instead of two APIs.


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

Branch: refs/heads/4.3
Commit: 62aa14771c80c46e78f993cae90f3026b2312dbe
Parents: 5b07590
Author: Min Chen <mi...@citrix.com>
Authored: Wed Jan 8 16:28:20 2014 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Wed Jan 8 16:33:37 2014 -0800

----------------------------------------------------------------------
 api/src/com/cloud/storage/StorageService.java   |   8 +-
 .../admin/host/AddSecondaryStorageCmd.java      |  13 +-
 .../command/admin/storage/AddImageStoreCmd.java |   9 +-
 .../api/command/admin/storage/AddS3Cmd.java     |  96 ++++++-------
 .../PrepareSecondaryStorageForMigrationCmd.java | 109 --------------
 .../storage/UpdateCloudToUseObjectStoreCmd.java | 142 +++++++++++++++++++
 .../api/command/admin/swift/AddSwiftCmd.java    |  26 ++--
 .../test/AddSecondaryStorageCmdTest.java        |  20 ++-
 client/tomcatconf/commands.properties.in        |   2 +-
 .../com/cloud/server/ManagementServerImpl.java  |   6 +-
 .../com/cloud/storage/StorageManagerImpl.java   |  65 ++++++---
 11 files changed, 277 insertions(+), 219 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/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 cbbc1f3..4d44045 100644
--- a/api/src/com/cloud/storage/StorageService.java
+++ b/api/src/com/cloud/storage/StorageService.java
@@ -17,8 +17,8 @@
 package com.cloud.storage;
 
 import java.net.UnknownHostException;
+import java.util.Map;
 
-import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
 import org.apache.cloudstack.api.command.admin.storage.CreateSecondaryStagingStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
@@ -95,7 +95,8 @@ public interface StorageService{
 
     boolean deleteSecondaryStagingStore(DeleteSecondaryStagingStoreCmd cmd);
 
-    ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
+    public ImageStore discoverImageStore(String name, String url, String providerName, Long dcId, Map details) throws IllegalArgumentException, DiscoveryException,
+            InvalidParameterValueException;
 
     /**
      * Prepare NFS secondary storage for object store migration
@@ -108,6 +109,9 @@ public interface StorageService{
      * @throws InsufficientCapacityException
      *             TODO
      */
+    public ImageStore migrateToObjectStore(String name, String url, String providerName, Map details) throws IllegalArgumentException, DiscoveryException,
+            InvalidParameterValueException;
+
     public ImageStore prepareSecondaryStorageForObjectStoreMigration(Long storeId) throws ResourceUnavailableException,
             InsufficientCapacityException;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/api/src/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java
index 69a4a49..02e53a9 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java
@@ -16,16 +16,16 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.host;
 
+import org.apache.log4j.Logger;
+
 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.command.admin.storage.AddImageStoreCmd;
 import org.apache.cloudstack.api.response.ImageStoreResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
-import org.apache.log4j.Logger;
 
 import com.cloud.exception.DiscoveryException;
 import com.cloud.storage.ImageStore;
@@ -78,19 +78,14 @@ public class AddSecondaryStorageCmd extends BaseCmd {
 
     @Override
     public void execute(){
-        AddImageStoreCmd cmd = new AddImageStoreCmd();
-        cmd.setUrl(this.getUrl());
-        cmd.setZoneId(this.getZoneId());
-        cmd.setProviderName("NFS");
-
         try{
-            ImageStore result = _storageService.discoverImageStore(cmd);
+            ImageStore result = _storageService.discoverImageStore(null, getUrl(), "NFS", getZoneId(), null);
             ImageStoreResponse storeResponse = null;
             if (result != null ) {
                     storeResponse = _responseGenerator.createImageStoreResponse(result);
                     storeResponse.setResponseName(getCommandName());
                     storeResponse.setObjectName("secondarystorage");
-                    this.setResponseObject(storeResponse);
+                    setResponseObject(storeResponse);
             } else {
                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/api/src/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java
index 1552e05..98c0988 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java
@@ -21,6 +21,8 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
@@ -29,7 +31,6 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.ImageStoreResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
-import org.apache.log4j.Logger;
 
 import com.cloud.exception.DiscoveryException;
 import com.cloud.storage.ImageStore;
@@ -98,7 +99,7 @@ public class AddImageStoreCmd extends BaseCmd {
     }
 
     public String getProviderName() {
-        return this.providerName;
+        return providerName;
     }
 
     public void setUrl(String url) {
@@ -136,13 +137,13 @@ public class AddImageStoreCmd extends BaseCmd {
     @Override
     public void execute(){
         try{
-            ImageStore result = _storageService.discoverImageStore(this);
+            ImageStore result = _storageService.discoverImageStore(getName(), getUrl(), getProviderName(), getZoneId(), getDetails());
             ImageStoreResponse storeResponse = null;
             if (result != null ) {
                 storeResponse = _responseGenerator.createImageStoreResponse(result);
                 storeResponse.setResponseName(getCommandName());
                 storeResponse.setObjectName("imagestore");
-                this.setResponseObject(storeResponse);
+                setResponseObject(storeResponse);
             } else {
                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java
index 0af1a85..035a85c 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java
@@ -34,6 +34,8 @@ import static org.apache.cloudstack.api.BaseCmd.CommandType.STRING;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
@@ -41,7 +43,6 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.ImageStoreResponse;
-import org.apache.log4j.Logger;
 
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.DiscoveryException;
@@ -94,39 +95,32 @@ public final class AddS3Cmd extends BaseCmd {
     ServerApiException, ConcurrentOperationException, ResourceAllocationException,
     NetworkRuleConflictException {
 
-        AddImageStoreCmd cmd = new AddImageStoreCmd() {
-            @Override
-            public Map<String, String> getDetails() {
-                Map<String, String> dm = new HashMap<String, String>();
-                dm.put(ApiConstants.S3_ACCESS_KEY, getAccessKey());
-                dm.put(ApiConstants.S3_SECRET_KEY, getSecretKey());
-                dm.put(ApiConstants.S3_END_POINT, getEndPoint());
-                dm.put(ApiConstants.S3_BUCKET_NAME, getBucketName());
-                if (getHttpsFlag() != null) {
-                    dm.put(ApiConstants.S3_HTTPS_FLAG, getHttpsFlag().toString());
-                }
-                if (getConnectionTimeout() != null) {
-                    dm.put(ApiConstants.S3_CONNECTION_TIMEOUT, getConnectionTimeout().toString());
-                }
-                if (getMaxErrorRetry() != null) {
-                    dm.put(ApiConstants.S3_MAX_ERROR_RETRY, getMaxErrorRetry().toString());
-                }
-                if (getSocketTimeout() != null) {
-                    dm.put(ApiConstants.S3_SOCKET_TIMEOUT, getSocketTimeout().toString());
-                }
-                return dm;
-            }
-        };
-        cmd.setProviderName("S3");
+        Map<String, String> dm = new HashMap<String, String>();
+        dm.put(ApiConstants.S3_ACCESS_KEY, getAccessKey());
+        dm.put(ApiConstants.S3_SECRET_KEY, getSecretKey());
+        dm.put(ApiConstants.S3_END_POINT, getEndPoint());
+        dm.put(ApiConstants.S3_BUCKET_NAME, getBucketName());
+        if (getHttpsFlag() != null) {
+            dm.put(ApiConstants.S3_HTTPS_FLAG, getHttpsFlag().toString());
+        }
+        if (getConnectionTimeout() != null) {
+            dm.put(ApiConstants.S3_CONNECTION_TIMEOUT, getConnectionTimeout().toString());
+        }
+        if (getMaxErrorRetry() != null) {
+            dm.put(ApiConstants.S3_MAX_ERROR_RETRY, getMaxErrorRetry().toString());
+        }
+        if (getSocketTimeout() != null) {
+            dm.put(ApiConstants.S3_SOCKET_TIMEOUT, getSocketTimeout().toString());
+        }
 
         try{
-            ImageStore result = _storageService.discoverImageStore(cmd);
+            ImageStore result = _storageService.discoverImageStore(null, null, "S3", null, dm);
             ImageStoreResponse storeResponse = null;
             if (result != null ) {
                 storeResponse = _responseGenerator.createImageStoreResponse(result);
                 storeResponse.setResponseName(getCommandName());
                 storeResponse.setObjectName("secondarystorage");
-                this.setResponseObject(storeResponse);
+                setResponseObject(storeResponse);
             } else {
                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add S3 secondary storage");
             }
@@ -149,35 +143,35 @@ public final class AddS3Cmd extends BaseCmd {
 
         final AddS3Cmd thatAddS3Cmd = (AddS3Cmd) thatObject;
 
-        if (this.httpsFlag != null ? !this.httpsFlag.equals(thatAddS3Cmd.httpsFlag) : thatAddS3Cmd.httpsFlag != null) {
+        if (httpsFlag != null ? !httpsFlag.equals(thatAddS3Cmd.httpsFlag) : thatAddS3Cmd.httpsFlag != null) {
             return false;
         }
 
-        if (this.accessKey != null ? !this.accessKey.equals(thatAddS3Cmd.accessKey) : thatAddS3Cmd.accessKey != null) {
+        if (accessKey != null ? !accessKey.equals(thatAddS3Cmd.accessKey) : thatAddS3Cmd.accessKey != null) {
             return false;
         }
 
-        if (this.connectionTimeout != null ? !this.connectionTimeout.equals(thatAddS3Cmd.connectionTimeout) : thatAddS3Cmd.connectionTimeout != null) {
+        if (connectionTimeout != null ? !connectionTimeout.equals(thatAddS3Cmd.connectionTimeout) : thatAddS3Cmd.connectionTimeout != null) {
             return false;
         }
 
-        if (this.endPoint != null ? !this.endPoint.equals(thatAddS3Cmd.endPoint) : thatAddS3Cmd.endPoint != null) {
+        if (endPoint != null ? !endPoint.equals(thatAddS3Cmd.endPoint) : thatAddS3Cmd.endPoint != null) {
             return false;
         }
 
-        if (this.maxErrorRetry != null ? !this.maxErrorRetry.equals(thatAddS3Cmd.maxErrorRetry) : thatAddS3Cmd.maxErrorRetry != null) {
+        if (maxErrorRetry != null ? !maxErrorRetry.equals(thatAddS3Cmd.maxErrorRetry) : thatAddS3Cmd.maxErrorRetry != null) {
             return false;
         }
 
-        if (this.secretKey != null ? !this.secretKey.equals(thatAddS3Cmd.secretKey) : thatAddS3Cmd.secretKey != null) {
+        if (secretKey != null ? !secretKey.equals(thatAddS3Cmd.secretKey) : thatAddS3Cmd.secretKey != null) {
             return false;
         }
 
-        if (this.socketTimeout != null ? !this.socketTimeout.equals(thatAddS3Cmd.socketTimeout) : thatAddS3Cmd.socketTimeout != null) {
+        if (socketTimeout != null ? !socketTimeout.equals(thatAddS3Cmd.socketTimeout) : thatAddS3Cmd.socketTimeout != null) {
             return false;
         }
 
-        if (this.bucketName != null ? !this.bucketName.equals(thatAddS3Cmd.bucketName) : thatAddS3Cmd.bucketName != null) {
+        if (bucketName != null ? !bucketName.equals(thatAddS3Cmd.bucketName) : thatAddS3Cmd.bucketName != null) {
             return false;
         }
 
@@ -188,14 +182,14 @@ public final class AddS3Cmd extends BaseCmd {
     @Override
     public int hashCode() {
 
-        int result = this.accessKey != null ? this.accessKey.hashCode() : 0;
-        result = 31 * result + (this.secretKey != null ? this.secretKey.hashCode() : 0);
-        result = 31 * result + (this.endPoint != null ? this.endPoint.hashCode() : 0);
-        result = 31 * result + (this.bucketName != null ? this.bucketName.hashCode() : 0);
-        result = 31 * result + (this.httpsFlag != null && this.httpsFlag == true ? 1 : 0);
-        result = 31 * result + (this.connectionTimeout != null ? this.connectionTimeout.hashCode() : 0);
-        result = 31 * result + (this.maxErrorRetry != null ? this.maxErrorRetry.hashCode() : 0);
-        result = 31 * result + (this.socketTimeout != null ? this.socketTimeout.hashCode() : 0);
+        int result = accessKey != null ? accessKey.hashCode() : 0;
+        result = 31 * result + (secretKey != null ? secretKey.hashCode() : 0);
+        result = 31 * result + (endPoint != null ? endPoint.hashCode() : 0);
+        result = 31 * result + (bucketName != null ? bucketName.hashCode() : 0);
+        result = 31 * result + (httpsFlag != null && httpsFlag == true ? 1 : 0);
+        result = 31 * result + (connectionTimeout != null ? connectionTimeout.hashCode() : 0);
+        result = 31 * result + (maxErrorRetry != null ? maxErrorRetry.hashCode() : 0);
+        result = 31 * result + (socketTimeout != null ? socketTimeout.hashCode() : 0);
 
         return result;
 
@@ -212,35 +206,35 @@ public final class AddS3Cmd extends BaseCmd {
     }
 
     public String getAccessKey() {
-        return this.accessKey;
+        return accessKey;
     }
 
     public String getSecretKey() {
-        return this.secretKey;
+        return secretKey;
     }
 
     public String getEndPoint() {
-        return this.endPoint;
+        return endPoint;
     }
 
     public String getBucketName() {
-        return this.bucketName;
+        return bucketName;
     }
 
     public Boolean getHttpsFlag() {
-        return this.httpsFlag;
+        return httpsFlag;
     }
 
     public Integer getConnectionTimeout() {
-        return this.connectionTimeout;
+        return connectionTimeout;
     }
 
     public Integer getMaxErrorRetry() {
-        return this.maxErrorRetry;
+        return maxErrorRetry;
     }
 
     public Integer getSocketTimeout() {
-        return this.socketTimeout;
+        return socketTimeout;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/api/src/org/apache/cloudstack/api/command/admin/storage/PrepareSecondaryStorageForMigrationCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/PrepareSecondaryStorageForMigrationCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/PrepareSecondaryStorageForMigrationCmd.java
deleted file mode 100644
index d0c995a..0000000
--- a/api/src/org/apache/cloudstack/api/command/admin/storage/PrepareSecondaryStorageForMigrationCmd.java
+++ /dev/null
@@ -1,109 +0,0 @@
-// 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 org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiCommandJobType;
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import org.apache.cloudstack.api.response.ImageStoreResponse;
-import org.apache.cloudstack.context.CallContext;
-
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.storage.ImageStore;
-import com.cloud.user.Account;
-
-@APICommand(name = "prepareSecondaryStorageForMigration", description = "Prepare a NFS secondary storage to migrate to use object store like S3", responseObject = ImageStoreResponse.class)
-public class PrepareSecondaryStorageForMigrationCmd extends BaseAsyncCmd {
-    public static final Logger s_logger = Logger.getLogger(PrepareSecondaryStorageForMigrationCmd.class.getName());
-    private static final String s_name = "preparesecondarystorageformigrationresponse";
-
-    /////////////////////////////////////////////////////
-    //////////////// API parameters /////////////////////
-    /////////////////////////////////////////////////////
-
-    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ImageStoreResponse.class,
-            required = true, description = "Secondary image store ID")
-    private Long id;
-
-    /////////////////////////////////////////////////////
-    /////////////////// Accessors ///////////////////////
-    /////////////////////////////////////////////////////
-
-    public Long getId() {
-        return id;
-    }
-
-    /////////////////////////////////////////////////////
-    /////////////// API Implementation///////////////////
-    /////////////////////////////////////////////////////
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    @Override
-    public ApiCommandJobType getInstanceType() {
-        return ApiCommandJobType.ImageStore;
-    }
-
-    @Override
-    public Long getInstanceId() {
-        return getId();
-    }
-
-    @Override
-    public long getEntityOwnerId() {
-        Account account = CallContext.current().getCallingAccount();
-        if (account != null) {
-            return account.getId();
-        }
-
-        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
-    }
-
-    @Override
-    public String getEventType() {
-        return EventTypes.EVENT_MIGRATE_PREPARE_SECONDARY_STORAGE;
-    }
-
-    @Override
-    public String getEventDescription() {
-        return "preparing secondary storage: " + getId() + " for object store migration";
-    }
-
-    @Override
-    public void execute() throws ResourceUnavailableException, InsufficientCapacityException{
-        ImageStore result = _storageService.prepareSecondaryStorageForObjectStoreMigration(getId());
-        if (result != null){
-            ImageStoreResponse response = _responseGenerator.createImageStoreResponse(result);
-            response.setResponseName(getCommandName());
-            response.setResponseName("secondarystorage");
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to prepare secondary storage for object store migration");
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java
new file mode 100644
index 0000000..983a01c
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java
@@ -0,0 +1,142 @@
+// 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 java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+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.ImageStoreResponse;
+
+import com.cloud.exception.DiscoveryException;
+import com.cloud.storage.ImageStore;
+import com.cloud.user.Account;
+
+@APICommand(name = "updateCloudToUseObjectStore", description = "Migrate current NFS secondary storages to use object store.", responseObject = ImageStoreResponse.class, since = "4.3.0")
+public class UpdateCloudToUseObjectStoreCmd extends BaseCmd {
+    public static final Logger s_logger = Logger.getLogger(UpdateCloudToUseObjectStoreCmd.class.getName());
+    private static final String s_name = "updatecloudtouseobjectstoreresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name for the image store")
+    private String name;
+
+    @Parameter(name=ApiConstants.URL, type=CommandType.STRING, description="the URL for the image store")
+    private String url;
+
+    @Parameter(name=ApiConstants.PROVIDER, type=CommandType.STRING,
+            required=true, description="the image store provider name")
+    private String providerName;
+
+    @Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="the details for the image store. Example: details[0].key=accesskey&details[0].value=s389ddssaa&details[1].key=secretkey&details[1].value=8dshfsss")
+    private Map details;
+
+
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+
+    public String getUrl() {
+        return url;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Map<String, String> getDetails() {
+        Map<String, String> detailsMap = null;
+        if (details != null && !details.isEmpty()) {
+            detailsMap = new HashMap<String, String>();
+            Collection<?> props = details.values();
+            Iterator<?> iter = props.iterator();
+            while (iter.hasNext()) {
+                HashMap<String, String> detail = (HashMap<String, String>) iter.next();
+                String key = detail.get("key");
+                String value = detail.get("value");
+                detailsMap.put(key, value);
+            }
+        }
+        return detailsMap;
+    }
+
+    public String getProviderName() {
+        return providerName;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+
+    public void setProviderName(String providerName) {
+        this.providerName = providerName;
+    }
+
+    public void setDetails(Map<String, String> details) {
+        this.details = details;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public void execute(){
+        try{
+            ImageStore result = _storageService.migrateToObjectStore(getName(), getUrl(), getProviderName(), getDetails());
+            ImageStoreResponse storeResponse = null;
+            if (result != null ) {
+                storeResponse = _responseGenerator.createImageStoreResponse(result);
+                storeResponse.setResponseName(getCommandName());
+                storeResponse.setObjectName("imagestore");
+                setResponseObject(storeResponse);
+            } else {
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
+            }
+        } catch (DiscoveryException ex) {
+            s_logger.warn("Exception: ", ex);
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java b/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java
index ea22429..ec6e88c 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java
@@ -19,15 +19,15 @@ package org.apache.cloudstack.api.command.admin.swift;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.log4j.Logger;
+
 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.command.admin.storage.AddImageStoreCmd;
 import org.apache.cloudstack.api.response.ImageStoreResponse;
-import org.apache.log4j.Logger;
 
 import com.cloud.exception.DiscoveryException;
 import com.cloud.storage.ImageStore;
@@ -89,28 +89,20 @@ public class AddSwiftCmd extends BaseCmd {
     }
 
     @Override
-    public void execute(){
-        AddImageStoreCmd cmd = new AddImageStoreCmd() {
-            @Override
-            public Map<String, String> getDetails() {
-                Map<String, String> dm = new HashMap<String, String>();
-                dm.put(ApiConstants.ACCOUNT, getAccount());
-                dm.put(ApiConstants.USERNAME, getUsername());
-                dm.put(ApiConstants.KEY, getKey());
-                return dm;
-            }
-        };
-        cmd.setProviderName("Swift");
-        cmd.setUrl(this.getUrl());
+    public void execute() {
+        Map<String, String> dm = new HashMap<String, String>();
+        dm.put(ApiConstants.ACCOUNT, getAccount());
+        dm.put(ApiConstants.USERNAME, getUsername());
+        dm.put(ApiConstants.KEY, getKey());
 
         try{
-            ImageStore result = _storageService.discoverImageStore(cmd);
+            ImageStore result = _storageService.discoverImageStore(null, getUrl(), "Swift", null, dm);
             ImageStoreResponse storeResponse = null;
             if (result != null ) {
                 storeResponse = _responseGenerator.createImageStoreResponse(result);
                 storeResponse.setResponseName(getCommandName());
                 storeResponse.setObjectName("secondarystorage");
-                this.setResponseObject(storeResponse);
+                setResponseObject(storeResponse);
             } else {
                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Swift secondary storage");
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/api/test/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java
----------------------------------------------------------------------
diff --git a/api/test/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java b/api/test/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java
index c221ace..552a3c7 100644
--- a/api/test/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java
+++ b/api/test/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java
@@ -16,20 +16,26 @@
 // under the License.
 package org.apache.cloudstack.api.command.test;
 
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+
+import java.util.Map;
+
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
-import org.apache.cloudstack.api.ResponseGenerator;
-import org.apache.cloudstack.api.ServerApiException;
-import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
-import org.apache.cloudstack.api.response.HostResponse;
-import org.apache.cloudstack.api.response.ImageStoreResponse;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
 
+import org.apache.cloudstack.api.ResponseGenerator;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
+import org.apache.cloudstack.api.response.ImageStoreResponse;
+
 import com.cloud.storage.ImageStore;
 import com.cloud.storage.StorageService;
 
@@ -56,7 +62,7 @@ public class AddSecondaryStorageCmdTest extends TestCase {
 
         ImageStore store = Mockito.mock(ImageStore.class);
 
-        Mockito.when(resourceService.discoverImageStore(addImageStoreCmd))
+        Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map)anyObject()))
                 .thenReturn(store);
 
         ResponseGenerator responseGenerator = Mockito
@@ -88,7 +94,7 @@ public class AddSecondaryStorageCmdTest extends TestCase {
         StorageService resourceService = Mockito.mock(StorageService.class);
         addImageStoreCmd._storageService = resourceService;
 
-        Mockito.when(resourceService.discoverImageStore(addImageStoreCmd))
+        Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map)anyObject()))
                 .thenReturn(null);
 
         try {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 3016543..28789c1 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -266,7 +266,7 @@ deleteImageStore=1
 createSecondaryStagingStore=1
 listSecondaryStagingStores=1
 deleteSecondaryStagingStore=1
-prepareSecondaryStorageForMigration=1
+updateCloudToUseObjectStore=1
 
 #### host commands
 addHost=3

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index d81e847..2237694 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -42,7 +42,6 @@ import javax.crypto.spec.SecretKeySpec;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.cloudstack.framework.config.ConfigDepot;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.log4j.Logger;
 
@@ -162,7 +161,7 @@ import org.apache.cloudstack.api.command.admin.storage.ListSecondaryStagingStore
 import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
 import org.apache.cloudstack.api.command.admin.storage.ListStorageProvidersCmd;
 import org.apache.cloudstack.api.command.admin.storage.PreparePrimaryStorageForMaintenanceCmd;
-import org.apache.cloudstack.api.command.admin.storage.PrepareSecondaryStorageForMigrationCmd;
+import org.apache.cloudstack.api.command.admin.storage.UpdateCloudToUseObjectStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
 import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd;
 import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd;
@@ -440,6 +439,7 @@ import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationSer
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
+import org.apache.cloudstack.framework.config.ConfigDepot;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
@@ -2876,7 +2876,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         cmdList.add(CreateSecondaryStagingStoreCmd.class);
         cmdList.add(ListSecondaryStagingStoresCmd.class);
         cmdList.add(DeleteSecondaryStagingStoreCmd.class);
-        cmdList.add(PrepareSecondaryStorageForMigrationCmd.class);
+        cmdList.add(UpdateCloudToUseObjectStoreCmd.class);
         cmdList.add(CreateApplicationLoadBalancerCmd.class);
         cmdList.add(ListApplicationLoadBalancersCmd.class);
         cmdList.add(DeleteApplicationLoadBalancerCmd.class);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/62aa1477/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 e478956..b901e49 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -41,7 +41,9 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
 import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
 import org.apache.cloudstack.api.command.admin.storage.CreateSecondaryStagingStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
@@ -86,8 +88,6 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
@@ -1670,8 +1670,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
     }
 
     @Override
-    public ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
-        String providerName = cmd.getProviderName();
+    public ImageStore discoverImageStore(String name, String url, String providerName, Long dcId, Map details) throws IllegalArgumentException, DiscoveryException,
+            InvalidParameterValueException {
         DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
 
         if (storeProvider == null) {
@@ -1682,16 +1682,13 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
             providerName = storeProvider.getName(); // ignored passed provider name and use default image store provider name
         }
 
-        Long dcId = cmd.getZoneId();
-        Map details = cmd.getDetails();
         ScopeType scopeType = ScopeType.ZONE;
         if (dcId == null) {
             scopeType = ScopeType.REGION;
         }
 
-        String name = cmd.getName();
         if (name == null) {
-            name = cmd.getUrl();
+            name = url;
         }
         ImageStoreVO imageStore = _imageStoreDao.findByName(name);
         if (imageStore != null) {
@@ -1699,7 +1696,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
         }
 
         // check if scope is supported by store provider
-        if (!((ImageStoreProvider) storeProvider).isScopeSupported(scopeType)) {
+        if (!((ImageStoreProvider)storeProvider).isScopeSupported(scopeType)) {
             throw new InvalidParameterValueException("Image store provider " + providerName + " does not support scope " + scopeType);
         }
 
@@ -1732,8 +1729,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
 
         Map<String, Object> params = new HashMap<String, Object>();
         params.put("zoneId", dcId);
-        params.put("url", cmd.getUrl());
-        params.put("name", cmd.getName());
+        params.put("url", url);
+        params.put("name", name);
         params.put("details", details);
         params.put("scope", scopeType);
         params.put("providerName", storeProvider.getName());
@@ -1744,11 +1741,11 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
         try {
             store = lifeCycle.initialize(params);
         } catch (Exception e) {
-            s_logger.debug("Failed to add data store: "+e.getMessage(), e);
-            throw new CloudRuntimeException("Failed to add data store: "+e.getMessage(), e);
+            s_logger.debug("Failed to add data store: " + e.getMessage(), e);
+            throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
         }
 
-        if (((ImageStoreProvider) storeProvider).needDownloadSysTemplate()) {
+        if (((ImageStoreProvider)storeProvider).needDownloadSysTemplate()) {
             // trigger system vm template download
             _imageSrv.downloadBootstrapSysTemplate(store);
         }
@@ -1766,7 +1763,43 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
             duplicateCacheStoreRecordsToRegionStore(store.getId());
         }
 
-        return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image);
+        return (ImageStore)_dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image);
+    }
+
+    @Override
+    public ImageStore migrateToObjectStore(String name, String url, String providerName, Map details) throws IllegalArgumentException, DiscoveryException,
+            InvalidParameterValueException {
+        // check if current cloud is ready to migrate, we only support cloud with only NFS secondary storages
+        List<ImageStoreVO> imgStores = _imageStoreDao.listImageStores();
+        List<ImageStoreVO> nfsStores = new ArrayList<ImageStoreVO>();
+        if (imgStores != null && imgStores.size() > 0) {
+            for (ImageStoreVO store : imgStores) {
+                if (!store.getProviderName().equals(DataStoreProvider.NFS_IMAGE)) {
+                    throw new InvalidParameterValueException("We only support migrate NFS secondary storage to use object store!");
+                } else {
+                    nfsStores.add(store);
+                }
+            }
+        }
+        // convert all NFS secondary storage to staging store
+        if (nfsStores != null && nfsStores.size() > 0) {
+            for (ImageStoreVO store : nfsStores) {
+                long storeId = store.getId();
+
+                _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
+
+                DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider(store.getProviderName());
+                DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
+                DataStore secStore = dataStoreMgr.getDataStore(storeId, DataStoreRole.Image);
+                lifeCycle.migrateToObjectStore(secStore);
+                // update store_role in template_store_ref and snapshot_store_ref to ImageCache
+                _templateStoreDao.updateStoreRoleToCachce(storeId);
+                _snapshotStoreDao.updateStoreRoleToCache(storeId);
+            }
+        }
+        // add object store
+        return discoverImageStore(name, url, providerName, null, details);
+
     }
 
     private void duplicateCacheStoreRecordsToRegionStore(long storeId) {