From 4b36677f90140921eeec6dfa5f43689eb9353a0f Mon Sep 17 00:00:00 2001 From: Sharma Date: Tue, 4 May 2021 14:33:22 -0700 Subject: [PATCH 01/29] ochre simulation --- .../OchreAllConfigurationHandler.java | 166 ++++++++++++++++++ .../process/ProcessNewSimulationRequest.java | 43 +++-- 2 files changed, 191 insertions(+), 18 deletions(-) create mode 100644 gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java new file mode 100644 index 00000000..bb9809a3 --- /dev/null +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * Copyright 2017, Battelle Memorial Institute All rights reserved. + * Battelle Memorial Institute (hereinafter Battelle) hereby grants permission to any person or entity + * lawfully obtaining a copy of this software and associated documentation files (hereinafter the + * Software) to redistribute and use the Software in source and binary forms, with or without modification. + * Such person or entity may use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and may permit others to do so, subject to the following conditions: + * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimers. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * Other than as used herein, neither the name Battelle Memorial Institute or Battelle may be used in any + * form whatsoever without the express written consent of Battelle. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * BATTELLE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * General disclaimer for use with OSS licenses + * + * This material was prepared as an account of work sponsored by an agency of the United States Government. + * Neither the United States Government nor the United States Department of Energy, nor Battelle, nor any + * of their employees, nor any jurisdiction or organization that has cooperated in the development of these + * materials, makes any warranty, express or implied, or assumes any legal liability or responsibility for + * the accuracy, completeness, or usefulness or any information, apparatus, product, software, or process + * disclosed, or represents that its use would not infringe privately owned rights. + * + * Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, + * or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United + * States Government or any agency thereof, or Battelle Memorial Institute. The views and opinions of authors expressed + * herein do not necessarily state or reflect those of the United States Government or any agency thereof. + * + * PACIFIC NORTHWEST NATIONAL LABORATORY operated by BATTELLE for the + * UNITED STATES DEPARTMENT OF ENERGY under Contract DE-AC05-76RL01830 + ******************************************************************************/ +package gov.pnnl.goss.gridappsd.configuration; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Properties; + +import org.apache.felix.dm.annotation.api.Component; +import org.apache.felix.dm.annotation.api.ServiceDependency; +import org.apache.felix.dm.annotation.api.Start; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import gov.pnnl.goss.gridappsd.api.ConfigurationHandler; +import gov.pnnl.goss.gridappsd.api.ConfigurationManager; +import gov.pnnl.goss.gridappsd.api.DataManager; +import gov.pnnl.goss.gridappsd.api.LogManager; +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.ProcessStatus; +import gov.pnnl.goss.gridappsd.dto.SimulationContext; +import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants; +import gov.pnnl.gridappsd.cimhub.CIMImporter; +import gov.pnnl.gridappsd.cimhub.queryhandler.QueryHandler; +import pnnl.goss.core.Client; + + +@Component +public class OchreAllConfigurationHandler extends BaseConfigurationHandler implements ConfigurationHandler {//implements ConfigurationManager{ + + private static Logger log = LoggerFactory.getLogger(OchreAllConfigurationHandler.class); + Client client = null; + + @ServiceDependency + private volatile ConfigurationManager configManager; + @ServiceDependency + private volatile SimulationManager simulationManager; + @ServiceDependency + private volatile PowergridModelDataManager powergridModelManager; + @ServiceDependency + private volatile LogManager logManager; + + public static final String TYPENAME = "OCHRE"; + public static final String MODELID = "model_id"; + public static final String SIMULATIONID = "simulation_id"; + public static final String CONFIGTARGET = "both"; //will build files for both glm and ochre + + public OchreAllConfigurationHandler() { + } + + public OchreAllConfigurationHandler(LogManager logManager, DataManager dataManager) { + + } + + + @Start + public void start(){ + if(configManager!=null) { + configManager.registerConfigurationHandler(TYPENAME, this); + } + else { + //TODO send log message and exception + log.warn("No Config manager avilable for "+getClass()); + } + + if(powergridModelManager == null){ + //TODO send log message and exception + } + } + + @Override + public void generateConfig(Properties parameters, PrintWriter out, String processId, String username) throws Exception { + logManager.info(ProcessStatus.RUNNING,processId,"Generating DSS Coordinate configuration file using parameters: "+parameters); + + String simulationId = GridAppsDConstants.getStringProperty(parameters, SIMULATIONID, null); + File configFile = null; + if(simulationId!=null){ + SimulationContext simulationContext = simulationManager.getSimulationContextForId(simulationId); + if(simulationContext!=null){ + configFile = new File(simulationContext.getSimulationDir()+File.separator+DSSBaseConfigurationHandler.DSSBUSXY_FILENAME); + //If the config file already has been created for this simulation then return it + if(configFile.exists()){ + printFileToOutput(configFile, out); + logManager.info(ProcessStatus.RUNNING,processId,"Dictionary DSS coordinates file for simulation "+simulationId+" already exists."); + return; + } + } else { + logManager.warn(ProcessStatus.RUNNING,processId,"No simulation context found for simulation_id: "+simulationId); + } + } + + String modelId = GridAppsDConstants.getStringProperty(parameters, MODELID, null); + if(modelId==null || modelId.trim().length()==0){ + logManager.error(ProcessStatus.ERROR, processId, "No "+MODELID+" parameter provided"); + throw new Exception("Missing parameter "+MODELID); + } + + + String bgHost = configManager.getConfigurationProperty(GridAppsDConstants.BLAZEGRAPH_HOST_PATH); + if(bgHost==null || bgHost.trim().length()==0){ + bgHost = BlazegraphQueryHandler.DEFAULT_ENDPOINT; + } + + //TODO write a query handler that uses the built in powergrid model data manager that talks to blazegraph internally + QueryHandler queryHandler = new BlazegraphQueryHandler(bgHost, logManager, processId, username); + queryHandler.addFeederSelection(modelId); + + CIMImporter cimImporter = new CIMImporter(); + //If the simulation info is available also write to file + if(configFile!=null){ + cimImporter.generateDSSCoordinates(queryHandler, new PrintWriter(new FileWriter(configFile))); + } else { + cimImporter.generateDSSCoordinates(queryHandler, out); + } + if(configFile!=null){ + //config was written to file, so return that + printFileToOutput(configFile, out); + } + logManager.info(ProcessStatus.RUNNING,processId,"Finished generating DSS Coordinate configuration file."); + + } + + + + +} diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java index 02aa9b0d..2d1bf9ab 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java @@ -39,6 +39,19 @@ ******************************************************************************/ package gov.pnnl.goss.gridappsd.process; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import com.google.gson.Gson; + import gov.pnnl.goss.gridappsd.api.AppManager; import gov.pnnl.goss.gridappsd.api.ConfigurationManager; import gov.pnnl.goss.gridappsd.api.DataManager; @@ -48,10 +61,9 @@ import gov.pnnl.goss.gridappsd.api.TestManager; import gov.pnnl.goss.gridappsd.configuration.DSSAllConfigurationHandler; import gov.pnnl.goss.gridappsd.configuration.GLDAllConfigurationHandler; +import gov.pnnl.goss.gridappsd.configuration.OchreAllConfigurationHandler; import gov.pnnl.goss.gridappsd.dto.AppInfo; import gov.pnnl.goss.gridappsd.dto.ApplicationObject; -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.dto.ModelCreationConfig; import gov.pnnl.goss.gridappsd.dto.RequestSimulation; @@ -62,21 +74,6 @@ import gov.pnnl.goss.gridappsd.dto.SimulationOutput; import gov.pnnl.goss.gridappsd.dto.SimulationOutputObject; import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import com.google.gson.Gson; - import pnnl.goss.core.DataResponse; import pnnl.goss.core.security.SecurityConfig; @@ -180,7 +177,17 @@ public void process(ConfigurationManager configurationManager, simulationParams.put(GridAppsDConstants.GRIDLABD_INTERFACE, gldInterface); } configurationManager.generateConfiguration(DSSAllConfigurationHandler.TYPENAME, simulationParams, new PrintWriter(new StringWriter()), simulationId, username); - } else { //otherwise use gridlabd + } + else if(simulator.equalsIgnoreCase(OchreAllConfigurationHandler.CONFIGTARGET)){ + Properties simulationParams = generateSimulationParameters(simRequest); + simulationParams.put(DSSAllConfigurationHandler.SIMULATIONID, simulationId); + simulationParams.put(DSSAllConfigurationHandler.DIRECTORY, tempDataPathDir.getAbsolutePath()); + if(gldInterface!=null){ + simulationParams.put(GridAppsDConstants.GRIDLABD_INTERFACE, gldInterface); + } + configurationManager.generateConfiguration(OchreAllConfigurationHandler.TYPENAME, simulationParams, new PrintWriter(new StringWriter()), simulationId, username); + } + else { //otherwise use gridlabd Properties simulationParams = generateSimulationParameters(simRequest); simulationParams.put(GLDAllConfigurationHandler.SIMULATIONID, simulationId); simulationParams.put(GLDAllConfigurationHandler.DIRECTORY, tempDataPathDir.getAbsolutePath()); From 816af183dd29d975523efafd235fee9032a04d4d Mon Sep 17 00:00:00 2001 From: Sharma Date: Thu, 6 May 2021 14:59:08 -0700 Subject: [PATCH 02/29] adding ochre config --- .../OchreAllConfigurationHandler.java | 84 +++++++++---------- .../process/ProcessNewSimulationRequest.java | 2 +- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java index bb9809a3..f5d00238 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java @@ -60,6 +60,7 @@ import gov.pnnl.goss.gridappsd.dto.LogMessage.ProcessStatus; import gov.pnnl.goss.gridappsd.dto.SimulationContext; import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants; +import gov.pnnl.goss.gridappsd.utils.RunCommandLine; import gov.pnnl.gridappsd.cimhub.CIMImporter; import gov.pnnl.gridappsd.cimhub.queryhandler.QueryHandler; import pnnl.goss.core.Client; @@ -81,9 +82,13 @@ public class OchreAllConfigurationHandler extends BaseConfigurationHandler imple private volatile LogManager logManager; public static final String TYPENAME = "OCHRE"; + public static final String DIRECTORY = "directory"; public static final String MODELID = "model_id"; public static final String SIMULATIONID = "simulation_id"; - public static final String CONFIGTARGET = "both"; //will build files for both glm and ochre + public static final String CONFIGTARGET = "ochre"; //will build files for both glm and ochre + public static final String CONFIG_FILENAME = "ochre_helics_config.json"; + public static final String SIMULATIONBROKERHOST = "simulation_broker_host"; + public static final String SIMULATIONBROKERPORT = "simulation_broker_port"; public OchreAllConfigurationHandler() { } @@ -110,56 +115,51 @@ public void start(){ @Override public void generateConfig(Properties parameters, PrintWriter out, String processId, String username) throws Exception { - logManager.info(ProcessStatus.RUNNING,processId,"Generating DSS Coordinate configuration file using parameters: "+parameters); + logManager.info(ProcessStatus.RUNNING,processId,"Generating OCHRE HELICS config file using parameters: "+parameters); - String simulationId = GridAppsDConstants.getStringProperty(parameters, SIMULATIONID, null); - File configFile = null; - if(simulationId!=null){ - SimulationContext simulationContext = simulationManager.getSimulationContextForId(simulationId); - if(simulationContext!=null){ - configFile = new File(simulationContext.getSimulationDir()+File.separator+DSSBaseConfigurationHandler.DSSBUSXY_FILENAME); - //If the config file already has been created for this simulation then return it - if(configFile.exists()){ - printFileToOutput(configFile, out); - logManager.info(ProcessStatus.RUNNING,processId,"Dictionary DSS coordinates file for simulation "+simulationId+" already exists."); - return; - } - } else { - logManager.warn(ProcessStatus.RUNNING,processId,"No simulation context found for simulation_id: "+simulationId); - } + String directory = GridAppsDConstants.getStringProperty(parameters, DIRECTORY, null); + if(directory==null || directory.trim().length()==0){ + logManager.error(ProcessStatus.ERROR,processId,"No "+DIRECTORY+" parameter provided"); + throw new Exception("Missing parameter "+DIRECTORY); } + File dir = new File(directory); + if(!dir.exists()){ + dir.mkdirs(); + String tempDataPath = dir.getAbsolutePath(); - String modelId = GridAppsDConstants.getStringProperty(parameters, MODELID, null); - if(modelId==null || modelId.trim().length()==0){ - logManager.error(ProcessStatus.ERROR, processId, "No "+MODELID+" parameter provided"); - throw new Exception("Missing parameter "+MODELID); + String simulationBrokerHost = GridAppsDConstants.getStringProperty(parameters, SIMULATIONBROKERHOST, null); + if(simulationBrokerHost==null || simulationBrokerHost.trim().length()==0){ + logManager.error(ProcessStatus.ERROR,processId,"No "+SIMULATIONBROKERHOST+" parameter provided"); + throw new Exception("Missing parameter "+SIMULATIONBROKERHOST); } - - String bgHost = configManager.getConfigurationProperty(GridAppsDConstants.BLAZEGRAPH_HOST_PATH); - if(bgHost==null || bgHost.trim().length()==0){ - bgHost = BlazegraphQueryHandler.DEFAULT_ENDPOINT; + String simulationBrokerPort = GridAppsDConstants.getStringProperty(parameters, SIMULATIONBROKERPORT, null); + if(simulationBrokerPort==null || simulationBrokerPort.trim().length()==0){ + logManager.error(ProcessStatus.ERROR,processId,"No "+SIMULATIONBROKERPORT+" parameter provided"); + throw new Exception("Missing parameter "+SIMULATIONBROKERPORT); } + + try{ + RunCommandLine.runCommand("python /gridappsd/services/gridappsd-cohre/bin/make_config_file.py "+ + simulationBrokerHost+" "+ + tempDataPath+" "+ + CONFIG_FILENAME+" "+ + simulationBrokerPort+" "+ + processId); + logManager.info(ProcessStatus.RUNNING, processId, "python /gridappsd/services/gridappsd-cohre/bin/make_config_file.py "+ + simulationBrokerHost+" "+ + tempDataPath+" "+ + CONFIG_FILENAME+" "+ + simulationBrokerPort+" "+ + processId); + }catch(Exception e){ + log.warn("Could not create OCHRE HELICS config file"); + } - //TODO write a query handler that uses the built in powergrid model data manager that talks to blazegraph internally - QueryHandler queryHandler = new BlazegraphQueryHandler(bgHost, logManager, processId, username); - queryHandler.addFeederSelection(modelId); - - CIMImporter cimImporter = new CIMImporter(); - //If the simulation info is available also write to file - if(configFile!=null){ - cimImporter.generateDSSCoordinates(queryHandler, new PrintWriter(new FileWriter(configFile))); - } else { - cimImporter.generateDSSCoordinates(queryHandler, out); - } - if(configFile!=null){ - //config was written to file, so return that - printFileToOutput(configFile, out); - } - logManager.info(ProcessStatus.RUNNING,processId,"Finished generating DSS Coordinate configuration file."); + logManager.info(ProcessStatus.RUNNING,processId,"Finished generating OCHRE HELICS config file."); } - + } diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java index 2d1bf9ab..f663f90e 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java @@ -178,7 +178,7 @@ public void process(ConfigurationManager configurationManager, } configurationManager.generateConfiguration(DSSAllConfigurationHandler.TYPENAME, simulationParams, new PrintWriter(new StringWriter()), simulationId, username); } - else if(simulator.equalsIgnoreCase(OchreAllConfigurationHandler.CONFIGTARGET)){ + else if(simulator.equalsIgnoreCase(OchreAllConfigurationHandler.TYPENAME)){ Properties simulationParams = generateSimulationParameters(simRequest); simulationParams.put(DSSAllConfigurationHandler.SIMULATIONID, simulationId); simulationParams.put(DSSAllConfigurationHandler.DIRECTORY, tempDataPathDir.getAbsolutePath()); From 3ab2958bddf3d7a86f1351231cc64136402420e7 Mon Sep 17 00:00:00 2001 From: Sharma Date: Thu, 6 May 2021 15:20:13 -0700 Subject: [PATCH 03/29] added ochre config --- services/ochre.config | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 services/ochre.config diff --git a/services/ochre.config b/services/ochre.config new file mode 100644 index 00000000..870167f2 --- /dev/null +++ b/services/ochre.config @@ -0,0 +1,14 @@ +{ + "id": "OCHRE", + "description": "OCHRE", + "creator": "NREL", + "inputs": [], + "outputs": [], + "static_args": ["run", "--path bin/config.json", "--broker-loglevel=2"], + "execution_path": "helics", + "type": "EXE", + "launch_on_startup": "false", + "service_dependencies": ["helics","helicsgossbridge","gridappsd-alarms","gridappsd-voltage-violation"], + "multiple_instances": false, + "environmentVariables":[] +} From 29ed43f83bb4dfd11e75dca87080529fbb8280d1 Mon Sep 17 00:00:00 2001 From: Sharma Date: Fri, 7 May 2021 09:41:31 -0700 Subject: [PATCH 04/29] resolved errors --- .../configuration/OchreAllConfigurationHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java index f5d00238..fd6dd933 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java @@ -123,7 +123,7 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces throw new Exception("Missing parameter "+DIRECTORY); } File dir = new File(directory); - if(!dir.exists()){ + if(!dir.exists()) dir.mkdirs(); String tempDataPath = dir.getAbsolutePath(); @@ -140,7 +140,7 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces } try{ - RunCommandLine.runCommand("python /gridappsd/services/gridappsd-cohre/bin/make_config_file.py "+ + RunCommandLine.runCommand("python /gridappsd/services/gridappsd-ochre/bin/make_config_file.py "+ simulationBrokerHost+" "+ tempDataPath+" "+ CONFIG_FILENAME+" "+ @@ -158,7 +158,7 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces logManager.info(ProcessStatus.RUNNING,processId,"Finished generating OCHRE HELICS config file."); - } + } From 1809444fabf859ccc85d8be61aa05b5d2c7b17be Mon Sep 17 00:00:00 2001 From: Sharma Date: Fri, 7 May 2021 11:33:20 -0700 Subject: [PATCH 05/29] chages to start ochre simulation --- .../process/ProcessNewSimulationRequest.java | 10 ++++- .../simulation/SimulationManagerImpl.java | 2 +- .../simulation/SimulationProcess.java | 38 +++++++++++++++++-- services/ochre.config | 2 +- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java index f663f90e..e3a9bbdb 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java @@ -145,7 +145,10 @@ public void process(ConfigurationManager configurationManager, simContext.simulationId = simulationId; simContext.simulationPort = simulationPort; simContext.simulationDir = tempDataPathDir.getAbsolutePath(); - simContext.startupFile = tempDataPathDir.getAbsolutePath()+File.separator+"model_startup.glm"; + if(simRequest.getSimulation_config().getSimulator().equals("GridLAB-D")) + simContext.startupFile = tempDataPathDir.getAbsolutePath()+File.separator+"model_startup.glm"; + else if(simRequest.getSimulation_config().getSimulator().equals("OCHRE")) + simContext.startupFile = tempDataPathDir.getAbsolutePath()+File.separator+"ochre_helics_config.json"; simContext.simulationUser = username; try{ simContext.simulatorPath = serviceManager.getService(simRequest.getSimulation_config().getSimulator()).getExecution_path(); @@ -208,7 +211,10 @@ else if(simulator.equalsIgnoreCase(OchreAllConfigurationHandler.TYPENAME)){ simulationContext.put("simulationHost","127.0.0.1"); simulationContext.put("simulationPort",simulationPort); simulationContext.put("simulationDir",simulationConfigDir); - simulationContext.put("simulationFile",tempDataPathDir.getAbsolutePath()+File.separator+"model_startup.glm"); + if(simRequest.getSimulation_config().getSimulator().equals("GridLAB-D")) + simulationContext.put("simulationFile",tempDataPathDir.getAbsolutePath()+File.separator+"model_startup.glm"); + else if(simRequest.getSimulation_config().getSimulator().equals("OCHRE")) + simulationContext.put("simulationFile",tempDataPathDir.getAbsolutePath()+File.separator+"ochre_helics_config.json"); simulationContext.put("logLevel", logManager.getLogLevel()); simulationContext.put("username", securityConfig.getManagerUser()); simulationContext.put("password", securityConfig.getManagerPassword()); diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationManagerImpl.java index ccc73461..2db9cc4f 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationManagerImpl.java @@ -141,7 +141,7 @@ public void startSimulation(String simulationId, SimulationConfig simulationConf simContexts.put(simContext.getSimulationId(), simContext); SimulationProcess simProc = new SimulationProcess(simContext, serviceManager, - simulationConfig, simulationId, logManager, appManager, client, securityConfig); + simulationConfig, simulationId, logManager, appManager, client, securityConfig, simulationContext); // simProcesses.put(simContext.getSimulationId(), simProc); simProc.start(); } diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java index 79c609b9..93bf9551 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java @@ -6,6 +6,7 @@ import gov.pnnl.goss.gridappsd.configuration.GLDAllConfigurationHandler; import gov.pnnl.goss.gridappsd.dto.FncsBridgeResponse; import gov.pnnl.goss.gridappsd.dto.LogMessage; +import gov.pnnl.goss.gridappsd.dto.ServiceInfo; import gov.pnnl.goss.gridappsd.dto.LogMessage.LogLevel; import gov.pnnl.goss.gridappsd.dto.LogMessage.ProcessStatus; import gov.pnnl.goss.gridappsd.dto.SimulationConfig; @@ -18,10 +19,13 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.Serializable; +import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,10 +67,11 @@ class SimulationTracker { AppManager appManager; Client client; SecurityConfig securityConfig; + Map simulationContex; public SimulationProcess(SimulationContext simContext, ServiceManager serviceManager, SimulationConfig simulationConfig, String simulationId, LogManager logManager, - AppManager appManager, Client client, SecurityConfig securityConfig){ + AppManager appManager, Client client, SecurityConfig securityConfig, Map simulationContex){ this.simContext = simContext; this.serviceManager = serviceManager; this.simulationConfig = simulationConfig; @@ -75,6 +80,7 @@ public SimulationProcess(SimulationContext simContext, ServiceManager serviceMan this.appManager = appManager; this.client = client; this.securityConfig = securityConfig; + this.simulationContex = simulationContex; } @@ -103,9 +109,33 @@ public void run() { } //} - //Start GridLAB-D + //Start Simulator logManager.info(ProcessStatus.RUNNING, simulationId, simContext.getSimulatorPath()+" "+simulationFile); - ProcessBuilder simulatorBuilder = new ProcessBuilder(simContext.getSimulatorPath(), simulationFile.getAbsolutePath()); + ProcessBuilder simulatorBuilder = null; + if(simulationConfig.getSimulator().equals("OCHRE")){ + List commands = new ArrayList(); + commands.add(simContext.getSimulatorPath()); + ServiceInfo serviceInfo = serviceManager.getService(simulationConfig.getSimulator()); + List staticArgsList = serviceInfo.getStatic_args(); + for(String staticArg : staticArgsList) { + if(staticArg!=null){ + //Right now this depends on having the simulationContext set, so don't try it if the simulation context is null + if(simulationContex!=null){ + if(staticArg.contains("(")){ + String[] replaceArgs = StringUtils.substringsBetween(staticArg, "(", ")"); + for(String args : replaceArgs){ + staticArg = staticArg.replace("("+args+")",simulationContex.get(args).toString()); + } + } + } + commands.add(staticArg); + } + } + simulatorBuilder = new ProcessBuilder(); + simulatorBuilder.command(commands); + } + else + simulatorBuilder = new ProcessBuilder(simContext.getSimulatorPath(), simulationFile.getAbsolutePath()); simulatorBuilder.redirectErrorStream(true); simulatorBuilder.redirectOutput(); //launch from directory containing simulation files @@ -117,7 +147,7 @@ public void run() { //TODO: check if GridLAB-D is started correctly and send publish simulation status accordingly - logManager.info(ProcessStatus.RUNNING, simulationId, "GridLAB-D started"); + logManager.info(ProcessStatus.RUNNING, simulationId, simulationConfig.getSimulator()+" simulator started"); //Subscribe to fncs-goss-bridge output topic GossFncsResponseEvent gossFncsResponseEvent = new GossFncsResponseEvent(logManager, isInitialized, isFinished, simulationId); diff --git a/services/ochre.config b/services/ochre.config index 870167f2..71ae5b87 100644 --- a/services/ochre.config +++ b/services/ochre.config @@ -4,7 +4,7 @@ "creator": "NREL", "inputs": [], "outputs": [], - "static_args": ["run", "--path bin/config.json", "--broker-loglevel=2"], + "static_args": ["run", "--path (simulationFile)", "--broker-loglevel=2"], "execution_path": "helics", "type": "EXE", "launch_on_startup": "false", From ccfc318997c8520afeb835740efe883441e500ba Mon Sep 17 00:00:00 2001 From: Sharma Date: Fri, 7 May 2021 12:01:57 -0700 Subject: [PATCH 06/29] starting ochre simulation --- .../gridappsd/simulation/SimulationProcess.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java index 93bf9551..64464a3a 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java @@ -110,10 +110,10 @@ public void run() { //} //Start Simulator - logManager.info(ProcessStatus.RUNNING, simulationId, simContext.getSimulatorPath()+" "+simulationFile); - ProcessBuilder simulatorBuilder = null; + ProcessBuilder simulatorBuilder = new ProcessBuilder(); + List commands = new ArrayList(); + if(simulationConfig.getSimulator().equals("OCHRE")){ - List commands = new ArrayList(); commands.add(simContext.getSimulatorPath()); ServiceInfo serviceInfo = serviceManager.getService(simulationConfig.getSimulator()); List staticArgsList = serviceInfo.getStatic_args(); @@ -131,15 +131,18 @@ public void run() { commands.add(staticArg); } } - simulatorBuilder = new ProcessBuilder(); simulatorBuilder.command(commands); } - else - simulatorBuilder = new ProcessBuilder(simContext.getSimulatorPath(), simulationFile.getAbsolutePath()); + else if(simulationConfig.getSimulator().equals("GridLAB-D")){ + commands.add(simContext.getSimulatorPath()); + commands.add(simulationFile.getAbsolutePath()); + simulatorBuilder.command(commands); + } simulatorBuilder.redirectErrorStream(true); simulatorBuilder.redirectOutput(); //launch from directory containing simulation files simulatorBuilder.directory(simulationFile.getParentFile()); + logManager.info(ProcessStatus.RUNNING, simulationId, "Starting simulator with command "+String.join(" ",commands)); simulatorProcess = simulatorBuilder.start(); // Watch the process watch(simulatorProcess, "Simulator-"+simulationId); From 9bc9a17bac54c18f7cf7e0657f1494ed460e8bd1 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Fri, 4 Jun 2021 15:17:02 -0700 Subject: [PATCH 07/29] Updates to allow the make ochre config to work from hte platform --- .../configuration/OchreAllConfigurationHandler.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java index fd6dd933..776a5d7b 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java @@ -140,13 +140,18 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces } try{ + File tmpDir = new File(tempDataPath); + RunCommandLine.runCommand("cp -r /gridappsd/services/gridappsd-ochre/inputs/ "+tempDataPath); + RunCommandLine.runCommand("cp -r /gridappsd/services/gridappsd-ochre/agents/ "+tempDataPath); + simulationBrokerHost = "localhost"; + RunCommandLine.runCommand("python /gridappsd/services/gridappsd-ochre/bin/make_config_file.py "+ simulationBrokerHost+" "+ tempDataPath+" "+ CONFIG_FILENAME+" "+ simulationBrokerPort+" "+ processId); - logManager.info(ProcessStatus.RUNNING, processId, "python /gridappsd/services/gridappsd-cohre/bin/make_config_file.py "+ + logManager.info(ProcessStatus.RUNNING, processId, "python /gridappsd/services/gridappsd-ochre/bin/make_config_file.py "+ simulationBrokerHost+" "+ tempDataPath+" "+ CONFIG_FILENAME+" "+ From 3501d5cbb0d87f51611066090b6cc93bc75f8b06 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Mon, 14 Jun 2021 12:03:20 -0700 Subject: [PATCH 08/29] Added code to start up gridlabd for ochre simulation --- .../simulation/SimulationProcess.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java index 64464a3a..4c3d7610 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java @@ -4,6 +4,7 @@ import gov.pnnl.goss.gridappsd.api.LogManager; import gov.pnnl.goss.gridappsd.api.ServiceManager; import gov.pnnl.goss.gridappsd.configuration.GLDAllConfigurationHandler; +import gov.pnnl.goss.gridappsd.configuration.OchreAllConfigurationHandler; import gov.pnnl.goss.gridappsd.dto.FncsBridgeResponse; import gov.pnnl.goss.gridappsd.dto.LogMessage; import gov.pnnl.goss.gridappsd.dto.ServiceInfo; @@ -38,7 +39,7 @@ public class SimulationProcess extends Thread { private static Logger log = LoggerFactory.getLogger(SimulationProcess.class); - + private static String gridlabdConstant = "GridLAB-D"; boolean running = true; @@ -113,7 +114,21 @@ public void run() { ProcessBuilder simulatorBuilder = new ProcessBuilder(); List commands = new ArrayList(); - if(simulationConfig.getSimulator().equals("OCHRE")){ + if(simulationConfig.getSimulator().equals(OchreAllConfigurationHandler.TYPENAME)){ + //Start gridlabd +// simulationContext.put("simulationFile",tempDataPathDir.getAbsolutePath()+File.separator+"model_startup.glm"); + File gldStartupFile = new File(simContext.simulationDir+File.separator+"inputs"+File.separator+"gridlabd"+File.separator+"IEEE-13"+File.separator+"IEEE-13_Houses.glm"); + String gldSimulatorPath = serviceManager.getService(gridlabdConstant).getExecution_path(); +// commands.add(simContext.getSimulatorPath()); + commands.add(gldSimulatorPath); +// commands.add(simulationFile.getAbsolutePath()); + commands.add(gldStartupFile.getAbsolutePath()); + simulatorBuilder.command(commands); + + + + //Start ochre + commands = new ArrayList(); commands.add(simContext.getSimulatorPath()); ServiceInfo serviceInfo = serviceManager.getService(simulationConfig.getSimulator()); List staticArgsList = serviceInfo.getStatic_args(); @@ -133,10 +148,12 @@ public void run() { } simulatorBuilder.command(commands); } - else if(simulationConfig.getSimulator().equals("GridLAB-D")){ + else if(simulationConfig.getSimulator().equals(gridlabdConstant)){ commands.add(simContext.getSimulatorPath()); commands.add(simulationFile.getAbsolutePath()); simulatorBuilder.command(commands); + } else { + log.warn("No known simulator: "+simulationConfig.getSimulator()); } simulatorBuilder.redirectErrorStream(true); simulatorBuilder.redirectOutput(); From 5bc2a41c92f77e8d72f6ac3fd19fca619daef738 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Mon, 14 Jun 2021 12:06:54 -0700 Subject: [PATCH 09/29] Generate gridlabd files as well as ochre --- .../pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java index e3a9bbdb..e196a814 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java @@ -188,6 +188,7 @@ else if(simulator.equalsIgnoreCase(OchreAllConfigurationHandler.TYPENAME)){ if(gldInterface!=null){ simulationParams.put(GridAppsDConstants.GRIDLABD_INTERFACE, gldInterface); } + configurationManager.generateConfiguration(GLDAllConfigurationHandler.TYPENAME, simulationParams, new PrintWriter(new StringWriter()), simulationId, username); configurationManager.generateConfiguration(OchreAllConfigurationHandler.TYPENAME, simulationParams, new PrintWriter(new StringWriter()), simulationId, username); } else { //otherwise use gridlabd From 1840126907e9eb34bd0c19dcd87836bc5f548fa9 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Mon, 14 Jun 2021 12:50:15 -0700 Subject: [PATCH 10/29] Actually start up gridlabd service when ochre is run --- .../gridappsd/simulation/SimulationProcess.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java index 4c3d7610..c84631e5 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java @@ -123,9 +123,16 @@ public void run() { commands.add(gldSimulatorPath); // commands.add(simulationFile.getAbsolutePath()); commands.add(gldStartupFile.getAbsolutePath()); - simulatorBuilder.command(commands); - - + ProcessBuilder gldSimulatorBuilder = new ProcessBuilder(); + gldSimulatorBuilder.command(commands); + gldSimulatorBuilder.redirectErrorStream(true); + gldSimulatorBuilder.redirectOutput(); + //launch from directory containing simulation files + gldSimulatorBuilder.directory(simulationFile.getParentFile()); + logManager.info(ProcessStatus.RUNNING, simulationId, "Starting gridlabd simulator with command "+String.join(" ",commands)); + simulatorProcess = gldSimulatorBuilder.start(); + // Watch the process + watch(simulatorProcess, "GLDSimulator-"+simulationId); //Start ochre commands = new ArrayList(); From ed3b5451181f7a721378fa7a92b88d82af279d93 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Mon, 14 Jun 2021 14:20:35 -0700 Subject: [PATCH 11/29] Made changes to put gld_helics_config in the correct location and more detailed logging when simulator starts up --- .../configuration/OchreAllConfigurationHandler.java | 5 ++++- .../goss/gridappsd/process/ProcessNewSimulationRequest.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java index 776a5d7b..988780f5 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java @@ -157,7 +157,10 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces CONFIG_FILENAME+" "+ simulationBrokerPort+" "+ processId); - }catch(Exception e){ + + RunCommandLine.runCommand("cp /gridappsd/services/gridappsd-ochre/inputs/gridlabd/IEEE-13/gld_helics_config.json "+tempDataPath); + + }catch(Exception e){ log.warn("Could not create OCHRE HELICS config file"); } diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java index e196a814..ade6a1b1 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java @@ -233,12 +233,14 @@ else if(simRequest.getSimulation_config().getSimulator().equals("OCHRE")) List connectServiceInstanceIds = new ArrayList(); List connectServiceIds = new ArrayList(); List connectedAppInstanceIds = new ArrayList(); - + logManager.info(ProcessStatus.RUNNING, simulationId, "Service configs "+simRequest.service_configs); if (simRequest.service_configs == null) { logManager.warn(ProcessStatus.RUNNING, simulationId, "No services found in request ="+simRequest.getSimulation_config().getSimulator()); } else{ for(ServiceConfig serviceConfig : simRequest.service_configs){ + logManager.info(ProcessStatus.RUNNING, simulationId, "Starting service"+serviceConfig.getId()); + String serviceInstanceId = serviceManager.startServiceForSimultion(serviceConfig.getId(), null, simulationContext); if(serviceInstanceId!=null){ connectServiceInstanceIds.add(serviceInstanceId); From 06ca481b333829a75fdc816895753e2116e83ef7 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Mon, 14 Jun 2021 15:00:00 -0700 Subject: [PATCH 12/29] Adding service logging --- .../gov/pnnl/goss/gridappsd/service/ServiceManagerImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/service/ServiceManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/service/ServiceManagerImpl.java index b3875fe2..dc6a71c6 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/service/ServiceManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/service/ServiceManagerImpl.java @@ -241,6 +241,9 @@ public String startServiceForSimultion(String serviceId, HashMap String simulationId = simulationContext.get("simulationId").toString(); String instanceId = serviceId+"-"+new Date().getTime(); + + logManager.info(ProcessStatus.RUNNING, simulationId, "Calling start service: "+instanceId); + // get execution path ServiceInfo serviceInfo = services.get(serviceId); if(serviceInfo==null){ @@ -378,7 +381,8 @@ public String startServiceForSimultion(String serviceId, HashMap //add to service instances map serviceInstances.put(instanceId, serviceInstance); - + logManager.info(ProcessStatus.RUNNING, simulationId, "Started service: "+instanceId); + watch(serviceInstance, simulationId); return instanceId; From 35749e90792b6466d11b8bededadb9e92011f700 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Mon, 14 Jun 2021 15:04:00 -0700 Subject: [PATCH 13/29] copy the correct file --- .../gridappsd/configuration/OchreAllConfigurationHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java index 988780f5..2e578421 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java @@ -158,7 +158,7 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces simulationBrokerPort+" "+ processId); - RunCommandLine.runCommand("cp /gridappsd/services/gridappsd-ochre/inputs/gridlabd/IEEE-13/gld_helics_config.json "+tempDataPath); + RunCommandLine.runCommand("cp "+tempDataPath+"/inputs/gridlabd/IEEE-13/gld_helics_config.json "+tempDataPath); }catch(Exception e){ log.warn("Could not create OCHRE HELICS config file"); From dc58bc2f1788fd6418f9134791c935ea2aee7821 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Fri, 25 Jun 2021 16:03:22 -0700 Subject: [PATCH 14/29] Added debuging and made federate count configurable --- Dockerfile | 1 - .../gov/pnnl/goss/gridappsd/dto/SimulationContext.java | 9 +++++++++ .../pnnl/goss/gridappsd/service/ServiceManagerImpl.java | 4 ++-- .../goss/gridappsd/simulation/SimulationProcess.java | 9 ++++++++- services/helics.config | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index fa3fa100..f2ad234b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -98,7 +98,6 @@ 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 diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/SimulationContext.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/SimulationContext.java index afa65f6c..a4990d66 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/SimulationContext.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/SimulationContext.java @@ -18,6 +18,7 @@ public class SimulationContext implements Serializable { public List appInstanceIds; public List serviceInstanceIds; public String simulationUser; + public int numFederates = 2; public String getSimulationId() { return simulationId; @@ -103,6 +104,14 @@ public void setSimulationUser(String simulationUser) { this.simulationUser = simulationUser; } + public int getNumFederates() { + return numFederates; + } + + public void setNumFederates(int numFederates) { + this.numFederates = numFederates; + } + } diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/service/ServiceManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/service/ServiceManagerImpl.java index dc6a71c6..27640fca 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/service/ServiceManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/service/ServiceManagerImpl.java @@ -333,7 +333,7 @@ public String startServiceForSimultion(String serviceId, HashMap processServiceBuilder.directory(serviceDirectory); processServiceBuilder.redirectErrorStream(true); processServiceBuilder.redirectOutput(); - logManager.debug(ProcessStatus.RUNNING, simulationId, "Starting service with command "+ String.join(" ",commands)); + logManager.info(ProcessStatus.RUNNING, simulationId, "Starting service with command "+ String.join(" ",commands)); process = processServiceBuilder.start(); } else if(serviceInfo.getType().equals(ServiceType.JAVA)){ @@ -344,7 +344,7 @@ public String startServiceForSimultion(String serviceId, HashMap processServiceBuilder.directory(serviceDirectory); processServiceBuilder.redirectErrorStream(true); processServiceBuilder.redirectOutput(); - logManager.debug(ProcessStatus.RUNNING, simulationId, "Starting service with command "+ String.join(" ",commands)); + logManager.info(ProcessStatus.RUNNING, simulationId, "Starting service with command "+ String.join(" ",commands)); process = processServiceBuilder.start(); diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java index c84631e5..043954a4 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java @@ -115,6 +115,9 @@ public void run() { List commands = new ArrayList(); if(simulationConfig.getSimulator().equals(OchreAllConfigurationHandler.TYPENAME)){ + simContext.setNumFederates(42); + logManager.info(ProcessStatus.RUNNING, simulationId, "Setting num federates "); + //Start gridlabd // simulationContext.put("simulationFile",tempDataPathDir.getAbsolutePath()+File.separator+"model_startup.glm"); File gldStartupFile = new File(simContext.simulationDir+File.separator+"inputs"+File.separator+"gridlabd"+File.separator+"IEEE-13"+File.separator+"IEEE-13_Houses.glm"); @@ -154,6 +157,8 @@ public void run() { } } simulatorBuilder.command(commands); + logManager.info(ProcessStatus.RUNNING, simulationId, "Command for ochre ready "+String.join(" ",commands)); + } else if(simulationConfig.getSimulator().equals(gridlabdConstant)){ commands.add(simContext.getSimulatorPath()); @@ -168,6 +173,8 @@ else if(simulationConfig.getSimulator().equals(gridlabdConstant)){ simulatorBuilder.directory(simulationFile.getParentFile()); logManager.info(ProcessStatus.RUNNING, simulationId, "Starting simulator with command "+String.join(" ",commands)); simulatorProcess = simulatorBuilder.start(); + logManager.info(ProcessStatus.RUNNING, simulationId, "Started simulator with command "+String.join(" ",commands)); + // Watch the process watch(simulatorProcess, "Simulator-"+simulationId); @@ -303,7 +310,7 @@ public void onMessage(Serializable response) { FncsBridgeResponse responseJson = gson.fromJson(dataResponse.getData().toString(), FncsBridgeResponse.class); //log.debug("FNCS output message: "+responseJson); if("isInitialized".equals(responseJson.command)){ - log.debug("Bridge Initialized response: "+responseJson); + log.info("Bridge Initialized response: "+responseJson); if("True".equals(responseJson.response)){ //log.info("FNCS is initialized "+initializedTracker); initializedTracker.isInited = true; diff --git a/services/helics.config b/services/helics.config index 8c929140..071d5e69 100644 --- a/services/helics.config +++ b/services/helics.config @@ -4,7 +4,7 @@ "creator": "PNNL", "inputs": [], "outputs": [], - "static_args": ["-f","2","--port=(simulationPort)","--loglevel=3"], + "static_args": ["-f","(numFederates)","--port=(simulationPort)","--loglevel=3"], "execution_path": "helics_broker", "type": "EXE", "launch_on_startup": "false", From 77ae398bf7885848004bb4e9558f74c391d49449 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Fri, 25 Jun 2021 16:20:17 -0700 Subject: [PATCH 15/29] Added num federates parameter --- .../goss/gridappsd/process/ProcessNewSimulationRequest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java index ade6a1b1..b4801e57 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java @@ -169,10 +169,12 @@ else if(simRequest.getSimulation_config().getSimulator().equals("OCHRE")) gldInterface = GridAppsDConstants.getGLDInterface(deps); } + int numFederates = 2; String simulator = simRequest.getSimulation_config().getSimulator(); //generate config files for requested simulator //if requested simulator is opendss if(simulator.equalsIgnoreCase(DSSAllConfigurationHandler.CONFIGTARGET)){ + numFederates = 42; Properties simulationParams = generateSimulationParameters(simRequest); simulationParams.put(DSSAllConfigurationHandler.SIMULATIONID, simulationId); simulationParams.put(DSSAllConfigurationHandler.DIRECTORY, tempDataPathDir.getAbsolutePath()); @@ -212,6 +214,8 @@ else if(simulator.equalsIgnoreCase(OchreAllConfigurationHandler.TYPENAME)){ simulationContext.put("simulationHost","127.0.0.1"); simulationContext.put("simulationPort",simulationPort); simulationContext.put("simulationDir",simulationConfigDir); + simulationContext.put("numFederates",numFederates); + if(simRequest.getSimulation_config().getSimulator().equals("GridLAB-D")) simulationContext.put("simulationFile",tempDataPathDir.getAbsolutePath()+File.separator+"model_startup.glm"); else if(simRequest.getSimulation_config().getSimulator().equals("OCHRE")) From 1388e9f51e84737e264687ebaaefd8cad827de89 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Sat, 26 Jun 2021 11:03:53 -0700 Subject: [PATCH 16/29] set numfederates in the wrong location --- .../goss/gridappsd/process/ProcessNewSimulationRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java index b4801e57..e94010b9 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java @@ -174,7 +174,6 @@ else if(simRequest.getSimulation_config().getSimulator().equals("OCHRE")) //generate config files for requested simulator //if requested simulator is opendss if(simulator.equalsIgnoreCase(DSSAllConfigurationHandler.CONFIGTARGET)){ - numFederates = 42; Properties simulationParams = generateSimulationParameters(simRequest); simulationParams.put(DSSAllConfigurationHandler.SIMULATIONID, simulationId); simulationParams.put(DSSAllConfigurationHandler.DIRECTORY, tempDataPathDir.getAbsolutePath()); @@ -184,6 +183,7 @@ else if(simRequest.getSimulation_config().getSimulator().equals("OCHRE")) configurationManager.generateConfiguration(DSSAllConfigurationHandler.TYPENAME, simulationParams, new PrintWriter(new StringWriter()), simulationId, username); } else if(simulator.equalsIgnoreCase(OchreAllConfigurationHandler.TYPENAME)){ + numFederates = 42; Properties simulationParams = generateSimulationParameters(simRequest); simulationParams.put(DSSAllConfigurationHandler.SIMULATIONID, simulationId); simulationParams.put(DSSAllConfigurationHandler.DIRECTORY, tempDataPathDir.getAbsolutePath()); From afe038720591d30d3e26afce3cf88c88f54771e0 Mon Sep 17 00:00:00 2001 From: Tara Date: Tue, 6 Jul 2021 07:15:55 -0700 Subject: [PATCH 17/29] Change the simulation startup timeout --- .../pnnl/goss/gridappsd/simulation/SimulationManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationManagerImpl.java index 2db9cc4f..d8e28fbf 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationManagerImpl.java @@ -80,7 +80,7 @@ public class SimulationManagerImpl implements SimulationManager{ private static Logger log = LoggerFactory.getLogger(SimulationManagerImpl.class); - final static int MAX_INIT_ATTEMPTS = 50; + final static int MAX_INIT_ATTEMPTS = 120; Client client = null; From 18cc9ca4b60cce718f45372dfc440fe1b28d623d Mon Sep 17 00:00:00 2001 From: poorva1209 Date: Wed, 21 Jul 2021 09:20:14 -0700 Subject: [PATCH 18/29] Update ochre.config --- services/ochre.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ochre.config b/services/ochre.config index 71ae5b87..3604dddb 100644 --- a/services/ochre.config +++ b/services/ochre.config @@ -4,7 +4,7 @@ "creator": "NREL", "inputs": [], "outputs": [], - "static_args": ["run", "--path (simulationFile)", "--broker-loglevel=2"], + "static_args": ["run", "--path","(simulationFile)", "--broker-loglevel=2"], "execution_path": "helics", "type": "EXE", "launch_on_startup": "false", From 190f1d58c37479100b134e1d6f8cce358f50564b Mon Sep 17 00:00:00 2001 From: poorva1209 Date: Mon, 26 Jul 2021 17:58:21 -0700 Subject: [PATCH 19/29] used ochre helics config in model start up intead of model output if OCHRe simulator is used --- build-docker.sh | 2 +- .../GLDAllConfigurationHandler.java | 7 +- .../VnomExportConfigurationHandler.java | 498 +++++++++--------- .../pnnl/goss/gridappsd/dto/ServiceInfo.java | 416 +++++++-------- .../process/ProcessNewSimulationRequest.java | 2 + services/ochre.config | 3 +- 6 files changed, 468 insertions(+), 460 deletions(-) diff --git a/build-docker.sh b/build-docker.sh index 5d504d14..67376f99 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -5,4 +5,4 @@ rm -rf gov.pnnl.goss/gridappsd/generated #copy built jar to docker echo "copying run.bnd.jar into container" -docker cp gov.pnnl.goss.gridappsd/generated/distributions/executable/run.bnd.jar gridappsddocker_gridappsd_1:/gridappsd/lib/run.bnd.jar +docker cp gov.pnnl.goss.gridappsd/generated/distributions/executable/run.bnd.jar gridappsd:/gridappsd/lib/run.bnd.jar diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java index 5ab76798..ad3b156b 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java @@ -117,6 +117,7 @@ public class GLDAllConfigurationHandler extends BaseConfigurationHandler impleme public static final String STARTTIME_FILTER = "startTime"; public static final String ENDTIME_FILTER = "endTime"; public static final String MODEL_STATE = "model_state"; + public static final String SIMULATOR = "simulator"; public static final int TIMEFILTER_YEAR = 2013; // public static final String CONFIGTARGET = "glm"; @@ -328,6 +329,7 @@ protected void generateStartupFile(Properties parameters, String tempDataPath, P String gldInterface = GridAppsDConstants.getStringProperty(parameters, GridAppsDConstants.GRIDLABD_INTERFACE, GridAppsDConstants.GRIDLABD_INTERFACE_FNCS); + String simulator = GridAppsDConstants.getStringProperty(parameters, SIMULATOR, null); String simulationBrokerHost = GridAppsDConstants.getStringProperty(parameters, SIMULATIONBROKERHOST, null); if(simulationBrokerHost==null || simulationBrokerHost.trim().length()==0){ @@ -432,7 +434,10 @@ protected void generateStartupFile(Properties parameters, String tempDataPath, P startupFileWriter.println("object helics_msg {"); startupFileWriter.println(" name "+simulationID+";"); startupFileWriter.println(" message_type JSON;"); - startupFileWriter.println(" configure model_outputs.json;"); + if(simulator.equals("GridLAB-D")) + startupFileWriter.println(" configure model_outputs.json;"); + else if(simulator.equals("OCHRE")) + startupFileWriter.println(" configure ochre_helics_config.json;"); startupFileWriter.println("}"); } else { diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/VnomExportConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/VnomExportConfigurationHandler.java index a063721b..3f39f0e1 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/VnomExportConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/VnomExportConfigurationHandler.java @@ -1,249 +1,249 @@ -/******************************************************************************* - * Copyright 2017, Battelle Memorial Institute All rights reserved. - * Battelle Memorial Institute (hereinafter Battelle) hereby grants permission to any person or entity - * lawfully obtaining a copy of this software and associated documentation files (hereinafter the - * Software) to redistribute and use the Software in source and binary forms, with or without modification. - * Such person or entity may use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and may permit others to do so, subject to the following conditions: - * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimers. - * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * Other than as used herein, neither the name Battelle Memorial Institute or Battelle may be used in any - * form whatsoever without the express written consent of Battelle. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * BATTELLE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * General disclaimer for use with OSS licenses - * - * This material was prepared as an account of work sponsored by an agency of the United States Government. - * Neither the United States Government nor the United States Department of Energy, nor Battelle, nor any - * of their employees, nor any jurisdiction or organization that has cooperated in the development of these - * materials, makes any warranty, express or implied, or assumes any legal liability or responsibility for - * the accuracy, completeness, or usefulness or any information, apparatus, product, software, or process - * disclosed, or represents that its use would not infringe privately owned rights. - * - * Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, - * or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United - * States Government or any agency thereof, or Battelle Memorial Institute. The views and opinions of authors expressed - * herein do not necessarily state or reflect those of the United States Government or any agency thereof. - * - * PACIFIC NORTHWEST NATIONAL LABORATORY operated by BATTELLE for the - * UNITED STATES DEPARTMENT OF ENERGY under Contract DE-AC05-76RL01830 - ******************************************************************************/ -package gov.pnnl.goss.gridappsd.configuration; - -import gov.pnnl.goss.gridappsd.api.ConfigurationHandler; -import gov.pnnl.goss.gridappsd.api.ConfigurationManager; -import gov.pnnl.goss.gridappsd.api.DataManager; -import gov.pnnl.goss.gridappsd.api.LogManager; -import gov.pnnl.goss.gridappsd.api.PowergridModelDataManager; -import gov.pnnl.goss.gridappsd.api.SimulationManager; -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.dto.SimulationContext; -import gov.pnnl.goss.gridappsd.dto.YBusExportResponse; -import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants; - -import java.io.File; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Properties; - -import org.apache.felix.dm.annotation.api.Component; -import org.apache.felix.dm.annotation.api.ServiceDependency; -import org.apache.felix.dm.annotation.api.Start; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -@Component -public class VnomExportConfigurationHandler implements ConfigurationHandler { - - private static Logger log = LoggerFactory.getLogger(VnomExportConfigurationHandler.class); - - @ServiceDependency - private volatile ConfigurationManager configManager; - - @ServiceDependency - private volatile SimulationManager simulationManager; - - @ServiceDependency - private volatile DataManager dataManager; - - @ServiceDependency - private volatile PowergridModelDataManager powergridModelManager; - - @ServiceDependency - volatile LogManager logManager; - - public static final String TYPENAME = "Vnom Export"; - public static final String SIMULATIONID = "simulation_id"; - public static final String DIRECTORY = "directory"; - public static final String MODELID = "model_id"; - public static final String ZFRACTION = "z_fraction"; - public static final String IFRACTION = "i_fraction"; - public static final String PFRACTION = "p_fraction"; - public static final String SCHEDULENAME = "schedule_name"; - public static final String LOADSCALINGFACTOR = "load_scaling_factor"; - - public VnomExportConfigurationHandler() { - } - - public VnomExportConfigurationHandler(LogManager logManager) { - - } - - - @Start - public void start(){ - if(configManager!=null) { - configManager.registerConfigurationHandler(TYPENAME, this); - } - else { - //TODO send log message and exception - log.warn("No Config manager avilable for "+getClass()); - } - } - - @Override - public void generateConfig(Properties parameters, PrintWriter out, String processId, String username) throws Exception { - - - String simulationId = parameters.getProperty(SIMULATIONID); - - String modelId = null; - File simulationDir = null; - - if(simulationId!=null) { - - SimulationContext simulationContext = simulationManager.getSimulationContextForId(simulationId); - - - parameters.put("i_fraction", Double.toString(simulationContext.getRequest().getSimulation_config().getModel_creation_config().getiFraction())); - parameters.put("z_fraction", Double.toString(simulationContext.getRequest().getSimulation_config().getModel_creation_config().getzFraction())); - parameters.put("p_fraction", Double.toString(simulationContext.getRequest().getSimulation_config().getModel_creation_config().getpFraction())); - parameters.put("load_scaling_factor", Double.toString(simulationContext.getRequest().getSimulation_config().getModel_creation_config().getLoadScalingFactor())); - parameters.put("schedule_name", simulationContext.getRequest().getSimulation_config().getModel_creation_config().getScheduleName()); - parameters.put("model_id", simulationContext.getRequest().getPower_system_config().getLine_name()); - parameters.put("directory",simulationContext.getSimulationDir()); - parameters.put("simulation_start_time",simulationContext.getRequest().getSimulation_config().getStart_time()); - parameters.put("simulation_duration",simulationContext.getRequest().getSimulation_config().getDuration()); - - simulationDir = new File(simulationContext.getSimulationDir()); - - - - - } - else { - modelId = GridAppsDConstants.getStringProperty(parameters, MODELID, null); - - simulationId = processId; - - if(modelId==null) - throw new Exception("Model Id or simulation Id not provided in request parameters."); - - simulationDir = new File(configManager.getConfigurationProperty(GridAppsDConstants.GRIDAPPSD_TEMP_PATH),"models/"+modelId); - - parameters.put("i_fraction", GridAppsDConstants.getDoubleProperty(parameters, IFRACTION, 0)); - parameters.put("z_fraction", GridAppsDConstants.getDoubleProperty(parameters, ZFRACTION, 0)); - parameters.put("p_fraction", GridAppsDConstants.getDoubleProperty(parameters, PFRACTION, 0)); - parameters.put("load_scaling_factor", GridAppsDConstants.getDoubleProperty(parameters, LOADSCALINGFACTOR, 1)); - parameters.put("schedule_name", GridAppsDConstants.getStringProperty(parameters, SCHEDULENAME, "")); - parameters.put("model_id", modelId); - parameters.put("directory",simulationDir); - - } - - - File commandFile = new File(simulationDir,"opendsscmdInput.txt"); - File dssBaseFile = new File(simulationDir,"model_base.dss"); - - for(Object key: parameters.keySet().toArray()){ - log.debug(key.toString() + " = "+ parameters.getProperty(key.toString())); - } - - logManager.debug(ProcessStatus.RUNNING, simulationId, "Generating DSS base file"); - - //Create DSS base file - PrintWriter basePrintWriter = new PrintWriter(new StringWriter()); - DSSAllConfigurationHandler baseConfigurationHandler = new DSSAllConfigurationHandler(logManager,simulationManager,configManager); - baseConfigurationHandler.generateConfig(parameters, basePrintWriter, simulationId, username); - - if(!dssBaseFile.exists()) - throw new Exception("Error: Could not create DSS base file to export Vnom matrix"); - - logManager.debug(ProcessStatus.RUNNING, simulationId,"Finished generating DSS base file"); - - logManager.debug(ProcessStatus.RUNNING, simulationId,"Generating commands file for opendsscmd"); - - //Create file with commands for opendsscmd - PrintWriter fileWriter = new PrintWriter(commandFile); - fileWriter.println("redirect model_base.dss"); - // transformer winding ratios must be consistent with base voltages for state estimation - // regulators should be at tap 0; in case LDC is active, we can not use a no-load solution - fileWriter.println("batchedit transformer..* wdg=2 tap=1"); - fileWriter.println("batchedit regcontrol..* enabled=false"); - // remove isource injections from the Y matrix - fileWriter.println("batchedit isource..* enabled=false"); - // ensure that the voltage source is set to 1.0 per-unit - fileWriter.println("batchedit vsource..* pu=1.0"); - // remove PC elements from the Y matrix on solve - fileWriter.println("batchedit load..* enabled=false"); - fileWriter.println("batchedit generator..* enabled=false"); - fileWriter.println("batchedit pvsystem..* enabled=false"); - fileWriter.println("batchedit storage..* enabled=false"); - fileWriter.println("batchedit capacitor..* enabled=false"); - // solve the system in unloaded condition with regulator taps locked - fileWriter.println("solve"); - fileWriter.println("export voltages base_voltages.csv"); - fileWriter.flush(); - fileWriter.close(); - - logManager.debug(ProcessStatus.RUNNING, simulationId, "Finished generating commands file for opendsscmd"); - - logManager.debug(ProcessStatus.RUNNING, simulationId, "Generating Y Bus matrix"); - - ProcessBuilder processServiceBuilder = new ProcessBuilder(); - processServiceBuilder.directory(simulationDir); - List commands = new ArrayList(); - commands.add("opendsscmd"); - commands.add(commandFile.getName()); - - processServiceBuilder.command(new ArrayList<>(Arrays.asList("opendsscmd", commandFile.getName()))); - processServiceBuilder.redirectErrorStream(true); - processServiceBuilder.redirectOutput(); - Process process = processServiceBuilder.start(); - process.waitFor(); - - - YBusExportResponse response = new YBusExportResponse(); - - File vnomPath = new File(simulationDir.getAbsolutePath()+File.separator+"base_voltages.csv"); - - response.setVnom(Files.readAllLines(Paths.get(vnomPath.getPath()))); - - logManager.debug(ProcessStatus.RUNNING, simulationId, "Finished generating Vnom export"); - - out.print(response); - - - } - - - -} +/******************************************************************************* + * Copyright 2017, Battelle Memorial Institute All rights reserved. + * Battelle Memorial Institute (hereinafter Battelle) hereby grants permission to any person or entity + * lawfully obtaining a copy of this software and associated documentation files (hereinafter the + * Software) to redistribute and use the Software in source and binary forms, with or without modification. + * Such person or entity may use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and may permit others to do so, subject to the following conditions: + * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimers. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * Other than as used herein, neither the name Battelle Memorial Institute or Battelle may be used in any + * form whatsoever without the express written consent of Battelle. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * BATTELLE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * General disclaimer for use with OSS licenses + * + * This material was prepared as an account of work sponsored by an agency of the United States Government. + * Neither the United States Government nor the United States Department of Energy, nor Battelle, nor any + * of their employees, nor any jurisdiction or organization that has cooperated in the development of these + * materials, makes any warranty, express or implied, or assumes any legal liability or responsibility for + * the accuracy, completeness, or usefulness or any information, apparatus, product, software, or process + * disclosed, or represents that its use would not infringe privately owned rights. + * + * Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, + * or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United + * States Government or any agency thereof, or Battelle Memorial Institute. The views and opinions of authors expressed + * herein do not necessarily state or reflect those of the United States Government or any agency thereof. + * + * PACIFIC NORTHWEST NATIONAL LABORATORY operated by BATTELLE for the + * UNITED STATES DEPARTMENT OF ENERGY under Contract DE-AC05-76RL01830 + ******************************************************************************/ +package gov.pnnl.goss.gridappsd.configuration; + +import gov.pnnl.goss.gridappsd.api.ConfigurationHandler; +import gov.pnnl.goss.gridappsd.api.ConfigurationManager; +import gov.pnnl.goss.gridappsd.api.DataManager; +import gov.pnnl.goss.gridappsd.api.LogManager; +import gov.pnnl.goss.gridappsd.api.PowergridModelDataManager; +import gov.pnnl.goss.gridappsd.api.SimulationManager; +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.dto.SimulationContext; +import gov.pnnl.goss.gridappsd.dto.YBusExportResponse; +import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Properties; + +import org.apache.felix.dm.annotation.api.Component; +import org.apache.felix.dm.annotation.api.ServiceDependency; +import org.apache.felix.dm.annotation.api.Start; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +@Component +public class VnomExportConfigurationHandler implements ConfigurationHandler { + + private static Logger log = LoggerFactory.getLogger(VnomExportConfigurationHandler.class); + + @ServiceDependency + private volatile ConfigurationManager configManager; + + @ServiceDependency + private volatile SimulationManager simulationManager; + + @ServiceDependency + private volatile DataManager dataManager; + + @ServiceDependency + private volatile PowergridModelDataManager powergridModelManager; + + @ServiceDependency + volatile LogManager logManager; + + public static final String TYPENAME = "Vnom Export"; + public static final String SIMULATIONID = "simulation_id"; + public static final String DIRECTORY = "directory"; + public static final String MODELID = "model_id"; + public static final String ZFRACTION = "z_fraction"; + public static final String IFRACTION = "i_fraction"; + public static final String PFRACTION = "p_fraction"; + public static final String SCHEDULENAME = "schedule_name"; + public static final String LOADSCALINGFACTOR = "load_scaling_factor"; + + public VnomExportConfigurationHandler() { + } + + public VnomExportConfigurationHandler(LogManager logManager) { + + } + + + @Start + public void start(){ + if(configManager!=null) { + configManager.registerConfigurationHandler(TYPENAME, this); + } + else { + //TODO send log message and exception + log.warn("No Config manager avilable for "+getClass()); + } + } + + @Override + public void generateConfig(Properties parameters, PrintWriter out, String processId, String username) throws Exception { + + + String simulationId = parameters.getProperty(SIMULATIONID); + + String modelId = null; + File simulationDir = null; + + if(simulationId!=null) { + + SimulationContext simulationContext = simulationManager.getSimulationContextForId(simulationId); + + + parameters.put("i_fraction", Double.toString(simulationContext.getRequest().getSimulation_config().getModel_creation_config().getiFraction())); + parameters.put("z_fraction", Double.toString(simulationContext.getRequest().getSimulation_config().getModel_creation_config().getzFraction())); + parameters.put("p_fraction", Double.toString(simulationContext.getRequest().getSimulation_config().getModel_creation_config().getpFraction())); + parameters.put("load_scaling_factor", Double.toString(simulationContext.getRequest().getSimulation_config().getModel_creation_config().getLoadScalingFactor())); + parameters.put("schedule_name", simulationContext.getRequest().getSimulation_config().getModel_creation_config().getScheduleName()); + parameters.put("model_id", simulationContext.getRequest().getPower_system_config().getLine_name()); + parameters.put("directory",simulationContext.getSimulationDir()); + parameters.put("simulation_start_time",simulationContext.getRequest().getSimulation_config().getStart_time()); + parameters.put("simulation_duration",simulationContext.getRequest().getSimulation_config().getDuration()); + + simulationDir = new File(simulationContext.getSimulationDir()); + + + + + } + else { + modelId = GridAppsDConstants.getStringProperty(parameters, MODELID, null); + + simulationId = processId; + + if(modelId==null) + throw new Exception("Model Id or simulation Id not provided in request parameters."); + + simulationDir = new File(configManager.getConfigurationProperty(GridAppsDConstants.GRIDAPPSD_TEMP_PATH),"models/"+modelId); + + parameters.put("i_fraction", GridAppsDConstants.getDoubleProperty(parameters, IFRACTION, 0)); + parameters.put("z_fraction", GridAppsDConstants.getDoubleProperty(parameters, ZFRACTION, 0)); + parameters.put("p_fraction", GridAppsDConstants.getDoubleProperty(parameters, PFRACTION, 0)); + parameters.put("load_scaling_factor", GridAppsDConstants.getDoubleProperty(parameters, LOADSCALINGFACTOR, 1)); + parameters.put("schedule_name", GridAppsDConstants.getStringProperty(parameters, SCHEDULENAME, "")); + parameters.put("model_id", modelId); + parameters.put("directory",simulationDir); + + } + + + File commandFile = new File(simulationDir,"opendsscmdInput.txt"); + File dssBaseFile = new File(simulationDir,"model_base.dss"); + + for(Object key: parameters.keySet().toArray()){ + log.debug(key.toString() + " = "+ parameters.getProperty(key.toString())); + } + + logManager.debug(ProcessStatus.RUNNING, simulationId, "Generating DSS base file"); + + //Create DSS base file + PrintWriter basePrintWriter = new PrintWriter(new StringWriter()); + DSSAllConfigurationHandler baseConfigurationHandler = new DSSAllConfigurationHandler(logManager,simulationManager,configManager); + baseConfigurationHandler.generateConfig(parameters, basePrintWriter, simulationId, username); + + if(!dssBaseFile.exists()) + throw new Exception("Error: Could not create DSS base file to export Vnom matrix"); + + logManager.debug(ProcessStatus.RUNNING, simulationId,"Finished generating DSS base file"); + + logManager.debug(ProcessStatus.RUNNING, simulationId,"Generating commands file for opendsscmd"); + + //Create file with commands for opendsscmd + PrintWriter fileWriter = new PrintWriter(commandFile); + fileWriter.println("redirect model_base.dss"); + // transformer winding ratios must be consistent with base voltages for state estimation + // regulators should be at tap 0; in case LDC is active, we can not use a no-load solution + fileWriter.println("batchedit transformer..* wdg=2 tap=1"); + fileWriter.println("batchedit regcontrol..* enabled=false"); + // remove isource injections from the Y matrix + fileWriter.println("batchedit isource..* enabled=false"); + // ensure that the voltage source is set to 1.0 per-unit + fileWriter.println("batchedit vsource..* pu=1.0"); + // remove PC elements from the Y matrix on solve + fileWriter.println("batchedit load..* enabled=false"); + fileWriter.println("batchedit generator..* enabled=false"); + fileWriter.println("batchedit pvsystem..* enabled=false"); + fileWriter.println("batchedit storage..* enabled=false"); + fileWriter.println("batchedit capacitor..* enabled=false"); + // solve the system in unloaded condition with regulator taps locked + fileWriter.println("solve"); + fileWriter.println("export voltages base_voltages.csv"); + fileWriter.flush(); + fileWriter.close(); + + logManager.debug(ProcessStatus.RUNNING, simulationId, "Finished generating commands file for opendsscmd"); + + logManager.debug(ProcessStatus.RUNNING, simulationId, "Generating Y Bus matrix"); + + ProcessBuilder processServiceBuilder = new ProcessBuilder(); + processServiceBuilder.directory(simulationDir); + List commands = new ArrayList(); + commands.add("opendsscmd"); + commands.add(commandFile.getName()); + + processServiceBuilder.command(new ArrayList<>(Arrays.asList("opendsscmd", commandFile.getName()))); + processServiceBuilder.redirectErrorStream(true); + processServiceBuilder.redirectOutput(); + Process process = processServiceBuilder.start(); + process.waitFor(); + + + YBusExportResponse response = new YBusExportResponse(); + + File vnomPath = new File(simulationDir.getAbsolutePath()+File.separator+"base_voltages.csv"); + + response.setVnom(Files.readAllLines(Paths.get(vnomPath.getPath()))); + + logManager.debug(ProcessStatus.RUNNING, simulationId, "Finished generating Vnom export"); + + out.print(response); + + + } + + + +} diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/ServiceInfo.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/ServiceInfo.java index c886fe0a..f9be190a 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/ServiceInfo.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/ServiceInfo.java @@ -1,208 +1,208 @@ -/******************************************************************************* - * Copyright (c) 2017, Battelle Memorial Institute All rights reserved. - * Battelle Memorial Institute (hereinafter Battelle) hereby grants permission to any person or entity - * lawfully obtaining a copy of this software and associated documentation files (hereinafter the - * Software) to redistribute and use the Software in source and binary forms, with or without modification. - * Such person or entity may use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and may permit others to do so, subject to the following conditions: - * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimers. - * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * Other than as used herein, neither the name Battelle Memorial Institute or Battelle may be used in any - * form whatsoever without the express written consent of Battelle. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * BATTELLE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * General disclaimer for use with OSS licenses - * - * This material was prepared as an account of work sponsored by an agency of the United States Government. - * Neither the United States Government nor the United States Department of Energy, nor Battelle, nor any - * of their employees, nor any jurisdiction or organization that has cooperated in the development of these - * materials, makes any warranty, express or implied, or assumes any legal liability or responsibility for - * the accuracy, completeness, or usefulness or any information, apparatus, product, software, or process - * disclosed, or represents that its use would not infringe privately owned rights. - * - * Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, - * or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United - * States Government or any agency thereof, or Battelle Memorial Institute. The views and opinions of authors expressed - * herein do not necessarily state or reflect those of the United States Government or any agency thereof. - * - * PACIFIC NORTHWEST NATIONAL LABORATORY operated by BATTELLE for the - * UNITED STATES DEPARTMENT OF ENERGY under Contract DE-AC05-76RL01830 - ******************************************************************************/ -package gov.pnnl.goss.gridappsd.dto; - - -import java.io.File; -import java.io.IOException; -import java.io.Serializable; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.List; - -import com.google.gson.Gson; -import com.google.gson.JsonSyntaxException; - -public class ServiceInfo implements Serializable { - - public enum ServiceType { - PYTHON, JAVA, WEB, EXE - } - - public enum ServiceCategory { - SIMULATOR, COSIMULATOR, SERVICE - } - - - String id; - String description; - String creator; - List input_topics; - List output_topics; - List static_args; - String execution_path; - HashMap user_input; - ServiceType type; - boolean launch_on_startup; - List service_dependencies; - boolean multiple_instances; - List environmentVariables; - ServiceCategory category = ServiceCategory.SERVICE; - - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getCreator() { - return creator; - } - - public void setCreator(String creator) { - this.creator = creator; - } - - public List getInput_topics() { - return input_topics; - } - - public void setInput_topics(List input_topics) { - this.input_topics = input_topics; - } - - public List getOutput_topics() { - return output_topics; - } - - public void setOutput_topics(List output_topics) { - this.output_topics = output_topics; - } - - public List getStatic_args() { - return static_args; - } - - public void setStatic_args(List static_args) { - this.static_args = static_args; - } - - public String getExecution_path() { - return execution_path; - } - - public void setExecution_path(String execution_path) { - this.execution_path = execution_path; - } - - - - public ServiceType getType() { - return type; - } - - public void setType(ServiceType type) { - this.type = type; - } - - public boolean isLaunch_on_startup() { - return launch_on_startup; - } - - public void setLaunch_on_startup(boolean launch_on_startup) { - this.launch_on_startup = launch_on_startup; - } - - public List getService_dependencies() { - return service_dependencies; - } - - public void setService_dependencies(List service_dependencies) { - this.service_dependencies = service_dependencies; - } - - public boolean isMultiple_instances() { - return multiple_instances; - } - - public void setMultiple_instances(boolean multiple_instances) { - this.multiple_instances = multiple_instances; - } - - public List getEnvironmentVariables() { - return environmentVariables; - } - - public void setEnvironmentVariables(List environmentVariables) { - this.environmentVariables = environmentVariables; - } - - public ServiceCategory getCatagory() { - return category; - } - - public void setCatagory(ServiceCategory catagory) { - this.category = catagory; - } - - @Override - public String toString() { - Gson gson = new Gson(); - return gson.toJson(this); - } - - public static ServiceInfo parse(String jsonString){ - Gson gson = new Gson(); - ServiceInfo obj = gson.fromJson(jsonString, ServiceInfo.class); - if(obj.id==null) - throw new JsonSyntaxException("Expected attribute service_id not found"); - return obj; - } - - public static void main(String[] args) throws IOException{ - - File test = new File("test.config"); - System.out.println(ServiceInfo.parse(new String(Files.readAllBytes(Paths.get(test.getAbsolutePath()))))); - } - -} +/******************************************************************************* + * Copyright (c) 2017, Battelle Memorial Institute All rights reserved. + * Battelle Memorial Institute (hereinafter Battelle) hereby grants permission to any person or entity + * lawfully obtaining a copy of this software and associated documentation files (hereinafter the + * Software) to redistribute and use the Software in source and binary forms, with or without modification. + * Such person or entity may use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and may permit others to do so, subject to the following conditions: + * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimers. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * Other than as used herein, neither the name Battelle Memorial Institute or Battelle may be used in any + * form whatsoever without the express written consent of Battelle. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * BATTELLE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * General disclaimer for use with OSS licenses + * + * This material was prepared as an account of work sponsored by an agency of the United States Government. + * Neither the United States Government nor the United States Department of Energy, nor Battelle, nor any + * of their employees, nor any jurisdiction or organization that has cooperated in the development of these + * materials, makes any warranty, express or implied, or assumes any legal liability or responsibility for + * the accuracy, completeness, or usefulness or any information, apparatus, product, software, or process + * disclosed, or represents that its use would not infringe privately owned rights. + * + * Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, + * or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United + * States Government or any agency thereof, or Battelle Memorial Institute. The views and opinions of authors expressed + * herein do not necessarily state or reflect those of the United States Government or any agency thereof. + * + * PACIFIC NORTHWEST NATIONAL LABORATORY operated by BATTELLE for the + * UNITED STATES DEPARTMENT OF ENERGY under Contract DE-AC05-76RL01830 + ******************************************************************************/ +package gov.pnnl.goss.gridappsd.dto; + + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; + +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; + +public class ServiceInfo implements Serializable { + + public enum ServiceType { + PYTHON, JAVA, WEB, EXE + } + + public enum ServiceCategory { + SIMULATOR, COSIMULATOR, SERVICE + } + + + String id; + String description; + String creator; + List input_topics; + List output_topics; + List static_args; + String execution_path; + HashMap user_input; + ServiceType type; + boolean launch_on_startup; + List service_dependencies; + boolean multiple_instances; + List environmentVariables; + ServiceCategory category = ServiceCategory.SERVICE; + + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public List getInput_topics() { + return input_topics; + } + + public void setInput_topics(List input_topics) { + this.input_topics = input_topics; + } + + public List getOutput_topics() { + return output_topics; + } + + public void setOutput_topics(List output_topics) { + this.output_topics = output_topics; + } + + public List getStatic_args() { + return static_args; + } + + public void setStatic_args(List static_args) { + this.static_args = static_args; + } + + public String getExecution_path() { + return execution_path; + } + + public void setExecution_path(String execution_path) { + this.execution_path = execution_path; + } + + + + public ServiceType getType() { + return type; + } + + public void setType(ServiceType type) { + this.type = type; + } + + public boolean isLaunch_on_startup() { + return launch_on_startup; + } + + public void setLaunch_on_startup(boolean launch_on_startup) { + this.launch_on_startup = launch_on_startup; + } + + public List getService_dependencies() { + return service_dependencies; + } + + public void setService_dependencies(List service_dependencies) { + this.service_dependencies = service_dependencies; + } + + public boolean isMultiple_instances() { + return multiple_instances; + } + + public void setMultiple_instances(boolean multiple_instances) { + this.multiple_instances = multiple_instances; + } + + public List getEnvironmentVariables() { + return environmentVariables; + } + + public void setEnvironmentVariables(List environmentVariables) { + this.environmentVariables = environmentVariables; + } + + public ServiceCategory getCatagory() { + return category; + } + + public void setCatagory(ServiceCategory catagory) { + this.category = catagory; + } + + @Override + public String toString() { + Gson gson = new Gson(); + return gson.toJson(this); + } + + public static ServiceInfo parse(String jsonString){ + Gson gson = new Gson(); + ServiceInfo obj = gson.fromJson(jsonString, ServiceInfo.class); + if(obj.id==null) + throw new JsonSyntaxException("Expected attribute service_id not found"); + return obj; + } + + public static void main(String[] args) throws IOException{ + + File test = new File("../services/ochre.config"); + System.out.println(ServiceInfo.parse(new String(Files.readAllBytes(Paths.get(test.getAbsolutePath()))))); + } + +} diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java index e94010b9..073f138b 100755 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessNewSimulationRequest.java @@ -365,6 +365,8 @@ Properties generateSimulationParameters(RequestSimulation requestSimulation){ Gson gson = new Gson(); params.put(GLDAllConfigurationHandler.MODEL_STATE, gson.toJson(modelConfig.getModel_state())); } + + params.put(GLDAllConfigurationHandler.SIMULATOR, requestSimulation.getSimulation_config().getSimulator()); return params; } diff --git a/services/ochre.config b/services/ochre.config index 71ae5b87..7a41e10c 100644 --- a/services/ochre.config +++ b/services/ochre.config @@ -10,5 +10,6 @@ "launch_on_startup": "false", "service_dependencies": ["helics","helicsgossbridge","gridappsd-alarms","gridappsd-voltage-violation"], "multiple_instances": false, - "environmentVariables":[] + "environmentVariables":[], + "category":"SIMULATOR" } From 1b8177c2be45e816721385a69ad3f30550fd9a23 Mon Sep 17 00:00:00 2001 From: poorva1209 Date: Mon, 26 Jul 2021 19:18:17 -0700 Subject: [PATCH 20/29] used gld_helics_config instead of ochre_helics_config in startup file --- .../gridappsd/configuration/GLDAllConfigurationHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java index ad3b156b..d0d1f1e1 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java @@ -437,7 +437,7 @@ protected void generateStartupFile(Properties parameters, String tempDataPath, P if(simulator.equals("GridLAB-D")) startupFileWriter.println(" configure model_outputs.json;"); else if(simulator.equals("OCHRE")) - startupFileWriter.println(" configure ochre_helics_config.json;"); + startupFileWriter.println(" configure gld_helics_config.json;"); startupFileWriter.println("}"); } else { From e3f60cf631e0fdc963f6f1e63b370859ba0707d6 Mon Sep 17 00:00:00 2001 From: Shiva Poudel Date: Wed, 28 Jul 2021 16:14:13 -0700 Subject: [PATCH 21/29] Updated after testing OCHRE control commands --- .../gridappsd/configuration/GLDAllConfigurationHandler.java | 2 +- services/helicsgossbridge/service/helics_goss_bridge.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java index ad3b156b..d0d1f1e1 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java @@ -437,7 +437,7 @@ protected void generateStartupFile(Properties parameters, String tempDataPath, P if(simulator.equals("GridLAB-D")) startupFileWriter.println(" configure model_outputs.json;"); else if(simulator.equals("OCHRE")) - startupFileWriter.println(" configure ochre_helics_config.json;"); + startupFileWriter.println(" configure gld_helics_config.json;"); startupFileWriter.println("}"); } else { diff --git a/services/helicsgossbridge/service/helics_goss_bridge.py b/services/helicsgossbridge/service/helics_goss_bridge.py index af739342..e7168ff1 100644 --- a/services/helicsgossbridge/service/helics_goss_bridge.py +++ b/services/helicsgossbridge/service/helics_goss_bridge.py @@ -744,7 +744,7 @@ def _publish_to_helics_bus(self, goss_message, command_filter): + f'\ngoss_message = {goss_message}') helics_input_endpoint = helics.helicsFederateGetEndpoint(self._helics_federate, "helics_input") helics_input_message = {f"{self._simulation_id}" : {}} - helics_input_message[f"{self._simulation_id}"]["external_event_handler"] = {} + # helics_input_message[f"{self._simulation_id}"]["external_event_handler"] = {} forward_differences_list = test_goss_message_format["message"]["forward_differences"] reverse_differences_list = test_goss_message_format["message"]["reverse_differences"] fault_list = [] @@ -905,6 +905,7 @@ def _publish_to_helics_bus(self, goss_message, command_filter): fault_val_dict["name"] = x.get("object", "") fault_list.append(fault_val_dict) if len(fault_list) != 0: + helics_input_message[f"{self._simulation_id}"]["external_event_handler"] = {} helics_input_message[f"{self._simulation_id}"]["external_event_handler"]["external_fault_event"] = json.dumps(fault_list) goss_message_converted = json.dumps(helics_input_message, indent=4, sort_keys=True) log.info(f"Sending the following message to the simulator. {goss_message_converted}") From b5970f4967154dd718a4b02e8b8898cb755e3521 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Tue, 3 Aug 2021 21:48:11 -0700 Subject: [PATCH 22/29] Changing queryModel to follow both incoming and outgoing links when building the model --- .../data/BGPowergridModelDataManagerImpl.java | 60 +++++++++++++++---- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/data/BGPowergridModelDataManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/data/BGPowergridModelDataManagerImpl.java index 43c4a5e1..6a129ccf 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/data/BGPowergridModelDataManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/data/BGPowergridModelDataManagerImpl.java @@ -46,6 +46,7 @@ import gov.pnnl.goss.gridappsd.api.LogManager; import gov.pnnl.goss.gridappsd.api.PowergridModelDataManager; import gov.pnnl.goss.gridappsd.data.handlers.BlazegraphQueryHandler; +import gov.pnnl.goss.gridappsd.log.LogManagerImpl; import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants; import pnnl.goss.core.ClientFactory; @@ -54,6 +55,7 @@ public class BGPowergridModelDataManagerImpl implements PowergridModelDataManage final String nsCIM = "http://iec.ch/TC57/CIM100#"; final String nsRDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; final String nsXSD = "http://www.w3.org/2001/XMLSchema#"; + final String feederProperty = "http://iec.ch/TC57/CIM100#Feeder.NormalEnergizingSubstation"; final String RDF_TYPE = nsRDF+"type"; final String RDF_RESOURCE = "rdf:resource"; final String RDF_ID = "rdf:ID"; @@ -135,6 +137,7 @@ public static void main(String[] args){ // BGPowergridModelDataManagerImpl bg = new BGPowergridModelDataManagerImpl("http://localhost:9999/blazegraph/namespace/kb/sparql"); // BGPowergridModelDataManagerImpl bg = new BGPowergridModelDataManagerImpl("http://192.168.99.100:8889/bigdata/namespace/kb/sparql"); BGPowergridModelDataManagerImpl bg = new BGPowergridModelDataManagerImpl("http://localhost:8889/bigdata/namespace/kb/sparql"); + bg.logManager = new LogManagerImpl(); bg.endpointNSURL = "http://localhost:8889/bigdata/namespace/kb/sparql"; try { @@ -145,7 +148,8 @@ public static void main(String[] args){ // System.out.println(bg.queryObjectTypes("_4F76A5F9-271D-9EB8-5E31-AA362D86F2C3", "JSON", "12345", "user")); System.out.println(bg.queryModelNameList("12345", "user")); long start = new Date().getTime(); - String model = bg.queryModel("_4F76A5F9-271D-9EB8-5E31-AA362D86F2C3", "", "", "XML", "12345", "user"); + String model = bg.queryModel("_5B816B93-7A5F-B64C-8460-47C17D6E4B0F", "", "", "XML", "12345", "user"); +// String model = bg.queryModel("_4F76A5F9-271D-9EB8-5E31-AA362D86F2C3", "", "", "XML", "12345", "user"); // String model = bg.queryModel("_503D6E20-F499-4CC7-8051-971E23D0BF79", "", "", "XML", "12345", "user"); @@ -287,10 +291,29 @@ public List queryObjectTypeList(String modelId, String processId, String @Override public String queryModel(String modelId, String objectType, String filter, String resultFormat, String processId, String username) throws Exception { String result = null; - ResultSet rs = queryModelResultSet(modelId, objectType, filter, processId, username, true); + HashSet alreadySeen = new HashSet(); Queue newIds = new PriorityQueue(); List results = new ArrayList(); + BlazegraphQueryHandler queryHandler = new BlazegraphQueryHandler(getEndpointURL(modelId), logManager, processId, username); + String baseUrl = getEndpointNS(null); + + //Add initial ids of incoming links + String intitialIdQuery = "CONSTRUCT {?s ?p ?o} WHERE { { ?s ?p ?o . VALUES ?o { <"+getEndpointNS(modelId)+"> }}}"; + newIds.add(getEndpointNS(modelId)); + ResultSet rs = queryHandler.construct(intitialIdQuery); + while(rs.hasNext()){ + QuerySolution qs = rs.nextSolution(); + String subjectUri = qs.getResource(SUBJECT).getURI(); + String propertyName = qs.getResource(PREDICATE).getURI(); + if (!alreadySeen.contains(subjectUri) && !newIds.contains(subjectUri) && !RDF_TYPE.equals(propertyName) && subjectUri.startsWith(baseUrl)){ + newIds.add(subjectUri); + + + } + } + +// rs = queryModelResultSet(modelId, objectType, filter, processId, username, true); //Tracks which subjects have been seen already and follows links to pull information on those that haven't been included yet while(rs.hasNext() || newIds.size()>0){ @@ -307,7 +330,7 @@ public String queryModel(String modelId, String objectType, String filter, Strin } else { Resource resource = qs.getResource(OBJECT); value = resource.toString(); - if(!alreadySeen.contains(value) && !newIds.contains(value)){ + if(!alreadySeen.contains(value) && !newIds.contains(value) && value.startsWith(baseUrl) && !feederProperty.equals(propertyName)){ newIds.add(value); } } @@ -320,23 +343,40 @@ public String queryModel(String modelId, String objectType, String filter, Strin BGResult r = new BGResult(subject, propertyName, value); results.add(r); } + if(newIds.size()>0){ //build query with new ids - String newIdQuery = "CONSTRUCT {?s ?p ?o} WHERE { "; - + String newOutgoingIdQuery = "CONSTRUCT {?s ?p ?o} WHERE { "; + String newIncomingIdQuery = "CONSTRUCT {?s ?p ?o} WHERE { "; for(int i=0;i<100 && newIds.size()>0; i++){ String id = newIds.poll(); - newIdQuery = newIdQuery+"{ ?s ?p ?o . VALUES ?s { <"+id+"> }} UNION"; + + newOutgoingIdQuery = newOutgoingIdQuery+"{ ?s ?p ?o . VALUES ?s { <"+id+"> }} UNION"; + newIncomingIdQuery = newIncomingIdQuery+"{ ?s ?p ?o . VALUES ?o { <"+id+"> }} UNION"; if(!alreadySeen.contains(id)) { alreadySeen.add(id); } } - newIdQuery = newIdQuery.substring(0,newIdQuery.length()-6); - newIdQuery = newIdQuery+" }"; + newOutgoingIdQuery = newOutgoingIdQuery.substring(0,newOutgoingIdQuery.length()-6); + newOutgoingIdQuery = newOutgoingIdQuery+" }"; + newIncomingIdQuery = newIncomingIdQuery.substring(0,newIncomingIdQuery.length()-6); + newIncomingIdQuery = newIncomingIdQuery+" }"; + + //Get ids for the incoming links + rs = queryHandler.construct(newIncomingIdQuery); + while(rs.hasNext()){ + QuerySolution qs = rs.nextSolution(); + String subjectUri = qs.getResource(SUBJECT).getURI(); + String propertyName = qs.getResource(PREDICATE).getURI(); + + if (!alreadySeen.contains(subjectUri) && !newIds.contains(subjectUri) && !RDF_TYPE.equals(propertyName) && !feederProperty.equals(propertyName) && subjectUri.startsWith(baseUrl)){ + newIds.add(subjectUri); + } + } + - BlazegraphQueryHandler queryHandler = new BlazegraphQueryHandler(getEndpointURL(modelId), logManager, processId, username); - rs = queryHandler.construct(newIdQuery); + rs = queryHandler.construct(newOutgoingIdQuery); From a52aabdf75a31e8913909dd67ca01aedd20e69d6 Mon Sep 17 00:00:00 2001 From: poorva1209 Date: Thu, 12 Aug 2021 04:29:58 -0700 Subject: [PATCH 23/29] passing model id when making ochre config file --- .../OchreAllConfigurationHandler.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java index 2e578421..233e31e1 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/OchreAllConfigurationHandler.java @@ -89,6 +89,7 @@ public class OchreAllConfigurationHandler extends BaseConfigurationHandler imple public static final String CONFIG_FILENAME = "ochre_helics_config.json"; public static final String SIMULATIONBROKERHOST = "simulation_broker_host"; public static final String SIMULATIONBROKERPORT = "simulation_broker_port"; + public static final String MODEL_ID = "model_id"; public OchreAllConfigurationHandler() { } @@ -138,7 +139,13 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces logManager.error(ProcessStatus.ERROR,processId,"No "+SIMULATIONBROKERPORT+" parameter provided"); throw new Exception("Missing parameter "+SIMULATIONBROKERPORT); } - + + String model_id = GridAppsDConstants.getStringProperty(parameters, MODEL_ID, null); + if(model_id==null || model_id.trim().length()==0){ + logManager.error(ProcessStatus.ERROR,processId,"No "+MODEL_ID+" parameter provided"); + throw new Exception("Missing parameter "+MODEL_ID); + } + try{ File tmpDir = new File(tempDataPath); RunCommandLine.runCommand("cp -r /gridappsd/services/gridappsd-ochre/inputs/ "+tempDataPath); @@ -150,13 +157,15 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces tempDataPath+" "+ CONFIG_FILENAME+" "+ simulationBrokerPort+" "+ - processId); + processId+" "+ + model_id); logManager.info(ProcessStatus.RUNNING, processId, "python /gridappsd/services/gridappsd-ochre/bin/make_config_file.py "+ simulationBrokerHost+" "+ tempDataPath+" "+ CONFIG_FILENAME+" "+ simulationBrokerPort+" "+ - processId); + processId+" "+ + model_id); RunCommandLine.runCommand("cp "+tempDataPath+"/inputs/gridlabd/IEEE-13/gld_helics_config.json "+tempDataPath); From 82bc76648a10a1ee28fbc9f4b1c45ba0089fd76d Mon Sep 17 00:00:00 2001 From: afisher1 Date: Wed, 25 Aug 2021 09:24:36 -0700 Subject: [PATCH 24/29] fixes for helics_goss_bridge to recieve ochre output --- .../service/helics_goss_bridge.py | 268 ++++++++---------- 1 file changed, 123 insertions(+), 145 deletions(-) diff --git a/services/helicsgossbridge/service/helics_goss_bridge.py b/services/helicsgossbridge/service/helics_goss_bridge.py index e7168ff1..30065865 100644 --- a/services/helicsgossbridge/service/helics_goss_bridge.py +++ b/services/helicsgossbridge/service/helics_goss_bridge.py @@ -520,7 +520,6 @@ def run_simulation(self): create_db_connection(archive_db_file) message = {} message['command'] = 'nextTimeStep' - measurement_message_count = 0 simulation_run_time_start = time.perf_counter() for current_time in range(simulation_length): if self._stop_simulation == True: @@ -542,20 +541,6 @@ def run_simulation(self): message['output'] = self._get_helics_bus_messages(self._measurement_filter) else: message['output'] = {} - response_msg = json.dumps(message['output'], indent=4, sort_keys=True) - - if message['output']!={}: - measurement_message_count += 1 - log.debug(f"measurement message recieved at timestep {current_time}.") - if not only_archive: - self._gad_connection.send(simulation_output_topic, response_msg) - if archive_db_file: - ts = message['output']['message']['timestamp'] - meas = message['output']['message']['measurements'] - log.debug("Passing timestamp {ts} to write_db_archive".format(ts=ts)) - write_db_archive(ts, meas) - if targz_file: - targz_file.write((response_msg+"\n").encode('utf-8')) if self._simulation_time == self._pause_simulation_at: self._pause_simulation = True log.info('The simulation has paused.') @@ -591,19 +576,6 @@ def run_simulation(self): message['output'] = self._get_helics_bus_messages(self._measurement_filter) else: message['output'] = {} - response_msg = json.dumps(message['output'], indent=4, sort_keys=True) - if message['output']!={}: - measurement_message_count += 1 - log.debug("measurement message received at end of simulation.") - if not only_archive: - self._gad_connection.send(simulation_output_topic, response_msg) - if archive_db_file: - ts = message['output']['message']['timestamp'] - meas = message['output']['message']['measurements'] - log.debug(f"Passing timestamp {ts} to write_db_archive") - write_db_archive(ts, meas) - if targz_file: - targz_file.write((response_msg+"\n").encode('utf-8')) if not self._stop_simulation: if federate_state == 2: helics.helicsFederateFinalize(self._helics_federate) @@ -615,7 +587,6 @@ def run_simulation(self): self._gad_connection.send(self._simulation_manager_input_topic, json.dumps(message)) log.info(f'Simulation {self._simulation_id} has finished.') self._gad_connection.send_simulation_status('COMPLETE', f'Simulation {self._simulation_id} has finished.', 'INFO') - log.debug(f"total measurement messages received {measurement_message_count}") except Exception as e: message_str = f'Error in run simulation {traceback.format_exc()}' log.error(message_str) @@ -744,7 +715,7 @@ def _publish_to_helics_bus(self, goss_message, command_filter): + f'\ngoss_message = {goss_message}') helics_input_endpoint = helics.helicsFederateGetEndpoint(self._helics_federate, "helics_input") helics_input_message = {f"{self._simulation_id}" : {}} - # helics_input_message[f"{self._simulation_id}"]["external_event_handler"] = {} + helics_input_message[f"{self._simulation_id}"]["external_event_handler"] = {} forward_differences_list = test_goss_message_format["message"]["forward_differences"] reverse_differences_list = test_goss_message_format["message"]["reverse_differences"] fault_list = [] @@ -905,7 +876,6 @@ def _publish_to_helics_bus(self, goss_message, command_filter): fault_val_dict["name"] = x.get("object", "") fault_list.append(fault_val_dict) if len(fault_list) != 0: - helics_input_message[f"{self._simulation_id}"]["external_event_handler"] = {} helics_input_message[f"{self._simulation_id}"]["external_event_handler"]["external_fault_event"] = json.dumps(fault_list) goss_message_converted = json.dumps(helics_input_message, indent=4, sort_keys=True) log.info(f"Sending the following message to the simulator. {goss_message_converted}") @@ -955,139 +925,147 @@ def _get_helics_bus_messages(self, measurement_filter): + f'simulation_id = {self._simulation_id}') helics_output_endpoint = helics.helicsFederateGetEndpoint(self._helics_federate, "helics_output") has_message = helics.helicsEndpointHasMessage(helics_output_endpoint) + pending_message_count = helics.helicsEndpointPendingMessagesCount(helics_output_endpoint) if has_message: - message_str = 'helics_output has a message' + message_str = f'helics_output has {pending_message_count} messages' else: message_str = 'helics_output has no messages' log.debug(message_str) self._gad_connection.send_simulation_status('RUNNING', message_str, 'DEBUG') + cim_output = {} if has_message: t_now = datetime.utcnow() + current_time = int(time.mktime(t_now.timetuple())) cim_measurements_dict = { "simulation_id": self._simulation_id, "message" : { - "timestamp" : int(time.mktime(t_now.timetuple())), + "timestamp" : current_time, "measurements" : {} } } helics_message = helics.helicsEndpointGetMessageObject(helics_output_endpoint) - helics_output = helics.helicsMessageGetString(helics_message) - helics_output_dict = json.loads(helics_output) - - sim_dict = helics_output_dict.get(self._simulation_id, None) - if sim_dict != None: - simulation_time = int(sim_dict.get("globals",{}).get("clock", 0)) - if simulation_time != 0: - cim_measurements_dict["message"]["timestamp"] = simulation_time - for x in self._object_property_to_measurement_id.keys(): - objectName = x - gld_properties_dict = sim_dict.get(x,None) - if gld_properties_dict == None: - err_msg = "All measurements for object {} are missing from the simulator output.".format(x) - log.warning(err_msg) - self._gad_connection.send_simulation_status('RUNNING', err_msg, 'WARN') - else: - for y in self._object_property_to_measurement_id.get(x,[]): - measurement = {} - property_name = y["property"] - propertyName = property_name - if y["measurement_mrid"] not in measurement_filter: - measurement["measurement_mrid"] = y["measurement_mrid"] - phases = y["phases"] - conducting_equipment_type_str = y["conducting_equipment_type"] - prop_val_str = gld_properties_dict.get(property_name, None) - propertyValue = prop_val_str - objectType = conducting_equipment_type_str - if prop_val_str == None: - err_msg = f"{property_name} measurement for object {x} is missing from the simulator output." - log.warning(err_msg) - self._gad_connection.send_simulation_status('RUNNING', err_msg, 'WARN') - else: - val_str = str(prop_val_str).split(" ")[0] - conducting_equipment_type = str(conducting_equipment_type_str).split("_")[0] - if conducting_equipment_type == "LinearShuntCompensator": - if property_name in ["voltage_"+phases]: - val = complex(val_str) - (mag,ang_rad) = cmath.polar(val) - ang_deg = math.degrees(ang_rad) - measurement["magnitude"] = mag - measurement["angle"] = ang_deg - elif property_name in ["shunt_"+phases]: - # Need voltage value and switch status to compute the reactive power - prop_val_str = gld_properties_dict.get("voltage_"+phases, None) - val_strVolt = str(prop_val_str).split(" ")[0] - valVolt = complex(val_strVolt) - (magV,ang_radV) = cmath.polar(valVolt) - prop_val_str = gld_properties_dict.get("switch"+phases, None) - val_str_switch = str(prop_val_str).split(" ")[0] - status = 1 - if val_str_switch == "OPEN": - status = 0 - val = complex(val_str) - (mag,ang_rad) = cmath.polar(val) - ang_deg = math.degrees(ang_rad) - measurement["magnitude"] = mag * magV * magV * status - measurement["angle"] = ang_deg - else: - if val_str == "OPEN": - measurement["value"] = 0 + for x in range(pending_message_count): + helics_output = helics.helicsMessageGetString(helics_message) + helics_message_source = helics.helicsMessageGetSource(helics_message) + if "status" in helics_message_source: + ochre_simulation_output_topic = f"/topic/goss.gridappsd.simulation.ochre.output.{self._simulation_id}" + log.debug(f"ochre measurement message recieved at timestep {current_time}.") + self._gad_connection.send(ochre_simulation_output_topic, helics_output) + else: + helics_output_dict = json.loads(helics_output) + + sim_dict = helics_output_dict.get(self._simulation_id, None) + if sim_dict == None: + sim_dict = helics_output_dict + simulation_time = int(sim_dict.get("globals",{}).get("clock", 0)) + if simulation_time != 0: + cim_measurements_dict["message"]["timestamp"] = simulation_time + for x in self._object_property_to_measurement_id.keys(): + objectName = x + gld_properties_dict = sim_dict.get(x,None) + if gld_properties_dict == None: + err_msg = "All measurements for object {} are missing from the simulator output.".format(x) + log.warning(err_msg) + self._gad_connection.send_simulation_status('RUNNING', err_msg, 'WARN') + else: + for y in self._object_property_to_measurement_id.get(x,[]): + measurement = {} + property_name = y["property"] + propertyName = property_name + if y["measurement_mrid"] not in measurement_filter: + measurement["measurement_mrid"] = y["measurement_mrid"] + phases = y["phases"] + conducting_equipment_type_str = y["conducting_equipment_type"] + prop_val_str = gld_properties_dict.get(property_name, None) + propertyValue = prop_val_str + objectType = conducting_equipment_type_str + if prop_val_str == None: + err_msg = f"{property_name} measurement for object {x} is missing from the simulator output." + log.warning(err_msg) + self._gad_connection.send_simulation_status('RUNNING', err_msg, 'WARN') + else: + val_str = str(prop_val_str).split(" ")[0] + conducting_equipment_type = str(conducting_equipment_type_str).split("_")[0] + if conducting_equipment_type == "LinearShuntCompensator": + if property_name in ["voltage_"+phases]: + val = complex(val_str) + (mag,ang_rad) = cmath.polar(val) + ang_deg = math.degrees(ang_rad) + measurement["magnitude"] = mag + measurement["angle"] = ang_deg + elif property_name in ["shunt_"+phases]: + # Need voltage value and switch status to compute the reactive power + prop_val_str = gld_properties_dict.get("voltage_"+phases, None) + val_strVolt = str(prop_val_str).split(" ")[0] + valVolt = complex(val_strVolt) + (magV,ang_radV) = cmath.polar(valVolt) + prop_val_str = gld_properties_dict.get("switch"+phases, None) + val_str_switch = str(prop_val_str).split(" ")[0] + status = 1 + if val_str_switch == "OPEN": + status = 0 + val = complex(val_str) + (mag,ang_rad) = cmath.polar(val) + ang_deg = math.degrees(ang_rad) + measurement["magnitude"] = mag * magV * magV * status + measurement["angle"] = ang_deg else: - measurement["value"] = 1 - elif conducting_equipment_type == "PowerTransformer": - if property_name in ["power_in_"+phases,"voltage_"+phases,"current_in_"+phases]: - val = complex(val_str) - (mag,ang_rad) = cmath.polar(val) - ang_deg = math.degrees(ang_rad) - measurement["magnitude"] = mag - measurement["angle"] = ang_deg - else: - measurement["value"] = int(val_str) - elif conducting_equipment_type in ["ACLineSegment","EnergyConsumer","PowerElectronicsConnection","SynchronousMachine"]: - if property_name == "state_of_charge": - measurement["value"] = float(val_str)*100.0 - else: - val = complex(val_str) - (mag,ang_rad) = cmath.polar(val) - ang_deg = math.degrees(ang_rad) - measurement["magnitude"] = mag - measurement["angle"] = ang_deg - elif conducting_equipment_type in ["LoadBreakSwitch", "Recloser", "Breaker"]: - if property_name in ["power_in_"+phases,"voltage_"+phases,"current_in_"+phases]: - val = complex(val_str) - (mag,ang_rad) = cmath.polar(val) - ang_deg = math.degrees(ang_rad) - measurement["magnitude"] = mag - measurement["angle"] = ang_deg - else: - if val_str == "OPEN": - measurement["value"] = 0 + if val_str == "OPEN": + measurement["value"] = 0 + else: + measurement["value"] = 1 + elif conducting_equipment_type == "PowerTransformer": + if property_name in ["power_in_"+phases,"voltage_"+phases,"current_in_"+phases]: + val = complex(val_str) + (mag,ang_rad) = cmath.polar(val) + ang_deg = math.degrees(ang_rad) + measurement["magnitude"] = mag + measurement["angle"] = ang_deg + else: + measurement["value"] = int(val_str) + elif conducting_equipment_type in ["ACLineSegment","EnergyConsumer","PowerElectronicsConnection","SynchronousMachine"]: + if property_name == "state_of_charge": + measurement["value"] = float(val_str)*100.0 + else: + val = complex(val_str) + (mag,ang_rad) = cmath.polar(val) + ang_deg = math.degrees(ang_rad) + measurement["magnitude"] = mag + measurement["angle"] = ang_deg + elif conducting_equipment_type in ["LoadBreakSwitch", "Recloser", "Breaker"]: + if property_name in ["power_in_"+phases,"voltage_"+phases,"current_in_"+phases]: + val = complex(val_str) + (mag,ang_rad) = cmath.polar(val) + ang_deg = math.degrees(ang_rad) + measurement["magnitude"] = mag + measurement["angle"] = ang_deg else: - measurement["value"] = 1 - elif conducting_equipment_type == "RatioTapChanger": - if property_name in ["power_in_"+phases,"voltage_"+phases,"current_in_"+phases]: - val = complex(val_str) - (mag,ang_rad) = cmath.polar(val) - ang_deg = math.degrees(ang_rad) - measurement["magnitude"] = mag - measurement["angle"] = ang_deg + if val_str == "OPEN": + measurement["value"] = 0 + else: + measurement["value"] = 1 + elif conducting_equipment_type == "RatioTapChanger": + if property_name in ["power_in_"+phases,"voltage_"+phases,"current_in_"+phases]: + val = complex(val_str) + (mag,ang_rad) = cmath.polar(val) + ang_deg = math.degrees(ang_rad) + measurement["magnitude"] = mag + measurement["angle"] = ang_deg + else: + measurement["value"] = int(val_str) else: - measurement["value"] = int(val_str) - else: - log.warning(f"{conducting_equipment_type} is not a recognized conducting equipment type.") - self._gad_connection.send_simulation_status('RUNNING', conducting_equipment_type+" not recognized", 'WARN') - raise RuntimeError(f"{conducting_equipment_type} is not a recognized conducting equipment type.") - # Should it raise runtime? - # change to be a dictionary rather than an array - cim_measurements_dict['message']["measurements"][measurement["measurement_mrid"]] = measurement - cim_output = cim_measurements_dict - else: - err_msg = "The message recieved from the simulator did not have the simulation id as a key in the json message." - log.error(err_msg) - self._gad_connection.send_simulation_status('ERROR', err_msg, 'ERROR') - raise RuntimeError(err_msg) + log.warning(f"{conducting_equipment_type} is not a recognized conducting equipment type.") + self._gad_connection.send_simulation_status('RUNNING', conducting_equipment_type+" not recognized", 'WARN') + raise RuntimeError(f"{conducting_equipment_type} is not a recognized conducting equipment type.") + # Should it raise runtime? + # change to be a dictionary rather than an array + cim_measurements_dict['message']["measurements"][measurement["measurement_mrid"]] = measurement + cim_output = cim_measurements_dict + log.debug(f"measurement message recieved at timestep {current_time}.") + self._gad_connection.send(topics.simulation_output_topic(self._simulation_id), json.dumps(cim_output, indent=4, sort_keys=True)) log.debug(f"Message from simulation processing time: {time.perf_counter() - get_helics_bus_messages_start}.") - return cim_output + return {} except ValueError as ve: raise RuntimeError(f"{str(ve)}.\nObject Name: {objectName}\nObject Type: {objectType}\nProperty Name: {propertyName}\n Property Value{propertyValue}") except Exception as e: From 346326242a68d294b2733e547c77b8597ee3c406 Mon Sep 17 00:00:00 2001 From: afisher1 Date: Wed, 25 Aug 2021 14:03:42 -0700 Subject: [PATCH 25/29] correcting mix of tab/space error in helics goss bridge --- services/helicsgossbridge/service/helics_goss_bridge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/helicsgossbridge/service/helics_goss_bridge.py b/services/helicsgossbridge/service/helics_goss_bridge.py index 30065865..e5742bde 100644 --- a/services/helicsgossbridge/service/helics_goss_bridge.py +++ b/services/helicsgossbridge/service/helics_goss_bridge.py @@ -936,7 +936,7 @@ def _get_helics_bus_messages(self, measurement_filter): cim_output = {} if has_message: t_now = datetime.utcnow() - current_time = int(time.mktime(t_now.timetuple())) + current_time = int(time.mktime(t_now.timetuple())) cim_measurements_dict = { "simulation_id": self._simulation_id, "message" : { From b743ee034345a683971a1c2baede4a3070e633b9 Mon Sep 17 00:00:00 2001 From: afisher1 Date: Wed, 25 Aug 2021 17:14:47 -0700 Subject: [PATCH 26/29] correcting a bug where helics messages are not being pulled based on the number of messages received --- services/helicsgossbridge/service/helics_goss_bridge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/helicsgossbridge/service/helics_goss_bridge.py b/services/helicsgossbridge/service/helics_goss_bridge.py index e5742bde..00b58f46 100644 --- a/services/helicsgossbridge/service/helics_goss_bridge.py +++ b/services/helicsgossbridge/service/helics_goss_bridge.py @@ -944,8 +944,8 @@ def _get_helics_bus_messages(self, measurement_filter): "measurements" : {} } } - helics_message = helics.helicsEndpointGetMessageObject(helics_output_endpoint) for x in range(pending_message_count): + helics_message = helics.helicsEndpointGetMessageObject(helics_output_endpoint) helics_output = helics.helicsMessageGetString(helics_message) helics_message_source = helics.helicsMessageGetSource(helics_message) if "status" in helics_message_source: From c7b00880cc6f0001494962cd34defd43689d2cba Mon Sep 17 00:00:00 2001 From: afisher1 Date: Thu, 26 Aug 2021 11:09:25 -0700 Subject: [PATCH 27/29] removing unnecessary GridLAB-D federate key when creating GridLAB-D helics message in helics_goss_bridge.py --- .../service/helics_goss_bridge.py | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/services/helicsgossbridge/service/helics_goss_bridge.py b/services/helicsgossbridge/service/helics_goss_bridge.py index 00b58f46..f73b0584 100644 --- a/services/helicsgossbridge/service/helics_goss_bridge.py +++ b/services/helicsgossbridge/service/helics_goss_bridge.py @@ -714,8 +714,8 @@ def _publish_to_helics_bus(self, goss_message, command_filter): 'goss_message is not a json formatted string of a python dictionary.' + f'\ngoss_message = {goss_message}') helics_input_endpoint = helics.helicsFederateGetEndpoint(self._helics_federate, "helics_input") - helics_input_message = {f"{self._simulation_id}" : {}} - helics_input_message[f"{self._simulation_id}"]["external_event_handler"] = {} + helics_input_message = {} + helics_input_message["external_event_handler"] = {} forward_differences_list = test_goss_message_format["message"]["forward_differences"] reverse_differences_list = test_goss_message_format["message"]["reverse_differences"] fault_list = [] @@ -746,84 +746,84 @@ def _publish_to_helics_bus(self, goss_message, command_filter): "object_property_list":object_property_list } raise RuntimeError(f"Forward difference command cannot be parsed correctly one or more of attributes needed was None.\ndifference:{json.dumps(x,indent=4,sort_keys=True)}\nparsed result:{json.dumps(parsed_result,indent=4,sort_keys=True)}") - if (object_name_prefix + object_name) not in helics_input_message[f"{self._simulation_id}"].keys(): - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name] = {} + if (object_name_prefix + object_name) not in helics_input_message.keys(): + helics_input_message[object_name_prefix + object_name] = {} if cim_attribute == "RegulatingControl.mode": val = int(x.get("value")) if val == 0: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0]] = "VOLT" + helics_input_message[object_name_prefix + object_name][object_property_list[0]] = "VOLT" if val == 1: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0]] = "MANUAL" + helics_input_message[object_name_prefix + object_name][object_property_list[0]] = "MANUAL" elif val == 2: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0]] = "VAR" + helics_input_message[object_name_prefix + object_name][object_property_list[0]] = "VAR" elif val == 3: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0]] = "CURRENT" + helics_input_message[object_name_prefix + object_name][object_property_list[0]] = "CURRENT" else: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0]] = "MANUAL" + helics_input_message[object_name_prefix + object_name][object_property_list[0]] = "MANUAL" log.warning("Unsupported capacitor control mode requested. The only supported control modes for capacitors are voltage, VAr, volt/VAr, and current. Setting control mode to MANUAL.") self._gad_connection.send_simulation_status("RUNNING", "Unsupported capacitor control mode requested. The only supported control modes for capacitors are voltage, VAr, volt/VAr, and current. Setting control mode to MANUAL.","WARN") elif cim_attribute == "RegulatingControl.targetDeadband": for y in self._difference_attribute_map[cim_attribute][object_type]["property"]: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][y] = float(x.get("value")) + helics_input_message[object_name_prefix + object_name][y] = float(x.get("value")) elif cim_attribute == "RegulatingControl.targetValue": for y in self._difference_attribute_map[cim_attribute][object_type]["property"]: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][y] = float(x.get("value")) + helics_input_message[object_name_prefix + object_name][y] = float(x.get("value")) elif cim_attribute == "RotatingMachine.p": for y in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format(y)] = float(x.get("value"))/3.0 + helics_input_message[object_name_prefix + object_name][object_property_list[0].format(y)] = float(x.get("value"))/3.0 elif cim_attribute == "RotatingMachine.q": for y in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format(y)] = float(x.get("value"))/3.0 + helics_input_message[object_name_prefix + object_name][object_property_list[0].format(y)] = float(x.get("value"))/3.0 elif cim_attribute == "ShuntCompensator.aVRDelay": for y in self._difference_attribute_map[cim_attribute][object_type]["property"]: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][y] = float(x.get("value")) + helics_input_message[object_name_prefix + object_name][y] = float(x.get("value")) elif cim_attribute == "ShuntCompensator.sections": if int(x.get("value")) == 1: val = "CLOSED" else: val = "OPEN" for y in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format(y)] = f"{val}" + helics_input_message[object_name_prefix + object_name][object_property_list[0].format(y)] = f"{val}" elif cim_attribute == "Switch.open": if int(x.get("value")) == 1: val = "OPEN" else: val = "CLOSED" - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0]] = f"{val}" + helics_input_message[object_name_prefix + object_name][object_property_list[0]] = f"{val}" elif cim_attribute == "TapChanger.initialDelay": for y in object_property_list: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][y] = float(x.get("value")) + helics_input_message[object_name_prefix + object_name][y] = float(x.get("value")) elif cim_attribute == "TapChanger.step": for y in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format(y)] = int(x.get("value")) + helics_input_message[object_name_prefix + object_name][object_property_list[0].format(y)] = int(x.get("value")) elif cim_attribute == "TapChanger.lineDropCompensation": if int(x.get("value")) == 1: val = "LINE_DROP_COMP" else: val = "MANUAL" - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0]] = f"{val}" + helics_input_message[object_name_prefix + object_name][object_property_list[0]] = f"{val}" elif cim_attribute == "TapChanger.lineDropR": for y in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format(y)] = float(x.get("value")) + helics_input_message[object_name_prefix + object_name][object_property_list[0].format(y)] = float(x.get("value")) elif cim_attribute == "TapChanger.lineDropX": for y in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format(y)] = float(x.get("value")) + helics_input_message[object_name_prefix + object_name][object_property_list[0].format(y)] = float(x.get("value")) elif cim_attribute == "PowerElectronicsConnection.p": - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0]] = float(x.get("value")) + helics_input_message[object_name_prefix + object_name][object_property_list[0]] = float(x.get("value")) elif cim_attribute == "PowerElectronicsConnection.q": - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0]] = float(x.get("value")) + helics_input_message[object_name_prefix + object_name][object_property_list[0]] = float(x.get("value")) elif cim_attribute == "EnergyConsumer.p": phase_count = len(object_phases) if "s1" in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format("1")] = float(x.get("value"))/2.0 + helics_input_message[object_name_prefix + object_name][object_property_list[0].format("1")] = float(x.get("value"))/2.0 if "s2" in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format("2")] = float(x.get("value"))/2.0 + helics_input_message[object_name_prefix + object_name][object_property_list[0].format("2")] = float(x.get("value"))/2.0 if "A" in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format("A")] = float(x.get("value"))/phase_count + helics_input_message[object_name_prefix + object_name][object_property_list[0].format("A")] = float(x.get("value"))/phase_count if "B" in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format("B")] = float(x.get("value"))/phase_count + helics_input_message[object_name_prefix + object_name][object_property_list[0].format("B")] = float(x.get("value"))/phase_count if "C" in object_phases: - helics_input_message[f"{self._simulation_id}"][object_name_prefix + object_name][object_property_list[0].format("C")] = float(x.get("value"))/phase_count + helics_input_message[object_name_prefix + object_name][object_property_list[0].format("C")] = float(x.get("value"))/phase_count else: log.warning(f"Attribute, {cim_attribute}, is not a supported attribute in the simulator at this current time. ignoring difference.") @@ -876,11 +876,13 @@ def _publish_to_helics_bus(self, goss_message, command_filter): fault_val_dict["name"] = x.get("object", "") fault_list.append(fault_val_dict) if len(fault_list) != 0: - helics_input_message[f"{self._simulation_id}"]["external_event_handler"]["external_fault_event"] = json.dumps(fault_list) + helics_input_message["external_event_handler"]["external_fault_event"] = json.dumps(fault_list) + if helics_input_message["external_event_handler"] == {}: + del helics_input_message["external_event_handler"] goss_message_converted = json.dumps(helics_input_message, indent=4, sort_keys=True) log.info(f"Sending the following message to the simulator. {goss_message_converted}") self._gad_connection.send_simulation_status("RUNNING", f"Sending the following message to the simulator. {goss_message_converted}","INFO") - if federate_state == 2 and helics_input_message[f"{self._simulation_id}"] != {}: + if federate_state == 2 and helics_input_message != {}: helics_msg = helics.helicsFederateCreateMessageObject(self._helics_federate) helics.helicsMessageSetString(helics_msg, goss_message_converted) helics.helicsEndpointSendMessage(helics_input_endpoint, helics_msg) From 3ad0231ac4d3d64153fb11aad4e7a019a93fd0e1 Mon Sep 17 00:00:00 2001 From: poorva1209 Date: Fri, 27 Aug 2021 10:52:01 -0700 Subject: [PATCH 28/29] added publish_period, using default model_startup if not ieee13ochre --- .../configuration/GLDAllConfigurationHandler.java | 9 ++++++--- .../goss/gridappsd/simulation/SimulationProcess.java | 9 ++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java index d0d1f1e1..368a3499 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/GLDAllConfigurationHandler.java @@ -433,11 +433,14 @@ protected void generateStartupFile(Properties parameters, String tempDataPath, P if(GridAppsDConstants.GRIDLABD_INTERFACE_HELICS.equals(gldInterface)){ startupFileWriter.println("object helics_msg {"); startupFileWriter.println(" name "+simulationID+";"); - startupFileWriter.println(" message_type JSON;"); - if(simulator.equals("GridLAB-D")) + if(simulator.equals("GridLAB-D")){ + startupFileWriter.println(" message_type JSON;"); startupFileWriter.println(" configure model_outputs.json;"); - else if(simulator.equals("OCHRE")) + } + else if(simulator.equals("OCHRE")){ + startupFileWriter.println(" publish_period 3;"); startupFileWriter.println(" configure gld_helics_config.json;"); + } startupFileWriter.println("}"); } else { diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java index 043954a4..599e3842 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/simulation/SimulationProcess.java @@ -10,6 +10,7 @@ import gov.pnnl.goss.gridappsd.dto.ServiceInfo; import gov.pnnl.goss.gridappsd.dto.LogMessage.LogLevel; import gov.pnnl.goss.gridappsd.dto.LogMessage.ProcessStatus; +import gov.pnnl.goss.gridappsd.dto.RequestSimulation; import gov.pnnl.goss.gridappsd.dto.SimulationConfig; import gov.pnnl.goss.gridappsd.dto.SimulationContext; import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants; @@ -120,7 +121,13 @@ public void run() { //Start gridlabd // simulationContext.put("simulationFile",tempDataPathDir.getAbsolutePath()+File.separator+"model_startup.glm"); - File gldStartupFile = new File(simContext.simulationDir+File.separator+"inputs"+File.separator+"gridlabd"+File.separator+"IEEE-13"+File.separator+"IEEE-13_Houses.glm"); + //TODO: Change this hard coded startup files + File gldStartupFile = null; + RequestSimulation simRequest = (RequestSimulation)simContext.getRequest(); + if (simRequest.power_system_config.Line_name.contains("_13AD8E07-3BF9-A4E2-CB8F-C3722F837B62")) + gldStartupFile = new File(simContext.simulationDir+File.separator+"inputs"+File.separator+"gridlabd"+File.separator+"IEEE-13"+File.separator+"IEEE-13_Houses.glm"); + else + gldStartupFile = new File(simContext.getSimulationDir()+File.separator+"model_startup.glm"); String gldSimulatorPath = serviceManager.getService(gridlabdConstant).getExecution_path(); // commands.add(simContext.getSimulatorPath()); commands.add(gldSimulatorPath); From a972534c1850a0e3b9fa18b8f738fffdb6af8470 Mon Sep 17 00:00:00 2001 From: tonya1 Date: Tue, 31 Aug 2021 12:40:48 -0700 Subject: [PATCH 29/29] Update main.yml Docker release tag parsing --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ed65da9d..5968a53b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,6 +58,7 @@ jobs: if: env.DOCKER_IMAGE_NAME != null run: | TAG="${GITHUB_REF#refs/heads/}" + TAG="${TAG#refs/tags/}" TAG="${TAG//\//_}" ORG=`echo "${{ secrets.DOCKER_PROJECT }}" | tr '[:upper:]' '[:lower:]'` ORG="${ORG:-gridappsd}" @@ -81,6 +82,7 @@ jobs: if: env.DOCKER_IMAGE_NAME != null run: | TAG="${GITHUB_REF#refs/heads/}" + TAG="${TAG#refs/tags/}" TAG="${TAG//\//_}" ORG=`echo "${{ secrets.DOCKER_PROJECT }}" | tr '[:upper:]' '[:lower:]'` ORG="${ORG:-gridappsd}"