mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge remote-tracking branch 'origin/4.18'
This commit is contained in:
commit
8a42ab9ce4
@ -80,7 +80,7 @@ public interface RoleService {
|
||||
*/
|
||||
List<Role> findRolesByName(String name);
|
||||
|
||||
Pair<List<Role>, Integer> findRolesByName(String name, Long startIndex, Long limit);
|
||||
Pair<List<Role>, Integer> findRolesByName(String name, String keyword, Long startIndex, Long limit);
|
||||
|
||||
/**
|
||||
* Find all roles by {@link RoleType}. If the role type is {@link RoleType#Admin}, the calling account must be a root admin, otherwise we return an empty list.
|
||||
|
||||
@ -105,8 +105,8 @@ public class ListRolesCmd extends BaseListCmd {
|
||||
Pair<List<Role>, Integer> roles;
|
||||
if (getId() != null && getId() > 0L) {
|
||||
roles = new Pair<List<Role>, Integer>(Collections.singletonList(roleService.findRole(getId())), 1);
|
||||
} else if (StringUtils.isNotBlank(getName())) {
|
||||
roles = roleService.findRolesByName(getName(), getStartIndex(), getPageSizeVal());
|
||||
} else if (StringUtils.isNotBlank(getName()) || StringUtils.isNotBlank(getKeyword())) {
|
||||
roles = roleService.findRolesByName(getName(), getKeyword(), getStartIndex(), getPageSizeVal());
|
||||
} else if (getRoleType() != null) {
|
||||
roles = roleService.findRolesByType(getRoleType(), getStartIndex(), getPageSizeVal());
|
||||
} else {
|
||||
|
||||
@ -356,4 +356,6 @@ public interface StorageManager extends StorageService {
|
||||
|
||||
void syncDatastoreClusterStoragePool(long datastoreClusterPoolId, List<ModifyStoragePoolAnswer> childDatastoreAnswerList, long hostId);
|
||||
|
||||
void validateChildDatastoresToBeAddedInUpState(StoragePoolVO datastoreClusterPool, List<ModifyStoragePoolAnswer> childDatastoreAnswerList);
|
||||
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ import java.util.List;
|
||||
public interface RoleDao extends GenericDao<RoleVO, Long> {
|
||||
List<RoleVO> findAllByName(String roleName);
|
||||
|
||||
Pair<List<RoleVO>, Integer> findAllByName(final String roleName, Long offset, Long limit);
|
||||
Pair<List<RoleVO>, Integer> findAllByName(final String roleName, String keyword, Long offset, Long limit);
|
||||
|
||||
List<RoleVO> findAllByRoleType(RoleType type);
|
||||
List<RoleVO> findByName(String roleName);
|
||||
|
||||
@ -25,6 +25,7 @@ import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.acl.RoleVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
@ -54,13 +55,19 @@ public class RoleDaoImpl extends GenericDaoBase<RoleVO, Long> implements RoleDao
|
||||
|
||||
@Override
|
||||
public List<RoleVO> findAllByName(final String roleName) {
|
||||
return findAllByName(roleName, null, null).first();
|
||||
return findAllByName(roleName, null, null, null).first();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<List<RoleVO>, Integer> findAllByName(final String roleName, Long offset, Long limit) {
|
||||
public Pair<List<RoleVO>, Integer> findAllByName(final String roleName, String keyword, Long offset, Long limit) {
|
||||
SearchCriteria<RoleVO> sc = RoleByNameSearch.create();
|
||||
sc.setParameters("roleName", "%" + roleName + "%");
|
||||
if (StringUtils.isNotEmpty(roleName)) {
|
||||
sc.setParameters("roleName", roleName);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(keyword)) {
|
||||
sc.setParameters("roleName", "%" + keyword + "%");
|
||||
}
|
||||
|
||||
return searchAndCount(sc, new Filter(RoleVO.class, "id", true, offset, limit));
|
||||
}
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
@ -593,6 +594,23 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
|
||||
return templateDataStoreVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets one valid record for the bypassed template.
|
||||
* In case of multiple valid records, the one with the greatest size is returned.
|
||||
*/
|
||||
protected TemplateDataStoreVO getValidGreaterSizeBypassedTemplate(List<TemplateDataStoreVO> list, long templateId) {
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
List<TemplateDataStoreVO> filteredList = list.stream()
|
||||
.filter(x -> x.getSize() > 0L &&
|
||||
x.getTemplateId() == templateId && x.getDownloadState() == Status.BYPASSED &&
|
||||
x.getState() == State.Ready)
|
||||
.sorted((x,y) -> Long.compare(y.getSize(), x.getSize()))
|
||||
.collect(Collectors.toList());
|
||||
return CollectionUtils.isNotEmpty(filteredList) ? filteredList.get(0) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateDataStoreVO getReadyBypassedTemplate(long templateId) {
|
||||
SearchCriteria<TemplateDataStoreVO> sc = directDownloadTemplateSeach.create();
|
||||
@ -600,10 +618,7 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
|
||||
sc.setParameters("download_state", Status.BYPASSED);
|
||||
sc.setParameters("state", State.Ready);
|
||||
List<TemplateDataStoreVO> list = search(sc, null);
|
||||
if (CollectionUtils.isEmpty(list) || list.size() > 1) {
|
||||
return null;
|
||||
}
|
||||
return list.get(0);
|
||||
return getValidGreaterSizeBypassedTemplate(list, templateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class TemplateDataStoreDaoImplTest {
|
||||
|
||||
private final TemplateDataStoreDaoImpl dao = new TemplateDataStoreDaoImpl();
|
||||
|
||||
private static final long templateId = 1;
|
||||
private static final long templateSize = 9999;
|
||||
|
||||
@Test
|
||||
public void testGetValidGreaterSizeBypassedTemplateEmptyList() {
|
||||
TemplateDataStoreVO ref = dao.getValidGreaterSizeBypassedTemplate(null, templateId);
|
||||
Assert.assertNull(ref);
|
||||
}
|
||||
|
||||
private TemplateDataStoreVO createNewTestReferenceRecord() {
|
||||
TemplateDataStoreVO ref = new TemplateDataStoreVO();
|
||||
ref.setTemplateId(templateId);
|
||||
ref.setState(ObjectInDataStoreStateMachine.State.Ready);
|
||||
ref.setDownloadState(VMTemplateStorageResourceAssoc.Status.BYPASSED);
|
||||
ref.setSize(templateSize);
|
||||
return ref;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValidGreaterSizeBypassedTemplateMultipleRecords() {
|
||||
TemplateDataStoreVO ref1 = createNewTestReferenceRecord();
|
||||
TemplateDataStoreVO ref2 = createNewTestReferenceRecord();
|
||||
TemplateDataStoreVO ref3 = createNewTestReferenceRecord();
|
||||
ref1.setSize(1111L);
|
||||
ref3.setSize(2L);
|
||||
TemplateDataStoreVO ref = dao.getValidGreaterSizeBypassedTemplate(Arrays.asList(ref1, ref2, ref3), templateId);
|
||||
Assert.assertNotNull(ref);
|
||||
Assert.assertEquals(templateSize, ref.getSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValidGreaterSizeBypassedTemplateOneRecord() {
|
||||
TemplateDataStoreVO ref1 = createNewTestReferenceRecord();
|
||||
TemplateDataStoreVO ref = dao.getValidGreaterSizeBypassedTemplate(List.of(ref1), templateId);
|
||||
Assert.assertNotNull(ref);
|
||||
Assert.assertEquals(templateSize, ref.getSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValidGreaterSizeBypassedTemplateOneRecordInvalidState() {
|
||||
TemplateDataStoreVO ref1 = createNewTestReferenceRecord();
|
||||
ref1.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
TemplateDataStoreVO ref = dao.getValidGreaterSizeBypassedTemplate(List.of(ref1), templateId);
|
||||
Assert.assertNull(ref);
|
||||
}
|
||||
}
|
||||
@ -152,6 +152,7 @@ public class DefaultHostListener implements HypervisorHostListener {
|
||||
updateStoragePoolHostVOAndDetails(poolVO, hostId, mspAnswer);
|
||||
|
||||
if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
|
||||
storageManager.validateChildDatastoresToBeAddedInUpState(poolVO, mspAnswer.getDatastoreClusterChildren());
|
||||
storageManager.syncDatastoreClusterStoragePool(poolId, ((ModifyStoragePoolAnswer) answer).getDatastoreClusterChildren(), hostId);
|
||||
}
|
||||
|
||||
|
||||
@ -287,7 +287,7 @@ public class MetricsServiceImpl extends MutualExclusiveIdsManagerBase implements
|
||||
|
||||
SearchBuilder<VMInstanceVO> sb = vmInstanceDao.createSearchBuilder();
|
||||
sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
|
||||
sb.and("type", sb.entity().getType(), SearchCriteria.Op.NEQ);
|
||||
|
||||
@ -340,7 +340,7 @@ public class MetricsServiceImpl extends MutualExclusiveIdsManagerBase implements
|
||||
|
||||
SearchBuilder<VolumeVO> sb = volumeDao.createSearchBuilder();
|
||||
sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
|
||||
|
||||
SearchCriteria<VolumeVO> sc = sb.create();
|
||||
|
||||
@ -1391,7 +1391,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
||||
final SearchBuilder<VpcVO> sb = vpcDao.createSearchBuilder();
|
||||
_accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
|
||||
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("displayText", sb.entity().getDisplayText(), SearchCriteria.Op.LIKE);
|
||||
sb.and("vpcOfferingId", sb.entity().getVpcOfferingId(), SearchCriteria.Op.EQ);
|
||||
|
||||
@ -4580,7 +4580,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
final SearchCriteria<UserDataVO> sc = sb.create();
|
||||
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
|
||||
|
||||
|
||||
@ -1889,7 +1889,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
return _storagePoolDao.findByUuid(uuid);
|
||||
}
|
||||
|
||||
private void validateChildDatastoresToBeAddedInUpState(StoragePoolVO datastoreClusterPool, List<ModifyStoragePoolAnswer> childDatastoreAnswerList) {
|
||||
public void validateChildDatastoresToBeAddedInUpState(StoragePoolVO datastoreClusterPool, List<ModifyStoragePoolAnswer> childDatastoreAnswerList) {
|
||||
for (ModifyStoragePoolAnswer childDataStoreAnswer : childDatastoreAnswerList) {
|
||||
StoragePoolInfo childStoragePoolInfo = childDataStoreAnswer.getPoolInfo();
|
||||
StoragePoolVO dataStoreVO = _storagePoolDao.findPoolByUUID(childStoragePoolInfo.getUuid());
|
||||
@ -1904,8 +1904,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
}
|
||||
}
|
||||
if (dataStoreVO != null && !dataStoreVO.getStatus().equals(StoragePoolStatus.Up)) {
|
||||
String msg = String.format("Cannot synchronise datastore cluster %s because primary storage with id %s is not ready for syncing, " +
|
||||
"as the status is %s", datastoreClusterPool.getUuid(), dataStoreVO.getUuid(), dataStoreVO.getStatus().toString());
|
||||
String msg = String.format("Cannot synchronise datastore cluster %s because primary storage with id %s is not in Up state, " +
|
||||
"current state is %s", datastoreClusterPool.getUuid(), dataStoreVO.getUuid(), dataStoreVO.getStatus().toString());
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,13 +357,13 @@ public class RoleManagerImpl extends ManagerBase implements RoleService, Configu
|
||||
|
||||
@Override
|
||||
public List<Role> findRolesByName(String name) {
|
||||
return findRolesByName(name, null, null).first();
|
||||
return findRolesByName(name, null, null, null).first();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<List<Role>, Integer> findRolesByName(String name, Long startIndex, Long limit) {
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
Pair<List<RoleVO>, Integer> data = roleDao.findAllByName(name, startIndex, limit);
|
||||
public Pair<List<Role>, Integer> findRolesByName(String name, String keyword, Long startIndex, Long limit) {
|
||||
if (StringUtils.isNotBlank(name) || StringUtils.isNotBlank(keyword)) {
|
||||
Pair<List<RoleVO>, Integer> data = roleDao.findAllByName(name, keyword, startIndex, limit);
|
||||
int removed = removeRootAdminRolesIfNeeded(data.first());
|
||||
return new Pair<List<Role>,Integer>(ListUtils.toListOfInterface(data.first()), Integer.valueOf(data.second() - removed));
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ public class BackupManagerImpl extends ManagerBase implements BackupManager {
|
||||
final Filter searchFilter = new Filter(BackupOfferingVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
SearchBuilder<BackupOfferingVO> sb = backupOfferingDao.createSearchBuilder();
|
||||
sb.and("zone_id", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
|
||||
final SearchCriteria<BackupOfferingVO> sc = sb.create();
|
||||
|
||||
|
||||
@ -166,7 +166,7 @@ public class RoleManagerImplTest {
|
||||
String roleName = "roleName";
|
||||
List<Role> roles = new ArrayList<>();
|
||||
Pair<ArrayList<RoleVO>, Integer> toBeReturned = new Pair(roles, 0);
|
||||
Mockito.doReturn(toBeReturned).when(roleDaoMock).findAllByName(roleName, null, null);
|
||||
Mockito.doReturn(toBeReturned).when(roleDaoMock).findAllByName(roleName, null, null, null);
|
||||
|
||||
roleManagerImpl.findRolesByName(roleName);
|
||||
Mockito.verify(roleManagerImpl).removeRootAdminRolesIfNeeded(roles);
|
||||
|
||||
@ -1433,13 +1433,13 @@ export default {
|
||||
continue
|
||||
}
|
||||
if (input === undefined || input === null ||
|
||||
(input === '' && !['updateStoragePool', 'updateHost', 'updatePhysicalNetwork', 'updateDiskOffering', 'updateNetworkOffering', 'updateServiceOffering', 'updateAccount'].includes(action.api))) {
|
||||
(input === '' && !['updateStoragePool', 'updateHost', 'updatePhysicalNetwork', 'updateDiskOffering', 'updateNetworkOffering', 'updateServiceOffering', 'updateZone', 'updateAccount'].includes(action.api))) {
|
||||
if (param.type === 'boolean') {
|
||||
params[key] = false
|
||||
}
|
||||
break
|
||||
}
|
||||
if (input === '' && !['tags', 'hosttags', 'storagetags', 'networkdomain'].includes(key)) {
|
||||
if (input === '' && !['tags', 'hosttags', 'storagetags', 'dns2', 'ip6dns1', 'ip6dns2', 'internaldns2', 'networkdomain'].includes(key)) {
|
||||
break
|
||||
}
|
||||
if (action.mapping && key in action.mapping && action.mapping[key].options) {
|
||||
@ -1636,9 +1636,7 @@ export default {
|
||||
if ('searchQuery' in opts) {
|
||||
const value = opts.searchQuery
|
||||
if (value && value.length > 0) {
|
||||
if (this.$route.name === 'role') {
|
||||
query.name = value
|
||||
} else if (this.$route.name === 'quotaemailtemplate') {
|
||||
if (this.$route.name === 'quotaemailtemplate') {
|
||||
query.templatetype = value
|
||||
} else if (this.$route.name === 'globalsetting') {
|
||||
query.name = value
|
||||
|
||||
@ -926,7 +926,7 @@ describe('Views > AutogenView.vue', () => {
|
||||
await flushPromises()
|
||||
|
||||
expect(router.currentRoute.value.path).toEqual('/role')
|
||||
expect(router.currentRoute.value.query).toEqual({ name: 'test-value', q: 'test-value', page: '1', pagesize: '20' })
|
||||
expect(router.currentRoute.value.query).toEqual({ keyword: 'test-value', q: 'test-value', page: '1', pagesize: '20' })
|
||||
done()
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user