Spaceman1984 commented on a change in pull request #3748: Systemvm template api (WIP) URL: https://github.com/apache/cloudstack/pull/3748#discussion_r358663124
########## File path: server/src/main/java/com/cloud/storage/download/managementserver/system/SystemTemplateDownloader.java ########## @@ -0,0 +1,267 @@ +// +// 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.download.managementserver.system; + +import com.cloud.storage.VMTemplateVO; +import com.cloud.storage.download.managementserver.TemplateDownloader; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.utils.UriUtils; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.script.Script; +import org.apache.cloudstack.utils.security.DigestHelper; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.NoSuchAlgorithmException; +import java.util.Optional; +import java.util.UUID; + +public abstract class SystemTemplateDownloader implements TemplateDownloader { + + private String destPoolPath; + private String downloadedFilePath; + private String installPath; + private VirtualMachineTemplate template; + private VMTemplateVO templateVO; + private boolean redownload = false; + private String srcHost; + private String srcPath; + + public static final Logger s_logger = Logger.getLogger(SystemTemplateDownloader.class.getName()); + private static String systemInstallDir = "template" + File.separator + "tmpl" + File.separator + "1"; + private static final String systemPropertiesFileName = "template.properties"; + + protected SystemTemplateDownloader(VirtualMachineTemplate template, VMTemplateVO templateVO, String destPoolPath) { + this.template = template; + this.templateVO = templateVO; + this.destPoolPath = destPoolPath; + parseUrl(); + } + + /** + * Return download path to download template + */ + protected static String getDownloadPath(Long templateId) { + return systemInstallDir + File.separator + templateId; + } + + /** + * Create folder on path if it does not exist + */ + protected void createFolder(String path) { + try { + Files.createDirectories(Paths.get(path)); + } catch (IOException e) { + s_logger.error(String.format("Unable to create directory %s for template %s: %s%n", path, getTemplate().getUrl(), e.toString())); Review comment: Done ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services