cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject git commit: updated refs/heads/master to 36c7a56
Date Tue, 06 Aug 2013 03:23:37 GMT
Updated Branches:
  refs/heads/master 56d7ccef9 -> 36c7a56d1


CLOUDSTACK-4073: fix s3 on vmware

Conflicts:

	plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java


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

Branch: refs/heads/master
Commit: 36c7a56d12f4d09c6a90a0f93e0eb17fe82823da
Parents: 56d7cce
Author: Edison Su <sudison@gmail.com>
Authored: Mon Aug 5 20:23:01 2013 -0700
Committer: Edison Su <sudison@gmail.com>
Committed: Mon Aug 5 20:23:01 2013 -0700

----------------------------------------------------------------------
 .../StorageSubsystemCommandHandlerBase.java     |   2 +-
 .../cloudstack/storage/command/CopyCommand.java |   8 ++
 .../cloudstack/storage/to/SnapshotObjectTO.java |   4 +
 .../vmware/manager/VmwareStorageManager.java    |   1 +
 .../manager/VmwareStorageManagerImpl.java       |  15 +++
 .../vmware/resource/VmwareResource.java         |   5 +-
 .../VmwareSecondaryStorageResourceHandler.java  |   8 +-
 .../resource/VmwareStorageProcessor.java        |   6 +-
 .../VmwareStorageSubsystemCommandHandler.java   | 112 +++++++++++++++++++
 .../resource/NfsSecondaryStorageResource.java   |   4 +
 10 files changed, 159 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36c7a56d/core/src/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java b/core/src/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java
index 385a277..ab9aa2a 100644
--- a/core/src/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java
+++ b/core/src/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java
@@ -39,7 +39,7 @@ import com.cloud.storage.Volume;
 
 public class StorageSubsystemCommandHandlerBase implements StorageSubsystemCommandHandler
{
     private static final Logger s_logger = Logger.getLogger(StorageSubsystemCommandHandlerBase.class);
-    private StorageProcessor processor;
+    protected StorageProcessor processor;
     public StorageSubsystemCommandHandlerBase(StorageProcessor processor) {
         this.processor = processor;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36c7a56d/core/src/org/apache/cloudstack/storage/command/CopyCommand.java
----------------------------------------------------------------------
diff --git a/core/src/org/apache/cloudstack/storage/command/CopyCommand.java b/core/src/org/apache/cloudstack/storage/command/CopyCommand.java
index f14f37e..629fafe 100644
--- a/core/src/org/apache/cloudstack/storage/command/CopyCommand.java
+++ b/core/src/org/apache/cloudstack/storage/command/CopyCommand.java
@@ -38,6 +38,14 @@ public final class CopyCommand extends Command implements StorageSubSystemComman
         return this.destTO;
     }
 
+    public void setSrcTO(DataTO srcTO) {
+        this.srcTO = srcTO;
+    }
+
+    public void setDestTO(DataTO destTO) {
+        this.destTO = destTO;
+    }
+
     public DataTO getSrcTO() {
         return this.srcTO;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36c7a56d/core/src/org/apache/cloudstack/storage/to/SnapshotObjectTO.java
----------------------------------------------------------------------
diff --git a/core/src/org/apache/cloudstack/storage/to/SnapshotObjectTO.java b/core/src/org/apache/cloudstack/storage/to/SnapshotObjectTO.java
index b4829bf..bacc0f9 100644
--- a/core/src/org/apache/cloudstack/storage/to/SnapshotObjectTO.java
+++ b/core/src/org/apache/cloudstack/storage/to/SnapshotObjectTO.java
@@ -66,6 +66,10 @@ public class SnapshotObjectTO implements DataTO {
         return this.dataStore;
     }
 
+    public void setDataStore(DataStoreTO store) {
+        this.dataStore = store;
+    }
+
     @Override
     public String getPath() {
         return this.path;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36c7a56d/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManager.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManager.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManager.java
index 1e45eb8..14f293a 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManager.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManager.java
@@ -37,4 +37,5 @@ public interface VmwareStorageManager {
     Answer execute(VmwareHostService hostService, DeleteVMSnapshotCommand cmd);
     Answer execute(VmwareHostService hostService, RevertToVMSnapshotCommand cmd);
     boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCommand cmd);
+    public void createOva(String path, String name);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36c7a56d/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
index 72fb65b..29aae56 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
@@ -110,6 +110,21 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager
{
         return true;
     }
 
+    @Override
+    public void createOva(String path, String name) {
+        Script commandSync = new Script(true, "sync", 0, s_logger);
+        commandSync.execute();
+
+        Script command = new Script(false, "tar", 0, s_logger);
+        command.setWorkDir(path);
+        command.add("-cf", name + ".ova");
+        command.add(name + ".ovf");		// OVF file should be the first file in OVA archive
+        command.add(name + "-disk0.vmdk");
+
+        s_logger.info("Package OVA with commmand: " + command.toString());
+        command.execute();
+    }
+
     private static final Logger s_logger = Logger.getLogger(VmwareStorageManagerImpl.class);
 
     private final VmwareStorageMount _mountService;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36c7a56d/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index a29b84b..18dc9e8 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -45,6 +45,7 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import com.cloud.agent.api.to.DhcpTO;
+import com.cloud.storage.resource.VmwareStorageSubsystemCommandHandler;
 import org.apache.log4j.Logger;
 import org.apache.log4j.NDC;
 
@@ -6308,9 +6309,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
         int timeout = NumbersUtil.parseInt(value, 1440) * 1000;
         VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
         VmwareStorageProcessor storageProcessor = new VmwareStorageProcessor((VmwareHostService)this,
_fullCloneFlag, (VmwareStorageMount)mgr,
-                timeout, this, _shutdown_waitMs
+                timeout, this, _shutdown_waitMs, null
                 );
-        storageHandler = new StorageSubsystemCommandHandlerBase(storageProcessor);
+        storageHandler = new VmwareStorageSubsystemCommandHandler(storageProcessor);
 
         return true;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36c7a56d/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
index 3631e38..5dc70e7 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
@@ -68,8 +68,12 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
         _gson = GsonHelper.getGsonLogger();
 
         VmwareStorageProcessor storageProcessor = new VmwareStorageProcessor(this, true,
this, resource.getTimeout(),
-                null, null);
-        storageSubsystemHandler = new StorageSubsystemCommandHandlerBase(storageProcessor);
+                null, null, _resource);
+        VmwareStorageSubsystemCommandHandler vmwareStorageSubsystemCommandHandler = new VmwareStorageSubsystemCommandHandler(storageProcessor);
+        vmwareStorageSubsystemCommandHandler.setStorageResource(_resource);
+        vmwareStorageSubsystemCommandHandler.setStorageManager(_storageMgr);
+        storageSubsystemHandler = vmwareStorageSubsystemCommandHandler;
+
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36c7a56d/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
index 112a0cb..cc1a168 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
@@ -95,10 +95,13 @@ public class VmwareStorageProcessor implements StorageProcessor {
     protected Integer _shutdown_waitMs;
     private final Gson _gson;
     private final StorageLayer _storage = new JavaStorageLayer();
+    private final PremiumSecondaryStorageResource storageResource;
+ 
     public VmwareStorageProcessor(VmwareHostService hostService, boolean fullCloneFlag, VmwareStorageMount
mountService,
                                   Integer timeout,
                                   VmwareResource resource,
-                                  Integer shutdownWaitMs) {
+                                  Integer shutdownWaitMs,
+                                  PremiumSecondaryStorageResource storageResource) {
         this.hostService = hostService;
         this._fullCloneFlag = fullCloneFlag;
         this.mountService = mountService;
@@ -106,6 +109,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
         this.resource = resource;
         this._shutdown_waitMs = shutdownWaitMs;
         _gson = GsonHelper.getGsonLogger();
+        this.storageResource = storageResource;
     }
 
     private String getOVFFilePath(String srcOVAFileName) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36c7a56d/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java
new file mode 100644
index 0000000..1361515
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java
@@ -0,0 +1,112 @@
+/*
+ * 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 com.cloud.storage.resource;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.to.DataObjectType;
+import com.cloud.agent.api.to.DataStoreTO;
+import com.cloud.agent.api.to.DataTO;
+import com.cloud.agent.api.to.NfsTO;
+import com.cloud.agent.api.to.S3TO;
+import com.cloud.agent.api.to.SwiftTO;
+import com.cloud.hypervisor.vmware.manager.VmwareStorageManager;
+import com.cloud.storage.DataStoreRole;
+import org.apache.cloudstack.storage.command.CopyCmdAnswer;
+import org.apache.cloudstack.storage.command.CopyCommand;
+import org.apache.cloudstack.storage.to.SnapshotObjectTO;
+
+import java.io.File;
+
+public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemCommandHandlerBase
{
+
+    private VmwareStorageManager storageManager;
+    private PremiumSecondaryStorageResource storageResource;
+
+    public PremiumSecondaryStorageResource getStorageResource() {
+        return storageResource;
+    }
+
+    public void setStorageResource(PremiumSecondaryStorageResource storageResource) {
+        this.storageResource = storageResource;
+    }
+
+    public VmwareStorageManager getStorageManager() {
+        return storageManager;
+    }
+
+    public void setStorageManager(VmwareStorageManager storageManager) {
+        this.storageManager = storageManager;
+    }
+
+    public VmwareStorageSubsystemCommandHandler(StorageProcessor processor
+                                               ) {
+        super(processor);
+    }
+
+
+    @Override
+    protected Answer execute(CopyCommand cmd) {
+        DataTO srcData = cmd.getSrcTO();
+        DataTO destData = cmd.getDestTO();
+        DataStoreTO srcDataStore = srcData.getDataStore();
+        DataStoreTO destDataStore = destData.getDataStore();
+        //if copied between s3 and nfs cache, go to resource
+        boolean needDelegation = false;
+        if (destDataStore instanceof NfsTO
+                && destDataStore.getRole() == DataStoreRole.ImageCache) {
+            if (srcDataStore instanceof S3TO || srcDataStore instanceof SwiftTO) {
+                needDelegation = true;
+            }
+        }
+
+        if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole()
== DataStoreRole.Image) {
+            needDelegation = true;
+        }
+
+        if (srcData.getObjectType() == DataObjectType.SNAPSHOT && srcData.getDataStore().getRole()
== DataStoreRole.Primary) {
+            //for back up snapshot, we need to do backup to cache, then to object store if
object store is used.
+            if (cmd.getCacheTO() != null) {
+                cmd.setDestTO(cmd.getCacheTO());
+
+                CopyCmdAnswer answer = (CopyCmdAnswer)processor.backupSnapshot(cmd);
+                if (!answer.getResult()) {
+                    return answer;
+                }
+                NfsTO cacheStore = (NfsTO)cmd.getCacheTO().getDataStore();
+                String parentPath = storageResource.getRootDir(cacheStore.getUrl());
+                SnapshotObjectTO newSnapshot = (SnapshotObjectTO)answer.getNewData();
+                String path = newSnapshot.getPath();
+                int index = path.lastIndexOf(File.separator);
+                String name = path.substring(index + 1);
+                String dir = path.substring(0, index);
+                storageManager.createOva(parentPath + File.separator + dir, name);
+                newSnapshot.setPath(newSnapshot.getPath() + ".ova");
+                newSnapshot.setDataStore(cmd.getCacheTO().getDataStore());
+                CopyCommand newCmd = new CopyCommand(newSnapshot, destData, cmd.getWait(),
cmd.executeInSequence());
+                return storageResource.defaultAction(newCmd);
+            }
+        }
+
+        if (needDelegation) {
+            return storageResource.defaultAction(cmd);
+        } else {
+            return super.execute(cmd);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36c7a56d/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index 0d6a23a..89ce8e0 100755
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -739,6 +739,10 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
                 newVol.setPath(key);
                 newVol.setSize(srcFile.length());
                 retObj = newVol;
+            } else if (destData.getObjectType() == DataObjectType.SNAPSHOT) {
+                SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
+                newSnapshot.setPath(key);
+                retObj = newSnapshot;
             }
 
             return new CopyCmdAnswer(retObj);


Mime
View raw message