mirror of https://github.com/apache/cloudstack.git
bug 11036: if resource_count record is missing for account or domain, insert it during the management server startup (with count=0)
status 11036: resolved fixed
This commit is contained in:
parent
f071ce571c
commit
569427ba1f
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package com.cloud.configuration.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cloud.configuration.ResourceCount.ResourceType;
|
||||
|
|
@ -80,4 +81,11 @@ public interface ResourceCountDao extends GenericDao<ResourceCountVO, Long> {
|
|||
|
||||
void createResourceCounts(long ownerId, OwnerType ownerType);
|
||||
|
||||
List<ResourceCountVO> listByDomainId(long domainId);
|
||||
|
||||
List<ResourceCountVO> listByAccountId(long accountId);
|
||||
|
||||
List<ResourceCountVO> listDomainCounts();
|
||||
|
||||
List<ResourceCountVO> listAccountCounts();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package com.cloud.configuration.dao;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
|
@ -37,26 +38,37 @@ import com.cloud.utils.db.Transaction;
|
|||
|
||||
@Local(value={ResourceCountDao.class})
|
||||
public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long> implements ResourceCountDao {
|
||||
private SearchBuilder<ResourceCountVO> IdTypeSearch;
|
||||
private SearchBuilder<ResourceCountVO> DomainIdTypeSearch;
|
||||
private SearchBuilder<ResourceCountVO> AccountTypeSearch;
|
||||
private SearchBuilder<ResourceCountVO> DomainTypeSearch;
|
||||
|
||||
private SearchBuilder<ResourceCountVO> AccountSearch;
|
||||
private SearchBuilder<ResourceCountVO> DomainSearch;
|
||||
|
||||
protected final DomainDaoImpl _domainDao = ComponentLocator.inject(DomainDaoImpl.class);
|
||||
|
||||
public ResourceCountDaoImpl() {
|
||||
IdTypeSearch = createSearchBuilder();
|
||||
IdTypeSearch.and("type", IdTypeSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
IdTypeSearch.and("accountId", IdTypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||
IdTypeSearch.done();
|
||||
AccountTypeSearch = createSearchBuilder();
|
||||
AccountTypeSearch.and("type", AccountTypeSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
AccountTypeSearch.and("accountId", AccountTypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||
AccountTypeSearch.done();
|
||||
|
||||
DomainIdTypeSearch = createSearchBuilder();
|
||||
DomainIdTypeSearch.and("type", DomainIdTypeSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
DomainIdTypeSearch.and("domainId", DomainIdTypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
DomainIdTypeSearch.done();
|
||||
DomainTypeSearch = createSearchBuilder();
|
||||
DomainTypeSearch.and("type", DomainTypeSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
DomainTypeSearch.and("domainId", DomainTypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
DomainTypeSearch.done();
|
||||
|
||||
AccountSearch = createSearchBuilder();
|
||||
AccountSearch.and("accountId", AccountSearch.entity().getAccountId(), SearchCriteria.Op.NNULL);
|
||||
AccountSearch.done();
|
||||
|
||||
DomainSearch = createSearchBuilder();
|
||||
DomainSearch.and("domainId", DomainSearch.entity().getDomainId(), SearchCriteria.Op.NNULL);
|
||||
DomainSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceCountVO findByAccountIdAndType(long accountId, ResourceType type) {
|
||||
SearchCriteria<ResourceCountVO> sc = IdTypeSearch.create();
|
||||
SearchCriteria<ResourceCountVO> sc = AccountTypeSearch.create();
|
||||
sc.setParameters("accountId", accountId);
|
||||
sc.setParameters("type", type);
|
||||
|
||||
|
|
@ -65,7 +77,7 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
|
|||
|
||||
@Override
|
||||
public ResourceCountVO findByDomainIdAndType(long domainId, ResourceType type) {
|
||||
SearchCriteria<ResourceCountVO> sc = DomainIdTypeSearch.create();
|
||||
SearchCriteria<ResourceCountVO> sc = DomainTypeSearch.create();
|
||||
sc.setParameters("domainId", domainId);
|
||||
sc.setParameters("type", type);
|
||||
|
||||
|
|
@ -166,4 +178,34 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
|
|||
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceCountVO> listByDomainId(long domainId) {
|
||||
SearchCriteria<ResourceCountVO> sc = DomainTypeSearch.create();
|
||||
sc.setParameters("domainId", domainId);
|
||||
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceCountVO> listByAccountId(long accountId) {
|
||||
SearchCriteria<ResourceCountVO> sc = AccountTypeSearch.create();
|
||||
sc.setParameters("accountId", accountId);
|
||||
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceCountVO> listDomainCounts() {
|
||||
SearchCriteria<ResourceCountVO> sc = DomainSearch.create();
|
||||
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceCountVO> listAccountCounts() {
|
||||
SearchCriteria<ResourceCountVO> sc = AccountSearch.create();
|
||||
|
||||
return listBy(sc);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ import java.security.NoSuchAlgorithmException;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
|
@ -47,6 +48,9 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationVO;
|
||||
import com.cloud.configuration.ResourceCount;
|
||||
import com.cloud.configuration.ResourceCount.ResourceType;
|
||||
import com.cloud.configuration.ResourceCountVO;
|
||||
import com.cloud.configuration.ResourceLimit.OwnerType;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.configuration.dao.ResourceCountDao;
|
||||
|
|
@ -250,6 +254,8 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
|||
txn.commit();
|
||||
}
|
||||
|
||||
updateResourceCount();
|
||||
|
||||
// keystore for SSL/TLS connection
|
||||
updateSSLKeystore();
|
||||
|
||||
|
|
@ -980,4 +986,56 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
|||
txn.commit();
|
||||
}
|
||||
|
||||
private void updateResourceCount() {
|
||||
ResourceType[] resourceTypes = ResourceCount.ResourceType.values();
|
||||
List<AccountVO> accounts = _accountDao.listAllIncludingRemoved();
|
||||
List<DomainVO> domains = _domainDao.listAllIncludingRemoved();
|
||||
List<ResourceCountVO> domainResourceCount = _resourceCountDao.listDomainCounts();
|
||||
List<ResourceCountVO> accountResourceCount = _resourceCountDao.listAccountCounts();
|
||||
|
||||
int resourceCount = resourceTypes.length;
|
||||
|
||||
if ((domainResourceCount.size() < resourceCount * domains.size())) {
|
||||
s_logger.debug("resource_count table has records missing for some domains...going to insert them");
|
||||
for (DomainVO domain : domains) {
|
||||
List<ResourceCountVO> domainCounts = _resourceCountDao.listByDomainId(domain.getId());
|
||||
List<String> domainCountStr = new ArrayList<String>();
|
||||
for (ResourceCountVO domainCount : domainCounts) {
|
||||
domainCountStr.add(domainCount.getType().toString());
|
||||
}
|
||||
|
||||
if (domainCountStr.size() < resourceCount) {
|
||||
for (ResourceType resourceType : resourceTypes) {
|
||||
if (!domainCountStr.contains(resourceType.toString())) {
|
||||
ResourceCountVO resourceCountVO = new ResourceCountVO(null, domain.getId(), resourceType, 0);
|
||||
s_logger.debug("Inserting resource count of type " + resourceType + " for domain id=" + domain.getId());
|
||||
_resourceCountDao.persist(resourceCountVO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((accountResourceCount.size() < resourceTypes.length * accounts.size())) {
|
||||
s_logger.debug("resource_count table has records missing for some accounts...going to insert them");
|
||||
for (AccountVO account : accounts) {
|
||||
List<ResourceCountVO> accountCounts = _resourceCountDao.listByAccountId(account.getId());
|
||||
List<String> accountCountStr = new ArrayList<String>();
|
||||
for (ResourceCountVO accountCount : accountCounts) {
|
||||
accountCountStr.add(accountCount.getType().toString());
|
||||
}
|
||||
|
||||
if (accountCountStr.size() < resourceCount) {
|
||||
for (ResourceType resourceType : resourceTypes) {
|
||||
if (!accountCountStr.contains(resourceType.toString())) {
|
||||
ResourceCountVO resourceCountVO = new ResourceCountVO(account.getId(), null, resourceType, 0);
|
||||
s_logger.debug("Inserting resource count of type " + resourceType + " for account id=" + account.getId());
|
||||
_resourceCountDao.persist(resourceCountVO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package com.cloud.servlet;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
|
|
@ -29,10 +31,6 @@ import com.cloud.server.ConfigurationServer;
|
|||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.utils.SerialVersionUID;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.SystemIntegrityChecker;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
public class CloudStartupServlet extends HttpServlet implements ServletContextListener {
|
||||
public static final Logger s_logger = Logger.getLogger(CloudStartupServlet.class.getName());
|
||||
|
|
|
|||
Loading…
Reference in New Issue