cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From likit...@apache.org
Subject git commit: updated refs/heads/ova-multiple-disks to 637b94c
Date Wed, 12 Mar 2014 04:52:14 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/ova-multiple-disks bb6fddf43 -> 637b94cfe


Agent command to analyze template


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

Branch: refs/heads/ova-multiple-disks
Commit: 637b94cfe80e05d9c4d26034056a97a6046a1541
Parents: bb6fddf
Author: Likitha Shetty <likitha.shetty@citrix.com>
Authored: Wed Mar 12 09:39:25 2014 +0530
Committer: Likitha Shetty <likitha.shetty@citrix.com>
Committed: Wed Mar 12 10:13:31 2014 +0530

----------------------------------------------------------------------
 .../api/storage/AnalyzeTemplateAnswer.java      | 41 ++++++++++++
 .../api/storage/AnalyzeTemplateCommand.java     | 43 ++++++++++++
 .../cloudstack/storage/to/TemplateObjectTO.java |  9 +++
 .../storage/image/BaseImageStoreDriverImpl.java | 59 ++++++++++++++++-
 .../vmware/manager/VmwareStorageManager.java    |  3 +
 .../manager/VmwareStorageManagerImpl.java       | 70 ++++++++++++++++++++
 .../VmwareSecondaryStorageResourceHandler.java  | 11 ++-
 7 files changed, 234 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/637b94cf/core/src/com/cloud/agent/api/storage/AnalyzeTemplateAnswer.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/storage/AnalyzeTemplateAnswer.java b/core/src/com/cloud/agent/api/storage/AnalyzeTemplateAnswer.java
new file mode 100644
index 0000000..e022aba
--- /dev/null
+++ b/core/src/com/cloud/agent/api/storage/AnalyzeTemplateAnswer.java
@@ -0,0 +1,41 @@
+// 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.agent.api.storage;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.storage.to.TemplateObjectTO;
+
+import com.cloud.agent.api.Answer;
+
+public class AnalyzeTemplateAnswer extends Answer {
+    private List<TemplateObjectTO> newDataList = new ArrayList<TemplateObjectTO>();
+
+    public AnalyzeTemplateAnswer(List<TemplateObjectTO> newDataList) {
+        super(null);
+        this.newDataList = newDataList;
+    }
+
+    public List<TemplateObjectTO> getNewDataList() {
+        return newDataList;
+    }
+
+    public AnalyzeTemplateAnswer(String errMsg) {
+        super(null, false, errMsg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/637b94cf/core/src/com/cloud/agent/api/storage/AnalyzeTemplateCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/storage/AnalyzeTemplateCommand.java b/core/src/com/cloud/agent/api/storage/AnalyzeTemplateCommand.java
new file mode 100644
index 0000000..214d968
--- /dev/null
+++ b/core/src/com/cloud/agent/api/storage/AnalyzeTemplateCommand.java
@@ -0,0 +1,43 @@
+// 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.agent.api.storage;
+
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.to.DataTO;
+
+public final class AnalyzeTemplateCommand extends Command {
+    private DataTO data;
+
+    public AnalyzeTemplateCommand(DataTO data) {
+        super();
+        this.data = data;
+    }
+
+    protected AnalyzeTemplateCommand() {
+        super();
+    }
+
+    @Override
+    public boolean executeInSequence() {
+        return false;
+    }
+
+    public DataTO getData() {
+        return this.data;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/637b94cf/core/src/org/apache/cloudstack/storage/to/TemplateObjectTO.java
----------------------------------------------------------------------
diff --git a/core/src/org/apache/cloudstack/storage/to/TemplateObjectTO.java b/core/src/org/apache/cloudstack/storage/to/TemplateObjectTO.java
index b201c38..421ff14 100644
--- a/core/src/org/apache/cloudstack/storage/to/TemplateObjectTO.java
+++ b/core/src/org/apache/cloudstack/storage/to/TemplateObjectTO.java
@@ -41,6 +41,7 @@ public class TemplateObjectTO implements DataTO {
     private Long size;
     private Long physicalSize;
     private Hypervisor.HypervisorType hypervisorType;
+    private boolean bootable;
 
     public TemplateObjectTO() {
 
@@ -204,6 +205,14 @@ public class TemplateObjectTO implements DataTO {
         return physicalSize;
     }
 
+    public void setIsBootable(boolean bootable) {
+        this.bootable = bootable;
+    }
+
+    public boolean isBootable() {
+        return bootable;
+    }
+
     public void setPhysicalSize(Long physicalSize) {
         this.physicalSize = physicalSize;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/637b94cf/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
index 7ed11ec..7401fdb 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
@@ -39,6 +39,7 @@ import org.apache.cloudstack.framework.async.AsyncRpcContext;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.storage.command.CommandResult;
 import org.apache.cloudstack.storage.command.DeleteCommand;
+
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
@@ -46,6 +47,7 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
 
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.storage.DownloadAnswer;
+import com.cloud.agent.api.storage.AnalyzeTemplateCommand;
 import com.cloud.agent.api.storage.Proxy;
 import com.cloud.agent.api.to.DataObjectType;
 import com.cloud.agent.api.to.DataTO;
@@ -182,7 +184,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver
{
                 templateDaoBuilder.setChecksum(answer.getCheckSum());
                 _templateDao.update(obj.getId(), templateDaoBuilder);
             }
-
+            analyseTemplate(obj);
             CreateCmdResult result = new CreateCmdResult(null, null);
             caller.complete(result);
         }
@@ -271,4 +273,59 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver
{
     @Override
     public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback)
{
     }
+
+    private void analyseTemplate(DataObject data) {
+        CommandResult result = new CommandResult();
+        DataStore store = data.getDataStore();
+        TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(),
data.getId());
+        try {
+            AnalyzeTemplateCommand cmd = new AnalyzeTemplateCommand(data.getTO());
+            EndPoint ep = _epSelector.select(data);
+            Answer answer = null;
+            if (ep == null) {
+                String errMsg = "No remote endpoint to send command, check if host or ssvm
is down?";
+                s_logger.error(errMsg);
+                answer = new Answer(cmd, false, errMsg);
+            } else {/*
+                (AnalyzeTemplateAnswer)answer = ep.sendMessage(cmd);
+                if (answer != null && !answer.getResult()) {
+                    result.setResult(answer.getDetails());
+                    // Registered template may have data disks - Creating DataDisk template
entries for each of these disks
+                    if (answer.getNewDataList() != null && !answer.getNewDataList().isEmpty())
{
+                        List<TemplateObjectTO> dataDiskTemplates = answer.getNewDataList();
+                        VMTemplateVO rootTemplate = _templateDao.findById(data.getId());
+                        int diskNumber = 1;
+                        for (TemplateObjectTO dataDiskTemplate : dataDiskTemplates) {
+                            if (dataDiskTemplate.isBootable()) // Root disk
+                                continue;
+                            long id = _templateDao.getNextInSequence(Long.class, "id");
+                            VMTemplateVO template = new VMTemplateVO(id, rootTemplate.getName()
+ "-DataDiskTemplate-" + diskNumber, rootTemplate.getFormat(), false,
+                                    false, rootTemplate.isExtractable(), TemplateType.DATADISK,
rootTemplate.getUrl(), rootTemplate.requiresHvm(), rootTemplate.getBits(),
+                                    rootTemplate.getAccountId(), rootTemplate.getChecksum(),
rootTemplate.getDisplayText() + "-DataDiskTemplate", false, 0, false,
+                                    rootTemplate.getHypervisorType(), null, null, false,
false);
+                            template = _templateDao.persist(template);
+                            template.setSize(dataDiskTemplate.getSize());
+                            _templateDao.update(template.getId(), template);
+
+                            TemplateDataStoreVO templateStore = new TemplateDataStoreVO(store.getId(),
template.getId(), null, 100, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
+                                    null, null, null, dataDiskTemplate.getInstallPath(),
tmpltStoreVO.getDownloadUrl());
+                            templateStore.setSize(dataDiskTemplate.getSize());
+                            templateStore.setDataStoreRole(tmpltStoreVO.getDataStoreRole());
+                            templateStore.setPhysicalSize(dataDiskTemplate.getPhysicalSize());
+                            _templateStoreDao.persist(templateStore);
+
+                            List<VMTemplateDetailVO> details = new ArrayList<VMTemplateDetailVO>();
+                            details.add(new VMTemplateDetailVO(rootTemplate.getId(), "child-datadisk-template",
template.getUuid(), true));
+                            details.add(new VMTemplateDetailVO(template.getId(), "parent-vm-template",
rootTemplate.getUuid(), true));
+                            _templateDetailsDao.saveDetails(details);
+                            diskNumber++;
+                        }
+                    }
+                }
+            */}
+        } catch (Exception ex) {
+            s_logger.debug("Unable to analyze " + data.getType().toString() + ": " + data.getId(),
ex);
+            result.setResult(ex.toString());
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/637b94cf/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 f78f370..d476350 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
@@ -26,6 +26,7 @@ import com.cloud.agent.api.CreateVMSnapshotCommand;
 import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
 import com.cloud.agent.api.DeleteVMSnapshotCommand;
 import com.cloud.agent.api.RevertToVMSnapshotCommand;
+import com.cloud.agent.api.storage.AnalyzeTemplateCommand;
 import com.cloud.agent.api.storage.CopyVolumeCommand;
 import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
@@ -49,6 +50,8 @@ public interface VmwareStorageManager {
 
     Answer execute(VmwareHostService hostService, RevertToVMSnapshotCommand cmd);
 
+    Answer execute(VmwareHostService hostService, AnalyzeTemplateCommand cmd);
+
     boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCommand cmd);
 
     public void createOva(String path, String name);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/637b94cf/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 e37bf38..0b7bf67 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
@@ -61,6 +61,8 @@ import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
 import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
+import com.cloud.agent.api.storage.AnalyzeTemplateAnswer;
+import com.cloud.agent.api.storage.AnalyzeTemplateCommand;
 import com.cloud.agent.api.to.DataObjectType;
 import com.cloud.agent.api.to.DataStoreTO;
 import com.cloud.agent.api.to.DataTO;
@@ -80,6 +82,7 @@ import com.cloud.storage.JavaStorageLayer;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.StorageLayer;
 import com.cloud.storage.Volume;
+import com.cloud.storage.resource.VmwareStorageLayoutHelper;
 import com.cloud.storage.template.OVAProcessor;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
@@ -1494,4 +1497,71 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager
{
     private static String getVolumeRelativeDirInSecStroage(long volumeId) {
         return "volumes/" + volumeId;
     }
+
+    @Override
+    public Answer execute(VmwareHostService hostService, AnalyzeTemplateCommand cmd) {
+        List<TemplateObjectTO> templateList = new ArrayList<TemplateObjectTO>();
+        DataTO srcData = cmd.getData();
+        TemplateObjectTO template = (TemplateObjectTO)srcData;
+        DataStoreTO srcStore = srcData.getDataStore();
+        if (!(srcStore instanceof NfsTO)) {
+            return new AnalyzeTemplateAnswer("unsupported protocol");
+        }
+        NfsTO nfsImageStore = (NfsTO)srcStore;
+        String secondaryStorageUrl = nfsImageStore.getUrl();
+        assert (secondaryStorageUrl != null);
+
+        String templateUrl = secondaryStorageUrl + "/" + srcData.getPath();
+        Pair<String, String> templateInfo = VmwareStorageLayoutHelper.decodeTemplateRelativePathAndNameFromUrl(secondaryStorageUrl,
templateUrl, template.getName());
+
+        VmwareContext context = hostService.getServiceContext(cmd);
+        try {
+            VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
+            ManagedObjectReference morRp = hyperHost.getHyperHostOwnerResourcePool();
+            ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost,
srcStore.getUuid());
+            assert (morDs != null);
+            DatastoreMO datastoreMo = new DatastoreMO(context, morDs);
+            String secondaryMountPoint = _mountService.getMountPoint(secondaryStorageUrl);
+            s_logger.info("Secondary storage mount point: " + secondaryMountPoint);
+
+            String srcOVAFileName = VmwareStorageLayoutHelper.getTemplateOnSecStorageFilePath(secondaryMountPoint,
templateInfo.first(), templateInfo.second(),
+                        ImageFormat.OVA.getFileExtension());
+
+            String srcFileName = getOVFFilePath(srcOVAFileName);
+            if (srcFileName == null) {
+                Script command = new Script("tar", 0, s_logger);
+                command.add("--no-same-owner");
+                command.add("-xf", srcOVAFileName);
+                command.setWorkDir(secondaryMountPoint + "/" + templateInfo.first());
+                s_logger.info("Executing command: " + command.toString());
+                String result = command.execute();
+                if (result != null) {
+                    String msg = "Unable to unpack snapshot OVA file at: " + srcOVAFileName;
+                    s_logger.error(msg);
+                    throw new Exception(msg);
+                }
+            }
+
+            srcFileName = getOVFFilePath(srcOVAFileName);
+            if (srcFileName == null) {
+                String msg = "Unable to locate OVF file in template package directory: "
+ srcOVAFileName;
+                s_logger.error(msg);
+                throw new Exception(msg);
+            }
+
+            // readOVF(hyperHost, srcFileName, datastoreMo, morRp, hyperHost.getMor());
+
+            // Temp answer
+            TemplateObjectTO dataDiskTemplate = new TemplateObjectTO();
+            dataDiskTemplate.setPath("temp-path");
+            dataDiskTemplate.setPhysicalSize(1L);
+            dataDiskTemplate.setIsBootable(false);
+            templateList.add(dataDiskTemplate);
+        } catch (Exception e) {
+            String msg = "Analyze template failed due to " + e.getMessage();
+            s_logger.error(msg);
+            return new AnalyzeTemplateAnswer(msg);
+        }
+        return new AnalyzeTemplateAnswer(templateList);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/637b94cf/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 baaaf21..b302e61 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
@@ -34,6 +34,7 @@ import com.cloud.agent.api.Command;
 import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
 import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
 import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
+import com.cloud.agent.api.storage.AnalyzeTemplateCommand;
 import com.cloud.agent.api.storage.CopyVolumeCommand;
 import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
@@ -100,7 +101,10 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
                 answer = storageSubsystemHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
             } else if (cmd instanceof CreateEntityDownloadURLCommand) {
                 answer = execute((CreateEntityDownloadURLCommand)cmd);
-            } else {
+            } else if(cmd instanceof AnalyzeTemplateCommand) {
+                answer = execute((AnalyzeTemplateCommand)cmd);
+            }
+            else {
                 answer = _resource.defaultAction(cmd);
             }
 
@@ -176,6 +180,11 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
         return _storageMgr.execute(this, cmd);
     }
 
+    private Answer execute(AnalyzeTemplateCommand cmd) {
+        _storageMgr.execute(this, cmd);
+        return _resource.defaultAction(cmd);
+    }
+
     @Override
     public VmwareContext getServiceContext(Command cmd) {
         String guid = cmd.getContextParam("guid");


Mime
View raw message