use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class InMemoryExploreServiceTest method testHiveIntegration.
@Test
public void testHiveIntegration() throws Exception {
String otherNamespace = "otherNamespace";
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(otherNamespace).build();
namespaceAdmin.create(namespaceMeta);
namespaceAdmin.create(new NamespaceMeta.Builder().setName(NamespaceId.DEFAULT).build());
waitForCompletionStatus(exploreService.createNamespace(namespaceMeta));
runCleanup(ImmutableList.of(NamespaceId.DEFAULT.getEntityName(), otherNamespace));
runNamespacedTest(NamespaceId.DEFAULT.getEntityName());
runNamespacedTest(otherNamespace);
runCleanup(ImmutableList.of(NamespaceId.DEFAULT.getEntityName(), otherNamespace));
waitForCompletionStatus(exploreService.deleteNamespace(new NamespaceId(otherNamespace)));
}
use of co.cask.cdap.proto.NamespaceMeta 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);
}
authorizationEnforcer.enforce(namespaceId, authenticationContext.getPrincipal(), Action.ADMIN);
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) {
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);
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class DefaultNamespaceAdmin method get.
/**
* Gets details of a namespace
*
* @param namespaceId the {@link Id.Namespace} of the requested namespace
* @return the {@link NamespaceMeta} of the requested namespace
* @throws NamespaceNotFoundException if the requested namespace is not found
* @throws UnauthorizedException if the namespace is not authorized to the logged-user
*/
@Override
public NamespaceMeta get(NamespaceId namespaceId) throws Exception {
NamespaceMeta namespaceMeta;
try {
namespaceMeta = namespaceMetaCache.get(namespaceId);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof NamespaceNotFoundException || cause instanceof IOException || cause instanceof UnauthorizedException) {
throw (Exception) cause;
}
throw e;
}
Principal principal = authenticationContext.getPrincipal();
// meta. See: CDAP-7387
if (masterShortUserName != null && masterShortUserName.equals(principal.getName())) {
return namespaceMeta;
}
Predicate<EntityId> filter = authorizationEnforcer.createFilter(principal);
if (!filter.apply(namespaceId)) {
throw new UnauthorizedException(principal, namespaceId);
}
return namespaceMeta;
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class ExistingEntitySystemMetadataWriter method write.
void write(DatasetFramework dsFramework) throws Exception {
for (NamespaceMeta namespaceMeta : namespaceQueryAdmin.list()) {
NamespaceId namespace = new NamespaceId(namespaceMeta.getName());
writeSystemMetadataForArtifacts(namespace);
writeSystemMetadataForApps(namespace);
writeSystemMetadataForDatasets(namespace, dsFramework);
writeSystemMetadataForStreams(namespace);
}
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class AbstractNamespaceQueryClient method list.
@Override
public List<NamespaceMeta> list() throws Exception {
HttpRequest request = HttpRequest.get(resolve("namespaces")).build();
HttpResponse response = execute(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return ObjectResponse.fromJsonBody(response, new TypeToken<List<NamespaceMeta>>() {
}).getResponseObject();
}
throw new IOException(String.format("Cannot list namespaces. Reason: %s", response.getResponseBodyAsString()));
}
Aggregations