Commit eaacddbb authored by Gianluca Filippone's avatar Gianluca Filippone
Browse files

Adapted monitor system to new requirements

parent f096a8d7
......@@ -19,9 +19,9 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.syncope.common.lib.AbstractBaseBean;
@XmlRootElement(name = "numberCoordMessage")
@XmlRootElement(name = "coordMessage")
@XmlType
public class NumberCoordMessageTO extends AbstractBaseBean {
public class CoordMessageTO extends AbstractBaseBean {
private static final long serialVersionUID = 6203745231037592740L;
......@@ -32,46 +32,67 @@ public class NumberCoordMessageTO extends AbstractBaseBean {
private String cdName;
private String operationName;
private String sourceState;
private String targetState;
private int messageNumber;
private long timestamp;
public String getChoreographyName() {
return choreographyName;
}
public void setChoreographyName(final String choreographyName) {
this.choreographyName = choreographyName;
}
public String getInstanceName() {
return instanceName;
}
public void setInstanceName(final String instanceName) {
this.instanceName = instanceName;
}
public String getCdName() {
return cdName;
}
public void setCdName(final String cdName) {
this.cdName = cdName;
}
public String getOperationName() {
return operationName;
}
public void setOperationName(final String operationName) {
this.operationName = operationName;
}
public void setMessageNumber(final int messageNumber) {
this.messageNumber = messageNumber;
public String getSourceState() {
return sourceState;
}
public String getChoreographyName() {
return this.choreographyName;
public void setSourceState(final String sourceState) {
this.sourceState = sourceState;
}
public String getInstanceName() {
return this.instanceName;
public String getTargetState() {
return targetState;
}
public String getCdName() {
return this.cdName;
public void setTargetState(final String targetState) {
this.targetState = targetState;
}
public String getOperationName() {
return this.operationName;
public long getTimestamp() {
return timestamp;
}
public int getMessageNumber() {
return this.messageNumber;
public void setTimestamp(final long timestamp) {
this.timestamp = timestamp;
}
}
......@@ -25,28 +25,28 @@ import org.apache.syncope.common.lib.AbstractBaseBean;
import eu.choreovolution.idm.common.to.EndRequestTO;
import eu.choreovolution.idm.common.to.ForwardRequestTO;
import eu.choreovolution.idm.common.to.ForwardResponseTO;
import eu.choreovolution.idm.common.to.NumberCoordMessageTO;
import eu.choreovolution.idm.common.to.CoordMessageTO;
import eu.choreovolution.idm.common.to.StartRequestTO;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.syncope.core.persistence.api.dao.EndRequestDAO;
import org.apache.syncope.core.persistence.api.dao.ForwardRequestDAO;
import org.apache.syncope.core.persistence.api.dao.ForwardResponseDAO;
import org.apache.syncope.core.persistence.api.dao.NumberCoordMessageDAO;
import org.apache.syncope.core.persistence.api.dao.StartRequestDAO;
import org.apache.syncope.core.persistence.api.entity.EndRequest;
import org.apache.syncope.core.persistence.api.entity.ForwardRequest;
import org.apache.syncope.core.persistence.api.entity.ForwardResponse;
import org.apache.syncope.core.persistence.api.entity.NumberCoordMessage;
import org.apache.syncope.core.persistence.api.entity.StartRequest;
import org.apache.syncope.core.persistence.api.entity.TimeData;
import org.apache.syncope.core.persistence.jpa.entity.JPAEndRequest;
import org.apache.syncope.core.persistence.jpa.entity.JPAForwardRequest;
import org.apache.syncope.core.persistence.jpa.entity.JPAForwardResponse;
import org.apache.syncope.core.persistence.jpa.entity.JPANumberCoordMessage;
import org.apache.syncope.core.persistence.jpa.entity.JPACoordMessage;
import org.apache.syncope.core.persistence.jpa.entity.JPAStartRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.apache.syncope.core.persistence.api.dao.CoordMessageDAO;
import org.apache.syncope.core.persistence.api.entity.CoordMessage;
@Component
public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
......@@ -64,7 +64,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
private EndRequestDAO endRequestDAO;
@Autowired
private NumberCoordMessageDAO numberCoordMessageDAO;
private CoordMessageDAO coordMessageDAO;
@Override
protected AbstractBaseBean resolveReference(final Method method, final Object... args)
......@@ -92,31 +92,6 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
result.add(to);
}
/*
to = new ChoreographyTO();
//to.setKey(1);
to.setDescription("Description of choreography 1");
to.setName("Choreography 1");
result.add(to);
to = new ChoreographyTO();
//to.setKey(2);
to.setDescription("Description of choreography 2");
to.setName("Choreography 2");
result.add(to);
to = new ChoreographyTO();
//to.setKey(3);
to.setDescription("Description of choreography 3");
to.setName("Choreography 3");
result.add(to);
to = new ChoreographyTO();
//to.setKey(4);
to.setDescription("Description of choreography 4");
to.setName("Choreography 4");
result.add(to);*/
return result;
}
......@@ -148,28 +123,6 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
result.add(to);
}
/*
to = new ChoreographyInstanceTO();
to.setChoreographyName(choreographyName);
to.setName("Instance 1");
to.setDescription("No description available");
result.add(to);
to = new ChoreographyInstanceTO();
to.setName("Instance 2");
to.setDescription("No description available");
result.add(to);
to = new ChoreographyInstanceTO();
to.setName("Instance 3");
to.setDescription("No description available");
result.add(to);
to = new ChoreographyInstanceTO();
to.setName("Instance 4");
to.setDescription("No description available");
result.add(to);*/
return result;
}
......@@ -227,10 +180,10 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
forwardRes = forwardResponseDAO.find(cdName, currentOp, instanceName, choreographyName);
endReq = endRequestDAO.find(cdName, currentOp, instanceName, choreographyName);
NumberCoordMessage numMessages = numberCoordMessageDAO.find(
cdName, currentOp, instanceName, choreographyName);
messageNumber = messageNumber + coordMessageDAO.findIntervalMessages(
cdName, currentOp, instanceName, choreographyName,
startReq.getRecordTime(), endReq.getRecordTime()).size();
messageNumber = messageNumber + numMessages.getNumMessages();
overhead = overhead
+ (forwardReq.getRecordTime() - startReq.getRecordTime())
+ (endReq.getRecordTime() - forwardRes.getRecordTime());
......@@ -244,61 +197,6 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
to.setTotalExecutionTime(executionTime);
coordinationDelegates.add(to);
}
/*
to = new CoordinationDelegateTO();
//to.setKey(1);
to.setName("CD 1");
to.setChoreographyInstanceName(instanceName);
to.setChoreographyName(choreographyName);
to.setExecutedOperations(2);
to.setSentMessages(10);
to.setTotalExecutionTime(40);
to.setTotalOverhead(24);
coordinationDelegates.add(to);
to = new CoordinationDelegateTO();
//to.setKey(2);
to.setName("CD 2");
to.setChoreographyInstanceName(instanceName);
to.setChoreographyName(choreographyName);
to.setExecutedOperations(4);
to.setSentMessages(7);
to.setTotalExecutionTime(60);
to.setTotalOverhead(40);
coordinationDelegates.add(to);
to = new CoordinationDelegateTO();
//to.setKey(3);
to.setName("CD 3");
to.setChoreographyInstanceName(instanceName);
to.setChoreographyName(choreographyName);
to.setExecutedOperations(1);
to.setSentMessages(4);
to.setTotalExecutionTime(19);
to.setTotalOverhead(5);
coordinationDelegates.add(to);
to = new CoordinationDelegateTO();
//to.setKey(4);
to.setName("CD 4");
to.setChoreographyInstanceName(instanceName);
to.setChoreographyName(choreographyName);
to.setExecutedOperations(6);
to.setSentMessages(13);
to.setTotalExecutionTime(66);
to.setTotalOverhead(54);
coordinationDelegates.add(to);
to = new CoordinationDelegateTO();
//to.setKey(5);
to.setName("CD 5");
to.setChoreographyInstanceName(instanceName);
to.setChoreographyName(choreographyName);
to.setExecutedOperations(1);
to.setSentMessages(2);
to.setTotalExecutionTime(20);
to.setTotalOverhead(14);
coordinationDelegates.add(to);*/
return coordinationDelegates;
}
......@@ -365,30 +263,17 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
}
}
public void saveMessageData(final NumberCoordMessageTO data) {
NumberCoordMessage requestEntity = new JPANumberCoordMessage();
public void saveMessageData(final CoordMessageTO data) {
CoordMessage requestEntity = new JPACoordMessage();
requestEntity.setCdName(data.getCdName());
requestEntity.setChoreographyName(data.getChoreographyName());
requestEntity.setInstanceName(data.getInstanceName());
requestEntity.setOperationName(data.getOperationName());
requestEntity.setNumMessages(data.getMessageNumber());
requestEntity.setSourceState(data.getSourceState());
requestEntity.setTargetState(data.getTargetState());
requestEntity.setRecordTime(data.getTimestamp());
numberCoordMessageDAO.save(requestEntity);
coordMessageDAO.save(requestEntity);
}
/* public StartRequest testMethod(final StartRequestTO data) {
// StartRequest request = new JPAStartRequest();
// request.setCdName(data.getCdName());
// request.setChoreographyName(data.getChoreographyName());
// request.setInstanceName(data.getInstanceName());
// request.setOperationName(data.toString());
// request.setRecordTime(data.getTimestamp());
// StartRequest ciao = startRequestDAO.find(
// data.getCdName(), data.getOperationName(), "Saved", data.getChoreographyName());
List<StartRequest> list = startRequestDAO.findAll();
StartRequest ciao = list.get(0);
//data.setInstanceName("Saved");
return ciao;
}*/
}
......@@ -16,15 +16,17 @@
package org.apache.syncope.core.persistence.api.dao;
import java.util.List;
import org.apache.syncope.core.persistence.api.entity.NumberCoordMessage;
import org.apache.syncope.core.persistence.api.entity.CoordMessage;
public interface NumberCoordMessageDAO extends DAO<NumberCoordMessage, Long> {
public interface CoordMessageDAO extends DAO<CoordMessage, Long> {
NumberCoordMessage find(String cdName, String operationName, String instanceName, String choreographyName);
List<CoordMessage> findIntervalMessages(
String cdName, String operationName, String instanceName, String choreographyname,
long startTime, long endTime);
List<CoordMessage> findAll();
List<NumberCoordMessage> findAll();
void save(NumberCoordMessage messages);
void save(CoordMessage messages);
void delete(String key);
}
......@@ -25,5 +25,5 @@ public interface ChoreographyEntityFactory {
EndRequest newEndRequest();
NumberCoordMessage newNumberCoordMessage();
CoordMessage newNumberCoordMessage();
}
......@@ -15,7 +15,7 @@
*/
package org.apache.syncope.core.persistence.api.entity;
public interface NumberCoordMessage extends Entity<Long> {
public interface CoordMessage extends Entity<Long> {
void setChoreographyName(String choreographyName);
......@@ -33,7 +33,15 @@ public interface NumberCoordMessage extends Entity<Long> {
String getOperationName();
void setNumMessages(int messages);
void setSourceState(String sourceState);
int getNumMessages();
String getSourceState();
void setTargetState(String targetState);
String getTargetState();
void setRecordTime(long time);
long getRecordTime();
}
......@@ -17,46 +17,49 @@ package org.apache.syncope.core.persistence.jpa.dao;
import java.util.List;
import javax.persistence.TypedQuery;
import org.apache.syncope.core.persistence.api.dao.NumberCoordMessageDAO;
import org.apache.syncope.core.persistence.api.entity.NumberCoordMessage;
import org.apache.syncope.core.persistence.jpa.entity.JPANumberCoordMessage;
import org.apache.syncope.core.persistence.jpa.entity.JPACoordMessage;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.apache.syncope.core.persistence.api.entity.CoordMessage;
import org.apache.syncope.core.persistence.api.dao.CoordMessageDAO;
@Repository
public class JPANumberCoordMessageDAO extends AbstractDAO<NumberCoordMessage, Long>
implements NumberCoordMessageDAO {
public class JPACoordMessageDAO extends AbstractDAO<CoordMessage, Long>
implements CoordMessageDAO {
@Transactional(readOnly = true)
@Override
public NumberCoordMessage find(final String cdName, final String operationName, final String instanceName,
final String choreographyName) {
public List<CoordMessage> findIntervalMessages(
final String cdName, final String operationName, final String instanceName,
final String choreographyName, final long startTime, final long endTime) {
TypedQuery<NumberCoordMessage> query = entityManager().createQuery(
"SELECT e FROM " + JPANumberCoordMessage.class.getSimpleName()
TypedQuery<CoordMessage> query = entityManager().createQuery(
"SELECT e FROM " + JPACoordMessage.class.getSimpleName()
+ " e WHERE e.cdName = :cdName AND e.operationName = :operationName"
+ " AND e.instanceName = :instanceName AND e.choreographyName = :choreographyName",
NumberCoordMessage.class);
+ " AND e.instanceName = :instanceName AND e.choreographyName = :choreographyName"
+ " AND e.recordTime > :startTime AND e.recordTime < :endTime", CoordMessage.class);
query.setParameter("cdName", cdName);
query.setParameter("operationName", operationName);
query.setParameter("instanceName", instanceName);
query.setParameter("choreographyName", choreographyName);
return query.getSingleResult();
query.setParameter("startTime", startTime);
query.setParameter("endTime", endTime);
return query.getResultList();
}
@Transactional(readOnly = true)
@Override
public List<NumberCoordMessage> findAll() {
TypedQuery<NumberCoordMessage> query = entityManager().createQuery(
"SELECT e FROM " + JPANumberCoordMessage.class.getSimpleName() + " e ", NumberCoordMessage.class);
public List<CoordMessage> findAll() {
TypedQuery<CoordMessage> query = entityManager().createQuery(
"SELECT e FROM " + JPACoordMessage.class.getSimpleName() + " e ", CoordMessage.class);
return query.getResultList();
}
@Transactional
@Override
public void save(final NumberCoordMessage messages) {
public void save(final CoordMessage messages) {
entityManager().persist(messages);
}
......@@ -64,4 +67,5 @@ public class JPANumberCoordMessageDAO extends AbstractDAO<NumberCoordMessage, Lo
@Override
public void delete(final String key) {
}
}
......@@ -19,9 +19,9 @@ import org.apache.syncope.core.persistence.api.entity.ChoreographyEntityFactory;
import org.apache.syncope.core.persistence.api.entity.EndRequest;
import org.apache.syncope.core.persistence.api.entity.ForwardRequest;
import org.apache.syncope.core.persistence.api.entity.ForwardResponse;
import org.apache.syncope.core.persistence.api.entity.NumberCoordMessage;
import org.apache.syncope.core.persistence.api.entity.StartRequest;
import org.springframework.stereotype.Component;
import org.apache.syncope.core.persistence.api.entity.CoordMessage;
@Component
public class JPAChoreographyEntityFactory implements ChoreographyEntityFactory {
......@@ -47,8 +47,8 @@ public class JPAChoreographyEntityFactory implements ChoreographyEntityFactory {
}
@Override
public NumberCoordMessage newNumberCoordMessage() {
return new JPANumberCoordMessage();
public CoordMessage newNumberCoordMessage() {
return new JPACoordMessage();
}
......
......@@ -20,12 +20,12 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.apache.syncope.core.persistence.api.entity.NumberCoordMessage;
import org.apache.syncope.core.persistence.api.entity.CoordMessage;
@Entity
@Table(name = JPANumberCoordMessage.TABLE, uniqueConstraints = @UniqueConstraint(
columnNames = {"instanceName", "operationName", "cdName", "choreographyName"}))
public class JPANumberCoordMessage extends AbstractEntity<Long> implements NumberCoordMessage {
@Table(name = JPACoordMessage.TABLE, uniqueConstraints = @UniqueConstraint(
columnNames = {"instanceName", "operationName", "cdName", "choreographyName", "recordTime"}))
public class JPACoordMessage extends AbstractEntity<Long> implements CoordMessage {
private static final long serialVersionUID = 1047456207239820219L;
......@@ -42,7 +42,11 @@ public class JPANumberCoordMessage extends AbstractEntity<Long> implements Numbe
private String choreographyName;
private int numMessages;
private String sourceState;
private String targetState;
private long recordTime;
@Override
public Long getKey() {
......@@ -90,13 +94,32 @@ public class JPANumberCoordMessage extends AbstractEntity<Long> implements Numbe
}
@Override
public void setNumMessages(final int messages) {
this.numMessages = messages;
public void setSourceState(final String sourceState) {
}
@Override
public String getSourceState() {
return sourceState;
}
@Override
public void setTargetState(final String targetState) {
this.targetState = targetState;
}
@Override
public String getTargetState() {
return targetState;
}
@Override
public void setRecordTime(final long recordTime) {
this.recordTime = recordTime;
}
@Override
public int getNumMessages() {
return numMessages;
public long getRecordTime() {
return recordTime;
}
}
......@@ -19,13 +19,11 @@ import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
//import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
//import javax.ws.rs.core.Response;
import eu.choreovolution.idm.common.to.EndRequestTO;
import eu.choreovolution.idm.common.to.ForwardRequestTO;
import eu.choreovolution.idm.common.to.ForwardResponseTO;
import eu.choreovolution.idm.common.to.NumberCoordMessageTO;
import eu.choreovolution.idm.common.to.CoordMessageTO;
import eu.choreovolution.idm.common.to.StartRequestTO;
/**
......@@ -79,23 +77,9 @@ public interface CollectorService extends JAXRSService {
*
* @param data
*/
@Path("numbercoordmessagesrequest")
@Path("coordmessagesrequest")
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
void setNumberCoordMessages(@NotNull NumberCoordMessageTO data);
void updateNumberCoordMessages(@NotNull CoordMessageTO data);
/**
*
* @param request
* @return response
*/
/* @Path("test")
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON})
Response testMethod(@NotNull StartRequestTO request);*/
// localhost:9080/syncope/rest/collector/test/?