public Account getCallingAccount() { if (account == null) { account = s_entityMgr.findById(Account.class, accountId); } return account; }
@Override public VirtualMachineTemplate getTemplate() { if (_template == null && _vm != null) { _template = s_entityMgr.findByIdIncludingRemoved(VirtualMachineTemplate.class, _vm.getTemplateId()); } return _template; }
private Object getEntityVO(Class entityType, Object entityId){ // entityId can be internal db id or UUID so accordingly call findbyId or findByUUID if (entityId instanceof Long){ // Its internal db id - use findById return _entityMgr.findById(entityType, (Long)entityId); } else if(entityId instanceof String){ try{ // In case its an async job the internal db id would be a string because of json deserialization Long internalId = Long.valueOf((String) entityId); return _entityMgr.findById(entityType, internalId); } catch (NumberFormatException e){ // It is uuid - use findByUuid` return _entityMgr.findByUuid(entityType, (String)entityId); } } return null; }
final VirtualMachineTemplate template = _entityMgr.findByIdIncludingRemoved(VirtualMachineTemplate.class, vm.getTemplateId()); final Account owner = _entityMgr.findById(Account.class, vm.getAccountId()); final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, template, offering, owner, params); DeployDestination dest = null;
public <T> boolean IsUuidUnique(Class<T> entityType, String uuid) { T obj = _entityMgr.findByUuid(entityType, uuid); if (obj != null) { return false; } else { return true; } }
final Object objVO = _entityMgr.findByUuidIncludingRemoved(entity, uuid); if (objVO == null) { continue;
public Map<Long, List<String>> getVmIdIpListMap() { Map<Long, List<String>> vmIdIpsMap = new HashMap<Long, List<String>>(); if (vmIdIpMap != null && !vmIdIpMap.isEmpty()) { Collection idIpsCollection = vmIdIpMap.values(); Iterator iter = idIpsCollection.iterator(); while (iter.hasNext()) { HashMap<String, String> idIpsMap = (HashMap<String, String>)iter.next(); String vmId = idIpsMap.get("vmid"); String vmIp = idIpsMap.get("vmip"); VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmId); if (lbvm == null) { throw new InvalidParameterValueException("Unable to find virtual machine ID: " + vmId); } Long longVmId = lbvm.getId(); List<String> ipsList = null; if (vmIdIpsMap.containsKey(longVmId)) { ipsList = vmIdIpsMap.get(longVmId); } else { ipsList = new ArrayList<String>(); } ipsList.add(vmIp); vmIdIpsMap.put(longVmId, ipsList); } } return vmIdIpsMap; }
ctx.setEventDisplayEnabled(cmd.isDisplay()); if(params.get(ApiConstants.PROJECT_ID) != null) { Project project = _entityMgr.findByUuidIncludingRemoved(Project.class, params.get(ApiConstants.PROJECT_ID)); ctx.setProject(project);
@Override public long getEntityOwnerId() { if (ownerId == null) { PortForwardingRule rule = _entityMgr.findById(PortForwardingRule.class, id); if (rule == null) { throw new InvalidParameterValueException("Unable to find port forwarding rule by ID=" + id); } else { ownerId = _entityMgr.findById(PortForwardingRule.class, id).getAccountId(); } } return ownerId; }
public DeployDestination getDeployDestination() { DataCenter zone = zoneId != null ? s_entityMgr.findById(DataCenter.class, zoneId) : null; Pod pod = podId != null ? s_entityMgr.findById(Pod.class, podId) : null; Cluster cluster = clusterId != null ? s_entityMgr.findById(Cluster.class, clusterId) : null; Host host = hostId != null ? s_entityMgr.findById(Host.class, hostId) : null; Map<Volume, StoragePool> vols = null; if (storage != null) { vols = new HashMap<Volume, StoragePool>(storage.size()); for (Map.Entry<String, String> entry : storage.entrySet()) { vols.put(s_entityMgr.findByUuid(Volume.class, entry.getKey()), s_entityMgr.findByUuid(StoragePool.class, entry.getValue())); } } DeployDestination dest = new DeployDestination(zone, pod, cluster, host, vols); return dest; }
public Map<Long, Long> getLoadBalancerRuleWeightMap() { Map<Long, Long> lbRuleWeightMap = new HashMap<Long, Long>(); if (gslbLbRuleWieghtMap == null || gslbLbRuleWieghtMap.isEmpty()) { return null; } Collection lbruleWeightsCollection = gslbLbRuleWieghtMap.values(); Iterator iter = lbruleWeightsCollection.iterator(); while (iter.hasNext()) { HashMap<String, String> map = (HashMap<String, String>)iter.next(); Long weight; LoadBalancer lbrule = _entityMgr.findByUuid(LoadBalancer.class, map.get("loadbalancerid")); if (lbrule == null) { throw new InvalidParameterValueException("Unable to find load balancer rule with ID: " + map.get("loadbalancerid")); } try { weight = Long.parseLong(map.get("weight")); if (weight < 1 || weight > 100) { throw new InvalidParameterValueException("Invalid weight " + weight + " given for the LB rule id: " + map.get("loadbalancerid")); } } catch (NumberFormatException nfe) { throw new InvalidParameterValueException("Unable to translate weight given for the LB rule id: " + map.get("loadbalancerid")); } lbRuleWeightMap.put(lbrule.getId(), weight); } return lbRuleWeightMap; }
usageRecResponse.setUsageType(usageRecord.getUsageType()); if (usageRecord.getVmInstanceId() != null) { VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getVmInstanceId()); if (vm != null) { usageRecResponse.setVirtualMachineId(vm.getUuid()); Long resourceId = null; if (usageRecord.getUsageType() == UsageTypes.RUNNING_VM || usageRecord.getUsageType() == UsageTypes.ALLOCATED_VM) { ServiceOfferingVO svcOffering = _entityMgr.findByIdIncludingRemoved(ServiceOfferingVO.class, usageRecord.getOfferingId().toString()); VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString()); if (vm != null) { resourceType = ResourceTag.ResourceObjectType.UserVm; IPAddressVO ip = _entityMgr.findByIdIncludingRemoved(IPAddressVO.class, usageRecord.getUsageId().toString()); if (ip != null) { resourceType = ResourceObjectType.PublicIpAddress; VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString()); if (vm != null) { resourceId = vm.getId(); HostVO host = _entityMgr.findByIdIncludingRemoved(HostVO.class, usageRecord.getUsageId().toString()); if (host != null) { usageRecResponse.setUsageId(host.getUuid()); NetworkVO network = _entityMgr.findByIdIncludingRemoved(NetworkVO.class, usageRecord.getNetworkId().toString()); if (network != null) { resourceType = ResourceObjectType.Network;
@Override public Account getAccount() { if (_account == null) { _account = s_entityMgr.findById(Account.class, _caller.getId()); } return _account; }
@Override public long getResourceId(String resourceId, ResourceObjectType resourceType) { Class<?> clazz = s_typeMap.get(resourceType); Object entity = _entityMgr.findByUuid(clazz, resourceId); if (entity != null) { return ((InternalIdentity)entity).getId(); } if (!StringUtils.isNumeric(resourceId)) { throw new InvalidParameterValueException("Unable to find resource by uuid " + resourceId + " and type " + resourceType); } entity = _entityMgr.findById(clazz, resourceId); if (entity != null) { return ((InternalIdentity)entity).getId(); } throw new InvalidParameterValueException("Unable to find resource by id " + resourceId + " and type " + resourceType); }
String vmIp = idIpsMap.get("vmip"); VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmId); if (lbvm == null) { throw new InvalidParameterValueException("Unable to find virtual machine ID: " + vmId);
@Override public AsyncJobResponse queryJobResult(final QueryAsyncJobResultCmd cmd) { final Account caller = CallContext.current().getCallingAccount(); final AsyncJob job = _entityMgr.findByIdIncludingRemoved(AsyncJob.class, cmd.getId()); if (job == null) { throw new InvalidParameterValueException("Unable to find a job by id " + cmd.getId()); } final User userJobOwner = _accountMgr.getUserIncludingRemoved(job.getUserId()); final Account jobOwner = _accountMgr.getAccount(userJobOwner.getAccountId()); //check permissions if (_accountMgr.isNormalUser(caller.getId())) { //regular user can see only jobs he owns if (caller.getId() != jobOwner.getId()) { throw new PermissionDeniedException("Account " + caller + " is not authorized to see job id=" + job.getId()); } } else if (_accountMgr.isDomainAdmin(caller.getId())) { _accountMgr.checkAccess(caller, null, true, jobOwner); } return createAsyncJobResponse(_jobMgr.queryJob(cmd.getId(), true)); }
private IpAddress getIpAddress(long id) { IpAddress ip = _entityMgr.findById(IpAddress.class, id); if (ip == null) { throw new InvalidParameterValueException("Unable to find IP address by ID=" + id); } else { return ip; } }
public Map<Long, DiskOffering> getDataDiskTemplateToDiskOfferingMap() { if (diskOfferingId != null && dataDiskTemplateToDiskOfferingList != null) { throw new InvalidParameterValueException("diskofferingid paramter can't be specified along with datadisktemplatetodiskofferinglist parameter"); } if (MapUtils.isEmpty(dataDiskTemplateToDiskOfferingList)) { return new HashMap<Long, DiskOffering>(); } HashMap<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap = new HashMap<Long, DiskOffering>(); for (Object objDataDiskTemplates : dataDiskTemplateToDiskOfferingList.values()) { HashMap<String, String> dataDiskTemplates = (HashMap<String, String>) objDataDiskTemplates; Long dataDiskTemplateId; DiskOffering dataDiskOffering = null; VirtualMachineTemplate dataDiskTemplate= _entityMgr.findByUuid(VirtualMachineTemplate.class, dataDiskTemplates.get("datadisktemplateid")); if (dataDiskTemplate == null) { dataDiskTemplate = _entityMgr.findById(VirtualMachineTemplate.class, dataDiskTemplates.get("datadisktemplateid")); if (dataDiskTemplate == null) throw new InvalidParameterValueException("Unable to translate and find entity with datadisktemplateid " + dataDiskTemplates.get("datadisktemplateid")); } dataDiskTemplateId = dataDiskTemplate.getId(); dataDiskOffering = _entityMgr.findByUuid(DiskOffering.class, dataDiskTemplates.get("diskofferingid")); if (dataDiskOffering == null) { dataDiskOffering = _entityMgr.findById(DiskOffering.class, dataDiskTemplates.get("diskofferingid")); if (dataDiskOffering == null) throw new InvalidParameterValueException("Unable to translate and find entity with diskofferingId " + dataDiskTemplates.get("diskofferingid")); } dataDiskTemplateToDiskOfferingMap.put(dataDiskTemplateId, dataDiskOffering); } return dataDiskTemplateToDiskOfferingMap; }
public static CallContext register(String callingUserUuid, String callingAccountUuid) { Account account = s_entityMgr.findByUuid(Account.class, callingAccountUuid); if (account == null) { throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, callingAccountUuid); } User user = s_entityMgr.findByUuid(User.class, callingUserUuid); if (user == null) { throw new CloudAuthenticationException("The user is no longer current.").add(User.class, callingUserUuid); } return register(user, account); }
@Override public long getEntityOwnerId() { Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); return vpc.getAccountId(); }