Skip to content

Commit

Permalink
fix: #50 set custom period for initial data reading (OracleEE* profil…
Browse files Browse the repository at this point in the history
…es) in Other tab
  • Loading branch information
akardapolov committed Sep 11, 2021
1 parent f3d462b commit f011c40
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 22 deletions.
2 changes: 2 additions & 0 deletions ashv/src/main/java/config/profile/ConfigProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class ConfigProfile {
private String configName;
private boolean isRunning;

private int initialLoading = ConstantManager.INITIAL_LOADING;

private int rawRetainDays = ConstantManager.RETAIN_DAYS_MAX;
private int olapRetainDays = ConstantManager.RETAIN_DAYS_MAX;

Expand Down
2 changes: 2 additions & 0 deletions ashv/src/main/java/core/manager/ConfigurationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public ConnectionBuilder getConnectionParameters(String connName) {
.url(connOut.getUrl())
.jar(connOut.getJar())
.profile(connOut.getProfileName())
.initialLoading(String.valueOf(cfg.getValue().getInitialLoading()))
.rawRetainDays(String.valueOf(cfg.getValue().getRawRetainDays()))
.olapRetainDays(String.valueOf(cfg.getValue().getOlapRetainDays()))
.build();
Expand All @@ -121,6 +122,7 @@ public void saveConnection(ConnectionBuilder connIn) {
connOut.setProfileName(connIn.getProfile());
connOut.setDriver(connIn.getDriverName());

cfg.getValue().setInitialLoading(Integer.parseInt(connIn.getInitialLoading()));
cfg.getValue().setRawRetainDays(getRawRetainDays());
cfg.getValue().setOlapRetainDays(getOlapRetainDays());

Expand Down
3 changes: 3 additions & 0 deletions ashv/src/main/java/core/manager/ConstantManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public enum RetainData {Never, Always};
public static int RETAIN_DAYS_MIN = 0;
public static int RETAIN_DAYS_MAX = 101;

public static int INITIAL_LOADING = -1;
public static int INITIAL_LOADING_DEFAULT = 5;

private static Map coreOpt = new LinkedHashMap();

private ConstantManager() {}
Expand Down
5 changes: 5 additions & 0 deletions ashv/src/main/java/core/parameter/ConnectionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class ConnectionBuilder {
private final String jar;
private final String profile;
private final String driverName;
private final String initialLoading;
private final String rawRetainDays;
private final String olapRetainDays;

Expand All @@ -18,6 +19,7 @@ public class ConnectionBuilder {
public String getJar() { return jar; }
public String getProfile() { return profile; }
public String getDriverName() { return driverName; }
public String getInitialLoading() { return initialLoading; }
public String getRawRetainDays() { return rawRetainDays; }
public String getOlapRetainDays() { return olapRetainDays; }

Expand All @@ -29,6 +31,7 @@ public static class Builder {
private String jar;
private String profile;
private String driverName;
private String initialLoading;
private String rawRetainDays;
private String olapRetainDays;

Expand All @@ -42,6 +45,7 @@ public Builder(String connectionName) {
public Builder jar(String jr) { jar = jr; return this; }
public Builder profile(String pr) { profile = pr; return this; }
public Builder driverName(String dr) { driverName = dr; return this; }
public Builder initialLoading(String il) { initialLoading = il; return this; }
public Builder rawRetainDays(String raw) { rawRetainDays = raw; return this; }
public Builder olapRetainDays(String raw) { olapRetainDays = raw; return this; }

Expand All @@ -58,6 +62,7 @@ private ConnectionBuilder(Builder builder){
jar = builder.jar;
profile = builder.profile;
driverName = builder.driverName;
initialLoading = builder.initialLoading;
rawRetainDays = builder.rawRetainDays;
olapRetainDays = builder.olapRetainDays;
}
Expand Down
74 changes: 57 additions & 17 deletions ashv/src/main/java/core/processing/GetFromRemoteAndStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.sleepycat.persist.EntityCursor;
import config.Labels;
import config.profile.ConnProfile;
import config.profile.SqlColProfile;
import core.manager.ColorManager;
import core.manager.ConfigurationManager;
import core.manager.ConstantManager;
Expand All @@ -10,6 +12,33 @@
import gui.chart.ChartDatasetManager;
import gui.chart.panel.NameChartDataset;
import gui.detail.explainplan.ExplainPlanModel10g2;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -19,33 +48,24 @@
import org.jdesktop.swingx.treetable.TreeTableModel;
import org.jetbrains.annotations.NotNull;
import org.rtv.Options;
import config.profile.ConnProfile;
import config.profile.SqlColProfile;
import pojo.SqlPlanPojo;
import pojo.SqlPojo;
import profile.IProfile;
import profile.OracleEE;
import profile.OracleEEObject;
import profile.Postgres;
import remote.RemoteDBManager;
import store.*;
import store.ConvertManager;
import store.OlapCacheManager;
import store.RawStoreManager;
import store.StoreManager;
import store.entity.database.SqlPlan;
import store.entity.olap.AshAggrMinData;
import store.entity.olap.AshUser;
import store.service.OlapDAO;
import utility.StackTraceUtil;
import utility.Utils;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.math.BigDecimal;
import java.sql.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
@Singleton
public class GetFromRemoteAndStore {
Expand Down Expand Up @@ -142,7 +162,8 @@ public void loadDataFromRemoteToLocalStore() {
this.loadUsername();

// For main chart
iProfile.getUniqueTreeEventListByWaitClass().forEach(e-> chartDatasetManager.getMainNameChartDataset()
iProfile.getUniqueTreeEventListByWaitClass().forEach(e ->
chartDatasetManager.getMainNameChartDataset()
.getStackChartPanel().getStackedChart().setSeriesPaintDynamicDetail(e));
}

Expand All @@ -152,7 +173,7 @@ public void loadDataFromRemoteToLocalStore() {
this.loadToMainStackedChart();
log.info("Stop loading olap");

if (!this.isFirstRun) { // resolve the issue with the gap for big data in ASH
if (!this.isFirstRun) { // resolve the issue with the gap for large amount of data in ASH
this.isFirstRun = true;
this.loadDataToOlap();
this.loadToMainStackedChart();
Expand Down Expand Up @@ -517,15 +538,34 @@ private PreparedStatement getPreparedStatement(String sqlText) throws SQLExcepti
PreparedStatement s;
if (!this.isFirstRun) {
s = connection.prepareStatement(sqlText);
ParameterBuilder param = new ParameterBuilder.Builder(currServerTime - ConstantManager.CURRENT_WINDOW, currServerTime).build();
s.setTimestamp(1, new Timestamp(this.storeManager.getDatabaseDAO().getMax(param)));
s.setTimestamp(1, new Timestamp(getSampleTimeValue(currServerTime)));
} else {
s = connection.prepareStatement(sqlText);
s.setTimestamp(1, new Timestamp(sampleTimeG));
}
return s;
}

private long getSampleTimeValue(long currServerTime) {
ParameterBuilder param =
new ParameterBuilder.Builder(currServerTime - ConstantManager.CURRENT_WINDOW, currServerTime)
.build();

long sampleTime = this.storeManager.getDatabaseDAO().getMax(param);

String initialLoadingStr = configurationManager
.getConnectionParameters(connProfile.getConnName()).getInitialLoading();

if (!initialLoadingStr.equals("-1")) {
long initialLoadingLong = Integer.parseInt(initialLoadingStr);
long sampleTimeFromConfig = currServerTime - (initialLoadingLong*60*1000);

sampleTime = Math.max(sampleTimeFromConfig, sampleTime);
}

return sampleTime;
}

private int getColumnIdForCol(String filterCol){
return metadataMap
.get(modNameAshSql)
Expand Down
89 changes: 86 additions & 3 deletions ashv/src/main/java/gui/connect/ConnectToDbArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
Expand All @@ -35,14 +37,18 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JViewport;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
Expand Down Expand Up @@ -109,6 +115,19 @@ public class ConnectToDbArea extends JDialog {
private JLabel profileMessageLbl = new JLabel(Labels.getLabel("gui.connection.profile.message"));
private JLabel offlineLbl = new JLabel(Labels.getLabel("gui.connection.offline"));


private JPanel initialLoadPanel;
private JLabel separatorInitialLoadingLbl = new JLabel(Labels.getLabel("gui.connection.initial.loading"));
private JLabel initialLoadingOracleEELbl = new JLabel(Labels.getLabel("gui.connection.initial.loading.oracle"));
private String initialLoadingAllStr = Labels.getLabel("gui.connection.initial.loading.all");
private String initialLoadingLastStr = Labels.getLabel("gui.connection.initial.loading.last");
private JLabel initialLoadingMinLbl = new JLabel(Labels.getLabel("gui.connection.initial.loading.min"));

private JSpinner initialLoadSpinner;
private SpinnerModel initialSpinnerModel;
private JRadioButton initialLoadAllRButton;
private JRadioButton initialLoadLastRButton;

private JLabel separatorRetainLbl = new JLabel(Labels.getLabel("gui.connection.retain"));
private JLabel retainRawDataLbl = new JLabel(Labels.getLabel("gui.connection.retain.raw"));
private JLabel retainOlapDataLbl = new JLabel(Labels.getLabel("gui.connection.retain.olap"));
Expand Down Expand Up @@ -157,7 +176,7 @@ public ConnectToDbArea(BasicFrame jFrame,
private void init(){
MigLayout lmMain = new MigLayout("", "[grow][][grow]", "[][][]");
MigLayout lmConnMain = new MigLayout("ins 10", "[para]0[grow][150lp, fill][60lp][95lp, fill]", "");
MigLayout lmConnOther = new MigLayout("ins 10", "[para]0[grow][200lp, fill][60lp][95lp, fill]", "");
MigLayout lmConnOther = new MigLayout("ins 10", "[para]0[grow][250lp, fill][60lp][95lp, fill]", "");
MigLayout lmButtonPanel = new MigLayout("fillx", "[50lp][50lp][50lp][50lp]");

mainJPanel = new JPanel(lmMain);
Expand Down Expand Up @@ -273,16 +292,56 @@ private void init_gui(){
configMainJPanel.add(isOffline, "span, growx");
isOffline.setSelected(false);

separatorInitialLoadingLbl.setForeground(LABEL_COLOR);
configOtherJPanel.add(separatorInitialLoadingLbl, "gapbottom 1, span, split 2, aligny center");
configOtherJPanel.add(new JSeparator(), "gapleft rel, growx");

MigLayout lmInitialLoad = new MigLayout("", "[30lp][30lp][30lp][30lp]");
initialLoadPanel = new JPanel(lmInitialLoad);

initialSpinnerModel = new SpinnerNumberModel(5, 0, 120, 1);
initialLoadSpinner = new JSpinner(initialSpinnerModel);
initialLoadSpinner.setToolTipText(Labels.getLabel("gui.connection.initial.loading.tooltip"));

initialLoadAllRButton = new JRadioButton(initialLoadingAllStr);
initialLoadAllRButton.addChangeListener(e -> {
AbstractButton aButton = (AbstractButton)e.getSource();
ButtonModel aModel = aButton.getModel();
if (aModel.isSelected()) {
initialLoadLastRButton.setSelected(false);
initialLoadSpinner.setEnabled(false);
}
});

initialLoadLastRButton = new JRadioButton(initialLoadingLastStr);
initialLoadLastRButton.addChangeListener(e -> {
AbstractButton aButton = (AbstractButton)e.getSource();
ButtonModel aModel = aButton.getModel();
if (aModel.isSelected()) {
initialLoadAllRButton.setSelected(false);
initialLoadSpinner.setEnabled(true);
}
});

initialLoadPanel.add(initialLoadAllRButton, "gap 1");
initialLoadPanel.add(new JSeparator(SwingConstants.VERTICAL), "growy, hmin 10, alignx center");
initialLoadPanel.add(initialLoadLastRButton, "gap 1");
initialLoadPanel.add(initialLoadSpinner);
initialLoadPanel.add(initialLoadingMinLbl);

configOtherJPanel.add(initialLoadingOracleEELbl, "skip");
configOtherJPanel.add(initialLoadPanel, "span, growx, wmin 100");

separatorRetainLbl.setForeground(LABEL_COLOR);
configOtherJPanel.add(separatorRetainLbl, "gapbottom 1, span, split 2, aligny center");
configOtherJPanel.add(new JSeparator(), "gapleft rel, growx");

configOtherJPanel.add(retainRawDataLbl, "skip");
configOtherJPanel.add(rawDataDaysRetainTF, "span, growx");
configOtherJPanel.add(rawDataDaysRetainTF, "span, growx, wmin 150");
rawDataDaysRetainTF.setToolTipText(Labels.getLabel("gui.connection.retain.raw.tooltip"));

configOtherJPanel.add(retainOlapDataLbl, "skip");
configOtherJPanel.add(olapDataDaysRetainTF, "span, growx");
configOtherJPanel.add(olapDataDaysRetainTF, "span, growx, wmin 150");
olapDataDaysRetainTF.setToolTipText(Labels.getLabel("gui.connection.retain.olap.tooltip"));

jButtonConnect.addActionListener(e -> {
Expand Down Expand Up @@ -427,6 +486,10 @@ private void setDetailEditable(boolean bParameter){
jButtonDeleteConfig.setEnabled(!bParameter);
jButtonSaveConfig.setEnabled(bParameter);
jButtonCancel.setEnabled(bParameter);

initialLoadAllRButton.setEnabled(bParameter);
initialLoadLastRButton.setEnabled(bParameter);
initialLoadSpinner.setEnabled(bParameter);
}

private void clearProfileFields(){
Expand All @@ -437,6 +500,9 @@ private void clearProfileFields(){
jarTF.setText("");
rawDataDaysRetainTF.setText("");
olapDataDaysRetainTF.setText("");

initialLoadAllRButton.setSelected(true);
initialLoadLastRButton.setSelected(false);
}

private void copyConnection(){
Expand Down Expand Up @@ -473,6 +539,8 @@ private void selectFromDbAndSetInGui(String connName){
jButtonConnect.setText(Labels.getLabel("gui.connection.button.connect"));
}

setInitialLoading(connParameters.getInitialLoading());

if (!rawDataDaysRetainTF.isEnabled()) {
setTextDataDaysRetainTF(rawDataDaysRetainTF, Integer.parseInt(connParameters.getRawRetainDays()));
}
Expand All @@ -491,6 +559,7 @@ private void saveData(){
.profile(String.valueOf((profileBox.getSelectedItem())))
.driverName(configurationManager.getProfileImpl(
String.valueOf((profileBox.getSelectedItem()))).getDriverName())
.initialLoading(initialLoadAllRButton.isSelected() ? "-1" : initialLoadSpinner.getValue().toString())
.rawRetainDays(rawDataDaysRetainTF.getText())
.olapRetainDays(olapDataDaysRetainTF.getText())
.build();
Expand Down Expand Up @@ -659,4 +728,18 @@ private void setProfileMessageLblVisible(String selectedItem) {
}
}

private void setInitialLoading(String initialLoading) {
if (initialLoading.equals("-1")) {
initialLoadAllRButton.setSelected(true);
initialLoadLastRButton.setSelected(false);
initialLoadSpinner.setEnabled(false);
initialLoadSpinner.setValue(ConstantManager.INITIAL_LOADING_DEFAULT);
} else {
initialLoadAllRButton.setSelected(false);
initialLoadLastRButton.setSelected(true);
initialLoadSpinner.setEnabled(connNameTF.isEnabled());
initialLoadSpinner.setValue(Integer.valueOf(initialLoading));
}
}

}
Loading

0 comments on commit f011c40

Please sign in to comment.