Search in sources :

Example 1 with MessageMav

use of io.datarouter.web.handler.mav.imp.MessageMav in project datarouter by hotpads.

the class HBaseHandler method moveRegionsToCorrectServer.

/*---------------------------- move handlers ----------------------------*/
@Handler
public Mav moveRegionsToCorrectServer(OptionalInteger pauseBetweenRegionsMs) throws IOException {
    initialize();
    int counter = 0;
    for (DrRegionInfo<?> region : regionList.get().getRegions()) {
        if (!region.isOnCorrectServer()) {
            ++counter;
            PhaseTimer timer = new PhaseTimer("move " + counter + " of " + datarouterWebRequestParams.getTableName());
            String encodedRegionNameString = region.getRegion().getEncodedName();
            String destinationServer = region.getConsistentHashServerName().getServerName();
            hBaseClientManager.getAdmin(datarouterWebRequestParams.getClientId()).move(Bytes.toBytes(encodedRegionNameString), Bytes.toBytes(destinationServer));
            logger.warn(timer.add("HBase moved region " + encodedRegionNameString + " to server " + destinationServer).toString());
        }
        ThreadTool.sleepUnchecked(pauseBetweenRegionsMs.orElse(500));
    }
    // mav.put("message-update", "HBase regions moved to correct server");
    return new MessageMav("HBase regions moved to correct server");
}
Also used : MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) PhaseTimer(io.datarouter.util.timer.PhaseTimer) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 2 with MessageMav

use of io.datarouter.web.handler.mav.imp.MessageMav in project datarouter by hotpads.

the class HBaseHandler method majorCompactHBaseTableRegions.

@Handler
public Mav majorCompactHBaseTableRegions() throws IOException {
    initialize();
    for (String encodedRegionNameString : encodedRegionNameStrings) {
        DrRegionInfo<?> region = regionList.get().getRegionByEncodedName(encodedRegionNameString);
        hBaseClientManager.getAdmin(datarouterWebRequestParams.getClientId()).majorCompactRegion(region.getRegion().getRegionName());
    }
    return new MessageMav("submitted major compaction requests for regions: " + encodedRegionNameStrings);
}
Also used : MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 3 with MessageMav

use of io.datarouter.web.handler.mav.imp.MessageMav 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 4 with MessageMav

use of io.datarouter.web.handler.mav.imp.MessageMav in project datarouter by hotpads.

the class DatarouterPermissionRequestHandler method showForm.

@Handler(defaultHandler = true)
private Mav showForm(OptionalString deniedUrl, OptionalString allowedRoles) {
    if (!authenticationConfig.useDatarouterAuthentication()) {
        return new MessageMav(noDatarouterAuthentication());
    }
    Mav mav = new Mav(files.jsp.authentication.permissionRequestJsp);
    mav.put("serviceName", serviceName.get());
    mav.put("permissionRequestPath", paths.permissionRequest.toSlashedString());
    Optional<String> defaultSpecifics = deniedUrl.map(url -> {
        return "I tried to go to this URL: " + url + "." + allowedRoles.map(" These are its allowed roles at the time of this request: "::concat).orElse("");
    });
    mav.put("defaultSpecifics", defaultSpecifics);
    DatarouterUser user = getCurrentUser();
    mav.put("currentRequest", datarouterPermissionRequestDao.scanOpenPermissionRequestsForUser(user.getId()).findMax(Comparator.comparing(request -> request.getKey().getRequestTime())).orElse(null));
    Set<String> emails = new HashSet<>();
    if (serverTypeDetector.mightBeProduction()) {
        emails.addAll(permissionRequestEmailType.tos);
    }
    emails.add(adminEmail.get());
    if (subscribersSettings.includeSubscribers.get()) {
        emails.addAll(subscibersEmail.get());
    }
    mav.put("email", emails);
    mav.put("submitPath", paths.permissionRequest.submit.join("/"));
    mav.put("declinePath", paths.permissionRequest.declineAll.join("/"));
    return mav;
}
Also used : MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) DatarouterUserExternalDetailService(io.datarouter.web.user.detail.DatarouterUserExternalDetailService) Date(java.util.Date) DatarouterEmailSubscriberSettings(io.datarouter.storage.config.setting.DatarouterEmailSubscriberSettings) DatarouterHtmlEmailService(io.datarouter.web.email.DatarouterHtmlEmailService) LoggerFactory(org.slf4j.LoggerFactory) DatarouterUserInfo(io.datarouter.auth.service.DatarouterUserInfo) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) ServiceName(io.datarouter.web.config.service.ServiceName) DatarouterAuthFiles(io.datarouter.auth.config.DatarouterAuthFiles) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) DatarouterUserService(io.datarouter.auth.service.DatarouterUserService) DatarouterUserRole(io.datarouter.web.user.role.DatarouterUserRole) GlobalRedirectMav(io.datarouter.web.handler.mav.imp.GlobalRedirectMav) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) ServerTypeDetector(io.datarouter.storage.servertype.ServerTypeDetector) TagCreator.table(j2html.TagCreator.table) Set(java.util.Set) Instant(java.time.Instant) ZoneId(java.time.ZoneId) DatarouterPermissionRequest(io.datarouter.auth.storage.permissionrequest.DatarouterPermissionRequest) DatarouterAuthenticationConfig(io.datarouter.web.user.authenticate.config.DatarouterAuthenticationConfig) ContainerTag(j2html.tags.ContainerTag) Objects(java.util.Objects) Optional(java.util.Optional) TagCreator.text(j2html.TagCreator.text) HashSet(java.util.HashSet) Inject(javax.inject.Inject) DatarouterUser(io.datarouter.web.user.databean.DatarouterUser) AdminEmail(io.datarouter.storage.config.properties.AdminEmail) DatarouterUserEditService(io.datarouter.auth.service.DatarouterUserEditService) TagCreator.p(j2html.TagCreator.p) Logger(org.slf4j.Logger) DatarouterAuthPaths(io.datarouter.auth.config.DatarouterAuthPaths) Mav(io.datarouter.web.handler.mav.Mav) TagCreator.b(j2html.TagCreator.b) StringTool(io.datarouter.util.string.StringTool) TagCreator.a(j2html.TagCreator.a) OptionalLong(io.datarouter.web.handler.types.optional.OptionalLong) ZonedDateFormatterTool(io.datarouter.util.time.ZonedDateFormatterTool) DomContent(j2html.tags.DomContent) DatarouterPermissionRequestDao(io.datarouter.auth.storage.permissionrequest.DatarouterPermissionRequestDao) TagCreator.td(j2html.TagCreator.td) PermissionRequestEmailType(io.datarouter.email.type.DatarouterEmailTypes.PermissionRequestEmailType) BaseHandler(io.datarouter.web.handler.BaseHandler) TagCreator.tr(j2html.TagCreator.tr) TagCreator.tbody(j2html.TagCreator.tbody) Comparator(java.util.Comparator) DatarouterSubscribersSupplier(io.datarouter.storage.config.DatarouterSubscribersSupplier) TagCreator.div(j2html.TagCreator.div) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) GlobalRedirectMav(io.datarouter.web.handler.mav.imp.GlobalRedirectMav) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) Mav(io.datarouter.web.handler.mav.Mav) DatarouterUser(io.datarouter.web.user.databean.DatarouterUser) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) HashSet(java.util.HashSet) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 5 with MessageMav

use of io.datarouter.web.handler.mav.imp.MessageMav in project datarouter by hotpads.

the class DatarouterPermissionRequestHandler method submit.

@Handler
private Mav submit(OptionalString specifics) {
    if (!authenticationConfig.useDatarouterAuthentication()) {
        return new MessageMav(noDatarouterAuthentication());
    }
    String reason = params.required(P_REASON);
    if (StringTool.isEmpty(reason)) {
        throw new IllegalArgumentException("Reason is required.");
    }
    String specificString = specifics.orElse("");
    DatarouterUser user = getCurrentUser();
    datarouterPermissionRequestDao.createPermissionRequest(new DatarouterPermissionRequest(user.getId(), new Date(), "reason: " + reason + ", specifics: " + specificString, null, null));
    sendRequestEmail(user, reason, specificString);
    // not just requestor, so send them to the home page after they make their request
    if (user.getRoles().size() > 1) {
        return new InContextRedirectMav(request, paths.home);
    }
    return showForm(new OptionalString(null), new OptionalString(null));
}
Also used : MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) DatarouterUser(io.datarouter.web.user.databean.DatarouterUser) DatarouterPermissionRequest(io.datarouter.auth.storage.permissionrequest.DatarouterPermissionRequest) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) Date(java.util.Date) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

MessageMav (io.datarouter.web.handler.mav.imp.MessageMav)21 BaseHandler (io.datarouter.web.handler.BaseHandler)14 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)11 Mav (io.datarouter.web.handler.mav.Mav)8 PhaseTimer (io.datarouter.util.timer.PhaseTimer)4 GlobalRedirectMav (io.datarouter.web.handler.mav.imp.GlobalRedirectMav)4 IOException (java.io.IOException)4 InContextRedirectMav (io.datarouter.web.handler.mav.imp.InContextRedirectMav)3 OptionalLong (io.datarouter.web.handler.types.optional.OptionalLong)3 DatarouterUser (io.datarouter.web.user.databean.DatarouterUser)3 Inject (javax.inject.Inject)3 Logger (org.slf4j.Logger)3 DatarouterPermissionRequest (io.datarouter.auth.storage.permissionrequest.DatarouterPermissionRequest)2 PathNode (io.datarouter.pathnode.PathNode)2 Scanner (io.datarouter.scanner.Scanner)2 Node (io.datarouter.storage.node.Node)2 Instant (java.time.Instant)2 Date (java.util.Date)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2