rhtyd commented on a change in pull request #4329:
URL: https://github.com/apache/cloudstack/pull/4329#discussion_r697268660



##########
File path: 
engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java
##########
@@ -0,0 +1,778 @@
+// 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.upgrade;
+
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.dc.dao.ClusterDaoImpl;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.DataCenterDaoImpl;
+import com.cloud.hypervisor.Hypervisor;
+import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.Storage;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.VMTemplateStorageResourceAssoc;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.storage.dao.VMTemplateDaoImpl;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.upgrade.dao.BasicTemplateDataStoreDaoImpl;
+import com.cloud.user.Account;
+import com.cloud.utils.DateUtil;
+import com.cloud.utils.Pair;
+import com.cloud.utils.UriUtils;
+import com.cloud.utils.db.GlobalLock;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionStatus;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+import com.cloud.vm.dao.VMInstanceDao;
+import com.cloud.vm.dao.VMInstanceDaoImpl;
+import 
org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDaoImpl;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.log4j.Logger;
+import org.ini4j.Ini;
+
+import javax.inject.Inject;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.sql.Connection;
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+public class SystemVmTemplateRegistration {
+    private static final Logger LOGGER = 
Logger.getLogger(SystemVmTemplateRegistration.class);
+    private static final String MOUNT_COMMAND = "sudo mount -t nfs %s %s";
+    private static final String UMOUNT_COMMAND = "sudo umount %s";
+    private static final String RELATIVE_TEMPLATE_PATH = 
"./engine/schema/dist/systemvm-templates/";
+    private static final String ABSOLUTE_TEMPLATE_PATH = 
"/usr/share/cloudstack-management/templates/systemvm/";
+    private static final String TEMPLATES_PATH = fetchTemplatesPath();
+    private static final String METADATA_FILE_NAME = "metadata.ini";
+    private static final String METADATA_FILE = TEMPLATES_PATH + 
METADATA_FILE_NAME;
+    public static final String TEMPORARY_SECONDARY_STORE = 
"/tmp/tmpSecStorage";
+    private static final String PARTIAL_TEMPLATE_FOLDER = 
String.format("/template/tmpl/%d/", Account.ACCOUNT_ID_SYSTEM);
+    private static final String FETCH_REGISTERED_TEMPLATE_INSTALL_PATH = 
"SELECT install_path FROM `cloud`.`template_store_ref` where template_id = ? 
LIMIT 1";
+    private static final String storageScriptsDir = 
"scripts/storage/secondary";
+    private static final Integer SCRIPT_TIMEOUT = 1800000;
+    private static final Integer LOCK_WAIT_TIMEOUT = 1200;
+    private static final Integer TOKEN_LENGTH = 10;
+
+    public static String CS_MAJOR_VERSION = null;
+    public static String CS_TINY_VERSION = null;
+
+    @Inject
+    DataCenterDao dataCenterDao;
+    @Inject
+    VMTemplateDao vmTemplateDao;
+    @Inject
+    TemplateDataStoreDao templateDataStoreDao;
+    @Inject
+    VMInstanceDao vmInstanceDao;
+    @Inject
+    ImageStoreDao imageStoreDao;
+    @Inject
+    ClusterDao clusterDao;
+    @Inject
+    ConfigurationDao configurationDao;
+
+    public SystemVmTemplateRegistration() {
+        dataCenterDao = new DataCenterDaoImpl();
+        vmTemplateDao = new VMTemplateDaoImpl();
+        templateDataStoreDao = new BasicTemplateDataStoreDaoImpl();
+        vmInstanceDao = new VMInstanceDaoImpl();
+        imageStoreDao = new ImageStoreDaoImpl();
+        clusterDao = new ClusterDaoImpl();
+        configurationDao = new ConfigurationDaoImpl();
+    }
+
+    private static class SystemVMTemplateDetails {
+        Long id;
+        String uuid;
+        String name;
+        String uniqueName;
+        Date created;
+        String url;
+        String checksum;
+        ImageFormat format;
+        Integer guestOsId;
+        Hypervisor.HypervisorType hypervisorType;
+        Long storeId;
+        Long size;
+        Long physicalSize;
+        String installPath;
+        boolean deployAsIs;
+        Date updated;
+
+        SystemVMTemplateDetails(String uuid, String name, Date created, String 
url, String checksum,
+                                ImageFormat format, Integer guestOsId, 
Hypervisor.HypervisorType hypervisorType,
+                                Long storeId) {
+            this.uuid = uuid;
+            this.name = name;
+            this.created = created;
+            this.url = url;
+            this.checksum = checksum;
+            this.format = format;
+            this.guestOsId = guestOsId;
+            this.hypervisorType = hypervisorType;
+            this.storeId = storeId;
+        }
+
+        public void setId(Long id) {
+            this.id = id;
+        }
+
+        public Long getId() {
+            return id;
+        }
+
+        public String getUuid() {
+            return uuid;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public Date getCreated() {
+            return created;
+        }
+
+        public String getUrl() {
+            return url;
+        }
+
+        public String getChecksum() {
+            return checksum;
+        }
+
+        public ImageFormat getFormat() {
+            return format;
+        }
+
+        public Integer getGuestOsId() {
+            return guestOsId;
+        }
+
+        public Hypervisor.HypervisorType getHypervisorType() {
+            return hypervisorType;
+        }
+
+        public Long getStoreId() {
+            return storeId;
+        }
+
+        public Long getSize() {
+            return size;
+        }
+
+        public void setSize(Long size) {
+            this.size = size;
+        }
+
+        public Long getPhysicalSize() {
+            return physicalSize;
+        }
+
+        public void setPhysicalSize(Long physicalSize) {
+            this.physicalSize = physicalSize;
+        }
+
+        public String getInstallPath() {
+            return installPath;
+        }
+
+        public void setInstallPath(String installPath) {
+            this.installPath = installPath;
+        }
+
+        public String getUniqueName() {
+            return uniqueName;
+        }
+
+        public void setUniqueName(String uniqueName) {
+            this.uniqueName = uniqueName;
+        }
+
+        public boolean isDeployAsIs() {
+            return deployAsIs;
+        }
+
+        public void setDeployAsIs(boolean deployAsIs) {
+            this.deployAsIs = deployAsIs;
+        }
+
+        public Date getUpdated() {
+            return updated;
+        }
+
+        public void setUpdated(Date updated) {
+            this.updated = updated;
+        }
+    }
+
+    public static final List<Hypervisor.HypervisorType> hypervisorList = 
Arrays.asList(Hypervisor.HypervisorType.KVM,
+            Hypervisor.HypervisorType.VMware,
+            Hypervisor.HypervisorType.XenServer,
+            Hypervisor.HypervisorType.Hyperv,
+            Hypervisor.HypervisorType.LXC,
+            Hypervisor.HypervisorType.Ovm3
+    );
+
+    public static final Map<Hypervisor.HypervisorType, String> 
NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>();
+    public static final Map<Hypervisor.HypervisorType, String> FileNames = new 
HashMap<Hypervisor.HypervisorType, String>();
+    public static final Map<Hypervisor.HypervisorType, String> NewTemplateUrl 
= new HashMap<Hypervisor.HypervisorType, String>();
+    public static final Map<Hypervisor.HypervisorType, String> 
NewTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>();
+
+    public static final Map<Hypervisor.HypervisorType, String> 
routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, 
String>() {
+        {
+            put(Hypervisor.HypervisorType.KVM, "router.template.kvm");
+            put(Hypervisor.HypervisorType.VMware, "router.template.vmware");
+            put(Hypervisor.HypervisorType.XenServer, 
"router.template.xenserver");
+            put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv");
+            put(Hypervisor.HypervisorType.LXC, "router.template.lxc");
+            put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3");
+        }
+    };
+
+    public static final Map<Hypervisor.HypervisorType, Integer> 
hypervisorGuestOsMap = new HashMap<Hypervisor.HypervisorType, Integer>() {
+        {
+            put(Hypervisor.HypervisorType.KVM, 15);

Review comment:
       Put a comment to explain the guest OS ID




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to