Merge branch 'master' into storage-offering-domains-zones

schema and server changes for VPC offering to honour changes from f653e61 in master
This commit is contained in:
Abhishek Kumar 2019-06-26 13:27:00 +05:30
commit 12218e398d
12 changed files with 67 additions and 20 deletions

View File

@ -45,11 +45,14 @@ public interface VpcProvisioningService {
*/
public boolean deleteVpcOffering(long offId);
@Deprecated
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state);
/**
* @param cmd
* @return
*/
public VpcOffering updateVpcOffering(UpdateVPCOfferingCmd cmd);
VpcOffering updateVpcOffering(final UpdateVPCOfferingCmd cmd);
/**
* Retrieve ID of domains for a VPC offering

View File

@ -69,6 +69,9 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd {
since = "4.13")
private String zoneIds;
@Parameter(name = ApiConstants.SORT_KEY, type = CommandType.INTEGER, description = "sort key of the VPC offering, integer")
private Integer sortKey;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -149,6 +152,10 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd {
return validZoneIds;
}
public Integer getSortKey() {
return sortKey;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -114,7 +114,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements L
+ "rule will be created for. Required when public Ip address is not associated with any Guest network yet (VPC case)")
private Long networkId;
@Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, description = "The protocol for the LB")
@Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, description = "The protocol for the LB such as tcp, udp or tcp-proxy.")
private String lbProtocol;
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})

View File

@ -76,6 +76,9 @@ public class VpcOfferingVO implements VpcOffering {
@Column(name = "redundant_router_service")
boolean redundantRouter = false;
@Column(name = "sort_key")
int sortKey;
public VpcOfferingVO() {
this.uuid = UUID.randomUUID().toString();
}
@ -193,4 +196,12 @@ public class VpcOfferingVO implements VpcOffering {
return this.redundantRouter;
}
public void setSortKey(int key) {
sortKey = key;
}
public int getSortKey() {
return sortKey;
}
}

View File

@ -26,6 +26,8 @@ INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid,hypervisor_type, hypervis
-- DPDK client and server mode support
ALTER TABLE `cloud`.`service_offering_details` CHANGE COLUMN `value` `value` TEXT NOT NULL;
ALTER TABLE `cloud`.`vpc_offerings` ADD COLUMN `sort_key` int(32) NOT NULL default 0 COMMENT 'sort key used for customising sort method';
-- Add `sort_key` column to data_center
ALTER TABLE `cloud`.`data_center` ADD COLUMN `sort_key` INT(32) NOT NULL DEFAULT 0;
@ -259,6 +261,7 @@ CREATE VIEW `cloud`.`vpc_offering_view` AS
`vpc_offerings`.`supports_distributed_router` AS `supports_distributed_router`,
`vpc_offerings`.`supports_region_level_vpc` AS `supports_region_level_vpc`,
`vpc_offerings`.`redundant_router_service` AS `redundant_router_service`,
`vpc_offerings`.`sort_key` AS `sort_key`,
GROUP_CONCAT(DISTINCT(domain.id)) AS domain_id,
GROUP_CONCAT(DISTINCT(domain.uuid)) AS domain_uuid,
GROUP_CONCAT(DISTINCT(domain.name)) AS domain_name,
@ -317,4 +320,4 @@ CREATE VIEW `cloud`.`data_center_view` AS
left join
`cloud`.`dedicated_resources` ON data_center.id = dedicated_resources.data_center_id
left join
`cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;
`cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;

View File

@ -319,7 +319,7 @@ public class MockAccountManager extends ManagerBase implements AccountManager {
}
@Override
public boolean moveUser(long id, Long domainId, long accountId) {
public boolean moveUser(long id, Long domainId, Account account) {
return false;
}

View File

@ -35,6 +35,7 @@ import com.cloud.user.UserAccount;
import com.cloud.user.dao.UserAccountDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.exception.CloudRuntimeException;
public class LdapAuthenticator extends AdapterBase implements UserAuthenticator {
private static final Logger s_logger = Logger.getLogger(LdapAuthenticator.class.getName());
@ -135,7 +136,11 @@ public class LdapAuthenticator extends AdapterBase implements UserAuthenticator
} else {
// not a new user, check if mapped group has changed
if(userAccount.getAccountId() != mapping.getAccountId()) {
_accountManager.moveUser(userAccount.getId(),userAccount.getDomainId(),mapping.getAccountId());
final Account mappedAccount = _accountManager.getAccount(mapping.getAccountId());
if (mappedAccount == null || mappedAccount.getRemoved() != null) {
throw new CloudRuntimeException("Mapped account for users does not exist. Please contact your administrator.");
}
_accountManager.moveUser(userAccount.getId(), userAccount.getDomainId(), mappedAccount);
}
// else { the user hasn't changed in ldap, the ldap group stayed the same, hurray, pass, fun thou self a lot of fun }
}

View File

@ -74,6 +74,9 @@ public class VpcOfferingJoinVO implements VpcOffering {
@Column(name = "redundant_router_service")
boolean redundantRouter = false;
@Column(name = "sort_key")
int sortKey;
@Column(name = "domain_id")
private String domainId;
@ -162,6 +165,10 @@ public class VpcOfferingJoinVO implements VpcOffering {
return redundantRouter;
}
public int getSortKey() {
return sortKey;
}
public String getDomainId() {
return domainId;
}

View File

@ -657,7 +657,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
final Long startIndex = cmd.getStartIndex();
final Long pageSizeVal = cmd.getPageSizeVal();
final Long zoneId = cmd.getZoneId();
final Filter searchFilter = new Filter(VpcOfferingJoinVO.class, "created", false, null, null);
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
isAscending = isAscending == null ? Boolean.TRUE : isAscending;
final Filter searchFilter = new Filter(VpcOfferingJoinVO.class, "sortKey", isAscending, null, null);
final SearchCriteria<VpcOfferingJoinVO> sc = vpcOfferingJoinDao.createSearchCriteria();
if (keyword != null) {
@ -800,13 +802,20 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering")
public VpcOffering updateVpcOffering(UpdateVPCOfferingCmd cmd) {
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state) {
return updateVpcOfferingInternal(vpcOffId, vpcOfferingName, displayText, state, null, null, null);
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering")
public VpcOffering updateVpcOffering(final UpdateVPCOfferingCmd cmd) {
final Long offeringId = cmd.getId();
final String vpcOfferingName = cmd.getVpcOfferingName();
final String displayText = cmd.getDisplayText();
final String state = cmd.getState();
final List<Long> domainIds = cmd.getDomainIds();
final List<Long> zoneIds = cmd.getZoneIds();
final Integer sortKey = cmd.getSortKey();
// check if valid domain
if (CollectionUtils.isNotEmpty(domainIds)) {
@ -825,10 +834,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
}
}
return updateVpcOffering(offeringId, vpcOfferingName, displayText, state, domainIds, zoneIds);
return updateVpcOfferingInternal(offeringId, vpcOfferingName, displayText, state, sortKey, domainIds, zoneIds);
}
private VpcOffering updateVpcOffering(final long vpcOffId,final String vpcOfferingName, final String displayText, final String state, final List<Long> domainIds, final List<Long> zoneIds) {
private VpcOffering updateVpcOfferingInternal(long vpcOffId, String vpcOfferingName, String displayText, String state, Integer sortKey, final List<Long> domainIds, final List<Long> zoneIds) {
CallContext.current().setEventDetails(" Id: " + vpcOffId);
// Verify input parameters
@ -854,7 +863,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
}
Collections.sort(filteredZoneIds);
final boolean updateNeeded = vpcOfferingName != null || displayText != null || state != null;
final boolean updateNeeded = vpcOfferingName != null || displayText != null || state != null || sortKey != null;
final VpcOfferingVO offering = _vpcOffDao.createForUpdate(vpcOffId);
@ -862,11 +871,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
if (vpcOfferingName != null) {
offering.setName(vpcOfferingName);
}
if (displayText != null) {
offering.setDisplayText(displayText);
}
if (state != null) {
boolean validState = false;
for (final VpcOffering.State st : VpcOffering.State.values()) {
@ -879,6 +886,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
throw new InvalidParameterValueException("Incorrect state value: " + state);
}
}
if (sortKey != null) {
offering.setSortKey(sortKey);
}
if (!_vpcOffDao.update(vpcOffId, offering)) {
return null;
}

View File

@ -180,11 +180,12 @@ public interface AccountManager extends AccountService, Configurable {
List<String> listAclGroupsByAccount(Long accountId);
public static final String MESSAGE_ADD_ACCOUNT_EVENT = "Message.AddAccount.Event";
String MESSAGE_ADD_ACCOUNT_EVENT = "Message.AddAccount.Event";
public static final String MESSAGE_REMOVE_ACCOUNT_EVENT = "Message.RemoveAccount.Event";
public static final ConfigKey<Boolean> UseSecretKeyInResponse = new ConfigKey<Boolean>("Advanced", Boolean.class, "use.secret.key.in.response", "false",
String MESSAGE_REMOVE_ACCOUNT_EVENT = "Message.RemoveAccount.Event";
ConfigKey<Boolean> UseSecretKeyInResponse = new ConfigKey<Boolean>("Advanced", Boolean.class, "use.secret.key.in.response", "false",
"This parameter allows the users to enable or disable of showing secret key as a part of response for various APIs. By default it is set to false.", true);
boolean moveUser(long id, Long domainId, long accountId);
boolean moveUser(long id, Long domainId, Account newAccount);
}

View File

@ -1820,13 +1820,12 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
}
@Override
public boolean moveUser(long id, Long domainId, long accountId) {
public boolean moveUser(long id, Long domainId, Account newAccount) {
UserVO user = getValidUserVO(id);
Account oldAccount = _accountDao.findById(user.getAccountId());
checkAccountAndAccess(user, oldAccount);
Account newAccount = _accountDao.findById(accountId);
checkIfNotMovingAcrossDomains(domainId, newAccount);
return moveUser(user, accountId);
return moveUser(user, newAccount.getId());
}
private boolean moveUser(UserVO user, long newAccountId) {

View File

@ -132,7 +132,7 @@ public class MockAccountManagerImpl extends ManagerBase implements Manager, Acco
}
@Override
public boolean moveUser(long id, Long domainId, long accountId) {
public boolean moveUser(long id, Long domainId, Account account) {
return false;
}