Skip to content

Commit

Permalink
1) Improvements on Proven responses were added to error conditions 2) A
Browse files Browse the repository at this point in the history
new debug REST service was added to provide feedback to the application
developer.  This supports queries now but could be expanded to handle
viewing construction of write statements.
  • Loading branch information
ericstephan committed Mar 26, 2020
1 parent 4ccc151 commit 6496ad4
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void onMessage(Message message) {

ProvenMessageResponse processMessage(ProvenMessage pm) {
ProvenMessageResponse pmr = new ProvenMessageResponse();
pmr = cs.influxWriteMeasurements(pm.getMeasurements());
//EGS 3/23/2020 pmr = cs.influxWriteMeasurements(pm.getMeasurements());

return pmr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,86 @@ public ProvenMessageResponse addProvenMessage(ProvenMessage pm) {
pmr = cs.influxQuery(pm);
}

// // Explicit
// if (stream.equals(MessageContent.Explicit.getStream())) {
// pmr = cs.influxWriteMeasurements(pm.getMeasurements());
// }

// Invalid message content
if (null == pmr) {
pmr = new ProvenMessageResponse();
pmr.setStatus(Status.BAD_REQUEST);
pmr.setReason("Invalid or missing message content type.");
pmr.setCode(Status.BAD_REQUEST.getStatusCode());
pmr.setResponse("{ \"ERROR\": \"Bad request made to time-series database.\" }");

cs.rollback();

} else {

cs.commit();
}

} catch (Exception e) {
cs.rollback();
pmr = new ProvenMessageResponse();
pmr.setStatus(Status.INTERNAL_SERVER_ERROR);
pmr.setReason(e.getMessage());
pmr.setCode(Status.INTERNAL_SERVER_ERROR.getStatusCode());
pmr.setResponse("{ \"ERROR\": \"Bad request made to time-series database.\" }");
e.printStackTrace();
}

return pmr;
}

@POST
@Path(R_PROVEN_MESSAGE_DEBUG)
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
// @formatter:off
@ApiOperation(value = "Debugs a translation of Proven message into Influx", notes = "Provided provenance mesage must be valid \"ProvenMessage\" object")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successful operation.", response = ProvenMessageResponse.class),
@ApiResponse(code = 201, message = "Created.", response = ProvenMessageResponse.class),
@ApiResponse(code = 403, message = "Invalid or missing message content", response = ProvenMessageResponse.class),
@ApiResponse(code = 500, message = "Internal server error.") })
// @formatter:on

public ProvenMessageResponse debugInfluxStatement(ProvenMessage pm) {

ProvenMessageResponse pmr = null;

try {
cs.begin();

// Add proven message to stream
// TODO Implement MapStore
String key = pm.getMessageKey();
pm.getMessageProperties().setDisclosure(new Date().getTime());
String stream = pm.getMessageContent().getStream();
if (null != hzMemberInstance) {
log.warn("HZ cluster instance could not be found");
IMap<String, ProvenMessage> pms = hzMemberInstance.getMap(stream);
pms.set(key, pm);
}

// Add statements to T3 store
Resource[] contexts = {};
Collection<Statement> statements = ConceptUtil.getSesameStatements(pm.getStatements());
cs.addStatements(statements, contexts);

// Query or Add measurements to TS store

// Query
if (stream.equals(MessageContent.Query.getStream())) {

pmr = cs.influxQuery(pm,true, true);
}

// Explicit
if (stream.equals(MessageContent.Explicit.getStream())) {
pmr = cs.influxWriteMeasurements(pm.getMeasurements());
// Do nothing.
}

// Invalid message content
Expand Down Expand Up @@ -947,8 +1024,8 @@ public ProvenMessageResponse addProvenMessage(ProvenMessage pm) {
}

return pmr;
}

}
@POST
@Path(R_PROVEN_MESSAGE_CSV)
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -990,7 +1067,7 @@ public ProvenMessageResponse addProvenMessageCsv(ProvenMessage pm) {
// Query
if (stream.equals(MessageContent.Query.getStream())) {

pmr = cs.influxQuery(pm,true);
pmr = cs.influxQuery(pm,true, false);
}

// Explicit
Expand Down Expand Up @@ -1024,9 +1101,7 @@ public ProvenMessageResponse addProvenMessageCsv(ProvenMessage pm) {
}

return pmr;
}


}
@POST
@Path("addBulkTimeSeries")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class ResourceConsts {

public static final String R_PROVEN_MESSAGE = "provenMessage";
public static final String R_PROVEN_MESSAGE_CSV = "provenMessage/csv";
public static final String R_PROVEN_MESSAGE_DEBUG = "provenMessage/debug";
public static final String R_PROVEN_MESSAGES = "messages";


Expand Down
Loading

0 comments on commit 6496ad4

Please sign in to comment.