List of usage examples for org.apache.commons.httpclient NameValuePair NameValuePair
public NameValuePair(String name, String value)
From source file:org.apache.cloudstack.region.RegionManagerImpl.java
/** * {@inheritDoc}//from w w w . j a va 2s . co m */ @Override public boolean deleteUserAccount(long accountId) { AccountVO account = _accountDao.findById(accountId); if (account == null) { throw new InvalidParameterValueException("The specified account does not exist in the system"); } String accountUUID = account.getUuid(); int regionId = account.getRegionId(); String command = "deleteAccount"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair(ApiConstants.ID, accountUUID)); if (getId() == regionId) { if (_accountMgr.deleteUserAccount(accountId)) { List<RegionVO> regions = _regionDao.listAll(); for (Region region : regions) { if (region.getId() == getId()) { continue; } params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true")); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug( "Successfully deleted account :" + accountUUID + " in Region: " + region.getId()); } else { s_logger.error( "Error while deleting account :" + accountUUID + " in Region: " + region.getId()); } } return true; } else { return false; } } else { //First delete in the Region where account is created Region region = _regionDao.findById(regionId); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug("Successfully deleted account :" + accountUUID + " in Region: " + region.getId()); return true; } else { s_logger.error("Error while deleting account :" + accountUUID + " in Region: " + region.getId()); return false; } } }
From source file:org.apache.cloudstack.region.RegionManagerImpl.java
/** * {@inheritDoc}//ww w . ja v a2 s. c o m */ @Override public Account updateAccount(UpdateAccountCmd cmd) { Long accountId = cmd.getId(); Long domainId = cmd.getDomainId(); DomainVO domain = _domainDao.findById(domainId); String accountName = cmd.getAccountName(); String newAccountName = cmd.getNewName(); String networkDomain = cmd.getNetworkDomain(); //ToDo send details Map<String, String> details = cmd.getDetails(); Account account = null; if (accountId != null) { account = _accountDao.findById(accountId); } else { account = _accountDao.findEnabledAccount(accountName, domainId); } // Check if account exists if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) { s_logger.error("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } String command = "updateAccount"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair(ApiConstants.NEW_NAME, newAccountName)); params.add(new NameValuePair(ApiConstants.ID, account.getUuid())); params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName)); params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid())); params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, networkDomain)); params.add(new NameValuePair(ApiConstants.NEW_NAME, newAccountName)); if (details != null) { params.add(new NameValuePair(ApiConstants.ACCOUNT_DETAILS, details.toString())); } int regionId = account.getRegionId(); if (getId() == regionId) { Account updatedAccount = _accountMgr.updateAccount(cmd); if (updatedAccount != null) { List<RegionVO> regions = _regionDao.listAll(); for (Region region : regions) { if (region.getId() == getId()) { continue; } params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true")); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug("Successfully updated account :" + account.getUuid() + " in Region: " + region.getId()); } else { s_logger.error("Error while updating account :" + account.getUuid() + " in Region: " + region.getId()); } } } return updatedAccount; } else { //First update in the Region where account is created Region region = _regionDao.findById(regionId); RegionAccount updatedAccount = RegionsApiUtil.makeAccountAPICall(region, command, params); if (updatedAccount != null) { Long id = _identityDao.getIdentityId("account", updatedAccount.getUuid()); updatedAccount.setId(id); Long domainID = _identityDao.getIdentityId("domain", updatedAccount.getDomainUuid()); updatedAccount.setDomainId(domainID); s_logger.debug("Successfully updated account :" + account.getUuid() + " in source Region: " + region.getId()); return updatedAccount; } else { throw new CloudRuntimeException("Error while updating account :" + account.getUuid() + " in source Region: " + region.getId()); } } }
From source file:org.apache.cloudstack.region.RegionManagerImpl.java
/** * {@inheritDoc}/*from www .j a v a 2 s .com*/ */ @Override public Account disableAccount(String accountName, Long domainId, Long accountId, Boolean lockRequested) throws ConcurrentOperationException, ResourceUnavailableException { Account account = null; if (accountId != null) { account = _accountDao.findById(accountId); } else { account = _accountDao.findActiveAccount(accountName, domainId); } if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) { throw new InvalidParameterValueException("Unable to find active account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } String accountUUID = account.getUuid(); String command = "disableAccount"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair(ApiConstants.LOCK, lockRequested.toString())); params.add(new NameValuePair(ApiConstants.ID, accountUUID)); DomainVO domain = _domainDao.findById(domainId); if (domain != null) { params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid())); } int regionId = account.getRegionId(); if (getId() == regionId) { Account retAccount = null; if (lockRequested) { retAccount = _accountMgr.lockAccount(accountName, domainId, accountId); } else { retAccount = _accountMgr.disableAccount(accountName, domainId, accountId); } if (retAccount != null) { List<RegionVO> regions = _regionDao.listAll(); for (Region region : regions) { if (region.getId() == getId()) { continue; } params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true")); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug( "Successfully disabled account :" + accountUUID + " in Region: " + region.getId()); } else { s_logger.error( "Error while disabling account :" + accountUUID + " in Region: " + region.getId()); } } } return retAccount; } else { //First disable account in the Region where account is created Region region = _regionDao.findById(regionId); Account retAccount = RegionsApiUtil.makeAccountAPICall(region, command, params); if (retAccount != null) { s_logger.debug( "Successfully disabled account :" + accountUUID + " in source Region: " + region.getId()); return retAccount; } else { throw new CloudRuntimeException( "Error while disabling account :" + accountUUID + " in source Region: " + region.getId()); } } }
From source file:org.apache.cloudstack.region.RegionManagerImpl.java
/** * {@inheritDoc}//from w ww .j a va2s. c o m */ @Override public Account enableAccount(String accountName, Long domainId, Long accountId) { // Check if account exists Account account = null; if (accountId != null) { account = _accountDao.findById(accountId); } else { account = _accountDao.findActiveAccount(accountName, domainId); } if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) { throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } String accountUUID = account.getUuid(); String command = "enableAccount"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair(ApiConstants.ID, accountUUID)); params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName)); DomainVO domain = _domainDao.findById(domainId); if (domain != null) { params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid())); } int regionId = account.getRegionId(); if (getId() == regionId) { Account retAccount = _accountMgr.enableAccount(accountName, domainId, accountId); if (retAccount != null) { List<RegionVO> regions = _regionDao.listAll(); for (Region region : regions) { if (region.getId() == getId()) { continue; } params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true")); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug( "Successfully enabled account :" + accountUUID + " in Region: " + region.getId()); } else { s_logger.error( "Error while enabling account :" + accountUUID + " in Region: " + region.getId()); } } } return retAccount; } else { //First disable account in the Region where account is created Region region = _regionDao.findById(regionId); Account retAccount = RegionsApiUtil.makeAccountAPICall(region, command, params); if (retAccount != null) { s_logger.debug( "Successfully enabled account :" + accountUUID + " in source Region: " + region.getId()); return retAccount; } else { throw new CloudRuntimeException( "Error while enabling account :" + accountUUID + " in source Region: " + region.getId()); } } }
From source file:org.apache.cloudstack.region.RegionManagerImpl.java
/** * {@inheritDoc}/*from w w w. jav a 2 s .c o m*/ */ @Override public boolean deleteUser(DeleteUserCmd cmd) { long id = cmd.getId(); UserVO user = _userDao.findById(id); if (user == null) { throw new InvalidParameterValueException("The specified user doesn't exist in the system"); } String userUUID = user.getUuid(); int regionId = user.getRegionId(); String command = "deleteUser"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair(ApiConstants.ID, userUUID)); if (getId() == regionId) { if (_accountMgr.deleteUser(cmd)) { List<RegionVO> regions = _regionDao.listAll(); for (Region region : regions) { if (region.getId() == getId()) { continue; } params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true")); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug("Successfully deleted user :" + userUUID + " in Region: " + region.getId()); } else { s_logger.error( "Error while deleting account :" + userUUID + " in Region: " + region.getId()); } } return true; } else { return false; } } else { //First delete in the Region where account is created Region region = _regionDao.findById(regionId); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug("Successfully deleted user :" + userUUID + " in source Region: " + region.getId()); return true; } else { s_logger.error("Error while deleting user :" + userUUID + " in source Region: " + region.getId()); return false; } } }
From source file:org.apache.cloudstack.region.RegionManagerImpl.java
/** * {@inheritDoc}//from w w w. j a v a 2s . c o m */ @Override public Domain updateDomain(UpdateDomainCmd cmd) { long id = cmd.getId(); DomainVO domain = _domainDao.findById(id); if (domain == null) { throw new InvalidParameterValueException("The specified domain doesn't exist in the system"); } String domainUUID = domain.getUuid(); String command = "updateDomain"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair(ApiConstants.ID, domainUUID)); params.add(new NameValuePair(ApiConstants.NAME, cmd.getDomainName())); params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, cmd.getNetworkDomain())); int regionId = domain.getRegionId(); if (getId() == regionId) { Domain updatedDomain = _domainMgr.updateDomain(cmd); if (updatedDomain != null) { List<RegionVO> regions = _regionDao.listAll(); for (Region region : regions) { if (region.getId() == getId()) { continue; } params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true")); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug("Successfully updated updatedDomain :" + domainUUID + " in Region: " + region.getId()); } else { s_logger.error("Error while updating updatedDomain :" + domainUUID + " in Region: " + region.getId()); } } } return updatedDomain; } else { //First update in the Region where domain was created Region region = _regionDao.findById(regionId); RegionDomain updatedDomain = RegionsApiUtil.makeDomainAPICall(region, command, params); if (updatedDomain != null) { Long parentId = _identityDao.getIdentityId("domain", updatedDomain.getParentUuid()); updatedDomain.setParent(parentId); s_logger.debug("Successfully updated user :" + domainUUID + " in source Region: " + region.getId()); return (DomainVO) updatedDomain; } else { throw new CloudRuntimeException( "Error while updating user :" + domainUUID + " in source Region: " + region.getId()); } } }
From source file:org.apache.cloudstack.region.RegionManagerImpl.java
/** * {@inheritDoc}/*from w w w . ja va 2 s . c o m*/ */ @Override public boolean deleteDomain(Long id, Boolean cleanup) { DomainVO domain = _domainDao.findById(id); if (domain == null) { throw new InvalidParameterValueException("The specified domain doesn't exist in the system"); } String domainUUID = domain.getUuid(); String command = "deleteDomain"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair(ApiConstants.ID, domainUUID)); params.add(new NameValuePair(ApiConstants.CLEANUP, cleanup.toString())); int regionId = domain.getRegionId(); if (getId() == regionId) { if (_domainMgr.deleteDomain(id, cleanup)) { List<RegionVO> regions = _regionDao.listAll(); for (Region region : regions) { if (region.getId() == getId()) { continue; } params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true")); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug( "Successfully deleted domain :" + domainUUID + " in Region: " + region.getId()); } else { s_logger.error( "Error while deleting domain :" + domainUUID + " in Region: " + region.getId()); } } return true; } else { return false; } } else { //First delete in the Region where domain is created Region region = _regionDao.findById(regionId); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug("Successfully deleted domain :" + domainUUID + " in Region: " + region.getId()); return true; } else { s_logger.error("Error while deleting domain :" + domainUUID + " in Region: " + region.getId()); return false; } } }
From source file:org.apache.cloudstack.region.RegionManagerImpl.java
/** * {@inheritDoc}//from w w w.ja v a2s . c o m */ @Override public UserAccount updateUser(UpdateUserCmd cmd) { long id = cmd.getId(); UserVO user = _userDao.findById(id); if (user == null) { throw new InvalidParameterValueException("The specified user doesn't exist in the system"); } String userUUID = user.getUuid(); String command = "updateUser"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair(ApiConstants.ID, userUUID)); params.add(new NameValuePair(ApiConstants.API_KEY, cmd.getApiKey())); params.add(new NameValuePair(ApiConstants.EMAIL, cmd.getEmail())); params.add(new NameValuePair(ApiConstants.FIRSTNAME, cmd.getFirstname())); params.add(new NameValuePair(ApiConstants.LASTNAME, cmd.getLastname())); params.add(new NameValuePair(ApiConstants.PASSWORD, cmd.getPassword())); params.add(new NameValuePair(ApiConstants.SECRET_KEY, cmd.getSecretKey())); params.add(new NameValuePair(ApiConstants.TIMEZONE, cmd.getTimezone())); params.add(new NameValuePair(ApiConstants.USERNAME, cmd.getUsername())); int regionId = user.getRegionId(); if (getId() == regionId) { UserAccount updateUser = _accountMgr.updateUser(cmd); if (updateUser != null) { List<RegionVO> regions = _regionDao.listAll(); for (Region region : regions) { if (region.getId() == getId()) { continue; } params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true")); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug("Successfully updated user :" + userUUID + " in Region: " + region.getId()); } else { s_logger.error("Error while updating user :" + userUUID + " in Region: " + region.getId()); } } } return updateUser; } else { //First update in the Region where user was created Region region = _regionDao.findById(regionId); UserAccount updateUser = RegionsApiUtil.makeUserAccountAPICall(region, command, params); if (updateUser != null) { s_logger.debug("Successfully updated user :" + userUUID + " in source Region: " + region.getId()); return updateUser; } else { throw new CloudRuntimeException( "Error while updating user :" + userUUID + " in source Region: " + region.getId()); } } }
From source file:org.apache.cloudstack.region.RegionManagerImpl.java
/** * {@inheritDoc}/* w w w. ja v a 2s. c o m*/ */ @Override public UserAccount disableUser(Long userId) { UserVO user = _userDao.findById(userId); if (user == null || user.getRemoved() != null) { throw new InvalidParameterValueException("Unable to find active user by id " + userId); } int regionId = user.getRegionId(); String command = "disableUser"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair(ApiConstants.ID, user.getUuid())); if (getId() == regionId) { UserAccount disabledUser = _accountMgr.disableUser(userId); if (disabledUser != null) { List<RegionVO> regions = _regionDao.listAll(); for (Region region : regions) { if (region.getId() == getId()) { continue; } params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true")); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug( "Successfully disabled user :" + user.getUuid() + " in Region: " + region.getId()); } else { s_logger.error( "Error while disabling user :" + user.getUuid() + " in Region: " + region.getId()); } } } return disabledUser; } else { //First disable in the Region where user was created Region region = _regionDao.findById(regionId); UserAccount disabledUser = RegionsApiUtil.makeUserAccountAPICall(region, command, params); if (disabledUser != null) { s_logger.debug( "Successfully disabled user :" + user.getUuid() + " in source Region: " + region.getId()); return disabledUser; } else { throw new CloudRuntimeException( "Error while disabling user :" + user.getUuid() + " in source Region: " + region.getId()); } } }
From source file:org.apache.cloudstack.region.RegionManagerImpl.java
/** * {@inheritDoc}/*from w ww .j av a 2s. c o m*/ */ @Override public UserAccount enableUser(long userId) { UserVO user = _userDao.findById(userId); if (user == null || user.getRemoved() != null) { throw new InvalidParameterValueException("Unable to find active user by id " + userId); } int regionId = user.getRegionId(); String command = "enableUser"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair(ApiConstants.ID, user.getUuid())); if (getId() == regionId) { UserAccount enabledUser = _accountMgr.enableUser(userId); if (enabledUser != null) { List<RegionVO> regions = _regionDao.listAll(); for (Region region : regions) { if (region.getId() == getId()) { continue; } params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true")); if (RegionsApiUtil.makeAPICall(region, command, params)) { s_logger.debug( "Successfully enabled user :" + user.getUuid() + " in Region: " + region.getId()); } else { s_logger.error( "Error while disabling user :" + user.getUuid() + " in Region: " + region.getId()); } } } return enabledUser; } else { //First enable in the Region where user was created Region region = _regionDao.findById(regionId); UserAccount enabledUser = RegionsApiUtil.makeUserAccountAPICall(region, command, params); if (enabledUser != null) { s_logger.debug( "Successfully enabled user :" + user.getUuid() + " in source Region: " + region.getId()); return enabledUser; } else { throw new CloudRuntimeException( "Error while enabling user :" + user.getUuid() + " in source Region: " + region.getId()); } } }