@Override public byte[] apply(NamespaceKey input) { return new NamespaceInternalKey(input, keyNormalization).getKey(); } }).toList();
public static byte[] getKey(NamespaceKey key) { return new NamespaceInternalKey(key).getKey(); } }
private Iterable<NameSpaceContainer> iterateEntity(final NamespaceKey rootKey) throws NamespaceException { final NamespaceInternalKey rootInternalKey = new NamespaceInternalKey(rootKey, keyNormalization); final Iterable<Map.Entry<byte[], NameSpaceContainer>> entries = namespace.find( new FindByRange<>(rootInternalKey.getRangeStartKey(), false, rootInternalKey.getRangeEndKey(), false)); return FluentIterable.from(entries).transform(input -> input.getValue()); }
@Override public boolean exists(final NamespaceKey key) { final NameSpaceContainer container = namespace.get(new NamespaceInternalKey(key).getKey()); return container != null; }
@Override public void deleteEntity(NamespaceKey entityPath) throws NamespaceException { namespace.delete(new NamespaceInternalKey(entityPath, keyNormalization).getKey()); }
@Override public Iterable<NamespaceKey> getAllDatasets(final NamespaceKey root) throws NamespaceException { final NameSpaceContainer rootContainer = namespace.get(new NamespaceInternalKey(root, keyNormalization).getKey()); if (rootContainer == null) { return Collections.emptyList(); } if (!isListable(rootContainer.getType())) { return Collections.emptyList(); } return () -> new LazyIteratorOverDatasets(root); }
@Override public boolean exists(final NamespaceKey key, final Type type) { final NameSpaceContainer container = namespace.get(new NamespaceInternalKey(key, keyNormalization).getKey()); return container != null && container.getType() == type; }
/** * Helper method that returns the list of the namespace entities on the given path. Except the last entity on the path * all other entities should return a non-null value. * * @param entityPath * @return */ protected List<NameSpaceContainer> getEntitiesOnPath(NamespaceKey entityPath) throws NamespaceException { final List<byte[]> keys = Lists.newArrayListWithExpectedSize(entityPath.getPathComponents().size()); NamespaceKey currentPath = entityPath; for (int i = 0; i < entityPath.getPathComponents().size(); i++) { keys.add(new NamespaceInternalKey(currentPath, keyNormalization).getKey()); if (currentPath.hasParent()) { currentPath = currentPath.getParent(); } } // reverse the keys so that the order of keys is from root to leaf level entity. Collections.reverse(keys); final List<NameSpaceContainer> entitiesOnPath = namespace.get(keys); for (int i = 0; i < entitiesOnPath.size() - 1; i++) { if (entitiesOnPath.get(i) == null) { throw new NamespaceNotFoundException(entityPath, "one or more elements on the path are not found in namespace"); } } return entitiesOnPath; }
protected NameSpaceContainer doDeleteEntity(final NamespaceKey path, final Type type, String version, List<NameSpaceContainer> entitiesOnPath, boolean deleteRoot) throws NamespaceException { final NamespaceInternalKey key = new NamespaceInternalKey(path, keyNormalization); final NameSpaceContainer container = lastElement(entitiesOnPath); traverseAndDeleteChildren(key, container); if(deleteRoot) { namespace.delete(key.getKey(), version); } return container; }
public static NamespaceInternalKey parseKey(byte[] keyBytes) { String path = extractKey(keyBytes, false); return new NamespaceInternalKey(new NamespaceKey(PathUtils.parseFullPath(path))); }
@Override public boolean tryCreatePhysicalDataset(NamespaceKey datasetPath, DatasetConfig datasetConfig, NamespaceAttribute... attributes) throws NamespaceException { if (createSourceFolders(datasetPath)) { datasetConfig.setSchemaVersion(DatasetHelper.CURRENT_VERSION); final NamespaceInternalKey searchKey = new NamespaceInternalKey(datasetPath, keyNormalization); NameSpaceContainer existingContainer = namespace.get(searchKey.getKey()); return doTryCreatePhysicalDataset(datasetPath, datasetConfig, searchKey, existingContainer, attributes); } return false; }
private static NamespaceInternalKey newKey(String path) { return new NamespaceInternalKey(new NamespaceKey(PathUtils.parseFullPath(path))); } }
List<String> fullPathList = components.subList(0, i + 1); NamespaceKey key = new NamespaceKey(fullPathList); final NamespaceInternalKey keyInternal = new NamespaceInternalKey(key, keyNormalization); NameSpaceContainer folderContainer = namespace.get(keyInternal.getKey());
/** * Helper method that converts the given object into a {@link NamespaceEntity} */ static NamespaceEntity toEntity(Type type, NamespaceKey path, Object config, boolean keyNormalization) { final NameSpaceContainer container = new NameSpaceContainer(); final NamespaceInternalKey namespaceInternalKey = new NamespaceInternalKey(path, keyNormalization); container.setType(type); switch (type) { case DATASET: container.setDataset((DatasetConfig) config); break; case FOLDER: container.setFolder((FolderConfig) config); break; case HOME: container.setHome((HomeConfig) config); break; case SOURCE: container.setSource((SourceConfig) config); break; case SPACE: container.setSpace((SpaceConfig) config); break; default: throw new UnsupportedOperationException("Unknown type: " + type); } container.setFullPathList(path.getPathComponents()); return new NamespaceEntity(namespaceInternalKey, container); } }
protected void doTraverseAndDeleteChildren(final NameSpaceContainer child) throws NamespaceException { final NamespaceInternalKey childKey = new NamespaceInternalKey(new NamespaceKey(child.getFullPathList()), keyNormalization); traverseAndDeleteChildren(childKey, child); switch (child.getType()) { case FOLDER: namespace.delete(childKey.getKey(), child.getFolder().getTag()); break; case DATASET: namespace.delete(childKey.getKey(), child.getDataset().getTag()); break; default: // Only leaf level or intermediate namespace container types are expected here. throw new RuntimeException("Unexpected namespace container type: " + child.getType()); } }
protected DatasetConfig doRenameDataset(NamespaceKey oldDatasetPath, NamespaceKey newDatasetPath, List<NameSpaceContainer> oldDatasetParentEntitiesOnPath, List<NameSpaceContainer> newDatasetParentEntitiesOnPath) throws NamespaceException { final String newDatasetName = newDatasetPath.getName(); final NamespaceInternalKey oldKey = new NamespaceInternalKey(oldDatasetPath, keyNormalization); final DatasetConfig datasetConfig = getEntity(oldDatasetPath, DATASET).getDataset(); if (isPhysicalDataset(datasetConfig.getType())) { throw UserException.validationError() .message("Failed to rename %s to %s. Renames on physical datasets are not allowed.", oldDatasetPath, newDatasetPath) .build(logger); } if (datasetConfig.getType() == DatasetType.PHYSICAL_DATASET_HOME_FILE && !newDatasetPath.getPathComponents().get(0).startsWith("@")) { throw UserException.validationError() .message("Failed to rename %s to %s. You cannot move a uploaded file in your home directory to a space.", oldDatasetPath, newDatasetPath) .build(logger); } datasetConfig.setName(newDatasetName); datasetConfig.setFullPathList(newDatasetPath.getPathComponents()); datasetConfig.setCreatedAt(System.currentTimeMillis()); NamespaceEntity newValue = NamespaceEntity.toEntity(DATASET, newDatasetPath, datasetConfig, keyNormalization); // in case of upgrade we may have a version here from previous versions, so clear out datasetConfig.setVersion(null); datasetConfig.setTag(null); namespace.put(newValue.getPathKey().getKey(), newValue.getContainer()); namespace.delete(oldKey.getKey()); return datasetConfig; }
isPhysicalDataset(newOrUpdatedEntity.getContainer().getDataset().getType()) && existingContainer.getType() == FOLDER) { namespace.delete((new NamespaceInternalKey(new NamespaceKey(existingContainer.getFullPathList()), keyNormalization)).getKey(), existingContainer.getFolder().getTag()); return false;