Modify DownloadCommand to pass DataTO.

This commit is contained in:
Min Chen 2013-05-02 23:05:19 -07:00
parent 87fafb7287
commit c60c373a38
42 changed files with 522 additions and 342 deletions

View File

@ -0,0 +1,39 @@
// 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;
/**
* Password authentication
*/
public class PasswordAuth {
String userName;
String password;
public PasswordAuth() {
}
public PasswordAuth(String user, String password) {
this.userName = user;
this.password = password;
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
}

View File

@ -0,0 +1,72 @@
// 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.net.URI;
/**
* Download Proxy
*/
public class Proxy {
private String _host;
private int _port;
private String _userName;
private String _password;
public Proxy() {
}
public Proxy(String host, int port, String userName, String password) {
this._host = host;
this._port = port;
this._userName = userName;
this._password = password;
}
public Proxy(URI uri) {
this._host = uri.getHost();
this._port = uri.getPort() == -1 ? 3128 : uri.getPort();
String userInfo = uri.getUserInfo();
if (userInfo != null) {
String[] tokens = userInfo.split(":");
if (tokens.length == 1) {
this._userName = userInfo;
this._password = "";
} else if (tokens.length == 2) {
this._userName = tokens[0];
this._password = tokens[1];
}
}
}
public String getHost() {
return _host;
}
public int getPort() {
return _port;
}
public String getUserName() {
return _userName;
}
public String getPassword() {
return _password;
}
}

View File

@ -18,7 +18,6 @@ package com.cloud.agent.api.storage;
import org.apache.cloudstack.api.InternalIdentity;
import com.cloud.agent.api.storage.DownloadCommand.PasswordAuth;
import com.cloud.agent.api.to.TemplateTO;
import com.cloud.storage.Upload.Type;
import com.cloud.template.VirtualMachineTemplate;

View File

@ -27,6 +27,8 @@ import java.util.Random;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
@ -48,8 +50,6 @@ import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
import com.cloud.agent.api.storage.DeleteTemplateCommand;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.UploadCommand;
import com.cloud.agent.api.storage.ssCommand;
import com.cloud.host.Host;

View File

@ -11,13 +11,13 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import org.apache.cloudstack.storage.command.DownloadSystemTemplateCommand;
import org.springframework.stereotype.Component;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadSystemTemplateCommand;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.agent.api.to.S3TO;

View File

@ -21,6 +21,8 @@ import java.util.Map;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
@ -35,8 +37,6 @@ import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.SecStorageSetupCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.ListTemplateAnswer;
import com.cloud.agent.api.storage.ListTemplateCommand;
import com.cloud.agent.api.storage.ssCommand;

View File

@ -50,6 +50,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
import org.apache.cloudstack.storage.command.CopyCommand;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@ -87,15 +90,12 @@ import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
import com.cloud.agent.api.storage.DeleteTemplateCommand;
import com.cloud.agent.api.storage.DeleteVolumeCommand;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.ListTemplateAnswer;
import com.cloud.agent.api.storage.ListTemplateCommand;
import com.cloud.agent.api.storage.ListVolumeAnswer;
import com.cloud.agent.api.storage.ListVolumeCommand;
import com.cloud.agent.api.storage.UploadCommand;
import com.cloud.agent.api.storage.ssCommand;
import com.cloud.agent.api.storage.DownloadCommand.ResourceType;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.agent.api.to.S3TO;

View File

@ -18,10 +18,11 @@ package com.cloud.storage.template;
import java.util.Map;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadCommand.Proxy;
import com.cloud.agent.api.storage.DownloadCommand.ResourceType;
import com.cloud.agent.api.storage.Proxy;
import com.cloud.agent.api.to.S3TO;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.Storage.ImageFormat;

View File

@ -47,6 +47,10 @@ import java.util.concurrent.Executors;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
@ -56,11 +60,7 @@ import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadCommand.Proxy;
import com.cloud.agent.api.storage.DownloadCommand.ResourceType;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import com.cloud.agent.api.storage.Proxy;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.S3TO;
import com.cloud.exception.InternalErrorException;
@ -649,29 +649,8 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
}
String installPathPrefix = null;
String installPathPrefix = cmd.getInstallPath();
DataStoreTO dstore = cmd.getDataStore();
if (dstore instanceof S3TO) {
if (resourceType == ResourceType.TEMPLATE) {
// convention is no / in the end for install path based on
// S3Utils implementation.
// template key is
// TEMPLATE_ROOT_DIR/account_id/template_id/template_name, by
// adding template_name in the key, I can avoid generating a
// template.properties file
// for listTemplateCommand.
installPathPrefix = join(asList(_templateDir, cmd.getAccountId(), cmd.getId(), cmd.getName()), S3Utils.SEPARATOR);
} else {
installPathPrefix = join(asList(_volumeDir, cmd.getAccountId(), cmd.getId()), S3Utils.SEPARATOR);
}
} else {
if (ResourceType.TEMPLATE == resourceType) {
installPathPrefix = resource.getRootDir(cmd) + File.separator + _templateDir;
} else {
installPathPrefix = resource.getRootDir(cmd) + File.separator + _volumeDir;
}
}
String user = null;
String password = null;
if (cmd.getAuth() != null) {

View File

@ -29,6 +29,7 @@ import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.Date;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import org.apache.commons.httpclient.ChunkedInputStream;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
@ -45,8 +46,7 @@ import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.log4j.Logger;
import com.cloud.agent.api.storage.DownloadCommand.Proxy;
import com.cloud.agent.api.storage.DownloadCommand.ResourceType;
import com.cloud.agent.api.storage.Proxy;
import com.cloud.storage.StorageLayer;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.Pair;
@ -79,7 +79,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
private ResourceType resourceType = ResourceType.TEMPLATE;
private final HttpMethodRetryHandler myretryhandler;
public HttpTemplateDownloader (StorageLayer storageLayer, String downloadUrl, String toDir, DownloadCompleteCallback callback, long maxTemplateSizeInBytes, String user, String password, Proxy proxy, ResourceType resourceType) {
this._storage = storageLayer;
@ -88,7 +88,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
this.status = TemplateDownloader.Status.NOT_STARTED;
this.resourceType = resourceType;
this.MAX_TEMPLATE_SIZE_IN_BYTES = maxTemplateSizeInBytes;
this.totalBytes = 0;
this.client = new HttpClient(s_httpClientManager);
@ -114,7 +114,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
return false;
}
};
try {
this.request = new GetMethod(downloadUrl);
this.request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler);
@ -122,14 +122,14 @@ public class HttpTemplateDownloader implements TemplateDownloader {
//this.request.setFollowRedirects(false);
File f = File.createTempFile("dnld", "tmp_", new File(toDir));
if (_storage != null) {
_storage.setWorldReadableAndWriteable(f);
}
toFile = f.getAbsolutePath();
Pair<String, Integer> hostAndPort = validateUrl(downloadUrl);
if (proxy != null) {
client.getHostConfiguration().setProxy(proxy.getHost(), proxy.getPort());
if (proxy.getUserName() != null) {
@ -144,7 +144,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
} else {
s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second());
}
}
} catch (IllegalArgumentException iae) {
errorString = iae.getMessage();
status = TemplateDownloader.Status.UNRECOVERABLE_ERROR;
@ -157,7 +157,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
s_logger.warn("throwable caught ", th);
}
}
private Pair<String, Integer> validateUrl(String url) throws IllegalArgumentException {
try {
@ -169,13 +169,13 @@ public class HttpTemplateDownloader implements TemplateDownloader {
if (!(port == 80 || port == 443 || port == -1)) {
throw new IllegalArgumentException("Only ports 80 and 443 are allowed");
}
if (port == -1 && uri.getScheme().equalsIgnoreCase("https")) {
port = 443;
} else if (port == -1 && uri.getScheme().equalsIgnoreCase("http")) {
port = 80;
}
String host = uri.getHost();
try {
InetAddress hostAddr = InetAddress.getByName(host);
@ -197,7 +197,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
throw new IllegalArgumentException(use.getMessage());
}
}
@Override
public long download(boolean resume, DownloadCompleteCallback callback) {
switch (status) {
@ -211,17 +211,17 @@ public class HttpTemplateDownloader implements TemplateDownloader {
int bytes=0;
File file = new File(toFile);
try {
long localFileSize = 0;
if (file.exists() && resume) {
localFileSize = file.length();
s_logger.info("Resuming download to file (current size)=" + localFileSize);
}
Date start = new Date();
int responseCode=0;
if (localFileSize > 0 ) {
// require partial content support for resume
request.addRequestHeader("Range", "bytes=" + localFileSize + "-");
@ -235,7 +235,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
errorString = " HTTP Server returned " + responseCode + " (expected 200 OK) ";
return 0; //FIXME: retry?
}
Header contentLengthHeader = request.getResponseHeader("Content-Length");
boolean chunked = false;
long remoteSize2 = 0;
@ -255,26 +255,26 @@ public class HttpTemplateDownloader implements TemplateDownloader {
if (remoteSize == 0) {
remoteSize = remoteSize2;
}
if (remoteSize > MAX_TEMPLATE_SIZE_IN_BYTES) {
s_logger.info("Remote size is too large: " + remoteSize + " , max=" + MAX_TEMPLATE_SIZE_IN_BYTES);
status = Status.UNRECOVERABLE_ERROR;
errorString = "Download file size is too large";
return 0;
}
if (remoteSize == 0) {
remoteSize = MAX_TEMPLATE_SIZE_IN_BYTES;
}
InputStream in = !chunked?new BufferedInputStream(request.getResponseBodyAsStream())
: new ChunkedInputStream(request.getResponseBodyAsStream());
RandomAccessFile out = new RandomAccessFile(file, "rwd");
out.seek(localFileSize);
s_logger.info("Starting download from " + getDownloadUrl() + " to " + toFile + " remoteSize=" + remoteSize + " , max size=" + MAX_TEMPLATE_SIZE_IN_BYTES);
byte[] block = new byte[CHUNK_SIZE];
long offset=0;
boolean done=false;
@ -298,7 +298,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
errorString = "Downloaded " + totalBytes + " bytes " + downloaded;
downloadTime += finish.getTime() - start.getTime();
out.close();
return totalBytes;
}catch (HttpException hte) {
status = TemplateDownloader.Status.UNRECOVERABLE_ERROR;
@ -336,8 +336,8 @@ public class HttpTemplateDownloader implements TemplateDownloader {
public long getDownloadTime() {
return downloadTime;
}
public long getDownloadedBytes() {
return totalBytes;
}
@ -375,7 +375,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
if (remoteSize == 0) {
return 0;
}
return (int)(100.0*totalBytes/remoteSize);
}
@ -388,7 +388,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
errorString = "Failed to install: " + t.getMessage();
status = TemplateDownloader.Status.UNRECOVERABLE_ERROR;
}
}
@Override
@ -424,10 +424,10 @@ public class HttpTemplateDownloader implements TemplateDownloader {
return toDir;
}
public long getMaxTemplateSizeInBytes() {
public long getMaxTemplateSizeInBytes() {
return this.MAX_TEMPLATE_SIZE_IN_BYTES;
}
public static void main(String[] args) {
String url ="http:// dev.mysql.com/get/Downloads/MySQL-5.0/mysql-noinstall-5.0.77-win32.zip/from/http://mirror.services.wisc.edu/mysql/";
try {

View File

@ -32,6 +32,7 @@ import java.net.URL;
import java.net.UnknownHostException;
import java.util.Date;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import org.apache.commons.httpclient.ChunkedInputStream;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
@ -52,8 +53,7 @@ import com.amazonaws.services.s3.model.ProgressEvent;
import com.amazonaws.services.s3.model.ProgressListener;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.StorageClass;
import com.cloud.agent.api.storage.DownloadCommand.Proxy;
import com.cloud.agent.api.storage.DownloadCommand.ResourceType;
import com.cloud.agent.api.storage.Proxy;
import com.cloud.agent.api.to.S3TO;
import com.cloud.utils.Pair;
import com.cloud.utils.S3Utils;

View File

@ -24,9 +24,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import org.apache.log4j.Logger;
import com.cloud.agent.api.storage.DownloadCommand.ResourceType;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageLayer;
import com.cloud.storage.template.Processor.FormatInfo;

View File

@ -20,6 +20,8 @@ import java.nio.ByteBuffer;
import junit.framework.TestCase;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Assert;
@ -30,7 +32,6 @@ import com.cloud.agent.api.GetHostStatsCommand;
import com.cloud.agent.api.SecStorageFirewallCfgCommand;
import com.cloud.agent.api.UpdateHostPasswordCommand;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.exception.UnsupportedVersionException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@ -132,7 +133,10 @@ public class RequestTest extends TestCase {
s_logger.info("Testing Download answer");
VMTemplateVO template = new VMTemplateVO(1, "templatename", ImageFormat.QCOW2, true, true, true, TemplateType.USER, "url", true, 32, 1, "chksum", "displayText", true, 30, true,
HypervisorType.KVM, null);
DownloadCommand cmd = new DownloadCommand(new NfsTO("secUrl", DataStoreRole.Image), template, 30000000l);
NfsTO nfs = new NfsTO("secUrl", DataStoreRole.Image);
TemplateObjectTO to = new TemplateObjectTO(template);
to.setImageDataStore(nfs);
DownloadCommand cmd = new DownloadCommand(to, 30000000l);
Request req = new Request(1, 1, cmd, true);
req.logD("Debug for Download");

View File

@ -18,8 +18,6 @@
*/
package org.apache.cloudstack.engine.subsystem.api.storage;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
import com.cloud.agent.api.Answer;
public interface DataObject {
@ -29,7 +27,7 @@ public interface DataObject {
public DataStore getDataStore();
public Long getSize();
public DataObjectType getType();
public DiskFormat getFormat();
//public DiskFormat getFormat();
public String getUuid();
public void processEvent(ObjectInDataStoreStateMachine.Event event);
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer);

View File

@ -18,7 +18,9 @@
*/
package org.apache.cloudstack.engine.subsystem.api.storage;
public interface TemplateInfo extends DataObject {
import com.cloud.template.VirtualMachineTemplate;
public interface TemplateInfo extends DataObject, VirtualMachineTemplate {
public String getUniqueName();
public String getInstallPath();
}

View File

@ -28,4 +28,5 @@ public interface VolumeInfo extends DataObject, Volume {
public HypervisorType getHypervisorType();
public Long getLastPoolId();
public String getAttachedVmName();
public String getInstallPath();
}

View File

@ -14,91 +14,27 @@
// 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.net.URI;
package org.apache.cloudstack.storage.command;
import org.apache.cloudstack.api.InternalIdentity;
import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import com.cloud.agent.api.storage.AbstractDownloadCommand;
import com.cloud.agent.api.storage.PasswordAuth;
import com.cloud.agent.api.storage.Proxy;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Volume;
import com.cloud.template.VirtualMachineTemplate;
public class DownloadCommand extends AbstractDownloadCommand implements InternalIdentity {
public static class PasswordAuth {
String userName;
String password;
public PasswordAuth() {
}
public PasswordAuth(String user, String password) {
this.userName = user;
this.password = password;
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
}
public static enum ResourceType {
VOLUME, TEMPLATE
}
public static class Proxy {
private String _host;
private int _port;
private String _userName;
private String _password;
public Proxy() {
}
public Proxy(String host, int port, String userName, String password) {
this._host = host;
this._port = port;
this._userName = userName;
this._password = password;
}
public Proxy(URI uri) {
this._host = uri.getHost();
this._port = uri.getPort() == -1 ? 3128 : uri.getPort();
String userInfo = uri.getUserInfo();
if (userInfo != null) {
String[] tokens = userInfo.split(":");
if (tokens.length == 1) {
this._userName = userInfo;
this._password = "";
} else if (tokens.length == 2) {
this._userName = tokens[0];
this._password = tokens[1];
}
}
}
public String getHost() {
return _host;
}
public int getPort() {
return _port;
}
public String getUserName() {
return _userName;
}
public String getPassword() {
return _password;
}
}
private boolean hvm;
private String description;
private String checksum;
@ -107,6 +43,7 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal
private Long maxDownloadSizeInBytes = null;
private long id;
private ResourceType resourceType = ResourceType.TEMPLATE;
private String installPath;
private DataStoreTO _store;
protected DownloadCommand() {
@ -123,46 +60,39 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal
this.setSecUrl(that.getSecUrl());
this.maxDownloadSizeInBytes = that.getMaxDownloadSizeInBytes();
this.resourceType = that.resourceType;
this.installPath = that.installPath;
this._store = that._store;
}
public DownloadCommand(DataStoreTO store, VirtualMachineTemplate template, Long maxDownloadSizeInBytes) {
super(template.getUniqueName(), template.getUrl(), template.getFormat(), template.getAccountId());
this._store = store;
public DownloadCommand(TemplateObjectTO template, Long maxDownloadSizeInBytes) {
super(template.getName(), template.getOrigUrl(), template.getFormat(), template.getAccountId());
this._store = template.getDataStore();
this.installPath = template.getPath();
this.hvm = template.isRequiresHvm();
this.checksum = template.getChecksum();
this.id = template.getId();
this.description = template.getDisplayText();
if (store instanceof NfsTO) {
this.setSecUrl(((NfsTO) store).getUrl());
this.description = template.getDescription();
if (_store instanceof NfsTO) {
this.setSecUrl(((NfsTO) _store).getUrl());
}
this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
}
public DownloadCommand(DataStoreTO store, Volume volume, Long maxDownloadSizeInBytes, String checkSum, String url, ImageFormat format) {
super(volume.getName(), url, format, volume.getAccountId());
//this.hvm = volume.isRequiresHvm();
this.checksum = checkSum;
this.id = volume.getId();
this._store = store;
this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
this.resourceType = ResourceType.VOLUME;
}
public DownloadCommand(DataStoreTO store, String url, VirtualMachineTemplate template, String user, String passwd, Long maxDownloadSizeInBytes) {
super(template.getUniqueName(), url, template.getFormat(), template.getAccountId());
this._store = store;
this.hvm = template.isRequiresHvm();
this.checksum = template.getChecksum();
this.id = template.getId();
this.description = template.getDisplayText();
if (store instanceof NfsTO) {
this.setSecUrl(((NfsTO) store).getUrl());
}
this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
public DownloadCommand(TemplateObjectTO template, String user, String passwd, Long maxDownloadSizeInBytes) {
this(template, maxDownloadSizeInBytes);
auth = new PasswordAuth(user, passwd);
}
public long getId() {
public DownloadCommand(VolumeObjectTO volume, Long maxDownloadSizeInBytes, String checkSum, String url, ImageFormat format) {
super(volume.getName(), url, format, volume.getAccountId());
this.checksum = checkSum;
this.id = volume.getVolumeId();
this._store = volume.getDataStore();
this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
this.resourceType = ResourceType.VOLUME;
}
@Override
public long getId() {
return id;
}
@ -237,6 +167,16 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal
}
public String getInstallPath() {
return installPath;
}
public void setInstallPath(String installPath) {
this.installPath = installPath;
}
}

View File

@ -14,7 +14,8 @@
// 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;
package org.apache.cloudstack.storage.command;

View File

@ -14,32 +14,18 @@
// 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;
package org.apache.cloudstack.storage.command;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.storage.DownloadCommand.Proxy;
import com.cloud.agent.api.storage.PasswordAuth;
import com.cloud.agent.api.storage.Proxy;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.template.VirtualMachineTemplate;
public class DownloadSystemTemplateCommand extends Command {
public static class PasswordAuth {
String userName;
String password;
public PasswordAuth() {
}
public PasswordAuth(String user, String password) {
this.userName = user;
this.password = password;
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
}
private PasswordAuth auth;

View File

@ -23,40 +23,86 @@ import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
import org.apache.cloudstack.storage.image.datastore.ImageStoreInfo;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.template.VirtualMachineTemplate;
public class TemplateObjectTO implements DataTO {
private String path;
private String origUrl;
private String uuid;
private DiskFormat diskType;
private long id;
private ImageFormat format;
private long accountId;
private String checksum;
private boolean hvm;
private String displayText;
private DataStoreTO imageDataStore;
private String name;
public TemplateObjectTO() {
}
public TemplateObjectTO(VirtualMachineTemplate template){
this.uuid = template.getUuid();
this.id = template.getId();
this.origUrl = template.getUrl();
this.displayText = template.getDisplayText();
this.checksum = template.getChecksum();
this.hvm = template.isRequiresHvm();
this.accountId = template.getAccountId();
this.name = template.getUniqueName();
this.format = template.getFormat();
}
public TemplateObjectTO(TemplateInfo template) {
this.path = template.getInstallPath();
this.uuid = template.getUuid();
this.origUrl = template.getUri();
//this.diskType = template.getDiskType();
this.imageDataStore = template.getDataStore().getTO();
this.id = template.getId();
this.origUrl = template.getUrl();
this.displayText = template.getDisplayText();
this.checksum = template.getChecksum();
this.hvm = template.isRequiresHvm();
this.accountId = template.getAccountId();
this.name = template.getUniqueName();
this.format = template.getFormat();
this.imageDataStore = template.getDataStore().getTO();
}
@Override
public String getPath() {
return this.path;
}
public String getUuid() {
return this.uuid;
}
public DiskFormat getDiskType() {
return this.diskType;
public long getId() {
return id;
}
public ImageFormat getFormat() {
return format;
}
public long getAccountId() {
return accountId;
}
public String getChecksum() {
return checksum;
}
public boolean isRequiresHvm() {
return hvm;
}
public void setRequiresHvm(boolean hvm){
this.hvm = hvm;
}
public String getDescription() {
return displayText;
}
public void setDescription(String desc){
this.displayText = desc;
}
public DataStoreTO getImageDataStore() {
return this.imageDataStore;
}
@ -92,4 +138,18 @@ public class TemplateObjectTO implements DataTO {
public void setOrigUrl(String origUrl) {
this.origUrl = origUrl;
}
public void setFormat(ImageFormat format) {
this.format = format;
}
public void setAccountId(long accountId) {
this.accountId = accountId;
}
public void setChecksum(String checksum) {
this.checksum = checksum;
}
public void setImageDataStore(DataStoreTO imageDataStore) {
this.imageDataStore = imageDataStore;
}
}

View File

@ -33,16 +33,16 @@ public class VolumeObjectTO implements DataTO {
private long size;
private String path;
private Long volumeId;
private long accountId;
public VolumeObjectTO() {
}
public VolumeObjectTO(VolumeInfo volume) {
this.uuid = volume.getUuid();
this.path = volume.getUri();
//this.volumeType = volume.getType();
//this.diskType = volume.getDiskType();
this.accountId = volume.getAccountId();
if (volume.getDataStore() != null) {
this.dataStore = volume.getDataStore().getTO();
} else {
@ -52,39 +52,39 @@ public class VolumeObjectTO implements DataTO {
this.size = volume.getSize();
this.setVolumeId(volume.getId());
}
public String getUuid() {
return this.uuid;
}
public String getPath() {
return this.path;
}
public VolumeType getVolumeType() {
return this.volumeType;
}
public DiskFormat getDiskType() {
return this.diskType;
}
public DataStoreTO getDataStore() {
return this.dataStore;
}
public void setDataStore(PrimaryDataStoreTO dataStore) {
this.dataStore = dataStore;
}
public String getName() {
return this.name;
}
public long getSize() {
return this.size;
}
public DataObjectType getObjectType() {
return DataObjectType.VOLUME;
}
@ -113,4 +113,13 @@ public class VolumeObjectTO implements DataTO {
this.volumeId = volumeId;
}
public long getAccountId() {
return accountId;
}
public void setAccountId(long accountId) {
this.accountId = accountId;
}
}

View File

@ -187,13 +187,13 @@ public class TemplateServiceImpl implements TemplateService {
@Override
public void handleSysTemplateDownload(HypervisorType hostHyper, Long dcId) {
Set<VMTemplateVO> toBeDownloaded = new HashSet<VMTemplateVO>();
List<DataStore> ssHosts = this._storeMgr.getImageStoresByScope(new ZoneScope(dcId));
if (ssHosts == null || ssHosts.isEmpty()){
List<DataStore> stores = this._storeMgr.getImageStoresByScope(new ZoneScope(dcId));
if (stores == null || stores.isEmpty()){
return;
}
/*Download all the templates in zone with the same hypervisortype*/
for ( DataStore ssHost : ssHosts) {
for ( DataStore store : stores) {
List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
@ -211,10 +211,10 @@ public class TemplateServiceImpl implements TemplateService {
}
for (VMTemplateVO template: toBeDownloaded) {
TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(ssHost.getId(), template.getId());
TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
if (tmpltHost == null || tmpltHost.getState() != ObjectInDataStoreStateMachine.State.Ready) {
DataObject tmpl = this._templateFactory.getTemplate(template.getId(), ssHost);
_dlMonitor.downloadTemplateToStorage(tmpl, ssHost, null);
TemplateInfo tmplt = this._templateFactory.getTemplate(template.getId());
this.createTemplateAsync(tmplt, store, null);
}
}
}
@ -370,8 +370,8 @@ public class TemplateServiceImpl implements TemplateService {
}
s_logger.debug("Template " + tmplt.getName() + " needs to be downloaded to " + store.getName());
//TODO: we should pass a callback here
DataObject tmpl = this._templateFactory.getTemplate(tmplt.getId(), store);
_dlMonitor.downloadTemplateToStorage(tmpl, store, null);
TemplateInfo tmpl = this._templateFactory.getTemplate(tmplt.getId());
this.createTemplateAsync(tmpl, store, null);
}
}
}

View File

@ -18,6 +18,9 @@
*/
package org.apache.cloudstack.storage.image.store;
import java.util.Date;
import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
@ -28,7 +31,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreState
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateEvent;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
@ -38,7 +40,10 @@ import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.TemplateType;
import com.cloud.storage.VMTemplateStoragePoolVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
@ -108,9 +113,9 @@ public class TemplateObject implements TemplateInfo {
@Override
public String getUri() {
VMTemplateVO image = imageDao.findById(this.imageVO.getId());
return image.getUrl();
}
@Override
@ -153,8 +158,8 @@ public class TemplateObject implements TemplateInfo {
}
@Override
public DiskFormat getFormat() {
return DiskFormat.valueOf(this.imageVO.getFormat().toString());
public ImageFormat getFormat() {
return this.imageVO.getFormat();
}
public boolean stateTransit(TemplateEvent e) throws NoTransitionException {
@ -188,7 +193,7 @@ public class TemplateObject implements TemplateInfo {
templatePoolRef.setInstallPath(newTemplate.getPath());
templatePoolDao.update(templatePoolRef.getId(), templatePoolRef);
}
} else if (this.getDataStore().getRole() == DataStoreRole.Image ||
} else if (this.getDataStore().getRole() == DataStoreRole.Image ||
this.getDataStore().getRole() == DataStoreRole.ImageCache) {
if (answer instanceof CopyCmdAnswer) {
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer;
@ -221,4 +226,115 @@ public class TemplateObject implements TemplateInfo {
DataObjectInStore obj = ojbectInStoreMgr.findObject(this, this.dataStore);
return obj.getInstallPath();
}
@Override
public long getAccountId() {
return this.imageVO.getAccountId();
}
@Override
public boolean isFeatured() {
return this.imageVO.isFeatured();
}
@Override
public boolean isPublicTemplate() {
return this.imageVO.isPublicTemplate();
}
@Override
public boolean isExtractable() {
return this.imageVO.isExtractable();
}
@Override
public String getName() {
return this.imageVO.getName();
}
@Override
public boolean isRequiresHvm() {
return this.imageVO.isRequiresHvm();
}
@Override
public String getDisplayText() {
return this.imageVO.getDisplayText();
}
@Override
public boolean getEnablePassword() {
return this.imageVO.getEnablePassword();
}
@Override
public boolean getEnableSshKey() {
return this.imageVO.getEnableSshKey();
}
@Override
public boolean isCrossZones() {
return this.imageVO.isCrossZones();
}
@Override
public Date getCreated() {
return this.imageVO.getCreated();
}
@Override
public long getGuestOSId() {
return this.imageVO.getGuestOSId();
}
@Override
public boolean isBootable() {
return this.imageVO.isBootable();
}
@Override
public TemplateType getTemplateType() {
return this.imageVO.getTemplateType();
}
@Override
public HypervisorType getHypervisorType() {
return this.imageVO.getHypervisorType();
}
@Override
public int getBits() {
return this.imageVO.getBits();
}
@Override
public String getUrl() {
return this.imageVO.getUrl();
}
@Override
public String getChecksum() {
return this.imageVO.getChecksum();
}
@Override
public Long getSourceTemplateId() {
return this.imageVO.getSourceTemplateId();
}
@Override
public String getTemplateTag() {
return this.imageVO.getTemplateTag();
}
@Override
public Map getDetails() {
return this.imageVO.getDetails();
}
@Override
public long getDomainId() {
return this.imageVO.getDomainId();
}
}

View File

@ -30,7 +30,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
import org.apache.cloudstack.storage.command.CreateObjectAnswer;
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
@ -93,12 +92,12 @@ public class SnapshotObject implements SnapshotInfo {
if (snapStoreVO == null) {
return null;
}
long parentId = snapStoreVO.getParentSnapshotId();
if (parentId == 0) {
return null;
}
return this.snapshotFactory.getSnapshot(parentId, store);
}
@ -145,10 +144,6 @@ public class SnapshotObject implements SnapshotInfo {
return DataObjectType.SNAPSHOT;
}
@Override
public DiskFormat getFormat() {
return null;
}
@Override
public String getUuid() {
@ -247,7 +242,7 @@ public class SnapshotObject implements SnapshotInfo {
@Override
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
SnapshotDataStoreVO snapshotStore = this.snapshotStoreDao.findByStoreSnapshot(this.getDataStore().getRole(),
SnapshotDataStoreVO snapshotStore = this.snapshotStoreDao.findByStoreSnapshot(this.getDataStore().getRole(),
this.getDataStore().getId(), this.getId());
if (answer instanceof CreateObjectAnswer) {
SnapshotObjectTO snapshotTO = (SnapshotObjectTO)((CreateObjectAnswer) answer).getData();
@ -274,7 +269,7 @@ public class SnapshotObject implements SnapshotInfo {
@Override
public void addPayload(Object data) {
// TODO Auto-generated method stub
}
}

View File

@ -7,12 +7,12 @@ import java.util.concurrent.TimeUnit;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.storage.command.CopyCommand;
import org.apache.cloudstack.storage.command.DownloadCommand;
import com.cloud.agent.Listener;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.resource.ServerResource;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.download.DownloadListener;

View File

@ -26,7 +26,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
@ -78,7 +77,8 @@ public class VolumeObject implements VolumeInfo {
vo.configure(dataStore, volumeVO);
return vo;
}
@Override
public String getAttachedVmName() {
Long vmId = this.volumeVO.getInstanceId();
if (vmId != null) {
@ -97,14 +97,15 @@ public class VolumeObject implements VolumeInfo {
return volumeVO.getUuid();
}
public void setPath(String uuid) {
volumeVO.setPath(uuid);
public void setUuid(String uuid) {
volumeVO.setUuid(uuid);
}
public void setSize(Long size) {
volumeVO.setSize(size);
}
@Override
public Volume.State getState() {
return volumeVO.getState();
}
@ -119,6 +120,12 @@ public class VolumeObject implements VolumeInfo {
return volumeVO.getSize();
}
@Override
public String getInstallPath() {
DataObjectInStore obj = ojbectInStoreMgr.findObject(this, this.dataStore);
return obj.getInstallPath();
}
public long getVolumeId() {
return volumeVO.getId();
}
@ -174,11 +181,6 @@ public class VolumeObject implements VolumeInfo {
return DataObjectType.VOLUME;
}
@Override
public DiskFormat getFormat() {
// TODO Auto-generated method stub
return null;
}
@Override
public void processEvent(
@ -388,7 +390,7 @@ public class VolumeObject implements VolumeInfo {
this.volumeStoreDao.update(volStore.getId(), volStore);
}
}
this.processEvent(event);
}
}

View File

@ -70,7 +70,6 @@ import com.cloud.storage.Volume.Type;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.download.DownloadMonitor;
import com.cloud.storage.secondary.SecondaryStorageVmManager;
import com.cloud.storage.snapshot.SnapshotManager;
import com.cloud.storage.template.TemplateProp;
import com.cloud.user.AccountManager;
@ -643,9 +642,9 @@ public class VolumeServiceImpl implements VolumeService {
AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
DataObject volumeOnStore = store.create(volume);
volumeOnStore.processEvent(Event.CreateOnlyRequested);
CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<VolumeApiResult>(null, volumeOnStore, future);
AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().registerVolumeCallback(null, null))
@ -657,7 +656,7 @@ public class VolumeServiceImpl implements VolumeService {
protected Void registerVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, CreateVolumeContext<VolumeApiResult> context) {
CreateCmdResult result = callback.getResult();
VolumeObject vo = (VolumeObject)context.volume;
if (result.isFailed()) {
vo.processEvent(Event.OperationFailed);
@ -813,7 +812,8 @@ public class VolumeServiceImpl implements VolumeService {
}
s_logger.debug("Volume " + volumeHost.getVolumeId() + " needs to be downloaded to " + store.getName());
//TODO: pass a callback later
downloadMonitor.downloadVolumeToStorage(this.volFactory.getVolume(volumeHost.getVolumeId()), store, volumeHost.getDownloadUrl(), volumeHost.getChecksum(), volumeHost.getFormat(), null);
VolumeInfo vol = this.volFactory.getVolume(volumeHost.getVolumeId());
this.createVolumeAsync(vol, store);
}
}
@ -843,12 +843,12 @@ public class VolumeServiceImpl implements VolumeService {
return null;
}
@Override
public SnapshotInfo takeSnapshot(VolumeInfo volume) {
VolumeObject vol = (VolumeObject)volume;
vol.stateTransit(Volume.Event.SnapshotRequested);
SnapshotInfo snapshot = null;
try {
snapshot = this.snapshotMgr.takeSnapshot(volume);
@ -861,7 +861,7 @@ public class VolumeServiceImpl implements VolumeService {
vol.stateTransit(Volume.Event.OperationFailed);
}
}
return snapshot;
}

View File

@ -16,6 +16,9 @@
// under the License.
package com.cloud.agent.manager;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.AttachIsoCommand;
import com.cloud.agent.api.AttachVolumeAnswer;
@ -41,8 +44,6 @@ import com.cloud.agent.api.storage.CreateAnswer;
import com.cloud.agent.api.storage.CreateCommand;
import com.cloud.agent.api.storage.DeleteTemplateCommand;
import com.cloud.agent.api.storage.DestroyCommand;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.ListTemplateCommand;
import com.cloud.agent.api.storage.ListVolumeCommand;
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;

View File

@ -48,8 +48,6 @@ import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
import com.cloud.agent.api.storage.DeleteTemplateCommand;
import com.cloud.agent.api.storage.DestroyCommand;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.ListTemplateAnswer;
import com.cloud.agent.api.storage.ListTemplateCommand;
import com.cloud.agent.api.storage.ListVolumeAnswer;
@ -81,6 +79,9 @@ import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.DiskProfile;
import com.cloud.vm.VirtualMachine.State;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.api.to.NfsTO;

View File

@ -34,6 +34,9 @@ import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine.State;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

View File

@ -34,6 +34,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.framework.async.AsyncRpcConext;
@ -45,19 +46,15 @@ import org.apache.cloudstack.storage.image.ImageStoreDriver;
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
import org.apache.cloudstack.storage.image.store.TemplateObject;
import org.apache.cloudstack.storage.snapshot.SnapshotObject;
import org.apache.cloudstack.storage.volume.VolumeObject;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.DeleteSnapshotBackupCommand;
import com.cloud.agent.api.storage.DeleteTemplateCommand;
import com.cloud.agent.api.storage.DeleteVolumeCommand;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.agent.api.to.S3TO;
import com.cloud.agent.api.to.SwiftTO;
import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.host.dao.HostDao;
@ -166,13 +163,9 @@ public class CloudStackImageStoreDriverImpl implements ImageStoreDriver {
if (data.getType() == DataObjectType.TEMPLATE) {
TemplateObject tData = (TemplateObject)data;
_downloadMonitor.downloadTemplateToStorage(tData, tData.getDataStore(), caller);
_downloadMonitor.downloadTemplateToStorage(data, caller);
} else if (data.getType() == DataObjectType.VOLUME) {
VolumeObject volInfo = (VolumeObject)data;
RegisterVolumePayload payload = (RegisterVolumePayload)volInfo.getpayload();
_downloadMonitor.downloadVolumeToStorage(volInfo, volInfo.getDataStore(), payload.getUrl(),
payload.getChecksum(), ImageFormat.valueOf(payload.getFormat().toUpperCase()), caller);
_downloadMonitor.downloadVolumeToStorage(data, caller);
}
}

View File

@ -36,6 +36,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.framework.async.AsyncRpcConext;
@ -48,7 +49,6 @@ import org.apache.cloudstack.storage.image.ImageStoreDriver;
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
import org.apache.cloudstack.storage.image.store.TemplateObject;
import org.apache.cloudstack.storage.snapshot.SnapshotObject;
import org.apache.cloudstack.storage.volume.VolumeObject;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
@ -59,10 +59,8 @@ import com.cloud.agent.api.storage.DeleteVolumeCommand;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.S3TO;
import com.cloud.agent.api.to.SwiftTO;
import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.storage.RegisterVolumePayload;
import com.cloud.storage.Storage.ImageFormat;
@ -71,13 +69,11 @@ import com.cloud.storage.SnapshotVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.VMTemplateZoneVO;
import com.cloud.storage.VolumeHostVO;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.SnapshotDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateZoneDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.dao.VolumeHostDao;
import com.cloud.storage.download.DownloadMonitor;
import com.cloud.storage.s3.S3Manager;
import com.cloud.storage.secondary.SecondaryStorageVmManager;
@ -179,13 +175,9 @@ public class S3ImageStoreDriverImpl implements ImageStoreDriver {
if (data.getType() == DataObjectType.TEMPLATE) {
TemplateObject tData = (TemplateObject)data;
_downloadMonitor.downloadTemplateToStorage(tData, tData.getDataStore(), caller);
_downloadMonitor.downloadTemplateToStorage(data, caller);
} else if (data.getType() == DataObjectType.VOLUME) {
VolumeObject volInfo = (VolumeObject)data;
RegisterVolumePayload payload = (RegisterVolumePayload)volInfo.getpayload();
_downloadMonitor.downloadVolumeToStorage(volInfo, volInfo.getDataStore(), payload.getUrl(),
payload.getChecksum(), ImageFormat.valueOf(payload.getFormat().toUpperCase()), caller);
_downloadMonitor.downloadVolumeToStorage(data, caller);
}
}

View File

@ -48,7 +48,6 @@ import org.apache.cloudstack.storage.image.ImageStoreDriver;
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
import org.apache.cloudstack.storage.image.store.TemplateObject;
import org.apache.cloudstack.storage.snapshot.SnapshotObject;
import org.apache.cloudstack.storage.volume.VolumeObject;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
@ -58,26 +57,21 @@ import com.cloud.agent.api.storage.DeleteTemplateCommand;
import com.cloud.agent.api.storage.DeleteVolumeCommand;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.S3TO;
import com.cloud.agent.api.to.SwiftTO;
import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.storage.RegisterVolumePayload;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.SnapshotVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.VMTemplateZoneVO;
import com.cloud.storage.VolumeHostVO;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.SnapshotDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateZoneDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.dao.VolumeHostDao;
import com.cloud.storage.download.DownloadMonitor;
import com.cloud.storage.s3.S3Manager;
import com.cloud.storage.secondary.SecondaryStorageVmManager;
@ -172,13 +166,9 @@ public class SwiftImageStoreDriverImpl implements ImageStoreDriver {
if (data.getType() == DataObjectType.TEMPLATE) {
TemplateObject tData = (TemplateObject)data;
_downloadMonitor.downloadTemplateToStorage(tData, tData.getDataStore(), caller);
_downloadMonitor.downloadTemplateToStorage(data, caller);
} else if (data.getType() == DataObjectType.VOLUME) {
VolumeObject volInfo = (VolumeObject)data;
RegisterVolumePayload payload = (RegisterVolumePayload)volInfo.getpayload();
_downloadMonitor.downloadVolumeToStorage(volInfo, volInfo.getDataStore(), payload.getUrl(),
payload.getChecksum(), ImageFormat.valueOf(payload.getFormat().toUpperCase()), caller);
_downloadMonitor.downloadVolumeToStorage(data, caller);
}
}

View File

@ -16,8 +16,9 @@
// under the License.
package com.cloud.storage.download;
import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
public class DownloadAbandonedState extends DownloadInactiveState {

View File

@ -16,10 +16,10 @@
// under the License.
package com.cloud.storage.download;
import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
import org.apache.log4j.Level;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
public abstract class DownloadActiveState extends DownloadState {

View File

@ -16,7 +16,8 @@
// under the License.
package com.cloud.storage.download;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
public class DownloadCompleteState extends DownloadInactiveState {

View File

@ -16,10 +16,10 @@
// under the License.
package com.cloud.storage.download;
import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
import org.apache.log4j.Level;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
public class DownloadErrorState extends DownloadInactiveState {

View File

@ -34,6 +34,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@ -46,10 +50,6 @@ import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.StartupSecondaryStorageCommand;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadCommand.ResourceType;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConnectionException;
import com.cloud.host.Host;

View File

@ -17,11 +17,9 @@
package com.cloud.storage.download;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.utils.component.Manager;
/**
@ -31,8 +29,8 @@ import com.cloud.utils.component.Manager;
public interface DownloadMonitor extends Manager{
public void downloadTemplateToStorage(DataObject template, DataStore store, AsyncCompletionCallback<DownloadAnswer> callback);
public void downloadTemplateToStorage(DataObject template, AsyncCompletionCallback<DownloadAnswer> callback);
public void downloadVolumeToStorage(DataObject volume, DataStore store, String url, String checkSum, ImageFormat format, AsyncCompletionCallback<DownloadAnswer> callback);
public void downloadVolumeToStorage(DataObject volume, AsyncCompletionCallback<DownloadAnswer> callback);
}

View File

@ -33,7 +33,12 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
@ -43,22 +48,12 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.agent.Listener;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadCommand.Proxy;
import com.cloud.agent.api.storage.DownloadCommand.ResourceType;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import com.cloud.agent.manager.Commands;
import com.cloud.alert.AlertManager;
import com.cloud.agent.api.storage.Proxy;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.host.HostVO;
import com.cloud.storage.RegisterVolumePayload;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageManager;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
@ -68,20 +63,15 @@ import com.cloud.storage.VolumeHostVO;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.secondary.SecondaryStorageVmManager;
import com.cloud.storage.swift.SwiftManager;
import com.cloud.storage.template.TemplateConstants;
import com.cloud.template.TemplateManager;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.AccountManager;
import com.cloud.user.ResourceLimitService;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.JoinBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.dao.UserVmDao;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.apache.cloudstack.storage.to.TemplateObjectTO;
@Component
@Local(value = { DownloadMonitor.class })
@ -175,14 +165,13 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
return (downloadsInProgress.size() == 0);
}
private void initiateTemplateDownload(DataObject template, DataStore store, AsyncCompletionCallback<DownloadAnswer> callback) {
private void initiateTemplateDownload(DataObject template, AsyncCompletionCallback<DownloadAnswer> callback) {
boolean downloadJobExists = false;
TemplateDataStoreVO vmTemplateStore = null;
DataStore store = template.getDataStore();
vmTemplateStore = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
if (vmTemplateStore == null) {
// This method can be invoked other places, for example,
// handleTemplateSync, in that case, vmTemplateStore may be null
vmTemplateStore = new TemplateDataStoreVO(store.getId(), template.getId(), new Date(), 0,
VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null, "jobid0000", null, template.getUri());
_vmTemplateStoreDao.persist(vmTemplateStore);
@ -194,7 +183,7 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
if (vmTemplateStore != null) {
start();
VirtualMachineTemplate tmpl = this._templateDao.findById(template.getId());
DownloadCommand dcmd = new DownloadCommand(store.getTO(), tmpl, maxTemplateSizeInBytes);
DownloadCommand dcmd = new DownloadCommand((TemplateObjectTO)(template.getTO()), maxTemplateSizeInBytes);
dcmd.setProxy(getHttpProxy());
if (downloadJobExists) {
dcmd = new DownloadProgressCommand(dcmd, vmTemplateStore.getJobId(), RequestType.GET_OR_RESTART);
@ -238,20 +227,26 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
@Override
public void downloadTemplateToStorage(DataObject template, DataStore store, AsyncCompletionCallback<DownloadAnswer> callback) {
public void downloadTemplateToStorage(DataObject template, AsyncCompletionCallback<DownloadAnswer> callback) {
long templateId = template.getId();
DataStore store = template.getDataStore();
if (isTemplateUpdateable(templateId, store.getId())) {
if (template != null && template.getUri() != null) {
initiateTemplateDownload(template, store, callback);
initiateTemplateDownload(template, callback);
}
}
}
@Override
public void downloadVolumeToStorage(DataObject volume, DataStore store, String url, String checkSum, ImageFormat format,
AsyncCompletionCallback<DownloadAnswer> callback) {
public void downloadVolumeToStorage(DataObject volume, AsyncCompletionCallback<DownloadAnswer> callback) {
boolean downloadJobExists = false;
VolumeDataStoreVO volumeHost = null;
DataStore store = volume.getDataStore();
VolumeInfo volInfo = (VolumeInfo)volume;
RegisterVolumePayload payload = (RegisterVolumePayload)volInfo.getpayload();
String url = payload.getUrl();
String checkSum = payload.getChecksum();
ImageFormat format = ImageFormat.valueOf(payload.getFormat());
volumeHost = _volumeStoreDao.findByStoreVolume(store.getId(), volume.getId());
if (volumeHost == null) {
@ -266,7 +261,7 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
if (volumeHost != null) {
start();
Volume vol = this._volumeDao.findById(volume.getId());
DownloadCommand dcmd = new DownloadCommand(store.getTO(), vol, maxVolumeSizeInBytes, checkSum, url, format);
DownloadCommand dcmd = new DownloadCommand((VolumeObjectTO)(volume.getTO()), maxVolumeSizeInBytes, checkSum, url, format);
dcmd.setProxy(getHttpProxy());
if (downloadJobExists) {
dcmd = new DownloadProgressCommand(dcmd, volumeHost.getJobId(), RequestType.GET_OR_RESTART);

View File

@ -16,7 +16,8 @@
// under the License.
package com.cloud.storage.download;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
public class NotDownloadedState extends DownloadActiveState {

View File

@ -24,6 +24,8 @@ import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.storage.command.DownloadCommand;
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
@ -39,8 +41,6 @@ import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.storage.DownloadCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.resource.ServerResource;