Skip to content

Commit

Permalink
Fixing MID-2866.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed May 25, 2016
1 parent 3fdc3c5 commit 79735c9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
Expand Up @@ -51,6 +51,8 @@ public class EnvironmentalPerformanceInformation {
private Map<NotificationsStatisticsKey,GenericStatisticsData> notificationsData = new HashMap<>();
private Map<MappingsStatisticsKey,GenericStatisticsData> mappingsData = new HashMap<>();

private static final int AGGREGATION_THRESHOLD = 50;

private StatusMessage lastMessage;

public EnvironmentalPerformanceInformation(EnvironmentalPerformanceInformationType value) {
Expand Down Expand Up @@ -109,17 +111,27 @@ private NotificationsStatisticsType toNotificationsStatisticsType() {
}

private MappingsStatisticsType toMappingsStatisticsType() {
MappingsStatisticsType rv = new MappingsStatisticsType();
final MappingsStatisticsType rv = new MappingsStatisticsType();
if (mappingsData == null) {
return rv;
}
final Map<String,Integer> entriesPerType = new HashMap<>();
for (MappingsStatisticsKey key: mappingsData.keySet()) {
Integer current = entriesPerType.get(key.getObjectType());
entriesPerType.put(key.getObjectType(), current != null ? current+1 : 1);
}
for (Map.Entry<MappingsStatisticsKey, GenericStatisticsData> entry : mappingsData.entrySet()) {
MappingsStatisticsKey key = entry.getKey();
String object = key.getObjectName();
MappingsStatisticsEntryType entryType = findMappingsEntryType(rv.getEntry(), object);
final MappingsStatisticsKey key = entry.getKey();
final String targetEntryName;
if (entriesPerType.get(key.getObjectType()) < AGGREGATION_THRESHOLD) {
targetEntryName = key.getObjectName();
} else {
targetEntryName = key.getObjectType() + " (aggregated)";
}
MappingsStatisticsEntryType entryType = findMappingsEntryType(rv.getEntry(), targetEntryName);
if (entryType == null) {
entryType = new MappingsStatisticsEntryType();
entryType.setObject(object);
entryType.setObject(targetEntryName);
rv.getEntry().add(entryType);
}
setValueMapping(entryType, entry.getValue().getCount(),
Expand Down Expand Up @@ -458,9 +470,9 @@ public synchronized void recordNotificationOperation(String transportName, boole
data.recordOperation(duration, 1);
}

public synchronized void recordMappingOperation(String objectOid, String objectName, String mappingName, long duration) {
public synchronized void recordMappingOperation(String objectOid, String objectName, String objectTypeName, String mappingName, long duration) {
// ignoring mapping name for now
MappingsStatisticsKey key = new MappingsStatisticsKey(objectOid, objectName);
MappingsStatisticsKey key = new MappingsStatisticsKey(objectOid, objectName, objectTypeName);
GenericStatisticsData data = mappingsData.get(key);
if (data == null) {
data = new GenericStatisticsData();
Expand Down
Expand Up @@ -21,12 +21,14 @@
*/
public class MappingsStatisticsKey {

private String objectOid;
private String objectName;
private final String objectOid;
private final String objectName;
private final String objectType;

public MappingsStatisticsKey(String objectOid, String objectName) {
public MappingsStatisticsKey(String objectOid, String objectName, String objectType) {
this.objectOid = objectOid;
this.objectName = objectName;
this.objectType = objectType;
}

public String getObjectOid() {
Expand All @@ -37,14 +39,19 @@ public String getObjectName() {
return objectName;
}

@Override
public String getObjectType() {
return objectType;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

MappingsStatisticsKey that = (MappingsStatisticsKey) o;

if (objectOid != null ? !objectOid.equals(that.objectOid) : that.objectOid != null) return false;
if (objectType != null ? !objectType.equals(that.objectType) : that.objectType != null) return false;
return !(objectName != null ? !objectName.equals(that.objectName) : that.objectName != null);

}
Expand Down
Expand Up @@ -56,7 +56,7 @@ public interface StatisticsCollector {

void recordNotificationOperation(String transportName, boolean success, long duration);

void recordMappingOperation(String objectOid, String objectName, String mappingName, long duration);
void recordMappingOperation(String objectOid, String objectName, String objectTypeName, String mappingName, long duration);

/**
* Records information about iterative processing of objects.
Expand Down
Expand Up @@ -80,16 +80,13 @@ public <V extends PrismValue, D extends ItemDefinition, F extends ObjectType> vo
ModelExpressionThreadLocalHolder.pushCurrentResult(parentResult);
ModelExpressionThreadLocalHolder.pushCurrentTask(task);
ObjectType originObject = mapping.getOriginObject();
String objectOid, objectName;
if (originObject instanceof FocusType) {
// MID-2866 - TEMPORARY WORKAROUND: it seems that originObject is sometimes a FocusType ... we have to aggregate such objects by type, as it yields huge statistics
objectOid = null;
objectName = originObject.getClass().getSimpleName();
} else if (originObject != null) {
String objectOid, objectName, objectTypeName;
if (originObject != null) {
objectOid = originObject.getOid();
objectName = String.valueOf(originObject.getName());
objectTypeName = originObject.getClass().getSimpleName();
} else {
objectOid = objectName = null;
objectOid = objectName = objectTypeName = null;
}
String mappingName = mapping.getItemName() != null ? mapping.getItemName().getLocalPart() : null;
long start = System.currentTimeMillis();
Expand All @@ -101,7 +98,7 @@ public <V extends PrismValue, D extends ItemDefinition, F extends ObjectType> vo
task.recordState("Evaluation of mapping " + mapping.getMappingContextDescription() + " finished with error in " + (System.currentTimeMillis()-start) + " ms.");
throw new IllegalArgumentException(e.getMessage()+" in "+mapping.getContextDescription(), e);
} finally {
task.recordMappingOperation(objectOid, objectName, mappingName, System.currentTimeMillis() - start);
task.recordMappingOperation(objectOid, objectName, objectTypeName, mappingName, System.currentTimeMillis() - start);
ModelExpressionThreadLocalHolder.popLensContext();
ModelExpressionThreadLocalHolder.popCurrentResult();
ModelExpressionThreadLocalHolder.popCurrentTask();
Expand Down
Expand Up @@ -699,7 +699,7 @@ public void recordNotificationOperation(String transportName, boolean success, l
}

@Override
public void recordMappingOperation(String objectOid, String objectName, String mappingName, long duration) {
public void recordMappingOperation(String objectOid, String objectName, String objectTypeName, String mappingName, long duration) {
}

@Override
Expand Down
Expand Up @@ -2807,8 +2807,8 @@ public void recordNotificationOperation(String transportName, boolean success, l
}

@Override
public void recordMappingOperation(String objectOid, String objectName, String mappingName, long duration) {
environmentalPerformanceInformation.recordMappingOperation(objectOid, objectName, mappingName, duration);
public void recordMappingOperation(String objectOid, String objectName, String objectTypeName, String mappingName, long duration) {
environmentalPerformanceInformation.recordMappingOperation(objectOid, objectName, objectTypeName, mappingName, duration);
}

@Override
Expand Down

0 comments on commit 79735c9

Please sign in to comment.