public static Guid getImageGroupIdFromImageFile(String imageFile) { if (!StringUtils.isBlank(imageFile)) { return Guid.createGuidFromStringDefaultEmpty(imageFile.split("[/]", -1)[0]); } return null; }
private AuditLogEvent extractAuditLogEvent(ResultSet rs, Set<String> downEvents) throws SQLException { AuditLogEvent auditLogEvent = new AuditLogEvent(); auditLogEvent.setId(rs.getLong("audit_log_id")); auditLogEvent.setLogTypeName(rs.getString("log_type_name")); if (downEvents.contains(auditLogEvent.getLogTypeName())) { auditLogEvent.setType(AuditLogEventType.resolveMessage); } else { auditLogEvent.setType(AuditLogEventType.alertMessage); } auditLogEvent.setUserId(Guid.createGuidFromString(rs.getString("user_id"))); auditLogEvent.setUserName(rs.getString("user_name")); auditLogEvent.setVmId(Guid.createGuidFromString(rs.getString("vm_id"))); auditLogEvent.setVmName(rs.getString("vm_name")); auditLogEvent.setVmTemplateId(Guid.createGuidFromString(rs.getString("vm_template_id"))); auditLogEvent.setVmTemplateName(rs.getString("vm_template_name")); auditLogEvent.setVdsId(Guid.createGuidFromString(rs.getString("vds_id"))); auditLogEvent.setVdsName(rs.getString("vds_name")); auditLogEvent.setStoragePoolId(Guid.createGuidFromStringDefaultEmpty(rs.getString("storage_pool_id"))); auditLogEvent.setStoragePoolName(rs.getString("storage_pool_name")); auditLogEvent.setStorageDomainId(Guid.createGuidFromStringDefaultEmpty(rs.getString("storage_domain_id"))); auditLogEvent.setStorageDomainName(rs.getString("storage_domain_name")); auditLogEvent.setLogTime(rs.getTimestamp("log_time")); auditLogEvent.setSeverity(AuditLogSeverity.forValue(rs.getInt("severity"))); auditLogEvent.setMessage(rs.getString("message")); return auditLogEvent; }
@SuppressWarnings("unchecked") protected List<org.ovirt.engine.core.common.businessentities.network.Network> getClusterNetworks(){ VDS vds = getEntity(VDS.class, QueryType.GetVdsByVdsId, new IdQueryParameters(Guid.createGuidFromStringDefaultEmpty(getHostId())), "Host"); return getEntity(List.class, QueryType.GetAllNetworksByClusterId, new IdQueryParameters(vds.getClusterId()), "Networks"); }
@Mapping(from = GlusterBrick.class, to = GlusterBrickEntity.class) public static GlusterBrickEntity map(GlusterBrick fromBrick, GlusterBrickEntity toBrick) { GlusterBrickEntity brick = (toBrick == null) ? new GlusterBrickEntity() : toBrick; if(fromBrick.isSetId()) { brick.setId(Guid.createGuidFromStringDefaultEmpty(fromBrick.getId())); } if(fromBrick.isSetServerId()) { brick.setServerId(Guid.createGuidFromStringDefaultEmpty(fromBrick.getServerId())); } if(fromBrick.isSetBrickDir()) { brick.setBrickDirectory(fromBrick.getBrickDir()); } return brick; }
protected Map<Guid, Guid> getDiskToDestinationMap(Action action) { Map<Guid, Guid> diskToDestinationMap = new HashMap<>(); if (action.isSetVm() && action.getVm().isSetDiskAttachments() && action.getVm().getDiskAttachments().isSetDiskAttachments()) { for (DiskAttachment diskAttachment : action.getVm().getDiskAttachments().getDiskAttachments()) { Disk disk = diskAttachment.getDisk(); if (disk != null && disk.isSetId() && disk.isSetStorageDomains() && disk.getStorageDomains().isSetStorageDomains() && disk.getStorageDomains().getStorageDomains().get(0).isSetId()) { diskToDestinationMap.put(Guid.createGuidFromStringDefaultEmpty(disk.getId()), Guid.createGuidFromStringDefaultEmpty(disk.getStorageDomains().getStorageDomains().get(0).getId())); } } } return diskToDestinationMap; } }
@Override public Response add(DiskAttachment attachment) { if (attachment.isSetDisk() && attachment.getDisk().isSetId()) { Guid diskId = Guid.createGuidFromStringDefaultEmpty(attachment.getDisk().getId()); return attachDiskToVm(this, attachment, new AttachDiskResolver(diskId, vmId)); } else { return createDisk(this, attachment, new AddDiskResolver()); } }
private void addInlineStatistics(Vm vm) { EntityIdResolver<Guid> resolver = new QueryIdResolver<>(QueryType.GetVmByVmId, IdQueryParameters.class); VmStatisticalQuery query = new VmStatisticalQuery(resolver, newModel(vm.getId())); BackendStatisticsResource<Vm, org.ovirt.engine.core.common.businessentities.VM> statisticsResource = inject(new BackendStatisticsResource<>(entityType, Guid.createGuidFromStringDefaultEmpty(vm.getId()), query)); Statistics statistics = statisticsResource.list(); vm.setStatistics(statistics); }
public DbUser getDbUser() { DbUser user = new DbUser(); user.setId(Guid.createGuidFromStringDefaultEmpty(getId())); user.setDomain(getDomain()); user.setLoginName(getUserName()); user.setAdmin(isAdmin()); return user; }
public Guid getStoragePoolId(Action action) { if(action.getStorageDomain().isSetId()){ return getDataCenterId(Guid.createGuidFromStringDefaultEmpty(action.getStorageDomain().getId())); } else { return getDataCenterId(lookupStorageDomainIdByName(action.getStorageDomain().getName())); } }
@Test public void testStringCreation() { Guid guid = Guid.newGuid(); Guid guidFromString = new Guid(guid.toString()); assertEquals(guidFromString, guid); guidFromString = Guid.createGuidFromString(guid.toString()); assertEquals(guidFromString, guid); guidFromString = Guid.createGuidFromString(null); assertNull(guidFromString); guidFromString = Guid.createGuidFromStringDefaultEmpty(guid.toString()); assertEquals(guidFromString, guid); guidFromString = Guid.createGuidFromStringDefaultEmpty(null); assertEquals(Guid.Empty, guidFromString); }
@Override public Response add(Disk disk) { DiskAttachment diskAttachment = new DiskAttachment(); if (disk.isSetBootable()) { diskAttachment.setBootable(disk.isBootable()); } else { diskAttachment.setBootable(false); } if (disk.isSetInterface()) { diskAttachment.setInterface(disk.getInterface()); } else { diskAttachment.setInterface(DiskInterface.VIRTIO); } if (disk.isSetActive()) { diskAttachment.setActive(disk.isActive()); } diskAttachment.setDisk(disk); if (disk.isSetId()) { Guid diskId = Guid.createGuidFromStringDefaultEmpty(disk.getId()); return getAttachmentsResource().attachDiskToVm(this, diskAttachment, new OldAttachDiskResolver(diskId)); } else { return getAttachmentsResource().createDisk(this, diskAttachment, new OldAddDiskResolver()); } }
protected Response attachDiskToVm(AbstractBackendCollectionResource resource, DiskAttachment attachment, IResolver entityResolver) { Guid diskId = Guid.createGuidFromStringDefaultEmpty(attachment.getDisk().getId()); DiskVmElement dve = map(attachment); dve.getId().setVmId(vmId); dve.getId().setDeviceId(diskId); AttachDetachVmDiskParameters params = new AttachDetachVmDiskParameters(dve); Disk disk = attachment.getDisk(); boolean isDiskActive = false; if (attachment.isSetActive()) { isDiskActive = BooleanUtils.toBoolean(attachment.isActive()); } params.setPlugUnPlug(isDiskActive); if (disk.isSetReadOnly()) { dve.setReadOnly(BooleanUtils.toBoolean(disk.isReadOnly())); } if (disk.isSetSnapshot()) { validateParameters(disk, "snapshot.id"); params.setSnapshotId(asGuid(disk.getSnapshot().getId())); } return resource.performCreate(ActionType.AttachDiskToVm, params, entityResolver); }
StorageDomain storageDomain = disk.getStorageDomains().getStorageDomains().get(0); diskImage.setStorageIds(new ArrayList<>()); diskImage.getStorageIds().add(Guid.createGuidFromStringDefaultEmpty(storageDomain.getId()));
volume.setId(Guid.createGuidFromStringDefaultEmpty(fromVolume.getId()));