Skip to content

Commit

Permalink
[webapp][server] API getting multiple xlogs by txids.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunlee01 committed Mar 3, 2018
1 parent 2c621d9 commit 269abcf
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 13 deletions.
1 change: 1 addition & 0 deletions scouter.common/src/main/java/scouter/net/RequestCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class RequestCmd {
public static final String TRANX_LOAD_TIME = "TRANX_LOAD_TIME";
public static final String XLOG_READ_BY_TXID = "XLOG_READ_BY_TXID";
public static final String XLOG_READ_BY_GXID = "XLOG_READ_BY_GXID";
public static final String XLOG_LOAD_BY_TXIDS = "XLOG_LOAD_BY_TXIDS";
public static final String XLOG_LOAD_BY_GXID = "XLOG_LOAD_BY_GXID";
public static final String TRANX_PROFILE = "TRANX_PROFILE";
public static final String TRANX_PROFILE_FULL = "TRANX_PROFILE_FULL";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,32 @@ class XLogService {
}
}

@ServiceHandler(RequestCmd.XLOG_LOAD_BY_TXIDS)
def loadByTxIds(din: DataInputX, dout: DataOutputX, login: Boolean) {
val param = din.readMapPack()
val date = param.getText("date")
val txidLv = param.getList("txid")

var loadCount = 0
try {
EnumerScala.foreach(txidLv, (txidValue: DecimalValue) => {
loadCount += 1;

if (loadCount >= Configure.getInstance().req_search_xlog_max_count) {
return;
}
val xbytes = XLogRD.getByTxid(date, txidValue.longValue())
if(xbytes != null) {
dout.writeByte(TcpFlag.HasNEXT)
dout.write(xbytes)
dout.flush()
}
})
} catch {
case e: Exception => {}
}
}

@ServiceHandler(RequestCmd.XLOG_LOAD_BY_GXID)
def loadByGxId(din: DataInputX, dout: DataOutputX, login: Boolean) {
val param = din.readMapPack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
}
httpServletResponse.addHeader("Access-Control-Allow-Origin", allowOrigin);
httpServletResponse.addHeader("Access-Control-Allow-Credentials", allowCredentials);
httpServletResponse.addHeader("Access-Control-Max-Age", "600");

httpServletResponse.addHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
httpServletResponse.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, PATCH");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public static List<Integer> splitParamAsInteger(String org) {
return Arrays.stream(items).map(Integer::parseInt).collect(Collectors.toList());
}

public static List<Long> splitParamAsLong(String org) {
org = stripFirstLastBracket(org);
String[] items = StringUtils.split(org, COMMA);
return Arrays.stream(items).map(Long::parseLong).collect(Collectors.toList());
}

public static Set<Integer> splitParamAsIntegerSet(String org) {
org = stripFirstLastBracket(org);
String[] items = StringUtils.split(org, COMMA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@
import scouterx.webapp.framework.client.net.TcpProxy;
import scouterx.webapp.model.XLogData;
import scouterx.webapp.model.scouter.SXLog;
import scouterx.webapp.request.GxidXLogRequest;
import scouterx.webapp.request.MultiXLogRequest;
import scouterx.webapp.request.PageableXLogRequest;
import scouterx.webapp.request.RealTimeXLogRequest;
import scouterx.webapp.request.SearchXLogRequest;
import scouterx.webapp.request.SingleXLogRequest;
import scouterx.webapp.request.GxidXLogRequest;
import scouterx.webapp.view.PageableXLogView;
import scouterx.webapp.view.RealTimeXLogView;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static scouter.lang.constants.ParamConstant.XLOG_TXID;

/**
* @author Gun Lee (gunlee01@gmail.com) on 2017. 8. 27.
*/
Expand Down Expand Up @@ -87,7 +90,7 @@ public void handlePageableXLog(final PageableXLogRequest pageableXLogRequest, fi
MapPack paramPack = new MapPack();
paramPack.put(ParamConstant.DATE, pageableXLogRequest.getYyyymmdd());
paramPack.put(ParamConstant.XLOG_START_TIME, pageableXLogRequest.getStartTimeMillis());
paramPack.put(ParamConstant.XLOG_TXID, pageableXLogRequest.getLastTxid());
paramPack.put(XLOG_TXID, pageableXLogRequest.getLastTxid());
paramPack.put(ParamConstant.XLOG_END_TIME, pageableXLogRequest.getEndTimeMillis());
paramPack.put(ParamConstant.XLOG_LAST_BUCKET_TIME, pageableXLogRequest.getLastXLogTime());
paramPack.put(ParamConstant.XLOG_PAGE_COUNT, pageableXLogRequest.getPageCount());
Expand Down Expand Up @@ -162,7 +165,7 @@ public SXLog retrieveByTxidAsXLog(final SingleXLogRequest singleXLogRequest) {
*
* @param xlogRequest
*/
public List<SXLog> retrieveXLogsByGxid(final GxidXLogRequest xlogRequest) {
public List<SXLog> retrieveXLogListByGxid(final GxidXLogRequest xlogRequest) {
return retrieveXLogPacksByGxid(xlogRequest).stream()
.map(pack -> (XLogPack) pack)
.map(SXLog::of)
Expand All @@ -175,18 +178,30 @@ public List<SXLog> retrieveXLogsByGxid(final GxidXLogRequest xlogRequest) {
*
* @param xLogRequest
*/
public List<XLogData> retrieveXLogDatasByGxid(final GxidXLogRequest xLogRequest) {
public List<XLogData> retrieveXLogDataListByGxid(final GxidXLogRequest xLogRequest) {
return retrieveXLogPacksByGxid(xLogRequest).stream()
.map(pack -> (XLogPack) pack)
.map(pack -> XLogData.of(pack, xLogRequest.getServerId()))
.collect(Collectors.toList());
}

/**
* retrieve XLog Data List by txids
*
* @param multiXLogRequest
*/
public List<XLogData> retrieveXLogDataListByTxids(final MultiXLogRequest multiXLogRequest) {
return retrieveXLogPacksByTxids(multiXLogRequest).stream()
.map(pack -> (XLogPack) pack)
.map(pack -> XLogData.of(pack, multiXLogRequest.getServerId()))
.collect(Collectors.toList());
}


private XLogPack retrieveByTxid(final SingleXLogRequest singleXLogRequest) {
MapPack param = new MapPack();
param.put(ParamConstant.DATE, singleXLogRequest.getYyyymmdd());
param.put(ParamConstant.XLOG_TXID, singleXLogRequest.getTxid());
param.put(XLOG_TXID, singleXLogRequest.getTxid());

XLogPack pack;
try (TcpProxy tcpProxy = TcpProxy.getTcpProxy(singleXLogRequest.getServerId())) {
Expand All @@ -208,6 +223,19 @@ private List<Pack> retrieveXLogPacksByGxid(GxidXLogRequest xlogRequest) {
return results;
}

private List<Pack> retrieveXLogPacksByTxids(MultiXLogRequest xlogRequest) {
MapPack param = new MapPack();
param.put(ParamConstant.DATE, xlogRequest.getYyyymmdd());
ListValue xlogLv = param.newList(XLOG_TXID);
xlogRequest.getTxidList().forEach(xlogLv::add);

List<Pack> results;
try (TcpProxy tcpProxy = TcpProxy.getTcpProxy(xlogRequest.getServerId())) {
results = tcpProxy.process(RequestCmd.XLOG_LOAD_BY_TXIDS, param);
}
return results;
}

private List<Pack> searchXLogPackList(final SearchXLogRequest searchXLogRequest) {
MapPack paramPack = new MapPack();
paramPack.put(ParamConstant.DATE,searchXLogRequest.getYyyymmdd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public CommonResultView<SXLog> retrieveSingleXLog(@Valid @BeanParam SingleXLogRe
@Consumes(MediaType.APPLICATION_JSON)
public CommonResultView<List<SXLog>> retrieveXLogsByGxid(@Valid @BeanParam GxidXLogRequest gxidRequest) {
gxidRequest.validate();
List<SXLog> xLogs = xLogService.retrieveXLogsByGxid(gxidRequest);
List<SXLog> xLogs = xLogService.retrieveXLogListByGxid(gxidRequest);

return CommonResultView.success(xLogs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import scouterx.webapp.model.XLogData;
import scouterx.webapp.model.XLogPackWrapper;
import scouterx.webapp.request.GxidXLogRequest;
import scouterx.webapp.request.MultiXLogRequest;
import scouterx.webapp.request.PageableXLogRequest;
import scouterx.webapp.request.RealTimeXLogDataRequest;
import scouterx.webapp.request.SearchXLogRequest;
Expand Down Expand Up @@ -177,7 +178,7 @@ public Response streamPageableXLog(@Valid @BeanParam PageableXLogRequest xLogReq

/**
* request xlog by txid
* uri : /xlog-data/{yyyymmdd}/{txid} @see {@link SingleXLogRequest}
* uri : /{yyyymmdd}/{txid} @see {@link SingleXLogRequest}
*
* @param singleXlogRequest
*/
Expand All @@ -191,6 +192,21 @@ public CommonResultView<XLogData> retrieveSingleXLog(@Valid @BeanParam SingleXLo
return CommonResultView.success(xLogData);
}

/**
* request xlog by txid
* uri : /{yyyymmdd}/multi @see {@link MultiXLogRequest}
*
* @param multiXLogRequest
*/
@GET
@Path("/{yyyymmdd}/multi/{txidList}")
@Consumes(MediaType.APPLICATION_JSON)
public CommonResultView<List<XLogData>> retrieveXLogDataListByTxids(@Valid @BeanParam MultiXLogRequest multiXLogRequest) {
List<XLogData> xLogs = xLogService.retrieveXLogDataListByTxids(multiXLogRequest);

return CommonResultView.success(xLogs);
}

/**
* request xlogs by gxid
* uri : /{yyyymmdd}/gxid/{gxid} @see {@link GxidXLogRequest}
Expand All @@ -200,9 +216,9 @@ public CommonResultView<XLogData> retrieveSingleXLog(@Valid @BeanParam SingleXLo
@GET
@Path("/{yyyymmdd}/gxid/{gxid}")
@Consumes(MediaType.APPLICATION_JSON)
public CommonResultView<List<XLogData>> retrieveXLogDatasByGxid(@Valid @BeanParam GxidXLogRequest gxidRequest) {
public CommonResultView<List<XLogData>> retrieveXLogDataListByGxid(@Valid @BeanParam GxidXLogRequest gxidRequest) {
gxidRequest.validate();
List<XLogData> xLogs = xLogService.retrieveXLogDatasByGxid(gxidRequest);
List<XLogData> xLogs = xLogService.retrieveXLogDataListByGxid(gxidRequest);

return CommonResultView.success(xLogs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import scouterx.webapp.layer.consumer.XLogConsumer;
import scouterx.webapp.model.XLogData;
import scouterx.webapp.model.scouter.SXLog;
import scouterx.webapp.request.MultiXLogRequest;
import scouterx.webapp.request.SearchXLogRequest;
import scouterx.webapp.request.PageableXLogRequest;
import scouterx.webapp.request.RealTimeXLogRequest;
Expand Down Expand Up @@ -88,16 +89,24 @@ public SXLog retrieveSingleXLog(final SingleXLogRequest singleXlogRequest) {
/**
* retrieve Xlog List by gxid
*/
public List<SXLog> retrieveXLogsByGxid(final GxidXLogRequest xlogRequest) {
return xLogConsumer.retrieveXLogsByGxid(xlogRequest);
public List<SXLog> retrieveXLogListByGxid(final GxidXLogRequest xlogRequest) {
return xLogConsumer.retrieveXLogListByGxid(xlogRequest);
}

/**
* retrieve Xlog data List by gxid
*/
public List<XLogData> retrieveXLogDatasByGxid(final GxidXLogRequest xlogRequest) {
return xLogConsumer.retrieveXLogDatasByGxid(xlogRequest);
public List<XLogData> retrieveXLogDataListByGxid(final GxidXLogRequest xlogRequest) {
return xLogConsumer.retrieveXLogDataListByGxid(xlogRequest);
}

/**
* retrieve Xlog data List by txids
*/
public List<XLogData> retrieveXLogDataListByTxids(final MultiXLogRequest multiXLogRequest) {
return xLogConsumer.retrieveXLogDataListByTxids(multiXLogRequest);
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2015 the original author or authors.
* @https://github.com/scouter-project/scouter
*
* 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 scouterx.webapp.request;

import lombok.Getter;
import lombok.Setter;
import scouterx.webapp.framework.client.server.ServerManager;
import scouterx.webapp.framework.util.ZZ;

import javax.validation.constraints.NotNull;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import java.util.List;

/**
* Created by jaco.ryu on 2017. 10. 13..
*/
@Getter
@Setter
public class MultiXLogRequest {
int serverId;

List<Long> txidList;

@NotNull
@PathParam("yyyymmdd")
String yyyymmdd;

@PathParam("txidList")
public void setTxidList(String txids) {
this.txidList = ZZ.splitParamAsLong(txids);
}

@QueryParam("serverId")
public void setServerId(int serverId) {
this.serverId = ServerManager.getInstance().getServerIfNullDefault(serverId).getId();
}


}

0 comments on commit 269abcf

Please sign in to comment.