use of com.cloud.agent.api.storage.CreateEntityDownloadURLCommand in project cloudstack by apache.
the class VmwareSecondaryStorageResourceHandler method executeRequest.
@Override
public Answer executeRequest(Command cmd) {
try {
Answer answer;
NDC.push(getCommandLogTitle(cmd));
if (s_logger.isDebugEnabled())
s_logger.debug("Executing " + _gson.toJson(cmd));
if (cmd instanceof PrimaryStorageDownloadCommand) {
answer = execute((PrimaryStorageDownloadCommand) cmd);
} else if (cmd instanceof BackupSnapshotCommand) {
answer = execute((BackupSnapshotCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
answer = execute((CreatePrivateTemplateFromVolumeCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
answer = execute((CreatePrivateTemplateFromSnapshotCommand) cmd);
} else if (cmd instanceof CopyVolumeCommand) {
answer = execute((CopyVolumeCommand) cmd);
} else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
answer = execute((CreateVolumeFromSnapshotCommand) cmd);
} else if (cmd instanceof StorageSubSystemCommand) {
answer = storageSubsystemHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
} else if (cmd instanceof CreateEntityDownloadURLCommand) {
answer = execute((CreateEntityDownloadURLCommand) cmd);
} else {
answer = _resource.defaultAction(cmd);
}
// special handling to pass-back context info for cleanups
if (cmd.getContextParam("execid") != null) {
answer.setContextParam("execid", cmd.getContextParam("execid"));
}
if (cmd.getContextParam("checkpoint") != null) {
answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
}
if (cmd.getContextParam("checkpoint2") != null) {
answer.setContextParam("checkpoint2", cmd.getContextParam("checkpoint2"));
}
if (s_logger.isDebugEnabled())
s_logger.debug("Command execution answer: " + _gson.toJson(answer));
return answer;
} finally {
if (s_logger.isDebugEnabled())
s_logger.debug("Done executing " + _gson.toJson(cmd));
recycleServiceContext();
NDC.pop();
}
}
use of com.cloud.agent.api.storage.CreateEntityDownloadURLCommand in project cloudstack by apache.
the class CloudStackImageStoreDriverImpl method createEntityExtractUrl.
@Override
public String createEntityExtractUrl(DataStore store, String installPath, ImageFormat format, DataObject dataObject) {
// find an endpoint to send command
EndPoint ep = _epSelector.select(store);
// Create Symlink at ssvm
String path = installPath;
String uuid = UUID.randomUUID().toString() + "." + format.getFileExtension();
CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(((ImageStoreEntity) store).getMountPoint(), path, uuid, dataObject.getTO());
Answer ans = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
ans = new Answer(cmd, false, errMsg);
} else {
ans = ep.sendMessage(cmd);
}
if (ans == null || !ans.getResult()) {
String errorString = "Unable to create a link for entity at " + installPath + " on ssvm," + ans.getDetails();
s_logger.error(errorString);
throw new CloudRuntimeException(errorString);
}
// Construct actual URL locally now that the symlink exists at SSVM
return generateCopyUrl(ep.getPublicAddr(), uuid);
}
use of com.cloud.agent.api.storage.CreateEntityDownloadURLCommand in project cloudstack by apache.
the class UploadMonitorImpl method createEntityDownloadURL.
@Override
public UploadVO createEntityDownloadURL(VMTemplateVO template, TemplateDataStoreVO vmTemplateHost, Long dataCenterId, long eventId) {
String errorString = "";
boolean success = false;
Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE;
// find an endpoint to send command
DataStore store = storeMgr.getDataStore(vmTemplateHost.getDataStoreId(), DataStoreRole.Image);
EndPoint ep = _epSelector.select(store);
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
return null;
}
//Check if it already exists.
List<UploadVO> extractURLList = _uploadDao.listByTypeUploadStatus(template.getId(), type, UploadVO.Status.DOWNLOAD_URL_CREATED);
if (extractURLList.size() > 0) {
// do some check here
UploadVO upload = extractURLList.get(0);
String uploadUrl = extractURLList.get(0).getUploadUrl();
String[] token = uploadUrl.split("/");
// example: uploadUrl = https://10-11-101-112.realhostip.com/userdata/2fdd9a70-9c4a-4a04-b1d5-1e41c221a1f9.iso
// then token[2] = 10-11-101-112.realhostip.com, token[4] = 2fdd9a70-9c4a-4a04-b1d5-1e41c221a1f9.iso
String hostname = ep.getPublicAddr().replace(".", "-") + ".";
if (// ssvm publicip and domain suffix not changed
(token != null) && (token.length == 5) && (token[2].equals(hostname + _ssvmUrlDomain)))
return extractURLList.get(0);
else if ((token != null) && (token.length == 5) && (token[2].startsWith(hostname))) {
// domain suffix changed
String uuid = token[4];
uploadUrl = generateCopyUrl(ep.getPublicAddr(), uuid);
UploadVO vo = _uploadDao.createForUpdate();
vo.setLastUpdated(new Date());
vo.setUploadUrl(uploadUrl);
_uploadDao.update(upload.getId(), vo);
return _uploadDao.findById(upload.getId(), true);
} else {
// ssvm publicip changed
return null;
}
}
// It doesn't exist so create a DB entry.
UploadVO uploadTemplateObj = new UploadVO(vmTemplateHost.getDataStoreId(), template.getId(), new Date(), Status.DOWNLOAD_URL_NOT_CREATED, 0, type, Mode.HTTP_DOWNLOAD);
uploadTemplateObj.setInstallPath(vmTemplateHost.getInstallPath());
_uploadDao.persist(uploadTemplateObj);
try {
// Create Symlink at ssvm
String path = vmTemplateHost.getInstallPath();
// adding "." + vhd/ova... etc.
String uuid = UUID.randomUUID().toString() + "." + template.getFormat().getFileExtension();
CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(((ImageStoreEntity) store).getMountPoint(), path, uuid, null);
Answer ans = ep.sendMessage(cmd);
if (ans == null || !ans.getResult()) {
errorString = "Unable to create a link for " + type + " id:" + template.getId() + "," + (ans == null ? "" : ans.getDetails());
s_logger.error(errorString);
throw new CloudRuntimeException(errorString);
}
//Construct actual URL locally now that the symlink exists at SSVM
String extractURL = generateCopyUrl(ep.getPublicAddr(), uuid);
UploadVO vo = _uploadDao.createForUpdate();
vo.setLastUpdated(new Date());
vo.setUploadUrl(extractURL);
vo.setUploadState(Status.DOWNLOAD_URL_CREATED);
_uploadDao.update(uploadTemplateObj.getId(), vo);
success = true;
return _uploadDao.findById(uploadTemplateObj.getId(), true);
} finally {
if (!success) {
UploadVO uploadJob = _uploadDao.createForUpdate(uploadTemplateObj.getId());
uploadJob.setLastUpdated(new Date());
uploadJob.setErrorString(errorString);
uploadJob.setUploadState(Status.ERROR);
_uploadDao.update(uploadTemplateObj.getId(), uploadJob);
}
}
}
use of com.cloud.agent.api.storage.CreateEntityDownloadURLCommand in project cloudstack by apache.
the class VMwareGuru method getCommandHostDelegation.
@Override
@DB
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
boolean needDelegation = false;
if (cmd instanceof StorageSubSystemCommand) {
Boolean fullCloneEnabled = VmwareFullClone.value();
StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
c.setExecuteInSequence(fullCloneEnabled);
}
//type is empty, so we need to check the format of volume at first.
if (cmd instanceof CopyCommand) {
CopyCommand cpyCommand = (CopyCommand) cmd;
DataTO srcData = cpyCommand.getSrcTO();
DataStoreTO srcStoreTO = srcData.getDataStore();
DataTO destData = cpyCommand.getDestTO();
DataStoreTO destStoreTO = destData.getDataStore();
boolean inSeq = true;
if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) || (destData.getObjectType() == DataObjectType.SNAPSHOT)) {
inSeq = false;
} else if ((destStoreTO.getRole() == DataStoreRole.Image) || (destStoreTO.getRole() == DataStoreRole.ImageCache)) {
inSeq = false;
} else if (!VmwareFullClone.value()) {
inSeq = false;
}
cpyCommand.setExecuteInSequence(inSeq);
if (srcData.getObjectType() == DataObjectType.VOLUME) {
VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
needDelegation = true;
}
}
if (!needDelegation && !(HypervisorType.VMware == srcData.getHypervisorType() || HypervisorType.VMware == destData.getHypervisorType())) {
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
if (destData.getObjectType() == DataObjectType.VOLUME && destStoreTO.getRole() == DataStoreRole.Primary && srcData.getObjectType() == DataObjectType.TEMPLATE && srcStoreTO.getRole() == DataStoreRole.Primary) {
needDelegation = false;
} else {
needDelegation = true;
}
} else if (cmd instanceof CreateEntityDownloadURLCommand) {
DataTO srcData = ((CreateEntityDownloadURLCommand) cmd).getData();
if ((HypervisorType.VMware == srcData.getHypervisorType())) {
needDelegation = true;
}
if (srcData.getObjectType() == DataObjectType.VOLUME) {
VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
needDelegation = true;
}
}
}
if (!needDelegation) {
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
HostVO host = _hostDao.findById(hostId);
long dcId = host.getDataCenterId();
Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd);
if (cmdTarget != null) {
// TODO, we need to make sure agent is actually connected too
cmd.setContextParam("hypervisor", HypervisorType.VMware.toString());
if (host.getType() == Host.Type.Routing) {
Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId);
cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid")));
cmd.setContextParam("username", hostDetails.get("username"));
cmd.setContextParam("password", hostDetails.get("password"));
cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName());
cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName());
}
CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1);
_cmdExecLogDao.persist(execLog);
cmd.setContextParam("execid", String.valueOf(execLog.getId()));
cmd.setContextParam("noderuninfo", String.format("%d-%d", _clusterMgr.getManagementNodeId(), _clusterMgr.getCurrentRunId()));
cmd.setContextParam("vCenterSessionTimeout", String.valueOf(_vmwareMgr.getVcenterSessionTimeout()));
if (cmd instanceof BackupSnapshotCommand || cmd instanceof CreatePrivateTemplateFromVolumeCommand || cmd instanceof CreatePrivateTemplateFromSnapshotCommand || cmd instanceof CopyVolumeCommand || cmd instanceof CopyCommand || cmd instanceof CreateVolumeOVACommand || cmd instanceof PrepareOVAPackingCommand || cmd instanceof CreateVolumeFromSnapshotCommand) {
String workerName = _vmwareMgr.composeWorkerName();
long checkPointId = 1;
// FIXME: Fix long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName));
cmd.setContextParam("worker", workerName);
cmd.setContextParam("checkpoint", String.valueOf(checkPointId));
// some commands use 2 workers
String workerName2 = _vmwareMgr.composeWorkerName();
long checkPointId2 = 1;
// FIXME: Fix long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2));
cmd.setContextParam("worker2", workerName2);
cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2));
}
return new Pair<Boolean, Long>(Boolean.TRUE, cmdTarget.first().getId());
}
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
use of com.cloud.agent.api.storage.CreateEntityDownloadURLCommand in project cloudstack by apache.
the class UploadMonitorImpl method createVolumeDownloadURL.
@Override
public void createVolumeDownloadURL(Long entityId, String path, Type type, Long dataCenterId, Long uploadId, ImageFormat format) {
String errorString = "";
boolean success = false;
try {
List<HostVO> storageServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.SecondaryStorage, dataCenterId);
if (storageServers == null) {
errorString = "No Storage Server found at the datacenter - " + dataCenterId;
throw new CloudRuntimeException(errorString);
}
// Update DB for state = DOWNLOAD_URL_NOT_CREATED.
UploadVO uploadJob = _uploadDao.createForUpdate(uploadId);
uploadJob.setUploadState(Status.DOWNLOAD_URL_NOT_CREATED);
uploadJob.setLastUpdated(new Date());
_uploadDao.update(uploadJob.getId(), uploadJob);
// Create Symlink at ssvm
String uuid = UUID.randomUUID().toString() + "." + format.toString().toLowerCase();
DataStore secStore = storeMgr.getDataStore(ApiDBUtils.findUploadById(uploadId).getDataStoreId(), DataStoreRole.Image);
EndPoint ep = _epSelector.select(secStore);
if (ep == null) {
errorString = "There is no secondary storage VM for secondary storage host " + secStore.getName();
throw new CloudRuntimeException(errorString);
}
CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(((ImageStoreEntity) secStore).getMountPoint(), path, uuid, null);
Answer ans = ep.sendMessage(cmd);
if (ans == null || !ans.getResult()) {
errorString = "Unable to create a link for " + type + " id:" + entityId + "," + (ans == null ? "" : ans.getDetails());
s_logger.warn(errorString);
throw new CloudRuntimeException(errorString);
}
List<SecondaryStorageVmVO> ssVms = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running);
if (ssVms.size() > 0) {
SecondaryStorageVmVO ssVm = ssVms.get(0);
if (ssVm.getPublicIpAddress() == null) {
errorString = "A running secondary storage vm has a null public ip?";
s_logger.error(errorString);
throw new CloudRuntimeException(errorString);
}
//Construct actual URL locally now that the symlink exists at SSVM
String extractURL = generateCopyUrl(ssVm.getPublicIpAddress(), uuid);
UploadVO vo = _uploadDao.createForUpdate();
vo.setLastUpdated(new Date());
vo.setUploadUrl(extractURL);
vo.setUploadState(Status.DOWNLOAD_URL_CREATED);
_uploadDao.update(uploadId, vo);
success = true;
return;
}
errorString = "Couldnt find a running SSVM in the zone" + dataCenterId + ". Couldnt create the extraction URL.";
throw new CloudRuntimeException(errorString);
} finally {
if (!success) {
UploadVO uploadJob = _uploadDao.createForUpdate(uploadId);
uploadJob.setLastUpdated(new Date());
uploadJob.setErrorString(errorString);
uploadJob.setUploadState(Status.ERROR);
_uploadDao.update(uploadId, uploadJob);
}
}
}
Aggregations