Commit 690c2e12 authored by Gianluca Filippone's avatar Gianluca Filippone
Browse files

Code refactoring

parent 3471dafc
......@@ -65,7 +65,7 @@ public class InstanceStatsPage extends BaseExtPage {
WebMarkupContainer content = new WebMarkupContainer("content");
content.setOutputMarkupId(true);
content.add(new Label("duration", getString("duration") + " " + (bundle.lastEnd - bundle.firstStart) + " ms"));
content.add(new Label("duration", getString("duration") + " " + (0) + " ms"));
RepeatingView chartList = new RepeatingView("stats");
//Total overhead and total execution time per CD
......@@ -213,10 +213,6 @@ public class InstanceStatsPage extends BaseExtPage {
private long totalSleep;
private long firstStart;
private long lastEnd;
InstanceStatisticsBundle(final List<CoordinationDelegateTO> cds) {
labels = new ArrayList<>();
overheads = new ArrayList<>();
......@@ -229,8 +225,6 @@ public class InstanceStatsPage extends BaseExtPage {
totalServiceExecution = 0;
totalOverhead = 0;
totalSleep = 0;
firstStart = 0;
lastEnd = 0;
for (CoordinationDelegateTO current : cds) {
labels.add(current.getName());
......@@ -244,14 +238,6 @@ public class InstanceStatsPage extends BaseExtPage {
totalServiceExecution = totalServiceExecution + current.getTotalServiceExecutionTime();
totalOverhead = totalOverhead + current.getTotalOverhead();
totalSleep = totalSleep + current.getTotalWaitTime();
if (firstStart > current.getStartTime() || firstStart == 0) {
firstStart = current.getStartTime();
}
if (lastEnd < current.getEndTime()) {
lastEnd = current.getEndTime();
}
}
}
}
......
......@@ -35,6 +35,8 @@ public class ChoreographyInstanceTO extends AbstractBaseBean {
private String choreographyName;
private Long executionTime;
public long getId() {
return id;
}
......@@ -75,4 +77,12 @@ public class ChoreographyInstanceTO extends AbstractBaseBean {
this.choreographyName = choreographyName;
}
public Long getExecutionTime() {
return executionTime;
}
public void setExecutionTime(final Long executionTime) {
this.executionTime = executionTime;
}
}
......@@ -92,22 +92,6 @@ public class CoordinationDelegateTO extends AbstractBaseBean {
this.totalWaitTime = totalWaitTime;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(final long startTime) {
this.startTime = startTime;
}
public long getEndTime() {
return endTime;
}
public void setEndTime(final long endTime) {
this.endTime = endTime;
}
public Long getInstanceId() {
return instanceId;
}
......
......@@ -31,10 +31,6 @@ public class OperationDataTO extends AbstractBaseBean {
private int messageNumber;
private long startTime;
private long endTime;
public String getName() {
return name;
}
......@@ -75,20 +71,4 @@ public class OperationDataTO extends AbstractBaseBean {
this.messageNumber = messageNumber;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(final long startTime) {
this.startTime = startTime;
}
public long getEndTime() {
return endTime;
}
public void setEndTime(final long endTime) {
this.endTime = endTime;
}
}
......@@ -23,8 +23,12 @@ public enum EventType {
REPLY_RESPONSE,
RECEIVING_RESPONSE,
FORWARDING_RESPONSE,
SEND_NOTIFY,
SEND_UPDATE,
WAIT_BEFORE,
WAIT_AFTER
SEND_UPDATE_BEFORE,
SEND_UPDATE_AFTER,
SEND_NOTIFY_BEFORE,
SEND_NOTIFY_AFTER,
WAIT_UPDATE_STATE_BEFORE,
WAIT_UPDATE_STATE_AFTER,
WAIT_ALL_NOTIFY_BEFORE,
WAIT_ALL_NOTIFY_AFTER
}
......@@ -53,20 +53,23 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
throw new UnresolvedReferenceException();
}
/**
* This method returns a list of all choreographies
*
* @return ChoreographyTO list
*/
public List<ChoreographyTO> choreographyList() {
List<ChoreographyTO> result = new LinkedList<>();
ChoreographyTO to;
List<Choreography> choreographies = choreographyDAO.findAll();
for (Choreography current : choreographies) {
to = new ChoreographyTO();
to.setId(current.getKey());
to.setName(current.getName());
to.setDescription(current.getDescription());
ChoreographyTO choreographyTO = new ChoreographyTO();
choreographyTO.setId(current.getKey());
choreographyTO.setName(current.getName());
choreographyTO.setDescription(current.getDescription());
result.add(to);
result.add(choreographyTO);
}
return result;
......@@ -81,19 +84,18 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
public List<ChoreographyInstanceTO> instanceList(final Long choreographyId) {
List<ChoreographyInstanceTO> result = new LinkedList<>();
ChoreographyInstanceTO to;
List<ChoreographyInstance> instances = choreographyInstanceDAO.findByChoreographyId(choreographyId);
for (ChoreographyInstance current : instances) {
to = new ChoreographyInstanceTO();
to.setId(current.getKey());
to.setChoreographyInstanceId(current.getChoreographyInstanceId());
to.setInstanceDescription(current.getDescription());
ChoreographyInstanceTO choreographyInstanceTO = new ChoreographyInstanceTO();
choreographyInstanceTO.setId(current.getKey()); // choreography instance primary key
choreographyInstanceTO.setChoreographyInstanceId(current.getChoreographyInstanceId());
choreographyInstanceTO.setInstanceDescription(current.getDescription());
choreographyInstanceTO.setExecutionTime(getChoreographyInstanceExecutionTime(current.getId()));
to.setChoreographyId(choreographyId);
choreographyInstanceTO.setChoreographyId(choreographyId);
result.add(to);
result.add(choreographyInstanceTO);
}
return result;
......@@ -106,52 +108,43 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
* @return CoordinationDelegateTO list
*/
public List<CoordinationDelegateTO> cdList(final Long choreographyInstancePK) {
List<CoordinationDelegateTO> coordinationDelegates = new LinkedList<>();
List<CoordinationDelegateTO> coordinationDelegateTOs = new LinkedList<>();
CoordinationDelegateTO to;
List<String> nameCDs = getCdNames(choreographyInstancePK);
List<String> availableCds = getCdNames(choreographyInstancePK);
for (String cdName : availableCds) {
to = new CoordinationDelegateTO();
to.setName(cdName);
to.setInstanceId(choreographyInstancePK);
for (String cdName : nameCDs) {
CoordinationDelegateTO coordinationDelegateTO = new CoordinationDelegateTO();
coordinationDelegateTO.setName(cdName);
coordinationDelegateTO.setInstanceId(choreographyInstancePK);
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;
int cdExchangedMessages = 0;
long overhead = 0;
long serviceExecutionTime = 0;
long waitTime = 0;
for (OperationDataTO operation : operations) {
messageNumber = messageNumber + operation.getMessageNumber();
// Update number of coordination messages sent by current CD
cdExchangedMessages = cdExchangedMessages + operation.getMessageNumber();
// Update overhead of current CD
overhead = overhead + operation.getOverhead();
// Update execution time of services involved in current CD tasks
serviceExecutionTime = serviceExecutionTime + operation.getServiceExecTime();
// Update wait time of current CD
waitTime = waitTime + operation.getWaitTime();
if (firstStart > operation.getStartTime() || firstStart == 0) {
firstStart = operation.getStartTime();
}
if (lastEnd < operation.getEndTime()) {
lastEnd = operation.getEndTime();
}
++opNumber;
}
to.setExecutedOperations(opNumber);
to.setSentMessages(messageNumber);
to.setTotalOverhead(overhead);
to.setTotalServiceExecutionTime(serviceExecutionTime);
to.setTotalWaitTime(waitTime);
to.setStartTime(firstStart);
to.setEndTime(lastEnd);
coordinationDelegates.add(to);
coordinationDelegateTO.setExecutedOperations(operations.size());
coordinationDelegateTO.setSentMessages(cdExchangedMessages);
coordinationDelegateTO.setTotalOverhead(overhead);
coordinationDelegateTO.setTotalServiceExecutionTime(serviceExecutionTime);
coordinationDelegateTO.setTotalWaitTime(waitTime);
coordinationDelegateTOs.add(coordinationDelegateTO);
}
return coordinationDelegates;
return coordinationDelegateTOs;
}
public List<OperationDataTO> operationList(
......@@ -165,16 +158,18 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
}
//TODO update method
private OperationDataTO getOperation(
final Long choreographyInstancePK,
final String opName,
final String operationName,
final ArtifactType artifactType,
final String artifactName) {
OperationDataTO operation = new OperationDataTO();
operation.setName(opName);
operation.setName(operationName);
List<Event> loggedEvents = eventDAO.findByOperation(choreographyInstancePK, opName, artifactType, artifactName);
List<Event> events = eventDAO.findByOperation(
choreographyInstancePK, operationName, artifactType, artifactName);
long receiveRequest = 0;
long forwardRequest = 0;
......@@ -185,13 +180,12 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
long waitBefore = 0;
long waitTime = 0;
for (Event currentEvent : loggedEvents) {
for (Event currentEvent : events) {
EventType eventType = currentEvent.getEventType();
long timestamp = currentEvent.getEventTimestamp();
switch (eventType) {
case RECEIVING_REQUEST :
operation.setStartTime(timestamp);
receiveRequest = timestamp;
break;
case FORWARDING_REQUEST:
......@@ -201,10 +195,9 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
receiveResponse = timestamp;
break;
case FORWARDING_RESPONSE:
operation.setEndTime(timestamp);
forwardResponse = timestamp;
break;
case SEND_NOTIFY:
/*case SEND_NOTIFY:
++messageNumber;
break;
case SEND_UPDATE:
......@@ -215,7 +208,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
break;
case WAIT_AFTER:
waitAfter = timestamp;
break;
break;*/
default:
}
}
......@@ -255,4 +248,61 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
private List<String> getCdNames(final Long choreographyInstancePK) {
return eventDAO.findArtifactsByType(choreographyInstancePK, ArtifactType.CD);
}
public ChoreographyTO getChoreography(final Long choreographyId) {
Choreography choreography = choreographyDAO.findById(choreographyId);
if (choreography == null) {
return null;
}
ChoreographyTO choreographyTO = new ChoreographyTO();
choreographyTO.setName(choreography.getName());
choreographyTO.setDescription(choreography.getDescription());
choreographyTO.setId(choreography.getId());
choreographyTO.setDiagram(choreography.getDiagram());
choreographyTO.setImage(choreography.getImage());
choreographyTO.setImageType(choreography.getImageType());
choreographyTO.setMessageTypes(choreography.getMessageTypes());
return choreographyTO;
}
public ChoreographyInstanceTO getChoreographyInstance(final Long choreographyInstancePK) {
ChoreographyInstance choreographyInstance = choreographyInstanceDAO.findById(choreographyInstancePK);
if (choreographyInstance == null) {
return null;
}
ChoreographyInstanceTO choreographyInstanceTO = new ChoreographyInstanceTO();
choreographyInstanceTO.setId(choreographyInstance.getId());
choreographyInstanceTO.setChoreographyInstanceId(choreographyInstance.getChoreographyInstanceId());
choreographyInstanceTO.setInstanceDescription(choreographyInstance.getDescription());
choreographyInstanceTO.setChoreographyId(choreographyInstance.getChoreography().getId());
choreographyInstanceTO.setChoreographyName(choreographyInstance.getChoreography().getName());
choreographyInstanceTO.setExecutionTime(getChoreographyInstanceExecutionTime(choreographyInstancePK));
return choreographyInstanceTO;
}
private Long getChoreographyInstanceExecutionTime(final Long choreographyInstancePK) {
List<Event> events = eventDAO.findByChoreographyInstancePK(choreographyInstancePK);
long start = 0L;
long end = 0L;
for (Event event : events) {
if (start > event.getEventTimestamp() || start == 0) {
start = event.getEventTimestamp();
}
if (end < event.getEventTimestamp()) {
end = event.getEventTimestamp();
}
}
return end - start;
}
}
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