Search in sources :

Example 31 with NamespaceMeta

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)));
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 32 with NamespaceMeta

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);
}
Also used : NamespaceConfig(co.cask.cdap.proto.NamespaceConfig) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) CacheBuilder(com.google.common.cache.CacheBuilder) BadRequestException(co.cask.cdap.common.BadRequestException) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException)

Example 33 with NamespaceMeta

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;
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) Principal(co.cask.cdap.proto.security.Principal)

Example 34 with 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);
    }
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 35 with NamespaceMeta

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()));
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) TypeToken(com.google.common.reflect.TypeToken) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) HttpResponse(co.cask.common.http.HttpResponse) IOException(java.io.IOException)

Aggregations

NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)58 NamespaceId (co.cask.cdap.proto.id.NamespaceId)26 Test (org.junit.Test)22 IOException (java.io.IOException)12 Location (org.apache.twill.filesystem.Location)6 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)5 BadRequestException (co.cask.cdap.common.BadRequestException)5 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)5 ApplicationManager (co.cask.cdap.test.ApplicationManager)5 ExecutionException (java.util.concurrent.ExecutionException)5 NamespaceConfig (co.cask.cdap.proto.NamespaceConfig)4 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)4 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 RowMaker (co.cask.cdap.cli.util.RowMaker)3 Table (co.cask.cdap.cli.util.table.Table)3 NotFoundException (co.cask.cdap.common.NotFoundException)3 CConfiguration (co.cask.cdap.common.conf.CConfiguration)3 NamespaceAdmin (co.cask.cdap.common.namespace.NamespaceAdmin)3 Id (co.cask.cdap.proto.Id)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3