Search in sources :

Example 66 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class RemoteNamespaceQueryTest method testCustomNS.

@Test
public void testCustomNS() throws Exception {
    String cdapNamespace = "NS1";
    String hbaseNamespace = "custHBase";
    String rootDirectory = "/directory";
    String hiveDb = "myHive";
    String schedulerQueue = "schQ";
    String description = "Namespace with custom HBase mapping";
    NamespaceConfig namespaceConfig = new NamespaceConfig(schedulerQueue, rootDirectory, hbaseNamespace, hiveDb, null, null, null);
    NamespaceMeta meta = new NamespaceMeta.Builder().setName(cdapNamespace).setDescription(description).setSchedulerQueueName(schedulerQueue).setRootDirectory(rootDirectory).setHBaseNamespace(hbaseNamespace).setHiveDatabase(hiveDb).build();
    // create the ns location since admin expect it to exists
    Location nsLocation = namespacePathLocator.get(meta);
    nsLocation.mkdirs();
    namespaceAdmin.create(meta);
    NamespaceId namespaceId = new NamespaceId(cdapNamespace);
    Assert.assertTrue(queryClient.exists(namespaceId));
    NamespaceMeta resultMeta = queryClient.get(namespaceId);
    Assert.assertEquals(namespaceConfig, resultMeta.getConfig());
    namespaceAdmin.delete(namespaceId);
    Assert.assertFalse(queryClient.exists(namespaceId));
}
Also used : NamespaceConfig(io.cdap.cdap.proto.NamespaceConfig) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 67 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class NamespaceHttpHandler method updateNamespaceProperties.

@PUT
@Path("/namespaces/{namespace-id}/properties")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void updateNamespaceProperties(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
    NamespaceMeta meta = getNamespaceMeta(request);
    namespaceAdmin.updateProperties(new NamespaceId(namespaceId), meta);
    responder.sendString(HttpResponseStatus.OK, String.format("Updated properties for namespace '%s'.", namespaceId));
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) AuditPolicy(io.cdap.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 68 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class NamespaceHttpHandler method create.

@PUT
@Path("/namespaces/{namespace-id}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void create(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
    NamespaceId namespace;
    try {
        namespace = new NamespaceId(namespaceId);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Namespace id can contain only alphanumeric characters or '_'.");
    }
    NamespaceMeta metadata = getNamespaceMeta(request);
    if (NamespaceId.isReserved(namespaceId)) {
        throw new BadRequestException(String.format("Cannot create the namespace '%s'. '%s' is a reserved namespace.", namespaceId, namespaceId));
    }
    NamespaceMeta.Builder builder = metadata == null ? new NamespaceMeta.Builder() : new NamespaceMeta.Builder(metadata);
    builder.setName(namespace);
    builder.setGeneration(System.currentTimeMillis());
    NamespaceMeta finalMetadata = builder.build();
    try {
        namespaceAdmin.create(finalMetadata);
        responder.sendString(HttpResponseStatus.OK, String.format("Namespace '%s' created successfully.", namespaceId));
    } catch (AlreadyExistsException e) {
        responder.sendString(HttpResponseStatus.OK, String.format("Namespace '%s' already exists.", namespaceId));
    }
}
Also used : AlreadyExistsException(io.cdap.cdap.common.AlreadyExistsException) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) BadRequestException(io.cdap.cdap.common.BadRequestException) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) AuditPolicy(io.cdap.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 69 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class PropertiesResolver method addNamespaceConfigs.

private void addNamespaceConfigs(Map<String, String> args, NamespaceId namespaceId) throws NamespaceNotFoundException, IOException {
    if (NamespaceId.isReserved(namespaceId.getNamespace())) {
        return;
    }
    try {
        NamespaceMeta namespaceMeta = namespaceQueryAdmin.get(namespaceId);
        SystemArguments.addNamespaceConfigs(args, namespaceMeta.getConfig());
        args.put(Constants.AppFabric.APP_SCHEDULER_QUEUE, queueResolver.getQueue(namespaceMeta));
    } catch (NamespaceNotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) IOException(java.io.IOException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) AccessException(io.cdap.cdap.api.security.AccessException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException)

Example 70 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class CapabilityApplier method doForAllAppsWithCapability.

// Find all applications for capability and call consumer for each
private void doForAllAppsWithCapability(String capability, CheckedConsumer<ApplicationId> consumer) throws Exception {
    for (NamespaceMeta namespaceMeta : namespaceAdmin.list()) {
        int offset = 0;
        int limit = 100;
        NamespaceId namespaceId = namespaceMeta.getNamespaceId();
        EntityResult<ApplicationId> results = getApplications(namespaceId, capability, null, offset, limit);
        while (!results.getEntities().isEmpty()) {
            // call consumer for each entity
            for (ApplicationId entity : results.getEntities()) {
                consumer.accept(entity);
            }
            offset += limit;
            results = getApplications(namespaceId, capability, results.getCursor(), offset, limit);
        }
    }
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Aggregations

NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)144 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)76 Test (org.junit.Test)54 IOException (java.io.IOException)30 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)18 BadRequestException (io.cdap.cdap.common.BadRequestException)14 NotFoundException (io.cdap.cdap.common.NotFoundException)14 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)14 DatasetId (io.cdap.cdap.proto.id.DatasetId)14 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)14 EntityId (io.cdap.cdap.proto.id.EntityId)12 GrantedPermission (io.cdap.cdap.proto.security.GrantedPermission)12 Location (org.apache.twill.filesystem.Location)12 Set (java.util.Set)11 ImmutableSet (com.google.common.collect.ImmutableSet)10 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)10 PartitionedFileSet (io.cdap.cdap.api.dataset.lib.PartitionedFileSet)10 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)10 AccessPermission (io.cdap.cdap.proto.security.AccessPermission)10