use of io.datarouter.web.handler.types.optional.OptionalLong in project datarouter by hotpads.
the class HBaseHandler method updateHBaseTableAttribute.
/*---------------------------- update handlers --------------------------*/
@Handler
public Mav updateHBaseTableAttribute(OptionalLong maxFileSizeMb, OptionalLong memstoreFlushSizeMb) throws IOException {
initialize();
Admin admin = hBaseClientManager.getAdmin(datarouterWebRequestParams.getClientId());
HTableDescriptor table;
table = admin.getTableDescriptor(TableName.valueOf(datarouterWebRequestParams.getTableName().getBytes()));
try {
admin.disableTable(TableName.valueOf(datarouterWebRequestParams.getTableName()));
logger.warn("table disabled");
maxFileSizeMb.map(mb -> mb * 1024 * 1024).ifPresent(table::setMaxFileSize);
memstoreFlushSizeMb.map(mb -> mb * 1024 * 1024).ifPresent(table::setMemStoreFlushSize);
admin.modifyTable(TableName.valueOf(StringCodec.UTF_8.encode(datarouterWebRequestParams.getTableName())), table);
} finally {
admin.enableTable(TableName.valueOf(datarouterWebRequestParams.getTableName()));
}
logger.warn("table enabled");
mav = new MessageMav("HBase table attributes updated");
return mav;
}
use of io.datarouter.web.handler.types.optional.OptionalLong in project datarouter by hotpads.
the class ExampleTaskTrackerHandler method countFiles.
@Handler
public Mav countFiles(String parentPath, OptionalLong logEveryN) throws IOException {
// create a TaskTracker
TaskTracker tracker = trackerFactory.create(// determines the tracker name
ExampleTaskTrackerHandler.class.getSimpleName(), // triggered by web request
LongRunningTaskType.REQUEST, // deadline
Instant.now().plus(Duration.ofMinutes(1)), // gracefully stop when the deadline is reached
true, // record which user triggered the request, viewable in the UI
getSessionInfo().getNonEmptyUsernameOrElse("anonymous"));
// update and check the TaskTracker during a potentially long task
Scanner.of(Files.walk(Paths.get(parentPath))).advanceUntil($ -> tracker.shouldStop()).map(Object::toString).each($ -> tracker.increment()).each(tracker::setLastItemProcessed).sample(logEveryN.orElse(1L), true).forEach(item -> logger.warn("{}={}", tracker.getCount(), item));
// return a message to the user, obtaining the count from the tracker
return new MessageMav("counted " + tracker.getCount());
}
Aggregations