Commit 3bd2eb53 authored by Gianluca Filippone's avatar Gianluca Filippone
Browse files

Completed client console interface and added console interface service

parent f1082173
/*
* 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 eu.chorevolution.idm.common.to;
import javax.ws.rs.PathParam;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.syncope.common.lib.AbstractBaseBean;
@XmlRootElement(name = "coordinationDelegate")
@XmlType
public class CoordinationDelegateTO extends AbstractBaseBean {
private static final long serialVersionUID = -7470302261846306678L;
private long key;
private String name;
private String choreographyInstanceName;
private int executedOperations;
private int sentMessages;
private long totalExecutionTime;
private long totalOverhead;
@PathParam("key")
public long getKey() {
return key;
}
public void setKey(final long key) {
this.key = key;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getChoreographyInstanceName() {
return choreographyInstanceName;
}
public void setChoreographyInstanceName(final String choreographyInstanceName) {
this.choreographyInstanceName = choreographyInstanceName;
}
public int getExecutedOperations() {
return executedOperations;
}
public void setExecutedOperations(final int executedOperations) {
this.executedOperations = executedOperations;
}
public void setSentMessages(final int sentMessages) {
this.sentMessages = sentMessages;
}
public int getSentMessages() {
return sentMessages;
}
public long getTotalExecutionTime() {
return totalExecutionTime;
}
public void setTotalExecutionTime(final long totalExecutionTime) {
this.totalExecutionTime = totalExecutionTime;
}
public long getTotalOverhead() {
return totalOverhead;
}
public void setTotalOverhead(final long totalOverhead) {
this.totalOverhead = totalOverhead;
}
}
......@@ -20,11 +20,12 @@ import com.pingunaut.wicket.chartjs.chart.impl.Doughnut;
import com.pingunaut.wicket.chartjs.core.panel.BarChartPanel;
import com.pingunaut.wicket.chartjs.core.panel.DoughnutChartPanel;
import com.pingunaut.wicket.chartjs.data.sets.BarDataSet;
import eu.chorevolution.idm.common.to.CoordinationDelegateTO;
import java.util.ArrayList;
import java.util.List;
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;
......@@ -35,53 +36,42 @@ public class InstanceStatsPage extends AbstractExtPage {
private static final long serialVersionUID = 3932245590233237182L;
public static final String PREF_STATS_PAGINATOR_ROWS = "stats.paginator.rows";
private final ChoreographyRestClient restClient;
private final String instanceName;
private final StatisticBundle bundle;
public InstanceStatsPage(final PageParameters parameters) {
super(parameters);
String instanceId = parameters.get("instance").toString();
String instanceName = parameters.get("name").toString();
restClient = new ChoreographyRestClient();
instanceName = parameters.get("instance").toString();
body.add(new Label("header", getString("header_title") + " " + instanceName));
//WebMarkupContainer content = new WebMarkupContainer("content");
//content.setOutputMarkupId(true);
List<CoordinationDelegateTO> cds = restClient.cdList(instanceName);
bundle = new StatisticBundle(cds);
RepeatingView chartList = new RepeatingView("stats");
//Total overhead and total execution time per CD (+ mean)
//Mean overhead and total execution time per CD (+ total average)
chartList.add(new StatsWidget(chartList.newChildId()) {
@Override
public void create() {
List<String> labels = new ArrayList<>();
labels.add("CD 1");
labels.add("CD 2");
labels.add("CD 3");
labels.add("CD 4");
labels.add("CD 5");
labels.add("Mean");
List<Double> overheads = new ArrayList<>();
overheads.add(12d);
overheads.add(10d);
overheads.add(5d);
overheads.add(9d);
overheads.add(14d);
overheads.add(10d);
List<Double> execTimes = new ArrayList<>();
execTimes.add(20d);
execTimes.add(15d);
execTimes.add(19d);
execTimes.add(11d);
execTimes.add(20d);
execTimes.add(16d);
bundle.labels.add("Overall mean");
double meanOverhead = (double) bundle.totalOverhead / bundle.totalOperations;
bundle.meanOverheads.add(Math.floor(meanOverhead));
double meanExecTime = (double) bundle.totalExecution / bundle.totalOperations;
bundle.meanExecTimes.add(Math.floor(meanExecTime));
Bar bar = new Bar();
bar.getData().getLabels().addAll(labels);
BarDataSet overheadDataSet = new BarDataSet(overheads);
bar.getData().getLabels().addAll(bundle.labels);
BarDataSet overheadDataSet = new BarDataSet(bundle.meanOverheads);
overheadDataSet.setFillColor("rgba(151,187,205,0.5)");
overheadDataSet.setStrokeColor("rgba(151,187,205,0.8)");
bar.getData().getDatasets().add(overheadDataSet);
bar.getData().getDatasets().add(new BarDataSet(execTimes));
bar.getData().getDatasets().add(new BarDataSet(bundle.meanExecTimes));
add(new BarChartPanel("chart", Model.of(bar)));
add(new Label("title", getString("cd_overhead_title")));
}
......@@ -90,35 +80,19 @@ public class InstanceStatsPage extends AbstractExtPage {
chartList.add(new StatsWidget(chartList.newChildId()) {
@Override
public void create() {
List<String> labels = new ArrayList<>();
labels.add("CD 1");
labels.add("CD 2");
labels.add("CD 3");
labels.add("CD 4");
labels.add("CD 5");
List<Double> operations = new ArrayList<>();
operations.add(2d);
operations.add(4d);
operations.add(1d);
operations.add(6d);
operations.add(1d);
List<Double> messages = new ArrayList<>();
messages.add(10d);
messages.add(7d);
messages.add(4d);
messages.add(13d);
messages.add(2d);
Bar bar = new Bar();
bar.getData().getLabels().addAll(labels);
BarDataSet operationsDataSet = new BarDataSet(operations);
bar.getData().getLabels().addAll(bundle.labels);
int meanExecutedOperations = (int) Math.floor(bundle.totalOperations / cds.size());
bundle.operations.add(meanExecutedOperations);
BarDataSet operationsDataSet = new BarDataSet(bundle.operations);
operationsDataSet.setFillColor("rgba(151,187,205,0.5)");
operationsDataSet.setStrokeColor("rgba(151,187,205,0.8)");
bar.getData().getDatasets().add(operationsDataSet);
bar.getData().getDatasets().add(new BarDataSet(messages));
int meanSentMessages = (int) Math.floor(bundle.totalMessages / cds.size());
bundle.messages.add(meanSentMessages);
bar.getData().getDatasets().add(new BarDataSet(bundle.messages));
add(new BarChartPanel("chart", Model.of(bar)));
add(new Label("title", getString("cd_operations_title")));
......@@ -132,16 +106,16 @@ public class InstanceStatsPage extends AbstractExtPage {
doughnut.getOptions().setResponsive(true);
doughnut.getOptions().setMaintainAspectRatio(true);
doughnut.getOptions().setTooltipTemplate("<%= label %>");
int totalExecution = 80;
int overhead = 50;
int execution = totalExecution - overhead;
long totalExecution = bundle.totalExecution;
long overhead = bundle.totalOverhead;
int execution = (int) (totalExecution - overhead);
doughnut.getData().add(
new LabeledDoughnutChartData(
execution, "FDB45C", getString("computation_time") + ": " + execution
));
doughnut.getData().add(
new LabeledDoughnutChartData(
overhead, "#F7464A", getString("overhead") + ": " + overhead
(int) overhead, "#F7464A", getString("overhead") + ": " + overhead
));
add(new DoughnutChartPanel("chart", Model.of(doughnut)));
add(new Label("title", getString("overhead_title")));
......@@ -155,15 +129,17 @@ public class InstanceStatsPage extends AbstractExtPage {
doughnut.getOptions().setResponsive(true);
doughnut.getOptions().setMaintainAspectRatio(true);
doughnut.getOptions().setTooltipTemplate("<%= label %>");
int messages = 5;
int operations = 7;
doughnut.getData().add(
new LabeledDoughnutChartData(
messages, "FDB45C", getString("sent_messages") + ": " + messages
bundle.totalMessages,
"FDB45C",
getString("sent_messages") + ": " + bundle.totalMessages
));
doughnut.getData().add(
new LabeledDoughnutChartData(
operations, "#F7464A", getString("executed_operations") + ": " + operations
bundle.totalOperations,
"#F7464A",
getString("executed_operations") + ": " + bundle.totalOperations
));
add(new DoughnutChartPanel("chart", Model.of(doughnut)));
add(new Label("title", getString("message_op_title")));
......@@ -175,4 +151,42 @@ public class InstanceStatsPage extends AbstractExtPage {
//body.add(content);
}
private class StatisticBundle {
private List<String> labels;
private List<Double> meanOverheads;
private List<Double> meanExecTimes;
private List<Integer> operations;
private List<Integer> messages;
private int totalMessages;
private int totalOperations;
private long totalExecution;
private long totalOverhead;
StatisticBundle(final List<CoordinationDelegateTO> cds) {
labels = new ArrayList<>();
meanOverheads = new ArrayList<>();
meanExecTimes = new ArrayList<>();
operations = new ArrayList<>();
messages = new ArrayList<>();
totalMessages = 0;
totalOperations = 0;
totalExecution = 0;
totalOverhead = 0;
for (CoordinationDelegateTO current: cds) {
labels.add(current.getName());
meanOverheads.add((double) current.getTotalOverhead() / current.getExecutedOperations());
meanExecTimes.add((double) current.getTotalExecutionTime() / current.getExecutedOperations());
operations.add(current.getExecutedOperations());
messages.add(current.getSentMessages());
totalMessages = totalMessages + current.getSentMessages();
totalOperations = totalOperations + current.getExecutedOperations();
totalExecution = totalExecution + current.getTotalExecutionTime();
totalOverhead = totalOverhead + current.getTotalOverhead();
}
}
}
}
......@@ -121,8 +121,7 @@ public class InstancePanel extends AbstractSearchResultPanel<
@Override
public void onClick(final AjaxRequestTarget target, final Serializable ignore) {
PageParameters param = new PageParameters();
param.add("instance", model.getObject().getKey());
param.add("name", model.getObject().getName());
param.add("instance", model.getObject().getName());
setResponsePage(InstanceStatsPage.class, param);
}
}, ActionLink.ActionType.SEARCH);
......
......@@ -17,8 +17,9 @@ package org.apache.syncope.client.console.rest;
import eu.chorevolution.idm.common.to.ChoreographyInstanceTO;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.CoordinationDelegateTO;
import java.util.List;
import org.apache.syncope.common.rest.api.service.CollectorService;
import org.apache.syncope.common.rest.api.service.ConsoleInterfaceService;
import org.springframework.stereotype.Component;
@Component
......@@ -27,11 +28,14 @@ public class ChoreographyRestClient extends BaseRestClient {
private static final long serialVersionUID = -2018208424159468912L;
public List<ChoreographyTO> choreographyList() {
return getService(CollectorService.class).choreographyList();
return getService(ConsoleInterfaceService.class).choreographyList();
}
public List<ChoreographyInstanceTO> instanceList(final long choreographyKey) {
return getService(CollectorService.class).instanceList(choreographyKey);
return getService(ConsoleInterfaceService.class).instanceList(choreographyKey);
}
public List<CoordinationDelegateTO> cdList(final String instanceName) {
return getService(ConsoleInterfaceService.class).cdList(instanceName);
}
}
......@@ -17,6 +17,7 @@ package org.apache.syncope.core.logic;
import eu.chorevolution.idm.common.to.ChoreographyInstanceTO;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.CoordinationDelegateTO;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
......@@ -79,7 +80,6 @@ public class CollectorLogic extends AbstractTransactionalLogic<AbstractBaseBean>
result.add(current);
}
}
return result;
}
......@@ -177,5 +177,68 @@ public class CollectorLogic extends AbstractTransactionalLogic<AbstractBaseBean>
return result;
}
/**
* This method returns a list of CDs for a given choreography instance
*
* @param instanceName
* @return List<CoordinationDelegateTO>
*/
public List<CoordinationDelegateTO> cdList(final String instanceName) {
List<CoordinationDelegateTO> result = new ArrayList<>();
CoordinationDelegateTO to = new CoordinationDelegateTO();
to.setKey(1);
to.setName("CD 1");
to.setChoreographyInstanceName(instanceName);
to.setExecutedOperations(2);
to.setSentMessages(10);
to.setTotalExecutionTime(40);
to.setTotalOverhead(24);
result.add(to);
to = new CoordinationDelegateTO();
to.setKey(2);
to.setName("CD 2");
to.setChoreographyInstanceName(instanceName);
to.setExecutedOperations(4);
to.setSentMessages(7);
to.setTotalExecutionTime(60);
to.setTotalOverhead(40);
result.add(to);
to = new CoordinationDelegateTO();
to.setKey(3);
to.setName("CD 3");
to.setChoreographyInstanceName(instanceName);
to.setExecutedOperations(1);
to.setSentMessages(4);
to.setTotalExecutionTime(19);
to.setTotalOverhead(5);
result.add(to);
to = new CoordinationDelegateTO();
to.setKey(4);
to.setName("CD 4");
to.setChoreographyInstanceName(instanceName);
to.setExecutedOperations(6);
to.setSentMessages(13);
to.setTotalExecutionTime(66);
to.setTotalOverhead(54);
result.add(to);
to = new CoordinationDelegateTO();
to.setKey(5);
to.setName("CD 5");
to.setChoreographyInstanceName(instanceName);
to.setExecutedOperations(1);
to.setSentMessages(2);
to.setTotalExecutionTime(20);
to.setTotalOverhead(14);
result.add(to);
return result;
}
}
......@@ -15,16 +15,13 @@
*/
package org.apache.syncope.common.rest.api.service;
import eu.chorevolution.idm.common.to.ChoreographyInstanceTO;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.syncope.common.lib.to.EndRequestTO;
import org.apache.syncope.common.lib.to.ForwardRequestTO;
import org.apache.syncope.common.lib.to.ForwardResponseTO;
......@@ -37,24 +34,6 @@ import org.apache.syncope.common.lib.to.StartRequestTO;
@Path("collector")
public interface CollectorService extends JAXRSService {
/**
* This is a temporary method.
*
* @return all defined choreographies
*/
@GET
List<ChoreographyTO> choreographyList();
/**
* This is a temporary method.
*
* @param chorId
* @return all running instances of choreographies
*/
@Path("{chor}")
@GET
List<ChoreographyInstanceTO> instanceList(@NotNull @PathParam("chor") long chorId);
/**
* This method allows to collect CD execution performance data.
*
......@@ -105,4 +84,12 @@ public interface CollectorService extends JAXRSService {
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
void setNumberCoordMessages(@NotNull NumberCoordMessageTO data);
/**
*
* @return response
*/
@Path("test")
@GET
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
Response testMethod();
}
/*
* 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.common.rest.api.service;
import eu.chorevolution.idm.common.to.ChoreographyInstanceTO;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.CoordinationDelegateTO;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
/**
* REST consoleinterface services.
*/
@Path("consoleinterface")
public interface ConsoleInterfaceService extends JAXRSService {
/**
* This is a temporary method.
*
* @return all defined choreographies
*/
@Path("choreographies")
@GET
List<ChoreographyTO> choreographyList();
/**
* This is a temporary method.
*
* @param chorId
* @return all instances of selected choreography
*/
@Path("instances/{chor}")
@GET
List<ChoreographyInstanceTO> instanceList(@PathParam("chor") long chorId);
/**
* This is a temporary method.
*
* @param instanceName
* @return all CDs of selected choreography instance
*/
@Path("cds/{instancename}")
@GET
List<CoordinationDelegateTO> cdList(@PathParam("instancename") String instanceName);
}