io.datarouter.gcp.spanner.web.SpannerWebInspector Maven / Gradle / Ivy
/*
* Copyright © 2009 HotPads ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.datarouter.gcp.spanner.web;
import static j2html.TagCreator.div;
import java.util.Map;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import io.datarouter.gcp.spanner.SpannerClientType;
import io.datarouter.gcp.spanner.client.SpannerClientOptions;
import io.datarouter.storage.client.ClientOptions;
import io.datarouter.web.browse.DatarouterClientWebInspector;
import io.datarouter.web.browse.dto.DatarouterWebRequestParamsFactory;
import io.datarouter.web.handler.mav.Mav;
import io.datarouter.web.handler.mav.imp.MessageMav;
import io.datarouter.web.handler.params.Params;
import io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory;
import io.datarouter.web.requirejs.DatarouterWebRequireJsV2;
public class SpannerWebInspector implements DatarouterClientWebInspector{
@Inject
private Bootstrap4PageFactory pageFactory;
@Inject
private DatarouterWebRequestParamsFactory paramsFactory;
@Inject
private ClientOptions clientOptions;
@Inject
private SpannerClientOptions spannerClientOptions;
@Override
public Mav inspectClient(Params params, HttpServletRequest request){
var clientParams = paramsFactory.new DatarouterWebRequestParams<>(params, SpannerClientType.class);
var clientId = clientParams.getClientId();
if(clientId == null){
return new MessageMav("Client not found");
}
var clientName = clientId.getName();
Map allClientOptions = clientOptions.getAllClientOptions(clientName);
allClientOptions.put(
SpannerClientOptions.makeSpannerKey(SpannerClientOptions.PROP_maxSessions),
String.valueOf(spannerClientOptions.maxSessions(clientName)));
allClientOptions.put(
SpannerClientOptions.makeSpannerKey(SpannerClientOptions.PROP_numChannels),
String.valueOf(spannerClientOptions.numChannels(clientName)));
var content = div(
buildClientPageHeader(clientName),
buildClientOptionsTable(allClientOptions))
.withClass("container my-3");
return pageFactory.startBuilder(request)
.withTitle("Datarouter Client - GCP Spanner")
.withRequires(DatarouterWebRequireJsV2.SORTTABLE)
.withContent(content)
.buildMav();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy