Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Jul 19, 2019
2 parents 38bcc04 + b3aa413 commit 2bfc7f3
Show file tree
Hide file tree
Showing 63 changed files with 1,917 additions and 470 deletions.
Expand Up @@ -609,7 +609,7 @@ public DashboardService getDashboardService() {
return dashboardService;
}

protected ModelDiagnosticService getModelDiagnosticService() {
public ModelDiagnosticService getModelDiagnosticService() {
return modelDiagnosticService;
}

Expand Down
Expand Up @@ -19,12 +19,14 @@
<body>
<wicket:panel>
<div class="row">
<div class="col-md-6">
<div class="col-md-12">
<h3><wicket:message key="PageInternals.title.cache"/></h3>

<div class="main-button-bar">
<a class="btn btn-primary" wicket:id="clearCaches"/>
</div>

<textarea wicket:id="information"></textarea>
<p></p>
<div class="main-button-bar">
<a class="btn btn-primary" wicket:id="clearCaches"/>
</div>

</div>
</div>
Expand Down
@@ -1,15 +1,29 @@
package com.evolveum.midpoint.web.page.admin.configuration;

import org.apache.wicket.ajax.AjaxRequestTarget;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.util.Holder;
import com.evolveum.midpoint.util.KeyValueTreeNode;
import com.evolveum.midpoint.util.TreeNode;
import com.evolveum.midpoint.web.component.AceEditor;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.security.MidPointApplication;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CachesStateInformationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ComponentSizeInformationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;

import java.util.ArrayList;
import java.util.List;

public class InternalsCachePanel extends BasePanel<Void>{

private static final long serialVersionUID = 1L;

private static final String ID_CLEAR_CACHES_BUTTON = "clearCaches";
private static final String ID_INFORMATION = "information";

public InternalsCachePanel(String id) {
super(id);
Expand All @@ -18,19 +32,100 @@ public InternalsCachePanel(String id) {
@Override
protected void onInitialize() {
super.onInitialize();

AjaxButton clearCustomFunctionCache = new AjaxButton(ID_CLEAR_CACHES_BUTTON, createStringResource("InternalsCachePanel.button.clearCaches")) {

setOutputMarkupId(true);

AceEditor informationText = new AceEditor(ID_INFORMATION, new IModel<String>() {
@Override
public String getObject() {
return getCacheInformation();
}

@Override
public void setObject(String object) {
// nothing to do here
}
});
informationText.setReadonly(true);
informationText.setHeight(300);
informationText.setResizeToMaxHeight(true);
informationText.setMode(null);
add(informationText);

AjaxButton clearCaches = new AjaxButton(ID_CLEAR_CACHES_BUTTON, createStringResource("InternalsCachePanel.button.clearCaches")) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
getPageBase().getCacheDispatcher().dispatchInvalidation(null, null, true, null);
target.add(InternalsCachePanel.this);
}
};

add(clearCustomFunctionCache);
add(clearCaches);
}

private String getCacheInformation() {
StringBuilder sb = new StringBuilder();
MidPointApplication midPointApplication = MidPointApplication.get();
if (midPointApplication != null) {
CachesStateInformationType state = midPointApplication.getCacheRegistry().getStateInformation();
List<KeyValueTreeNode<String, Integer>> trees = new ArrayList<>();
for (SingleCacheStateInformationType entry : state.getEntry()) {
KeyValueTreeNode<String, Integer> root = new KeyValueTreeNode<>(entry.getName(), entry.getSize());
trees.add(root);
addComponents(root, entry.getComponent());
}
Holder<Integer> maxLabelLength = new Holder<>(0);
Holder<Integer> maxSize = new Holder<>(0);
trees.forEach(tree -> tree.acceptDepthFirst(node -> {
int labelLength = node.getUserObject().getKey().length() + node.getDepth() * 2;
Integer size = node.getUserObject().getValue();
if (labelLength > maxLabelLength.getValue()) {
maxLabelLength.setValue(labelLength);
}
if (size != null && size > maxSize.getValue()) {
maxSize.setValue(size);
}
}));
int labelSize = Math.max(maxLabelLength.getValue() + 1, 30);
int sizeSize = Math.max((int) Math.log10(maxSize.getValue()) + 2, 7);
int firstPart = labelSize + 3;
int secondPart = sizeSize + 3;
String headerFormatString = " %-" + labelSize + "s | %" + sizeSize + "s \n";
String valueFormatString = " %-" + labelSize + "s | %" + sizeSize + "d \n";
//System.out.println("valueFormatString = " + valueFormatString);
sb.append("\n");
sb.append(String.format(headerFormatString, "Cache", "Size"));
sb.append(StringUtils.repeat("=", firstPart)).append("+").append(StringUtils.repeat("=", secondPart)).append("\n");
trees.forEach(tree -> {
tree.acceptDepthFirst(node -> printNode(sb, valueFormatString, node));
sb.append(StringUtils.repeat("-", firstPart)).append("+").append(StringUtils.repeat("-", secondPart)).append("\n");
});
}
return sb.toString();
}


private void printNode(StringBuilder sb, String formatString, TreeNode<Pair<String, Integer>> node) {
Pair<String, Integer> pair = node.getUserObject();
if (pair != null) {
int depth = node.getDepth();
StringBuilder prefix = new StringBuilder();
if (depth > 0) {
for (int i = 0; i < depth - 1; i++) {
prefix.append(" ");
}
prefix.append("- ");
}
sb.append(String.format(formatString, prefix + pair.getKey(), pair.getValue()));
}
}

private void addComponents(KeyValueTreeNode<String, Integer> node, List<ComponentSizeInformationType> components) {
for (ComponentSizeInformationType component : components) {
KeyValueTreeNode<String, Integer> child = node.createChild(component.getName(), component.getSize());
addComponents(child, component.getComponent());
}
}
}
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 Evolveum
~
~ 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.
-->

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>

<textarea wicket:id="information"></textarea>

</wicket:panel>
</body>
</html>

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2010-2019 Evolveum
*
* 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 com.evolveum.midpoint.web.page.admin.configuration;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.schema.util.ExceptionUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.web.component.AceEditor;
import org.apache.wicket.model.IModel;

/**
* Unfinished.
*/
public class InternalsMemoryPanel extends BasePanel<Void> {
private static final long serialVersionUID = 1L;

private static final String ID_INFORMATION = "information";

private static final String OPERATION_GET_MEMORY_INFORMATION = InternalsMemoryPanel.class.getName() + ".getMemoryInformation";

InternalsMemoryPanel(String id) {
super(id);
initLayout();
}

private void initLayout() {
AceEditor informationText = new AceEditor(ID_INFORMATION, new IModel<String>() {
@Override
public String getObject() {
return getMemoryInformation();
}

@Override
public void setObject(String object) {
// nothing to do here
}
});
informationText.setReadonly(true);
informationText.setHeight(300);
informationText.setResizeToMaxHeight(true);
informationText.setMode(null);
add(informationText);

}

@SuppressWarnings("Duplicates")
private String getMemoryInformation() {
try {
Task task = getPageBase().createSimpleTask(OPERATION_GET_MEMORY_INFORMATION);
return getPageBase().getModelDiagnosticService().getMemoryInformation(task, task.getResult());
} catch (Throwable t) {
// TODO show feedback message as well
return ExceptionUtil.printStackTrace(t);
}
}
}
Expand Up @@ -57,8 +57,6 @@ public class PageInternals extends PageAdminConfiguration {

private static final String ID_TAB_PANEL = "tabPanel";



private LoadableModel<XMLGregorianCalendar> model;
private IModel<InternalsConfigDto> internalsModel;
private Map<String,Boolean> tracesMap;
Expand Down Expand Up @@ -163,10 +161,18 @@ public WebMarkupContainer getPanel(String panelId) {
return initPerformancePanel(panelId);
}
});
// TODO show only if experimental features are enabled?
tabs.add(new AbstractTab(createStringResource("PageInternals.tab.memory")) {

TabbedPanel<ITab> tabPannel = new TabbedPanel<>(ID_TAB_PANEL, tabs);
add(tabPannel);

private static final long serialVersionUID = 1L;

@Override
public WebMarkupContainer getPanel(String panelId) {
return initMemoryPanel(panelId);
}
});

add(new TabbedPanel<>(ID_TAB_PANEL, tabs));
}

private WebMarkupContainer createClockPanel(String panelId) {
Expand Down Expand Up @@ -200,4 +206,8 @@ private WebMarkupContainer initThreadsPanel(String panelId) {
private WebMarkupContainer initPerformancePanel(String panelId) {
return new InternalsPerformancePanel(panelId);
}

private WebMarkupContainer initMemoryPanel(String panelId) {
return new InternalsMemoryPanel(panelId);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExportType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.JasperReportEngineConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.commons.lang.BooleanUtils;
Expand Down Expand Up @@ -66,18 +67,31 @@ public ReportDto(byte[] reportJrxml) {
public ReportDto(ReportType reportType, boolean onlyForPromptingParams) {
this.oid = reportType.getOid();
this.name = reportType.getName().getOrig();
this.exportType = reportType.getExport();
this.searchOnResource = false;
this.description = reportType.getDescription();
// this.xml = new String(Base64.decodeBase64(reportType.getTemplate()));
this.jasperReportDto = new JasperReportDto(reportType.getTemplate(), onlyForPromptingParams);
this.templateStyle = reportType.getTemplateStyle();
this.parent = !BooleanUtils.isFalse(reportType.isParent());
this.virtualizer = reportType.getVirtualizer();
this.virtualizerKickOn = reportType.getVirtualizerKickOn();
this.maxPages = reportType.getMaxPages();
this.timeout = reportType.getTimeout();
this.reportType = reportType;
this.searchOnResource = false;
JasperReportEngineConfigurationType jasperConfig = reportType.getJasper();
if (jasperConfig == null) {
this.exportType = reportType.getExport();
// this.xml = new String(Base64.decodeBase64(reportType.getTemplate()));
this.jasperReportDto = new JasperReportDto(reportType.getTemplate(), onlyForPromptingParams);
this.templateStyle = reportType.getTemplateStyle();
this.parent = !BooleanUtils.isFalse(reportType.isParent());
this.virtualizer = reportType.getVirtualizer();
this.virtualizerKickOn = reportType.getVirtualizerKickOn();
this.maxPages = reportType.getMaxPages();
this.timeout = reportType.getTimeout();
} else {
this.exportType = jasperConfig.getExport();
// this.xml = new String(Base64.decodeBase64(reportType.getTemplate()));
this.jasperReportDto = new JasperReportDto(jasperConfig.getTemplate(), onlyForPromptingParams);
this.templateStyle = jasperConfig.getTemplateStyle();
this.parent = !BooleanUtils.isFalse(jasperConfig.isParent());
this.virtualizer = jasperConfig.getVirtualizer();
this.virtualizerKickOn = jasperConfig.getVirtualizerKickOn();
this.maxPages = jasperConfig.getMaxPages();
this.timeout = jasperConfig.getTimeout();
}
}

public ReportDto(ReportType reportType) {
Expand Down
Expand Up @@ -124,7 +124,7 @@ private ResourceVisualizationDto loadVisualizationDto() {
renderer += " -Tsvg";
StringBuilder output = new StringBuilder();
try {
SystemUtil.executeCommand(renderer, dot, output);
SystemUtil.executeCommand(renderer, dot, output, -1);
return new ResourceVisualizationDto(dot, output.toString(), null);
} catch (IOException|RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute SVG renderer command: {}", e, renderer);
Expand Down
Expand Up @@ -44,6 +44,7 @@
import javax.validation.Validator;
import javax.xml.datatype.Duration;

import com.evolveum.midpoint.repo.cache.CacheRegistry;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.io.IOUtils;
import org.apache.wicket.Component;
Expand Down Expand Up @@ -232,6 +233,8 @@ public class MidPointApplication extends AuthenticatedWebApplication implements
@Autowired
transient private RepositoryService repositoryService; // temporary
@Autowired
transient private CacheRegistry cacheRegistry;
@Autowired
transient private WorkflowService workflowService;
@Autowired
transient private WorkflowManager workflowManager;
Expand Down Expand Up @@ -556,6 +559,10 @@ public RepositoryService getRepositoryService() {
return repositoryService;
}

public CacheRegistry getCacheRegistry() {
return cacheRegistry;
}

public TaskService getTaskService() {
return taskService;
}
Expand Down

0 comments on commit 2bfc7f3

Please sign in to comment.