List of usage examples for java.util UUID nameUUIDFromBytes
public static UUID nameUUIDFromBytes(byte[] name)
From source file:org.apache.flink.table.runtime.functions.SqlFunctionUtils.java
public static String uuid(byte[] b) { return UUID.nameUUIDFromBytes(b).toString(); }
From source file:org.apache.nifi.remote.StandardRemoteProcessGroup.java
private String generatePortId(final String targetId) { return UUID.nameUUIDFromBytes((this.getIdentifier() + targetId).getBytes(StandardCharsets.UTF_8)) .toString();/*from w w w . ja v a2 s . com*/ }
From source file:org.apache.nifi.controller.StandardFlowService.java
/** * In NiFi 0.x, templates were stored in a templates directory as separate * files. They are now stored in the flow itself. If there already are * templates in that directory, though, we want to restore them. * * @return the templates found in the templates directory * @throws IOException if unable to read from the file system */// ww w .j a v a 2s . com public List<Template> loadTemplates() throws IOException { final Path templatePath = nifiProperties.getTemplateDirectory(); final File[] files = templatePath.toFile().listFiles(pathname -> { final String lowerName = pathname.getName().toLowerCase(); return lowerName.endsWith(".template") || lowerName.endsWith(".xml"); }); if (files == null) { return Collections.emptyList(); } final List<Template> templates = new ArrayList<>(); for (final File file : files) { try (final FileInputStream fis = new FileInputStream(file); final BufferedInputStream bis = new BufferedInputStream(fis)) { final TemplateDTO templateDto; try { templateDto = TemplateDeserializer.deserialize(bis); } catch (final Exception e) { logger.error("Unable to interpret " + file + " as a Template. Skipping file."); continue; } if (templateDto.getId() == null) { // If there is no ID assigned, we need to assign one. We do this by generating // an ID from the name. This is because we know that Template Names are unique // and are consistent across all nodes in the cluster. final String uuid = UUID .nameUUIDFromBytes(templateDto.getName().getBytes(StandardCharsets.UTF_8)).toString(); templateDto.setId(uuid); } final Template template = new Template(templateDto); templates.add(template); } } return templates; }
From source file:org.apache.nifi.authorization.FileAuthorizer.java
/** * Finds the Group with the given name, or creates a new one and adds it to Tenants. * * @param tenants the Tenants reference/*ww w . ja v a 2 s.co m*/ * @param groupName the name of the group to look for * @return the Group from Tenants with the given name, or a new instance that was added to Tenants */ private org.apache.nifi.authorization.file.tenants.generated.Group getOrCreateGroup(final Tenants tenants, final String groupName) { if (StringUtils.isBlank(groupName)) { return null; } org.apache.nifi.authorization.file.tenants.generated.Group foundGroup = null; for (org.apache.nifi.authorization.file.tenants.generated.Group group : tenants.getGroups().getGroup()) { if (group.getName().equals(groupName)) { foundGroup = group; break; } } if (foundGroup == null) { UUID newGroupIdentifier = UUID.nameUUIDFromBytes(groupName.getBytes(StandardCharsets.UTF_8)); foundGroup = new org.apache.nifi.authorization.file.tenants.generated.Group(); foundGroup.setIdentifier(newGroupIdentifier.toString()); foundGroup.setName(groupName); tenants.getGroups().getGroup().add(foundGroup); } return foundGroup; }
From source file:org.apache.nifi.authorization.FileAuthorizer.java
/** * Finds the Policy matching the resource and action, or creates a new one and adds it to the list of policies. * * @param policies the policies to search through * @param seedIdentity the seedIdentity to use when creating identifiers for new policies * @param resource the resource for the policy * @param action the action string for the police (R or RW) * @return the matching policy or a new policy *//*www. j a v a 2 s .c o m*/ private Policy getOrCreatePolicy(final List<Policy> policies, final String seedIdentity, final String resource, final String action) { Policy foundPolicy = null; // try to find a policy with the same resource and actions for (Policy policy : policies) { if (policy.getResource().equals(resource) && policy.getAction().equals(action)) { foundPolicy = policy; break; } } // if a matching policy wasn't found then create one if (foundPolicy == null) { final String uuidSeed = resource + action + seedIdentity; final UUID policyIdentifier = UUID.nameUUIDFromBytes(uuidSeed.getBytes(StandardCharsets.UTF_8)); foundPolicy = new Policy(); foundPolicy.setIdentifier(policyIdentifier.toString()); foundPolicy.setResource(resource); foundPolicy.setAction(action); policies.add(foundPolicy); } return foundPolicy; }
From source file:org.apache.nifi.authorization.FileAuthorizer.java
/** * Creates and adds an access policy for the given resource, identity, and actions. * * @param authorizations the Authorizations instance to add the policy to * @param resource the resource for the policy * @param identity the identity for the policy * @param action the action for the policy */// w w w. ja v a 2 s .co m private void addAccessPolicy(final Authorizations authorizations, final String resource, final String identity, final String action) { // first try to find an existing policy for the given resource and action Policy foundPolicy = null; for (Policy policy : authorizations.getPolicies().getPolicy()) { if (policy.getResource().equals(resource) && policy.getAction().equals(action)) { foundPolicy = policy; break; } } if (foundPolicy == null) { // if we didn't find an existing policy create a new one final String uuidSeed = resource + identity + action; final UUID policyIdentifier = UUID.nameUUIDFromBytes(uuidSeed.getBytes(StandardCharsets.UTF_8)); final AccessPolicy.Builder builder = new AccessPolicy.Builder().identifier(policyIdentifier.toString()) .resource(resource).addUser(identity); if (action.equals(READ_CODE)) { builder.action(RequestAction.READ); } else if (action.equals(WRITE_CODE)) { builder.action(RequestAction.WRITE); } else { throw new IllegalStateException("Unknown Policy Action: " + action); } final AccessPolicy accessPolicy = builder.build(); final Policy jaxbPolicy = createJAXBPolicy(accessPolicy); authorizations.getPolicies().getPolicy().add(jaxbPolicy); } else { // otherwise add the user to the existing policy Policy.User policyUser = new Policy.User(); policyUser.setIdentifier(identity); foundPolicy.getUser().add(policyUser); } }
From source file:com.cloud.user.AccountManagerImpl.java
@Override @DB/*from ww w . j a v a 2 s . c o m*/ @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_CREATE, eventDescription = "creating Account") public UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain, Map<String, String> details) { if (accountName == null) { accountName = userName; } if (domainId == null) { domainId = DomainVO.ROOT_DOMAIN; } if (userName.isEmpty()) { throw new InvalidParameterValueException("Username is empty"); } if (firstName.isEmpty()) { throw new InvalidParameterValueException("Firstname is empty"); } if (lastName.isEmpty()) { throw new InvalidParameterValueException("Lastname is empty"); } // Validate domain Domain domain = _domainMgr.getDomain(domainId); if (domain == null) { throw new InvalidParameterValueException( "The domain " + domainId + " does not exist; unable to create account"); } // Check permissions checkAccess(UserContext.current().getCaller(), domain); if (!_userAccountDao.validateUsernameInDomain(userName, domainId)) { throw new InvalidParameterValueException( "The user " + userName + " already exists in domain " + domainId); } if (networkDomain != null) { if (!NetUtils.verifyDomainName(networkDomain)) { throw new InvalidParameterValueException( "Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " + "and the hyphen ('-'); can't start or end with \"-\""); } } Transaction txn = Transaction.currentTxn(); txn.start(); // create account Account account = createAccount(accountName, accountType, domainId, networkDomain, details); long accountId = account.getId(); // create the first user for the account UserVO user = createUser(accountId, userName, password, firstName, lastName, email, timezone); if (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { // set registration token byte[] bytes = (domainId + accountName + userName + System.currentTimeMillis()).getBytes(); String registrationToken = UUID.nameUUIDFromBytes(bytes).toString(); user.setRegistrationToken(registrationToken); } txn.commit(); return _userAccountDao.findById(user.getId()); }
From source file:org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.java
private String generateRecordIdFromPrimaryKeyValues(Map<String, Object> values, List<String> primaryKeys) { StringBuilder builder = new StringBuilder(); Object obj;//from w w w . j av a2 s . com for (String key : primaryKeys) { obj = values.get(key); if (obj != null) { builder.append(obj.toString()); } } /* to make sure, we don't have an empty string */ builder.append(""); try { byte[] data = builder.toString().getBytes(Constants.DEFAULT_CHARSET); return UUID.nameUUIDFromBytes(data).toString(); } catch (UnsupportedEncodingException e) { /* this wouldn't happen */ throw new RuntimeException(e); } }
From source file:com.cloud.hypervisor.xen.resource.Xenserver625StorageProcessor.java
@Override public Answer createTemplateFromSnapshot(CopyCommand cmd) { Connection conn = hypervisorResource.getConnection(); DataTO srcData = cmd.getSrcTO();// www.j a va 2s.co m DataTO destData = cmd.getDestTO(); int wait = cmd.getWait(); SnapshotObjectTO srcObj = (SnapshotObjectTO) srcData; TemplateObjectTO destObj = (TemplateObjectTO) destData; NfsTO srcStore = (NfsTO) srcObj.getDataStore(); NfsTO destStore = (NfsTO) destObj.getDataStore(); URI srcUri = null; URI destUri = null; try { srcUri = new URI(srcStore.getUrl()); destUri = new URI(destStore.getUrl()); } catch (Exception e) { s_logger.debug("incorrect url", e); return new CopyCmdAnswer("incorrect url" + e.toString()); } String srcPath = srcObj.getPath(); int index = srcPath.lastIndexOf("/"); String srcDir = srcPath.substring(0, index); 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); String destNfsPath = destUri.getHost() + ":" + destUri.getPath(); 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); String nameLabel = "cloud-" + UUID.randomUUID().toString(); String[] parents = srcObj.getParents(); List<VDI> snapshotChains = new ArrayList<VDI>(); if (parents != null) { for (int i = 0; i < parents.length; i++) { String snChainPath = parents[i]; String uuid = getSnapshotUuid(snChainPath); VDI chain = VDI.getByUuid(conn, uuid); snapshotChains.add(chain); } } String snapshotUuid = getSnapshotUuid(srcPath); VDI snapshotVdi = VDI.getByUuid(conn, snapshotUuid); snapshotChains.add(snapshotVdi); long templateVirtualSize = snapshotChains.get(0).getVirtualSize(conn); destVdi = createVdi(conn, nameLabel, destSr, templateVirtualSize); String destVdiUuid = destVdi.getUuid(conn); for (VDI snapChain : snapshotChains) { Task task = snapChain.copyAsync2(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); String templatePath = destDir + "/" + destVdiUuid + ".vhd"; templatePath = templatePath.replaceAll("//", "/"); TemplateObjectTO newTemplate = new TemplateObjectTO(); newTemplate.setPath(templatePath); 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 (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 (Exception e) { s_logger.debug("Clean up left over on dest storage failed: ", e); } } } if (destSr != null) { hypervisorResource.removeSR(conn, destSr); } if (srcSr != null) { hypervisorResource.removeSR(conn, srcSr); } } }
From source file:org.codice.alliance.nsili.common.ResultDAGConverter.java
private static UUID getUUIDFromCard(String id) { UUID uuid = null;/*from www . j a v a2 s . co m*/ try { if (id.contains("-")) { uuid = UUID.fromString(id); } else if (id.length() == 32) { //Attempt to parse as a UUID with no dashes StringBuilder sb = new StringBuilder(id); sb.insert(8, "-"); sb.insert(13, "-"); sb.insert(18, "-"); sb.insert(23, "-"); uuid = UUID.fromString(sb.toString()); } } catch (Exception e) { } //If parsing fails, get a v3 UUID from the bytes of the metacard ID if (uuid == null) { uuid = UUID.nameUUIDFromBytes(id.getBytes()); } return uuid; }