use of com.cloud.api.query.vo.ResourceTagJoinVO in project cloudstack by apache.
the class SecurityGroupJoinDaoImpl method setSecurityGroupResponse.
@Override
public SecurityGroupResponse setSecurityGroupResponse(SecurityGroupResponse vsgData, SecurityGroupJoinVO vsg) {
Long rule_id = vsg.getRuleId();
if (rule_id != null && rule_id.longValue() > 0) {
SecurityGroupRuleResponse ruleData = new SecurityGroupRuleResponse();
ruleData.setRuleId(vsg.getRuleUuid());
ruleData.setProtocol(vsg.getRuleProtocol());
if ("icmp".equalsIgnoreCase(vsg.getRuleProtocol())) {
ruleData.setIcmpType(vsg.getRuleStartPort());
ruleData.setIcmpCode(vsg.getRuleEndPort());
} else {
ruleData.setStartPort(vsg.getRuleStartPort());
ruleData.setEndPort(vsg.getRuleEndPort());
}
if (vsg.getRuleAllowedNetworkId() != null) {
List<SecurityGroupJoinVO> sgs = this.searchByIds(vsg.getRuleAllowedNetworkId());
if (sgs != null && sgs.size() > 0) {
SecurityGroupJoinVO sg = sgs.get(0);
ruleData.setSecurityGroupName(sg.getName());
ruleData.setAccountName(sg.getAccountName());
}
} else {
ruleData.setCidr(vsg.getRuleAllowedSourceIpCidr());
}
// add the tags to the rule data
List<ResourceTagJoinVO> tags = _resourceTagJoinDao.listBy(vsg.getRuleUuid(), ResourceTag.ResourceObjectType.SecurityGroupRule);
Set<ResourceTagResponse> tagResponse = new HashSet<ResourceTagResponse>();
for (ResourceTagJoinVO tag : tags) {
tagResponse.add(ApiDBUtils.newResourceTagResponse(tag, false));
}
// add the tags to the rule data
ruleData.setTags(tagResponse);
if (vsg.getRuleType() == SecurityRuleType.IngressRule) {
ruleData.setObjectName("ingressrule");
vsgData.addSecurityGroupIngressRule(ruleData);
} else {
ruleData.setObjectName("egressrule");
vsgData.addSecurityGroupEgressRule(ruleData);
}
}
// update tag information
Long tag_id = vsg.getTagId();
if (tag_id != null && tag_id.longValue() > 0) {
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
if (vtag != null) {
vsgData.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
}
}
return vsgData;
}
use of com.cloud.api.query.vo.ResourceTagJoinVO in project cloudstack by apache.
the class SecurityGroupJoinDaoImpl method newSecurityGroupResponse.
@Override
public SecurityGroupResponse newSecurityGroupResponse(SecurityGroupJoinVO vsg, Account caller) {
SecurityGroupResponse sgResponse = new SecurityGroupResponse();
sgResponse.setId(vsg.getUuid());
sgResponse.setName(vsg.getName());
sgResponse.setDescription(vsg.getDescription());
ApiResponseHelper.populateOwner(sgResponse, vsg);
Long rule_id = vsg.getRuleId();
if (rule_id != null && rule_id.longValue() > 0) {
SecurityGroupRuleResponse ruleData = new SecurityGroupRuleResponse();
ruleData.setRuleId(vsg.getRuleUuid());
ruleData.setProtocol(vsg.getRuleProtocol());
if ("icmp".equalsIgnoreCase(vsg.getRuleProtocol())) {
ruleData.setIcmpType(vsg.getRuleStartPort());
ruleData.setIcmpCode(vsg.getRuleEndPort());
} else {
ruleData.setStartPort(vsg.getRuleStartPort());
ruleData.setEndPort(vsg.getRuleEndPort());
}
if (vsg.getRuleAllowedNetworkId() != null) {
List<SecurityGroupJoinVO> sgs = this.searchByIds(vsg.getRuleAllowedNetworkId());
if (sgs != null && sgs.size() > 0) {
SecurityGroupJoinVO sg = sgs.get(0);
ruleData.setSecurityGroupName(sg.getName());
ruleData.setAccountName(sg.getAccountName());
}
} else {
ruleData.setCidr(vsg.getRuleAllowedSourceIpCidr());
}
// list the tags by rule uuid
List<ResourceTagJoinVO> tags = _resourceTagJoinDao.listBy(vsg.getRuleUuid(), ResourceTag.ResourceObjectType.SecurityGroupRule);
Set<ResourceTagResponse> tagResponse = new HashSet<ResourceTagResponse>();
for (ResourceTagJoinVO tag : tags) {
tagResponse.add(ApiDBUtils.newResourceTagResponse(tag, false));
}
// add the tags to the rule data
ruleData.setTags(tagResponse);
if (vsg.getRuleType() == SecurityRuleType.IngressRule) {
ruleData.setObjectName("ingressrule");
sgResponse.addSecurityGroupIngressRule(ruleData);
} else {
ruleData.setObjectName("egressrule");
sgResponse.addSecurityGroupEgressRule(ruleData);
}
}
List<SecurityGroupVMMapVO> securityGroupVmMap = _securityGroupVMMapDao.listBySecurityGroup(vsg.getId());
s_logger.debug("newSecurityGroupResponse() -> virtualmachine count: " + securityGroupVmMap.size());
sgResponse.setVirtualMachineCount(securityGroupVmMap.size());
for (SecurityGroupVMMapVO securityGroupVMMapVO : securityGroupVmMap) {
final UserVmVO userVmVO = _userVmDao.findById(securityGroupVMMapVO.getInstanceId());
if (userVmVO != null) {
sgResponse.addVirtualMachineId(userVmVO.getUuid());
}
}
// update tag information
Long tag_id = vsg.getTagId();
if (tag_id != null && tag_id.longValue() > 0) {
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
if (vtag != null) {
sgResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
}
}
// set async job
if (vsg.getJobId() != null) {
sgResponse.setJobId(vsg.getJobUuid());
sgResponse.setJobStatus(vsg.getJobStatus());
}
sgResponse.setObjectName("securitygroup");
return sgResponse;
}
use of com.cloud.api.query.vo.ResourceTagJoinVO in project cloudstack by apache.
the class ProjectJoinDaoImpl method newProjectResponse.
@Override
public ProjectResponse newProjectResponse(EnumSet<DomainDetails> details, ProjectJoinVO proj) {
ProjectResponse response = new ProjectResponse();
response.setId(proj.getUuid());
response.setName(proj.getName());
response.setDisplaytext(proj.getDisplayText());
if (proj.getState() != null) {
response.setState(proj.getState().toString());
}
response.setDomainId(proj.getDomainUuid());
response.setDomain(proj.getDomainName());
List<ProjectAccountVO> projectAccounts = projectAccountDao.listByProjectId(proj.getId());
projectAccounts = projectAccounts.stream().filter(projectAccount -> projectAccount.getAccountRole() == ProjectAccount.Role.Admin).collect(Collectors.toList());
List<Map<String, String>> ownersList = new ArrayList<>();
for (ProjectAccount projectAccount : projectAccounts) {
Map<String, String> ownerDetails = new HashMap<>();
if (projectAccount.getUserId() != null) {
User user = userDao.findById(projectAccount.getUserId());
ownerDetails.put("account", _accountDao.findById(projectAccount.getAccountId()).getAccountName());
ownerDetails.put("user", user.getUsername());
ownerDetails.put("userid", user.getUuid());
} else {
ownerDetails.put("account", _accountDao.findById(projectAccount.getAccountId()).getAccountName());
}
ownersList.add(ownerDetails);
}
response.setOwners(ownersList);
response.setCreated(proj.getCreated());
// update tag information
List<ResourceTagJoinVO> tags = ApiDBUtils.listResourceTagViewByResourceUUID(proj.getUuid(), ResourceObjectType.Project);
for (ResourceTagJoinVO vtag : tags) {
response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
}
// set resource limit/count information for the project (by getting the info of the project's account)
Account account = _accountDao.findByIdIncludingRemoved(proj.getProjectAccountId());
if (details.contains(DomainDetails.all) || details.contains(DomainDetails.resource)) {
AccountJoinVO accountJn = ApiDBUtils.newAccountView(account);
_accountJoinDao.setResourceLimits(accountJn, false, response);
}
response.setProjectAccountName(account.getAccountName());
response.setObjectName("project");
return response;
}
use of com.cloud.api.query.vo.ResourceTagJoinVO in project cloudstack by apache.
the class QueryManagerImpl method listTagsInternal.
private Pair<List<ResourceTagJoinVO>, Integer> listTagsInternal(ListTagsCmd cmd) {
Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
String key = cmd.getKey();
String value = cmd.getValue();
String resourceId = cmd.getResourceId();
String resourceType = cmd.getResourceType();
String customerName = cmd.getCustomer();
boolean listAll = cmd.listAll();
Long projectId = cmd.getProjectId();
if (projectId == null && ResourceObjectType.Project.name().equalsIgnoreCase(resourceType) && StringUtils.isNotEmpty(resourceId)) {
try {
projectId = Long.parseLong(resourceId);
} catch (final NumberFormatException e) {
final ProjectVO project = _projectDao.findByUuidIncludingRemoved(resourceId);
if (project != null) {
projectId = project.getId();
}
}
}
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
_accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
Filter searchFilter = new Filter(ResourceTagJoinVO.class, "resourceType", false, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder<ResourceTagJoinVO> sb = _resourceTagJoinDao.createSearchBuilder();
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
sb.and("key", sb.entity().getKey(), SearchCriteria.Op.EQ);
sb.and("value", sb.entity().getValue(), SearchCriteria.Op.EQ);
if (resourceId != null) {
sb.and("resourceId", sb.entity().getResourceId(), SearchCriteria.Op.EQ);
sb.and("resourceUuid", sb.entity().getResourceUuid(), SearchCriteria.Op.EQ);
}
sb.and("resourceType", sb.entity().getResourceType(), SearchCriteria.Op.EQ);
sb.and("customer", sb.entity().getCustomer(), SearchCriteria.Op.EQ);
// now set the SC criteria...
SearchCriteria<ResourceTagJoinVO> sc = sb.create();
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (key != null) {
sc.setParameters("key", key);
}
if (value != null) {
sc.setParameters("value", value);
}
if (resourceId != null) {
try {
long rid = Long.parseLong(resourceId);
sc.setParameters("resourceId", rid);
} catch (NumberFormatException ex) {
// internal id instead of resource id is passed
sc.setParameters("resourceUuid", resourceId);
}
}
if (resourceType != null) {
sc.setParameters("resourceType", resourceType);
}
if (customerName != null) {
sc.setParameters("customer", customerName);
}
Pair<List<ResourceTagJoinVO>, Integer> result = _resourceTagJoinDao.searchAndCount(sc, searchFilter);
return result;
}
Aggregations