Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/wrapper-cle…
Browse files Browse the repository at this point in the history
…anup
  • Loading branch information
katkav committed Apr 27, 2020
2 parents 2f09dec + 69fc1ad commit ae39b86
Show file tree
Hide file tree
Showing 85 changed files with 2,041 additions and 1,015 deletions.
Expand Up @@ -133,7 +133,7 @@ protected void newObjectPerformed(AjaxRequestTarget target, AssignmentObjectRela
}
}

private List<ObjectReferenceType> getReferencesList(CompiledObjectCollectionView collectionView) {
protected List<ObjectReferenceType> getReferencesList(CompiledObjectCollectionView collectionView) {
if (!isArchetypedCollectionView(collectionView)) {
return null;
}
Expand Down
Expand Up @@ -2102,6 +2102,11 @@ public static <AHT extends AssignmentHolderType> void initNewObjectWithReference
PrismObjectDefinition<AHT> def = prismContext.getSchemaRegistry().findObjectDefinitionByType(type);
PrismObject<AHT> obj = def.instantiate();
AHT assignmentHolder = obj.asObjectable();
initNewObjectWithReference(pageBase, assignmentHolder, newReferences);
}


public static <AHT extends AssignmentHolderType> void initNewObjectWithReference(PageBase pageBase, AHT assignmentHolder, List<ObjectReferenceType> newReferences) throws SchemaException {
if (newReferences != null) {
newReferences.stream().forEach(ref -> {
AssignmentType assignment = new AssignmentType();
Expand All @@ -2119,7 +2124,7 @@ public static <AHT extends AssignmentHolderType> void initNewObjectWithReference
});
}

WebComponentUtil.dispatchToObjectDetailsPage(obj, true, pageBase);
WebComponentUtil.dispatchToObjectDetailsPage(assignmentHolder.asPrismObject(), true, pageBase);
}

public static String createErrorIcon(OperationResult result) {
Expand Down
Expand Up @@ -17,6 +17,7 @@ <h3><wicket:message key="PageInternals.title.cache"/></h3>
<p></p>
<div class="main-button-bar">
<a class="btn btn-primary" wicket:id="clearCaches"/>
<a class="btn btn-primary" wicket:id="dumpContent"/>
</div>

</div>
Expand Down
Expand Up @@ -10,6 +10,8 @@
import com.evolveum.midpoint.util.Holder;
import com.evolveum.midpoint.util.KeyValueTreeNode;
import com.evolveum.midpoint.util.TreeNode;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AceEditor;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.security.MidPointApplication;
Expand All @@ -24,11 +26,16 @@
import java.util.ArrayList;
import java.util.List;

import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;

public class InternalsCachePanel extends BasePanel<Void>{

private static final long serialVersionUID = 1L;

private static final Trace LOGGER = TraceManager.getTrace(InternalsCachePanel.class);

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

public InternalsCachePanel(String id) {
Expand Down Expand Up @@ -58,7 +65,7 @@ public void setObject(String object) {
informationText.setMode(null);
add(informationText);

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

private static final long serialVersionUID = 1L;

Expand All @@ -67,54 +74,89 @@ public void onClick(AjaxRequestTarget target) {
getPageBase().getCacheDispatcher().dispatchInvalidation(null, null, true, null);
target.add(InternalsCachePanel.this);
}
};
});

add(new AjaxButton(ID_DUMP_CONTENT_BUTTON, createStringResource("InternalsCachePanel.button.dumpContent")) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
String cacheInformation = getCacheInformation();
LOGGER.info("Dumping the content of the caches.\nCurrent counters:\n{}\n", cacheInformation);
MidPointApplication.get().getCacheRegistry().dumpContent();

add(clearCaches);
getSession().success(getPageBase().getString("InternalsCachePanel.result.dumped"));
target.add(getPageBase());
}
});
}

private static class SizeInformation {
private final int size;
private final int secondarySize;

private SizeInformation(SingleCacheStateInformationType info) {
size = defaultIfNull(info.getSize(), 0);
secondarySize = defaultIfNull(info.getSecondarySize(), 0);
}

private SizeInformation(ComponentSizeInformationType info) {
size = defaultIfNull(info.getSize(), 0);
secondarySize = defaultIfNull(info.getSecondarySize(), 0);
}
}

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");
});
CachesStateInformationType state = MidPointApplication.get().getCacheRegistry().getStateInformation();
List<KeyValueTreeNode<String, SizeInformation>> trees = new ArrayList<>();
for (SingleCacheStateInformationType entry : state.getEntry()) {
KeyValueTreeNode<String, SizeInformation> root = new KeyValueTreeNode<>(entry.getName(), new SizeInformation(entry));
trees.add(root);
addComponents(root, entry.getComponent());
}
Holder<Integer> maxLabelLength = new Holder<>(0);
Holder<Integer> maxSize = new Holder<>(1); // to avoid issues with log10
Holder<Integer> maxSecondarySize = new Holder<>(1); // to avoid issues with log10
trees.forEach(tree -> tree.acceptDepthFirst(node -> {
int labelLength = node.getUserObject().getKey().length() + node.getDepth() * 2;
int size = node.getUserObject().getValue().size;
int secondarySize = node.getUserObject().getValue().secondarySize;
if (labelLength > maxLabelLength.getValue()) {
maxLabelLength.setValue(labelLength);
}
if (size > maxSize.getValue()) {
maxSize.setValue(size);
}
if (secondarySize > maxSecondarySize.getValue()) {
maxSecondarySize.setValue(secondarySize);
}
}));
int labelSize = Math.max(maxLabelLength.getValue() + 1, 30);
int sizeSize = Math.max((int) Math.log10(maxSize.getValue()) + 2, 7);
int secondarySizeSize = Math.max((int) Math.log10(maxSecondarySize.getValue()) + 2, 8);
int firstPart = labelSize + 3;
int secondPart = sizeSize + 2;
int thirdPart = secondarySizeSize + 3;
String headerFormatString = " %-" + labelSize + "s | %" + sizeSize + "s | %" + secondarySizeSize + "s\n";
String valueFormatString = " %-" + labelSize + "s | %" + sizeSize + "d | %" + secondarySizeSize + "s\n";
sb.append("\n");
sb.append(String.format(headerFormatString, "Cache", "Size", "Sec. size"));
sb.append(StringUtils.repeat("=", firstPart)).append("+")
.append(StringUtils.repeat("=", secondPart)).append("+")
.append(StringUtils.repeat("=", thirdPart)).append("\n");
trees.forEach(tree -> {
tree.acceptDepthFirst(node -> printNode(sb, valueFormatString, node));
sb.append(StringUtils.repeat("-", firstPart)).append("+")
.append(StringUtils.repeat("-", secondPart)).append("+")
.append(StringUtils.repeat("-", thirdPart)).append("\n");
});
return sb.toString();
}

private void printNode(StringBuilder sb, String formatString, TreeNode<Pair<String, Integer>> node) {
Pair<String, Integer> pair = node.getUserObject();
private void printNode(StringBuilder sb, String formatString, TreeNode<Pair<String, SizeInformation>> node) {
Pair<String, SizeInformation> pair = node.getUserObject();
if (pair != null) {
int depth = node.getDepth();
StringBuilder prefix = new StringBuilder();
Expand All @@ -124,13 +166,22 @@ private void printNode(StringBuilder sb, String formatString, TreeNode<Pair<Stri
}
prefix.append("- ");
}
sb.append(String.format(formatString, prefix + pair.getKey(), pair.getValue()));
sb.append(String.format(formatString, prefix + pair.getKey(), pair.getValue().size,
emptyIfZero(pair.getValue().secondarySize)));
}
}

private String emptyIfZero(int number) {
if (number != 0) {
return String.valueOf(number);
} else {
return "";
}
}

private void addComponents(KeyValueTreeNode<String, Integer> node, List<ComponentSizeInformationType> components) {
private void addComponents(KeyValueTreeNode<String, SizeInformation> node, List<ComponentSizeInformationType> components) {
for (ComponentSizeInformationType component : components) {
KeyValueTreeNode<String, Integer> child = node.createChild(component.getName(), component.getSize());
KeyValueTreeNode<String, SizeInformation> child = node.createChild(component.getName(), new SizeInformation(component));
addComponents(child, component.getComponent());
}
}
Expand Down

0 comments on commit ae39b86

Please sign in to comment.