From 522b82dec97b82356431ca7bf4acdf9ba7ba2fdd Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Thu, 21 Nov 2019 13:18:15 -0800 Subject: [PATCH 1/9] Updates to support latest changes to cim2glm code in version 18.0.0 --- gov.pnnl.goss.gridappsd/bnd.bnd | 2 +- gov.pnnl.goss.gridappsd/run.bnd.bndrun | 2 +- .../configuration/DSSAllConfigurationHandler.java | 2 +- .../configuration/GLDAllConfigurationHandler.java | 2 +- .../gridappsd/data/BGPowergridModelDataManagerImpl.java | 6 +++--- .../gridappsd/data/handlers/BlazegraphQueryHandler.java | 2 +- .../gridappsd/testmanager/TestManagerQueryFactory.java | 8 ++++---- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/bnd.bnd b/gov.pnnl.goss.gridappsd/bnd.bnd index 022c6beb..986b77e7 100644 --- a/gov.pnnl.goss.gridappsd/bnd.bnd +++ b/gov.pnnl.goss.gridappsd/bnd.bnd @@ -29,7 +29,7 @@ osgi.enroute.base.api,\ org.mockito.mockito-all,\ httpcore,\ - blazegraph.cim2glm;version=17.0.0,\ + blazegraph.cim2glm;version=18.0.0,\ httpclient,\ com.bigdata.rdf,\ proven-client;version=0.2.3,\ diff --git a/gov.pnnl.goss.gridappsd/run.bnd.bndrun b/gov.pnnl.goss.gridappsd/run.bnd.bndrun index 56433f1e..8dc7d919 100644 --- a/gov.pnnl.goss.gridappsd/run.bnd.bndrun +++ b/gov.pnnl.goss.gridappsd/run.bnd.bndrun @@ -74,7 +74,7 @@ httpcore,\ httpclient,\ xml-apis,\ - blazegraph.cim2glm;version=17.0.0,\ + blazegraph.cim2glm;version=18.0.0,\ org.eclipse.jetty.aggregate.jetty-all-server;version=7.6.9,\ javax.servlet-api,\ com.bigdata.rdf,\ diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/DSSAllConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/DSSAllConfigurationHandler.java index b8c983b9..e31e8d09 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/DSSAllConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/DSSAllConfigurationHandler.java @@ -228,7 +228,7 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces //CIM2GLM utility uses CIMImporter cimImporter = new CIMImporter(); - cimImporter.start(queryHandler, CONFIGTARGET, fRoot, scheduleName, loadScale, bWantSched, bWantZip, bWantRandomFractions, useHouses, zFraction, iFraction, pFraction, bHaveEventGen, modelState); + cimImporter.start(queryHandler, CONFIGTARGET, fRoot, scheduleName, loadScale, bWantSched, bWantZip, bWantRandomFractions, useHouses, zFraction, iFraction, pFraction, bHaveEventGen, modelState, false); logRunning("Finished generating all DSS configuration files.", processId, username, logManager); 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 52ff2fc4..db4fe1b6 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 @@ -244,7 +244,7 @@ public void generateConfig(Properties parameters, PrintWriter out, String proces //CIM2GLM utility uses CIMImporter cimImporter = new CIMImporter(); - cimImporter.start(queryHandler, CONFIGTARGET, fRoot, scheduleName, loadScale, bWantSched, bWantZip, bWantRandomFractions, useHouses, zFraction, iFraction, pFraction, bHaveEventGen, modelState); + cimImporter.start(queryHandler, CONFIGTARGET, fRoot, scheduleName, loadScale, bWantSched, bWantZip, bWantRandomFractions, useHouses, zFraction, iFraction, pFraction, bHaveEventGen, modelState, false); String tempDataPath = dir.getAbsolutePath(); //If use climate, then generate gridlabd weather data file 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 b0231b6c..d5f5256e 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 @@ -199,7 +199,7 @@ public String query(String modelId, String query, String resultFormat, String pr public ResultSet queryResultSet(String modelId, String query, String processId, String username) { String endpoint = getEndpointURL(modelId); BlazegraphQueryHandler queryHandler = new BlazegraphQueryHandler(endpoint, logManager, processId, username); - return queryHandler.query(query); + return queryHandler.query(query, null); } @@ -231,7 +231,7 @@ public ResultSet queryObjectResultSet(String modelId, String mrid, String proces String query = "select ?property ?value where {<"+getEndpointNS(mrid)+"> ?property ?value}"; BlazegraphQueryHandler queryHandler = new BlazegraphQueryHandler(getEndpointURL(modelId), logManager, processId, username); - ResultSet rs = queryHandler.query(query); + ResultSet rs = queryHandler.query(query, null); return rs; } @@ -251,7 +251,7 @@ public List queryObjectTypeList(String modelId, String processId, String } query = query + "}"; BlazegraphQueryHandler queryHandler = new BlazegraphQueryHandler(getEndpointURL(modelId), logManager, processId, username); - ResultSet rs = queryHandler.query(query); + ResultSet rs = queryHandler.query(query, null); List objectTypes = new ArrayList(); while(rs.hasNext()){ diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/data/handlers/BlazegraphQueryHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/data/handlers/BlazegraphQueryHandler.java index 7d77f70f..666a9615 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/data/handlers/BlazegraphQueryHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/data/handlers/BlazegraphQueryHandler.java @@ -91,7 +91,7 @@ public void setLogManager(LogManager logManager) { this.logManager = logManager; } @Override - public ResultSetCloseable query(String szQuery) { + public ResultSetCloseable query(String szQuery, String szTag) { Query query = QueryFactory.create (Q_PREFIX + szQuery); GridAppsDConstants.logMessage(logManager, this.getClass().getName(), "Executing query "+szQuery, processID, username, LogLevel.DEBUG); diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/testmanager/TestManagerQueryFactory.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/testmanager/TestManagerQueryFactory.java index b5749652..411dfa88 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/testmanager/TestManagerQueryFactory.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/testmanager/TestManagerQueryFactory.java @@ -24,7 +24,7 @@ public String getFeeder() { QueryHandler queryHandler = getQueryHandler(); String lineQuery = "SELECT ?name WHERE { " + "?s r:type c:Feeder. " + "?s c:IdentifiedObject.name ?name} " + "ORDER by ?name"; - ResultSet results = queryHandler.query(lineQuery); + ResultSet results = queryHandler.query(lineQuery, null); String feederName = getResultName(results); return feederName; } @@ -34,7 +34,7 @@ public String getGeographicalRegion() { String geoRegionQuery = "SELECT ?name WHERE { " + "?s r:type c:GeographicalRegion. " + "?s c:IdentifiedObject.name ?name} " + "ORDER by ?name"; - ResultSet results = queryHandler.query(geoRegionQuery); + ResultSet results = queryHandler.query(geoRegionQuery, null); String geoName = getResultName(results); return geoName; } @@ -43,7 +43,7 @@ public String getSubGeographicalRegion() { QueryHandler queryHandler = getQueryHandler(); String subGeoRegionQuery = "SELECT ?name WHERE { " + "?s r:type c:SubGeographicalRegion. " + "?s c:IdentifiedObject.name ?name} " + "ORDER by ?name"; - ResultSet results = queryHandler.query(subGeoRegionQuery); + ResultSet results = queryHandler.query(subGeoRegionQuery, null); String subGeoName = getResultName(results); return subGeoName; } @@ -108,7 +108,7 @@ public void getMeasurements(){ "?s c:Measurement.phases ?phsraw ."+ " {bind(strafter(str(?phsraw),\"PhaseCode.\") as ?phases)}"+ "} ORDER BY ?class ?type ?name"; - ResultSet results = queryHandler.query(query); + ResultSet results = queryHandler.query(query, null); String subGeoName = getResultName(results); System.out.println(subGeoName); } From 97fd2b9de2062ff5234564d668476efb32f2302e Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Wed, 4 Dec 2019 14:53:20 -0800 Subject: [PATCH 2/9] Added queue to config manager, and in ybus config, check to see if dss base file already exists before generating it again. in GLDall config generate both glm and dss configs --- .../ConfigurationManagerImpl.java | 48 +++++++++++++++++-- .../GLDAllConfigurationHandler.java | 3 +- .../YBusExportConfigurationHandler.java | 11 +++-- .../pnnl/goss/gridappsd/dto/RoleRequest.java | 34 +++++++++++++ 4 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/RoleRequest.java diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java index 7fa89fca..afa782d0 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java @@ -44,12 +44,14 @@ import java.util.Date; import java.util.Dictionary; import java.util.HashMap; +import java.util.LinkedList; import java.util.Properties; import org.apache.felix.dm.annotation.api.Component; import org.apache.felix.dm.annotation.api.ConfigurationDependency; import org.apache.felix.dm.annotation.api.ServiceDependency; import org.apache.felix.dm.annotation.api.Start; +import org.apache.jena.sparql.function.library.leviathan.e; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,6 +101,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager{ private HashMap configHandlers = new HashMap(); + LinkedList configQueue = new LinkedList(); + public ConfigurationManagerImpl() { } @@ -167,17 +171,51 @@ public void registerConfigurationHandler(String type, ConfigurationHandler handl @Override public void generateConfiguration(String type, Properties parameters, PrintWriter out, String processId, String username) throws Exception { - if(configHandlers.containsKey(type) && configHandlers.get(type)!=null){ - configHandlers.get(type).generateConfig(parameters, out, processId, username); + //Should process the configuration requests as a queue, if there are already configs in a queue, add it + if(configQueue.size()>0){ + configQueue.add(new Configuration(type, parameters, out, processId, username)); + } else { + //otherwise add the one and begin processing it + configQueue.add(new Configuration(type, parameters, out, processId, username)); + while(configQueue.size()>0){ + processConfiguration(configQueue.pop()); + } + } + + + + } + + + private void processConfiguration(Configuration config) throws Exception{ + if(configHandlers.containsKey(config.type) && configHandlers.get(config.type)!=null){ + configHandlers.get(config.type).generateConfig(config.parameters, config.out, config.processId, config.username); } else { logManager.log( new LogMessage(this.getClass().getName(), new Integer( - processId).toString(), new Date().getTime(), - "No configuration handler registered for '"+type+"'", LogLevel.ERROR, + config.processId).toString(), new Date().getTime(), + "No configuration handler registered for '"+config.type+"'", LogLevel.ERROR, ProcessStatus.ERROR, false), "", GridAppsDConstants.topic_platformLog); - throw new Exception("No configuration handler registered for '"+type+"'"); + throw new Exception("No configuration handler registered for '"+config.type+"'"); } } + private class Configuration{ + private String type; + private Properties parameters; + private PrintWriter out; + private String processId; + private String username; + + public Configuration(String type, Properties parameters, PrintWriter out, String processId, String username){ + this.type = type; + this.parameters = parameters; + this.out = out; + this.processId = processId; + this.username = username; + } + + } + } 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 db4fe1b6..868913d9 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 @@ -119,7 +119,8 @@ public class GLDAllConfigurationHandler extends BaseConfigurationHandler impleme public static final String MODEL_STATE = "model_state"; public static final int TIMEFILTER_YEAR = 2013; - public static final String CONFIGTARGET = "glm"; +// public static final String CONFIGTARGET = "glm"; + public static final String CONFIGTARGET = "both"; //will build files for both glm and dss public static final String CIM2GLM_PREFIX = "model"; public static final String BASE_FILENAME = CIM2GLM_PREFIX+"_base.glm"; diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/YBusExportConfigurationHandler.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/YBusExportConfigurationHandler.java index 4ffcd41b..8533267d 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/YBusExportConfigurationHandler.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/YBusExportConfigurationHandler.java @@ -152,10 +152,13 @@ simulationId, new Date().getTime(), ProcessStatus.RUNNING, true), username, GridAppsDConstants.topic_simulationLog+simulationId); - //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()) { + //Create DSS base file if it doesn't already exist + 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 YBus matrix"); diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/RoleRequest.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/RoleRequest.java new file mode 100644 index 00000000..a367a163 --- /dev/null +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/RoleRequest.java @@ -0,0 +1,34 @@ +package gov.pnnl.goss.gridappsd.dto; + +import java.io.Serializable; +import com.google.gson.Gson; + +public class RoleRequest implements Serializable{ + + private static final long serialVersionUID = -3277794121736133832L; + + + public RoleRequest(){} + + public String user; + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + @Override + public String toString() { + Gson gson = new Gson(); + return gson.toJson(this); + } + + public static RoleRequest parse(String jsonString){ + Gson gson = new Gson(); + RoleRequest obj = gson.fromJson(jsonString, RoleRequest.class); + return obj; + } +} From 10a98a06d591929630e7916126c699da49873cc9 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Thu, 5 Dec 2019 09:50:21 -0800 Subject: [PATCH 3/9] Added debug statement --- .../goss/gridappsd/configuration/ConfigurationManagerImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java index afa782d0..e44f6e63 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java @@ -188,6 +188,8 @@ public void generateConfiguration(String type, Properties parameters, PrintWrite private void processConfiguration(Configuration config) throws Exception{ + + System.out.println("PROCESSING CONFIGURATION "+config.type); if(configHandlers.containsKey(config.type) && configHandlers.get(config.type)!=null){ configHandlers.get(config.type).generateConfig(config.parameters, config.out, config.processId, config.username); } else { From 6dce0429c4b86e010662677d8b2e6a735bb0fb58 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Thu, 5 Dec 2019 11:05:02 -0800 Subject: [PATCH 4/9] Changed how config queue is implmented --- .../ConfigurationManagerImpl.java | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java index e44f6e63..8b87ca8c 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java @@ -51,6 +51,7 @@ import org.apache.felix.dm.annotation.api.ConfigurationDependency; import org.apache.felix.dm.annotation.api.ServiceDependency; import org.apache.felix.dm.annotation.api.Start; +import org.apache.felix.dm.annotation.api.Stop; import org.apache.jena.sparql.function.library.leviathan.e; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,6 +102,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager{ private HashMap configHandlers = new HashMap(); + boolean isRunning = true; + LinkedList configQueue = new LinkedList(); public ConfigurationManagerImpl() { @@ -113,9 +116,31 @@ public ConfigurationManagerImpl(LogManager logManager, DataManager dataManager) @Start - public void start(){ - //TODO send log "Starting configuration manager + public void start() throws InterruptedException{ + while(isRunning){ + System.out.println("CONFIG QUEUE SIZE "+configQueue.size()); + if(configQueue.size()>0){ + try { + Configuration nextConfig = configQueue.pop(); + System.out.println("ABOUT TO PROCESS "+nextConfig.type+" "+configQueue.size()); + processConfiguration(nextConfig); + System.out.println("DONE PROCESSING, QUEUE IS "+configQueue.size()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + Thread.sleep(5000); + + } + + + + } + @Stop + public void stop() { + this.isRunning = false; } @@ -172,15 +197,15 @@ public void registerConfigurationHandler(String type, ConfigurationHandler handl @Override public void generateConfiguration(String type, Properties parameters, PrintWriter out, String processId, String username) throws Exception { //Should process the configuration requests as a queue, if there are already configs in a queue, add it - if(configQueue.size()>0){ - configQueue.add(new Configuration(type, parameters, out, processId, username)); - } else { - //otherwise add the one and begin processing it +// if(configQueue.size()>0){ configQueue.add(new Configuration(type, parameters, out, processId, username)); - while(configQueue.size()>0){ - processConfiguration(configQueue.pop()); - } - } +// } else { +// //otherwise add the one and begin processing it +// configQueue.add(new Configuration(type, parameters, out, processId, username)); +// while(configQueue.size()>0){ +// processConfiguration(configQueue.pop()); +// } +// } From 95a8cf1178fa77981559d1cb7b3965b35ca98ff9 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Thu, 5 Dec 2019 11:13:36 -0800 Subject: [PATCH 5/9] Moved to a thread --- .../ConfigurationManagerImpl.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java index 8b87ca8c..38b33a57 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java @@ -117,26 +117,32 @@ public ConfigurationManagerImpl(LogManager logManager, DataManager dataManager) @Start public void start() throws InterruptedException{ - while(isRunning){ - System.out.println("CONFIG QUEUE SIZE "+configQueue.size()); - if(configQueue.size()>0){ - try { - Configuration nextConfig = configQueue.pop(); - System.out.println("ABOUT TO PROCESS "+nextConfig.type+" "+configQueue.size()); - processConfiguration(nextConfig); - System.out.println("DONE PROCESSING, QUEUE IS "+configQueue.size()); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Thread thread = new Thread(){ + public void run(){ + while(isRunning){ + System.out.println("CONFIG QUEUE SIZE "+configQueue.size()); + if(configQueue.size()>0){ + try { + Configuration nextConfig = configQueue.pop(); + System.out.println("ABOUT TO PROCESS "+nextConfig.type+" "+configQueue.size()); + processConfiguration(nextConfig); + System.out.println("DONE PROCESSING, QUEUE IS "+configQueue.size()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + try { + sleep(5000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } - } - Thread.sleep(5000); - - } - - - - + } + }; + thread.start(); } @Stop public void stop() { From 5aa72d64e42d72b0a70b3a7ac730c69de6c91574 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Thu, 5 Dec 2019 13:21:11 -0800 Subject: [PATCH 6/9] Change how the config is implemented again for the configuration manager --- .../ConfigurationManagerImpl.java | 78 +++++++++++-------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java index 38b33a57..2399bf03 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java @@ -117,37 +117,37 @@ public ConfigurationManagerImpl(LogManager logManager, DataManager dataManager) @Start public void start() throws InterruptedException{ - Thread thread = new Thread(){ - public void run(){ - while(isRunning){ - System.out.println("CONFIG QUEUE SIZE "+configQueue.size()); - if(configQueue.size()>0){ - try { - Configuration nextConfig = configQueue.pop(); - System.out.println("ABOUT TO PROCESS "+nextConfig.type+" "+configQueue.size()); - processConfiguration(nextConfig); - System.out.println("DONE PROCESSING, QUEUE IS "+configQueue.size()); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - try { - sleep(5000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - } - }; - thread.start(); - } - @Stop - public void stop() { - this.isRunning = false; +// Thread thread = new Thread(){ +// public void run(){ +// while(isRunning){ +// System.out.println("CONFIG QUEUE SIZE "+configQueue.size()); +// if(configQueue.size()>0){ +// try { +// Configuration nextConfig = configQueue.pop(); +// System.out.println("ABOUT TO PROCESS "+nextConfig.type+" "+configQueue.size()); +// processConfiguration(nextConfig); +// System.out.println("DONE PROCESSING, QUEUE IS "+configQueue.size()); +// } catch (Exception e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// } +// try { +// sleep(5000); +// } catch (InterruptedException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// +// } +// } +// }; +// thread.start(); } +// @Stop +// public void stop() { +// this.isRunning = false; +// } /** @@ -203,8 +203,24 @@ public void registerConfigurationHandler(String type, ConfigurationHandler handl @Override public void generateConfiguration(String type, Properties parameters, PrintWriter out, String processId, String username) throws Exception { //Should process the configuration requests as a queue, if there are already configs in a queue, add it + + Configuration config = new Configuration(type, parameters, out, processId, username); + configQueue.add(config); + + //Implement a queue so that configurations will be implemented in the order they are received and wait until the previous configs have been + // processed. This will help perfomance on jobs like ybus to make sure the GLD all config has completed before the ybus config starts so that it + // can re-use the config files generated by the GLD all config + Configuration nextConfig = configQueue.peek(); + System.out.println("CHECKING "+nextConfig+" = "+config); + while(nextConfig!=null && !config.equals(nextConfig)){ + Thread.sleep(5000); + nextConfig = configQueue.peek(); + System.out.println("CHECKING "+nextConfig+" = "+config); + } + System.out.println("PROCESSING "+config.type); + processConfiguration(config); // if(configQueue.size()>0){ - configQueue.add(new Configuration(type, parameters, out, processId, username)); + // } else { // //otherwise add the one and begin processing it // configQueue.add(new Configuration(type, parameters, out, processId, username)); From aae4d6f069a7d5e583e47c7ac712288796a1cffa Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Thu, 5 Dec 2019 13:26:15 -0800 Subject: [PATCH 7/9] Added lines I forgot in config manager --- .../goss/gridappsd/configuration/ConfigurationManagerImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java index 2399bf03..e95d4140 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java @@ -213,12 +213,13 @@ public void generateConfiguration(String type, Properties parameters, PrintWrite Configuration nextConfig = configQueue.peek(); System.out.println("CHECKING "+nextConfig+" = "+config); while(nextConfig!=null && !config.equals(nextConfig)){ - Thread.sleep(5000); + Thread.sleep(1000); nextConfig = configQueue.peek(); System.out.println("CHECKING "+nextConfig+" = "+config); } System.out.println("PROCESSING "+config.type); processConfiguration(config); + configQueue.pop(); // if(configQueue.size()>0){ // } else { From e6bae3c47d85b4eb61f93cc1aa805db5bf9d7007 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Thu, 5 Dec 2019 13:40:09 -0800 Subject: [PATCH 8/9] Make sure valid json returned from process event --- .../src/gov/pnnl/goss/gridappsd/process/ProcessEvent.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessEvent.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessEvent.java index 336da403..5d060a7a 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessEvent.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/process/ProcessEvent.java @@ -296,6 +296,10 @@ public void onMessage(Serializable message) { private void sendData(Client client, Destination replyDestination, Serializable data, int processId, String username){ try { + //Make sure it is sending back something in the data field for valid json (or if it is null maybe it should send error response instead???) + if(data==null || data.toString().length()==0){ + data = "{}"; + } String r = "{\"data\":"+data+",\"responseComplete\":true,\"id\":\""+processId+"\"}"; /*DataResponse r = new DataResponse(); r.setData(data); From 5a9c8b885ee5c5213a8fc71b1f67ddc6ad06b3d8 Mon Sep 17 00:00:00 2001 From: Tara Gibson Date: Fri, 6 Dec 2019 11:09:38 -0800 Subject: [PATCH 9/9] Actually I dont' think we need the queue --- .../ConfigurationManagerImpl.java | 105 ++---------------- 1 file changed, 12 insertions(+), 93 deletions(-) diff --git a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java index e95d4140..b8cbd1c7 100644 --- a/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java +++ b/gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/configuration/ConfigurationManagerImpl.java @@ -44,15 +44,12 @@ import java.util.Date; import java.util.Dictionary; import java.util.HashMap; -import java.util.LinkedList; import java.util.Properties; import org.apache.felix.dm.annotation.api.Component; import org.apache.felix.dm.annotation.api.ConfigurationDependency; import org.apache.felix.dm.annotation.api.ServiceDependency; import org.apache.felix.dm.annotation.api.Start; -import org.apache.felix.dm.annotation.api.Stop; -import org.apache.jena.sparql.function.library.leviathan.e; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -102,9 +99,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager{ private HashMap configHandlers = new HashMap(); - boolean isRunning = true; - - LinkedList configQueue = new LinkedList(); public ConfigurationManagerImpl() { } @@ -116,38 +110,10 @@ public ConfigurationManagerImpl(LogManager logManager, DataManager dataManager) @Start - public void start() throws InterruptedException{ -// Thread thread = new Thread(){ -// public void run(){ -// while(isRunning){ -// System.out.println("CONFIG QUEUE SIZE "+configQueue.size()); -// if(configQueue.size()>0){ -// try { -// Configuration nextConfig = configQueue.pop(); -// System.out.println("ABOUT TO PROCESS "+nextConfig.type+" "+configQueue.size()); -// processConfiguration(nextConfig); -// System.out.println("DONE PROCESSING, QUEUE IS "+configQueue.size()); -// } catch (Exception e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// } -// try { -// sleep(5000); -// } catch (InterruptedException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// -// } -// } -// }; -// thread.start(); + public void start(){ + //TODO send log "Starting configuration manager + } -// @Stop -// public void stop() { -// this.isRunning = false; -// } /** @@ -202,70 +168,23 @@ public void registerConfigurationHandler(String type, ConfigurationHandler handl @Override public void generateConfiguration(String type, Properties parameters, PrintWriter out, String processId, String username) throws Exception { - //Should process the configuration requests as a queue, if there are already configs in a queue, add it - - Configuration config = new Configuration(type, parameters, out, processId, username); - configQueue.add(config); - - //Implement a queue so that configurations will be implemented in the order they are received and wait until the previous configs have been - // processed. This will help perfomance on jobs like ybus to make sure the GLD all config has completed before the ybus config starts so that it - // can re-use the config files generated by the GLD all config - Configuration nextConfig = configQueue.peek(); - System.out.println("CHECKING "+nextConfig+" = "+config); - while(nextConfig!=null && !config.equals(nextConfig)){ - Thread.sleep(1000); - nextConfig = configQueue.peek(); - System.out.println("CHECKING "+nextConfig+" = "+config); - } - System.out.println("PROCESSING "+config.type); - processConfiguration(config); - configQueue.pop(); -// if(configQueue.size()>0){ - -// } else { -// //otherwise add the one and begin processing it -// configQueue.add(new Configuration(type, parameters, out, processId, username)); -// while(configQueue.size()>0){ -// processConfiguration(configQueue.pop()); -// } -// } - - - - } - - - private void processConfiguration(Configuration config) throws Exception{ - - System.out.println("PROCESSING CONFIGURATION "+config.type); - if(configHandlers.containsKey(config.type) && configHandlers.get(config.type)!=null){ - configHandlers.get(config.type).generateConfig(config.parameters, config.out, config.processId, config.username); + if(configHandlers.containsKey(type) && configHandlers.get(type)!=null){ + configHandlers.get(type).generateConfig(parameters, out, processId, username); } else { logManager.log( new LogMessage(this.getClass().getName(), new Integer( - config.processId).toString(), new Date().getTime(), - "No configuration handler registered for '"+config.type+"'", LogLevel.ERROR, + processId).toString(), new Date().getTime(), + "No configuration handler registered for '"+type+"'", LogLevel.ERROR, ProcessStatus.ERROR, false), "", GridAppsDConstants.topic_platformLog); - throw new Exception("No configuration handler registered for '"+config.type+"'"); + throw new Exception("No configuration handler registered for '"+type+"'"); } - } - - private class Configuration{ - private String type; - private Properties parameters; - private PrintWriter out; - private String processId; - private String username; - public Configuration(String type, Properties parameters, PrintWriter out, String processId, String username){ - this.type = type; - this.parameters = parameters; - this.out = out; - this.processId = processId; - this.username = username; - } + } + + + }