Commit 3471dafc authored by Gianluca Filippone's avatar Gianluca Filippone
Browse files

Added list for operations and code refactoring

parent fe9028f1
......@@ -24,9 +24,11 @@ import eu.chorevolution.idm.common.to.OperationDataTO;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.syncope.client.console.panels.OperationPanel;
import org.apache.syncope.client.console.rest.ChoreographyRestClient;
import org.apache.syncope.client.console.widget.StatsWidget;
import org.apache.syncope.client.console.widgets.LabeledDoughnutChartData;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.Model;
......@@ -59,6 +61,9 @@ public class CDDetailPage extends BaseExtPage {
List<OperationDataTO> operations = restClient.operationList(instanceId, cdName);
bundle = new CDStatisticsBundle(operations);
WebMarkupContainer content = new WebMarkupContainer("content");
content.setOutputMarkupId(true);
RepeatingView chartList = new RepeatingView("stats");
// Sleeptime, Overhead and Execution time for each operation
......@@ -121,8 +126,10 @@ public class CDDetailPage extends BaseExtPage {
add(new Label("caption", getString("total_operation_overhead_caption")));
}
});
body.add(chartList);
content.add(chartList);
content.add(new OperationPanel("operations", getPageReference(), instanceId, cdName));
body.add(content);
}
private class CDStatisticsBundle implements Serializable {
......
/*
* Copyright 2016 The CHOReVOLUTION project.
*
* 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.
*/
/*
* Copyright 2016 The CHOReVOLUTION project.
*
* 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 org.apache.syncope.client.console.panels;
import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
import eu.chorevolution.idm.common.to.OperationDataTO;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.apache.syncope.client.console.commons.SearchableDataProvider;
import org.apache.syncope.client.console.pages.InstanceStatsPage;
import org.apache.syncope.client.console.panels.OperationPanel.OperationProvider;
import org.apache.syncope.client.console.rest.ChoreographyRestClient;
import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
import org.apache.syncope.client.console.wizards.WizardMgtPanel;
import org.apache.wicket.PageReference;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;
public class OperationPanel extends AbstractSearchResultPanel<
OperationDataTO, OperationDataTO, OperationProvider, ChoreographyRestClient> {
private static final long serialVersionUID = 3727444742501082182L;
private Long instanceId;
private String cdName;
public OperationPanel(final String id, final PageReference pageRef,
final Long instanceId, final String cdName) {
super(id, new AbstractSearchResultPanel.Builder<OperationDataTO, OperationDataTO, ChoreographyRestClient>(
new ChoreographyRestClient(), pageRef) {
private static final long serialVersionUID = 4218621294354212530L;
@Override
protected WizardMgtPanel<OperationDataTO> newInstance(final String id) {
return new OperationPanel(id, this);
}
}.disableCheckBoxes());
this.instanceId = instanceId;
this.cdName = cdName;
setFooterVisibility(true);
modal.addSumbitButton();
modal.size(Modal.Size.Large);
initResultTable();
}
private OperationPanel(
final String id,
final AbstractSearchResultPanel.Builder<OperationDataTO, OperationDataTO, ChoreographyRestClient> builder) {
super(id, builder);
}
@Override
protected OperationProvider dataProvider() {
return new OperationProvider(rows);
}
@Override
protected String paginatorRowsKey() {
return InstanceStatsPage.PREF_STATS_PAGINATOR_ROWS;
}
@Override
protected Collection<ActionLink.ActionType> getBulkActions() {
return Collections.<ActionLink.ActionType>emptyList();
}
@Override
protected List<IColumn<OperationDataTO, String>> getColumns() {
final List<IColumn<OperationDataTO, String>> columns = new ArrayList<>();
columns.add(new PropertyColumn<>(new ResourceModel("name"), "Name", "name"));
columns.add(new PropertyColumn<>(new ResourceModel("overhead", "Overhead (ms)"), "overhead"));
columns.add(new PropertyColumn<>(new ResourceModel("waitTime", "Wait Time (ms)"), "waitTime"));
columns.add(new PropertyColumn<>(new ResourceModel("serviceExecTime", "Service Execution Time (ms)"),
"serviceExecTime"));
columns.add(new PropertyColumn<>(new ResourceModel("messageNumber", "Coordination Messages"), "messageNumber"));
return columns;
}
protected final class OperationProvider extends SearchableDataProvider<OperationDataTO> {
private static final long serialVersionUID = -185944053385660794L;
private final Comparator<OperationDataTO> comparator;
private OperationProvider(final int paginatorRows) {
super(paginatorRows);
comparator = new Comparator<OperationDataTO>() {
@Override
public int compare(final OperationDataTO o1, final OperationDataTO o2) {
return o1.getName().compareTo(o2.getName());
}
};
}
@Override
public Iterator<OperationDataTO> iterator(final long first, final long count) {
List<OperationDataTO> list = restClient.operationList(instanceId, cdName);
Collections.sort(list, comparator);
return list.subList((int) first, (int) first + (int) count).iterator();
}
@Override
public long size() {
return restClient.operationList(instanceId, cdName).size();
}
@Override
public IModel<OperationDataTO> model(final OperationDataTO object) {
return new CompoundPropertyModel<>(object);
}
}
}
......@@ -22,10 +22,13 @@ limitations under the License.
</h1>
</section>
<section class="content">
<section class="content" wicket:id="content">
<div class="row">
<div class="col-md-6" wicket:id="stats"/>
</div>
<div class="box">
<div class="box-body" wicket:id="operations"/>
</div>
</section>
</wicket:extend>
</html>
\ No newline at end of file
......@@ -110,23 +110,20 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
CoordinationDelegateTO to;
List<String> availableCds = eventDAO.findArtifactsByType(choreographyInstancePK, ArtifactType.CD);
List<String> availableCds = getCdNames(choreographyInstancePK);
for (String cdName : availableCds) {
to = new CoordinationDelegateTO();
to.setName(cdName);
to.setInstanceId(choreographyInstancePK);
List<String> operations = eventDAO.findOperationsByArtifact(choreographyInstancePK, cdName);
List<OperationDataTO> operations = operationList(choreographyInstancePK, ArtifactType.CD, cdName);
int opNumber = 0, messageNumber = 0;
long overhead = 0, serviceExecutionTime = 0, waitTime = 0;
long firstStart = 0, lastEnd = 0;
OperationDataTO operation;
for (String currentOp : operations) {
operation = getOperation(choreographyInstancePK, currentOp);
for (OperationDataTO operation : operations) {
messageNumber = messageNumber + operation.getMessageNumber();
overhead = overhead + operation.getOverhead();
......@@ -159,27 +156,25 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
public List<OperationDataTO> operationList(
final Long choreographyInstancePK,
final String cdName) {
List<String> operationNames = eventDAO.findOperationsByArtifact(choreographyInstancePK, cdName);
final ArtifactType artifactType,
final String artifactName) {
List<OperationDataTO> operations = new LinkedList();
List<String> operationNames = getOperationNames(choreographyInstancePK, artifactName);
for (String currentOp : operationNames) {
operations.add(getOperation(choreographyInstancePK, currentOp));
}
return getOperationList(operationNames, choreographyInstancePK, artifactType, artifactName);
return operations;
}
public OperationDataTO getOperation(
private OperationDataTO getOperation(
final Long choreographyInstancePK,
final String opName) {
final String opName,
final ArtifactType artifactType,
final String artifactName) {
OperationDataTO operation = new OperationDataTO();
operation.setName(opName);
List<Event> loggedEvents = eventDAO.findByOperation(choreographyInstancePK, opName);
List<Event> loggedEvents = eventDAO.findByOperation(choreographyInstancePK, opName, artifactType, artifactName);
long receiveRequest = 0;
long forwardRequest = 0;
......@@ -238,4 +233,26 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
return operation;
}
private List<OperationDataTO> getOperationList(
final List<String> operationNames,
final Long choreographyInstancePK,
final ArtifactType artifactType,
final String artifactName) {
List<OperationDataTO> operations = new LinkedList();
for (String currentOp : operationNames) {
operations.add(getOperation(choreographyInstancePK, currentOp, artifactType, artifactName));
}
return operations;
}
private List<String> getOperationNames(final Long choreographyInstancePK, final String artifactName) {
return eventDAO.findOperationsByArtifact(choreographyInstancePK, artifactName);
}
private List<String> getCdNames(final Long choreographyInstancePK) {
return eventDAO.findArtifactsByType(choreographyInstancePK, ArtifactType.CD);
}
}
......@@ -29,6 +29,10 @@ public interface EventDAO extends DAO<Event, Long> {
List<Event> findByOperation(Long choreographyInstancePK, String operationName);
List<Event> findByOperation(
Long choreographyInstancePK, String operationName,
ArtifactType artifactType, String artifactName);
List<String> findArtifactsByType(Long choreographyInstancePK, ArtifactType artifactType);
List<String> findOperationsByArtifact(Long choreographyInstancePK, String artifactName);
......
......@@ -79,6 +79,27 @@ public class JPAEventDAO extends AbstractDAO<Event, Long> implements EventDAO {
return query.getResultList();
}
@Transactional(readOnly = true)
@Override
public List<Event> findByOperation(
final Long choreographyInstancePK,
final String operationName,
final ArtifactType artifactType,
final String artifactName) {
TypedQuery<Event> query = entityManager().createQuery(
"SELECT e FROM " + JPAEvent.class.getSimpleName()
+ " e WHERE e.choreographyInstance.id = :choreographyInstancePK"
+ " AND e.operationName = :operationName"
+ " AND e.artifactType = :artifactType"
+ " AND e.artifactName = :artifactName",
Event.class);
query.setParameter("choreographyInstancePK", choreographyInstancePK);
query.setParameter("operationName", operationName);
query.setParameter("artifactType", artifactType);
query.setParameter("artifactName", artifactName);
return query.getResultList();
}
@Transactional(readOnly = true)
@Override
public List<String> findArtifactsByType(final Long choreographyInstancePK, final ArtifactType artifactType) {
......@@ -89,7 +110,7 @@ public class JPAEventDAO extends AbstractDAO<Event, Long> implements EventDAO {
String.class);
query.setParameter("choreographyInstancePK", choreographyInstancePK);
query.setParameter("artifactType", artifactType);
return query.getResultList();
return query.getResultList();
}
@Transactional(readOnly = true)
......
......@@ -19,6 +19,7 @@ import eu.chorevolution.idm.common.to.ChoreographyInstanceTO;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.CoordinationDelegateTO;
import eu.chorevolution.idm.common.to.OperationDataTO;
import eu.chorevolution.idm.common.types.ArtifactType;
import java.util.List;
import org.apache.syncope.common.rest.api.service.ConsoleInterfaceService;
import org.apache.syncope.core.logic.MonitorLogic;
......@@ -49,9 +50,8 @@ public class ConsoleInterfaceServiceImpl extends AbstractServiceImpl implements
@Override
public List<OperationDataTO> operationList(
final Long instancePK,
final String cdName) {
return logic.operationList(instancePK, cdName);
final String artifactName) {
return logic.operationList(instancePK, ArtifactType.CD, artifactName);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment