Package com.cloud.server.api.response

Examples of com.cloud.server.api.response.UsageRecordResponse


        List<UsageVO> usageRecords = _mgrExt.getUsageRecords(this);
        IdentityDao identityDao = new IdentityDaoImpl();
        ListResponse<UsageRecordResponse> response = new ListResponse<UsageRecordResponse>();
        List<UsageRecordResponse> usageResponses = new ArrayList<UsageRecordResponse>();
        for (Object usageRecordGeneric : usageRecords) {
            UsageRecordResponse usageRecResponse = new UsageRecordResponse();
            if (usageRecordGeneric instanceof UsageVO) {
                UsageVO usageRecord = (UsageVO)usageRecordGeneric;
     
                Account account = ApiDBUtils.findAccountByIdIncludingRemoved(usageRecord.getAccountId());
                if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
                    //find the project
                    Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
                    usageRecResponse.setProjectId(project.getId());
                    usageRecResponse.setProjectName(project.getName());
                } else {
                    usageRecResponse.setAccountId(account.getId());
                    usageRecResponse.setAccountName(account.getAccountName());
                }
            
                usageRecResponse.setDomainId(usageRecord.getDomainId());
               
                usageRecResponse.setZoneId(usageRecord.getZoneId());
                usageRecResponse.setDescription(usageRecord.getDescription());
                usageRecResponse.setUsage(usageRecord.getUsageDisplay());
                usageRecResponse.setUsageType(usageRecord.getUsageType());
                usageRecResponse.setVirtualMachineId(usageRecord.getVmInstanceId());
                usageRecResponse.setVmName(usageRecord.getVmName());
                usageRecResponse.setTemplateId(usageRecord.getTemplateId());
               
                if(usageRecord.getUsageType() == UsageTypes.RUNNING_VM || usageRecord.getUsageType() == UsageTypes.ALLOCATED_VM){
                  //Service Offering Id
                  usageRecResponse.setOfferingId(identityDao.getIdentityUuid("disk_offering", usageRecord.getOfferingId().toString()));
                  //VM Instance ID
                  usageRecResponse.setUsageId(identityDao.getIdentityUuid("vm_instance", usageRecord.getUsageId().toString()));
                  //Hypervisor Type
                  usageRecResponse.setType(usageRecord.getType());
                 
                } else if(usageRecord.getUsageType() == UsageTypes.IP_ADDRESS){
                  //isSourceNAT
                    usageRecResponse.setSourceNat((usageRecord.getType().equals("SourceNat"))?true:false);
                    //isSystem
                    usageRecResponse.setSystem((usageRecord.getSize() == 1)?true:false);
                    //IP Address ID
                    usageRecResponse.setUsageId(identityDao.getIdentityUuid("user_ip_address", usageRecord.getUsageId().toString()));
                   
                } else if(usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_SENT || usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_RECEIVED){
                  //Device Type
                  usageRecResponse.setType(usageRecord.getType());
                  if(usageRecord.getType().equals("DomainRouter")){
                        //Domain Router Id
                        usageRecResponse.setUsageId(identityDao.getIdentityUuid("vm_instance", usageRecord.getUsageId().toString()));
                  } else {
                    //External Device Host Id
                    usageRecResponse.setUsageId(identityDao.getIdentityUuid("host", usageRecord.getUsageId().toString()))
                  }
                    //Network ID
                    usageRecResponse.setNetworkId(identityDao.getIdentityUuid("networks", usageRecord.getNetworkId().toString()));
                   
                } else if(usageRecord.getUsageType() == UsageTypes.VOLUME){
                    //Volume ID
                    usageRecResponse.setUsageId(identityDao.getIdentityUuid("volumes", usageRecord.getUsageId().toString()));
                    //Volume Size
                    usageRecResponse.setSize(usageRecord.getSize());
                  //Disk Offering Id
                    if(usageRecord.getOfferingId() != null){
                      usageRecResponse.setOfferingId(identityDao.getIdentityUuid("disk_offering", usageRecord.getOfferingId().toString()));
                    }

                } else if(usageRecord.getUsageType() == UsageTypes.TEMPLATE || usageRecord.getUsageType() == UsageTypes.ISO){
                    //Template/ISO ID
                    usageRecResponse.setUsageId(identityDao.getIdentityUuid("vm_template", usageRecord.getUsageId().toString()));
                    //Template/ISO Size
                    usageRecResponse.setSize(usageRecord.getSize());
                   
                } else if(usageRecord.getUsageType() == UsageTypes.SNAPSHOT){
                    //Snapshot ID
                    usageRecResponse.setUsageId(identityDao.getIdentityUuid("snapshots", usageRecord.getUsageId().toString()));
                    //Snapshot Size
                    usageRecResponse.setSize(usageRecord.getSize());
                   
                } else if(usageRecord.getUsageType() == UsageTypes.LOAD_BALANCER_POLICY){
                    //Load Balancer Policy ID
                    usageRecResponse.setUsageId(usageRecord.getUsageId().toString());
                   
                } else if(usageRecord.getUsageType() == UsageTypes.PORT_FORWARDING_RULE){
                    //Port Forwarding Rule ID
                    usageRecResponse.setUsageId(usageRecord.getUsageId().toString());
                   
                } else if(usageRecord.getUsageType() == UsageTypes.NETWORK_OFFERING){
                  //Network Offering Id
                  usageRecResponse.setOfferingId(identityDao.getIdentityUuid("network_offerings", usageRecord.getOfferingId().toString()));
                  //is Default
                  usageRecResponse.setDefault((usageRecord.getUsageId() == 1)? true:false);
                 
                } else if(usageRecord.getUsageType() == UsageTypes.VPN_USERS){
                    //VPN User ID
                    usageRecResponse.setUsageId(usageRecord.getUsageId().toString());
                   
                } else if(usageRecord.getUsageType() == UsageTypes.SECURITY_GROUP){
                  //Security Group Id
                  usageRecResponse.setUsageId(identityDao.getIdentityUuid("security_group", usageRecord.getUsageId().toString()));
                }
               
                if (usageRecord.getRawUsage() != null) {
                    DecimalFormat decimalFormat = new DecimalFormat("###########.######");
                    usageRecResponse.setRawUsage(decimalFormat.format(usageRecord.getRawUsage()));
                }

                if (usageRecord.getStartDate() != null) {
                    usageRecResponse.setStartDate(getDateStringInternal(usageRecord.getStartDate()));
                }
                if (usageRecord.getEndDate() != null) {
                    usageRecResponse.setEndDate(getDateStringInternal(usageRecord.getEndDate()));
                }
            }

            usageRecResponse.setObjectName("usagerecord");
            usageResponses.add(usageRecResponse);
        }

        response.setResponses(usageResponses);
        response.setResponseName(getCommandName());
View Full Code Here

TOP

Related Classes of com.cloud.server.api.response.UsageRecordResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.