Skip to content

Commit

Permalink
First attempt at showing current state + performance info, shown from…
Browse files Browse the repository at this point in the history
… GUI.
  • Loading branch information
mederly committed Sep 14, 2015
1 parent 2353f9a commit 7ec3e46
Show file tree
Hide file tree
Showing 37 changed files with 1,877 additions and 151 deletions.
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2010-2015 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.component.progress;

import com.evolveum.midpoint.schema.statistics.GenericStatisticsData;
import com.evolveum.midpoint.schema.statistics.MappingsStatisticsKey;
import com.evolveum.midpoint.schema.statistics.OperationalInformation;
import org.apache.commons.lang.StringUtils;

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

/**
* @author Pavol Mederly
*/
public class MappingsLineDto {

public static final String F_OBJECT = "object";
public static final String F_COUNT = "count";
public static final String F_AVERAGE_TIME = "averageTime";
public static final String F_MIN_TIME = "minTime";
public static final String F_MAX_TIME = "maxTime";
public static final String F_TOTAL_TIME = "totalTime";

private String object;
private int count;
private Integer minTime;
private Integer maxTime;
private int totalTime;

public MappingsLineDto(String object) {
this.object = object;
}

public String getObject() {
return object;
}

public int getCount() {
return count;
}

public int getAverageTime() {
if (count > 0) {
return totalTime / count;
} else {
return 0;
}
}

public int getMinTime() {
return minTime != null ? minTime : 0;
}

public int getMaxTime() {
return maxTime != null ? maxTime : 0;
}

public int getTotalTime() {
return totalTime;
}

public static List<MappingsLineDto> extractFromOperationalInformation(OperationalInformation operationalInformation) {
List<MappingsLineDto> retval = new ArrayList<>();
Map<MappingsStatisticsKey, GenericStatisticsData> dataMap = operationalInformation.getMappingsData();
if (dataMap == null) {
return retval;
}
// this is much more generic that needs to be - but useful for future, maybe
for (Map.Entry<MappingsStatisticsKey, GenericStatisticsData> entry : dataMap.entrySet()) {
MappingsStatisticsKey key = entry.getKey();
String object = key.getObjectName() != null ? key.getObjectName() : key.getObjectOid();
MappingsLineDto lineDto = findLineDto(retval, object);
if (lineDto == null) {
lineDto = new MappingsLineDto(object);
retval.add(lineDto);
}
lineDto.setValue(entry.getValue().getCount(), entry.getValue().getMinDuration(),
entry.getValue().getMaxDuration(), entry.getValue().getTotalDuration());
}
return retval;
}

private static MappingsLineDto findLineDto(List<MappingsLineDto> list, String object) {
for (MappingsLineDto lineDto : list) {
if (StringUtils.equals(lineDto.getObject(), object)) {
return lineDto;
}
}
return null;
}

private void setValue(int count, int min, int max, long totalDuration) {
this.count += count;
if (minTime == null || min < minTime) {
minTime = min;
}
if (maxTime == null || max > maxTime) {
maxTime = max;
}
totalTime += totalDuration;
}
}
@@ -0,0 +1,128 @@
/*
* Copyright (c) 2010-2015 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.component.progress;

import com.evolveum.midpoint.schema.statistics.GenericStatisticsData;
import com.evolveum.midpoint.schema.statistics.NotificationsStatisticsKey;
import com.evolveum.midpoint.schema.statistics.OperationalInformation;
import org.apache.commons.lang.StringUtils;

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

/**
* @author Pavol Mederly
*/
public class NotificationsLineDto {

public static final String F_TRANSPORT = "transport";
public static final String F_COUNT_SUCCESS = "countSuccess";
public static final String F_COUNT_FAILURE = "countFailure";
public static final String F_AVERAGE_TIME = "averageTime";
public static final String F_MIN_TIME = "minTime";
public static final String F_MAX_TIME = "maxTime";
public static final String F_TOTAL_TIME = "totalTime";

private String transport;
private int countSuccess;
private int countFailure;
private Integer minTime;
private Integer maxTime;
private int totalTime;

public NotificationsLineDto(String transport) {
this.transport = transport;
}

public String getTransport() {
return transport;
}

public int getCountSuccess() {
return countSuccess;
}

public int getCountFailure() {
return countFailure;
}

public int getAverageTime() {
int count = countSuccess + countFailure;
if (count > 0) {
return totalTime / count;
} else {
return 0;
}
}

public int getMinTime() {
return minTime != null ? minTime : 0;
}

public int getMaxTime() {
return maxTime != null ? maxTime : 0;
}

public int getTotalTime() {
return totalTime;
}

public static List<NotificationsLineDto> extractFromOperationalInformation(OperationalInformation operationalInformation) {
List<NotificationsLineDto> retval = new ArrayList<>();
Map<NotificationsStatisticsKey, GenericStatisticsData> dataMap = operationalInformation.getNotificationsData();
if (dataMap == null) {
return retval;
}
for (Map.Entry<NotificationsStatisticsKey, GenericStatisticsData> entry : dataMap.entrySet()) {
NotificationsStatisticsKey key = entry.getKey();
String transport = key.getTransport();
NotificationsLineDto lineDto = findLineDto(retval, transport);
if (lineDto == null) {
lineDto = new NotificationsLineDto(transport);
retval.add(lineDto);
}
lineDto.setValue(key.isSuccess(), entry.getValue().getCount(), entry.getValue().getMinDuration(),
entry.getValue().getMaxDuration(), entry.getValue().getTotalDuration());
}
return retval;
}

private static NotificationsLineDto findLineDto(List<NotificationsLineDto> list, String transport) {
for (NotificationsLineDto lineDto : list) {
if (StringUtils.equals(lineDto.getTransport(), transport)) {
return lineDto;
}
}
return null;
}

private void setValue(boolean success, int count, int min, int max, long totalDuration) {
if (success) {
this.countSuccess += count;
} else {
this.countFailure += count;
}
if (minTime == null || min < minTime) {
minTime = min;
}
if (maxTime == null || max > maxTime) {
maxTime = max;
}
totalTime += totalDuration;
}
}
Expand Up @@ -16,6 +16,8 @@

package com.evolveum.midpoint.web.component.progress;

import com.evolveum.midpoint.schema.statistics.StatusMessage;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -27,6 +29,7 @@ public class ProgressDto implements Serializable {

private List<ProgressReportActivityDto> progressReportActivities = new ArrayList<>();
private List<String> logItems = new ArrayList<>();
private List<StatusMessage> logEntries = new ArrayList<>();

public List<ProgressReportActivityDto> getProgressReportActivities() {
return progressReportActivities;
Expand Down Expand Up @@ -65,4 +68,8 @@ public boolean allSuccess() {
}
return true;
}

public List<StatusMessage> getLogEntries() {
return logEntries;
}
}
Expand Up @@ -31,6 +31,9 @@
<td><span wicket:id="comment"/></td>
</tr>
</table>

<div wicket:id="statistics"/>

<span wicket:id="executionTime"/>
<span wicket:id="logItems">
<span wicket:id="logItem">label</span><br/>
Expand Down
Expand Up @@ -17,19 +17,17 @@
package com.evolveum.midpoint.web.component.progress;

import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusIcon;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import java.util.List;

Expand All @@ -46,6 +44,7 @@ public class ProgressPanel extends SimplePanel<ProgressDto> {
private static final String ID_ACTIVITY_DESCRIPTION = "description";
private static final String ID_ACTIVITY_STATE = "status";
private static final String ID_ACTIVITY_COMMENT = "comment";
private static final String ID_STATISTICS = "statistics";
private static final String ID_LOG_ITEMS = "logItems";
private static final String ID_LOG_ITEM = "logItem";
private static final String ID_EXECUTION_TIME = "executionTime";
Expand All @@ -54,6 +53,8 @@ public class ProgressPanel extends SimplePanel<ProgressDto> {
private long operationDurationTime; // if >0, operation has finished

private WebMarkupContainer contentsPanel;
private StatisticsPanel statisticsPanel;
private transient Task task;

public ProgressPanel(String id) {
super(id);
Expand Down Expand Up @@ -159,6 +160,9 @@ private Label createImageLabel(String id, IModel<String> cssClass, IModel<String
};
contentsPanel.add(statusItemsListView);

statisticsPanel = new StatisticsPanel(ID_STATISTICS, task);
contentsPanel.add(statisticsPanel);

ListView logItemsListView = new ListView(ID_LOG_ITEMS, new AbstractReadOnlyModel<List>() {
@Override
public List getObject() {
Expand Down Expand Up @@ -206,4 +210,15 @@ public void recordExecutionStart() {
public void recordExecutionStop() {
operationDurationTime = System.currentTimeMillis() - operationStartTime;
}

public void setTask(Task task) {
this.task = task;
if (statisticsPanel != null) {
statisticsPanel.setTask(task);
}
}

public Task getTask() {
return task;
}
}
Expand Up @@ -173,6 +173,7 @@ private void executeChangesAsync(final Collection<ObjectDelta<? extends ObjectTy
startRefreshingProgressPanel(target);
showProgressPanel();

progressPanel.setTask(task);
progressListener = new DefaultGuiProgressListener(parentPage, progressPanel.getModelObject());
Runnable execution = new Runnable() {
@Override
Expand Down

0 comments on commit 7ec3e46

Please sign in to comment.