use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class DefaultNamespaceAdmin method list.
/**
* Lists all namespaces
*
* @return a list of {@link NamespaceMeta} for all namespaces
*/
@Override
public List<NamespaceMeta> list() throws Exception {
List<NamespaceMeta> namespaces = nsStore.list();
Principal principal = authenticationContext.getPrincipal();
final Predicate<EntityId> filter = authorizationEnforcer.createFilter(principal);
return Lists.newArrayList(Iterables.filter(namespaces, new com.google.common.base.Predicate<NamespaceMeta>() {
@Override
public boolean apply(NamespaceMeta namespaceMeta) {
return filter.apply(namespaceMeta.getNamespaceId());
}
}));
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class DefaultNamespaceAdmin method delete.
/**
* Deletes the specified namespace
*
* @param namespaceId the {@link Id.Namespace} of the specified namespace
* @throws NamespaceCannotBeDeletedException if the specified namespace cannot be deleted
* @throws NamespaceNotFoundException if the specified namespace does not exist
*/
@Override
@AuthEnforce(entities = "namespaceId", enforceOn = NamespaceId.class, actions = Action.ADMIN)
public synchronized void delete(@Name("namespaceId") final NamespaceId namespaceId) throws Exception {
// TODO: CDAP-870, CDAP-1427: Delete should be in a single transaction.
NamespaceMeta namespaceMeta = get(namespaceId);
if (checkProgramsRunning(namespaceId)) {
throw new NamespaceCannotBeDeletedException(namespaceId, String.format("Some programs are currently running in namespace " + "'%s', please stop them before deleting namespace", namespaceId));
}
LOG.info("Deleting namespace '{}'.", namespaceId);
try {
resourceDeleter.get().deleteResources(namespaceMeta);
// namespace in the storage provider (Hive, HBase, etc), since we re-use their default namespace.
if (!NamespaceId.DEFAULT.equals(namespaceId)) {
// Finally delete namespace from MDS and remove from cache
deleteNamespaceMeta(namespaceId);
// revoke privileges as the final step. This is done in the end, because if it is done before actual deletion,
// and deletion fails, we may have a valid (or invalid) namespace in the system, that no one has privileges on,
// so no one can clean up. This may result in orphaned privileges, which will be cleaned up by the create API
// if the same namespace is successfully re-created.
privilegesManager.revoke(namespaceId);
LOG.info("Namespace '{}' deleted", namespaceId);
} else {
LOG.info("Keeping the '{}' namespace after removing all data.", NamespaceId.DEFAULT);
}
} catch (Exception e) {
LOG.warn("Error while deleting namespace {}", namespaceId, e);
throw new NamespaceCannotBeDeletedException(namespaceId, e);
}
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class ListNamespacesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
Table table = Table.builder().setHeader("name", "description", "config").setRows(namespaceClient.list(), new RowMaker<NamespaceMeta>() {
@Override
public List<?> makeRow(NamespaceMeta object) {
return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig()));
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class StreamFileJanitor method cleanAll.
/**
* Performs file cleanup for all streams.
*/
public void cleanAll() throws Exception {
List<NamespaceMeta> namespaces = namespaceQueryAdmin.list();
for (final NamespaceMeta namespace : namespaces) {
final NamespaceId namespaceId = namespace.getNamespaceId();
final Location streamBaseLocation = impersonator.doAs(namespaceId, new Callable<Location>() {
@Override
public Location call() throws Exception {
return namespacedLocationFactory.get(namespaceId).append(streamBaseDirPath);
}
});
boolean exists = streamBaseLocation.exists();
if (exists) {
// Remove everything under the deleted directory
Location deletedLocation = StreamUtils.getDeletedLocation(streamBaseLocation);
if (deletedLocation.exists()) {
Locations.deleteContent(deletedLocation);
}
}
if (!exists) {
continue;
}
Iterable<Location> streamLocations = StreamUtils.listAllStreams(streamBaseLocation);
for (final Location streamLocation : streamLocations) {
final StreamId streamId = namespaceId.stream(StreamUtils.getStreamNameFromLocation(streamLocation));
final AtomicLong ttl = new AtomicLong(0);
if (isStreamExists(streamId)) {
ttl.set(streamAdmin.getConfig(streamId).getTTL());
}
clean(streamLocation, ttl.get(), System.currentTimeMillis());
}
}
}
use of co.cask.cdap.proto.NamespaceMeta 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(Id.Namespace namespaceId) throws IOException, NamespaceNotFoundException {
NamespaceMeta meta;
try {
meta = namespaceQueryAdmin.get(namespaceId.toEntityId());
} 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();
}
}
Aggregations