Skip to content

Commit

Permalink
#2 List implemented prefixes at http://localhost:4901/reporter/observ…
Browse files Browse the repository at this point in the history
…e/implementedprefix
  • Loading branch information
baardl committed Jul 29, 2015
1 parent b23f79f commit 02806a2
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 26 deletions.
33 changes: 33 additions & 0 deletions src/main/java/org/valuereporter/gui/ImplementedController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.valuereporter.gui;

import org.slf4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

import static org.slf4j.LoggerFactory.getLogger;

/**
* Created by baardl on 29.07.15.
*/
@Controller
public class ImplementedController {
private static final Logger log = getLogger(ImplementedController.class);
public static final String PREFIX = "prefix";
public static final String METHOD_NAME = "methodName";
public static final String FROM = "from";
public static final String TO = "to";

@RequestMapping("/implemented")
public ModelAndView showSlaGraph(@RequestParam(value = PREFIX, required = true) String prefix, @RequestParam(value = METHOD_NAME, required = true) String methodName) {
Map model = new HashMap<String,String>();
model.put(PREFIX, prefix);
model.put(METHOD_NAME, methodName);
log.trace("Input prefix {}, methodName {}", prefix,methodName);
return new ModelAndView("implemented", "model", model);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,11 @@ public int addAll(final List<ImplementedMethod> implementedMethods) {
}
return inserted;
}

public List<String> findImplementedPrefixes() {
String sql = "SELECT DISTINCT prefix FROM ImplementedMethod;";
List<String> implementedMethods = jdbcTemplate.queryForList(sql, String.class);
return implementedMethods;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public long addImplementedMethods(List<ImplementedMethod> implementedMethods) {
}
return size;
}

@Override
public List<String> findImplementedPrefixes() {
return implementedMethodDao.findImplementedPrefixes();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.valuereporter.implemented;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.List;

import static org.slf4j.LoggerFactory.getLogger;

/**
* Created by baardl on 29.07.15.
*/
@Component
@Path("/implementedprefix")
public class ImplementedPrefixResource {
private static final Logger log = getLogger(ImplementedPrefixResource.class);

private final QueryOperations queryOperations;
private final WriteOperations writeOperations;
private final ObjectMapper mapper;

@Autowired
public ImplementedPrefixResource(ObjectMapper mapper, QueryOperations queryOperations, WriteOperations writeOperations) {
this.mapper = mapper;
this.queryOperations = queryOperations;
this.writeOperations = writeOperations;
}

//http://localhost:4901/reporter/observe/implementedprefix
/**
* List prefixes registered in the database
*
* @return List of ImplementedPrefix'es
*/
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response findAllPrefixes() {
final List<String> implementedPrefixes;

implementedPrefixes = queryOperations.findImplementedPrefixes();

Writer strWriter = new StringWriter();
try {
mapper.writeValue(strWriter, implementedPrefixes);
} catch (IOException e) {
log.error("Could not convert {} ImplementedPrefixes to JSON.", implementedPrefixes.size(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error converting to requested format.").build();
}
return Response.ok(strWriter.toString()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
*/
public interface QueryOperations {
List<ImplementedMethod> findImplementedMethods(String prefix, String name);

List<String> findImplementedPrefixes();
}
58 changes: 34 additions & 24 deletions src/main/java/org/valuereporter/observation/ObservationDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import org.valuereporter.ValuereporterException;
import org.valuereporter.helper.StatusType;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -118,31 +121,38 @@ public ObservedMethod mapRow(ResultSet resultSet, int i) throws SQLException {
}

public void addAll(final String prefix, final List<ObservedMethod> observedMethods) {
String sql = "INSERT INTO "
+ "ObservedMethod "
+ "(prefix,methodName, startTime, endTime, duration) "
+ "VALUES " + "(?,?,?,?,?)";

jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

@Override
public void setValues(PreparedStatement ps, int i)
throws SQLException {

ObservedMethod observedMethod = observedMethods.get(i);
ps.setString(1,prefix);
ps.setString(2, observedMethod.getName());
ps.setTimestamp(3, new Timestamp(observedMethod.getStartTime()));
ps.setTimestamp(4, new Timestamp(observedMethod.getEndTime()));
ps.setLong(5, observedMethod.getDuration());

if (observedMethods != null && observedMethods.size() > 0) {
try {
String sql = "INSERT INTO "
+ "ObservedMethod "
+ "(prefix,methodName, startTime, endTime, duration) "
+ "VALUES " + "(?,?,?,?,?)";

jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

@Override
public void setValues(PreparedStatement ps, int i)
throws SQLException {

ObservedMethod observedMethod = observedMethods.get(i);
ps.setString(1, prefix);
ps.setString(2, observedMethod.getName());
ps.setTimestamp(3, new Timestamp(observedMethod.getStartTime()));
ps.setTimestamp(4, new Timestamp(observedMethod.getEndTime()));
ps.setLong(5, observedMethod.getDuration());

}

@Override
public int getBatchSize() {
return observedMethods.size();
}
});
} catch (DataAccessException dae) {
log.warn("Failed to update via batch. Batch size {}, reason {}",observedMethods.size(),dae.getMessage());
throw new ValuereporterException("Failed to update via batch. Batch size " + observedMethods.size() +". Reason: " + dae.getMessage(), dae,StatusType.data_error);
}

@Override
public int getBatchSize() {
return observedMethods.size();
}
});
}


}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/valuereporter.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ admin.connection.host=localhost
admin.connection.databasename=ValueReporter

observation.methods.detailed=false
//15 minutes intervalls
observation.interval.seconds=900
//1 minute intervalls
observation.interval.seconds=60

jetty.http.port=4901

Expand Down
21 changes: 21 additions & 0 deletions src/main/webapp/pages/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,25 @@
<title>Statistics and Value Reporting</title>
</head>
<body>
<h3>Implemented methods</h3>
<li><a href="./gui/implemented?prefixOnly">List of prefix's</a> </li>
<li><a href="./gui/implemented?prefix=dummy-load">List of methods within a prefix.</a> </li>


<h3>Observations</h3>
<li><a href="./gui/observations?prefix=dummy-load">List usage-count pr method.</a> </li>
<li><a href="./gui/slainterval?prefix=dummy-load&methodName=org.dummy.load.LoadThread.performVisibleLoad">Graph of Count/time for a method and prefix.</a> </li>

<h3>InUse - which methods are actually being used</h3>
<li><a href="./gui/inuse?prefix=dummy-load">Show methods implemented vs. in use.</a> </li>


<h3>Rest interface</h3>
<li><a href="./observe/implementedprefix">List implemented prefixes</a> </li>
<li><a href="./observe/implementedmethods/dummy-load">List implemented methods for prefix</a> </li>"

________
<h3>Old stuff...</h3>
<li><a href="./observe/observedmethods/{prefix}/{name}">template listing of operations (./observe/observedmethods/{prefix}/{name})</a></li>
<b>Ping and Hello test</b>
<li><a href="./observe/observedmethods/initial/com.valuereporter.test">Initial Data</a> </li>
Expand All @@ -22,5 +40,8 @@
<li>SLA Summary: <a href="./gui/slainterval?prefix=template-prefix&methodName=org.valuereporter.Welcome.ping">SLA reporting on Welcome.ping</a></li>
<li>SLA rest: <a href="./observe/sla/observations/template-prefix?filter=org.valuereporter.Welcome.hello">http://localhost:4901/reporter/observe/sla/observations/{prefix}?filter={methodName}</a></li>

<h3>Load Generator</h3>
<li>SLA Interval/Summary: <a href="./gui/slainterval?prefix=dummy-load&methodName=org.dummy.load.LoadThread.performVisibleLoad">Graph of Count/time</a> </li>

</body>
</html>

0 comments on commit 02806a2

Please sign in to comment.