Skip to content

Commit

Permalink
made more changes for log manager and comments for pull request 355
Browse files Browse the repository at this point in the history
  • Loading branch information
poorva1209 committed Nov 30, 2017
1 parent 7871865 commit d5eebe4
Show file tree
Hide file tree
Showing 19 changed files with 309 additions and 193 deletions.
6 changes: 6 additions & 0 deletions applications/.project
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions docs/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>docs</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
8 changes: 4 additions & 4 deletions docs/source/developer_resources/Developing_Apps.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

Supported Application Types
^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Puthon
- Python
- Java (Jar)

Registering Application With Platform
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Platform requires a config file for each application on a particular location in order to register the applications.
Assumptions: GOSS-GridAPPS-D repository (https://github.com/GRIDAPPSD/GOSS-GridAPPS-D.git) is cloned under [ROOT_DIR]

1. Create a [app_name].config file in JSON format with keys and values as described below. where app_name should be unique for the application.

Expand All @@ -27,9 +27,9 @@ Platform requires a config file for each application on a particular location in
"multiple_instances":true|false
}

2. Put [app_name].config file under applications folder in GOSS-GridAPPS-D GitHub repo https://github.com/GRIDAPPSD/GOSS-GridAPPS-D
2. Put [app_name].config file in applications folder under cloned repository location

3. Put your application under applications/[app_name] folder on Gihub as shown below.
3. Put your application under applications/[app_name] folder under cloned repository location as shown below.

::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public interface LogDataManager {
void store (String process_id, long timestamp,
String log_message, LogLevel log_level, ProcessStatus process_status, String username);

void query(String process_id, long timestamp, LogLevel log_level, ProcessStatus process_status, String username);
void query(String process_id, long timestamp, LogLevel log_level, ProcessStatus process_status, String username, String resultTopic, String logTopic);

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public interface LogManager {

void log(LogMessage message, String username);


void get(LogMessage message);
/**
* Implementation of this method should call an implementation of LogDataManager and get the log messages
* from data store based on the not null values in LogMessage object.
*/
void get(LogMessage message, String outputTopics, String LogTopic);

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public synchronized File getSimulationFile(int simulationId, RequestSimulation p

if(resp!=null && (resp instanceof DataResponse) && (((DataResponse)resp).getData())!=null && (((DataResponse)resp).getData() instanceof File)){
//Update simulation status after every step, for example:
statusReporter.reportStatus(GridAppsDConstants.topic_simulationStatus+simulationId, "Simulation files created");
statusReporter.reportStatus(GridAppsDConstants.topic_simulationLog+simulationId, "Simulation files created");
return (File)((DataResponse)resp).getData();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,54 @@
import gov.pnnl.goss.gridappsd.api.LogDataManager;
import gov.pnnl.goss.gridappsd.dto.LogMessage.LogLevel;
import gov.pnnl.goss.gridappsd.dto.LogMessage.ProcessStatus;
import gov.pnnl.goss.gridappsd.utils.GridAppsDConstants;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

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.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;

import pnnl.goss.core.Client;
import pnnl.goss.core.ClientFactory;
import pnnl.goss.core.Client.PROTOCOL;


@Component
public class LogDataManagerMySQL implements LogDataManager {

@ServiceDependency
GridAppsDataSources dataSources;

@ServiceDependency
ClientFactory clientFactory;

private Connection connection;
private PreparedStatement preparedStatement;;
private PreparedStatement preparedStatement;
Client client;

@Start
public void start(){

try {
Credentials credentials = new UsernamePasswordCredentials(
GridAppsDConstants.username, GridAppsDConstants.password);
client = clientFactory.create(PROTOCOL.STOMP,credentials);
connection = dataSources.getDataSourceByKey("gridappsd").getConnection();

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
Expand Down Expand Up @@ -101,9 +121,40 @@ public void store(String process_id, long timestamp,
}

@Override
public void query(String process_id, long timestamp, LogLevel log_level, ProcessStatus process_status, String username) {
// TODO Auto-generated method stub
public void query(String process_id, long timestamp, LogLevel log_level, ProcessStatus process_status, String username, String resultTopic, String logTopic) {

try {
String queryString = "SELECT * FROM gridappsd.log WHERE";
if(process_id!=null)
queryString+=" process_id="+process_id;
if(log_level!=null)
queryString+=" log_level="+log_level;
if(process_status!=null)
queryString+=" process_status="+process_status;
if(username!=null)
queryString+=" username="+username;
if(timestamp!=new Long("OL"))
queryString+=" timestamp="+timestamp;

preparedStatement = connection.prepareStatement(queryString);

ResultSet rs = preparedStatement.executeQuery();

ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();
String rowResult="";

while (rs.next()) {
for(int i = 1; i < columnsNumber; i++)
rowResult = rowResult + " " + rs.getString(i);
client.publish(resultTopic, rowResult);
}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void start(){

@Override
public Response handle(Serializable request, int simulationId, String tempDataPath, StatusReporter statusReporter) throws Exception {
statusReporter.reportStatus(GridAppsDConstants.topic_simulationStatus+simulationId, "Generating GridLABD simulation files");
statusReporter.reportStatus(GridAppsDConstants.topic_simulationLog+simulationId, "Generating GridLABD simulation files");
//TODO check content in the request for validity
if(request instanceof String){
Gson gson = new Gson();
Expand Down Expand Up @@ -258,7 +258,7 @@ public Response handle(Serializable request, int simulationId, String tempDataPa
modelConfig.load_scaling_factor, bWantSched, bWantZip, 0, 0, 0, fXY);

}
statusReporter.reportStatus(GridAppsDConstants.topic_simulationStatus+simulationId, "GridLABD base file generated");
statusReporter.reportStatus(GridAppsDConstants.topic_simulationLog+simulationId, "GridLABD base file generated");
//cleanup rdf file
// rdfFile.delete();

Expand All @@ -284,7 +284,7 @@ public Response handle(Serializable request, int simulationId, String tempDataPa
configFileOut.write(configFileValue.getBytes());
configFileOut.flush();
configFileOut.close();
statusReporter.reportStatus(GridAppsDConstants.topic_simulationStatus+simulationId, "GridLABD output config file generated");
statusReporter.reportStatus(GridAppsDConstants.topic_simulationLog+simulationId, "GridLABD output config file generated");


//generate simulation config startup file
Expand Down Expand Up @@ -357,7 +357,7 @@ public Response handle(Serializable request, int simulationId, String tempDataPa
startupFileWriter.flush();
startupFileWriter.close();

statusReporter.reportStatus(GridAppsDConstants.topic_simulationStatus+simulationId, "GridLABD startup file generated");
statusReporter.reportStatus(GridAppsDConstants.topic_simulationLog+simulationId, "GridLABD startup file generated");


return new DataResponse(startupFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,67 +54,65 @@ public enum ProcessStatus {
STARTING, STARTED, RUNNING, ERROR, CLOSED, COMPLETE
}

String process_id;
String processId;
long timestamp;
String log_message;
LogLevel log_level;
ProcessStatus process_status;
Boolean store_to_db = true;

//I would change timestamp to a long, log level and process status to enums. and probably process id to a numeric. and storeToDB should be store_to_db for consistency
String logMessage;
LogLevel logLevel;
ProcessStatus processStatus;
Boolean storeToDb = true;

public LogMessage(){}
public LogMessage(String process_id, long timestamp, String log_message, LogLevel log_level, ProcessStatus process_status, Boolean storeToDB){
this.process_id = process_id;

public LogMessage(String processId, long timestamp, String logMessage, LogLevel logLevel, ProcessStatus processStatus, Boolean storeToDb){
this.processId = processId;
this.timestamp = timestamp;
this.log_level = log_level;
this.log_message = log_message;
this.process_status = process_status;
this.store_to_db = storeToDB;
this.logLevel = logLevel;
this.logMessage = logMessage;
this.processStatus = processStatus;
this.storeToDb = storeToDb;
}

public String getProcess_id() {
return process_id;
public String getProcessId() {
return processId;
}
public void setProcess_id(String process_id) {
this.process_id = process_id;
public void setProcessId(String processId) {
this.processId = processId;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public String getLog_message() {
return log_message;
public String getLogMessage() {
return logMessage;
}
public void setLog_message(String log_message) {
this.log_message = log_message;
public void setLogMessage(String logMessage) {
this.logMessage = logMessage;
}
public LogLevel getLog_level() {
return log_level;
public LogLevel getLogLevel() {
return logLevel;
}
public void setLog_level(LogLevel log_level) {
this.log_level = log_level;
public void setLogLevel(LogLevel logLevel) {
this.logLevel = logLevel;
}
public ProcessStatus getProcess_status() {
return process_status;
public ProcessStatus getProcessStatus() {
return processStatus;
}
public void setProcess_status(ProcessStatus process_status) {
this.process_status = process_status;
public void setProcessStatus(ProcessStatus processStatus) {
this.processStatus = processStatus;
}
public Boolean getStoreToDB() {
return store_to_db;
public Boolean getStoreToDb() {
return storeToDb;
}
public void setStoreToDB(Boolean storeToDB) {
this.store_to_db = storeToDB;
public void setStoreToDb(Boolean storeToDb) {
this.storeToDb = storeToDb;
}


public static LogMessage parse(String jsonString){
Gson gson = new Gson();
LogMessage obj = gson.fromJson(jsonString, LogMessage.class);
if(obj.log_message==null)
if(obj.logMessage==null)
throw new RuntimeException("Expected attribute log_message not found");
return obj;
}
Expand Down

0 comments on commit d5eebe4

Please sign in to comment.