CLOUDSTACK-8592: Adding new APIs and implementing the API stubs

This commit is contained in:
Abhinandan Prateek 2015-07-08 11:13:35 +05:30 committed by Rohit Yadav
parent f6e7c52c12
commit a558afae57
9 changed files with 242 additions and 130 deletions

View File

@ -784,11 +784,13 @@ addGloboDnsHost=1
### Quota Service
listQuotaConfigurations=15
quotaRefresh=15
quotaCredits=15
quotaStatement=15
quotaEmailTemplateUpdate=3
quotaEmailTemplateDelete=3
quotaEmailTemplateAdd=3
quotaReports=3
quotaEmailTemplateUpdate=15
quotaEmailTemplateDelete=15
quotaEmailTemplateAdd=15
quotaReports=15

View File

@ -27,6 +27,10 @@
<bean id="QuotaManager" class="org.apache.cloudstack.quota.QuotaManagerImpl" />
<bean id="QuotaConfigurationDao" class="org.apache.cloudstack.quota.dao.QuotaConfigurationDaoImpl" />
<bean id="QuotaBalanceDao" class="org.apache.cloudstack.quota.dao.QuotaBalanceDaoImpl"/>
<bean id="QuotaCreditsDao" class="org.apache.cloudstack.quota.dao.QuotaCreditsDaoImpl"/>
<bean id="QuotaEmailTemplatesDao" class="org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDaoImpl"/>
<bean id="QuotaSentEmailDao" class="org.apache.cloudstack.quota.dao.QuotaSentEmailsDaoImpl"/>
<bean id="QuotaUsageDao" class="org.apache.cloudstack.quota.dao.QuotaUsageDaoImpl"/>
</beans>

View File

@ -22,7 +22,7 @@ import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.DomainResponse;
@ -30,87 +30,85 @@ import org.apache.cloudstack.api.response.QuotaCreditsResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.quota.QuotaManager;
import com.cloud.user.Account;
@APICommand(name = "quotaCredits", responseObject = QuotaCreditsResponse.class, description = "Add +-credits to an account", since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class QuotaCreditsCmd extends BaseListCmd {
public class QuotaCreditsCmd extends BaseCmd {
public static final Logger s_logger = Logger
.getLogger(QuotaStatementCmd.class.getName());
public static final Logger s_logger = Logger
.getLogger(QuotaStatementCmd.class.getName());
private static final String s_name = "quotacreditsresponse";
private static final String s_name = "quotacreditsresponse";
@Inject
private QuotaManager _quotaManager;
@Inject
private QuotaManager _quotaManager;
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Account Id for which quota credits need to be added")
private String accountName;
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Account Id for which quota credits need to be added")
private String accountName;
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "Domain for which quota credits need to be added")
private Long domainId;
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "Domain for which quota credits need to be added")
private Long domainId;
@Parameter(name = ApiConstants.VALUE, type = CommandType.INTEGER, entityType = DomainResponse.class, description = "Value of the credits to be added+, subtracted-")
private Integer value;
@Parameter(name = ApiConstants.VALUE, type = CommandType.INTEGER, entityType = DomainResponse.class, description = "Value of the credits to be added+, subtracted-")
private Integer value;
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public Long getDomainId() {
return domainId;
}
public void setDomainId(Long domainId) {
this.domainId = domainId;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public QuotaCreditsCmd() {
super();
}
public QuotaCreditsCmd(final QuotaManager quotaManager) {
super();
_quotaManager = quotaManager;
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute() {
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, null, true);
if (accountId==null){
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "The account does not exists or has been removed/disabled");
public String getAccountName() {
return accountName;
}
final QuotaCreditsResponse credit_response = _quotaManager.addQuotaCredits(accountId, domainId, value, CallContext.current().getCallingAccount().getId());
public void setAccountName(String accountName) {
this.accountName = accountName;
}
setResponseObject(credit_response);
}
public Long getDomainId() {
return domainId;
}
public void setDomainId(Long domainId) {
this.domainId = domainId;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public QuotaCreditsCmd() {
super();
}
public QuotaCreditsCmd(final QuotaManager quotaManager) {
super();
_quotaManager = quotaManager;
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute() {
Long accountId = _accountService.finalyzeAccountId(accountName,
domainId, null, true);
if (accountId == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
"The account does not exists or has been removed/disabled");
}
final QuotaCreditsResponse credit_response = _quotaManager
.addQuotaCredits(accountId, domainId, value, CallContext
.current().getCallingAccount().getId());
setResponseObject(credit_response);
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
}

View File

@ -0,0 +1,67 @@
//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.api.command;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.QuotaRefreshResponse;
import org.apache.cloudstack.quota.QuotaManager;
import com.cloud.user.Account;
@APICommand(name = "quotaRefresh", responseObject = QuotaRefreshResponse.class, description = "Refresh the quota for all accounts if enabled", since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class QuotaRefreshCmd extends BaseCmd {
public static final Logger s_logger = Logger
.getLogger(QuotaStatementCmd.class.getName());
private static final String s_name = "quotarefreshresponse";
@Inject
private QuotaManager _quotaManager;
public QuotaRefreshCmd() {
super();
}
public QuotaRefreshCmd(final QuotaManager quotaManager) {
super();
_quotaManager = quotaManager;
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute() throws ServerApiException {
final QuotaRefreshResponse response = new QuotaRefreshResponse(
"Success");
setResponseObject(response);
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
}

View File

@ -20,38 +20,25 @@ import java.sql.Timestamp;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.quota.QuotaCreditsVO;
import com.cloud.serializer.Param;
public class QuotaCreditsResponse extends BaseResponse {
@SerializedName(ApiConstants.ID)
@Param(description = "the ID of the credit")
private String id;
@SerializedName(ApiConstants.ACCOUNT)
@Param(description = "the account name of the api remaining count")
private String accountName;
@SerializedName(ApiConstants.DOMAIN_ID)
@Param(description = "the domain ID of the iam policy")
private String domainId;
@SerializedName("credits")
@Param(description = "the credit deposited")
private String credits;
private Integer credits;
@SerializedName("balance")
@Param(description = "the balance credit in account")
private String balance;
private Integer balance;
@SerializedName("updated_by")
@Param(description = "the account name of the admin who updated the credits")
private String updatedBy;
@SerializedName("updated_on")
@Param(description = "the account name of the admin who updated the credits")
private Timestamp updatedOn;
@ -61,52 +48,34 @@ public class QuotaCreditsResponse extends BaseResponse {
super();
}
public String getId() {
return id;
}
public QuotaCreditsResponse(QuotaCreditsVO result) {
super();
if (result != null){
this.credits = 100;
this.balance = 200;
this.updatedBy = "1";
this.updatedOn = new Timestamp(System.currentTimeMillis());
}
}
public void setId(String id) {
this.id = id;
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public String getDomainId() {
return domainId;
}
public void setDomainId(String domainId) {
this.domainId = domainId;
}
public String getCredits() {
public Integer getCredits() {
return credits;
}
public void setCredits(String credits) {
public void setCredits(Integer credits) {
this.credits = credits;
}
public String getBalance() {
public Integer getBalance() {
return balance;
}
public void setBalance(String balance) {
public void setBalance(Integer balance) {
this.balance = balance;
}
@ -131,5 +100,4 @@ public class QuotaCreditsResponse extends BaseResponse {
}
}

View File

@ -0,0 +1,49 @@
//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.api.response;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
public class QuotaRefreshResponse extends BaseResponse {
@SerializedName("result")
@Param(description = "Execution result for the quota refresh command")
private String result;
public QuotaRefreshResponse() {
super();
// TODO Auto-generated constructor stub
}
public QuotaRefreshResponse(String result) {
super();
this.result = result;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}

View File

@ -24,6 +24,10 @@ import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.command.ListQuotaConfigurationsCmd;
import org.apache.cloudstack.api.command.QuotaCreditsCmd;
import org.apache.cloudstack.api.command.QuotaEmailTemplateAddCmd;
import org.apache.cloudstack.api.command.QuotaRefreshCmd;
import org.apache.cloudstack.api.command.QuotaStatementCmd;
import org.apache.cloudstack.api.response.QuotaConfigurationResponse;
import org.apache.cloudstack.api.response.QuotaCreditsResponse;
import org.apache.cloudstack.quota.dao.QuotaConfigurationDao;
@ -32,6 +36,7 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.utils.Pair;
import com.cloud.utils.db.TransactionLegacy;
@Component
@Local(value = QuotaManager.class)
@ -59,12 +64,17 @@ private QuotaCreditsDao _quotaCreditsDao;
public List<Class<?>> getCommands() {
final List<Class<?>> cmdList = new ArrayList<Class<?>>();
cmdList.add(ListQuotaConfigurationsCmd.class);
cmdList.add(QuotaCreditsCmd.class);
cmdList.add(QuotaEmailTemplateAddCmd.class);
cmdList.add(QuotaRefreshCmd.class);
cmdList.add(QuotaStatementCmd.class);
return cmdList;
}
@Override
public Pair<List<QuotaConfigurationVO>, Integer> listConfigurations(final ListQuotaConfigurationsCmd cmd) {
final Pair<List<QuotaConfigurationVO>, Integer> result = _quotaConfigurationDao.searchConfigurations();
TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
return result;
}
@ -83,10 +93,17 @@ private QuotaCreditsDao _quotaCreditsDao;
@Override
public QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId, Integer amount, Long updatedBy) {
QuotaCreditsVO credits = new QuotaCreditsVO(accountId, domainId, amount, updatedBy);
credits.setUpdatedOn(new Date());
_quotaCreditsDao.persist(credits);
return null;
QuotaCreditsVO result=null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
try {
QuotaCreditsVO credits = new QuotaCreditsVO(accountId, domainId, amount, updatedBy);
credits.setUpdatedOn(new Date());
result = _quotaCreditsDao.persist(credits);
} finally {
txn.close();
}
TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
return new QuotaCreditsResponse(result);
}

View File

@ -27,6 +27,7 @@ import com.cloud.utils.Pair;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.TransactionLegacy;
@Component
@Local(value = {QuotaConfigurationDao.class})
@ -54,9 +55,14 @@ public class QuotaConfigurationDaoImpl extends GenericDaoBase<QuotaConfiguration
@Override
public Pair<List<QuotaConfigurationVO>, Integer> searchConfigurations() {
final SearchCriteria<QuotaConfigurationVO> sc = listAllIncludedUsageType.create();
sc.setParameters("include", 1);
return searchAndCount(sc, null);
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
try {
final SearchCriteria<QuotaConfigurationVO> sc = listAllIncludedUsageType.create();
sc.setParameters("include", 1);
return searchAndCount(sc, null);
} finally {
txn.close();
}
}

View File

@ -114,6 +114,7 @@ CREATE TABLE `cloud_usage.quota_email_templates` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`template_name` varchar(64) DEFAULT NULL,
`template_text` longtext,
`category` int(10) unsigned NOT NULL DEFAULT '0',
`last_updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`locale` varchar(25) DEFAULT 'en_US',
`version` int(11) DEFAULT '0',