mirror of https://github.com/apache/cloudstack.git
Merge remote-tracking branch 'origin/4.19'
This commit is contained in:
commit
33dc7465c2
|
|
@ -102,7 +102,7 @@ public interface ServiceOffering extends InfrastructureEntity, InternalIdentity,
|
|||
|
||||
boolean getDefaultUse();
|
||||
|
||||
String getSystemVmType();
|
||||
String getVmType();
|
||||
|
||||
String getDeploymentPlanner();
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,9 @@ public interface RoleService {
|
|||
* Moreover, we will check if the requested role is of 'Admin' type; roles with 'Admin' type should only be visible to 'root admins'.
|
||||
* Therefore, if a non-'root admin' user tries to search for an 'Admin' role, this method will return null.
|
||||
*/
|
||||
Role findRole(Long id, boolean removePrivateRoles);
|
||||
Role findRole(Long id, boolean ignorePrivateRoles);
|
||||
|
||||
List<Role> findRoles(List<Long> ids, boolean ignorePrivateRoles);
|
||||
|
||||
Role findRole(Long id);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,4 +25,18 @@ import java.io.Serializable;
|
|||
|
||||
public interface InternalIdentity extends Serializable {
|
||||
long getId();
|
||||
|
||||
/*
|
||||
Helper method to add conditions in joins where some column name is equal to a string value
|
||||
*/
|
||||
default Object setString(String str) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
Helper method to add conditions in joins where some column name is equal to a long value
|
||||
*/
|
||||
default Object setLong(Long l) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,4 +142,19 @@ public interface PrimaryDataStoreDriver extends DataStoreDriver {
|
|||
boolean isStorageSupportHA(StoragePoolType type);
|
||||
|
||||
void detachVolumeFromAllStorageNodes(Volume volume);
|
||||
/**
|
||||
* Data store driver needs its grantAccess() method called for volumes in order for them to be used with a host.
|
||||
* @return true if we should call grantAccess() to use a volume
|
||||
*/
|
||||
default boolean volumesRequireGrantAccessWhenUsed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zone-wide data store supports using a volume across clusters without the need for data motion
|
||||
* @return true if we don't need to data motion volumes across clusters for zone-wide use
|
||||
*/
|
||||
default boolean zoneWideVolumesAvailableWithoutClusterMotion() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1858,6 +1858,18 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
|
|||
return _volsDao.persist(volume);
|
||||
}
|
||||
|
||||
protected void grantVolumeAccessToHostIfNeeded(PrimaryDataStore volumeStore, long volumeId, Host host, String volToString) {
|
||||
PrimaryDataStoreDriver driver = (PrimaryDataStoreDriver)volumeStore.getDriver();
|
||||
if (!driver.volumesRequireGrantAccessWhenUsed()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
volService.grantAccess(volFactory.getVolume(volumeId), host, volumeStore);
|
||||
} catch (Exception e) {
|
||||
throw new StorageAccessException(String.format("Unable to grant access to volume [%s] on host [%s].", volToString, host));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException, StorageAccessException {
|
||||
if (dest == null) {
|
||||
|
|
@ -1875,18 +1887,18 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
|
|||
|
||||
List<VolumeTask> tasks = getTasks(vols, dest.getStorageForDisks(), vm);
|
||||
Volume vol = null;
|
||||
StoragePool pool;
|
||||
PrimaryDataStore store;
|
||||
for (VolumeTask task : tasks) {
|
||||
if (task.type == VolumeTaskType.NOP) {
|
||||
vol = task.volume;
|
||||
|
||||
String volToString = getReflectOnlySelectedFields(vol);
|
||||
|
||||
pool = (StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
|
||||
store = (PrimaryDataStore)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
|
||||
|
||||
// For zone-wide managed storage, it is possible that the VM can be started in another
|
||||
// cluster. In that case, make sure that the volume is in the right access group.
|
||||
if (pool.isManaged()) {
|
||||
if (store.isManaged()) {
|
||||
Host lastHost = _hostDao.findById(vm.getVirtualMachine().getLastHostId());
|
||||
Host host = _hostDao.findById(vm.getVirtualMachine().getHostId());
|
||||
|
||||
|
|
@ -1895,37 +1907,27 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
|
|||
|
||||
if (lastClusterId != clusterId) {
|
||||
if (lastHost != null) {
|
||||
storageMgr.removeStoragePoolFromCluster(lastHost.getId(), vol.get_iScsiName(), pool);
|
||||
|
||||
DataStore storagePool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
|
||||
|
||||
volService.revokeAccess(volFactory.getVolume(vol.getId()), lastHost, storagePool);
|
||||
storageMgr.removeStoragePoolFromCluster(lastHost.getId(), vol.get_iScsiName(), store);
|
||||
volService.revokeAccess(volFactory.getVolume(vol.getId()), lastHost, store);
|
||||
}
|
||||
|
||||
try {
|
||||
volService.grantAccess(volFactory.getVolume(vol.getId()), host, (DataStore)pool);
|
||||
volService.grantAccess(volFactory.getVolume(vol.getId()), host, store);
|
||||
} catch (Exception e) {
|
||||
throw new StorageAccessException(String.format("Unable to grant access to volume [%s] on host [%s].", volToString, host));
|
||||
}
|
||||
} else {
|
||||
// This might impact other managed storages, grant access for PowerFlex and Iscsi/Solidfire storage pool only
|
||||
if (pool.getPoolType() == Storage.StoragePoolType.PowerFlex || pool.getPoolType() == Storage.StoragePoolType.Iscsi) {
|
||||
try {
|
||||
volService.grantAccess(volFactory.getVolume(vol.getId()), host, (DataStore)pool);
|
||||
} catch (Exception e) {
|
||||
throw new StorageAccessException(String.format("Unable to grant access to volume [%s] on host [%s].", volToString, host));
|
||||
}
|
||||
}
|
||||
grantVolumeAccessToHostIfNeeded(store, vol.getId(), host, volToString);
|
||||
}
|
||||
} else {
|
||||
handleCheckAndRepairVolume(vol, vm.getVirtualMachine().getHostId());
|
||||
}
|
||||
} else if (task.type == VolumeTaskType.MIGRATE) {
|
||||
pool = (StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
|
||||
vol = migrateVolume(task.volume, pool);
|
||||
store = (PrimaryDataStore) dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
|
||||
vol = migrateVolume(task.volume, store);
|
||||
} else if (task.type == VolumeTaskType.RECREATE) {
|
||||
Pair<VolumeVO, DataStore> result = recreateVolume(task.volume, vm, dest);
|
||||
pool = (StoragePool)dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary);
|
||||
store = (PrimaryDataStore) dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary);
|
||||
vol = result.first();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,13 @@ package org.apache.cloudstack.engine.orchestration;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
|
@ -31,14 +38,22 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import com.cloud.configuration.Resource;
|
||||
import com.cloud.exception.StorageAccessException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.user.ResourceLimitService;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class VolumeOrchestratorTest {
|
||||
|
||||
@Mock
|
||||
protected ResourceLimitService resourceLimitMgr;
|
||||
@Mock
|
||||
protected VolumeService volumeService;
|
||||
@Mock
|
||||
protected VolumeDataFactory volumeDataFactory;
|
||||
|
||||
@Spy
|
||||
@InjectMocks
|
||||
|
|
@ -100,4 +115,44 @@ public class VolumeOrchestratorTest {
|
|||
public void testCheckAndUpdateVolumeAccountResourceCountLessSize() {
|
||||
runCheckAndUpdateVolumeAccountResourceCountTest(20L, 10L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGrantVolumeAccessToHostIfNeededDriverNoNeed() {
|
||||
PrimaryDataStore store = Mockito.mock(PrimaryDataStore.class);
|
||||
PrimaryDataStoreDriver driver = Mockito.mock(PrimaryDataStoreDriver.class);
|
||||
Mockito.when(driver.volumesRequireGrantAccessWhenUsed()).thenReturn(false);
|
||||
Mockito.when(store.getDriver()).thenReturn(driver);
|
||||
volumeOrchestrator.grantVolumeAccessToHostIfNeeded(store, 1L,
|
||||
Mockito.mock(HostVO.class), "");
|
||||
Mockito.verify(volumeService, Mockito.never())
|
||||
.grantAccess(Mockito.any(DataObject.class), Mockito.any(Host.class), Mockito.any(DataStore.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGrantVolumeAccessToHostIfNeededDriverNeeds() {
|
||||
PrimaryDataStore store = Mockito.mock(PrimaryDataStore.class);
|
||||
PrimaryDataStoreDriver driver = Mockito.mock(PrimaryDataStoreDriver.class);
|
||||
Mockito.when(driver.volumesRequireGrantAccessWhenUsed()).thenReturn(true);
|
||||
Mockito.when(store.getDriver()).thenReturn(driver);
|
||||
Mockito.when(volumeDataFactory.getVolume(Mockito.anyLong())).thenReturn(Mockito.mock(VolumeInfo.class));
|
||||
Mockito.doReturn(true).when(volumeService)
|
||||
.grantAccess(Mockito.any(DataObject.class), Mockito.any(Host.class), Mockito.any(DataStore.class));
|
||||
volumeOrchestrator.grantVolumeAccessToHostIfNeeded(store, 1L,
|
||||
Mockito.mock(HostVO.class), "");
|
||||
Mockito.verify(volumeService, Mockito.times(1))
|
||||
.grantAccess(Mockito.any(DataObject.class), Mockito.any(Host.class), Mockito.any(DataStore.class));
|
||||
}
|
||||
|
||||
@Test(expected = StorageAccessException.class)
|
||||
public void testGrantVolumeAccessToHostIfNeededDriverNeedsButException() {
|
||||
PrimaryDataStore store = Mockito.mock(PrimaryDataStore.class);
|
||||
PrimaryDataStoreDriver driver = Mockito.mock(PrimaryDataStoreDriver.class);
|
||||
Mockito.when(driver.volumesRequireGrantAccessWhenUsed()).thenReturn(true);
|
||||
Mockito.when(store.getDriver()).thenReturn(driver);
|
||||
Mockito.when(volumeDataFactory.getVolume(Mockito.anyLong())).thenReturn(Mockito.mock(VolumeInfo.class));
|
||||
Mockito.doThrow(CloudRuntimeException.class).when(volumeService)
|
||||
.grantAccess(Mockito.any(DataObject.class), Mockito.any(Host.class), Mockito.any(DataStore.class));
|
||||
volumeOrchestrator.grantVolumeAccessToHostIfNeeded(store, 1L,
|
||||
Mockito.mock(HostVO.class), "");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ public class ServiceOfferingVO implements ServiceOffering {
|
|||
limitCpuUse = offering.getLimitCpuUse();
|
||||
volatileVm = offering.isVolatileVm();
|
||||
hostTag = offering.getHostTag();
|
||||
vmType = offering.getSystemVmType();
|
||||
vmType = offering.getVmType();
|
||||
systemUse = offering.isSystemUse();
|
||||
dynamicScalingEnabled = offering.isDynamicScalingEnabled();
|
||||
diskOfferingStrictness = offering.diskOfferingStrictness;
|
||||
|
|
@ -278,7 +278,7 @@ public class ServiceOfferingVO implements ServiceOffering {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getSystemVmType() {
|
||||
public String getVmType() {
|
||||
return vmType;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,4 +37,6 @@ public interface RoleDao extends GenericDao<RoleVO, Long> {
|
|||
Pair<List<RoleVO>, Integer> findAllByRoleType(RoleType type, Long offset, Long limit, boolean showPrivateRole);
|
||||
|
||||
Pair<List<RoleVO>, Integer> listAllRoles(Long startIndex, Long limit, boolean showPrivateRole);
|
||||
|
||||
List<RoleVO> searchByIds(Long... ids);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,13 @@ import org.apache.cloudstack.acl.RoleVO;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class RoleDaoImpl extends GenericDaoBase<RoleVO, Long> implements RoleDao {
|
||||
|
||||
private final SearchBuilder<RoleVO> RoleByIdsSearch;
|
||||
private final SearchBuilder<RoleVO> RoleByNameSearch;
|
||||
private final SearchBuilder<RoleVO> RoleByTypeSearch;
|
||||
private final SearchBuilder<RoleVO> RoleByNameAndTypeSearch;
|
||||
|
|
@ -40,6 +43,10 @@ public class RoleDaoImpl extends GenericDaoBase<RoleVO, Long> implements RoleDao
|
|||
public RoleDaoImpl() {
|
||||
super();
|
||||
|
||||
RoleByIdsSearch = createSearchBuilder();
|
||||
RoleByIdsSearch.and("idIN", RoleByIdsSearch.entity().getId(), SearchCriteria.Op.IN);
|
||||
RoleByIdsSearch.done();
|
||||
|
||||
RoleByNameSearch = createSearchBuilder();
|
||||
RoleByNameSearch.and("roleName", RoleByNameSearch.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
RoleByNameSearch.and("isPublicRole", RoleByNameSearch.entity().isPublicRole(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -116,6 +123,16 @@ public class RoleDaoImpl extends GenericDaoBase<RoleVO, Long> implements RoleDao
|
|||
return searchAndCount(sc, new Filter(RoleVO.class, "id", true, startIndex, limit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleVO> searchByIds(Long... ids) {
|
||||
if (ids == null || ids.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
SearchCriteria<RoleVO> sc = RoleByIdsSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
public void filterPrivateRolesIfNeeded(SearchCriteria<RoleVO> sc, boolean showPrivateRole) {
|
||||
if (!showPrivateRole) {
|
||||
sc.setParameters("isPublicRole", true);
|
||||
|
|
|
|||
|
|
@ -65,6 +65,10 @@ public class DiskOfferingDetailVO implements ResourceDetail {
|
|||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
|
|
|
|||
|
|
@ -51,4 +51,6 @@ public interface ImageStoreDao extends GenericDao<ImageStoreVO, Long> {
|
|||
ImageStoreVO findOneByZoneAndProtocol(long zoneId, String protocol);
|
||||
|
||||
List<ImageStoreVO> listImageStoresByZoneIds(Long... zoneIds);
|
||||
|
||||
List<ImageStoreVO> listByIds(List<Long> ids);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@
|
|||
*/
|
||||
package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.utils.db.Filter;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
|
|
@ -44,6 +46,7 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implem
|
|||
private SearchBuilder<ImageStoreVO> zoneProtocolSearch;
|
||||
|
||||
private SearchBuilder<ImageStoreVO> zonesInSearch;
|
||||
private SearchBuilder<ImageStoreVO> IdsSearch;
|
||||
|
||||
public ImageStoreDaoImpl() {
|
||||
super();
|
||||
|
|
@ -62,6 +65,9 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implem
|
|||
zonesInSearch.and("zonesIn", zonesInSearch.entity().getDcId(), SearchCriteria.Op.IN);
|
||||
zonesInSearch.done();
|
||||
|
||||
IdsSearch = createSearchBuilder();
|
||||
IdsSearch.and("ids", IdsSearch.entity().getId(), SearchCriteria.Op.IN);
|
||||
IdsSearch.done();
|
||||
}
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
|
|
@ -206,4 +212,14 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implem
|
|||
sc.setParametersIfNotNull("zonesIn", zoneIds);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImageStoreVO> listByIds(List<Long> ids) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
SearchCriteria<ImageStoreVO> sc = IdsSearch.create();
|
||||
sc.setParameters("ids", ids.toArray());
|
||||
return listBy(sc);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
|||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.StoragePoolStatus;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
/**
|
||||
|
|
@ -140,4 +142,10 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
|
|||
List<StoragePoolVO> findPoolsByStorageType(Storage.StoragePoolType storageType);
|
||||
|
||||
List<StoragePoolVO> listStoragePoolsWithActiveVolumesByOfferingId(long offeringid);
|
||||
|
||||
Pair<List<Long>, Integer> searchForIdsAndCount(Long storagePoolId, String storagePoolName, Long zoneId,
|
||||
String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status,
|
||||
String keyword, Filter searchFilter);
|
||||
|
||||
List<StoragePoolVO> listByIds(List<Long> ids);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,16 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
||||
import com.cloud.host.Status;
|
||||
|
|
@ -58,6 +62,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
|
|||
private final SearchBuilder<StoragePoolVO> DcLocalStorageSearch;
|
||||
private final GenericSearchBuilder<StoragePoolVO, Long> StatusCountSearch;
|
||||
private final SearchBuilder<StoragePoolVO> ClustersSearch;
|
||||
private final SearchBuilder<StoragePoolVO> IdsSearch;
|
||||
|
||||
@Inject
|
||||
private StoragePoolDetailsDao _detailsDao;
|
||||
|
|
@ -144,6 +149,11 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
|
|||
ClustersSearch = createSearchBuilder();
|
||||
ClustersSearch.and("clusterIds", ClustersSearch.entity().getClusterId(), Op.IN);
|
||||
ClustersSearch.and("status", ClustersSearch.entity().getStatus(), Op.EQ);
|
||||
ClustersSearch.done();
|
||||
|
||||
IdsSearch = createSearchBuilder();
|
||||
IdsSearch.and("ids", IdsSearch.entity().getId(), SearchCriteria.Op.IN);
|
||||
IdsSearch.done();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -670,4 +680,92 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
|
|||
throw new CloudRuntimeException("Caught: " + sql, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<List<Long>, Integer> searchForIdsAndCount(Long storagePoolId, String storagePoolName, Long zoneId,
|
||||
String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status,
|
||||
String keyword, Filter searchFilter) {
|
||||
SearchCriteria<StoragePoolVO> sc = createStoragePoolSearchCriteria(storagePoolId, storagePoolName, zoneId, path, podId, clusterId, address, scopeType, status, keyword);
|
||||
Pair<List<StoragePoolVO>, Integer> uniquePair = searchAndCount(sc, searchFilter);
|
||||
List<Long> idList = uniquePair.first().stream().map(StoragePoolVO::getId).collect(Collectors.toList());
|
||||
return new Pair<>(idList, uniquePair.second());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StoragePoolVO> listByIds(List<Long> ids) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
SearchCriteria<StoragePoolVO> sc = IdsSearch.create();
|
||||
sc.setParameters("ids", ids.toArray());
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
private SearchCriteria<StoragePoolVO> createStoragePoolSearchCriteria(Long storagePoolId, String storagePoolName,
|
||||
Long zoneId, String path, Long podId, Long clusterId, String address, ScopeType scopeType,
|
||||
StoragePoolStatus status, String keyword) {
|
||||
SearchBuilder<StoragePoolVO> sb = createSearchBuilder();
|
||||
sb.select(null, SearchCriteria.Func.DISTINCT, sb.entity().getId()); // select distinct
|
||||
// ids
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
sb.and("path", sb.entity().getPath(), SearchCriteria.Op.EQ);
|
||||
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
|
||||
sb.and("hostAddress", sb.entity().getHostAddress(), SearchCriteria.Op.EQ);
|
||||
sb.and("scope", sb.entity().getScope(), SearchCriteria.Op.EQ);
|
||||
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
|
||||
sb.and("parent", sb.entity().getParent(), SearchCriteria.Op.EQ);
|
||||
|
||||
SearchCriteria<StoragePoolVO> sc = sb.create();
|
||||
|
||||
if (keyword != null) {
|
||||
SearchCriteria<StoragePoolVO> ssc = createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
ssc.addOr("poolType", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
|
||||
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
|
||||
if (storagePoolId != null) {
|
||||
sc.setParameters("id", storagePoolId);
|
||||
}
|
||||
|
||||
if (storagePoolName != null) {
|
||||
sc.setParameters("name", storagePoolName);
|
||||
}
|
||||
|
||||
if (path != null) {
|
||||
sc.setParameters("path", path);
|
||||
}
|
||||
if (zoneId != null) {
|
||||
sc.setParameters("dataCenterId", zoneId);
|
||||
}
|
||||
if (podId != null) {
|
||||
SearchCriteria<StoragePoolVO> ssc = createSearchCriteria();
|
||||
ssc.addOr("podId", SearchCriteria.Op.EQ, podId);
|
||||
ssc.addOr("podId", SearchCriteria.Op.NULL);
|
||||
|
||||
sc.addAnd("podId", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
if (address != null) {
|
||||
sc.setParameters("hostAddress", address);
|
||||
}
|
||||
if (clusterId != null) {
|
||||
SearchCriteria<StoragePoolVO> ssc = createSearchCriteria();
|
||||
ssc.addOr("clusterId", SearchCriteria.Op.EQ, clusterId);
|
||||
ssc.addOr("clusterId", SearchCriteria.Op.NULL);
|
||||
|
||||
sc.addAnd("clusterId", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
if (scopeType != null) {
|
||||
sc.setParameters("scope", scopeType.toString());
|
||||
}
|
||||
if (status != null) {
|
||||
sc.setParameters("status", status.toString());
|
||||
}
|
||||
sc.setParameters("parent", 0);
|
||||
return sc;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ SELECT
|
|||
FROM
|
||||
`cloud`.`service_offering`
|
||||
INNER JOIN
|
||||
`cloud`.`disk_offering_view` AS `disk_offering` ON service_offering.disk_offering_id = disk_offering.id
|
||||
`cloud`.`disk_offering` ON service_offering.disk_offering_id = disk_offering.id AND `disk_offering`.`state`='Active'
|
||||
LEFT JOIN
|
||||
`cloud`.`service_offering_details` AS `domain_details` ON `domain_details`.`service_offering_id` = `service_offering`.`id` AND `domain_details`.`name`='domainid'
|
||||
LEFT JOIN
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ public class Attribute {
|
|||
|
||||
protected String table;
|
||||
protected String columnName;
|
||||
protected Object value;
|
||||
protected Field field;
|
||||
protected int flags;
|
||||
protected Column column;
|
||||
|
|
@ -100,6 +101,10 @@ public class Attribute {
|
|||
this.column = null;
|
||||
}
|
||||
|
||||
public Attribute(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
protected void setupColumnInfo(Class<?> clazz, AttributeOverride[] overrides, String tableName, boolean isEmbedded, boolean isId) {
|
||||
flags = Flag.Selectable.setTrue(flags);
|
||||
GeneratedValue gv = field.getAnnotation(GeneratedValue.class);
|
||||
|
|
@ -214,6 +219,10 @@ public class Attribute {
|
|||
return field;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object get(Object entity) {
|
||||
try {
|
||||
return field.get(entity);
|
||||
|
|
|
|||
|
|
@ -286,4 +286,6 @@ public interface GenericDao<T, ID extends Serializable> {
|
|||
Pair<List<T>, Integer> searchAndDistinctCount(final SearchCriteria<T> sc, final Filter filter, final String[] distinctColumns);
|
||||
|
||||
Integer countAll();
|
||||
|
||||
List<T> findByUuids(String... uuidArray);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ import javax.persistence.Enumerated;
|
|||
import javax.persistence.Table;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
import com.amazonaws.util.CollectionUtils;
|
||||
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
|
|
@ -376,10 +377,11 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
}
|
||||
|
||||
Collection<JoinBuilder<SearchCriteria<?>>> joins = null;
|
||||
List<Attribute> joinAttrList = null;
|
||||
if (sc != null) {
|
||||
joins = sc.getJoins();
|
||||
if (joins != null) {
|
||||
addJoins(str, joins);
|
||||
joinAttrList = addJoins(str, joins);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -399,6 +401,13 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||
int i = 1;
|
||||
|
||||
if (!CollectionUtils.isNullOrEmpty(joinAttrList)) {
|
||||
for (Attribute attr : joinAttrList) {
|
||||
prepareAttribute(i++, pstmt, attr, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (clause != null) {
|
||||
for (final Pair<Attribute, Object> value : sc.getValues()) {
|
||||
prepareAttribute(i++, pstmt, value.first(), value.second());
|
||||
|
|
@ -451,8 +460,9 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
|
||||
Collection<JoinBuilder<SearchCriteria<?>>> joins = null;
|
||||
joins = sc.getJoins();
|
||||
List<Attribute> joinAttrList = null;
|
||||
if (joins != null) {
|
||||
addJoins(str, joins);
|
||||
joinAttrList = addJoins(str, joins);
|
||||
}
|
||||
|
||||
List<Object> groupByValues = addGroupBy(str, sc);
|
||||
|
|
@ -465,6 +475,13 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||
int i = 1;
|
||||
|
||||
if (!CollectionUtils.isNullOrEmpty(joinAttrList)) {
|
||||
for (Attribute attr : joinAttrList) {
|
||||
prepareAttribute(i++, pstmt, attr, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (clause != null) {
|
||||
for (final Pair<Attribute, Object> value : sc.getValues()) {
|
||||
prepareAttribute(i++, pstmt, value.first(), value.second());
|
||||
|
|
@ -1278,12 +1295,13 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
}
|
||||
|
||||
@DB()
|
||||
protected void addJoins(StringBuilder str, Collection<JoinBuilder<SearchCriteria<?>>> joins) {
|
||||
addJoins(str, joins, new HashMap<>());
|
||||
protected List<Attribute> addJoins(StringBuilder str, Collection<JoinBuilder<SearchCriteria<?>>> joins) {
|
||||
return addJoins(str, joins, new HashMap<>());
|
||||
}
|
||||
|
||||
@DB()
|
||||
protected void addJoins(StringBuilder str, Collection<JoinBuilder<SearchCriteria<?>>> joins, Map<String, Integer> joinedTableNames) {
|
||||
protected List<Attribute> addJoins(StringBuilder str, Collection<JoinBuilder<SearchCriteria<?>>> joins, Map<String, String> joinedTableNames) {
|
||||
List<Attribute> joinAttrList = new ArrayList<>();
|
||||
boolean hasWhereClause = true;
|
||||
int fromIndex = str.lastIndexOf("WHERE");
|
||||
if (fromIndex == -1) {
|
||||
|
|
@ -1294,8 +1312,14 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
}
|
||||
|
||||
for (JoinBuilder<SearchCriteria<?>> join : joins) {
|
||||
String joinTableName = join.getSecondAttribute().table;
|
||||
String joinTableAlias = findNextJoinTableName(joinTableName, joinedTableNames);
|
||||
String joinTableName = join.getSecondAttribute()[0].table;
|
||||
String joinTableAlias;
|
||||
if (StringUtils.isNotEmpty(join.getName())) {
|
||||
joinTableAlias = join.getName();
|
||||
joinedTableNames.put(joinTableName, joinTableAlias);
|
||||
} else {
|
||||
joinTableAlias = joinedTableNames.getOrDefault(joinTableName, joinTableName);
|
||||
}
|
||||
StringBuilder onClause = new StringBuilder();
|
||||
onClause.append(" ")
|
||||
.append(join.getType().getName())
|
||||
|
|
@ -1304,21 +1328,36 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
if (!joinTableAlias.equals(joinTableName)) {
|
||||
onClause.append(" ").append(joinTableAlias);
|
||||
}
|
||||
onClause.append(" ON ")
|
||||
.append(join.getFirstAttribute().table)
|
||||
.append(".")
|
||||
.append(join.getFirstAttribute().columnName)
|
||||
.append("=");
|
||||
if(!joinTableAlias.equals(joinTableName)) {
|
||||
onClause.append(joinTableAlias);
|
||||
} else {
|
||||
onClause.append(joinTableName);
|
||||
onClause.append(" ON ");
|
||||
for (int i = 0; i < join.getFirstAttributes().length; i++) {
|
||||
if (i > 0) {
|
||||
onClause.append(join.getCondition().getName());
|
||||
}
|
||||
if (join.getFirstAttributes()[i].getValue() != null) {
|
||||
onClause.append("?");
|
||||
joinAttrList.add(join.getFirstAttributes()[i]);
|
||||
} else {
|
||||
onClause.append(joinedTableNames.getOrDefault(join.getFirstAttributes()[i].table, join.getFirstAttributes()[i].table))
|
||||
.append(".")
|
||||
.append(join.getFirstAttributes()[i].columnName);
|
||||
}
|
||||
onClause.append("=");
|
||||
if (join.getSecondAttribute()[i].getValue() != null) {
|
||||
onClause.append("?");
|
||||
joinAttrList.add(join.getSecondAttribute()[i]);
|
||||
} else {
|
||||
if(!joinTableAlias.equals(joinTableName)) {
|
||||
onClause.append(joinTableAlias);
|
||||
} else {
|
||||
onClause.append(joinTableName);
|
||||
}
|
||||
onClause.append(".")
|
||||
.append(join.getSecondAttribute()[i].columnName);
|
||||
}
|
||||
}
|
||||
onClause.append(".")
|
||||
.append(join.getSecondAttribute().columnName)
|
||||
.append(" ");
|
||||
onClause.append(" ");
|
||||
str.insert(fromIndex, onClause);
|
||||
String whereClause = join.getT().getWhereClause();
|
||||
String whereClause = join.getT().getWhereClause(joinTableAlias);
|
||||
if (StringUtils.isNotEmpty(whereClause)) {
|
||||
if (!hasWhereClause) {
|
||||
str.append(" WHERE ");
|
||||
|
|
@ -1335,20 +1374,10 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
|
||||
for (JoinBuilder<SearchCriteria<?>> join : joins) {
|
||||
if (join.getT().getJoins() != null) {
|
||||
addJoins(str, join.getT().getJoins(), joinedTableNames);
|
||||
joinAttrList.addAll(addJoins(str, join.getT().getJoins(), joinedTableNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static String findNextJoinTableName(String tableName, Map<String, Integer> usedTableNames) {
|
||||
if (usedTableNames.containsKey(tableName)) {
|
||||
Integer tableCounter = usedTableNames.get(tableName);
|
||||
usedTableNames.put(tableName, ++tableCounter);
|
||||
tableName = tableName + tableCounter;
|
||||
} else {
|
||||
usedTableNames.put(tableName, 0);
|
||||
}
|
||||
return tableName;
|
||||
return joinAttrList;
|
||||
}
|
||||
|
||||
private void removeAndClause(StringBuilder sql) {
|
||||
|
|
@ -1601,13 +1630,28 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
return;
|
||||
}
|
||||
}
|
||||
if(attr.field.getDeclaredAnnotation(Convert.class) != null) {
|
||||
|
||||
if (attr.getValue() != null && attr.getValue() instanceof String) {
|
||||
pstmt.setString(j, (String)attr.getValue());
|
||||
} else if (attr.getValue() != null && attr.getValue() instanceof Long) {
|
||||
pstmt.setLong(j, (Long)attr.getValue());
|
||||
} else if(attr.field.getDeclaredAnnotation(Convert.class) != null) {
|
||||
Object val = _conversionSupport.convertToDatabaseColumn(attr.field, value);
|
||||
pstmt.setObject(j, val);
|
||||
} else if (attr.field.getType() == String.class) {
|
||||
final String str = (String)value;
|
||||
if (str == null) {
|
||||
pstmt.setString(j, null);
|
||||
final String str;
|
||||
try {
|
||||
str = (String) value;
|
||||
if (str == null) {
|
||||
pstmt.setString(j, null);
|
||||
return;
|
||||
}
|
||||
} catch (ClassCastException ex) {
|
||||
// This happens when we pass in an integer, long or any other object which can't be cast to String.
|
||||
// Converting to string in case of integer or long can result in different results. Required specifically for details tables.
|
||||
// So, we set the value for the object directly.
|
||||
logger.debug("ClassCastException when casting value to String. Setting the value of the object directly.");
|
||||
pstmt.setObject(j, value);
|
||||
return;
|
||||
}
|
||||
final Column column = attr.field.getAnnotation(Column.class);
|
||||
|
|
@ -2027,10 +2071,11 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
}
|
||||
|
||||
Collection<JoinBuilder<SearchCriteria<?>>> joins = null;
|
||||
List<Attribute> joinAttrList = null;
|
||||
if (sc != null) {
|
||||
joins = sc.getJoins();
|
||||
if (joins != null) {
|
||||
addJoins(str, joins);
|
||||
joinAttrList = addJoins(str, joins);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2043,6 +2088,13 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||
int i = 1;
|
||||
|
||||
if (!CollectionUtils.isNullOrEmpty(joinAttrList)) {
|
||||
for (Attribute attr : joinAttrList) {
|
||||
prepareAttribute(i++, pstmt, attr, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (clause != null) {
|
||||
for (final Pair<Attribute, Object> value : sc.getValues()) {
|
||||
prepareAttribute(i++, pstmt, value.first(), value.second());
|
||||
|
|
@ -2090,10 +2142,11 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
}
|
||||
|
||||
Collection<JoinBuilder<SearchCriteria<?>>> joins = null;
|
||||
List<Attribute> joinAttrList = null;
|
||||
if (sc != null) {
|
||||
joins = sc.getJoins();
|
||||
if (joins != null) {
|
||||
addJoins(str, joins);
|
||||
joinAttrList = addJoins(str, joins);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2102,6 +2155,13 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
|
||||
try (PreparedStatement pstmt = txn.prepareAutoCloseStatement(sql)) {
|
||||
int i = 1;
|
||||
|
||||
if (!CollectionUtils.isNullOrEmpty(joinAttrList)) {
|
||||
for (Attribute attr : joinAttrList) {
|
||||
prepareAttribute(i++, pstmt, attr, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (clause != null) {
|
||||
for (final Pair<Attribute, Object> value : sc.getValues()) {
|
||||
prepareAttribute(i++, pstmt, value.first(), value.second());
|
||||
|
|
@ -2128,6 +2188,13 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
return getCount(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> findByUuids(String... uuidArray) {
|
||||
SearchCriteria<T> sc = createSearchCriteria();
|
||||
sc.addAnd("uuid", SearchCriteria.Op.IN, uuidArray);
|
||||
return search(sc, null);
|
||||
}
|
||||
|
||||
public Integer getCount(SearchCriteria<T> sc) {
|
||||
sc = checkAndSetRemovedIsNull(sc);
|
||||
return getCountIncludingRemoved(sc);
|
||||
|
|
@ -2145,10 +2212,11 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
}
|
||||
|
||||
Collection<JoinBuilder<SearchCriteria<?>>> joins = null;
|
||||
List<Attribute> joinAttrList = null;
|
||||
if (sc != null) {
|
||||
joins = sc.getJoins();
|
||||
if (joins != null) {
|
||||
addJoins(str, joins);
|
||||
joinAttrList = addJoins(str, joins);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2159,6 +2227,13 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||
int i = 1;
|
||||
|
||||
if (!CollectionUtils.isNullOrEmpty(joinAttrList)) {
|
||||
for (Attribute attr : joinAttrList) {
|
||||
prepareAttribute(i++, pstmt, attr, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (clause != null) {
|
||||
for (final Pair<Attribute, Object> value : sc.getValues()) {
|
||||
prepareAttribute(i++, pstmt, value.first(), value.second());
|
||||
|
|
|
|||
|
|
@ -80,6 +80,12 @@ public class GenericSearchBuilder<T, K> extends SearchBase<GenericSearchBuilder<
|
|||
return this;
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> and(String joinName, String name, Object field, Op op) {
|
||||
SearchBase<?, ?, ?> join = _joins.get(joinName).getT();
|
||||
constructCondition(joinName, name, " AND ", join._specifiedAttrs.get(0), op);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an AND condition. Some prefer this method because it looks like
|
||||
* the actual SQL query.
|
||||
|
|
@ -134,6 +140,12 @@ public class GenericSearchBuilder<T, K> extends SearchBase<GenericSearchBuilder<
|
|||
return this;
|
||||
}
|
||||
|
||||
protected GenericSearchBuilder<T, K> left(String joinName, Object field, Op op, String name) {
|
||||
SearchBase<?, ?, ?> joinSb = _joins.get(joinName).getT();
|
||||
constructCondition(joinName, name, " ( ", joinSb._specifiedAttrs.get(0), op);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Preset left(Object field, Op op) {
|
||||
Condition condition = constructCondition(UUID.randomUUID().toString(), " ( ", _specifiedAttrs.get(0), op);
|
||||
return new Preset(this, condition);
|
||||
|
|
@ -169,6 +181,10 @@ public class GenericSearchBuilder<T, K> extends SearchBase<GenericSearchBuilder<
|
|||
return left(field, op, name);
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> op(String joinName, String name, Object field, Op op) {
|
||||
return left(joinName, field, op, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an OR condition to the SearchBuilder.
|
||||
*
|
||||
|
|
@ -182,6 +198,12 @@ public class GenericSearchBuilder<T, K> extends SearchBase<GenericSearchBuilder<
|
|||
return this;
|
||||
}
|
||||
|
||||
public GenericSearchBuilder<T, K> or(String joinName, String name, Object field, Op op) {
|
||||
SearchBase<?, ?, ?> join = _joins.get(joinName).getT();
|
||||
constructCondition(joinName, name, " OR ", join._specifiedAttrs.get(0), op);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an OR condition
|
||||
*
|
||||
|
|
|
|||
|
|
@ -31,19 +31,57 @@ public class JoinBuilder<T> {
|
|||
return _name;
|
||||
}
|
||||
}
|
||||
public enum JoinCondition {
|
||||
AND(" AND "), OR(" OR ");
|
||||
|
||||
private final String name;
|
||||
|
||||
JoinCondition(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private final T t;
|
||||
private final String name;
|
||||
private JoinType type;
|
||||
private Attribute firstAttribute;
|
||||
private Attribute secondAttribute;
|
||||
|
||||
public JoinBuilder(T t, Attribute firstAttribute, Attribute secondAttribute, JoinType type) {
|
||||
private JoinCondition condition;
|
||||
private Attribute[] firstAttributes;
|
||||
private Attribute[] secondAttribute;
|
||||
|
||||
public JoinBuilder(String name, T t, Attribute firstAttributes, Attribute secondAttribute, JoinType type) {
|
||||
this.name = name;
|
||||
this.t = t;
|
||||
this.firstAttribute = firstAttribute;
|
||||
this.firstAttributes = new Attribute[]{firstAttributes};
|
||||
this.secondAttribute = new Attribute[]{secondAttribute};
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public JoinBuilder(String name, T t, Attribute[] firstAttributes, Attribute[] secondAttribute, JoinType type) {
|
||||
this.name = name;
|
||||
this.t = t;
|
||||
this.firstAttributes = firstAttributes;
|
||||
this.secondAttribute = secondAttribute;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public JoinBuilder(String name, T t, Attribute[] firstAttributes, Attribute[] secondAttribute, JoinType type, JoinCondition condition) {
|
||||
this.name = name;
|
||||
this.t = t;
|
||||
this.firstAttributes = firstAttributes;
|
||||
this.secondAttribute = secondAttribute;
|
||||
this.type = type;
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public T getT() {
|
||||
return t;
|
||||
}
|
||||
|
|
@ -56,19 +94,23 @@ public class JoinBuilder<T> {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public Attribute getFirstAttribute() {
|
||||
return firstAttribute;
|
||||
public JoinCondition getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public void setFirstAttribute(Attribute firstAttribute) {
|
||||
this.firstAttribute = firstAttribute;
|
||||
public Attribute[] getFirstAttributes() {
|
||||
return firstAttributes;
|
||||
}
|
||||
|
||||
public Attribute getSecondAttribute() {
|
||||
public void setFirstAttributes(Attribute[] firstAttributes) {
|
||||
this.firstAttributes = firstAttributes;
|
||||
}
|
||||
|
||||
public Attribute[] getSecondAttribute() {
|
||||
return secondAttribute;
|
||||
}
|
||||
|
||||
public void setSecondAttribute(Attribute secondAttribute) {
|
||||
public void setSecondAttribute(Attribute[] secondAttribute) {
|
||||
this.secondAttribute = secondAttribute;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||
import net.sf.cglib.proxy.Factory;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* SearchBase contains the methods that are used to build up search
|
||||
|
|
@ -70,6 +71,14 @@ public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
|
|||
init(entityType, resultType);
|
||||
}
|
||||
|
||||
public SearchBase<?, ?, ?> getJoinSB(String name) {
|
||||
JoinBuilder<SearchBase<?, ?, ?>> jb = null;
|
||||
if (_joins != null) {
|
||||
jb = _joins.get(name);
|
||||
}
|
||||
return jb == null ? null : jb.getT();
|
||||
}
|
||||
|
||||
protected void init(final Class<T> entityType, final Class<K> resultType) {
|
||||
_dao = (GenericDaoBase<? extends T, ? extends Serializable>)GenericDaoBase.getDao(entityType);
|
||||
if (_dao == null) {
|
||||
|
|
@ -194,15 +203,45 @@ public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
|
|||
* @param joinType type of join
|
||||
* @return itself
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public J join(final String name, final SearchBase<?, ?, ?> builder, final Object joinField1, final Object joinField2, final JoinBuilder.JoinType joinType) {
|
||||
assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert _specifiedAttrs.size() == 1 : "You didn't select the attribute.";
|
||||
assert builder._entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert builder._specifiedAttrs.size() == 1 : "You didn't select the attribute.";
|
||||
assert builder != this : "You can't add yourself, can you? Really think about it!";
|
||||
if (_specifiedAttrs.size() != 1)
|
||||
throw new CloudRuntimeException("You didn't select the attribute.");
|
||||
if (builder._specifiedAttrs.size() != 1)
|
||||
throw new CloudRuntimeException("You didn't select the attribute.");
|
||||
|
||||
final JoinBuilder<SearchBase<?, ?, ?>> t = new JoinBuilder<SearchBase<?, ?, ?>>(builder, _specifiedAttrs.get(0), builder._specifiedAttrs.get(0), joinType);
|
||||
return join(name, builder, joinType, null, joinField1, joinField2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* joins this search with another search with multiple conditions in the join clause
|
||||
*
|
||||
* @param name name given to the other search. used for setJoinParameters.
|
||||
* @param builder The other search
|
||||
* @param joinType type of join
|
||||
* @param condition condition to be used for multiple conditions in the join clause
|
||||
* @param joinFields fields the first and second table used to perform the join.
|
||||
* The fields should be in the order of the checks between the two tables.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public J join(final String name, final SearchBase<?, ?, ?> builder, final JoinBuilder.JoinType joinType, final
|
||||
JoinBuilder.JoinCondition condition, final Object... joinFields) {
|
||||
if (_entity == null)
|
||||
throw new CloudRuntimeException("SearchBuilder cannot be modified once it has been setup");
|
||||
if (_specifiedAttrs.isEmpty())
|
||||
throw new CloudRuntimeException("Attribute not specified.");
|
||||
if (builder._entity == null)
|
||||
throw new CloudRuntimeException("SearchBuilder cannot be modified once it has been setup");
|
||||
if (builder._specifiedAttrs.isEmpty())
|
||||
throw new CloudRuntimeException("Attribute not specified.");
|
||||
if (builder == this)
|
||||
throw new CloudRuntimeException("Can't join with itself. Create a new SearchBuilder for the same entity and use that.");
|
||||
if (_specifiedAttrs.size() != builder._specifiedAttrs.size())
|
||||
throw new CloudRuntimeException("Number of attributes to join on must be the same.");
|
||||
|
||||
final JoinBuilder<SearchBase<?, ?, ?>> t = new JoinBuilder<>(name, builder, _specifiedAttrs.toArray(new Attribute[0]),
|
||||
builder._specifiedAttrs.toArray(new Attribute[0]), joinType, condition);
|
||||
if (_joins == null) {
|
||||
_joins = new HashMap<String, JoinBuilder<SearchBase<?, ?, ?>>>();
|
||||
}
|
||||
|
|
@ -223,6 +262,16 @@ public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
|
|||
_specifiedAttrs.add(attr);
|
||||
}
|
||||
|
||||
/*
|
||||
Allows to set conditions in join where one entity is equivalent to a string or a long
|
||||
e.g. join("vm", vmSearch, VmDetailVO.class, entity.getName(), "vm.id", SearchCriteria.Op.EQ);
|
||||
will create a condition 'vm.name = "vm.id"'
|
||||
*/
|
||||
protected void setAttr(final Object obj) {
|
||||
final Attribute attr = new Attribute(obj);
|
||||
_specifiedAttrs.add(attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return entity object. This allows the caller to use the entity return
|
||||
* to specify the field to be selected in many of the search parameters.
|
||||
|
|
@ -242,17 +291,26 @@ public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
|
|||
return _specifiedAttrs;
|
||||
}
|
||||
|
||||
protected Condition constructCondition(final String conditionName, final String cond, final Attribute attr, final Op op) {
|
||||
protected Condition constructCondition(final String joinName, final String conditionName, final String cond, final Attribute attr, final Op op) {
|
||||
assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
|
||||
assert op == null || _specifiedAttrs.size() == 1 : "You didn't select the attribute.";
|
||||
assert op != Op.SC : "Call join";
|
||||
|
||||
final Condition condition = new Condition(conditionName, cond, attr, op);
|
||||
if (StringUtils.isNotEmpty(joinName)) {
|
||||
condition.setJoinName(joinName);
|
||||
}
|
||||
_conditions.add(condition);
|
||||
_specifiedAttrs.clear();
|
||||
return condition;
|
||||
}
|
||||
|
||||
|
||||
protected Condition constructCondition(final String conditionName, final String cond, final Attribute attr, final Op op) {
|
||||
return constructCondition(null, conditionName, cond, attr, op);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* creates the SearchCriteria so the actual values can be filled in.
|
||||
*
|
||||
|
|
@ -364,6 +422,7 @@ public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
|
|||
protected static class Condition {
|
||||
protected final String name;
|
||||
protected final String cond;
|
||||
protected String joinName;
|
||||
protected final Op op;
|
||||
protected final Attribute attr;
|
||||
protected Object[] presets;
|
||||
|
|
@ -388,11 +447,15 @@ public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
|
|||
this.presets = presets;
|
||||
}
|
||||
|
||||
public void setJoinName(final String joinName) {
|
||||
this.joinName = joinName;
|
||||
}
|
||||
|
||||
public Object[] getPresets() {
|
||||
return presets;
|
||||
}
|
||||
|
||||
public void toSql(final StringBuilder sql, final Object[] params, final int count) {
|
||||
public void toSql(final StringBuilder sql, String tableAlias, final Object[] params, final int count) {
|
||||
if (count > 0) {
|
||||
sql.append(cond);
|
||||
}
|
||||
|
|
@ -414,7 +477,15 @@ public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
|
|||
sql.append(" FIND_IN_SET(?, ");
|
||||
}
|
||||
|
||||
sql.append(attr.table).append(".").append(attr.columnName).append(op.toString());
|
||||
if (tableAlias == null) {
|
||||
if (joinName != null) {
|
||||
tableAlias = joinName;
|
||||
} else {
|
||||
tableAlias = attr.table;
|
||||
}
|
||||
}
|
||||
|
||||
sql.append(tableAlias).append(".").append(attr.columnName).append(op.toString());
|
||||
if (op == Op.IN && params.length == 1) {
|
||||
sql.delete(sql.length() - op.toString().length(), sql.length());
|
||||
sql.append("=?");
|
||||
|
|
@ -485,6 +556,8 @@ public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
|
|||
final String fieldName = Character.toLowerCase(name.charAt(2)) + name.substring(3);
|
||||
set(fieldName);
|
||||
return null;
|
||||
} else if (name.equals("setLong") || name.equals("setString")) {
|
||||
setAttr(args[0]);
|
||||
} else {
|
||||
final Column ann = method.getAnnotation(Column.class);
|
||||
if (ann != null) {
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public class SearchCriteria<K> {
|
|||
for (Map.Entry<String, JoinBuilder<SearchBase<?, ?, ?>>> entry : sb._joins.entrySet()) {
|
||||
JoinBuilder<SearchBase<?, ?, ?>> value = entry.getValue();
|
||||
_joins.put(entry.getKey(),
|
||||
new JoinBuilder<SearchCriteria<?>>(value.getT().create(), value.getFirstAttribute(), value.getSecondAttribute(), value.getType()));
|
||||
new JoinBuilder<SearchCriteria<?>>(entry.getKey(), value.getT().create(), value.getFirstAttributes(), value.getSecondAttribute(), value.getType(), value.getCondition()));
|
||||
}
|
||||
}
|
||||
_selects = sb._selects;
|
||||
|
|
@ -250,7 +250,7 @@ public class SearchCriteria<K> {
|
|||
_additionals.add(condition);
|
||||
}
|
||||
|
||||
public String getWhereClause() {
|
||||
public String getWhereClause(String tableAlias) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
int i = 0;
|
||||
for (Condition condition : _conditions) {
|
||||
|
|
@ -259,7 +259,7 @@ public class SearchCriteria<K> {
|
|||
}
|
||||
Object[] params = _params.get(condition.name);
|
||||
if ((condition.op == null || condition.op.params == 0) || (params != null)) {
|
||||
condition.toSql(sql, params, i++);
|
||||
condition.toSql(sql, tableAlias, params, i++);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -269,13 +269,17 @@ public class SearchCriteria<K> {
|
|||
}
|
||||
Object[] params = _params.get(condition.name);
|
||||
if ((condition.op.params == 0) || (params != null)) {
|
||||
condition.toSql(sql, params, i++);
|
||||
condition.toSql(sql, tableAlias, params, i++);
|
||||
}
|
||||
}
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
public String getWhereClause() {
|
||||
return getWhereClause(null);
|
||||
}
|
||||
|
||||
public List<Pair<Attribute, Object>> getValues() {
|
||||
ArrayList<Pair<Attribute, Object>> params = new ArrayList<Pair<Attribute, Object>>(_params.size());
|
||||
for (Condition condition : _conditions) {
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
|
@ -229,12 +227,16 @@ public class GenericDaoBaseTest {
|
|||
Attribute attr2 = new Attribute("table2", "column2");
|
||||
Attribute attr3 = new Attribute("table3", "column1");
|
||||
Attribute attr4 = new Attribute("table4", "column2");
|
||||
Attribute attr5 = new Attribute("table3", "column1");
|
||||
Attribute attr6 = new Attribute("XYZ");
|
||||
|
||||
joins.add(new JoinBuilder<>(dbTestDao.createSearchCriteria(), attr1, attr2, JoinBuilder.JoinType.INNER));
|
||||
joins.add(new JoinBuilder<>(dbTestDao.createSearchCriteria(), attr3, attr4, JoinBuilder.JoinType.INNER));
|
||||
joins.add(new JoinBuilder<>("", dbTestDao.createSearchCriteria(), attr1, attr2, JoinBuilder.JoinType.INNER));
|
||||
joins.add(new JoinBuilder<>("", dbTestDao.createSearchCriteria(),
|
||||
new Attribute[]{attr3, attr5}, new Attribute[]{attr4, attr6}, JoinBuilder.JoinType.INNER, JoinBuilder.JoinCondition.OR));
|
||||
dbTestDao.addJoins(joinString, joins);
|
||||
|
||||
Assert.assertEquals(" INNER JOIN table2 ON table1.column1=table2.column2 INNER JOIN table4 ON table3.column1=table4.column2 ", joinString.toString());
|
||||
Assert.assertEquals(" INNER JOIN table2 ON table1.column1=table2.column2 " +
|
||||
" INNER JOIN table4 ON table3.column1=table4.column2 OR table3.column1=? ", joinString.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -248,22 +250,17 @@ public class GenericDaoBaseTest {
|
|||
Attribute tBc2 = new Attribute("tableB", "column2");
|
||||
Attribute tCc3 = new Attribute("tableC", "column3");
|
||||
Attribute tDc4 = new Attribute("tableD", "column4");
|
||||
Attribute tDc5 = new Attribute("tableD", "column5");
|
||||
Attribute attr = new Attribute(123);
|
||||
|
||||
joins.add(new JoinBuilder<>(dbTestDao.createSearchCriteria(), tBc2, tAc1, JoinBuilder.JoinType.INNER));
|
||||
joins.add(new JoinBuilder<>(dbTestDao.createSearchCriteria(), tCc3, tAc2, JoinBuilder.JoinType.INNER));
|
||||
joins.add(new JoinBuilder<>(dbTestDao.createSearchCriteria(), tDc4, tAc3, JoinBuilder.JoinType.INNER));
|
||||
joins.add(new JoinBuilder<>("tableA1Alias", dbTestDao.createSearchCriteria(), tBc2, tAc1, JoinBuilder.JoinType.INNER));
|
||||
joins.add(new JoinBuilder<>("tableA2Alias", dbTestDao.createSearchCriteria(), tCc3, tAc2, JoinBuilder.JoinType.INNER));
|
||||
joins.add(new JoinBuilder<>("tableA3Alias", dbTestDao.createSearchCriteria(),
|
||||
new Attribute[]{tDc4, tDc5}, new Attribute[]{tAc3, attr}, JoinBuilder.JoinType.INNER, JoinBuilder.JoinCondition.AND));
|
||||
dbTestDao.addJoins(joinString, joins);
|
||||
|
||||
Assert.assertEquals(" INNER JOIN tableA ON tableB.column2=tableA.column1 INNER JOIN tableA tableA1 ON tableC.column3=tableA1.column2 INNER JOIN tableA tableA2 ON tableD.column4=tableA2.column3 ", joinString.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findNextTableNameTest() {
|
||||
Map<String, Integer> usedTables = new HashMap<>();
|
||||
|
||||
Assert.assertEquals("tableA", GenericDaoBase.findNextJoinTableName("tableA", usedTables));
|
||||
Assert.assertEquals("tableA1", GenericDaoBase.findNextJoinTableName("tableA", usedTables));
|
||||
Assert.assertEquals("tableA2", GenericDaoBase.findNextJoinTableName("tableA", usedTables));
|
||||
Assert.assertEquals("tableA3", GenericDaoBase.findNextJoinTableName("tableA", usedTables));
|
||||
Assert.assertEquals(" INNER JOIN tableA tableA1Alias ON tableB.column2=tableA1Alias.column1 " +
|
||||
" INNER JOIN tableA tableA2Alias ON tableC.column3=tableA2Alias.column2 " +
|
||||
" INNER JOIN tableA tableA3Alias ON tableD.column4=tableA3Alias.column3 AND tableD.column5=? ", joinString.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,12 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.utils.Ternary;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ListClustersMetricsCmd;
|
||||
|
|
@ -632,6 +634,7 @@ public class MetricsServiceImpl extends MutualExclusiveIdsManagerBase implements
|
|||
@Override
|
||||
public List<StoragePoolMetricsResponse> listStoragePoolMetrics(List<StoragePoolResponse> poolResponses) {
|
||||
final List<StoragePoolMetricsResponse> metricsResponses = new ArrayList<>();
|
||||
Map<String, Long> clusterUuidToIdMap = clusterDao.findByUuids(poolResponses.stream().map(StoragePoolResponse::getClusterId).toArray(String[]::new)).stream().collect(Collectors.toMap(ClusterVO::getUuid, ClusterVO::getId));
|
||||
for (final StoragePoolResponse poolResponse: poolResponses) {
|
||||
StoragePoolMetricsResponse metricsResponse = new StoragePoolMetricsResponse();
|
||||
|
||||
|
|
@ -641,11 +644,7 @@ public class MetricsServiceImpl extends MutualExclusiveIdsManagerBase implements
|
|||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate storagepool metrics response");
|
||||
}
|
||||
|
||||
Long poolClusterId = null;
|
||||
final Cluster cluster = clusterDao.findByUuid(poolResponse.getClusterId());
|
||||
if (cluster != null) {
|
||||
poolClusterId = cluster.getId();
|
||||
}
|
||||
Long poolClusterId = clusterUuidToIdMap.get(poolResponse.getClusterId());
|
||||
final Double storageThreshold = AlertManager.StorageCapacityThreshold.valueIn(poolClusterId);
|
||||
final Double storageDisableThreshold = CapacityManager.StorageCapacityDisableThreshold.valueIn(poolClusterId);
|
||||
|
||||
|
|
|
|||
|
|
@ -1891,4 +1891,9 @@ public class DateraPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
|||
@Override
|
||||
public void detachVolumeFromAllStorageNodes(Volume volume) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean volumesRequireGrantAccessWhenUsed() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,4 +269,9 @@ public class NexentaPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
|||
@Override
|
||||
public void detachVolumeFromAllStorageNodes(Volume volume) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean volumesRequireGrantAccessWhenUsed() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1431,4 +1431,14 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
|||
@Override
|
||||
public void detachVolumeFromAllStorageNodes(Volume volume) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean volumesRequireGrantAccessWhenUsed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoneWideVolumesAvailableWithoutClusterMotion() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1673,4 +1673,9 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
|||
@Override
|
||||
public void detachVolumeFromAllStorageNodes(Volume volume) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean volumesRequireGrantAccessWhenUsed() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@
|
|||
package com.cloud.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
|
@ -2077,6 +2079,29 @@ public class ApiDBUtils {
|
|||
return response;
|
||||
}
|
||||
|
||||
public static List<AccountResponse> newAccountResponses(ResponseView view, EnumSet<DomainDetails> details, AccountJoinVO... accounts) {
|
||||
List<AccountResponse> responseList = new ArrayList<>();
|
||||
|
||||
List<Long> roleIdList = Arrays.stream(accounts).map(AccountJoinVO::getRoleId).collect(Collectors.toList());
|
||||
Map<Long,Role> roleIdMap = s_roleService.findRoles(roleIdList, false).stream().collect(Collectors.toMap(Role::getId, Function.identity()));
|
||||
|
||||
for (AccountJoinVO account : accounts) {
|
||||
AccountResponse response = s_accountJoinDao.newAccountResponse(view, details, account);
|
||||
// Populate account role information
|
||||
if (account.getRoleId() != null) {
|
||||
Role role = roleIdMap.get(account.getRoleId());
|
||||
if (role != null) {
|
||||
response.setRoleId(role.getUuid());
|
||||
response.setRoleType(role.getRoleType());
|
||||
response.setRoleName(role.getName());
|
||||
}
|
||||
}
|
||||
responseList.add(response);
|
||||
}
|
||||
|
||||
return responseList;
|
||||
}
|
||||
|
||||
public static AccountJoinVO newAccountView(Account e) {
|
||||
return s_accountJoinDao.newAccountView(e);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -542,11 +542,7 @@ public class ViewResponseHelper {
|
|||
}
|
||||
|
||||
public static List<AccountResponse> createAccountResponse(ResponseView view, EnumSet<DomainDetails> details, AccountJoinVO... accounts) {
|
||||
List<AccountResponse> respList = new ArrayList<AccountResponse>();
|
||||
for (AccountJoinVO vt : accounts){
|
||||
respList.add(ApiDBUtils.newAccountResponse(view, details, vt));
|
||||
}
|
||||
return respList;
|
||||
return ApiDBUtils.newAccountResponses(view, details, accounts);
|
||||
}
|
||||
|
||||
public static List<AsyncJobResponse> createAsyncJobResponse(AsyncJobJoinVO... jobs) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package com.cloud.api.query.dao;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants.DomainDetails;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
|
|
@ -35,4 +36,5 @@ public interface AccountJoinDao extends GenericDao<AccountJoinVO, Long> {
|
|||
|
||||
void setResourceLimits(AccountJoinVO account, boolean accountIsAdmin, ResourceLimitAndCountResponse response);
|
||||
|
||||
List<AccountJoinVO> searchByIds(Long... ids);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@
|
|||
// under the License.
|
||||
package com.cloud.api.query.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants.DomainDetails;
|
||||
|
|
@ -44,12 +46,19 @@ import com.cloud.utils.db.SearchCriteria;
|
|||
@Component
|
||||
public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> implements AccountJoinDao {
|
||||
|
||||
@Inject
|
||||
private ConfigurationDao configDao;
|
||||
private final SearchBuilder<AccountJoinVO> acctIdSearch;
|
||||
private final SearchBuilder<AccountJoinVO> domainSearch;
|
||||
@Inject
|
||||
AccountManager _acctMgr;
|
||||
|
||||
protected AccountJoinDaoImpl() {
|
||||
|
||||
domainSearch = createSearchBuilder();
|
||||
domainSearch.and("idIN", domainSearch.entity().getId(), SearchCriteria.Op.IN);
|
||||
domainSearch.done();
|
||||
|
||||
acctIdSearch = createSearchBuilder();
|
||||
acctIdSearch.and("id", acctIdSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
acctIdSearch.done();
|
||||
|
|
@ -230,6 +239,50 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
|
|||
response.setSecondaryStorageAvailable(secondaryStorageAvail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AccountJoinVO> searchByIds(Long... accountIds) {
|
||||
// set detail batch query size
|
||||
int DETAILS_BATCH_SIZE = 2000;
|
||||
String batchCfg = configDao.getValue("detail.batch.query.size");
|
||||
if (batchCfg != null) {
|
||||
DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg);
|
||||
}
|
||||
|
||||
List<AccountJoinVO> uvList = new ArrayList<>();
|
||||
// query details by batches
|
||||
int curr_index = 0;
|
||||
if (accountIds.length > DETAILS_BATCH_SIZE) {
|
||||
while ((curr_index + DETAILS_BATCH_SIZE) <= accountIds.length) {
|
||||
Long[] ids = new Long[DETAILS_BATCH_SIZE];
|
||||
for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) {
|
||||
ids[k] = accountIds[j];
|
||||
}
|
||||
SearchCriteria<AccountJoinVO> sc = domainSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
List<AccountJoinVO> accounts = searchIncludingRemoved(sc, null, null, false);
|
||||
if (accounts != null) {
|
||||
uvList.addAll(accounts);
|
||||
}
|
||||
curr_index += DETAILS_BATCH_SIZE;
|
||||
}
|
||||
}
|
||||
if (curr_index < accountIds.length) {
|
||||
int batch_size = (accountIds.length - curr_index);
|
||||
// set the ids value
|
||||
Long[] ids = new Long[batch_size];
|
||||
for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) {
|
||||
ids[k] = accountIds[j];
|
||||
}
|
||||
SearchCriteria<AccountJoinVO> sc = domainSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
List<AccountJoinVO> accounts = searchIncludingRemoved(sc, null, null, false);
|
||||
if (accounts != null) {
|
||||
uvList.addAll(accounts);
|
||||
}
|
||||
}
|
||||
return uvList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountJoinVO newAccountView(Account acct) {
|
||||
SearchCriteria<AccountJoinVO> sc = acctIdSearch.create();
|
||||
|
|
|
|||
|
|
@ -33,4 +33,6 @@ public interface DiskOfferingJoinDao extends GenericDao<DiskOfferingJoinVO, Long
|
|||
DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO dof);
|
||||
|
||||
DiskOfferingJoinVO newDiskOfferingView(DiskOffering dof);
|
||||
|
||||
List<DiskOfferingJoinVO> searchByIds(Long... idArray);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
// under the License.
|
||||
package com.cloud.api.query.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ import org.apache.cloudstack.annotation.dao.AnnotationDao;
|
|||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.response.DiskOfferingResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
|
|
@ -49,9 +51,12 @@ public class DiskOfferingJoinDaoImpl extends GenericDaoBase<DiskOfferingJoinVO,
|
|||
@Inject
|
||||
private AnnotationDao annotationDao;
|
||||
@Inject
|
||||
private ConfigurationDao configDao;
|
||||
@Inject
|
||||
private AccountManager accountManager;
|
||||
|
||||
private final SearchBuilder<DiskOfferingJoinVO> dofIdSearch;
|
||||
private SearchBuilder<DiskOfferingJoinVO> diskOfferingSearch;
|
||||
private final Attribute _typeAttr;
|
||||
|
||||
protected DiskOfferingJoinDaoImpl() {
|
||||
|
|
@ -60,6 +65,11 @@ public class DiskOfferingJoinDaoImpl extends GenericDaoBase<DiskOfferingJoinVO,
|
|||
dofIdSearch.and("id", dofIdSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
dofIdSearch.done();
|
||||
|
||||
diskOfferingSearch = createSearchBuilder();
|
||||
diskOfferingSearch.and("idIN", diskOfferingSearch.entity().getId(), SearchCriteria.Op.IN);
|
||||
diskOfferingSearch.done();
|
||||
|
||||
|
||||
_typeAttr = _allAttributes.get("type");
|
||||
|
||||
_count = "select count(distinct id) from disk_offering_view WHERE ";
|
||||
|
|
@ -152,4 +162,48 @@ public class DiskOfferingJoinDaoImpl extends GenericDaoBase<DiskOfferingJoinVO,
|
|||
assert offerings != null && offerings.size() == 1 : "No disk offering found for offering id " + offering.getId();
|
||||
return offerings.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DiskOfferingJoinVO> searchByIds(Long... offeringIds) {
|
||||
// set detail batch query size
|
||||
int DETAILS_BATCH_SIZE = 2000;
|
||||
String batchCfg = configDao.getValue("detail.batch.query.size");
|
||||
if (batchCfg != null) {
|
||||
DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg);
|
||||
}
|
||||
|
||||
List<DiskOfferingJoinVO> uvList = new ArrayList<>();
|
||||
// query details by batches
|
||||
int curr_index = 0;
|
||||
if (offeringIds.length > DETAILS_BATCH_SIZE) {
|
||||
while ((curr_index + DETAILS_BATCH_SIZE) <= offeringIds.length) {
|
||||
Long[] ids = new Long[DETAILS_BATCH_SIZE];
|
||||
for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) {
|
||||
ids[k] = offeringIds[j];
|
||||
}
|
||||
SearchCriteria<DiskOfferingJoinVO> sc = diskOfferingSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
List<DiskOfferingJoinVO> accounts = searchIncludingRemoved(sc, null, null, false);
|
||||
if (accounts != null) {
|
||||
uvList.addAll(accounts);
|
||||
}
|
||||
curr_index += DETAILS_BATCH_SIZE;
|
||||
}
|
||||
}
|
||||
if (curr_index < offeringIds.length) {
|
||||
int batch_size = (offeringIds.length - curr_index);
|
||||
// set the ids value
|
||||
Long[] ids = new Long[batch_size];
|
||||
for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) {
|
||||
ids[k] = offeringIds[j];
|
||||
}
|
||||
SearchCriteria<DiskOfferingJoinVO> sc = diskOfferingSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
List<DiskOfferingJoinVO> accounts = searchIncludingRemoved(sc, null, null, false);
|
||||
if (accounts != null) {
|
||||
uvList.addAll(accounts);
|
||||
}
|
||||
}
|
||||
return uvList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package com.cloud.api.query.dao;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants.DomainDetails;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
|
|
@ -35,4 +36,5 @@ public interface DomainJoinDao extends GenericDao<DomainJoinVO, Long> {
|
|||
|
||||
void setResourceLimits(DomainJoinVO domain, boolean isRootDomain, ResourceLimitAndCountResponse response);
|
||||
|
||||
List<DomainJoinVO> searchByIds(Long... domainIds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
// under the License.
|
||||
package com.cloud.api.query.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -29,6 +30,7 @@ import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
|||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ResourceLimitAndCountResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
|
|
@ -45,10 +47,13 @@ import javax.inject.Inject;
|
|||
public class DomainJoinDaoImpl extends GenericDaoBase<DomainJoinVO, Long> implements DomainJoinDao {
|
||||
|
||||
private SearchBuilder<DomainJoinVO> domainIdSearch;
|
||||
private SearchBuilder<DomainJoinVO> domainSearch;
|
||||
|
||||
@Inject
|
||||
private AnnotationDao annotationDao;
|
||||
@Inject
|
||||
private ConfigurationDao configDao;
|
||||
@Inject
|
||||
private AccountManager accountManager;
|
||||
|
||||
protected DomainJoinDaoImpl() {
|
||||
|
|
@ -57,6 +62,10 @@ public class DomainJoinDaoImpl extends GenericDaoBase<DomainJoinVO, Long> implem
|
|||
domainIdSearch.and("id", domainIdSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
domainIdSearch.done();
|
||||
|
||||
domainSearch = createSearchBuilder();
|
||||
domainSearch.and("idIN", domainSearch.entity().getId(), SearchCriteria.Op.IN);
|
||||
domainSearch.done();
|
||||
|
||||
this._count = "select count(distinct id) from domain_view WHERE ";
|
||||
}
|
||||
|
||||
|
|
@ -205,6 +214,50 @@ public class DomainJoinDaoImpl extends GenericDaoBase<DomainJoinVO, Long> implem
|
|||
response.setSecondaryStorageAvailable(secondaryStorageAvail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DomainJoinVO> searchByIds(Long... domainIds) {
|
||||
// set detail batch query size
|
||||
int DETAILS_BATCH_SIZE = 2000;
|
||||
String batchCfg = configDao.getValue("detail.batch.query.size");
|
||||
if (batchCfg != null) {
|
||||
DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg);
|
||||
}
|
||||
|
||||
List<DomainJoinVO> uvList = new ArrayList<>();
|
||||
// query details by batches
|
||||
int curr_index = 0;
|
||||
if (domainIds.length > DETAILS_BATCH_SIZE) {
|
||||
while ((curr_index + DETAILS_BATCH_SIZE) <= domainIds.length) {
|
||||
Long[] ids = new Long[DETAILS_BATCH_SIZE];
|
||||
for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) {
|
||||
ids[k] = domainIds[j];
|
||||
}
|
||||
SearchCriteria<DomainJoinVO> sc = domainSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
List<DomainJoinVO> domains = searchIncludingRemoved(sc, null, null, false);
|
||||
if (domains != null) {
|
||||
uvList.addAll(domains);
|
||||
}
|
||||
curr_index += DETAILS_BATCH_SIZE;
|
||||
}
|
||||
}
|
||||
if (curr_index < domainIds.length) {
|
||||
int batch_size = (domainIds.length - curr_index);
|
||||
// set the ids value
|
||||
Long[] ids = new Long[batch_size];
|
||||
for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) {
|
||||
ids[k] = domainIds[j];
|
||||
}
|
||||
SearchCriteria<DomainJoinVO> sc = domainSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
List<DomainJoinVO> domains = searchIncludingRemoved(sc, null, null, false);
|
||||
if (domains != null) {
|
||||
uvList.addAll(domains);
|
||||
}
|
||||
}
|
||||
return uvList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainJoinVO newDomainView(Domain domain) {
|
||||
SearchCriteria<DomainJoinVO> sc = domainIdSearch.create();
|
||||
|
|
|
|||
|
|
@ -34,4 +34,5 @@ public interface ServiceOfferingJoinDao extends GenericDao<ServiceOfferingJoinVO
|
|||
ServiceOfferingJoinVO newServiceOfferingView(ServiceOffering offering);
|
||||
|
||||
Map<Long, List<String>> listDomainsOfServiceOfferingsUsedByDomainPath(String domainPath);
|
||||
List<ServiceOfferingJoinVO> searchByIds(Long... id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -34,6 +35,8 @@ import com.cloud.storage.DiskOfferingVO;
|
|||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
|
|
@ -54,10 +57,14 @@ public class ServiceOfferingJoinDaoImpl extends GenericDaoBase<ServiceOfferingJo
|
|||
@Inject
|
||||
private AnnotationDao annotationDao;
|
||||
@Inject
|
||||
private ConfigurationDao configDao;
|
||||
@Inject
|
||||
private AccountManager accountManager;
|
||||
|
||||
private SearchBuilder<ServiceOfferingJoinVO> sofIdSearch;
|
||||
|
||||
private SearchBuilder<ServiceOfferingJoinVO> srvOfferingSearch;
|
||||
|
||||
/**
|
||||
* Constant used to convert GB into Bytes (or the other way around).
|
||||
* GB * MB * KB = Bytes //
|
||||
|
|
@ -83,6 +90,10 @@ public class ServiceOfferingJoinDaoImpl extends GenericDaoBase<ServiceOfferingJo
|
|||
sofIdSearch.and("id", sofIdSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sofIdSearch.done();
|
||||
|
||||
srvOfferingSearch = createSearchBuilder();
|
||||
srvOfferingSearch.and("idIN", srvOfferingSearch.entity().getId(), SearchCriteria.Op.IN);
|
||||
srvOfferingSearch.done();
|
||||
|
||||
this._count = "select count(distinct service_offering_view.id) from service_offering_view WHERE ";
|
||||
}
|
||||
|
||||
|
|
@ -182,10 +193,9 @@ public class ServiceOfferingJoinDaoImpl extends GenericDaoBase<ServiceOfferingJo
|
|||
return offerings.get(0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Long, List<String>> listDomainsOfServiceOfferingsUsedByDomainPath(String domainPath) {
|
||||
logger.debug(String.format("Retrieving the domains of the service offerings used by domain with path [%s].", domainPath));
|
||||
logger.debug("Retrieving the domains of the service offerings used by domain with path [{}].", domainPath);
|
||||
|
||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||
try (PreparedStatement pstmt = txn.prepareStatement(LIST_DOMAINS_OF_SERVICE_OFFERINGS_USED_BY_DOMAIN_PATH)) {
|
||||
|
|
@ -215,4 +225,48 @@ public class ServiceOfferingJoinDaoImpl extends GenericDaoBase<ServiceOfferingJo
|
|||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServiceOfferingJoinVO> searchByIds(Long... offeringIds) {
|
||||
// set detail batch query size
|
||||
int DETAILS_BATCH_SIZE = 2000;
|
||||
String batchCfg = configDao.getValue("detail.batch.query.size");
|
||||
if (batchCfg != null) {
|
||||
DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg);
|
||||
}
|
||||
|
||||
List<ServiceOfferingJoinVO> uvList = new ArrayList<>();
|
||||
// query details by batches
|
||||
int curr_index = 0;
|
||||
if (offeringIds.length > DETAILS_BATCH_SIZE) {
|
||||
while ((curr_index + DETAILS_BATCH_SIZE) <= offeringIds.length) {
|
||||
Long[] ids = new Long[DETAILS_BATCH_SIZE];
|
||||
for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) {
|
||||
ids[k] = offeringIds[j];
|
||||
}
|
||||
SearchCriteria<ServiceOfferingJoinVO> sc = srvOfferingSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
List<ServiceOfferingJoinVO> accounts = searchIncludingRemoved(sc, null, null, false);
|
||||
if (accounts != null) {
|
||||
uvList.addAll(accounts);
|
||||
}
|
||||
curr_index += DETAILS_BATCH_SIZE;
|
||||
}
|
||||
}
|
||||
if (curr_index < offeringIds.length) {
|
||||
int batch_size = (offeringIds.length - curr_index);
|
||||
// set the ids value
|
||||
Long[] ids = new Long[batch_size];
|
||||
for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) {
|
||||
ids[k] = offeringIds[j];
|
||||
}
|
||||
SearchCriteria<ServiceOfferingJoinVO> sc = srvOfferingSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
List<ServiceOfferingJoinVO> accounts = searchIncludingRemoved(sc, null, null, false);
|
||||
if (accounts != null) {
|
||||
uvList.addAll(accounts);
|
||||
}
|
||||
}
|
||||
return uvList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,6 @@ package com.cloud.api.query.dao;
|
|||
import java.util.List;
|
||||
|
||||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.storage.StoragePoolStatus;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
|
||||
import com.cloud.api.query.vo.StoragePoolJoinVO;
|
||||
|
|
@ -43,8 +40,6 @@ public interface StoragePoolJoinDao extends GenericDao<StoragePoolJoinVO, Long>
|
|||
|
||||
List<StoragePoolJoinVO> searchByIds(Long... spIds);
|
||||
|
||||
Pair<List<StoragePoolJoinVO>, Integer> searchAndCount(Long storagePoolId, String storagePoolName, Long zoneId, String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status, String keyword, Filter searchFilter);
|
||||
|
||||
List<StoragePoolVO> findStoragePoolByScopeAndRuleTags(Long datacenterId, Long podId, Long clusterId, ScopeType scopeType, List<String> tags);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,13 +43,10 @@ import com.cloud.storage.DataStoreRole;
|
|||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.storage.StoragePoolStatus;
|
||||
import com.cloud.storage.StorageStats;
|
||||
import com.cloud.storage.VolumeApiServiceImpl;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
|
@ -311,77 +308,6 @@ public class StoragePoolJoinDaoImpl extends GenericDaoBase<StoragePoolJoinVO, Lo
|
|||
return uvList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<List<StoragePoolJoinVO>, Integer> searchAndCount(Long storagePoolId, String storagePoolName, Long zoneId, String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status, String keyword, Filter searchFilter) {
|
||||
SearchCriteria<StoragePoolJoinVO> sc = createStoragePoolSearchCriteria(storagePoolId, storagePoolName, zoneId, path, podId, clusterId, address, scopeType, status, keyword);
|
||||
return searchAndCount(sc, searchFilter);
|
||||
}
|
||||
|
||||
private SearchCriteria<StoragePoolJoinVO> createStoragePoolSearchCriteria(Long storagePoolId, String storagePoolName, Long zoneId, String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status, String keyword) {
|
||||
SearchBuilder<StoragePoolJoinVO> sb = createSearchBuilder();
|
||||
sb.select(null, SearchCriteria.Func.DISTINCT, sb.entity().getId()); // select distinct
|
||||
// ids
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
sb.and("path", sb.entity().getPath(), SearchCriteria.Op.EQ);
|
||||
sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
|
||||
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
|
||||
sb.and("hostAddress", sb.entity().getHostAddress(), SearchCriteria.Op.EQ);
|
||||
sb.and("scope", sb.entity().getScope(), SearchCriteria.Op.EQ);
|
||||
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
|
||||
sb.and("parent", sb.entity().getParent(), SearchCriteria.Op.EQ);
|
||||
|
||||
SearchCriteria<StoragePoolJoinVO> sc = sb.create();
|
||||
|
||||
if (keyword != null) {
|
||||
SearchCriteria<StoragePoolJoinVO> ssc = createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
ssc.addOr("poolType", SearchCriteria.Op.LIKE, new Storage.StoragePoolType("%" + keyword + "%"));
|
||||
|
||||
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
|
||||
if (storagePoolId != null) {
|
||||
sc.setParameters("id", storagePoolId);
|
||||
}
|
||||
|
||||
if (storagePoolName != null) {
|
||||
sc.setParameters("name", storagePoolName);
|
||||
}
|
||||
|
||||
if (path != null) {
|
||||
sc.setParameters("path", path);
|
||||
}
|
||||
if (zoneId != null) {
|
||||
sc.setParameters("dataCenterId", zoneId);
|
||||
}
|
||||
if (podId != null) {
|
||||
SearchCriteria<StoragePoolJoinVO> ssc = createSearchCriteria();
|
||||
ssc.addOr("podId", SearchCriteria.Op.EQ, podId);
|
||||
ssc.addOr("podId", SearchCriteria.Op.NULL);
|
||||
|
||||
sc.addAnd("podId", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
if (address != null) {
|
||||
sc.setParameters("hostAddress", address);
|
||||
}
|
||||
if (clusterId != null) {
|
||||
SearchCriteria<StoragePoolJoinVO> ssc = createSearchCriteria();
|
||||
ssc.addOr("clusterId", SearchCriteria.Op.EQ, clusterId);
|
||||
ssc.addOr("clusterId", SearchCriteria.Op.NULL);
|
||||
|
||||
sc.addAnd("clusterId", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
if (scopeType != null) {
|
||||
sc.setParameters("scope", scopeType.toString());
|
||||
}
|
||||
if (status != null) {
|
||||
sc.setParameters("status", status.toString());
|
||||
}
|
||||
sc.setParameters("parent", 0);
|
||||
return sc;
|
||||
}
|
||||
@Override
|
||||
public List<StoragePoolVO> findStoragePoolByScopeAndRuleTags(Long datacenterId, Long podId, Long clusterId, ScopeType scopeType, List<String> tags) {
|
||||
SearchCriteria<StoragePoolJoinVO> sc = findByDatacenterAndScopeSb.create();
|
||||
|
|
|
|||
|
|
@ -196,11 +196,15 @@ public class TemplateJoinDaoImpl extends GenericDaoBaseWithTagInformation<Templa
|
|||
List<ImageStoreVO> storesInZone = dataStoreDao.listStoresByZoneId(template.getDataCenterId());
|
||||
Long[] storeIds = storesInZone.stream().map(ImageStoreVO::getId).toArray(Long[]::new);
|
||||
List<TemplateDataStoreVO> templatesInStore = _templateStoreDao.listByTemplateNotBypassed(template.getId(), storeIds);
|
||||
|
||||
List<Long> dataStoreIdList = templatesInStore.stream().map(TemplateDataStoreVO::getDataStoreId).collect(Collectors.toList());
|
||||
Map<Long, ImageStoreVO> imageStoreMap = dataStoreDao.listByIds(dataStoreIdList).stream().collect(Collectors.toMap(ImageStoreVO::getId, imageStore -> imageStore));
|
||||
|
||||
List<Map<String, String>> downloadProgressDetails = new ArrayList<>();
|
||||
HashMap<String, String> downloadDetailInImageStores = null;
|
||||
for (TemplateDataStoreVO templateInStore : templatesInStore) {
|
||||
downloadDetailInImageStores = new HashMap<>();
|
||||
ImageStoreVO imageStore = dataStoreDao.findById(templateInStore.getDataStoreId());
|
||||
ImageStoreVO imageStore = imageStoreMap.get(templateInStore.getDataStoreId());
|
||||
if (imageStore != null) {
|
||||
downloadDetailInImageStores.put("datastore", imageStore.getName());
|
||||
if (view.equals(ResponseView.Full)) {
|
||||
|
|
@ -217,9 +221,12 @@ public class TemplateJoinDaoImpl extends GenericDaoBaseWithTagInformation<Templa
|
|||
List<Long> poolIds = poolsInZone.stream().map(StoragePoolVO::getId).collect(Collectors.toList());
|
||||
List<VMTemplateStoragePoolVO> templatesInPool = templatePoolDao.listByTemplateId(template.getId(), poolIds);
|
||||
|
||||
dataStoreIdList = templatesInStore.stream().map(TemplateDataStoreVO::getDataStoreId).collect(Collectors.toList());
|
||||
Map<Long, StoragePoolVO> storagePoolMap = primaryDataStoreDao.listByIds(dataStoreIdList).stream().collect(Collectors.toMap(StoragePoolVO::getId, store -> store));
|
||||
|
||||
for (VMTemplateStoragePoolVO templateInPool : templatesInPool) {
|
||||
downloadDetailInImageStores = new HashMap<>();
|
||||
StoragePoolVO storagePool = primaryDataStoreDao.findById(templateInPool.getDataStoreId());
|
||||
StoragePoolVO storagePool = storagePoolMap.get(templateInPool.getDataStoreId());
|
||||
if (storagePool != null) {
|
||||
downloadDetailInImageStores.put("datastore", storagePool.getName());
|
||||
if (view.equals(ResponseView.Full)) {
|
||||
|
|
|
|||
|
|
@ -7232,7 +7232,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
}
|
||||
}
|
||||
|
||||
offering.setTags(tags);
|
||||
if (StringUtils.isBlank(tags)) {
|
||||
offering.setTags(null);
|
||||
} else {
|
||||
offering.setTags(tags);
|
||||
}
|
||||
}
|
||||
|
||||
// Verify availability
|
||||
|
|
@ -7539,7 +7543,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
networkRate = offering.getRateMbps();
|
||||
} else {
|
||||
// for domain router service offering, get network rate from
|
||||
if (offering.getSystemVmType() != null && offering.getSystemVmType().equalsIgnoreCase(VirtualMachine.Type.DomainRouter.toString())) {
|
||||
if (offering.getVmType() != null && offering.getVmType().equalsIgnoreCase(VirtualMachine.Type.DomainRouter.toString())) {
|
||||
networkRate = NetworkOrchestrationService.NetworkThrottlingRate.valueIn(dataCenterId);
|
||||
} else {
|
||||
networkRate = Integer.parseInt(_configDao.getValue(Config.VmNetworkThrottlingRate.key()));
|
||||
|
|
|
|||
|
|
@ -4371,9 +4371,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
|
|||
}
|
||||
|
||||
final String virtualMachineDomainRouterType = VirtualMachine.Type.DomainRouter.toString();
|
||||
if (!virtualMachineDomainRouterType.equalsIgnoreCase(serviceOffering.getSystemVmType())) {
|
||||
if (!virtualMachineDomainRouterType.equalsIgnoreCase(serviceOffering.getVmType())) {
|
||||
throw new InvalidParameterValueException(String.format("The specified service offering [%s] is of type [%s]. Virtual routers can only be created with service offering "
|
||||
+ "of type [%s].", serviceOffering, serviceOffering.getSystemVmType(), virtualMachineDomainRouterType.toLowerCase()));
|
||||
+ "of type [%s].", serviceOffering, serviceOffering.getVmType(), virtualMachineDomainRouterType.toLowerCase()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
|
|||
"If true, router minimum required version is checked before sending command", false);
|
||||
ConfigKey<Boolean> UseExternalDnsServers = new ConfigKey<>(Boolean.class, "use.external.dns", "Advanced", "false",
|
||||
"Bypass internal dns, use external dns1 and dns2", true, ConfigKey.Scope.Zone, null);
|
||||
ConfigKey<Boolean> ExposeDnsAndBootpServer = new ConfigKey<>(Boolean.class, "expose.dns.externally", "Advanced", "true",
|
||||
ConfigKey<Boolean> ExposeDnsAndBootpServer = new ConfigKey<>(Boolean.class, "expose.dns.externally", "Advanced", "false",
|
||||
"open dns, dhcp and bootp on the public interface", true, ConfigKey.Scope.Zone, null);
|
||||
|
||||
ConfigKey<String> VirtualRouterServiceOffering = new ConfigKey<>(String.class, VirtualRouterServiceOfferingCK, "Advanced", "",
|
||||
|
|
|
|||
|
|
@ -605,6 +605,9 @@ import org.apache.cloudstack.config.Configuration;
|
|||
import org.apache.cloudstack.config.ConfigurationGroup;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
|
||||
import org.apache.cloudstack.framework.config.ConfigDepot;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
|
|
@ -969,6 +972,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||
@Inject
|
||||
private PrimaryDataStoreDao _primaryDataStoreDao;
|
||||
@Inject
|
||||
private DataStoreManager dataStoreManager;
|
||||
@Inject
|
||||
private VolumeDataStoreDao _volumeStoreDao;
|
||||
@Inject
|
||||
private TemplateDataStoreDao _vmTemplateStoreDao;
|
||||
|
|
@ -1420,6 +1425,20 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||
return listHostsForMigrationOfVM(vm, startIndex, pageSize, keyword, Collections.emptyList());
|
||||
}
|
||||
|
||||
protected boolean zoneWideVolumeRequiresStorageMotion(PrimaryDataStore volumeDataStore,
|
||||
final Host sourceHost, final Host destinationHost) {
|
||||
if (volumeDataStore.isManaged() && sourceHost.getClusterId() != destinationHost.getClusterId()) {
|
||||
PrimaryDataStoreDriver driver = (PrimaryDataStoreDriver)volumeDataStore.getDriver();
|
||||
// Depends on the storage driver. For some storages simply
|
||||
// changing volume access to host should work: grant access on destination
|
||||
// host and revoke access on source host. For others, we still have to perform a storage migration
|
||||
// because we need to create a new target volume and copy the contents of the
|
||||
// source volume into it before deleting the source volume.
|
||||
return !driver.zoneWideVolumesAvailableWithoutClusterMotion();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>> listHostsForMigrationOfVM(final VirtualMachine vm, final Long startIndex, final Long pageSize,
|
||||
final String keyword, List<VirtualMachine> vmList) {
|
||||
|
|
@ -1488,8 +1507,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||
filteredHosts = new ArrayList<>(allHosts);
|
||||
|
||||
for (final VolumeVO volume : volumes) {
|
||||
StoragePool storagePool = _poolDao.findById(volume.getPoolId());
|
||||
Long volClusterId = storagePool.getClusterId();
|
||||
PrimaryDataStore primaryDataStore = (PrimaryDataStore)dataStoreManager.getPrimaryDataStore(volume.getPoolId());
|
||||
Long volClusterId = primaryDataStore.getClusterId();
|
||||
|
||||
for (Iterator<HostVO> iterator = filteredHosts.iterator(); iterator.hasNext();) {
|
||||
final Host host = iterator.next();
|
||||
|
|
@ -1499,8 +1518,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||
}
|
||||
|
||||
if (volClusterId != null) {
|
||||
if (storagePool.isLocal() || !host.getClusterId().equals(volClusterId) || usesLocal) {
|
||||
if (storagePool.isManaged()) {
|
||||
if (primaryDataStore.isLocal() || !host.getClusterId().equals(volClusterId) || usesLocal) {
|
||||
if (primaryDataStore.isManaged()) {
|
||||
// At the time being, we do not support storage migration of a volume from managed storage unless the managed storage
|
||||
// is at the zone level and the source and target storage pool is the same.
|
||||
// If the source and target storage pool is the same and it is managed, then we still have to perform a storage migration
|
||||
|
|
@ -1518,18 +1537,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (storagePool.isManaged()) {
|
||||
if (srcHost.getClusterId() != host.getClusterId()) {
|
||||
if (storagePool.getPoolType() == Storage.StoragePoolType.PowerFlex) {
|
||||
// No need of new volume creation for zone wide PowerFlex/ScaleIO pool
|
||||
// Simply, changing volume access to host should work: grant access on dest host and revoke access on source host
|
||||
continue;
|
||||
}
|
||||
// If the volume's storage pool is managed and at the zone level, then we still have to perform a storage migration
|
||||
// because we need to create a new target volume and copy the contents of the source volume into it before deleting
|
||||
// the source volume.
|
||||
requiresStorageMotion.put(host, true);
|
||||
}
|
||||
if (zoneWideVolumeRequiresStorageMotion(primaryDataStore, srcHost, host)) {
|
||||
requiresStorageMotion.put(host, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class RoleManagerImpl extends ManagerBase implements RoleService, Configu
|
|||
}
|
||||
|
||||
@Override
|
||||
public Role findRole(Long id, boolean removePrivateRoles) {
|
||||
public Role findRole(Long id, boolean ignorePrivateRoles) {
|
||||
if (id == null || id < 1L) {
|
||||
logger.trace(String.format("Role ID is invalid [%s]", id));
|
||||
return null;
|
||||
|
|
@ -101,13 +101,36 @@ public class RoleManagerImpl extends ManagerBase implements RoleService, Configu
|
|||
logger.trace(String.format("Role not found [id=%s]", id));
|
||||
return null;
|
||||
}
|
||||
if (!isCallerRootAdmin() && (RoleType.Admin == role.getRoleType() || (!role.isPublicRole() && removePrivateRoles))) {
|
||||
if (!isCallerRootAdmin() && (RoleType.Admin == role.getRoleType() || (!role.isPublicRole() && ignorePrivateRoles))) {
|
||||
logger.debug(String.format("Role [id=%s, name=%s] is either of 'Admin' type or is private and is only visible to 'Root admins'.", id, role.getName()));
|
||||
return null;
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Role> findRoles(List<Long> ids, boolean ignorePrivateRoles) {
|
||||
List<Role> result = new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
logger.trace(String.format("Role IDs are invalid [%s]", ids));
|
||||
return result;
|
||||
}
|
||||
|
||||
List<RoleVO> roles = roleDao.searchByIds(ids.toArray(new Long[0]));
|
||||
if (CollectionUtils.isEmpty(roles)) {
|
||||
logger.trace(String.format("Roles not found [ids=%s]", ids));
|
||||
return result;
|
||||
}
|
||||
for (Role role : roles) {
|
||||
if (!isCallerRootAdmin() && (RoleType.Admin == role.getRoleType() || (!role.isPublicRole() && ignorePrivateRoles))) {
|
||||
logger.debug(String.format("Role [id=%s, name=%s] is either of 'Admin' type or is private and is only visible to 'Root admins'.", role.getId(), role.getName()));
|
||||
continue;
|
||||
}
|
||||
result.add(role);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Role findRole(Long id) {
|
||||
return findRole(id, false);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ package com.cloud.api.query;
|
|||
import com.cloud.api.query.dao.TemplateJoinDao;
|
||||
import com.cloud.api.query.vo.EventJoinVO;
|
||||
import com.cloud.api.query.vo.TemplateJoinVO;
|
||||
import com.cloud.event.EventVO;
|
||||
import com.cloud.event.dao.EventDao;
|
||||
import com.cloud.event.dao.EventJoinDao;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
|
|
@ -95,6 +97,9 @@ public class QueryManagerImplTest {
|
|||
@Mock
|
||||
AccountManager accountManager;
|
||||
|
||||
@Mock
|
||||
EventDao eventDao;
|
||||
|
||||
@Mock
|
||||
EventJoinDao eventJoinDao;
|
||||
|
||||
|
|
@ -133,12 +138,12 @@ public class QueryManagerImplTest {
|
|||
UUID.randomUUID().toString(), User.Source.UNKNOWN);
|
||||
CallContext.register(user, account);
|
||||
Mockito.when(accountManager.isRootAdmin(account.getId())).thenReturn(false);
|
||||
final SearchBuilder<EventJoinVO> searchBuilder = Mockito.mock(SearchBuilder.class);
|
||||
final SearchCriteria<EventJoinVO> searchCriteria = Mockito.mock(SearchCriteria.class);
|
||||
final EventJoinVO eventJoinVO = Mockito.mock(EventJoinVO.class);
|
||||
when(searchBuilder.entity()).thenReturn(eventJoinVO);
|
||||
when(searchBuilder.create()).thenReturn(searchCriteria);
|
||||
Mockito.when(eventJoinDao.createSearchBuilder()).thenReturn(searchBuilder);
|
||||
final SearchBuilder<EventVO> eventSearchBuilder = Mockito.mock(SearchBuilder.class);
|
||||
final SearchCriteria<EventVO> eventSearchCriteria = Mockito.mock(SearchCriteria.class);
|
||||
final EventVO eventVO = Mockito.mock(EventVO.class);
|
||||
when(eventSearchBuilder.entity()).thenReturn(eventVO);
|
||||
when(eventSearchBuilder.create()).thenReturn(eventSearchCriteria);
|
||||
Mockito.when(eventDao.createSearchBuilder()).thenReturn(eventSearchBuilder);
|
||||
}
|
||||
|
||||
private ListEventsCmd setupMockListEventsCmd() {
|
||||
|
|
@ -154,19 +159,26 @@ public class QueryManagerImplTest {
|
|||
String uuid = UUID.randomUUID().toString();
|
||||
Mockito.when(cmd.getResourceId()).thenReturn(uuid);
|
||||
Mockito.when(cmd.getResourceType()).thenReturn(ApiCommandResourceType.Network.toString());
|
||||
List<EventJoinVO> events = new ArrayList<>();
|
||||
events.add(Mockito.mock(EventJoinVO.class));
|
||||
events.add(Mockito.mock(EventJoinVO.class));
|
||||
events.add(Mockito.mock(EventJoinVO.class));
|
||||
Pair<List<EventJoinVO>, Integer> pair = new Pair<>(events, events.size());
|
||||
List<EventVO> events = new ArrayList<>();
|
||||
events.add(Mockito.mock(EventVO.class));
|
||||
events.add(Mockito.mock(EventVO.class));
|
||||
events.add(Mockito.mock(EventVO.class));
|
||||
Pair<List<EventVO>, Integer> pair = new Pair<>(events, events.size());
|
||||
|
||||
List<EventJoinVO> eventJoins = new ArrayList<>();
|
||||
eventJoins.add(Mockito.mock(EventJoinVO.class));
|
||||
eventJoins.add(Mockito.mock(EventJoinVO.class));
|
||||
eventJoins.add(Mockito.mock(EventJoinVO.class));
|
||||
|
||||
NetworkVO network = Mockito.mock(NetworkVO.class);
|
||||
Mockito.when(network.getId()).thenReturn(1L);
|
||||
Mockito.when(network.getAccountId()).thenReturn(account.getId());
|
||||
Mockito.when(entityManager.findByUuidIncludingRemoved(Network.class, uuid)).thenReturn(network);
|
||||
Mockito.doNothing().when(accountManager).checkAccess(account, SecurityChecker.AccessType.ListEntry, true, network);
|
||||
Mockito.when(eventJoinDao.searchAndCount(Mockito.any(), Mockito.any(Filter.class))).thenReturn(pair);
|
||||
Mockito.when(eventDao.searchAndCount(Mockito.any(), Mockito.any(Filter.class))).thenReturn(pair);
|
||||
Mockito.when(eventJoinDao.searchByIds(Mockito.any())).thenReturn(eventJoins);
|
||||
List<EventResponse> respList = new ArrayList<EventResponse>();
|
||||
for (EventJoinVO vt : events) {
|
||||
for (EventJoinVO vt : eventJoins) {
|
||||
respList.add(eventJoinDao.newEventResponse(vt));
|
||||
}
|
||||
try (MockedStatic<ViewResponseHelper> ignored = Mockito.mockStatic(ViewResponseHelper.class)) {
|
||||
|
|
|
|||
|
|
@ -793,10 +793,10 @@ public class NetworkServiceImplTest {
|
|||
public void validateIfServiceOfferingIsActiveAndSystemVmTypeIsDomainRouterTestMustThrowInvalidParameterValueExceptionWhenSystemVmTypeIsNotDomainRouter() {
|
||||
doReturn(serviceOfferingVoMock).when(serviceOfferingDaoMock).findById(anyLong());
|
||||
doReturn(ServiceOffering.State.Active).when(serviceOfferingVoMock).getState();
|
||||
doReturn(VirtualMachine.Type.ElasticLoadBalancerVm.toString()).when(serviceOfferingVoMock).getSystemVmType();
|
||||
doReturn(VirtualMachine.Type.ElasticLoadBalancerVm.toString()).when(serviceOfferingVoMock).getVmType();
|
||||
|
||||
String expectedMessage = String.format("The specified service offering [%s] is of type [%s]. Virtual routers can only be created with service offering of type [%s].",
|
||||
serviceOfferingVoMock, serviceOfferingVoMock.getSystemVmType(), VirtualMachine.Type.DomainRouter.toString().toLowerCase());
|
||||
serviceOfferingVoMock, serviceOfferingVoMock.getVmType(), VirtualMachine.Type.DomainRouter.toString().toLowerCase());
|
||||
InvalidParameterValueException assertThrows = Assert.assertThrows(expectedException, () -> {
|
||||
service.validateIfServiceOfferingIsActiveAndSystemVmTypeIsDomainRouter(1l);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ import org.apache.cloudstack.api.command.user.userdata.DeleteUserDataCmd;
|
|||
import org.apache.cloudstack.api.command.user.userdata.ListUserDataCmd;
|
||||
import org.apache.cloudstack.api.command.user.userdata.RegisterUserDataCmd;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.userdata.UserDataManager;
|
||||
import org.junit.After;
|
||||
|
|
@ -645,4 +647,41 @@ public class ManagementServerImplTest {
|
|||
Assert.assertNotNull(result.second());
|
||||
Assert.assertEquals(0, result.second().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoneWideVolumeRequiresStorageMotionNonManaged() {
|
||||
PrimaryDataStore dataStore = Mockito.mock(PrimaryDataStore.class);
|
||||
Mockito.when(dataStore.isManaged()).thenReturn(false);
|
||||
Assert.assertFalse(spy.zoneWideVolumeRequiresStorageMotion(dataStore,
|
||||
Mockito.mock(Host.class), Mockito.mock(Host.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoneWideVolumeRequiresStorageMotionSameClusterHost() {
|
||||
PrimaryDataStore dataStore = Mockito.mock(PrimaryDataStore.class);
|
||||
Mockito.when(dataStore.isManaged()).thenReturn(true);
|
||||
Host host1 = Mockito.mock(Host.class);
|
||||
Mockito.when(host1.getClusterId()).thenReturn(1L);
|
||||
Host host2 = Mockito.mock(Host.class);
|
||||
Mockito.when(host2.getClusterId()).thenReturn(1L);
|
||||
Assert.assertFalse(spy.zoneWideVolumeRequiresStorageMotion(dataStore, host1, host2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoneWideVolumeRequiresStorageMotionDriverDependent() {
|
||||
PrimaryDataStore dataStore = Mockito.mock(PrimaryDataStore.class);
|
||||
Mockito.when(dataStore.isManaged()).thenReturn(true);
|
||||
PrimaryDataStoreDriver driver = Mockito.mock(PrimaryDataStoreDriver.class);
|
||||
Mockito.when(dataStore.getDriver()).thenReturn(driver);
|
||||
Host host1 = Mockito.mock(Host.class);
|
||||
Mockito.when(host1.getClusterId()).thenReturn(1L);
|
||||
Host host2 = Mockito.mock(Host.class);
|
||||
Mockito.when(host2.getClusterId()).thenReturn(2L);
|
||||
|
||||
Mockito.when(driver.zoneWideVolumesAvailableWithoutClusterMotion()).thenReturn(true);
|
||||
Assert.assertFalse(spy.zoneWideVolumeRequiresStorageMotion(dataStore, host1, host2));
|
||||
|
||||
Mockito.when(driver.zoneWideVolumesAvailableWithoutClusterMotion()).thenReturn(false);
|
||||
Assert.assertTrue(spy.zoneWideVolumeRequiresStorageMotion(dataStore, host1, host2));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,6 +297,11 @@ public class MockUsageEventDao implements UsageEventDao{
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UsageEventVO> findByUuids(String... uuids) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UsageEventVO> listLatestEvents(Date endDate) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -306,7 +306,11 @@ export default {
|
|||
message: this.$t('label.loadbalancerinstance')
|
||||
})
|
||||
this.$emit('close-action')
|
||||
this.parentFetchData()
|
||||
if (this.$store.getters.project?.id) {
|
||||
this.$router.push({ path: '/vm' })
|
||||
} else {
|
||||
this.parentFetchData()
|
||||
}
|
||||
}).catch(error => {
|
||||
this.$notifyError(error)
|
||||
}).finally(() => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue