List of usage examples for java.util UUID nameUUIDFromBytes
public static UUID nameUUIDFromBytes(byte[] name)
From source file:com.cloud.storage.resource.NfsSecondaryStorageResource.java
private Answer execute(SecStorageSetupCommand cmd) { if (!_inSystemVM) { return new Answer(cmd, true, null); }/* ww w .j a v a 2 s.c om*/ String secUrl = cmd.getSecUrl(); try { URI uri = new URI(secUrl); String nfsHost = uri.getHost(); InetAddress nfsHostAddr = InetAddress.getByName(nfsHost); String nfsHostIp = nfsHostAddr.getHostAddress(); addRouteToInternalIpOrCidr(_storageGateway, _storageIp, _storageNetmask, nfsHostIp); String nfsPath = nfsHostIp + ":" + uri.getPath(); String dir = UUID.nameUUIDFromBytes(nfsPath.getBytes()).toString(); String root = _parent + "/" + dir; mount(root, nfsPath); configCerts(cmd.getCerts()); nfsIps.add(nfsHostIp); return new SecStorageSetupAnswer(dir); } catch (Exception e) { String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString(); s_logger.error(msg); return new Answer(cmd, false, msg); } }
From source file:org.wso2.carbon.dataservices.core.DBUtils.java
public static void populateStandardCustomDSProps(Map<String, String> dsProps, DataService dataService, Config config) {/*ww w.j a v a2s.c o m*/ String dsInfo = dataService.getTenantId() + "#" + dataService.getName() + "#" + config.getConfigId(); dsProps.put(DBConstants.CustomDataSource.DATASOURCE_ID, UUID .nameUUIDFromBytes(dsInfo.getBytes(Charset.forName(DBConstants.DEFAULT_CHAR_SET_TYPE))).toString()); if (log.isDebugEnabled()) { log.debug("Custom Inline Data Source; ID: " + dsInfo + " UUID:" + dsProps.get(DBConstants.CustomDataSource.DATASOURCE_ID)); } }
From source file:eionet.util.Util.java
/** * * @param schemaSet//from ww w . jav a 2 s . c om * @return */ public static String generateContinuityId(SchemaSet schemaSet) { if (schemaSet == null || isEmpty(schemaSet.getIdentifier())) { return null; } String name = schemaSet.getIdentifier() + Thread.currentThread().getId() + System.currentTimeMillis(); return UUID.nameUUIDFromBytes(name.getBytes()).toString(); }
From source file:eionet.util.Util.java
/** * * @param schema/* w ww . j ava 2 s.c o m*/ * @return */ public static String generateContinuityId(Schema schema) { if (schema == null || isEmpty(schema.getFileName())) { return null; } String name = schema.getFileName() + Thread.currentThread().getId() + System.currentTimeMillis(); return UUID.nameUUIDFromBytes(name.getBytes()).toString(); }
From source file:com.cloud.hypervisor.xenserver.resource.Xenserver625StorageProcessor.java
@Override public Answer createTemplateFromSnapshot(final CopyCommand cmd) { final Connection conn = hypervisorResource.getConnection(); final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); if (srcData.getDataStore() instanceof PrimaryDataStoreTO && destData.getDataStore() instanceof NfsTO) { return createTemplateFromSnapshot2(cmd); }//from w w w. j ava2 s . co m final int wait = cmd.getWait(); final SnapshotObjectTO srcObj = (SnapshotObjectTO) srcData; final TemplateObjectTO destObj = (TemplateObjectTO) destData; final NfsTO srcStore = (NfsTO) srcObj.getDataStore(); final NfsTO destStore = (NfsTO) destObj.getDataStore(); URI srcUri = null; URI destUri = null; try { srcUri = new URI(srcStore.getUrl()); destUri = new URI(destStore.getUrl()); } catch (final Exception e) { s_logger.debug("incorrect url", e); return new CopyCmdAnswer("incorrect url" + e.toString()); } final String srcPath = srcObj.getPath(); final int index = srcPath.lastIndexOf("/"); final String srcDir = srcPath.substring(0, index); final String destDir = destObj.getPath(); SR srcSr = null; SR destSr = null; VDI destVdi = null; boolean result = false; try { srcSr = createFileSr(conn, srcUri.getHost() + ":" + srcUri.getPath(), srcDir); final String destNfsPath = destUri.getHost() + ":" + destUri.getPath(); final String localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(destNfsPath.getBytes()); mountNfs(conn, destUri.getHost() + ":" + destUri.getPath(), localDir); makeDirectory(conn, localDir + "/" + destDir); destSr = createFileSR(conn, localDir + "/" + destDir); final String nameLabel = "cloud-" + UUID.randomUUID().toString(); final String[] parents = srcObj.getParents(); final List<VDI> snapshotChains = new ArrayList<VDI>(); if (parents != null) { for (int i = 0; i < parents.length; i++) { final String snChainPath = parents[i]; final String uuid = getSnapshotUuid(snChainPath); final VDI chain = VDI.getByUuid(conn, uuid); snapshotChains.add(chain); } } final String snapshotUuid = getSnapshotUuid(srcPath); final VDI snapshotVdi = VDI.getByUuid(conn, snapshotUuid); snapshotChains.add(snapshotVdi); final long templateVirtualSize = snapshotChains.get(0).getVirtualSize(conn); destVdi = createVdi(conn, nameLabel, destSr, templateVirtualSize); final String destVdiUuid = destVdi.getUuid(conn); for (final VDI snapChain : snapshotChains) { final Task task = snapChain.copyAsync(conn, null, null, destVdi); // poll every 1 seconds , hypervisorResource.waitForTask(conn, task, 1000, wait * 1000); hypervisorResource.checkForSuccess(conn, task); task.destroy(conn); } destVdi = VDI.getByUuid(conn, destVdiUuid); // scan makes XenServer pick up VDI physicalSize destSr.scan(conn); final String templateUuid = destVdi.getUuid(conn); final String templateFilename = templateUuid + ".vhd"; final long virtualSize = destVdi.getVirtualSize(conn); final long physicalSize = destVdi.getPhysicalUtilisation(conn); String templatePath = destNfsPath + "/" + destDir; templatePath = templatePath.replaceAll("//", "/"); result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, nameLabel, null, physicalSize, virtualSize, destObj.getId()); if (!result) { throw new CloudRuntimeException( "Could not create the template.properties file on secondary storage dir"); } final TemplateObjectTO newTemplate = new TemplateObjectTO(); newTemplate.setPath(destDir + "/" + templateFilename); newTemplate.setFormat(Storage.ImageFormat.VHD); newTemplate.setSize(destVdi.getVirtualSize(conn)); newTemplate.setPhysicalSize(destVdi.getPhysicalUtilisation(conn)); newTemplate.setName(destVdiUuid); result = true; return new CopyCmdAnswer(newTemplate); } catch (final Exception e) { s_logger.error("Failed create template from snapshot", e); return new CopyCmdAnswer("Failed create template from snapshot " + e.toString()); } finally { if (!result) { if (destVdi != null) { try { destVdi.destroy(conn); } catch (final Exception e) { s_logger.debug("Clean up left over on dest storage failed: ", e); } } } if (srcSr != null) { hypervisorResource.removeSR(conn, srcSr); } if (destSr != null) { hypervisorResource.removeSR(conn, destSr); } } }
From source file:org.openecomp.sdc.action.impl.ActionManagerImpl.java
/** * Generate artifact UUID at runtime using action name and effective version. * * @param action {@link Action} for which the artifact is being uploaded/updated/downloaded. * @param artifactName Artifact name./*w w w.ja va2 s . com*/ * @return Generated UUID string. */ private String generateActionArtifactUuId(Action action, String artifactName) { int effectiveVersion = getEffectiveVersion(action.getVersion()); //Upper case for maintaining case-insensitive behavior for the artifact names String artifactUuIdString = action.getName().toUpperCase() + effectiveVersion + artifactName.toUpperCase(); String generateArtifactUuId = UUID.nameUUIDFromBytes((artifactUuIdString).getBytes()).toString(); String artifactUuId = generateArtifactUuId.replace("-", ""); return artifactUuId.toUpperCase(); }
From source file:eionet.util.Util.java
/** * Return unique continuity ID for vocabulary folder. * * @param vocabularyFolder//from w ww . j a v a2 s . c om * @return */ public static String generateContinuityId(VocabularyFolder vocabularyFolder) { if (vocabularyFolder == null || isEmpty(vocabularyFolder.getIdentifier())) { return null; } String name = vocabularyFolder.getIdentifier() + Thread.currentThread().getId() + System.currentTimeMillis(); return UUID.nameUUIDFromBytes(name.getBytes()).toString(); }
From source file:com.cloud.hypervisor.xenserver.resource.Xenserver625StorageProcessor.java
public Answer createTemplateFromSnapshot2(final CopyCommand cmd) { final Connection conn = hypervisorResource.getConnection(); final SnapshotObjectTO snapshotObjTO = (SnapshotObjectTO) cmd.getSrcTO(); final TemplateObjectTO templateObjTO = (TemplateObjectTO) cmd.getDestTO(); if (!(snapshotObjTO.getDataStore() instanceof PrimaryDataStoreTO) || !(templateObjTO.getDataStore() instanceof NfsTO)) { return null; }/*w ww.j a v a 2 s .c om*/ NfsTO destStore = null; URI destUri = null; try { destStore = (NfsTO) templateObjTO.getDataStore(); destUri = new URI(destStore.getUrl()); } catch (final Exception ex) { s_logger.debug("Invalid URI", ex); return new CopyCmdAnswer("Invalid URI: " + ex.toString()); } SR srcSr = null; SR destSr = null; final String destDir = templateObjTO.getPath(); VDI destVdi = null; boolean result = false; try { final Map<String, String> srcDetails = cmd.getOptions(); final String iScsiName = srcDetails.get(DiskTO.IQN); final String storageHost = srcDetails.get(DiskTO.STORAGE_HOST); final String chapInitiatorUsername = srcDetails.get(DiskTO.CHAP_INITIATOR_USERNAME); final String chapInitiatorSecret = srcDetails.get(DiskTO.CHAP_INITIATOR_SECRET); srcSr = hypervisorResource.getIscsiSR(conn, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, true); final String destNfsPath = destUri.getHost() + ":" + destUri.getPath(); final String localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(destNfsPath.getBytes()); mountNfs(conn, destNfsPath, localDir); makeDirectory(conn, localDir + "/" + destDir); destSr = createFileSR(conn, localDir + "/" + destDir); // there should only be one VDI in this SR final VDI srcVdi = srcSr.getVDIs(conn).iterator().next(); destVdi = srcVdi.copy(conn, destSr); final String nameLabel = "cloud-" + UUID.randomUUID().toString(); destVdi.setNameLabel(conn, nameLabel); // scan makes XenServer pick up VDI physicalSize destSr.scan(conn); final String templateUuid = destVdi.getUuid(conn); final String templateFilename = templateUuid + ".vhd"; final long virtualSize = destVdi.getVirtualSize(conn); final long physicalSize = destVdi.getPhysicalUtilisation(conn); // create the template.properties file String templatePath = destNfsPath + "/" + destDir; templatePath = templatePath.replaceAll("//", "/"); result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, nameLabel, null, physicalSize, virtualSize, templateObjTO.getId()); if (!result) { throw new CloudRuntimeException( "Could not create the template.properties file on secondary storage dir"); } final TemplateObjectTO newTemplate = new TemplateObjectTO(); newTemplate.setPath(destDir + "/" + templateFilename); newTemplate.setFormat(Storage.ImageFormat.VHD); newTemplate.setHypervisorType(HypervisorType.XenServer); newTemplate.setSize(virtualSize); newTemplate.setPhysicalSize(physicalSize); newTemplate.setName(templateUuid); result = true; return new CopyCmdAnswer(newTemplate); // } catch (Exception ex) { // s_logger.error("Failed to create a template from a snapshot", // ex); // // return new // CopyCmdAnswer("Failed to create a template from a snapshot: " + // ex.toString()); } catch (final BadServerResponse e) { s_logger.error("Failed to create a template from a snapshot due to incomprehensible server response", e); return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString()); } catch (final XenAPIException e) { s_logger.error("Failed to create a template from a snapshot due to xenapi error", e); return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString()); } catch (final XmlRpcException e) { s_logger.error("Failed to create a template from a snapshot due to rpc error", e); return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString()); } finally { if (!result) { if (destVdi != null) { try { destVdi.destroy(conn); } catch (final Exception e) { s_logger.debug("Cleaned up leftover VDI on destination storage due to failure: ", e); } } } if (srcSr != null) { hypervisorResource.removeSR(conn, srcSr); } if (destSr != null) { hypervisorResource.removeSR(conn, destSr); } } }
From source file:org.apache.nifi.web.util.SnippetUtils.java
/** * Generates a new type 1 id (UUID) for the current id that is specified. If * seed is provided, it will be incorporated into generation logic of the * new ID.// ww w .java 2 s.c om * The contract of this method is as follows: * - The 'currentId' must never be null and it must be String representation * of type-one UUID. * - If seed is provided, the new ID will be generated from the 'msb' extracted from * the 'currentId' and the 'lsb' extracted from the UUID generated via * UUID.nameUUIDFromBytes(currentId + seed). * - If seed is NOT provided and 'isCopy' flag is set the new ID will be generated from * the 'msb' extracted from the 'currentId' and random integer as 'lsb'. In this case * the new ID will always be > the previous ID essentially resulting in the new ID for * the component that being copied (e.g., copy/paste). * - If seed is NOT provided and 'isCopy' flag is NOT set the new ID will be generated from * the 'msb' extracted from the 'currentId' and random integer as 'lsb'. */ private String generateId(final String currentId, final String seed, boolean isCopy) { long msb = UUID.fromString(currentId).getMostSignificantBits(); UUID uuid; if (StringUtils.isBlank(seed)) { long lsb = randomGenerator.nextLong(); if (isCopy) { uuid = ComponentIdGenerator.generateId(msb, lsb, true); // will increment msb if necessary } else { // since msb is extracted from type-one UUID, the type-one semantics will be preserved uuid = new UUID(msb, lsb); } } else { UUID seedId = UUID.nameUUIDFromBytes((currentId + seed).getBytes(StandardCharsets.UTF_8)); if (isCopy) { // will ensure the type-one semantics for new UUID generated from msb extracted from seedId uuid = ComponentIdGenerator.generateId(seedId.getMostSignificantBits(), seedId.getLeastSignificantBits(), false); } else { uuid = new UUID(msb, seedId.getLeastSignificantBits()); } } logger.debug("Generating UUID {} from currentId={}, seed={}, isCopy={}", uuid, currentId, seed, isCopy); return uuid.toString(); }
From source file:com.cloud.hypervisor.xenserver.resource.CitrixResourceBase.java
protected SR createNfsSRbyURI(final Connection conn, final URI uri, final boolean shared) { try {//from w ww . j a va2s . co m if (s_logger.isDebugEnabled()) { s_logger.debug("Creating a " + (shared ? "shared SR for " : "not shared SR for ") + uri); } final Map<String, String> deviceConfig = new HashMap<String, String>(); String path = uri.getPath(); path = path.replace("//", "/"); deviceConfig.put("server", uri.getHost()); deviceConfig.put("serverpath", path); final String name = UUID.nameUUIDFromBytes(new String(uri.getHost() + path).getBytes()).toString(); if (!shared) { final Set<SR> srs = SR.getByNameLabel(conn, name); for (final SR sr : srs) { final SR.Record record = sr.getRecord(conn); if (SRType.NFS.equals(record.type) && record.contentType.equals("user") && !record.shared) { removeSRSync(conn, sr); } } } final Host host = Host.getByUuid(conn, _host.getUuid()); final Map<String, String> smConfig = new HashMap<String, String>(); smConfig.put("nosubdir", "true"); final SR sr = SR.create(conn, host, deviceConfig, new Long(0), name, uri.getHost() + uri.getPath(), SRType.NFS.toString(), "user", shared, smConfig); if (!checkSR(conn, sr)) { throw new Exception("no attached PBD"); } if (s_logger.isDebugEnabled()) { s_logger.debug(logX(sr, "Created a SR; UUID is " + sr.getUuid(conn) + " device config is " + deviceConfig)); } sr.scan(conn); return sr; } catch (final XenAPIException e) { final String msg = "Can not create second storage SR mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.toString(); s_logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } catch (final Exception e) { final String msg = "Can not create second storage SR mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.getMessage(); s_logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } }