Skip to content

Commit

Permalink
Merge pull request #1642 from GRIDAPPSD/releases/2022.04.0
Browse files Browse the repository at this point in the history
Release of version 2022.04.0
  • Loading branch information
tonya1 authored Apr 21, 2022
2 parents bacf337 + 397baa2 commit 646f563
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 52 deletions.
10 changes: 7 additions & 3 deletions gov.pnnl.goss.gridappsd/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
cimhub.lib;version=0.2.4,\
httpclient,\
com.bigdata.rdf,\
proven-client;version=0.2.4,\
proven-message;version=0.5,\
com.nimbusds.nimbus-jose-jwt-dependencies
org.glassfish.jersey.core.jersey-client;version=2.26,\
org.glassfish.jersey.core.jersey-common;version=2.26,\
org.glassfish.jersey.media.jersey-media-json-jackson;version=2.26.0,\
proven-client;version=0.2.5,\
proven-message;version=0.5,\
com.nimbusds.nimbus-jose-jwt-dependencies,\


-plugin org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin;log=debug

Expand Down
6 changes: 6 additions & 0 deletions gov.pnnl.goss.gridappsd/conf/pnnl.goss.gridappsd.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ proven.write.path = http://proven:8080/hybrid/rest/v1/repository/addBulkTimeSeri
# docker-compose default network.
proven.query.path = http://proven:8080/hybrid/rest/v1/repository/provenMessage

# Uses docker composed proven host here. Note this is not the
# external address, but from inside one of the containers on the
# docker-compose default network.
proven.advanced_query.path = http://proven:8080/hybrid/rest/v1/repository/getAdvancedTsQuery


# Power grid model MRID for deployed Field Bus
field.model.mrid = _49AD8E07-3BF9-A4E2-CB8F-C3722F837B62
8 changes: 4 additions & 4 deletions gov.pnnl.goss.gridappsd/run.bnd.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@
org.eclipse.jetty.aggregate.jetty-all-server;version=7.6.9,\
com.bigdata.rdf,\
proven-message;version=0.5,\
proven-client;version=0.2.4,\
proven-client;version=0.2.5,\
javax.ws.rs-api,\
org.apache.commons.codec,\
shacl,\
com.hazelcast,\
org.glassfish.jersey.core.jersey-client,\
org.glassfish.jersey.core.jersey-client;version=2.26,\
javax.annotation-api;version=1.2.0,\
javax.inject;version=1.0.0,\
org.glassfish.jersey.bundles.repackaged.jersey-guava,\
org.glassfish.hk2.api;version=2.4.0,\
aopalliance,\
org.glassfish.hk2.utils;version=2.5.0,\
org.glassfish.jersey.core.jersey-common,\
org.glassfish.jersey.core.jersey-common;version=2.26,\
org.glassfish.hk2.osgi-resource-locator,\
org.glassfish.jersey.media.jersey-media-json-jackson;version=2.18.0,\
org.glassfish.jersey.media.jersey-media-json-jackson;version=2.26.0,\
com.fasterxml.jackson.module.jackson-module-jaxb-annotations,\
org.glassfish.jersey.ext.jersey-entity-filtering,\
com.google.guava;version=14.0.0,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import gov.pnnl.goss.gridappsd.data.handlers.BlazegraphQueryHandler;
import gov.pnnl.goss.gridappsd.dto.LogMessage.ProcessStatus;
import gov.pnnl.goss.gridappsd.dto.RequestTimeseriesData;
import gov.pnnl.goss.gridappsd.dto.RequestTimeseriesDataBasic;
import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants;
import pnnl.goss.core.Client;
import pnnl.goss.core.DataResponse;
Expand Down Expand Up @@ -253,7 +254,7 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces
//If use climate, then generate gridlabd weather data file
try {
if(useClimate){
RequestTimeseriesData weatherRequest = new RequestTimeseriesData();
RequestTimeseriesDataBasic weatherRequest = new RequestTimeseriesDataBasic();
weatherRequest.setQueryMeasurement("weather");
weatherRequest.setResponseFormat(ProvenWeatherToGridlabdWeatherConverter.OUTPUT_FORMAT);
Map<String, Object> queryFilter = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import gov.pnnl.goss.gridappsd.dto.LogMessage.LogLevel;
import gov.pnnl.goss.gridappsd.dto.LogMessage.ProcessStatus;
import gov.pnnl.goss.gridappsd.dto.RequestTimeseriesData;
import gov.pnnl.goss.gridappsd.dto.RequestTimeseriesDataBasic;
import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants;

import java.io.File;
Expand Down Expand Up @@ -164,7 +165,7 @@ public void generateConfig(Properties parameters, PrintWriter out,
logManager.error(ProcessStatus.ERROR, simulationID,"Simulation ID not a valid "+simulationID+", defaulting to "+simId);
}

RequestTimeseriesData request = new RequestTimeseriesData();
RequestTimeseriesDataBasic request = new RequestTimeseriesDataBasic();
request.setQueryMeasurement(loadprofile);
request.setResponseFormat(ProvenLoadScheduleToGridlabdLoadScheduleConverter.OUTPUT_FORMAT);
Map<String, Object> queryFilter = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import gov.pnnl.goss.gridappsd.data.conversion.DataFormatConverter;
import gov.pnnl.goss.gridappsd.dto.LogMessage.ProcessStatus;
import gov.pnnl.goss.gridappsd.dto.RequestTimeseriesData;
import gov.pnnl.goss.gridappsd.dto.RequestTimeseriesDataAdvanced;
import gov.pnnl.goss.gridappsd.dto.RequestTimeseriesDataBasic;
import gov.pnnl.goss.gridappsd.dto.SimulationContext;
import gov.pnnl.goss.gridappsd.dto.TimeSeriesEntryResult;
import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants;
Expand Down Expand Up @@ -73,6 +75,7 @@ public class ProvenTimeSeriesDataManagerImpl implements TimeseriesDataManager, D
Gson gson = new Gson();
String provenUri = null;
String provenQueryUri = null;
String provenAdvancedQueryUri = null;
String provenWriteUri = null;

ProvenProducer provenQueryProducer = new ProvenProducer();
Expand All @@ -90,9 +93,16 @@ public void start(){
provenUri = configManager.getConfigurationProperty(GridAppsDConstants.PROVEN_PATH);
provenWriteUri = configManager.getConfigurationProperty(GridAppsDConstants.PROVEN_WRITE_PATH);
provenQueryUri = configManager.getConfigurationProperty(GridAppsDConstants.PROVEN_QUERY_PATH);
provenAdvancedQueryUri = configManager.getConfigurationProperty(GridAppsDConstants.PROVEN_ADVANCED_QUERY_PATH);
provenQueryProducer.restProducer(provenQueryUri, null, null);
provenWriteProducer.restProducer(provenWriteUri, null, null);

try {
this.subscribeAndStoreDataFromTopic("/topic/goss.gridappsd.*.output", null, null, null);
} catch (Exception e) {
e.printStackTrace();
}

}


Expand All @@ -106,7 +116,20 @@ public Serializable handle(Serializable requestContent, String processId,
return query((RequestTimeseriesData)requestContent);
}
else if(requestContent instanceof String){
RequestTimeseriesData timeSeriesRequest = RequestTimeseriesData.parse((String)requestContent);
//First try to parse the query as the new format, if that fails try the old
RequestTimeseriesData timeSeriesRequest;
try{
timeSeriesRequest = RequestTimeseriesDataAdvanced.parse((String)requestContent);
}catch (Exception e) {
// TODO: handle exception
try{
timeSeriesRequest = RequestTimeseriesDataBasic.parse((String)requestContent);
}catch (Exception e2) {
throw new Exception("Failed to parse time series data request");
}
}


return query(timeSeriesRequest);
}

Expand All @@ -116,9 +139,17 @@ else if(requestContent instanceof String){
@Override
public Serializable query(RequestTimeseriesData requestTimeseriesData) throws Exception {

provenQueryProducer.restProducer(provenQueryUri, null, null);
provenQueryProducer.setMessageInfo("GridAPPSD", "QUERY", this.getClass().getSimpleName(), keywords);
ProvenResponse response = provenQueryProducer.sendMessage(requestTimeseriesData.toString(), requestId);
ProvenResponse response = null;

if(requestTimeseriesData instanceof RequestTimeseriesDataAdvanced){
provenQueryProducer.restProducer(provenAdvancedQueryUri, null, null);
provenQueryProducer.setMessageInfo("GridAPPSD", "QUERY", this.getClass().getSimpleName(), keywords);
response = provenQueryProducer.getAdvancedTsQuery(requestTimeseriesData.toString(), requestId);
}else {
provenQueryProducer.restProducer(provenQueryUri, null, null);
provenQueryProducer.setMessageInfo("GridAPPSD", "QUERY", this.getClass().getSimpleName(), keywords);
response = provenQueryProducer.sendMessage(requestTimeseriesData.toString(), requestId);
}
TimeSeriesEntryResult result = TimeSeriesEntryResult.parse(response.data.toString());
if(result.getData().size()==0)
return null;
Expand Down Expand Up @@ -171,8 +202,12 @@ private void subscribeAndStoreDataFromTopic(String topic, String appOrServiceid,
inputClient.subscribe(topic, new GossResponseEvent() {
@Override
public void onMessage(Serializable message) {
DataResponse event = (DataResponse)message;
try{
DataResponse event = (DataResponse)message;
for(String str : event.getDestination().split(".")){
System.out.println(str);
}
String appOrServiceid = event.getDestination().split("[.]")[2];
try{
provenWriteProducer.sendBulkMessage(event.getData().toString(), appOrServiceid, instanceId, simulationId, new Date().getTime());
}catch(Exception e){

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package gov.pnnl.goss.gridappsd.dto;

import java.io.IOException;

//import gov.pnnl.goss.gridappsd.api.TimeseriesDataManager.ResultFormat;

import java.io.Serializable;
import java.util.Map;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

public class RequestTimeseriesData implements Serializable {
public abstract class RequestTimeseriesData implements Serializable {

private static final long serialVersionUID = -820277813503252519L;

String queryMeasurement;
Map<String,Object> queryFilter;
//ResultFormat responseFormat = ResultFormat.JSON;
String responseFormat ="JSON";
private String queryType = "time-series";
int simulationYear;
Expand All @@ -33,13 +23,6 @@ public void setQueryMeasurement(String queryMeasurement) {
this.queryMeasurement = queryMeasurement;
}

public Map<String, Object> getQueryFilter() {
return queryFilter;
}

public void setQueryFilter(Map<String, Object> queryFilter) {
this.queryFilter = queryFilter;
}

public String getResponseFormat() {
return responseFormat;
Expand All @@ -64,29 +47,21 @@ public String getOriginalFormat() {
public void setOriginalFormat(String originalFormat) {
this.originalFormat = originalFormat;
}

public String getQueryType() {
return queryType;
}

public void setQueryType(String queryType) {
this.queryType = queryType;
}

@Override
public String toString() {
Gson gson = new Gson();
return gson.toJson(this);
}

public static RequestTimeseriesData parse(String jsonString){
ObjectMapper objectMapper = new ObjectMapper();
RequestTimeseriesData obj = null;
try {
obj = objectMapper.readValue(jsonString, RequestTimeseriesData.class);
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if(obj.queryMeasurement.equals("simulation"))
if(obj.queryFilter==null || !obj.queryFilter.containsKey("simulation_id"))
throw new JsonSyntaxException("Expected filter simulation_id not found.");
return obj;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package gov.pnnl.goss.gridappsd.dto;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.exception.ExceptionUtils;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

public class RequestTimeseriesDataAdvanced extends RequestTimeseriesData {

private static final long serialVersionUID = -820277813503252512L;

List<Object> queryFilter = new ArrayList<Object>();

List<String> selectCriteria = new ArrayList<String>();
Integer last;
Integer first;

public List<Object> getQueryFilter() {
return queryFilter;
}

public void setQueryFilter(List<Object> advancedQueryFilter) {
this.queryFilter = advancedQueryFilter;
}



public List<String> getSelectCriteria() {
return selectCriteria;
}
public void setSelectCriteria(List<String> selectCriteria) {
this.selectCriteria = selectCriteria;
}


public Integer getLast() {
return last;
}

public void setLast(Integer last) {
this.last = last;
}

public Integer getFirst() {
return first;
}

public void setFirst(Integer first) {
this.first = first;
}


@Override
public String toString() {
Gson gson = new Gson();
return gson.toJson(this);
}

public static RequestTimeseriesDataAdvanced parse(String jsonString){
ObjectMapper objectMapper = new ObjectMapper();
RequestTimeseriesDataAdvanced obj = null;
String error = "";
try {
obj = objectMapper.readValue(jsonString, RequestTimeseriesDataAdvanced.class);
} catch (JsonParseException e) {
error = ExceptionUtils.getStackTrace(e);
} catch (JsonMappingException e) {
error = ExceptionUtils.getStackTrace(e);
} catch (IOException e) {
error = ExceptionUtils.getStackTrace(e);
}
if(obj==null){
throw new JsonSyntaxException("Request time series data request could not be parsed: "+error);
}

// if(obj!=null && obj.queryMeasurement.equals("simulation")){
//if(obj.queryFilter==null || !obj.queryFilter.containsKey("simulation_id"))
// throw new JsonSyntaxException("Expected filter simulation_id not found.");
//TODO iterate through and look for key = simulation_id
return obj;
}



}
Loading

0 comments on commit 646f563

Please sign in to comment.