public <T> boolean IsUuidUnique(Class<T> entityType, String uuid) { T obj = _entityMgr.findByUuid(entityType, uuid); if (obj != null) { return false; } else { return true; } }
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, 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; }
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; }
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; }
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); }
public static LogContext 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); }
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);
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; }
@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); }
VirtualMachine vm = _entityMgr.findByUuid(VirtualMachine.class, vmIdString); if (vm == null) { s_logger.info("invalid console servlet command parameter: " + vmIdString);
lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i)); VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmResponses.get(i).getId()); lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), lbvm.getId())); lbRuleVmIpResponse.setObjectName("lbrulevmidip");
lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i)); VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmResponses.get(i).getId()); lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), lbvm.getId())); lbRuleVmIpResponse.setObjectName("lbrulevmidip");
@Override public AcquirePodIpCmdResponse allocatePodIp(Account ipOwner, String zoneId, String podId) throws ResourceAllocationException { Account caller = CallContext.current().getCallingAccount(); long callerUserId = CallContext.current().getCallingUserId(); DataCenter zone = _entityMgr.findByUuid(DataCenter.class, zoneId); if (zone == null) { throw new InvalidParameterValueException("Invalid zone Id "); } if (_accountMgr.checkAccessAndSpecifyAuthority(caller, zone.getId()) != zone.getId()) { throw new InvalidParameterValueException("Caller does not have permission for this Zone" + "(" + zoneId + ")"); } if (s_logger.isDebugEnabled()) { s_logger.debug("Associate IP address called by the user " + callerUserId + " account " + ipOwner.getId()); } return _ipAddrMgr.allocatePodIp(zoneId, podId); }
public AcquirePodIpCmdResponse allocatePodIp(String zoneId, String podId) throws ConcurrentOperationException, ResourceAllocationException { DataCenter zone = _entityMgr.findByUuid(DataCenter.class, zoneId); Account caller = CallContext.current().getCallingAccount(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) {