mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
bug 7519 : Extract links would have Java genereated UUID instead.
This commit is contained in:
parent
ffe387ab5b
commit
dce1e2031b
12
core/src/com/cloud/agent/api/storage/CreateEntityDownloadURLCommand.java
Normal file → Executable file
12
core/src/com/cloud/agent/api/storage/CreateEntityDownloadURLCommand.java
Normal file → Executable file
@ -4,15 +4,17 @@ import com.cloud.agent.api.Command;
|
||||
|
||||
public class CreateEntityDownloadURLCommand extends AbstractDownloadCommand {
|
||||
|
||||
public CreateEntityDownloadURLCommand(String installPath) {
|
||||
public CreateEntityDownloadURLCommand(String installPath, String uuid) {
|
||||
super();
|
||||
this.installPath = installPath;
|
||||
this.extractLinkUUID = uuid;
|
||||
}
|
||||
|
||||
public CreateEntityDownloadURLCommand() {
|
||||
}
|
||||
|
||||
private String installPath;
|
||||
private String extractLinkUUID;
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
@ -27,4 +29,12 @@ public class CreateEntityDownloadURLCommand extends AbstractDownloadCommand {
|
||||
this.installPath = installPath;
|
||||
}
|
||||
|
||||
public String getExtractLinkUUID() {
|
||||
return extractLinkUUID;
|
||||
}
|
||||
|
||||
public void setExtractLinkUUID(String extractLinkUUID) {
|
||||
this.extractLinkUUID = extractLinkUUID;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,13 +4,15 @@ import com.cloud.storage.Upload;
|
||||
|
||||
public class DeleteEntityDownloadURLCommand extends AbstractDownloadCommand {
|
||||
|
||||
String path;
|
||||
Upload.Type type;
|
||||
private String path;
|
||||
private String extractUrl;
|
||||
private Upload.Type type;
|
||||
|
||||
public DeleteEntityDownloadURLCommand(String path, Upload.Type type) {
|
||||
public DeleteEntityDownloadURLCommand(String path, Upload.Type type, String url) {
|
||||
super();
|
||||
this.path = path;
|
||||
this.type = type;
|
||||
this.extractUrl = url;
|
||||
}
|
||||
|
||||
public DeleteEntityDownloadURLCommand() {
|
||||
@ -33,4 +35,12 @@ public class DeleteEntityDownloadURLCommand extends AbstractDownloadCommand {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getExtractUrl() {
|
||||
return extractUrl;
|
||||
}
|
||||
|
||||
public void setExtractUrl(String extractUrl) {
|
||||
this.extractUrl = extractUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -331,9 +331,10 @@ public class UploadManagerImpl implements UploadManager {
|
||||
return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
|
||||
}
|
||||
// Create the directory structure so that its visible under apache server root
|
||||
String extractDir = "/var/www/html/userdata/";
|
||||
Script command = new Script("mkdir", s_logger);
|
||||
command.add("-p");
|
||||
command.add("/var/www/html/userdata/");
|
||||
command.add(extractDir);
|
||||
String result = command.execute();
|
||||
if (result != null) {
|
||||
String errorString = "Error in creating directory =" + result;
|
||||
@ -341,11 +342,23 @@ public class UploadManagerImpl implements UploadManager {
|
||||
return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
|
||||
}
|
||||
|
||||
// Create a random file under the directory for security reasons.
|
||||
String uuid = cmd.getExtractLinkUUID();
|
||||
command = new Script("touch", s_logger);
|
||||
command.add(extractDir + uuid);
|
||||
result = command.execute();
|
||||
if (result != null) {
|
||||
String errorString = "Error in creating file " +uuid+ " ,error: " + result;
|
||||
s_logger.warn(errorString);
|
||||
return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
// Create a symbolic link from the actual directory to the template location. The entity would be directly visible under /var/www/html/userdata
|
||||
cmd.getInstallPath();
|
||||
command = new Script("/bin/bash", s_logger);
|
||||
command.add("-c");
|
||||
command.add("ln -sf " + extractMountPoint + File.separator + cmd.getInstallPath() + " /var/www/html/userdata/");
|
||||
command.add("ln -sf " + extractMountPoint + File.separator + cmd.getInstallPath() + " " + extractDir + uuid);
|
||||
result = command.execute();
|
||||
if (result != null) {
|
||||
String errorString = "Error in linking err=" + result;
|
||||
@ -365,8 +378,10 @@ public class UploadManagerImpl implements UploadManager {
|
||||
String path = cmd.getPath();
|
||||
Script command = new Script("/bin/bash", s_logger);
|
||||
command.add("-c");
|
||||
//We just need to remove the UUID.vhd
|
||||
command.add("unlink /var/www/html/userdata/" +path.substring(path.lastIndexOf(File.separator) + 1));
|
||||
|
||||
//We just need to remove the UUID.vhd
|
||||
String extractUrl = cmd.getExtractUrl();
|
||||
command.add("unlink /var/www/html/userdata/" +extractUrl.substring(extractUrl.lastIndexOf(File.separator) + 1));
|
||||
String result = command.execute();
|
||||
if (result != null) {
|
||||
String errorString = "Error in deleting =" + result;
|
||||
|
||||
1
server/src/com/cloud/configuration/Config.java
Normal file → Executable file
1
server/src/com/cloud/configuration/Config.java
Normal file → Executable file
@ -121,6 +121,7 @@ public enum Config {
|
||||
ExpungeDelay("Advanced", UserVmManager.class, Integer.class, "expunge.delay", "86400", "Determines how long to wait before actually expunging destroyed vm. The default value = the default value of expunge.interval", null),
|
||||
ExpungeInterval("Advanced", UserVmManager.class, Integer.class, "expunge.interval", "86400", "The interval to wait before running the expunge thread.", null),
|
||||
ExpungeWorkers("Advanced", UserVmManager.class, Integer.class, "expunge.workers", "1", "Number of workers performing expunge ", null),
|
||||
ExtractURLCleanUpInterval("Advanced", ManagementServer.class, Integer.class, "extract.url.cleanup.interval", "120", "The interval to wait before cleaning up the extract URL's ", null),
|
||||
HostStatsInterval("Advanced", ManagementServer.class, Integer.class, "host.stats.interval", "60000", "The interval in milliseconds when host stats are retrieved from agents.", null),
|
||||
HostRetry("Advanced", AgentManager.class, Integer.class, "host.retry", "2", "Number of times to retry hosts for creating a volume", null),
|
||||
IntegrationAPIPort("Advanced", ManagementServer.class, Integer.class, "integration.api.port", "8096", "Defaul API port", null),
|
||||
|
||||
@ -6,6 +6,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@ -62,7 +63,6 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
|
||||
static final Logger s_logger = Logger.getLogger(UploadMonitorImpl.class);
|
||||
|
||||
private String _hyperVisorType;
|
||||
@Inject
|
||||
VMTemplateHostDao _vmTemplateHostDao;
|
||||
@Inject
|
||||
@ -84,10 +84,10 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
|
||||
private String _name;
|
||||
private Boolean _sslCopy = new Boolean(false);
|
||||
private String _copyAuthPasswd;
|
||||
private ScheduledExecutorService _executor = null;
|
||||
|
||||
Timer _timer;
|
||||
int _cleanupInterval;
|
||||
|
||||
final Map<UploadVO, UploadListener> _listenerMap = new ConcurrentHashMap<UploadVO, UploadListener>();
|
||||
|
||||
@ -200,7 +200,8 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
_uploadDao.persist(uploadTemplateObj);
|
||||
try{
|
||||
// Create Symlink at ssvm
|
||||
CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(vmTemplateHost.getInstallPath());
|
||||
String uuid = UUID.randomUUID().toString() + ".vhd";
|
||||
CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(vmTemplateHost.getInstallPath(), uuid);
|
||||
long result = send(sserver.getId(), cmd, null);
|
||||
if (result == -1){
|
||||
errorString = "Unable to create a link for " +type+ " id:"+template.getId();
|
||||
@ -217,7 +218,7 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
s_logger.error(errorString);
|
||||
throw new CloudRuntimeException(errorString);
|
||||
}
|
||||
String extractURL = generateCopyUrl(ssVm.getPublicIpAddress(), vmTemplateHost.getInstallPath());
|
||||
String extractURL = generateCopyUrl(ssVm.getPublicIpAddress(), uuid);
|
||||
UploadVO vo = _uploadDao.createForUpdate();
|
||||
vo.setLastUpdated(new Date());
|
||||
vo.setUploadUrl(extractURL);
|
||||
@ -259,7 +260,8 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
_uploadDao.update(uploadJob.getId(), uploadJob);
|
||||
|
||||
// Create Symlink at ssvm
|
||||
CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(path);
|
||||
String uuid = UUID.randomUUID().toString() + ".vhd";
|
||||
CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(path, uuid);
|
||||
long result = send(ApiDBUtils.findUploadById(uploadId).getHostId(), cmd, null);
|
||||
if (result == -1){
|
||||
errorString = "Unable to create a link for " +type+ " id:"+entityId;
|
||||
@ -276,7 +278,7 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
s_logger.warn(errorString);
|
||||
throw new CloudRuntimeException(errorString);
|
||||
}
|
||||
String extractURL = generateCopyUrl(ssVm.getPublicIpAddress(), path);
|
||||
String extractURL = generateCopyUrl(ssVm.getPublicIpAddress(), uuid);
|
||||
UploadVO vo = _uploadDao.createForUpdate();
|
||||
vo.setLastUpdated(new Date());
|
||||
vo.setUploadUrl(extractURL);
|
||||
@ -298,7 +300,7 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
private String generateCopyUrl(String ipAddress, String path){
|
||||
private String generateCopyUrl(String ipAddress, String uuid){
|
||||
String hostname = ipAddress;
|
||||
String scheme = "http";
|
||||
if (_sslCopy) {
|
||||
@ -306,7 +308,7 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
hostname = hostname + ".realhostip.com";
|
||||
scheme = "https";
|
||||
}
|
||||
return scheme + "://" + hostname + "/userdata" + path.substring(path.lastIndexOf("/"));
|
||||
return scheme + "://" + hostname + "/userdata/" + uuid;
|
||||
}
|
||||
|
||||
|
||||
@ -325,13 +327,12 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
String cert = configs.get("secstorage.secure.copy.cert");
|
||||
if ("realhostip.com".equalsIgnoreCase(cert)) {
|
||||
s_logger.warn("Only realhostip.com ssl cert is supported, ignoring self-signed and other certs");
|
||||
}
|
||||
|
||||
_hyperVisorType = _configDao.getValue("hypervisor.type");
|
||||
|
||||
_copyAuthPasswd = configs.get("secstorage.copy.password");
|
||||
}
|
||||
|
||||
_agentMgr.registerForHostEvents(new UploadListener(this), true, false, false);
|
||||
String cleanupInterval = (String)params.get("extract.url.cleanup.interval");
|
||||
_cleanupInterval = NumbersUtil.parseInt(cleanupInterval, 21600);
|
||||
|
||||
|
||||
String workers = (String)params.get("expunge.workers");
|
||||
int wrks = NumbersUtil.parseInt(workers, 1);
|
||||
@ -345,9 +346,8 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
//FIX ME - Make the timings configurable. // Keep them to 86400 for now.
|
||||
_executor.scheduleWithFixedDelay(new StorageGarbageCollector(), 86400, 86400, TimeUnit.SECONDS);
|
||||
public boolean start() {
|
||||
_executor.scheduleWithFixedDelay(new StorageGarbageCollector(), _cleanupInterval, _cleanupInterval, TimeUnit.SECONDS);
|
||||
_timer = new Timer();
|
||||
return true;
|
||||
}
|
||||
@ -477,7 +477,7 @@ public class UploadMonitorImpl implements UploadMonitor {
|
||||
String path = extractJob.getInstallPath();
|
||||
s_logger.debug("Sending deletion of extract URL "+extractJob.getUploadUrl());
|
||||
// Would delete the symlink for the Type and if Type == VOLUME then also the volume
|
||||
DeleteEntityDownloadURLCommand cmd = new DeleteEntityDownloadURLCommand(path, extractJob.getType());
|
||||
DeleteEntityDownloadURLCommand cmd = new DeleteEntityDownloadURLCommand(path, extractJob.getType(),extractJob.getUploadUrl());
|
||||
long result = send(extractJob.getHostId(), cmd, null);
|
||||
if (result == -1){
|
||||
s_logger.warn("Unable to delete the link for " +extractJob.getType()+ " id=" +extractJob.getTypeId()+ " url="+extractJob.getUploadUrl());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user