mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
Cleaning up some TODOs related to generating API command responses. Now that the ApiDBUtils class is available, setting things like domainNames is possible, so make use of that.
This commit is contained in:
parent
8607fbe923
commit
be6a4612a4
@ -29,14 +29,18 @@ import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.storage.GuestOSCategoryVO;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.storage.StorageStats;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.DiskOfferingDao;
|
||||
import com.cloud.storage.dao.GuestOSCategoryDao;
|
||||
import com.cloud.storage.dao.GuestOSDao;
|
||||
import com.cloud.storage.dao.SnapshotDao;
|
||||
import com.cloud.storage.dao.StoragePoolDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
@ -73,6 +77,7 @@ public class ApiDBUtils {
|
||||
private static IPAddressDao _ipAddressDao;
|
||||
private static HostPodDao _podDao;
|
||||
private static ServiceOfferingDao _serviceOfferingDao;
|
||||
private static SnapshotDao _snapshotDao;
|
||||
private static StoragePoolDao _storagePoolDao;
|
||||
private static VMTemplateDao _templateDao;
|
||||
private static VMTemplateHostDao _templateHostDao;
|
||||
@ -102,6 +107,7 @@ public class ApiDBUtils {
|
||||
_ipAddressDao = locator.getDao(IPAddressDao.class);
|
||||
_podDao = locator.getDao(HostPodDao.class);
|
||||
_serviceOfferingDao = locator.getDao(ServiceOfferingDao.class);
|
||||
_snapshotDao = locator.getDao(SnapshotDao.class);
|
||||
_storagePoolDao = locator.getDao(StoragePoolDao.class);
|
||||
_templateDao = locator.getDao(VMTemplateDao.class);
|
||||
_templateHostDao = locator.getDao(VMTemplateHostDao.class);
|
||||
@ -167,6 +173,10 @@ public class ApiDBUtils {
|
||||
return _networkGroupMgr.getNetworkGroupsNamesForVm(vmId);
|
||||
}
|
||||
|
||||
public static String getStoragePoolTags(long poolId) {
|
||||
return _storageMgr.getStoragePoolTags(poolId);
|
||||
}
|
||||
|
||||
public static boolean isLocalStorageActiveOnHost(HostVO host) {
|
||||
return _storageMgr.isLocalStorageActiveOnHost(host);
|
||||
}
|
||||
@ -179,6 +189,10 @@ public class ApiDBUtils {
|
||||
return _statsCollector.getHostStats(hostId);
|
||||
}
|
||||
|
||||
public static StorageStats getStoragePoolStatistics(long id) {
|
||||
return _statsCollector.getStoragePoolStats(id);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Dao methods //
|
||||
/////////////////////////////////////////////////////////////
|
||||
@ -229,6 +243,16 @@ public class ApiDBUtils {
|
||||
return _serviceOfferingDao.findById(serviceOfferingId);
|
||||
}
|
||||
|
||||
public static Snapshot findSnapshotById(long snapshotId) {
|
||||
SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
|
||||
if (snapshot != null && snapshot.getRemoved() == null && snapshot.getStatus() == Snapshot.Status.BackedUp) {
|
||||
return snapshot;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static StoragePoolVO findStoragePoolById(Long storagePoolId) {
|
||||
return _storagePoolDao.findById(storagePoolId);
|
||||
}
|
||||
@ -237,6 +261,15 @@ public class ApiDBUtils {
|
||||
return _templateDao.findById(templateId);
|
||||
}
|
||||
|
||||
public static VMTemplateHostVO findTemplateHostRef(long templateId, long zoneId) {
|
||||
HostVO secondaryStorageHost = _storageMgr.getSecondaryStorageHost(zoneId);
|
||||
if (secondaryStorageHost == null) {
|
||||
return null;
|
||||
} else {
|
||||
return _templateHostDao.findByHostTemplate(secondaryStorageHost.getId(), templateId);
|
||||
}
|
||||
}
|
||||
|
||||
public static User findUserById(Long userId) {
|
||||
return _userDao.findById(userId);
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
import com.cloud.api.Implementation;
|
||||
@ -29,6 +30,7 @@ import com.cloud.api.Parameter;
|
||||
import com.cloud.api.response.StoragePoolResponse;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.storage.StorageStats;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Implementation(method="createPool", manager=Manager.StorageManager)
|
||||
@ -109,12 +111,8 @@ public class CreateStoragePoolCmd extends BaseCmd {
|
||||
|
||||
StoragePoolResponse response = new StoragePoolResponse();
|
||||
response.setClusterId(pool.getClusterId());
|
||||
// TODO: Implement
|
||||
//response.setClusterName(pool.getClusterName());
|
||||
//response.setDiskSizeAllocated(pool.getDiskSizeAllocated());
|
||||
//response.setDiskSizeTotal(pool.getDiskSizeTotal());
|
||||
//response.setPodName(pool.getPodName());
|
||||
//response.setTags(pool.getTags());
|
||||
response.setClusterName(ApiDBUtils.findClusterById(pool.getClusterId()).getName());
|
||||
response.setPodName(ApiDBUtils.findPodById(pool.getPodId()).getName());
|
||||
response.setCreated(pool.getCreated());
|
||||
response.setId(pool.getId());
|
||||
response.setIpAddress(pool.getHostAddress());
|
||||
@ -122,6 +120,15 @@ public class CreateStoragePoolCmd extends BaseCmd {
|
||||
response.setPath(pool.getPath());
|
||||
response.setPodId(pool.getPodId());
|
||||
response.setType(pool.getPoolType().toString());
|
||||
response.setTags(ApiDBUtils.getStoragePoolTags(pool.getId()));
|
||||
|
||||
StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId());
|
||||
long used = pool.getCapacityBytes() - pool.getAvailableBytes();
|
||||
if (stats != null) {
|
||||
used = stats.getByteUsed();
|
||||
}
|
||||
response.setDiskSizeTotal(pool.getCapacityBytes());
|
||||
response.setDiskSizeAllocated(used);
|
||||
|
||||
return SerializerHelper.toSerializedString(response);
|
||||
}
|
||||
|
||||
@ -22,11 +22,19 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseAsyncCreateCmd;
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.response.TemplateResponse;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@Implementation(method="createPrivateTemplate", createMethod="createPrivateTemplateRecord", manager=Manager.UserVmManager)
|
||||
public class CreateTemplateCmd extends BaseAsyncCreateCmd {
|
||||
@ -138,28 +146,39 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd {
|
||||
response.setPasswordEnabled(template.getEnablePassword());
|
||||
response.setCrossZones(template.isCrossZones());
|
||||
|
||||
// TODO: implement
|
||||
// VMTemplateHostVO templateHostRef = managerServer.findTemplateHostRef(template.getId(), volume.getDataCenterId());
|
||||
// response.setCreated(templateHostRef.getCreated());
|
||||
// response.setReady(templateHostRef != null && templateHostRef.getDownloadState() == Status.DOWNLOADED);
|
||||
// if (os != null) {
|
||||
// resultObject.setOsTypeId(os.getId());
|
||||
// resultObject.setOsTypeName(os.getDisplayName());
|
||||
// } else {
|
||||
// resultObject.setOsTypeId(-1L);
|
||||
// resultObject.setOsTypeName("");
|
||||
// }
|
||||
// Account owner = managerServer.findAccountById(template.getAccountId());
|
||||
// if (owner != null) {
|
||||
// resultObject.setAccount(owner.getAccountName());
|
||||
// resultObject.setDomainId(owner.getDomainId());
|
||||
// resultObject.setDomainName(managerServer.findDomainIdById(owner.getDomainId()).getName());
|
||||
// }
|
||||
// DataCenterVO zone = managerServer.findDataCenterById(dataCenterId);
|
||||
// if (zone != null) {
|
||||
// resultObject.setZoneId(zone.getId());
|
||||
// resultObject.setZoneName(zone.getName());
|
||||
// }
|
||||
VolumeVO volume = null;
|
||||
if (snapshotId != null) {
|
||||
Snapshot snapshot = ApiDBUtils.findSnapshotById(snapshotId);
|
||||
volume = ApiDBUtils.findVolumeById(snapshot.getVolumeId());
|
||||
} else {
|
||||
volume = ApiDBUtils.findVolumeById(volumeId);
|
||||
}
|
||||
|
||||
VMTemplateHostVO templateHostRef = ApiDBUtils.findTemplateHostRef(template.getId(), volume.getDataCenterId());
|
||||
response.setCreated(templateHostRef.getCreated());
|
||||
response.setReady(templateHostRef != null && templateHostRef.getDownloadState() == Status.DOWNLOADED);
|
||||
|
||||
GuestOS os = ApiDBUtils.findGuestOSById(template.getGuestOSId());
|
||||
if (os != null) {
|
||||
response.setOsTypeId(os.getId());
|
||||
response.setOsTypeName(os.getDisplayName());
|
||||
} else {
|
||||
response.setOsTypeId(-1L);
|
||||
response.setOsTypeName("");
|
||||
}
|
||||
|
||||
Account owner = ApiDBUtils.findAccountById(template.getAccountId());
|
||||
if (owner != null) {
|
||||
response.setAccount(owner.getAccountName());
|
||||
response.setDomainId(owner.getDomainId());
|
||||
response.setDomainName(ApiDBUtils.findDomainById(owner.getDomainId()).getName());
|
||||
}
|
||||
|
||||
DataCenterVO zone = ApiDBUtils.findZoneById(volume.getDataCenterId());
|
||||
if (zone != null) {
|
||||
response.setZoneId(zone.getId());
|
||||
response.setZoneName(zone.getName());
|
||||
}
|
||||
|
||||
return SerializerHelper.toSerializedString(response);
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ package com.cloud.api.commands;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
@ -125,8 +126,7 @@ public class CreateUserCmd extends BaseCmd {
|
||||
response.setAccountType(user.getType());
|
||||
response.setCreated(user.getCreated());
|
||||
response.setDomainId(user.getDomainId());
|
||||
// TODO: implement
|
||||
// response.setDomainName(user.getDomainName());
|
||||
response.setDomainName(ApiDBUtils.findDomainById(user.getDomainId()).getName());
|
||||
response.setEmail(user.getEmail());
|
||||
response.setFirstname(user.getFirstname());
|
||||
response.setId(user.getId());
|
||||
|
||||
@ -20,6 +20,7 @@ package com.cloud.api.commands;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
import com.cloud.api.Implementation;
|
||||
@ -127,6 +128,11 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
|
||||
public String getResponse() {
|
||||
VlanVO vlan = (VlanVO)getResponseObject();
|
||||
|
||||
String domainNameResponse = null;
|
||||
if ((accountName != null) && (domainId != null)) {
|
||||
domainNameResponse = ApiDBUtils.findDomainById(domainId).getName();
|
||||
}
|
||||
|
||||
VlanIpRangeResponse response = new VlanIpRangeResponse();
|
||||
response.setAccountName(accountName);
|
||||
response.setDescription(vlan.getIpRange());
|
||||
@ -140,9 +146,10 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
|
||||
response.setStartIp(startIp);
|
||||
response.setVlan(vlan.getVlanId());
|
||||
response.setZoneId(vlan.getDataCenterId());
|
||||
// TODO: implement
|
||||
// response.setDomainName(vlan.getDomainName());
|
||||
// response.setPodName(podName);
|
||||
response.setDomainName(domainNameResponse);
|
||||
if (podId != null) {
|
||||
response.setPodName(ApiDBUtils.findPodById(podId).getName());
|
||||
}
|
||||
|
||||
return SerializerHelper.toSerializedString(response);
|
||||
}
|
||||
|
||||
@ -119,12 +119,10 @@ import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.DiskTemplateVO;
|
||||
import com.cloud.storage.GuestOSCategoryVO;
|
||||
import com.cloud.storage.GuestOSVO;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.SnapshotPolicyVO;
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.storage.StorageStats;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VolumeStats;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
@ -295,13 +293,7 @@ public interface ManagementServer {
|
||||
* @return StorageStats
|
||||
*/
|
||||
StorageStats getStorageStatistics(long hostId);
|
||||
|
||||
/** Get storage statistics (used/available) for a pool
|
||||
* @param id pool id
|
||||
* @return storage statistics
|
||||
*/
|
||||
StorageStats getStoragePoolStatistics(long id);
|
||||
|
||||
|
||||
/**
|
||||
* Gets Host/VM statistics for a given host
|
||||
*
|
||||
@ -692,14 +684,6 @@ public interface ManagementServer {
|
||||
*/
|
||||
VMTemplateVO findTemplateById(long templateId);
|
||||
|
||||
/**
|
||||
* Finds a template-host reference by the specified template and zone IDs
|
||||
* @param templateId
|
||||
* @param zoneId
|
||||
* @return template-host reference
|
||||
*/
|
||||
VMTemplateHostVO findTemplateHostRef(long templateId, long zoneId);
|
||||
|
||||
/**
|
||||
* Obtains a list of virtual machines by the specified search criteria.
|
||||
* Can search by: "userId", "name", "state", "dataCenterId", "podId", "hostId"
|
||||
@ -1073,13 +1057,6 @@ public interface ManagementServer {
|
||||
*/
|
||||
List<SnapshotVO> listSnapshots(ListSnapshotsCmd cmd) throws InvalidParameterValueException;
|
||||
|
||||
/**
|
||||
* find a single snapshot by id
|
||||
* @param snapshotId
|
||||
* @return the snapshot if found, null otherwise
|
||||
*/
|
||||
Snapshot findSnapshotById(long snapshotId);
|
||||
|
||||
/**
|
||||
* Finds a diskOffering by the specified ID.
|
||||
* @param diskOfferingId
|
||||
@ -1318,13 +1295,6 @@ public interface ManagementServer {
|
||||
boolean isHypervisorSnapshotCapable();
|
||||
List<String> searchForStoragePoolDetails(long poolId, String value);
|
||||
|
||||
/**
|
||||
* Returns a comma separated list of tags for the specified storage pool
|
||||
* @param poolId
|
||||
* @return comma separated list of tags
|
||||
*/
|
||||
String getStoragePoolTags(long poolId);
|
||||
|
||||
public List<PreallocatedLunVO> getPreAllocatedLuns(ListPreallocatedLunsCmd cmd);
|
||||
|
||||
boolean checkLocalStorageConfigVal();
|
||||
|
||||
@ -213,7 +213,6 @@ import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.storage.StorageStats;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.Volume.VolumeType;
|
||||
import com.cloud.storage.VolumeStats;
|
||||
@ -228,7 +227,6 @@ import com.cloud.storage.dao.SnapshotPolicyDao;
|
||||
import com.cloud.storage.dao.StoragePoolDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao.TemplateFilter;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.preallocatedlun.PreallocatedLunVO;
|
||||
import com.cloud.storage.preallocatedlun.dao.PreallocatedLunDao;
|
||||
@ -321,7 +319,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
private final ServiceOfferingDao _offeringsDao;
|
||||
private final DiskOfferingDao _diskOfferingDao;
|
||||
private final VMTemplateDao _templateDao;
|
||||
private final VMTemplateHostDao _templateHostDao;
|
||||
private final LaunchPermissionDao _launchPermissionDao;
|
||||
private final DomainDao _domainDao;
|
||||
private final AccountDao _accountDao;
|
||||
@ -414,7 +411,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
_offeringsDao = locator.getDao(ServiceOfferingDao.class);
|
||||
_diskOfferingDao = locator.getDao(DiskOfferingDao.class);
|
||||
_templateDao = locator.getDao(VMTemplateDao.class);
|
||||
_templateHostDao = locator.getDao(VMTemplateHostDao.class);
|
||||
_launchPermissionDao = locator.getDao(LaunchPermissionDao.class);
|
||||
_domainDao = locator.getDao(DomainDao.class);
|
||||
_accountDao = locator.getDao(AccountDao.class);
|
||||
@ -3519,16 +3515,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return _templateDao.findById(templateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMTemplateHostVO findTemplateHostRef(long templateId, long zoneId) {
|
||||
HostVO secondaryStorageHost = _storageMgr.getSecondaryStorageHost(zoneId);
|
||||
if (secondaryStorageHost == null) {
|
||||
return null;
|
||||
} else {
|
||||
return _templateHostDao.findByHostTemplate(secondaryStorageHost.getId(), templateId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserVmVO> searchForUserVMs(ListVMsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||
Account account = (Account)UserContext.current().getAccountObject();
|
||||
@ -5226,17 +5212,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return _snapshotDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Snapshot findSnapshotById(long snapshotId) {
|
||||
SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
|
||||
if (snapshot != null && snapshot.getRemoved() == null && snapshot.getStatus() == Snapshot.Status.BackedUp) {
|
||||
return snapshot;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskOfferingVO findDiskOfferingById(long diskOfferingId) {
|
||||
return _diskOfferingDao.findById(diskOfferingId);
|
||||
@ -6222,22 +6197,12 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return poolsAndHosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageStats getStoragePoolStatistics(long id) {
|
||||
return _statsCollector.getStoragePoolStats(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> searchForStoragePoolDetails(long poolId, String value)
|
||||
{
|
||||
return _poolDao.searchForStoragePoolDetails(poolId, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStoragePoolTags(long poolId) {
|
||||
return _storageMgr.getStoragePoolTags(poolId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AsyncJobVO> searchForAsyncJobs(ListAsyncJobsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||
Filter searchFilter = new Filter(AsyncJobVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user