protected void doCreateOrUpdateEntity(final NamespaceEntity entity, List<NameSpaceContainer> entitiesOnPath, NamespaceAttribute... attributes) throws NamespaceException { final NameSpaceContainer prevContainer = lastElement(entitiesOnPath); ensureIdExistsTypeMatches(entity, prevContainer); namespace.put(entity.getPathKey().getKey(), entity.getContainer()); }
@Override public void addOrUpdateSource(NamespaceKey sourcePath, SourceConfig sourceConfig, NamespaceAttribute... attributes) throws NamespaceException { createOrUpdateEntity(NamespaceEntity.toEntity(SOURCE, sourcePath, sourceConfig, keyNormalization), attributes); }
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; }
/** * Helper method which creates a new entity or update the existing entity with given entity * * @param entity * @throws NamespaceException */ private void createOrUpdateEntity(final NamespaceEntity entity, NamespaceAttribute... attributes) throws NamespaceException { final NamespaceKey entityPath = entity.getPathKey().getPath(); final List<NameSpaceContainer> entitiesOnPath = getEntitiesOnPath(entityPath); doCreateOrUpdateEntity(entity, entitiesOnPath, attributes); }
/** * 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); } }
final String idInContainer = getId(newOrUpdatedEntity.getContainer()); setId(newOrUpdatedEntity.getContainer(), UUID.randomUUID().toString()); return true; if (newOrUpdatedEntity.getContainer().getType() == DATASET && isPhysicalDataset(newOrUpdatedEntity.getContainer().getDataset().getType()) && existingContainer.getType() == FOLDER) { namespace.delete((new NamespaceInternalKey(new NamespaceKey(existingContainer.getFullPathList()), keyNormalization)).getKey(), final String newVersion = extractor.getTag(newOrUpdatedEntity.getContainer()); final String oldVersion = extractor.getTag(existingContainer); if(!Objects.equals(newVersion, oldVersion)) { newOrUpdatedEntity.getContainer().getType() != existingContainer.getType() || existingContainer.getType(), newOrUpdatedEntity.getPathKey().getPath()) .build(logger);
@Override public void addOrUpdateHome(NamespaceKey homePath, HomeConfig homeConfig) throws NamespaceException { createOrUpdateEntity(NamespaceEntity.toEntity(HOME, homePath, homeConfig, keyNormalization)); }
@Override public void addOrUpdateSpace(NamespaceKey spacePath, SpaceConfig spaceConfig, NamespaceAttribute... attributes) throws NamespaceException { createOrUpdateEntity(NamespaceEntity.toEntity(SPACE, spacePath, spaceConfig, keyNormalization), attributes); }
@Override public void addOrUpdateFolder(NamespaceKey folderPath, FolderConfig folderConfig, NamespaceAttribute... attributes) throws NamespaceException { createOrUpdateEntity(NamespaceEntity.toEntity(FOLDER, folderPath, folderConfig, keyNormalization), attributes); }
createOrUpdateEntity(NamespaceEntity.toEntity(DATASET, datasetPath, dataset, keyNormalization), attributes);