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));
}
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));
}
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));
}
}
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);
}
}
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);
}
}
}
Aggregations