mirror of https://github.com/apache/cloudstack.git
volume-upload: initializing state for volume and also setting the post url in volume_store_ref
This commit is contained in:
parent
c5be9d0b9b
commit
7900ae5d9f
|
|
@ -31,13 +31,13 @@ import javax.inject.Inject;
|
|||
import com.cloud.utils.EncryptionUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import org.apache.cloudstack.api.command.user.volume.GetUploadParamsForVolumeCmd;
|
||||
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand;
|
||||
import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommandTypeAdapter;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
|
||||
import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
|
||||
import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
|
||||
|
|
@ -156,6 +156,7 @@ import com.cloud.vm.dao.UserVmDao;
|
|||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.cloud.vm.snapshot.VMSnapshotVO;
|
||||
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
|
|
@ -262,7 +263,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||
|
||||
validateVolume(caller, ownerId, zoneId, volumeName, url, format, diskOfferingId);
|
||||
|
||||
VolumeVO volume = persistVolume(owner, zoneId, volumeName, url, cmd.getFormat(), diskOfferingId);
|
||||
VolumeVO volume = persistVolume(owner, zoneId, volumeName, url, cmd.getFormat(), diskOfferingId, Volume.State.Allocated);
|
||||
|
||||
VolumeInfo vol = volFactory.getVolume(volume.getId());
|
||||
|
||||
|
|
@ -289,7 +290,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||
|
||||
validateVolume(caller, ownerId, zoneId, volumeName, null, format, diskOfferingId);
|
||||
|
||||
VolumeVO volume = persistVolume(owner, zoneId, volumeName, null, cmd.getFormat(), diskOfferingId);
|
||||
VolumeVO volume = persistVolume(owner, zoneId, volumeName, null, cmd.getFormat(), diskOfferingId, Volume.State.NotUploaded);
|
||||
|
||||
VolumeInfo vol = volFactory.getVolume(volume.getId());
|
||||
|
||||
|
|
@ -304,6 +305,12 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||
String url = "https://" + command.getEndPoint().getPublicAddr() + "/upload/" + command.getDataObject().getUuid();
|
||||
response.setPostURL(new URL(url));
|
||||
|
||||
// set the post url, this is used in the monitoring thread to determine the SSVM
|
||||
VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
|
||||
if (volumeStore != null) {
|
||||
volumeStore.setExtractUrl(url);
|
||||
}
|
||||
|
||||
response.setId(UUID.fromString(command.getDataObject().getUuid()));
|
||||
|
||||
/*
|
||||
|
|
@ -395,7 +402,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||
|
||||
@DB
|
||||
protected VolumeVO persistVolume(final Account owner, final Long zoneId, final String volumeName, final String url,
|
||||
final String format, final Long diskOfferingId) {
|
||||
final String format, final Long diskOfferingId, final Volume.State state) {
|
||||
return Transaction.execute(new TransactionCallback<VolumeVO>() {
|
||||
@Override
|
||||
public VolumeVO doInTransaction(TransactionStatus status) {
|
||||
|
|
@ -403,7 +410,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||
volume.setPoolId(null);
|
||||
volume.setDataCenterId(zoneId);
|
||||
volume.setPodId(null);
|
||||
// to prevent a nullpointer deref I put the system account id here when no owner is given.
|
||||
volume.setState(state); // initialize the state
|
||||
// to prevent a null pointer deref I put the system account id here when no owner is given.
|
||||
// TODO Decide if this is valid or whether throwing a CloudRuntimeException is more appropriate
|
||||
volume.setAccountId((owner == null) ? Account.ACCOUNT_ID_SYSTEM : owner.getAccountId());
|
||||
volume.setDomainId((owner == null) ? Domain.ROOT_DOMAIN : owner.getDomainId());
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
|
@ -56,7 +55,6 @@ import org.apache.cloudstack.storage.template.UploadEntity;
|
|||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpException;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class UploadEntity {
|
|||
private String errorMessage=null;
|
||||
private File file;
|
||||
|
||||
public UploadEntity(long filesize, Status status, String filename, String absoluteFilePath){
|
||||
public UploadEntity(long filesize, Status status, String filename, String absoluteFilePath) {
|
||||
this.filesize=filesize;
|
||||
this.uploadState=status;
|
||||
this.downloadedsize=0l;
|
||||
|
|
@ -47,7 +47,7 @@ public class UploadEntity {
|
|||
this.absoluteFilePath=absoluteFilePath;
|
||||
}
|
||||
|
||||
public void setEntitysize(long filesize){
|
||||
public void setEntitysize(long filesize) {
|
||||
this.filesize=filesize;
|
||||
}
|
||||
|
||||
|
|
@ -86,6 +86,7 @@ public class UploadEntity {
|
|||
public void incremetByteCount(long numberOfBytes) {
|
||||
this.downloadedsize+= numberOfBytes;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
Loading…
Reference in New Issue