@Override public void onPublishMessage(String senderAddress, String subject, Object args) { try { final Account account = accountDao.findByIdIncludingRemoved((Long) args); if(!removeUserAccount(account)) { LOG.warn(String.format("Failed to remove account to Cloudian while removing CloudStack account=%s, id=%s", account.getAccountName(), account.getId())); } } catch (final Exception e) { LOG.error("Caught exception while removing account in Cloudian: ", e); } } });
public String getAccountName() { if (accountName != null) { return accountName; } else { return CallContext.current().getCallingAccount().getAccountName(); } }
public String getAccountName() { if (accountName == null) { return CallContext.current().getCallingAccount().getAccountName(); } return accountName; }
public String getAccountName() { if (accountName == null) { return CallContext.current().getCallingAccount().getAccountName(); } return accountName; }
public String getAccountName() { if (accountName != null) { return accountName; } return CallContext.current().getCallingAccount().getAccountName(); }
@Override public void onPublishMessage(String senderAddress, String subject, Object args) { try { final Map<Long, Long> accountGroupMap = (Map<Long, Long>) args; final Long accountId = accountGroupMap.keySet().iterator().next(); final Account account = accountDao.findById(accountId); final Domain domain = domainDao.findById(account.getDomainId()); if (!addUserAccount(account, domain)) { LOG.warn(String.format("Failed to add account in Cloudian while adding CloudStack account=%s in domain=%s", account.getAccountName(), domain.getPath())); } } catch (final Exception e) { LOG.error("Caught exception while adding account in Cloudian: ", e); } } });
public String getAccountName() { return CallContext.current().getCallingAccount().getAccountName(); }
public String getAccountName() { return CallContext.current().getCallingAccount().getAccountName(); }
public String getAccountName() { return CallContext.current().getCallingAccount().getAccountName(); }
private void checkAccountResourceLimit(final Account account, final Project project, final ResourceType type, long numResources) throws ResourceAllocationException { // Check account limits long accountResourceLimit = findCorrectResourceLimitForAccount(account, type); long currentResourceCount = _resourceCountDao.getResourceCount(account.getId(), ResourceOwnerType.Account, type); long requestedResourceCount = currentResourceCount + numResources; String messageSuffix = " amount of resources of Type = '" + type + "' for " + (project == null ? "Account Name = " + account.getAccountName() : "Project Name = " + project.getName()) + " in Domain Id = " + account.getDomainId() + " is exceeded: Account Resource Limit = " + accountResourceLimit + ", Current Account Resource Amount = " + currentResourceCount + ", Requested Resource Amount = " + numResources + "."; if (s_logger.isDebugEnabled()) { s_logger.debug("Checking if" + messageSuffix); } if (accountResourceLimit != Resource.RESOURCE_UNLIMITED && requestedResourceCount > accountResourceLimit) { String message = "Maximum" + messageSuffix; ResourceAllocationException e = new ResourceAllocationException(message, type); s_logger.error(message, e); throw e; } }
private void populateAccount(ControlledEntityResponse response, long accountId) { Account account = ApiDBUtils.findAccountById(accountId); if (account == null) { s_logger.debug("Unable to find account with id: " + accountId); } else if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) { // find the project Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId()); if (project != null) { response.setProjectId(project.getUuid()); response.setProjectName(project.getName()); response.setAccountName(account.getAccountName()); } else { s_logger.debug("Unable to find project with id: " + account.getId()); } } else { response.setAccountName(account.getAccountName()); } }
@Override public SecurityGroupVO createDefaultSecurityGroup(Long accountId) { SecurityGroupVO groupVO = _securityGroupDao.findByAccountAndName(accountId, SecurityGroupManager.DEFAULT_GROUP_NAME); if (groupVO == null) { Account accVO = _accountDao.findById(accountId); if (accVO != null) { return createSecurityGroup(SecurityGroupManager.DEFAULT_GROUP_NAME, SecurityGroupManager.DEFAULT_GROUP_DESCRIPTION, accVO.getDomainId(), accVO.getId(), accVO.getAccountName()); } } return groupVO; }
private boolean updateUserAccount(final Account account, final Domain domain, final CloudianUser existingUser) { if (account == null || domain == null || !isEnabled()) { return false; } final CloudianClient client = getClient(); if (existingUser != null) { final User accountUser = userDao.listByAccount(account.getId()).get(0); final String fullName = String.format("%s %s (%s)", accountUser.getFirstname(), accountUser.getLastname(), account.getAccountName()); if (!existingUser.getActive() || !existingUser.getFullName().equals(fullName) || !existingUser.getEmailAddr().equals(accountUser.getEmail())) { existingUser.setActive(true); existingUser.setFullName(fullName); existingUser.setEmailAddr(accountUser.getEmail()); return client.updateUser(existingUser); } return true; } return false; }
@Override public void execute() { Account caller = CallContext.current().getCallingAccount(); List<QuotaSummaryResponse> responses; if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN) { //admin account if (getAccountName() != null && getDomainId() != null) responses = _responseBuilder.createQuotaSummaryResponse(caller.getAccountName(), caller.getDomainId()); else responses = _responseBuilder.createQuotaSummaryResponse(isListAll()); } else { responses = _responseBuilder.createQuotaSummaryResponse(caller.getAccountName(), caller.getDomainId()); } final ListResponse<QuotaSummaryResponse> response = new ListResponse<QuotaSummaryResponse>(); response.setResponses(responses); response.setResponseName(getCommandName()); setResponseObject(response); }
private boolean addUserAccount(final Account account, final Domain domain) { if (account == null || domain == null || !isEnabled()) { return false; } final User accountUser = userDao.listByAccount(account.getId()).get(0); final CloudianClient client = getClient(); final String fullName = String.format("%s %s (%s)", accountUser.getFirstname(), accountUser.getLastname(), account.getAccountName()); final CloudianUser user = new CloudianUser(); user.setUserId(account.getUuid()); user.setGroupId(domain.getUuid()); user.setFullName(fullName); user.setEmailAddr(accountUser.getEmail()); user.setUserType(CloudianUser.USER); user.setActive(true); return client.addUser(user); }
@Override public ServiceInstanceResponse createServiceInstanceResponse(long instanceId) { s_logger.debug("ServiceInstance response for id: " + instanceId); UserVmVO vm = _vmDao.findById(instanceId); ServiceInstanceResponse response = new ServiceInstanceResponse(); response.setId(vm.getUuid()); Account owner = _accountService.getAccount(vm.getAccountId()); if (owner.getType() == Account.ACCOUNT_TYPE_PROJECT) { Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(owner.getAccountId()); response.setProjectId(project.getUuid()); response.setProjectName(project.getName()); } else { response.setAccountName(owner.getAccountName()); } return response; }
private void populateOwner(ControlledEntityResponse response, ControlledEntity object) { Account account = ApiDBUtils.findAccountById(object.getAccountId()); if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) { // find the project Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId()); response.setProjectId(project.getUuid()); response.setProjectName(project.getName()); } else { response.setAccountName(account.getAccountName()); } Domain domain = ApiDBUtils.findDomainById(object.getDomainId()); response.setDomainId(domain.getUuid()); response.setDomainName(domain.getName()); }
@Override public SSHKeyPairResponse createSSHKeyPairResponse(SSHKeyPair sshkeyPair, boolean privatekey) { SSHKeyPairResponse response = new SSHKeyPairResponse(sshkeyPair.getName(), sshkeyPair.getFingerprint()); if (privatekey) { response = new CreateSSHKeyPairResponse(sshkeyPair.getName(), sshkeyPair.getFingerprint(), sshkeyPair.getPrivateKey()); } Account account = ApiDBUtils.findAccountById(sshkeyPair.getAccountId()); response.setAccountName(account.getAccountName()); Domain domain = ApiDBUtils.findDomainById(sshkeyPair.getDomainId()); response.setDomainId(domain.getUuid()); response.setDomainName(domain.getName()); return response; } }
@Override @ActionEvent(eventType = EventTypes.EVENT_SECURITY_GROUP_CREATE, eventDescription = "creating security group") public SecurityGroupVO createSecurityGroup(CreateSecurityGroupCmd cmd) throws PermissionDeniedException, InvalidParameterValueException { String name = cmd.getSecurityGroupName(); Account caller = CallContext.current().getCallingAccount(); Account owner = _accountMgr.finalizeOwner(caller, cmd.getAccountName(), cmd.getDomainId(), cmd.getProjectId()); if (_securityGroupDao.isNameInUse(owner.getId(), owner.getDomainId(), cmd.getSecurityGroupName())) { throw new InvalidParameterValueException("Unable to create security group, a group with name " + name + " already exists."); } return createSecurityGroup(cmd.getSecurityGroupName(), cmd.getDescription(), owner.getDomainId(), owner.getAccountId(), owner.getAccountName()); }
@Override public AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group) { AffinityGroupResponse response = new AffinityGroupResponse(); Account account = ApiDBUtils.findAccountById(group.getAccountId()); response.setId(group.getUuid()); response.setAccountName(account.getAccountName()); response.setName(group.getName()); response.setType(group.getType()); response.setDescription(group.getDescription()); Domain domain = ApiDBUtils.findDomainById(account.getDomainId()); if (domain != null) { response.setDomainId(domain.getUuid()); response.setDomainName(domain.getName()); } response.setObjectName("affinitygroup"); return response; }