Skip to content

Commit c09888f

Browse files
author
Kishan Kavala
committed
CLOUDSTACK-7237 : Added TAR image processor for templates with tar extension
1 parent 6bccf5f commit c09888f

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.storage.template;
21+
22+
import com.cloud.storage.Storage.ImageFormat;
23+
import com.cloud.storage.StorageLayer;
24+
import com.cloud.utils.component.AdapterBase;
25+
import org.apache.log4j.Logger;
26+
27+
import javax.ejb.Local;
28+
import javax.naming.ConfigurationException;
29+
import java.io.File;
30+
import java.util.Map;
31+
32+
@Local(value = Processor.class)
33+
public class TARProcessor extends AdapterBase implements Processor {
34+
private static final Logger s_logger = Logger.getLogger(TARProcessor.class);
35+
36+
private StorageLayer _storage;
37+
38+
@Override
39+
public FormatInfo process(String templatePath, ImageFormat format, String templateName) {
40+
if (format != null) {
41+
s_logger.debug("We currently don't handle conversion from " + format + " to TAR.");
42+
return null;
43+
}
44+
45+
String tarPath = templatePath + File.separator + templateName + "." + ImageFormat.TAR.getFileExtension();
46+
47+
if (!_storage.exists(tarPath)) {
48+
s_logger.debug("Unable to find the tar file: " + tarPath);
49+
return null;
50+
}
51+
52+
FormatInfo info = new FormatInfo();
53+
info.format = ImageFormat.TAR;
54+
info.filename = templateName + "." + ImageFormat.TAR.getFileExtension();
55+
56+
File tarFile = _storage.getFile(tarPath);
57+
58+
info.size = _storage.getSize(tarPath);
59+
60+
info.virtualSize = getVirtualSize(tarFile);
61+
62+
return info;
63+
}
64+
65+
@Override
66+
public long getVirtualSize(File file) {
67+
return file.length();
68+
}
69+
70+
@Override
71+
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
72+
_storage = (StorageLayer)params.get(StorageLayer.InstanceConfigKey);
73+
if (_storage == null) {
74+
throw new ConfigurationException("Unable to get storage implementation");
75+
}
76+
77+
return true;
78+
}
79+
}

services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
import com.cloud.storage.template.Processor.FormatInfo;
122122
import com.cloud.storage.template.QCOW2Processor;
123123
import com.cloud.storage.template.RawImageProcessor;
124+
import com.cloud.storage.template.TARProcessor;
124125
import com.cloud.storage.template.TemplateLocation;
125126
import com.cloud.storage.template.TemplateProp;
126127
import com.cloud.storage.template.VhdProcessor;
@@ -813,6 +814,8 @@ protected long getVirtualSize(File file, ImageFormat format) {
813814
processor = new RawImageProcessor();
814815
} else if (format == ImageFormat.VMDK) {
815816
processor = new VmdkProcessor();
817+
} if (format == ImageFormat.TAR) {
818+
processor = new TARProcessor();
816819
}
817820

818821
if (processor == null) {

services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import com.cloud.storage.template.Processor.FormatInfo;
6868
import com.cloud.storage.template.QCOW2Processor;
6969
import com.cloud.storage.template.RawImageProcessor;
70+
import com.cloud.storage.template.TARProcessor;
7071
import com.cloud.storage.template.S3TemplateDownloader;
7172
import com.cloud.storage.template.ScpTemplateDownloader;
7273
import com.cloud.storage.template.TemplateConstants;
@@ -996,6 +997,10 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
996997
processor.configure("Raw Image Processor", params);
997998
_processors.put("Raw Image Processor", processor);
998999

1000+
processor = new TARProcessor();
1001+
processor.configure("TAR Processor", params);
1002+
_processors.put("TAR Processor", processor);
1003+
9991004
_templateDir = (String)params.get("public.templates.root.dir");
10001005
if (_templateDir == null) {
10011006
_templateDir = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR;

0 commit comments

Comments
 (0)