Skip to content

Commit

Permalink
Merge pull request #1275 from GRIDAPPSD/releases/2020.04.0
Browse files Browse the repository at this point in the history
Release of version 2020.04.0
  • Loading branch information
poorva1209 authored May 5, 2020
2 parents 000f4c7 + 35f18ed commit 239c77a
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gov.pnnl.goss.gridappsd/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
osgi.enroute.base.api,\
org.mockito.mockito-all,\
httpcore,\
blazegraph.cim2glm;version=18.0.1,\
blazegraph.cim2glm;version=18.0.3,\
httpclient,\
com.bigdata.rdf,\
proven-client;version=0.2.3,\
Expand Down
2 changes: 1 addition & 1 deletion gov.pnnl.goss.gridappsd/conf/pnnl.goss.core.server.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# The following are used for the core-client connection.
goss.openwire.uri = tcp://0.0.0.0:61616
goss.stomp.uri = stomp://0.0.0.0:61613
goss.ws.uri = ws://0.0.0.0:61614
goss.ws.uri = ws://0.0.0.0:61614?websocket.maxTextMessageSize=999999
goss.ssl.uri = ssl://0.0.0.0:61443

goss.start.broker = true
Expand Down
2 changes: 1 addition & 1 deletion gov.pnnl.goss.gridappsd/run.bnd.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
httpcore,\
httpclient,\
xml-apis,\
blazegraph.cim2glm;version=18.0.1,\
blazegraph.cim2glm;version=18.0.3,\
org.eclipse.jetty.aggregate.jetty-all-server;version=7.6.9,\
javax.servlet-api,\
com.bigdata.rdf,\
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*******************************************************************************
* 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.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.cim2glm.CIMImporter;
import gov.pnnl.goss.cim2glm.OperationalLimits;
import gov.pnnl.goss.cim2glm.queryhandler.QueryHandler;
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.LogLevel;
import gov.pnnl.goss.gridappsd.dto.SimulationContext;
import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants;
import pnnl.goss.core.Client;


@Component
public class GLDLimitsConfigurationHandler extends BaseConfigurationHandler implements ConfigurationHandler {

private static Logger log = LoggerFactory.getLogger(GLDLimitsConfigurationHandler.class);
Client client = null;

@ServiceDependency
private volatile ConfigurationManager configManager;
@ServiceDependency
private volatile PowergridModelDataManager powergridModelManager;
@ServiceDependency
private volatile SimulationManager simulationManager;
@ServiceDependency
volatile LogManager logManager;
@ServiceDependency
volatile DataManager dataManager;


public static final String TYPENAME = "GridLAB-D Limits";
public static final String RANDOMIZEFRACTIONS = "randomize_zipload_fractions";
public static final String MODELID = "model_id";
public static final String SIMULATIONID = "simulation_id";
public static final String CIM2GLM_PREFIX = "model";
public static final String LIMITS_FILENAME = CIM2GLM_PREFIX+"_limits.json";

public GLDLimitsConfigurationHandler() {
}

public GLDLimitsConfigurationHandler(LogManager logManager, DataManager dataManager) {
this.logManager = logManager;
this.dataManager = dataManager;
}

@Override
@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 {

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+GLDLimitsConfigurationHandler.LIMITS_FILENAME);
//If the config file already has been created for this simulation then return it
if(configFile.exists()){
printFileToOutput(configFile, out);
logRunning("Limits file for simulation "+simulationId+" already exists.", processId, username, logManager);
return;
}
} else {
logRunning("No simulation context found for simulation_id: "+simulationId, processId, username, logManager, LogLevel.WARN);
}
}

logRunning("Generating limits file using parameters: "+parameters, processId, username, logManager);

String modelId = GridAppsDConstants.getStringProperty(parameters, MODELID, null);
if(modelId==null || modelId.trim().length()==0){
logError("No "+MODELID+" parameter provided", processId, username, logManager);
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;
}

QueryHandler queryHandler = new BlazegraphQueryHandler(bgHost, logManager, processId, username);
queryHandler.addFeederSelection(modelId);

//CIM2GLM utility uses
CIMImporter cimImporter = new CIMImporter();

OperationalLimits oLimits = new OperationalLimits();
oLimits.BuildLimitMaps (cimImporter, queryHandler);
out.println("{\"limits\":{");
out.println("\"voltages\":[");
oLimits.VoltageMapToJSON (out);
out.println("],");
out.println("\"currents\":[");
oLimits.CurrentMapToJSON (out);
out.println("]");
out.println("}}");
out.close();

logRunning("Finished generating GridLAB-D limits file.", processId, username, logManager);

}


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

import java.io.IOException;

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

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

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

Expand Down Expand Up @@ -58,8 +63,17 @@ public String toString() {
}

public static RequestTimeseriesData parse(String jsonString){
Gson gson = new Gson();
RequestTimeseriesData obj = gson.fromJson(jsonString, RequestTimeseriesData.class);
ObjectMapper objectMapper = new ObjectMapper();
RequestTimeseriesData obj = null;
try {
obj = objectMapper.readValue(jsonString, RequestTimeseriesData.class);
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if(obj.queryMeasurement.equals("simulation"))
if(obj.queryFilter==null || !obj.queryFilter.containsKey("simulation_id"))
throw new JsonSyntaxException("Expected filter simulation_id not found.");
Expand Down
4 changes: 2 additions & 2 deletions services/fncsgossbridge/service/fncs_goss_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ def _publish_to_fncs_bus(simulation_id, goss_message, command_filter):
elif cim_attribute == "EnergyConsumer.p":
phase_count = len(object_phases)
if "s1" in object_phases:
fncs_input_message["{}".format(simulation_id)][object_name_prefix + object_name][object_property_list[0].format("1")] = float(x.get("value"))/phase_count
fncs_input_message["{}".format(simulation_id)][object_name_prefix + object_name][object_property_list[0].format("1")] = float(x.get("value"))/2.0
if "s2" in object_phases:
fncs_input_message["{}".format(simulation_id)][object_name_prefix + object_name][object_property_list[0].format("2")] = float(x.get("value"))/phase_count
fncs_input_message["{}".format(simulation_id)][object_name_prefix + object_name][object_property_list[0].format("2")] = float(x.get("value"))/2.0
if "A" in object_phases:
fncs_input_message["{}".format(simulation_id)][object_name_prefix + object_name][object_property_list[0].format("A")] = float(x.get("value"))/phase_count
if "B" in object_phases:
Expand Down

0 comments on commit 239c77a

Please sign in to comment.