Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jul 6, 2017
2 parents a717be8 + 4aa648e commit 083186e
Show file tree
Hide file tree
Showing 20 changed files with 841 additions and 127 deletions.
Expand Up @@ -66,9 +66,7 @@ public class GetOperationOptions extends AbstractOptions implements Serializable
private Boolean resolve;

/**
* Resolve the object reference names. (Currently applicable only as a top-level option.)
*
* EXPERIMENTAL.
* Resolve the object reference names.
*/
private Boolean resolveNames;

Expand Down Expand Up @@ -149,6 +147,11 @@ public class GetOperationOptions extends AbstractOptions implements Serializable
*/
private Boolean distinct;

/**
* Whether to attach diagnostics data to the returned object(s).
*/
private Boolean attachDiagData;

public RetrieveOption getRetrieve() {
return retrieve;
}
Expand Down Expand Up @@ -650,6 +653,32 @@ public static GetOperationOptions createDistinct() {
return opts;
}

public Boolean getAttachDiagData() {
return attachDiagData;
}

public void setAttachDiagData(Boolean value) {
this.attachDiagData = value;
}

public static boolean isAttachDiagData(GetOperationOptions options) {
if (options == null) {
return false;
}
if (options.attachDiagData == null) {
return false;
}
return options.attachDiagData;
}

/**
* Whether to attach diagnostics data to the returned object(s).
*/
public static GetOperationOptions createAttachDiagData() {
GetOperationOptions opts = new GetOperationOptions();
opts.setAttachDiagData(true);
return opts;
}

public RelationalValueSearchQuery getRelationalValueSearchQuery() {
return relationalValueSearchQuery;
Expand Down
Expand Up @@ -47,6 +47,7 @@ public class OperationConstants {
public static final String CREATE_REPORT_FILE = PREFIX + ".createReportFile";

public static final String CHECK_SHADOW_INTEGRITY = PREFIX + ".checkShadowIntegrity";
public static final String CHECK_OBJECT_INTEGRITY = PREFIX + ".checkObjectIntegrity";
public static final String REINDEX = PREFIX + ".reindex";
public static final String AUDIT_REINDEX = PREFIX + ".auditReindex";
public static final String SHADOW_REFRESH = PREFIX + ".shadowRefresh";
Expand Down
@@ -0,0 +1,153 @@
/*
* Copyright (c) 2010-2017 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.util.histogram;

import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;

/**
* @author mederly
*/
public class Histogram<T> {

private final int step;
private final int maxLength;

public Histogram(int step, int maxLength) {
this.step = step;
this.maxLength = maxLength;
}

private final ArrayList<HistogramEntry<T>> entries = new ArrayList<>();

private long minValue, maxValue, totalValue = 0;
private T minItem, maxItem;
private int items = 0;

public void register(T item, long value) {
if (items == 0) {
minValue = maxValue = value;
minItem = maxItem = item;
} else {
if (value < minValue) {
minValue = value;
minItem = item;
}
if (value > maxValue) {
maxValue = value;
maxItem = item;
}
}
totalValue += value;
items++;

long bucketLong = value / step;
int bucket = bucketLong < maxLength-1 ? (int) bucketLong : maxLength-1;
if (entries.size() <= bucket) {
entries.ensureCapacity(bucket);
while (entries.size() <= bucket) {
entries.add(new HistogramEntry<>());
}
}
entries.get(bucket).record(item, value);
}

public int getStep() {
return step;
}

public int getMaxLength() {
return maxLength;
}

public ArrayList<HistogramEntry<T>> getEntries() {
return entries;
}

@SuppressWarnings("unused")
public long getMinValue() {
return minValue;
}

@SuppressWarnings("unused")
public long getMaxValue() {
return maxValue;
}

@SuppressWarnings("unused")
public long getTotalValue() {
return totalValue;
}

public int getItems() {
return items;
}

public String dump(int columns) {
StringBuilder sb = new StringBuilder();
sb.append("Count: ").append(items).append("\n");
if (items == 0) {
return sb.toString();
}
sb.append("Min: ").append(minValue).append(" (").append(minItem).append(")\n");
sb.append("Max: ").append(maxValue).append(" (").append(maxItem).append(")\n");
sb.append("Avg: ").append(totalValue / items).append("\n");
sb.append("\nHistogram:\n\n");
int maxIntervalLength = Math.max(getIntervalString(entries.size()).length(), 10);
String rowFormatString = "%" + maxIntervalLength + "s : %6s : %s : %s\n";
//noinspection ConstantConditions
int maxCount = entries.stream().mapToInt(e -> e.getItemsCount()).max().getAsInt();
sb.append(String.format(rowFormatString, "Interval", "Items", column(0, maxCount, columns), "Representative"));
sb.append(StringUtils.repeat("-", maxIntervalLength + columns + 40)).append("\n");
for (int i = 0; i < entries.size(); i++) {
HistogramEntry<T> entry = entries.get(i);
sb.append(String.format(rowFormatString, getIntervalString(i),
String.valueOf(entry.getItemsCount()), column(entry.getItemsCount(), maxCount, columns), getRepresentative(entry)));
}
sb.append("\n");
return sb.toString();
}

private Object column(int count, int maxCount, int columns) {
int bars = (int) ((double) columns * (double) count / (double) maxCount);
return StringUtils.repeat("#", bars) + StringUtils.repeat(" ", columns-bars);
}

private String getRepresentative(HistogramEntry<T> entry) {
if (entry.getRepresentativeItem() == null) {
return "";
}
return entry.getRepresentativeItem() + " (" + entry.getRepresentativeItemValue() + ")";
}

private String getIntervalString(int i) {
if (i == entries.size()-1) {
return String.format("[%d-%d]", getLower(i), maxValue);
} else {
return String.format("[%d-%d]", getLower(i), getUpper(i));
}
}

private long getLower(int bucket) {
return bucket * step;
}

private long getUpper(int bucket) {
return getLower(bucket+1)-1;
}
}
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2010-2017 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.util.histogram;

/**
* @author mederly
*/
public class HistogramEntry<T> {

private int itemsCount;
private long representativeItemValue;
private T representativeItem;

public int getItemsCount() {
return itemsCount;
}

public T getRepresentativeItem() {
return representativeItem;
}

public long getRepresentativeItemValue() {
return representativeItemValue;
}

public void record(T item, long value) {
if (representativeItem == null || representativeItemValue < value) {
representativeItem = item;
representativeItemValue = value;
}
itemsCount++;
}
}
Expand Up @@ -33,6 +33,7 @@ public class ModelPublicConstants {
public static final String AUDIT_REINDEX_TASK_HANDLER_URI = SchemaConstants.NS_MODEL + "/auditReindex/handler-3";
public static final String CLEANUP_TASK_HANDLER_URI = SchemaConstants.NS_MODEL + "/cleanup/handler-3";
public static final String SHADOW_INTEGRITY_CHECK_TASK_HANDLER_URI = SchemaConstants.NS_MODEL + "/shadow-integrity-check/handler-3";
public static final String OBJECT_INTEGRITY_CHECK_TASK_HANDLER_URI = SchemaConstants.NS_MODEL + "/object-integrity-check/handler-3";
public static final String FOCUS_VALIDITY_SCANNER_TASK_HANDLER_URI = NS_SYNCHRONIZATION_TASK_PREFIX + "/focus-validation-scanner/handler-3"; // TODO why synchronization?
public static final String TRIGGER_SCANNER_TASK_HANDLER_URI = SchemaConstants.NS_MODEL + "/trigger/scanner/handler-3";
public static final String SHADOW_REFRESH_TASK_HANDLER_URI = SchemaConstants.NS_MODEL + "/shadowRefresh/handler-3";
Expand Down

0 comments on commit 083186e

Please sign in to comment.