use of co.cask.cdap.api.data.DatasetContext in project cdap by caskdata.
the class BodyConsumerAdapter method finished.
@Override
public void finished(HttpResponder responder) {
TransactionControl txCtrl = Transactions.getTransactionControl(TransactionControl.IMPLICIT, HttpContentConsumer.class, delegate, "onFinish", HttpServiceResponder.class);
try {
if (TransactionControl.IMPLICIT == txCtrl) {
transactional.execute(new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
delegate.onFinish(BodyConsumerAdapter.this.responder);
}
});
} else {
delegate.onFinish(BodyConsumerAdapter.this.responder);
}
} catch (Throwable t) {
onError(t, this.responder);
return;
}
// To the HttpContentConsumer, the call is completed even if it fails to send response back to client.
completed = true;
try {
BodyConsumerAdapter.this.responder.execute();
} finally {
if (!this.responder.hasContentProducer()) {
contextReleaser.cancel();
}
}
}
use of co.cask.cdap.api.data.DatasetContext in project cdap by caskdata.
the class BodyProducerAdapter method finished.
@Override
public void finished() throws Exception {
TransactionControl txCtrl = Transactions.getTransactionControl(TransactionControl.IMPLICIT, HttpContentProducer.class, delegate, "onFinish");
if (TransactionControl.IMPLICIT == txCtrl) {
serviceContext.execute(new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
delegate.onFinish();
}
});
} else {
delegate.onFinish();
}
try {
serviceContext.dismissTransactionContext();
} finally {
completed = true;
contextReleaser.cancel();
}
}
use of co.cask.cdap.api.data.DatasetContext in project cdap by caskdata.
the class BodyProducerAdapter method handleError.
@Override
public void handleError(final Throwable throwable) {
if (completed) {
return;
}
// To the HttpContentProducer, if there is error, no other methods will be triggered
completed = true;
TransactionControl txCtrl = Transactions.getTransactionControl(TransactionControl.IMPLICIT, HttpContentProducer.class, delegate, "onError", Throwable.class);
try {
if (TransactionControl.IMPLICIT == txCtrl) {
serviceContext.execute(new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
delegate.onError(throwable);
}
});
} else {
delegate.onError(throwable);
}
} catch (Throwable t) {
throwable.addSuppressed(t);
// nothing much can be done. Simply emit a debug log.
LOG.warn("Exception in calling HttpContentProducer.onError.", t);
}
try {
serviceContext.dismissTransactionContext();
} finally {
contextReleaser.cancel();
}
}
use of co.cask.cdap.api.data.DatasetContext in project cdap by caskdata.
the class DatasetTypeService method deleteSystemModules.
private void deleteSystemModules() throws Exception {
final List<DatasetModuleMeta> toRevoke = new ArrayList<>();
Transactions.createTransactional(datasetCache).execute(60, new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
DatasetTypeMDS datasetTypeMDS = datasetCache.getDataset(DatasetMetaTableUtil.META_TABLE_NAME);
Collection<DatasetModuleMeta> allDatasets = datasetTypeMDS.getModules(NamespaceId.SYSTEM);
for (DatasetModuleMeta ds : allDatasets) {
if (ds.getJarLocationPath() == null) {
LOG.debug("Deleting system dataset module: {}", ds.toString());
DatasetModuleId moduleId = NamespaceId.SYSTEM.datasetModule(ds.getName());
datasetTypeMDS.deleteModule(moduleId);
toRevoke.add(ds);
}
}
}
});
long startTime = System.currentTimeMillis();
LOG.trace("Revoking all privileges for {} system dataset modules. ", toRevoke.size());
for (DatasetModuleMeta ds : toRevoke) {
revokeAllPrivilegesOnModule(NamespaceId.SYSTEM.datasetModule(ds.getName()), ds);
}
long doneTime = System.currentTimeMillis();
float elapsedSeconds = doneTime == startTime ? 0.0F : ((float) doneTime - startTime) / 1000;
LOG.debug("Revoking all privileges for {} system dataset modules took {} seconds.", toRevoke.size(), elapsedSeconds);
}
use of co.cask.cdap.api.data.DatasetContext in project cdap by caskdata.
the class ArtifactStore method clear.
/**
* Clear all data in the given namespace. Used only in unit tests.
*
* @param namespace the namespace to delete data in
* @throws IOException if there was some problem deleting the data
*/
@VisibleForTesting
void clear(final NamespaceId namespace) throws IOException {
final Id.Namespace namespaceId = namespace.toId();
namespacedLocationFactory.get(namespace).append(ARTIFACTS_PATH).delete(true);
try {
transactional.execute(new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
// delete all rows about artifacts in the namespace
Table metaTable = getMetaTable(context);
Row row;
try (Scanner scanner = metaTable.scan(scanArtifacts(namespace))) {
while ((row = scanner.next()) != null) {
metaTable.delete(row.getRow());
}
}
// delete all rows about artifacts in the namespace and the plugins they have access to
Scan pluginsScan = new Scan(Bytes.toBytes(String.format("%s:%s:", PLUGIN_PREFIX, namespace.getNamespace())), Bytes.toBytes(String.format("%s:%s;", PLUGIN_PREFIX, namespace.getNamespace())));
try (Scanner scanner = metaTable.scan(pluginsScan)) {
while ((row = scanner.next()) != null) {
metaTable.delete(row.getRow());
}
}
// delete app classes in this namespace
try (Scanner scanner = metaTable.scan(scanAppClasses(namespace))) {
while ((row = scanner.next()) != null) {
metaTable.delete(row.getRow());
}
}
// delete plugins in this namespace from system artifacts
// for example, if there was an artifact in this namespace that extends a system artifact
Scan systemPluginsScan = new Scan(Bytes.toBytes(String.format("%s:%s:", PLUGIN_PREFIX, Id.Namespace.SYSTEM.getId())), Bytes.toBytes(String.format("%s:%s;", PLUGIN_PREFIX, Id.Namespace.SYSTEM.getId())));
try (Scanner scanner = metaTable.scan(systemPluginsScan)) {
while ((row = scanner.next()) != null) {
for (Map.Entry<byte[], byte[]> columnVal : row.getColumns().entrySet()) {
// the column is the id of the artifact the plugin is from
ArtifactColumn column = ArtifactColumn.parse(columnVal.getKey());
// if the plugin artifact is in the namespace we're deleting, delete this column.
if (column.artifactId.getNamespace().equals(namespaceId)) {
metaTable.delete(row.getRow(), column.getColumn());
}
}
}
}
}
});
} catch (TransactionFailureException e) {
throw Transactions.propagate(e, IOException.class);
}
}
Aggregations