Skip to content

Commit

Permalink
Merge pull request #1490 from GRIDAPPSD/releases/2021.02.0
Browse files Browse the repository at this point in the history
Release of version 2021.02.0
  • Loading branch information
poorva1209 authored Mar 13, 2021
2 parents fe1ce8e + 767527a commit 8c6691f
Show file tree
Hide file tree
Showing 43 changed files with 5,954 additions and 551 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ RUN ln -s run-gridappsd.sh run-docker.sh
# Add the opendss command and library to the container
COPY ./opendss/opendsscmd /usr/local/bin
COPY ./opendss/liblinenoise.so /usr/local/lib
COPY ./opendss/libklusolve.so /usr/local/lib
RUN chmod +x /usr/local/bin/opendsscmd && \
ldconfig

Expand All @@ -96,6 +97,7 @@ RUN useradd -m gridappsd \
&& if [ -d /etc/sudoers.d ] ; then echo "gridappsd ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/gridappsd ; fi \
&& echo "[client]\nuser=gridappsd\npassword=gridappsd1234\ndatabase=gridappsd\nhost=mysql" > /home/gridappsd/.my.cnf \
&& chown gridappsd:gridappsd /home/gridappsd/.my.cnf \
&& chown -R gridappsd:gridappsd /gridappsd/services/gridappsd-ochre \
&& mkdir /gridappsd/log \
&& chown gridappsd:gridappsd /gridappsd/log

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ public void registerApp() throws IOException, SystemException, JMSException{
appInfo.setExecution_path("app/vvoapp.py");

List<String> inputs = new ArrayList<String>();
inputs.add(GridAppsDConstants.topic_FNCS_output);
inputs.add(GridAppsDConstants.topic_COSIM_input);
appInfo.setInputs(inputs);

List<String> outputs = new ArrayList<String>();
outputs.add(GridAppsDConstants.topic_FNCS_input);
outputs.add(GridAppsDConstants.topic_COSIM_input);
appInfo.setOutputs(outputs);

appInfo.setLaunch_on_startup(false);
Expand Down
14 changes: 10 additions & 4 deletions gov.pnnl.goss.gridappsd/conf/pnnl.goss.core.security.userfile.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ evaluator1=evaluator,evaluator
evaluator2=evaluator,evaluator
testmanager1=testmanager,testmanager
testmanager2=testmanager,testmanager
application1=application,application
application2=application,application
service1=service,service
service2=service,service
app_reg=1234App,application,admin
app_user=1234App,application,admin
service_reg=1234Svc,service,admin
service_user=1234Svc,service,admin
test_sys_user=1Test,admin,operator,evaluator,testmanager,application,service
test_oper_user=2Test,operator
test_eval_user=3Test,evaluator
test_app_user=4Test,application
test_svc_user=5Test,service
tutorial_user=12345!,admin,operator,evaluator,testmanager,application,service



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,12 @@
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import org.apache.felix.dm.annotation.api.Start;

import gov.pnnl.goss.gridappsd.api.ConfigurationHandler;
import gov.pnnl.goss.gridappsd.api.DataManager;
import gov.pnnl.goss.gridappsd.api.LogManager;
import gov.pnnl.goss.gridappsd.dto.LogMessage;
import gov.pnnl.goss.gridappsd.dto.LogMessage.LogLevel;
import gov.pnnl.goss.gridappsd.dto.LogMessage.ProcessStatus;
import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants;


Expand All @@ -78,28 +74,6 @@ public BaseConfigurationHandler(LogManager logManager, DataManager dataManager)
public void start(){
}

/*void logRunning(String message, String simulationID, String username, LogManager logManager){
logRunning(message, simulationID, username, logManager, LogLevel.INFO);
}
void logRunning(String message, String simulationID, String username, LogManager logManager, LogLevel logLevel){
logManager.log(
new LogMessage(this.getClass().getSimpleName(), new Integer(
simulationID).toString(), new Date().getTime(),
message, logLevel,
ProcessStatus.RUNNING, false), username,
GridAppsDConstants.topic_platformLog);
}
void logError(String message, String simulationID, String username, LogManager logManager){
logManager.log(
new LogMessage(this.getClass().getName(), new Integer(
simulationID).toString(), new Date().getTime(),
message, LogLevel.ERROR,
ProcessStatus.ERROR, false), username,
GridAppsDConstants.topic_platformLog);
}*/


void printFileToOutput(File configFile, PrintWriter out) throws IOException{
BufferedReader reader = new BufferedReader(new FileReader(configFile));
Expand All @@ -111,4 +85,5 @@ void printFileToOutput(File configFile, PrintWriter out) throws IOException{
reader.close();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import gov.pnnl.goss.gridappsd.data.ProvenTimeSeriesDataManagerImpl;
import gov.pnnl.goss.gridappsd.data.conversion.ProvenWeatherToGridlabdWeatherConverter;
import gov.pnnl.goss.gridappsd.data.handlers.BlazegraphQueryHandler;
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.utils.GridAppsDConstants;
Expand Down Expand Up @@ -226,7 +225,7 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces
logManager.error(ProcessStatus.ERROR,processId,"No "+SIMULATIONDURATION+" parameter provided");
throw new Exception("Missing parameter "+SIMULATIONDURATION);
}
long simulationEndTime = simulationStartTime+(1000*simulationDuration);
// long simulationEndTime = simulationStartTime+(1000*simulationDuration);

QueryHandler queryHandler = new BlazegraphQueryHandler(bgHost, logManager, processId, username);
queryHandler.addFeederSelection(modelId);
Expand Down Expand Up @@ -308,6 +307,9 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces
simOutputParams.setProperty(GLDSimulationOutputConfigurationHandler.DICTIONARY_FILE, dictFile);
simOutputParams.setProperty(GLDSimulationOutputConfigurationHandler.MODELID, modelId);
simOutputParams.setProperty(GLDSimulationOutputConfigurationHandler.USEHOUSES, Boolean.toString(useHouses));
simOutputParams.setProperty(SIMULATIONBROKERHOST, parameters.getProperty(SIMULATIONBROKERHOST,"127.0.0.1"));
simOutputParams.setProperty(SIMULATIONBROKERPORT, parameters.getProperty(SIMULATIONBROKERPORT,"5570"));
simOutputParams.setProperty(GridAppsDConstants.GRIDLABD_INTERFACE, parameters.getProperty(GridAppsDConstants.GRIDLABD_INTERFACE,GridAppsDConstants.GRIDLABD_INTERFACE_FNCS));
GLDSimulationOutputConfigurationHandler simulationOutputConfig = new GLDSimulationOutputConfigurationHandler(configManager, powergridModelManager, logManager);
simulationOutputConfig.generateConfig(simOutputParams, simulationOutputs, processId, username);

Expand All @@ -321,7 +323,10 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces

protected void generateStartupFile(Properties parameters, String tempDataPath, PrintWriter startupFileWriter, String modelId, String processId, String username, boolean useClimate, boolean useHouses) throws Exception{
logManager.info(ProcessStatus.RUNNING,processId,"Generating startup file for GridLAB-D configuration using parameters: "+parameters);



String gldInterface = GridAppsDConstants.getStringProperty(parameters, GridAppsDConstants.GRIDLABD_INTERFACE, GridAppsDConstants.GRIDLABD_INTERFACE_FNCS);

String simulationBrokerHost = GridAppsDConstants.getStringProperty(parameters, SIMULATIONBROKERHOST, null);
if(simulationBrokerHost==null || simulationBrokerHost.trim().length()==0){
logManager.error(ProcessStatus.ERROR,processId,"No "+SIMULATIONBROKERHOST+" parameter provided");
Expand Down Expand Up @@ -382,7 +387,7 @@ protected void generateStartupFile(Properties parameters, String tempDataPath, P
String brokerPort = String.valueOf(simulationBrokerPort);

Calendar c = Calendar.getInstance();
simulationStartTime = simulationStartTime;
// simulationStartTime = simulationStartTime;
Date startTime = new Date(simulationStartTime * 1000); //GridAppsDConstants.SDF_GLM_CLOCK.parse(simulationStartTime);
c.setTime(startTime);
c.add(Calendar.SECOND, new Integer(simulationDuration));
Expand Down Expand Up @@ -421,13 +426,22 @@ protected void generateStartupFile(Properties parameters, String tempDataPath, P
}
startupFileWriter.println("module reliability;");

if(GridAppsDConstants.GRIDLABD_INTERFACE_HELICS.equals(gldInterface)){
startupFileWriter.println("object helics_msg {");
startupFileWriter.println(" name "+simulationID+";");
startupFileWriter.println(" message_type JSON;");
startupFileWriter.println(" configure model_outputs.json;");
startupFileWriter.println("}");

startupFileWriter.println("object fncs_msg {");
startupFileWriter.println(" name "+simulationID+";");
startupFileWriter.println(" message_type JSON;");
startupFileWriter.println(" configure model_outputs.json;");
startupFileWriter.println(" option \"transport:hostname "+brokerLocation+", port "+brokerPort+"\";");
startupFileWriter.println("}");
} else {
startupFileWriter.println("object fncs_msg {");
startupFileWriter.println(" name "+simulationID+";");
startupFileWriter.println(" message_type JSON;");
startupFileWriter.println(" configure model_outputs.json;");
startupFileWriter.println(" option \"transport:hostname "+brokerLocation+", port "+brokerPort+"\";");
startupFileWriter.println("}");
}

startupFileWriter.println("object recorder {");
startupFileWriter.println(" parent "+simulationID+";");
startupFileWriter.println(" property message_type;");
Expand Down Expand Up @@ -486,5 +500,6 @@ protected void generateStartupFile(Properties parameters, String tempDataPath, P
logManager.info(ProcessStatus.RUNNING,processId,"Finished generating startup file for GridLAB-D configuration.");

}



}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
import gov.pnnl.goss.gridappsd.api.PowergridModelDataManager;
import gov.pnnl.goss.gridappsd.api.SimulationManager;
import gov.pnnl.goss.gridappsd.data.handlers.BlazegraphQueryHandler;
import gov.pnnl.goss.gridappsd.dto.LogMessage.LogLevel;
import gov.pnnl.goss.gridappsd.dto.LogMessage.ProcessStatus;
import gov.pnnl.goss.gridappsd.dto.SimulationContext;
import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants;
Expand All @@ -103,6 +102,17 @@ public class GLDSimulationOutputConfigurationHandler extends BaseConfigurationHa
public static final String DICTIONARY_FILE = "dictionary_file";
public static final String SIMULATIONID = "simulation_id";
public static final String USEHOUSES = "use_houses";
public static final String SIMULATIONBROKERHOST = "simulation_broker_host";
public static final String SIMULATIONBROKERPORT = "simulation_broker_port";


public static final String HELICS_PREFIX = "{\"name\": \"PROCESS_ID\",\"log_level\": 3,"
+ "\"period\": 1.0,\"broker\": \"BROKER_LOCATION:BROKER_PORT\",\"endpoints\": [{\"name\": \"helics_input\","
+ "\"global\": false,\"type\": \"string\", "
+ "\"info\": \"This is the endpoint which recieves CIM commands from the HELICS GOSS bridge.\"},"
+ "{\"name\": \"helics_output\",\"global\": false,\"type\": \"string\", "
+ "\"destination\": \"HELICS_GOSS_Bridge_PROCESS_ID/helics_output\", \"info\": \"";
public static final String HELICS_SUFFIX = "\"}]}";

public GLDSimulationOutputConfigurationHandler() {
}
Expand Down Expand Up @@ -153,16 +163,21 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces
}
}

String gldInterface = GridAppsDConstants.getStringProperty(parameters, GridAppsDConstants.GRIDLABD_INTERFACE, GridAppsDConstants.GRIDLABD_INTERFACE_FNCS);

StringWriter parameters_writer = new StringWriter();
parameters.list(new PrintWriter(parameters_writer));
String parameters_list = parameters_writer.getBuffer().toString();
String modelId = GridAppsDConstants.getStringProperty(parameters, MODELID, null);
if(modelId==null || modelId.trim().length()==0){
logManager.error(ProcessStatus.RUNNING, processId,"No "+MODELID+" parameter provided");
throw new Exception("Missing parameter "+MODELID);
logManager.error(ProcessStatus.RUNNING, processId,"No "+MODELID+" parameter provided.\nSimulationParameters: "+parameters_list);
throw new Exception("Missing parameter "+MODELID+"\nSimulation Parameters: "+parameters_list);
}

ModelState modelState = new ModelState();
String modelStateStr = GridAppsDConstants.getStringProperty(parameters, MODELSTATE, null);
if(modelStateStr==null || modelStateStr.trim().length()==0){
logManager.info(ProcessStatus.RUNNING, processId,"No "+MODELSTATE+" parameter provided");
logManager.info(ProcessStatus.RUNNING, processId,"No "+MODELSTATE+" parameter provided.\nSimulationParameters: "+parameters_list);
} else {
Gson gson = new Gson();
modelState = gson.fromJson(modelStateStr, ModelState.class);
Expand Down Expand Up @@ -204,6 +219,28 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces
}

String result = CreateGldPubs(measurementFileReader, processId, username);

//if it is for helics wrap it in the helix endpoint definition
if(GridAppsDConstants.GRIDLABD_INTERFACE_HELICS.equals(gldInterface)){
//Escape the json and embed it in the helics config file
String simulationBrokerHost = GridAppsDConstants.getStringProperty(parameters, SIMULATIONBROKERHOST, null);
if(simulationBrokerHost==null || simulationBrokerHost.trim().length()==0){
logManager.error(ProcessStatus.ERROR,processId,"No "+SIMULATIONBROKERHOST+" parameter provided.\nSimulationParameters: "+parameters_list);
throw new Exception("Missing parameter "+SIMULATIONBROKERHOST+"\nSimulation Parameters: "+parameters_list);
}
String simulationBrokerPort = GridAppsDConstants.getStringProperty(parameters, SIMULATIONBROKERPORT, null);
if(simulationBrokerPort==null || simulationBrokerPort.trim().length()==0){
logManager.error(ProcessStatus.ERROR,processId,"No "+SIMULATIONBROKERPORT+" parameter provided.\nSimulationParameters: "+parameters_list);
throw new Exception("Missing parameter "+SIMULATIONBROKERPORT+"\nSimulation Parameters: "+parameters_list);
}
String brokerLocation = simulationBrokerHost;
String brokerPort = String.valueOf(simulationBrokerPort);
String HELICS_PREFIX1 = HELICS_PREFIX.replaceAll("BROKER_LOCATION", brokerLocation);
String HELICS_PREFIX2 = HELICS_PREFIX1.replaceAll("BROKER_PORT", brokerPort);
result = HELICS_PREFIX2.replaceAll("PROCESS_ID", processId)
+result.replaceAll("\"", "\\\\\"").replaceAll("\n","")+
HELICS_SUFFIX;
}

if(configFile!=null){
FileWriter fw = new FileWriter(configFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public PowergridModelDataRequest(){}
//For all except query model names
public String modelId;
//Expected to match ResultFormat enum
public String resultFormat;
public String resultFormat = "JSON";

//For query
public String queryString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ public void setSimulationUser(String simulationUser) {
this.simulationUser = simulationUser;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import pnnl.goss.core.ClientFactory;
import pnnl.goss.core.DataResponse;
import pnnl.goss.core.GossResponseEvent;
import pnnl.goss.core.security.JWTAuthenticationToken;
import pnnl.goss.core.security.SecurityConfig;

/**
Expand Down Expand Up @@ -134,8 +135,22 @@ public void onMessage(Serializable message) {
* @param message A DataResponse message.
*/
private void logIncomingMessage(Serializable message) {

DataResponse event = (DataResponse)message;
String username = event.getUsername();
LogMessage logMessage = LogMessage.parse(event.getData().toString());

//If it is a token instead of username
if(username!=null && username.length()>250){ //if it is a token
boolean valid = securityConfig.validateToken(username);
if(!valid){
this.error(ProcessStatus.ERROR, logMessage.getProcessId(),"Failure to validate authentication token:"+username);
return;
}
//Get username from token
JWTAuthenticationToken tokenObj = securityConfig.parseToken(username);
username = tokenObj.getSub();
}
logToConsole(LogMessage.parse(event.getData().toString()), username, null);
}

Expand Down Expand Up @@ -167,7 +182,9 @@ private void logToConsole(LogMessage message, String username, String topic) {
if(logString.length() > 200 && message.getLogLevel()!=LogLevel.ERROR) {
logString = logString.substring(0,200);
}
switch(message.getLogLevel()) {
LogLevel messageLevel = message.getLogLevel();
if(messageLevel==null){ messageLevel = LogLevel.DEBUG; }
switch(messageLevel) {
case TRACE: log.trace(logString);
break;
case DEBUG: log.debug(logString);
Expand Down
Loading

0 comments on commit 8c6691f

Please sign in to comment.