Search in sources :

Example 1 with OptionalLong

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;
}
Also used : Scanner(io.datarouter.scanner.Scanner) Arrays(java.util.Arrays) DatarouterWebRequestParamsFactory(io.datarouter.web.browse.dto.DatarouterWebRequestParamsFactory) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) RequestTool(io.datarouter.web.util.http.RequestTool) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) LoggerFactory(org.slf4j.LoggerFactory) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) DrRegionInfo(io.datarouter.client.hbase.cluster.DrRegionInfo) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) DatarouterWebRequestParams(io.datarouter.web.browse.dto.DatarouterWebRequestParamsFactory.DatarouterWebRequestParams) Map(java.util.Map) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) ThreadTool(io.datarouter.util.concurrent.ThreadTool) OptionalInteger(io.datarouter.web.handler.types.optional.OptionalInteger) PhaseTimer(io.datarouter.util.timer.PhaseTimer) Collection(java.util.Collection) DatarouterHBaseFiles(io.datarouter.client.hbase.config.DatarouterHBaseFiles) List(java.util.List) Entry(java.util.Map.Entry) ClientType(io.datarouter.storage.client.ClientType) HBaseClientType(io.datarouter.client.hbase.HBaseClientType) Supplier(java.util.function.Supplier) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HBaseClientTool(io.datarouter.client.hbase.util.HBaseClientTool) ServerNameTool(io.datarouter.client.hbase.util.ServerNameTool) Inject(javax.inject.Inject) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) NodeTool(io.datarouter.storage.node.NodeTool) Logger(org.slf4j.Logger) DrServerList(io.datarouter.client.hbase.cluster.DrServerList) Mav(io.datarouter.web.handler.mav.Mav) IOException(java.io.IOException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) OptionalLong(io.datarouter.web.handler.types.optional.OptionalLong) DrServerInfo(io.datarouter.client.hbase.cluster.DrServerInfo) HBaseBalancerFactory(io.datarouter.client.hbase.balancer.HBaseBalancerFactory) TreeMap(java.util.TreeMap) Admin(org.apache.hadoop.hbase.client.Admin) StringCodec(io.datarouter.bytes.codec.stringcodec.StringCodec) DrRegionListFactory(io.datarouter.client.hbase.cluster.DrRegionListFactory) ServerLoad(org.apache.hadoop.hbase.ServerLoad) HBaseClientManager(io.datarouter.client.hbase.HBaseClientManager) BaseHandler(io.datarouter.web.handler.BaseHandler) DrTableSettings(io.datarouter.client.hbase.cluster.DrTableSettings) DrRegionList(io.datarouter.client.hbase.cluster.DrRegionListFactory.DrRegionList) SingletonSupplier(io.datarouter.util.singletonsupplier.SingletonSupplier) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) Admin(org.apache.hadoop.hbase.client.Admin) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 2 with OptionalLong

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());
}
Also used : TaskTracker(io.datarouter.instrumentation.task.TaskTracker) LongRunningTaskType(io.datarouter.tasktracker.scheduler.LongRunningTaskType) Scanner(io.datarouter.scanner.Scanner) LongRunningTaskTrackerFactory(io.datarouter.tasktracker.service.LongRunningTaskTrackerFactory) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Mav(io.datarouter.web.handler.mav.Mav) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) TaskTracker(io.datarouter.instrumentation.task.TaskTracker) Instant(java.time.Instant) OptionalLong(io.datarouter.web.handler.types.optional.OptionalLong) Inject(javax.inject.Inject) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) Paths(java.nio.file.Paths) Duration(java.time.Duration) BaseHandler(io.datarouter.web.handler.BaseHandler) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

Scanner (io.datarouter.scanner.Scanner)2 BaseHandler (io.datarouter.web.handler.BaseHandler)2 Mav (io.datarouter.web.handler.mav.Mav)2 MessageMav (io.datarouter.web.handler.mav.imp.MessageMav)2 OptionalLong (io.datarouter.web.handler.types.optional.OptionalLong)2 IOException (java.io.IOException)2 Inject (javax.inject.Inject)2 StringCodec (io.datarouter.bytes.codec.stringcodec.StringCodec)1 HBaseClientManager (io.datarouter.client.hbase.HBaseClientManager)1 HBaseClientType (io.datarouter.client.hbase.HBaseClientType)1 HBaseBalancerFactory (io.datarouter.client.hbase.balancer.HBaseBalancerFactory)1 DrRegionInfo (io.datarouter.client.hbase.cluster.DrRegionInfo)1 DrRegionListFactory (io.datarouter.client.hbase.cluster.DrRegionListFactory)1 DrRegionList (io.datarouter.client.hbase.cluster.DrRegionListFactory.DrRegionList)1 DrServerInfo (io.datarouter.client.hbase.cluster.DrServerInfo)1 DrServerList (io.datarouter.client.hbase.cluster.DrServerList)1 DrTableSettings (io.datarouter.client.hbase.cluster.DrTableSettings)1 DatarouterHBaseFiles (io.datarouter.client.hbase.config.DatarouterHBaseFiles)1 HBaseClientTool (io.datarouter.client.hbase.util.HBaseClientTool)1 ServerNameTool (io.datarouter.client.hbase.util.ServerNameTool)1