Example usage for java.util UUID nameUUIDFromBytes

List of usage examples for java.util UUID nameUUIDFromBytes

Introduction

In this page you can find the example usage for java.util UUID nameUUIDFromBytes.

Prototype

public static UUID nameUUIDFromBytes(byte[] name) 

Source Link

Document

Static factory to retrieve a type 3 (name based) UUID based on the specified byte array.

Usage

From source file:org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource.java

/**
 * Mount remote device named on local file system on subfolder of _parent
 * field.//  ww  w . j a v  a  2  s .  co m
 * <p>
 *
 * Supported schemes are "nfs" and "cifs".
 * <p>
 *
 * CIFS parameters are documented with mount.cifs at
 * http://linux.die.net/man/8/mount.cifs
 * For simplicity, when a URI is used to specify a CIFS share,
 * options such as domain,user,password are passed as query parameters.
 *
 * @param uri
 *            crresponding to the remote device. Will throw for unsupported
 *            scheme.
 * @param imgStoreId
 * @param nfsVersion NFS version to use in mount command
 * @return name of folder in _parent that device was mounted.
 * @throws UnknownHostException
 */
protected String mountUri(URI uri, Integer nfsVersion) throws UnknownHostException {
    String uriHostIp = getUriHostIp(uri);
    String nfsPath = uriHostIp + ":" + uri.getPath();

    // Single means of calculating mount directory regardless of scheme
    String dir = UUID.nameUUIDFromBytes(nfsPath.getBytes(com.cloud.utils.StringUtils.getPreferredCharset()))
            .toString();
    String localRootPath = _parent + "/" + dir;

    // remote device syntax varies by scheme.
    String remoteDevice;
    if (uri.getScheme().equals("cifs")) {
        remoteDevice = "//" + uriHostIp + uri.getPath();
        s_logger.debug("Mounting device with cifs-style path of " + remoteDevice);
    } else {
        remoteDevice = nfsPath;
        s_logger.debug("Mounting device with nfs-style path of " + remoteDevice);
    }
    mount(localRootPath, remoteDevice, uri, nfsVersion);
    return dir;
}

From source file:com.cloud.storage.resource.VmwareStorageProcessor.java

private static String deriveTemplateUuidOnHost(VmwareHypervisorHost hyperHost, String storeIdentifier,
        String templateName) {//from   w  ww. j av a  2  s  . c  o m
    String templateUuid;
    try {
        templateUuid = UUID.nameUUIDFromBytes(
                (templateName + "@" + storeIdentifier + "-" + hyperHost.getMor().getValue()).getBytes("UTF-8"))
                .toString();
    } catch (UnsupportedEncodingException e) {
        s_logger.warn("unexpected encoding error, using default Charset: " + e.getLocalizedMessage());
        templateUuid = UUID
                .nameUUIDFromBytes((templateName + "@" + storeIdentifier + "-" + hyperHost.getMor().getValue())
                        .getBytes(Charset.defaultCharset()))
                .toString();
    }
    templateUuid = templateUuid.replaceAll("-", "");
    return templateUuid;
}

From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java

public void revisitSignalIds(Definitions def) {
    List<RootElement> rootElements = def.getRootElements();
    for (RootElement re : rootElements) {
        if (re instanceof Signal) {
            Signal signal = (Signal) re;
            if (signal.getName() != null) {
                try {
                    signal.setId("_" + UUID.nameUUIDFromBytes(signal.getName().getBytes("UTF-8")));
                } catch (UnsupportedEncodingException e) {
                    signal.setId("_" + UUID.nameUUIDFromBytes(signal.getName().getBytes()));
                }// w w  w. j a v a 2s  . c  om
            }
        }
    }
}

From source file:org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource.java

public String postUpload(String uuid, String filename) {
    UploadEntity uploadEntity = uploadEntityStateMap.get(uuid);
    int installTimeoutPerGig = 180 * 60 * 1000;

    String resourcePath = uploadEntity.getInstallPathPrefix();
    String finalResourcePath = uploadEntity.getTmpltPath(); // template download
    UploadEntity.ResourceType resourceType = uploadEntity.getResourceType();

    String fileSavedTempLocation = uploadEntity.getInstallPathPrefix() + "/" + filename;

    String uploadedFileExtension = FilenameUtils.getExtension(filename);
    String userSelectedFormat = uploadEntity.getFormat().toString();
    if (uploadedFileExtension.equals("zip") || uploadedFileExtension.equals("bz2")
            || uploadedFileExtension.equals("gz")) {
        userSelectedFormat += "." + uploadedFileExtension;
    }/*w  w w .j a  v a2  s  . c  o  m*/
    String formatError = ImageStoreUtil.checkTemplateFormat(fileSavedTempLocation, userSelectedFormat);
    if (StringUtils.isNotBlank(formatError)) {
        String errorString = "File type mismatch between uploaded file and selected format. Selected file format: "
                + userSelectedFormat + ". Received: " + formatError;
        s_logger.error(errorString);
        return errorString;
    }

    int imgSizeGigs = getSizeInGB(_storage.getSize(fileSavedTempLocation));
    int maxSize = uploadEntity.getMaxSizeInGB();
    if (imgSizeGigs > maxSize) {
        String errorMessage = "Maximum file upload size exceeded. Physical file size: " + imgSizeGigs
                + "GB. Maximum allowed size: " + maxSize + "GB.";
        s_logger.error(errorMessage);
        return errorMessage;
    }
    imgSizeGigs++; // add one just in case
    long timeout = (long) imgSizeGigs * installTimeoutPerGig;
    Script scr = new Script(getScriptLocation(resourceType), timeout, s_logger);
    scr.add("-s", Integer.toString(imgSizeGigs));
    scr.add("-S", Long.toString(UploadEntity.s_maxTemplateSize));
    if (uploadEntity.getDescription() != null && uploadEntity.getDescription().length() > 1) {
        scr.add("-d", uploadEntity.getDescription());
    }
    if (uploadEntity.isHvm()) {
        scr.add("-h");
    }
    String checkSum = uploadEntity.getChksum();
    if (StringUtils.isNotBlank(checkSum)) {
        scr.add("-c", checkSum);
    }

    // add options common to ISO and template
    String extension = uploadEntity.getFormat().getFileExtension();
    String templateName = "";
    if (extension.equals("iso")) {
        templateName = uploadEntity.getUuid().trim().replace(" ", "_");
    } else {
        try {
            templateName = UUID
                    .nameUUIDFromBytes(
                            (uploadEntity.getFilename() + System.currentTimeMillis()).getBytes("UTF-8"))
                    .toString();
        } catch (UnsupportedEncodingException e) {
            templateName = uploadEntity.getUuid().trim().replace(" ", "_");
        }
    }

    // run script to mv the temporary template file to the final template
    // file
    String templateFilename = templateName + "." + extension;
    uploadEntity.setTemplatePath(finalResourcePath + "/" + templateFilename);
    scr.add("-n", templateFilename);

    scr.add("-t", resourcePath);
    scr.add("-f", fileSavedTempLocation); // this is the temporary
    // template file downloaded
    if (uploadEntity.getChksum() != null && uploadEntity.getChksum().length() > 1) {
        scr.add("-c", uploadEntity.getChksum());
    }
    scr.add("-u"); // cleanup
    String result;
    result = scr.execute();

    if (result != null) {
        return result;
    }

    // Set permissions for the downloaded template
    File downloadedTemplate = new File(resourcePath + "/" + templateFilename);
    _storage.setWorldReadableAndWriteable(downloadedTemplate);

    // Set permissions for template/volume.properties
    String propertiesFile = resourcePath;
    if (resourceType == UploadEntity.ResourceType.TEMPLATE) {
        propertiesFile += "/template.properties";
    } else {
        propertiesFile += "/volume.properties";
    }
    File templateProperties = new File(propertiesFile);
    _storage.setWorldReadableAndWriteable(templateProperties);

    TemplateLocation loc = new TemplateLocation(_storage, resourcePath);
    try {
        loc.create(uploadEntity.getEntityId(), true, uploadEntity.getFilename());
    } catch (IOException e) {
        s_logger.warn("Something is wrong with template location " + resourcePath, e);
        loc.purge();
        return "Unable to upload due to " + e.getMessage();
    }

    Map<String, Processor> processors = _dlMgr.getProcessors();
    for (Processor processor : processors.values()) {
        FormatInfo info = null;
        try {
            info = processor.process(resourcePath, null, templateName);
        } catch (InternalErrorException e) {
            s_logger.error("Template process exception ", e);
            return e.toString();
        }
        if (info != null) {
            loc.addFormat(info);
            uploadEntity.setVirtualSize(info.virtualSize);
            uploadEntity.setPhysicalSize(info.size);
            break;
        }
    }

    if (!loc.save()) {
        s_logger.warn("Cleaning up because we're unable to save the formats");
        loc.purge();
    }
    uploadEntity.setStatus(UploadEntity.Status.COMPLETED);
    uploadEntityStateMap.put(uploadEntity.getUuid(), uploadEntity);
    return null;
}

From source file:com.cloud.hypervisor.vmware.resource.VmwareResource.java

private static String getSecondaryDatastoreUUID(String storeUrl) {
    String uuid = null;/* w w  w .ja  v a2  s  .co  m*/
    try {
        uuid = UUID.nameUUIDFromBytes(storeUrl.getBytes("UTF-8")).toString();
    } catch (UnsupportedEncodingException e) {
        s_logger.warn(
                "Failed to create UUID from string " + storeUrl + ". Bad storeUrl or UTF-8 encoding error.");
    }
    return uuid;
}

From source file:com.cloud.hypervisor.xen.resource.CitrixResourceBase.java

protected SR createNfsSRbyURI(Connection conn, URI uri, boolean shared) {
    try {/*from w ww .  j  a  v a 2s.  c o  m*/
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Creating a " + (shared ? "shared SR for " : "not shared SR for ") + uri);
        }

        Map<String, String> deviceConfig = new HashMap<String, String>();
        String path = uri.getPath();
        path = path.replace("//", "/");
        deviceConfig.put("server", uri.getHost());
        deviceConfig.put("serverpath", path);
        String name = UUID.nameUUIDFromBytes(new String(uri.getHost() + path).getBytes()).toString();
        if (!shared) {
            Set<SR> srs = SR.getByNameLabel(conn, name);
            for (SR sr : srs) {
                SR.Record record = sr.getRecord(conn);
                if (SRType.NFS.equals(record.type) && record.contentType.equals("user") && !record.shared) {
                    removeSRSync(conn, sr);
                }
            }
        }

        Host host = Host.getByUuid(conn, _host.uuid);

        SR sr = SR.create(conn, host, deviceConfig, new Long(0), name, uri.getHost() + uri.getPath(),
                SRType.NFS.toString(), "user", shared, new HashMap<String, String>());
        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 (XenAPIException e) {
        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 (Exception e) {
        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);
    }
}

From source file:org.jbpm.designer.bpmn2.impl.Bpmn2JsonUnmarshaller.java

private String getIdForRootElement(String name) {
    String id = null;//from  w  w  w . j  av  a 2  s .  c  o m
    if (name != null && !name.isEmpty()) {
        try {
            id = "_" + UUID.nameUUIDFromBytes(name.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException uee) {
            id = "_" + UUID.nameUUIDFromBytes(name.getBytes());
        }
    } else {
        id = "_" + UUID.randomUUID();
    }

    return Utils.toBPMNIdentifier(id);
}