mirror of https://github.com/apache/cloudstack.git
Volume upload: sending the nfsstore url in the metadata
decoding the metadata and deserialising it on receiving it
This commit is contained in:
parent
cd02ceb7a1
commit
ad6b7b30cb
|
|
@ -26,6 +26,130 @@ public class TemplateOrVolumePostUploadCommand {
|
|||
DataObject dataObject;
|
||||
EndPoint endPoint;
|
||||
|
||||
long entityId;
|
||||
String entityUUID;
|
||||
String absolutePath;
|
||||
String checksum;
|
||||
String type;
|
||||
String name;
|
||||
// String installPathPrefix;
|
||||
String localPath;
|
||||
// String isHvm;
|
||||
String imageFormat;
|
||||
String dataTo;
|
||||
String dataToRole;
|
||||
|
||||
public TemplateOrVolumePostUploadCommand(long entityId, String entityUUID, String absolutePath, String checksum, String type, String name,
|
||||
String localPath, String imageFormat, String dataTo, String dataToRole) {
|
||||
this.entityId = entityId;
|
||||
this.entityUUID = entityUUID;
|
||||
this.absolutePath = absolutePath;
|
||||
this.checksum = checksum;
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
// this.installPathPrefix = installPathPrefix;
|
||||
this.localPath = localPath;
|
||||
// this.isHvm = isHvm;
|
||||
this.imageFormat = imageFormat;
|
||||
this.dataTo = dataTo;
|
||||
this.dataToRole = dataToRole;
|
||||
}
|
||||
|
||||
public String getDataTo() {
|
||||
return dataTo;
|
||||
}
|
||||
|
||||
public void setDataTo(String dataTo) {
|
||||
this.dataTo = dataTo;
|
||||
}
|
||||
|
||||
public String getDataToRole() {
|
||||
return dataToRole;
|
||||
}
|
||||
|
||||
public void setDataToRole(String dataToRole) {
|
||||
this.dataToRole = dataToRole;
|
||||
}
|
||||
// public String getInstallPathPrefix() {
|
||||
// return installPathPrefix;
|
||||
// }
|
||||
//
|
||||
// public void setInstallPathPrefix(String installPathPrefix) {
|
||||
// this.installPathPrefix = installPathPrefix;
|
||||
// }
|
||||
|
||||
public String getLocalPath() {
|
||||
return localPath;
|
||||
}
|
||||
|
||||
public void setLocalPath(String localPath) {
|
||||
this.localPath = localPath;
|
||||
}
|
||||
|
||||
// public String getIsHvm() {
|
||||
// return isHvm;
|
||||
// }
|
||||
|
||||
// public void setIsHvm(String isHvm) {
|
||||
// this.isHvm = isHvm;
|
||||
// }
|
||||
|
||||
public String getImageFormat() {
|
||||
return imageFormat;
|
||||
}
|
||||
|
||||
public void setImageFormat(String imageFormat) {
|
||||
this.imageFormat = imageFormat;
|
||||
}
|
||||
|
||||
public long getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public void setEntityId(long entityId) {
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public String getEntityUUID() {
|
||||
return entityUUID;
|
||||
}
|
||||
|
||||
public void setEntityUUID(String entityUUID) {
|
||||
this.entityUUID = entityUUID;
|
||||
}
|
||||
|
||||
public String getAbsolutePath() {
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
public void setAbsolutePath(String absolutePath) {
|
||||
this.absolutePath = absolutePath;
|
||||
}
|
||||
|
||||
public String getChecksum() {
|
||||
return checksum;
|
||||
}
|
||||
|
||||
public void setChecksum(String checksum) {
|
||||
this.checksum = checksum;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public TemplateOrVolumePostUploadCommand(DataObject dataObject, EndPoint endPoint) {
|
||||
this.dataObject = dataObject;
|
||||
this.endPoint = endPoint;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.apache.cloudstack.engine.subsystem.api.storage;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
|
||||
import org.apache.cloudstack.framework.async.AsyncCallFuture;
|
||||
import org.apache.cloudstack.storage.command.CommandResult;
|
||||
|
|
@ -94,7 +95,7 @@ public interface VolumeService {
|
|||
|
||||
AsyncCallFuture<VolumeApiResult> registerVolume(VolumeInfo volume, DataStore store);
|
||||
|
||||
public EndPoint registerVolumeForPostUpload(VolumeInfo volume, DataStore store);
|
||||
public Pair<EndPoint,DataObject> registerVolumeForPostUpload(VolumeInfo volume, DataStore store);
|
||||
|
||||
AsyncCallFuture<VolumeApiResult> resize(VolumeInfo volume);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.util.Map;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.storage.RegisterVolumePayload;
|
||||
import com.cloud.utils.Pair;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
|
||||
|
|
@ -1224,7 +1225,7 @@ public class VolumeServiceImpl implements VolumeService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public EndPoint registerVolumeForPostUpload(VolumeInfo volume, DataStore store) {
|
||||
public Pair<EndPoint,DataObject> registerVolumeForPostUpload(VolumeInfo volume, DataStore store) {
|
||||
DataObject volumeOnStore = store.create(volume);
|
||||
|
||||
volumeOnStore.processEvent(Event.CreateOnlyRequested);
|
||||
|
|
@ -1234,7 +1235,7 @@ public class VolumeServiceImpl implements VolumeService {
|
|||
s_logger.warn("There is no secondary storage VM for image store " + store.getName());
|
||||
return null;
|
||||
}
|
||||
return ep;
|
||||
return new Pair<>(ep,volumeOnStore);
|
||||
}
|
||||
|
||||
protected Void registerVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, CreateVolumeContext<VolumeApiResult> context) {
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ 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.DataObject;
|
||||
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;
|
||||
|
|
@ -297,21 +297,23 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||
RegisterVolumePayload payload = new RegisterVolumePayload(null, cmd.getChecksum(), cmd.getFormat());
|
||||
vol.addPayload(payload);
|
||||
|
||||
EndPoint ep = volService.registerVolumeForPostUpload(vol, store);
|
||||
Pair<EndPoint, DataObject> pair = volService.registerVolumeForPostUpload(vol, store);
|
||||
EndPoint ep = pair.first();
|
||||
DataObject dataObject = pair.second();
|
||||
|
||||
TemplateOrVolumePostUploadCommand command = new TemplateOrVolumePostUploadCommand(vol, ep);
|
||||
|
||||
GetUploadParamsResponse response = new GetUploadParamsResponse();
|
||||
String url = "https://" + command.getEndPoint().getPublicAddr() + "/upload/" + command.getDataObject().getUuid();
|
||||
String url = "https://" + ep.getPublicAddr() + "/upload/" + vol.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);
|
||||
_volumeStoreDao.persist(volumeStore);
|
||||
}
|
||||
|
||||
response.setId(UUID.fromString(command.getDataObject().getUuid()));
|
||||
response.setId(UUID.fromString(vol.getUuid()));
|
||||
|
||||
/*
|
||||
* TODO: hardcoding the timeout to current + 60 min for now. This needs to goto the database
|
||||
|
|
@ -323,10 +325,15 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||
|
||||
String key = _configDao.getValue(Config.SSVMPSK.key());
|
||||
/*
|
||||
* encoded metadata using the post upload config ssh key
|
||||
* encoded metadata using the post upload config key
|
||||
*/
|
||||
|
||||
Gson gson = new GsonBuilder().registerTypeAdapter(TemplateOrVolumePostUploadCommand.class, new TemplateOrVolumePostUploadCommandTypeAdapter()).create();
|
||||
|
||||
TemplateOrVolumePostUploadCommand command =
|
||||
new TemplateOrVolumePostUploadCommand(vol.getId(), vol.getUuid(), volumeStore.getInstallPath(), volumeStore.getChecksum(), vol.getType().toString(), vol.getName(),
|
||||
volumeStore.getLocalDownloadPath(), vol.getFormat().toString(), dataObject.getDataStore().getUri(),
|
||||
dataObject.getDataStore().getRole().toString());
|
||||
Gson gson = new GsonBuilder().create();
|
||||
String jsonPayload = gson.toJson(command);
|
||||
response.setMetadata(EncryptionUtil.encodeData(jsonPayload, key));
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ import java.util.UUID;
|
|||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.utils.EncryptionUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand;
|
||||
import org.apache.cloudstack.storage.template.UploadEntity;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
|
|
@ -183,6 +187,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
|
||||
private static final String TEMPLATE_ROOT_DIR = "template/tmpl";
|
||||
private static final String VOLUME_ROOT_DIR = "volumes";
|
||||
private static final String POST_UPLOAD_KEY_LOCATION = "/etc/cloudstack/agent/ms-psk";
|
||||
|
||||
int _timeout;
|
||||
|
||||
|
|
@ -1401,7 +1406,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
|
||||
private void savePostUploadPSK(String psk) {
|
||||
try {
|
||||
FileUtils.writeStringToFile(new File("/etc/cloudstack/agent/ms-psk"),psk, "utf-8");
|
||||
FileUtils.writeStringToFile(new File(POST_UPLOAD_KEY_LOCATION),psk, "utf-8");
|
||||
} catch (IOException ex) {
|
||||
s_logger.debug("Failed to copy PSK to the file.", ex);
|
||||
}
|
||||
|
|
@ -2725,13 +2730,18 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||
|
||||
InputStream inputStream = new ByteArrayInputStream(data);
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
HashMap<String, String> paramsMap = new HashMap<>();
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
|
||||
parsePostBody(inputStream, output, paramsMap);
|
||||
parsePostBody(inputStream, output, params);
|
||||
String encodedMetadata = params.get("metadata");
|
||||
String key = FileUtils.readFileToString(new File(POST_UPLOAD_KEY_LOCATION), "utf-8");
|
||||
String metadata = EncryptionUtil.decodeData(encodedMetadata, key);
|
||||
|
||||
Gson gson = new GsonBuilder().create();
|
||||
TemplateOrVolumePostUploadCommand cmd = gson.fromJson(metadata, TemplateOrVolumePostUploadCommand.class);
|
||||
|
||||
//call handle upload method.
|
||||
//TODO: get entityid, absolute path from metadata and filename from post data
|
||||
handleuplod(1, null, "file", output.size(), output.toByteArray());
|
||||
handleuplod(cmd.getEntityId(), cmd.getAbsolutePath(), cmd.getName(), output.size(), output.toByteArray());
|
||||
|
||||
s_logger.error(new String(data));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue