use of com.cloud.domain.DomainVO in project cloudstack by apache.
the class CertServiceTest method runUploadSslCertExpiredCert.
@Test
public void runUploadSslCertExpiredCert() throws IOException, IllegalAccessException, NoSuchFieldException {
// Reading appropritate files
final String certFile = URLDecoder.decode(getClass().getResource("/certs/expired_cert.crt").getFile(), Charset.defaultCharset().name());
final String keyFile = URLDecoder.decode(getClass().getResource("/certs/rsa_self_signed.key").getFile(), Charset.defaultCharset().name());
final String cert = readFileToString(new File(certFile));
final String key = readFileToString(new File(keyFile));
final CertServiceImpl certService = new CertServiceImpl();
// setting mock objects
certService._accountMgr = Mockito.mock(AccountManager.class);
final Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(certService._accountMgr.getAccount(anyLong())).thenReturn(account);
certService._domainDao = Mockito.mock(DomainDao.class);
final DomainVO domain = new DomainVO("networkdomain", 1L, 1L, "networkdomain");
when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain);
certService._sslCertDao = Mockito.mock(SslCertDao.class);
when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO());
// creating the command
final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn();
final Class<?> klazz = uploadCmd.getClass().getSuperclass();
final Field certField = klazz.getDeclaredField("cert");
certField.setAccessible(true);
certField.set(uploadCmd, cert);
final Field keyField = klazz.getDeclaredField("key");
keyField.setAccessible(true);
keyField.set(uploadCmd, key);
try {
certService.uploadSslCert(uploadCmd);
Assert.fail("Given an expired certificate, upload should fail");
} catch (final Exception e) {
System.out.println(e.getMessage());
Assert.assertTrue(e.getMessage().contains("Parsing certificate/key failed: NotAfter:"));
}
}
use of com.cloud.domain.DomainVO in project cloudstack by apache.
the class ConfigurationServerImpl method updateResourceCount.
@DB
public void updateResourceCount() {
ResourceType[] resourceTypes = Resource.ResourceType.values();
List<AccountVO> accounts = _accountDao.listAll();
List<DomainVO> domains = _domainDao.listAll();
List<ResourceCountVO> domainResourceCount = _resourceCountDao.listResourceCountByOwnerType(ResourceOwnerType.Domain);
List<ResourceCountVO> accountResourceCount = _resourceCountDao.listResourceCountByOwnerType(ResourceOwnerType.Account);
final List<ResourceType> accountSupportedResourceTypes = new ArrayList<ResourceType>();
final List<ResourceType> domainSupportedResourceTypes = new ArrayList<ResourceType>();
for (ResourceType resourceType : resourceTypes) {
if (resourceType.supportsOwner(ResourceOwnerType.Account)) {
accountSupportedResourceTypes.add(resourceType);
}
if (resourceType.supportsOwner(ResourceOwnerType.Domain)) {
domainSupportedResourceTypes.add(resourceType);
}
}
final int accountExpectedCount = accountSupportedResourceTypes.size();
final int domainExpectedCount = domainSupportedResourceTypes.size();
if ((domainResourceCount.size() < domainExpectedCount * domains.size())) {
s_logger.debug("resource_count table has records missing for some domains...going to insert them");
for (final DomainVO domain : domains) {
// Lock domain
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
_domainDao.lockRow(domain.getId(), true);
List<ResourceCountVO> domainCounts = _resourceCountDao.listByOwnerId(domain.getId(), ResourceOwnerType.Domain);
List<String> domainCountStr = new ArrayList<String>();
for (ResourceCountVO domainCount : domainCounts) {
domainCountStr.add(domainCount.getType().toString());
}
if (domainCountStr.size() < domainExpectedCount) {
for (ResourceType resourceType : domainSupportedResourceTypes) {
if (!domainCountStr.contains(resourceType.toString())) {
ResourceCountVO resourceCountVO = new ResourceCountVO(resourceType, 0, domain.getId(), ResourceOwnerType.Domain);
s_logger.debug("Inserting resource count of type " + resourceType + " for domain id=" + domain.getId());
_resourceCountDao.persist(resourceCountVO);
}
}
}
}
});
}
}
if ((accountResourceCount.size() < accountExpectedCount * accounts.size())) {
s_logger.debug("resource_count table has records missing for some accounts...going to insert them");
for (final AccountVO account : accounts) {
// lock account
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
_accountDao.lockRow(account.getId(), true);
List<ResourceCountVO> accountCounts = _resourceCountDao.listByOwnerId(account.getId(), ResourceOwnerType.Account);
List<String> accountCountStr = new ArrayList<String>();
for (ResourceCountVO accountCount : accountCounts) {
accountCountStr.add(accountCount.getType().toString());
}
if (accountCountStr.size() < accountExpectedCount) {
for (ResourceType resourceType : accountSupportedResourceTypes) {
if (!accountCountStr.contains(resourceType.toString())) {
ResourceCountVO resourceCountVO = new ResourceCountVO(resourceType, 0, account.getId(), ResourceOwnerType.Account);
s_logger.debug("Inserting resource count of type " + resourceType + " for account id=" + account.getId());
_resourceCountDao.persist(resourceCountVO);
}
}
}
}
});
}
}
}
use of com.cloud.domain.DomainVO in project cloudstack by apache.
the class ResourceLimitManagerImpl method recalculateResourceCount.
@Override
public List<ResourceCountVO> recalculateResourceCount(Long accountId, Long domainId, Integer typeId) throws InvalidParameterValueException, CloudRuntimeException, PermissionDeniedException {
Account callerAccount = CallContext.current().getCallingAccount();
long count = 0;
List<ResourceCountVO> counts = new ArrayList<ResourceCountVO>();
List<ResourceType> resourceTypes = new ArrayList<ResourceType>();
ResourceType resourceType = null;
if (typeId != null) {
for (ResourceType type : Resource.ResourceType.values()) {
if (type.getOrdinal() == typeId.intValue()) {
resourceType = type;
}
}
if (resourceType == null) {
throw new InvalidParameterValueException("Please specify valid resource type");
}
}
DomainVO domain = _domainDao.findById(domainId);
if (domain == null) {
throw new InvalidParameterValueException("Please specify a valid domain ID.");
}
_accountMgr.checkAccess(callerAccount, domain);
if (resourceType != null) {
resourceTypes.add(resourceType);
} else {
resourceTypes = Arrays.asList(Resource.ResourceType.values());
}
for (ResourceType type : resourceTypes) {
if (accountId != null) {
if (type.supportsOwner(ResourceOwnerType.Account)) {
count = recalculateAccountResourceCount(accountId, type);
counts.add(new ResourceCountVO(type, count, accountId, ResourceOwnerType.Account));
}
} else {
if (type.supportsOwner(ResourceOwnerType.Domain)) {
count = recalculateDomainResourceCount(domainId, type);
counts.add(new ResourceCountVO(type, count, domainId, ResourceOwnerType.Domain));
}
}
}
return counts;
}
use of com.cloud.domain.DomainVO in project cloudstack by apache.
the class ManagementServerImpl method deleteEvents.
@Override
public boolean deleteEvents(final DeleteEventsCmd cmd) {
final Account caller = getCaller();
final List<Long> ids = cmd.getIds();
boolean result = true;
List<Long> permittedAccountIds = new ArrayList<Long>();
if (_accountMgr.isNormalUser(caller.getId()) || caller.getType() == Account.ACCOUNT_TYPE_PROJECT) {
permittedAccountIds.add(caller.getId());
} else {
final DomainVO domain = _domainDao.findById(caller.getDomainId());
final List<Long> permittedDomainIds = _domainDao.getDomainChildrenIds(domain.getPath());
permittedAccountIds = _accountDao.getAccountIdsForDomains(permittedDomainIds);
}
final List<EventVO> events = _eventDao.listToArchiveOrDeleteEvents(ids, cmd.getType(), cmd.getStartDate(), cmd.getEndDate(), permittedAccountIds);
final ControlledEntity[] sameOwnerEvents = events.toArray(new ControlledEntity[events.size()]);
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, false, sameOwnerEvents);
if (ids != null && events.size() < ids.size()) {
result = false;
return result;
}
for (final EventVO event : events) {
_eventDao.remove(event.getId());
}
return result;
}
use of com.cloud.domain.DomainVO in project cloudstack by apache.
the class AssignLoadBalancerTest method setUp.
@Before
public void setUp() {
assignToLbRuleCmd = new AssignToLoadBalancerRuleCmd() {
};
// ComponentContext.initComponentsLifeCycle();
AccountVO account = new AccountVO(accountName, domainId, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
DomainVO domain = new DomainVO("rootDomain", 5L, 5L, "networkDomain");
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
}
Aggregations