Skip to content

Commit

Permalink
Merge pull request #1551 from GRIDAPPSD/releases/2021.08.1
Browse files Browse the repository at this point in the history
Releases/2021.08.1
  • Loading branch information
tonya1 authored Aug 31, 2021
2 parents 5dfbf90 + 06ea4a6 commit a5fd96a
Show file tree
Hide file tree
Showing 15 changed files with 1,013 additions and 678 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -431,8 +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;");
startupFileWriter.println(" configure model_outputs.json;");
if(simulator.equals("GridLAB-D")){
startupFileWriter.println(" message_type JSON;");
startupFileWriter.println(" configure model_outputs.json;");
}
else if(simulator.equals("OCHRE")){
startupFileWriter.println(" publish_period 3;");
startupFileWriter.println(" configure gld_helics_config.json;");
}
startupFileWriter.println("}");

} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*******************************************************************************
* 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.goss.gridappsd.utils.RunCommandLine;
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 DIRECTORY = "directory";
public static final String MODELID = "model_id";
public static final String SIMULATIONID = "simulation_id";
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 static final String MODEL_ID = "model_id";

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 OCHRE HELICS config file using parameters: "+parameters);

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 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 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);
}

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);
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+" "+
model_id);
logManager.info(ProcessStatus.RUNNING, processId, "python /gridappsd/services/gridappsd-ochre/bin/make_config_file.py "+
simulationBrokerHost+" "+
tempDataPath+" "+
CONFIG_FILENAME+" "+
simulationBrokerPort+" "+
processId+" "+
model_id);

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");
}

logManager.info(ProcessStatus.RUNNING,processId,"Finished generating OCHRE HELICS config file.");


}



}
Loading

0 comments on commit a5fd96a

Please sign in to comment.