@Override public EntityId apply(NamespaceMeta input) { return input.getNamespaceId(); } }, new Predicate<NamespaceMeta>() {
@Override public List<?> makeRow(NamespaceMeta object) { return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig())); } }).build();
public String getHBaseNamespace(NamespaceMeta namespaceMeta) { if (!Strings.isNullOrEmpty(namespaceMeta.getConfig().getHbaseNamespace())) { return namespaceMeta.getConfig().getHbaseNamespace(); } return toCDAPManagedHBaseNamespace(namespaceMeta.getNamespaceId()); }
@Override public void create(NamespaceMeta metadata) throws Exception { URL url = resolve(String.format("namespaces/%s", metadata.getName())); HttpResponse response = execute(HttpRequest.put(url).withBody(GSON.toJson(metadata)).build()); String responseBody = response.getResponseBodyAsString(); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { if (responseBody.equals(String.format("Namespace '%s' already exists.", metadata.getName()))) { throw new NamespaceAlreadyExistsException(metadata.getNamespaceId()); } return; } if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException("Bad request: " + responseBody); } throw new IOException(String.format("Cannot create namespace %s. Reason: %s", metadata.getName(), responseBody)); }
if (NamespaceId.DEFAULT.equals(namespaceMeta.getNamespaceId())) { return; if (Strings.isNullOrEmpty(namespaceMeta.getConfig().getHbaseNamespace())) { try (HBaseDDLExecutor executor = hBaseDDLExecutorFactory.get()) { boolean created = executor.createNamespaceIfNotExists(hbaseNamespace); if (namespaceMeta.getConfig().getGroupName() != null) { try { executor.grantPermissions(hbaseNamespace, null, ImmutableMap.of("@" + namespaceMeta.getConfig().getGroupName(), "C")); } catch (IOException | RuntimeException e) { try { super.delete(namespaceMeta.getNamespaceId()); } catch (Exception e) { t.addSuppressed(e); throw new IOException(String.format("HBase namespace '%s' specified for new namespace '%s' does not" + " exist. Please specify an existing HBase namespace.", hbaseNamespace, namespaceMeta.getName()));
@Override public boolean apply(NamespaceMeta input) { return input.getName().equals(namespaceId.getNamespace()); } });
@Override public String toString() { return "NamespaceMeta{" + "name='" + name + '\'' + ", description='" + description + '\'' + ", config=" + getConfig() + '}'; } }
Assert.fail("Should not create duplicate namespace."); } catch (NamespaceAlreadyExistsException e) { Assert.assertEquals(TEST_NAMESPACE_META1.getNamespaceId(), e.getId()); try { NamespaceMeta namespaceMeta = namespaceAdmin.get(namespaceId); Assert.assertEquals(namespaceId.getNamespace(), namespaceMeta.getName()); Assert.assertEquals("", namespaceMeta.getDescription()); Assert.assertEquals(namespaceId.getNamespace(), namespaceMeta.getName()); Assert.assertEquals("describes " + namespaceId.getNamespace(), namespaceMeta.getDescription());
private void validateCustomMapping(NamespaceMeta metadata) throws Exception { for (NamespaceMeta existingNamespaceMeta : list()) { NamespaceConfig existingConfig = existingNamespaceMeta.getConfig(); if (!Strings.isNullOrEmpty(metadata.getConfig().getHbaseNamespace()) && metadata.getConfig().getHbaseNamespace().equals(existingConfig.getHbaseNamespace())) { throw new BadRequestException(String.format("A namespace '%s' already exists with the given " + "namespace mapping for hbase namespace '%s'", existingNamespaceMeta.getName(), existingConfig.getHbaseNamespace())); if (!Strings.isNullOrEmpty(metadata.getConfig().getHiveDatabase()) && metadata.getConfig().getHiveDatabase().equals(existingConfig.getHiveDatabase())) { throw new BadRequestException(String.format("A namespace '%s' already exists with the given " + "namespace mapping for hive database '%s'", existingNamespaceMeta.getName(), existingConfig.getHiveDatabase())); if (!Strings.isNullOrEmpty(metadata.getConfig().getRootDirectory())) { validatePath(metadata.getName(), metadata.getConfig().getRootDirectory()); if (hasSubDirRelationship(existingConfig.getRootDirectory(), metadata.getConfig().getRootDirectory())) { throw new BadRequestException(String.format("Failed to create namespace %s with custom " + "location %s. A namespace '%s' already exists " + "with location '%s' and these two locations are " + "have a subdirectory relationship.", metadata.getName(), metadata.getConfig().getRootDirectory(), existingNamespaceMeta.getName(),
NamespaceMeta.Builder builder = new NamespaceMeta.Builder(existingMeta); if (namespaceMeta.getDescription() != null) { builder.setDescription(namespaceMeta.getDescription()); NamespaceConfig config = namespaceMeta.getConfig(); if (config != null && !Strings.isNullOrEmpty(config.getSchedulerQueueName())) { builder.setSchedulerQueueName(config.getSchedulerQueueName()); throw new BadRequestException("Cannot update keytab URI with an empty URI."); String existingKeytabURI = existingMeta.getConfig().getKeytabURIWithoutVersion(); if (existingKeytabURI == null) { throw new BadRequestException("Cannot update keytab URI since there is no existing principal or keytab URI."); Set<String> difference = existingMeta.getConfig().getDifference(config); if (!difference.isEmpty()) { throw new BadRequestException(String.format("Mappings %s for namespace %s cannot be updated once the namespace " +
if (NamespaceId.DEFAULT.equals(namespaceMeta.getNamespaceId())) { return; if (Strings.isNullOrEmpty(namespaceMeta.getConfig().getHbaseNamespace())) { try (HBaseDDLExecutor executor = hBaseDDLExecutorFactory.get()) { boolean created = executor.createNamespaceIfNotExists(hbaseNamespace); if (namespaceMeta.getConfig().getGroupName() != null) { try { executor.grantPermissions(hbaseNamespace, null, ImmutableMap.of("@" + namespaceMeta.getConfig().getGroupName(), "C")); } catch (IOException | RuntimeException e) { try { super.delete(namespaceMeta.getNamespaceId()); } catch (Exception e) { t.addSuppressed(e); throw new IOException(String.format("HBase namespace '%s' specified for new namespace '%s' does not" + " exist. Please specify an existing HBase namespace.", hbaseNamespace, namespaceMeta.getName()));
public String getHBaseNamespace(NamespaceMeta namespaceMeta) { if (!Strings.isNullOrEmpty(namespaceMeta.getConfig().getHbaseNamespace())) { return namespaceMeta.getConfig().getHbaseNamespace(); } return toCDAPManagedHBaseNamespace(namespaceMeta.getNamespaceId()); }
@Override public void create(NamespaceMeta metadata) throws Exception { URL url = resolve(String.format("namespaces/%s", metadata.getName())); HttpResponse response = execute(HttpRequest.put(url).withBody(GSON.toJson(metadata)).build()); String responseBody = response.getResponseBodyAsString(); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { if (responseBody.equals(String.format("Namespace '%s' already exists.", metadata.getName()))) { throw new NamespaceAlreadyExistsException(metadata.getNamespaceId()); } return; } if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException("Bad request: " + responseBody); } throw new IOException(String.format("Cannot create namespace %s. Reason: %s", metadata.getName(), responseBody)); }
@Override public boolean apply(NamespaceMeta input) { return input.getName().equals(namespaceId.getNamespace()); } });
@Override public String toString() { return "NamespaceMeta{" + "name='" + name + '\'' + ", description='" + description + '\'' + ", config=" + getConfig() + '}'; } }
private void validateCustomMapping(NamespaceMeta metadata) throws Exception { for (NamespaceMeta existingNamespaceMeta : list()) { NamespaceConfig existingConfig = existingNamespaceMeta.getConfig(); if (!Strings.isNullOrEmpty(metadata.getConfig().getHbaseNamespace()) && metadata.getConfig().getHbaseNamespace().equals(existingConfig.getHbaseNamespace())) { throw new BadRequestException(String.format("A namespace '%s' already exists with the given " + "namespace mapping for hbase namespace '%s'", existingNamespaceMeta.getName(), existingConfig.getHbaseNamespace())); if (!Strings.isNullOrEmpty(metadata.getConfig().getHiveDatabase()) && metadata.getConfig().getHiveDatabase().equals(existingConfig.getHiveDatabase())) { throw new BadRequestException(String.format("A namespace '%s' already exists with the given " + "namespace mapping for hive database '%s'", existingNamespaceMeta.getName(), existingConfig.getHiveDatabase())); if (!Strings.isNullOrEmpty(metadata.getConfig().getRootDirectory())) { validatePath(metadata.getName(), metadata.getConfig().getRootDirectory()); if (hasSubDirRelationship(existingConfig.getRootDirectory(), metadata.getConfig().getRootDirectory())) { throw new BadRequestException(String.format("Failed to create namespace %s with custom " + "location %s. A namespace '%s' already exists " + "with location '%s' and these two locations are " + "have a subdirectory relationship.", metadata.getName(), metadata.getConfig().getRootDirectory(), existingNamespaceMeta.getName(),
NamespaceMeta.Builder builder = new NamespaceMeta.Builder(existingMeta); if (namespaceMeta.getDescription() != null) { builder.setDescription(namespaceMeta.getDescription()); NamespaceConfig config = namespaceMeta.getConfig(); if (config != null && !Strings.isNullOrEmpty(config.getSchedulerQueueName())) { builder.setSchedulerQueueName(config.getSchedulerQueueName()); throw new BadRequestException("Cannot update keytab URI with an empty URI."); String existingKeytabURI = existingMeta.getConfig().getKeytabURIWithoutVersion(); if (existingKeytabURI == null) { throw new BadRequestException("Cannot update keytab URI since there is no existing principal or keytab URI."); Set<String> difference = existingMeta.getConfig().getDifference(config); if (!difference.isEmpty()) { throw new BadRequestException(String.format("Mappings %s for namespace %s cannot be updated once the namespace " +
if (NamespaceId.DEFAULT.equals(namespaceMeta.getNamespaceId())) { return QueryHandle.NO_OP; sessionHandle = openHiveSession(sessionConf); QueryHandle handle; if (Strings.isNullOrEmpty(namespaceMeta.getConfig().getHiveDatabase())) { String database = createHiveDBName(namespaceMeta.getName()); String statement = String.format("USE %s", namespaceMeta.getConfig().getHiveDatabase()); "which does not exists. Please create the database in hive " + "for the user and try creating the namespace again.", namespaceMeta.getConfig().getHiveDatabase(), namespaceMeta.getName()), e); } else { namespaceMeta.getConfig().getHiveDatabase(), namespaceMeta.getName()), e); namespaceMeta.getConfig().getHiveDatabase()); LOG.debug("Custom database {} existence verified with handle {}", namespaceMeta.getConfig().getHiveDatabase(), handle);
@Override public void update(NamespaceMeta metadata) { if (namespaces.containsKey(metadata.getNamespaceId())) { namespaces.put(metadata.getNamespaceId(), metadata); } }
@Override public Location get(NamespaceMeta namespaceMeta) throws IOException { String rootDirectory = namespaceMeta.getConfig().getRootDirectory(); if (isReservedNamespace(namespaceMeta.getNamespaceId()) || Strings.isNullOrEmpty(rootDirectory)) { // if no custom mapping was specified, then use the default namespaces location return getNonCustomMappedLocation(namespaceMeta.getNamespaceId()); } return Locations.getLocationFromAbsolutePath(locationFactory, rootDirectory); }