use of io.cdap.cdap.proto.NamespaceConfig in project cdap by caskdata.
the class DistributedStorageProviderNamespaceAdmin method delete.
@SuppressWarnings("ConstantConditions")
@Override
public void delete(NamespaceId namespaceId) throws IOException, ExploreException, SQLException {
// delete namespace directory from filesystem
super.delete(namespaceId);
if (NamespaceId.DEFAULT.equals(namespaceId)) {
return;
}
// delete HBase namespace
NamespaceConfig namespaceConfig;
try {
namespaceConfig = namespaceQueryAdmin.get(namespaceId).getConfig();
} catch (Exception ex) {
throw new IOException("Could not fetch custom HBase mapping.", ex);
}
if (!Strings.isNullOrEmpty(namespaceConfig.getHbaseNamespace())) {
// custom namespace mapping is set for HBase, hence don't do anything during delete since the lifecycle of the
// namespace will be managed by the user
LOG.debug("Custom HBase mapping {} was found while deleting {}. Hence skipping deletion of HBase namespace", namespaceConfig.getHbaseNamespace(), namespaceId);
return;
}
// delete HBase namespace
String namespace = tableUtil.getHBaseNamespace(namespaceId);
try (HBaseDDLExecutor executor = hBaseDDLExecutorFactory.get()) {
executor.deleteNamespaceIfExists(namespace);
}
}
use of io.cdap.cdap.proto.NamespaceConfig in project cdap by caskdata.
the class SchedulerQueueResolver method getQueue.
/**
* Get queue at namespace level if it is empty returns the default queue.
*
* @param namespaceId NamespaceId
* @return schedule queue at namespace level or default queue.
*/
@Nullable
public String getQueue(NamespaceId namespaceId) throws IOException, NamespaceNotFoundException {
if (namespaceId.equals(NamespaceId.SYSTEM)) {
return systemQueue;
}
NamespaceMeta meta;
try {
meta = namespaceQueryAdmin.get(namespaceId);
} catch (NamespaceNotFoundException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
if (meta != null) {
NamespaceConfig config = meta.getConfig();
String namespaceQueue = config.getSchedulerQueueName();
return Strings.isNullOrEmpty(namespaceQueue) ? getDefaultQueue() : namespaceQueue;
} else {
return getDefaultQueue();
}
}
use of io.cdap.cdap.proto.NamespaceConfig in project cdap by caskdata.
the class DefaultOwnerAdmin method getImpersonationInfo.
@Nullable
@Override
public ImpersonationInfo getImpersonationInfo(NamespacedEntityId entityId) throws AccessException {
try {
entityId = getEffectiveEntity(entityId);
if (!entityId.getEntityType().equals(EntityType.NAMESPACE)) {
KerberosPrincipalId effectiveOwner = ownerStore.getOwner(entityId);
if (effectiveOwner != null) {
return new ImpersonationInfo(effectiveOwner.getPrincipal(), SecurityUtil.getKeytabURIforPrincipal(effectiveOwner.getPrincipal(), cConf));
}
}
// (CDAP-8176) Since no owner was found for the entity return namespace principal if present.
NamespaceConfig nsConfig = getNamespaceConfig(entityId.getNamespaceId());
return nsConfig.getPrincipal() == null ? null : new ImpersonationInfo(nsConfig.getPrincipal(), nsConfig.getKeytabURI());
} catch (IOException e) {
throw AuthEnforceUtil.propagateAccessException(e);
}
}
use of io.cdap.cdap.proto.NamespaceConfig in project cdap by caskdata.
the class NamespaceHttpHandlerTest method testProperties.
@Test
public void testProperties() throws Exception {
// create a namespace with principal
String nsPrincipal = "nsCreator/somehost.net@somekdc.net";
String nsKeytabURI = "some/path";
NamespaceMeta impNsMeta = new NamespaceMeta.Builder().setName(NAME).setPrincipal(nsPrincipal).setKeytabURI(nsKeytabURI).build();
HttpResponse response = createNamespace(GSON.toJson(impNsMeta), impNsMeta.getName());
assertResponseCode(200, response);
// verify
response = getNamespace(NAME);
JsonObject namespace = readGetResponse(response);
Assert.assertNotNull(namespace);
Assert.assertEquals(NAME, namespace.get(NAME_FIELD).getAsString());
Assert.assertEquals(EMPTY, namespace.get(DESCRIPTION_FIELD).getAsString());
// Update scheduler queue name.
String nonexistentName = NAME + "nonexistent";
NamespaceMeta meta = new NamespaceMeta.Builder(impNsMeta).setName(nonexistentName).setSchedulerQueueName("prod").build();
setProperties(NAME, meta);
// assert that the name in the metadata is ignored (the name from the url should be used, instead
HttpResponse nonexistentGet = getNamespace(nonexistentName);
Assert.assertEquals(404, nonexistentGet.getResponseCode());
response = getNamespace(NAME);
namespace = readGetResponse(response);
Assert.assertNotNull(namespace);
NamespaceConfig config = GSON.fromJson(namespace.get(CONFIG_FIELD).getAsJsonObject(), NamespaceConfig.class);
Assert.assertEquals("prod", config.getSchedulerQueueName());
Assert.assertEquals(NAME, namespace.get(NAME_FIELD).getAsString());
Assert.assertEquals(EMPTY, namespace.get(DESCRIPTION_FIELD).getAsString());
// Update description
meta = new NamespaceMeta.Builder(impNsMeta).setName(NAME).setDescription("new fancy description").build();
setProperties(NAME, meta);
response = getNamespace(NAME);
namespace = readGetResponse(response);
Assert.assertNotNull(namespace);
// verify that the description has changed
Assert.assertEquals("new fancy description", namespace.get(DESCRIPTION_FIELD).getAsString());
Assert.assertEquals(NAME, namespace.get(NAME_FIELD).getAsString());
// verify other properties set earlier has not changed.
config = GSON.fromJson(namespace.get(CONFIG_FIELD).getAsJsonObject(), NamespaceConfig.class);
Assert.assertEquals("prod", config.getSchedulerQueueName());
// verify updating keytab URI with version initialized
setProperties(NAME, new NamespaceMeta.Builder(impNsMeta).setKeytabURI("new/url").build());
response = getNamespace(NAME);
namespace = readGetResponse(response);
Assert.assertNotNull(namespace);
config = GSON.fromJson(namespace.get(CONFIG_FIELD).getAsJsonObject(), NamespaceConfig.class);
// verify that the uri has changed
Assert.assertEquals("new/url", config.getKeytabURI());
// cleanup
response = deleteNamespace(NAME);
Assert.assertEquals(200, response.getResponseCode());
}
use of io.cdap.cdap.proto.NamespaceConfig in project cdap by caskdata.
the class DefaultNamespaceAdmin method updateProperties.
@Override
public synchronized void updateProperties(NamespaceId namespaceId, NamespaceMeta namespaceMeta) throws Exception {
if (!exists(namespaceId)) {
throw new NamespaceNotFoundException(namespaceId);
}
accessEnforcer.enforce(namespaceId, authenticationContext.getPrincipal(), StandardPermission.UPDATE);
NamespaceMeta existingMeta = nsStore.get(namespaceId);
// Already ensured that namespace exists, so namespace meta should not be null
Preconditions.checkNotNull(existingMeta);
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());
}
if (config != null && config.getKeytabURI() != null) {
String keytabURI = config.getKeytabURI();
if (keytabURI.isEmpty()) {
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.");
}
if (keytabURI.equals(existingKeytabURI)) {
// The given keytab URI is the same as the existing one, but the content of the keytab file might be changed.
// Increment the keytab URI version so that the cache will reload content in the updated keytab file.
builder.incrementKeytabURIVersion();
} else {
builder.setKeytabURIWithoutVersion(keytabURI);
// clear keytab URI version
builder.setKeytabURIVersion(0);
}
}
if (config != null) {
builder.setExploreAsPrincipal(config.isExploreAsPrincipal());
}
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 " + "is created.", difference, namespaceId));
}
NamespaceMeta updatedMeta = builder.build();
nsStore.update(updatedMeta);
// refresh the cache with new meta
namespaceMetaCache.refresh(namespaceId);
LOG.info("Namespace {} updated with meta {}", namespaceId, updatedMeta);
}
Aggregations