Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@
<bean id="storagePoolDetailsDaoImpl" class="com.cloud.storage.dao.StoragePoolDetailsDaoImpl" />
<bean id="storagePoolJoinDaoImpl" class="com.cloud.api.query.dao.StoragePoolJoinDaoImpl" />
<bean id="storagePoolTagsDaoImpl" class="com.cloud.storage.dao.StoragePoolTagsDaoImpl" />
<bean id="storageTagDaoImpl" class="com.cloud.api.query.dao.StorageTagDaoImpl" />
<bean id="hostTagDaoImpl" class="com.cloud.api.query.dao.HostTagDaoImpl" />
<bean id="storagePoolWorkDaoImpl" class="com.cloud.storage.dao.StoragePoolWorkDaoImpl" />
<bean id="templatePrimaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.volume.db.TemplatePrimaryDataStoreDaoImpl" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.List;

import org.apache.cloudstack.api.response.StorageTagResponse;

import com.cloud.storage.StoragePoolTagVO;
import com.cloud.utils.db.GenericDao;

Expand All @@ -26,5 +28,7 @@ public interface StoragePoolTagsDao extends GenericDao<StoragePoolTagVO, Long> {
void persist(long poolId, List<String> storagePoolTags);
List<String> getStoragePoolTags(long poolId);
void deleteTags(long poolId);
List<StoragePoolTagVO> searchByIds(Long... stIds);
StorageTagResponse newStorageTagResponse(StoragePoolTagVO tag);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.apache.cloudstack.api.response.StorageTagResponse;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;

import com.cloud.storage.StoragePoolTagVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
Expand All @@ -26,12 +32,21 @@

public class StoragePoolTagsDaoImpl extends GenericDaoBase<StoragePoolTagVO, Long> implements StoragePoolTagsDao {

@Inject
private ConfigurationDao _configDao;

protected final SearchBuilder<StoragePoolTagVO> StoragePoolSearch;
private final SearchBuilder<StoragePoolTagVO> StoragePoolIdsSearch;

private static final int DEFAULT_BATCH_QUERY_SIZE = 2000;

public StoragePoolTagsDaoImpl() {
StoragePoolSearch = createSearchBuilder();
StoragePoolSearch.and("poolId", StoragePoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
StoragePoolSearch.done();
StoragePoolIdsSearch = createSearchBuilder();
StoragePoolIdsSearch.and("idIN", StoragePoolIdsSearch.entity().getId(), SearchCriteria.Op.IN);
StoragePoolIdsSearch.done();
}

@Override
Expand Down Expand Up @@ -77,4 +92,69 @@ public void deleteTags(long poolId) {
txn.commit();
}

@Override
public List<StoragePoolTagVO> searchByIds(Long... stIds) {
final int detailsBatchSize = getDetailsBatchSize();

// query details by batches
List<StoragePoolTagVO> uvList = new ArrayList<StoragePoolTagVO>();
int curr_index = 0;

while ((curr_index + detailsBatchSize) <= stIds.length) {
searchForStoragePoolIdsInternal(curr_index, detailsBatchSize, stIds, uvList);
curr_index += detailsBatchSize;
}

if (curr_index < stIds.length) {
int batch_size = (stIds.length - curr_index);
searchForStoragePoolIdsInternal(curr_index, batch_size, stIds, uvList);
}

return uvList;
}

/**
* Search for storage pools based on their IDs.
* The search is executed in batch, this means that we will load a batch of size {@link StoragePoolTagsDaoImpl#getDetailsBatchSize()}
* {@link StoragePoolTagVO} at each time.
* The loaded storage pools are added in the pools parameter.
* @param currIndex current index
* @param batchSize batch size
* @param stIds storage tags array
* @param pools list in which storage pools are added
*/
protected void searchForStoragePoolIdsInternal(int currIndex, int batchSize, Long[] stIds, List<StoragePoolTagVO> pools) {
Long[] ids = new Long[batchSize];
for (int k = 0, j = currIndex; j < currIndex + batchSize; j++, k++) {
ids[k] = stIds[j];
}
SearchCriteria<StoragePoolTagVO> sc = StoragePoolIdsSearch.create();
sc.setParameters("idIN", (Object[])ids);
List<StoragePoolTagVO> vms = searchIncludingRemoved(sc, null, null, false);
if (vms != null) {
pools.addAll(vms);
}
}

/**
* Retrieve {@code detail.batch.query.size} configuration value. If not available, return default value {@link StoragePoolTagsDaoImpl#DEFAULT_BATCH_QUERY_SIZE}
* @return detail.batch.query.size configuration value
*/
protected int getDetailsBatchSize() {
String batchCfg = _configDao.getValue("detail.batch.query.size");
return batchCfg != null ? Integer.parseInt(batchCfg) : DEFAULT_BATCH_QUERY_SIZE;
}

@Override
public StorageTagResponse newStorageTagResponse(StoragePoolTagVO tag) {
StorageTagResponse tagResponse = new StorageTagResponse();

tagResponse.setName(tag.getTag());
tagResponse.setPoolId(tag.getPoolId());

tagResponse.setObjectName("storagetag");

return tagResponse;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
*/
void updateCapacityIops(long id, long capacityIops);

StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details);
StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details, List<String> tags);

/**
* Find pool by name.
Expand Down Expand Up @@ -100,7 +100,7 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {

Map<String, String> getDetails(long poolId);

List<String> searchForStoragePoolDetails(long poolId, String value);
List<String> searchForStoragePoolTags(long poolId);

List<StoragePoolVO> findIfDuplicatePoolsExistByUUID(String uuid);

Expand All @@ -121,4 +121,6 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
List<StoragePoolVO> findLocalStoragePoolsByHostAndTags(long hostId, String[] tags);

List<StoragePoolVO> listLocalStoragePoolByPath(long datacenterId, String path);

void deletePoolTags(long poolId);
}
Loading