Search in sources :

Example 16 with ResourceTagJoinVO

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;
}
Also used : ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) SecurityGroupRuleResponse(org.apache.cloudstack.api.response.SecurityGroupRuleResponse) SecurityGroupJoinVO(com.cloud.api.query.vo.SecurityGroupJoinVO) HashSet(java.util.HashSet)

Example 17 with ResourceTagJoinVO

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;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) SecurityGroupResponse(org.apache.cloudstack.api.response.SecurityGroupResponse) SecurityGroupRuleResponse(org.apache.cloudstack.api.response.SecurityGroupRuleResponse) SecurityGroupJoinVO(com.cloud.api.query.vo.SecurityGroupJoinVO) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) SecurityGroupVMMapVO(com.cloud.network.security.SecurityGroupVMMapVO) HashSet(java.util.HashSet)

Example 18 with ResourceTagJoinVO

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;
}
Also used : Account(com.cloud.user.Account) ProjectAccount(com.cloud.projects.ProjectAccount) User(com.cloud.user.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProjectAccount(com.cloud.projects.ProjectAccount) ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) ProjectAccountVO(com.cloud.projects.ProjectAccountVO) HashMap(java.util.HashMap) Map(java.util.Map) AccountJoinVO(com.cloud.api.query.vo.AccountJoinVO)

Example 19 with ResourceTagJoinVO

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;
}
Also used : Account(com.cloud.user.Account) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) ProjectVO(com.cloud.projects.ProjectVO) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)19 Account (com.cloud.user.Account)9 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 AccountJoinVO (com.cloud.api.query.vo.AccountJoinVO)3 TemplateResponse (com.cloud.api.response.TemplateResponse)3 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)3 AffinityGroupResponse (com.cloud.affinity.AffinityGroupResponse)2 SecurityGroupJoinVO (com.cloud.api.query.vo.SecurityGroupJoinVO)2 NicResponse (com.cloud.api.response.NicResponse)2 NicSecondaryIpResponse (com.cloud.api.response.NicSecondaryIpResponse)2 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)2 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)2 User (com.cloud.user.User)2 Ternary (com.cloud.utils.Ternary)2 Filter (com.cloud.utils.db.Filter)2 NicSecondaryIpVO (com.cloud.vm.dao.NicSecondaryIpVO)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ChildTemplateResponse (org.apache.cloudstack.api.response.ChildTemplateResponse)2