Skip to content

Commit

Permalink
upgraded platform from 1.6.x to 1.9.x etc
Browse files Browse the repository at this point in the history
  • Loading branch information
kaweesi committed Jan 31, 2017
1 parent 60e7aea commit 98beb41
Show file tree
Hide file tree
Showing 16 changed files with 1,030 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static Long logCurrentUsedMemory() {
resetDateTimes(today);
try {
if (!logFile.exists()) {
if (!logFile.getParentFile().exists())
logFile.getParentFile().mkdirs();
logFile.createNewFile();
} else if (logFile.exists() && updatedOn.before(today)) {
logFile.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
import org.openmrs.api.context.ContextAuthenticationException;
import org.openmrs.module.systemmonitor.api.SystemMonitorService;
import org.openmrs.scheduler.SchedulerConstants;
import org.openmrs.scheduler.tasks.AbstractTask;

public class LocalLogsAndDHISDataCleanerTask extends AbstractTask {
Expand All @@ -16,25 +13,7 @@ public class LocalLogsAndDHISDataCleanerTask extends AbstractTask {
@Override
public void execute() {
log.info("Executing " + getClass() + " background task");
authenticateHack();
SystemMonitorTask.authenticateHack();
Context.getService(SystemMonitorService.class).cleanOldLocallyStoredLogsAndDHISData();
Context.closeSession();
}

protected void authenticateHack() {
try {
try {
Context.openSession();

AdministrationService adminService = Context.getAdministrationService();
Context.authenticate(adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_USERNAME_PROPERTY),
adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_PASSWORD_PROPERTY));
} catch (ContextAuthenticationException e) {
log.error("Error authenticating user", e);
}

} catch (ContextAuthenticationException e) {
log.error("Error authenticating user", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
import org.openmrs.api.context.ContextAuthenticationException;
import org.openmrs.module.systemmonitor.memory.MemoryAggregation;
import org.openmrs.scheduler.SchedulerConstants;
import org.openmrs.scheduler.tasks.AbstractTask;

public class MemoryAggregationTask extends AbstractTask {
Expand All @@ -15,25 +12,8 @@ public class MemoryAggregationTask extends AbstractTask {
@Override
public void execute() {
log.info("Executing " + getClass() + " background task");
authenticateHack();
SystemMonitorTask.authenticateHack();
MemoryAggregation.logCurrentUsedMemory();
Context.closeSession();
}

protected void authenticateHack() {
try {
try {
Context.openSession();

AdministrationService adminService = Context.getAdministrationService();
Context.authenticate(adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_USERNAME_PROPERTY),
adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_PASSWORD_PROPERTY));
} catch (ContextAuthenticationException e) {
log.error("Error authenticating user", e);
}

} catch (ContextAuthenticationException e) {
log.error("Error authenticating user", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
import org.openmrs.api.context.ContextAuthenticationException;
import org.openmrs.module.systemmonitor.uptime.OpenmrsUpAndDownTracker;
import org.openmrs.scheduler.SchedulerConstants;
import org.openmrs.scheduler.tasks.AbstractTask;

public class OpenMRSUptimeTask extends AbstractTask {
Expand All @@ -15,25 +11,8 @@ public class OpenMRSUptimeTask extends AbstractTask {
@Override
public void execute() {
log.info("Executing " + getClass() + " background task");
authenticateHack();
SystemMonitorTask.authenticateHack();
OpenmrsUpAndDownTracker.logCurrentOpenMRSUptime();
Context.closeSession();
}

protected void authenticateHack() {
try {
try {
Context.openSession();

AdministrationService adminService = Context.getAdministrationService();
Context.authenticate(adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_USERNAME_PROPERTY),
adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_PASSWORD_PROPERTY));
} catch (ContextAuthenticationException e) {
log.error("Error authenticating user", e);
}

} catch (ContextAuthenticationException e) {
log.error("Error authenticating user", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
import org.openmrs.api.context.ContextAuthenticationException;
import org.openmrs.module.systemmonitor.api.SystemMonitorService;
import org.openmrs.scheduler.SchedulerConstants;
import org.openmrs.scheduler.tasks.AbstractTask;

/**
Expand All @@ -24,26 +21,8 @@ public class PushMonitoredDataTask extends AbstractTask {
@Override
public void execute() {
log.info("Executing " + getClass() + " background task");
authenticateHack();
SystemMonitorTask.authenticateHack();
Context.getService(SystemMonitorService.class).pushMonitoredDataToDHIS();
Context.clearSession();
}

protected void authenticateHack() {
try {
try {
Context.openSession();

AdministrationService adminService = Context.getAdministrationService();
Context.authenticate(adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_USERNAME_PROPERTY),
adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_PASSWORD_PROPERTY));
} catch (ContextAuthenticationException e) {
log.error("Error authenticating user", e);
}

} catch (ContextAuthenticationException e) {
log.error("Error authenticating user", e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.openmrs.module.systemmonitor.scheduler;

import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
import org.openmrs.api.context.ContextAuthenticationException;
import org.openmrs.module.ModuleUtil;
import org.openmrs.module.systemmonitor.SystemMonitorConstants;
import org.openmrs.scheduler.SchedulerConstants;

public class SystemMonitorTask {
public static void authenticateHack() {
try {
try {
if (!ModuleUtil.matchRequiredVersions(SystemMonitorConstants.OPENMRS_VERSION, "1.9")
&& !Context.isAuthenticated()) {
AdministrationService adminService = Context.getAdministrationService();
Context.authenticate(adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_USERNAME_PROPERTY),
adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_PASSWORD_PROPERTY));
}
} catch (ContextAuthenticationException e) {
System.out.println("Error authenticating user: " + e);
}

} catch (ContextAuthenticationException e) {
System.out.println("Error authenticating user: " + e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
import org.openmrs.api.context.ContextAuthenticationException;
import org.openmrs.module.systemmonitor.api.SystemMonitorService;
import org.openmrs.scheduler.SchedulerConstants;
import org.openmrs.scheduler.tasks.AbstractTask;

/**
Expand All @@ -23,25 +20,8 @@ public class UpdateLocallyStoredDHISMetadataFromRemoteTask extends AbstractTask
@Override
public void execute() {
log.info("Executing " + getClass() + " background task");
authenticateHack();
SystemMonitorTask.authenticateHack();
Context.getService(SystemMonitorService.class).updateLocallyStoredDHISMetadata();
Context.closeSession();
}

protected void authenticateHack() {
try {
try {
Context.openSession();

AdministrationService adminService = Context.getAdministrationService();
Context.authenticate(adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_USERNAME_PROPERTY),
adminService.getGlobalProperty(SchedulerConstants.SCHEDULER_PASSWORD_PROPERTY));
} catch (ContextAuthenticationException e) {
log.error("Error authenticating user", e);
}

} catch (ContextAuthenticationException e) {
log.error("Error authenticating user", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static void logCurrentOpenMRSUptime() {

try {
if (!upTimelogFile.exists()) {
if (!upTimelogFile.getParentFile().exists())
upTimelogFile.getParentFile().mkdirs();
upTimelogFile.createNewFile();
} else if (upTimelogFile.exists() && updatedOn.before(todate)) {
upTimelogFile.delete();
Expand Down
6 changes: 5 additions & 1 deletion api/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ ${project.parent.artifactId}.clientPushing.pushFromClient=Push From Current Clie
${project.parent.artifactId}.clientPushing.description=Push From Current Client supports sending data to DHIS using the current computer from which the EMR(OpenMRS) is being interfaced, This will instead download the data onto the Client machine if it fails to push the data
${project.parent.artifactId}.clientPushing.failureMessage=Pushing to DHIS failed because of no Internet Connection or since the Administrator has not yet setup up an interoperability layer, However the data is downloadable for you to upload directly into DHIS
${project.parent.artifactId}.pushToDHIS.serverInternetFailure=Pushing from the server failed most likely because of lack of an Internet Connection at the Server or evaluation time is outside configured clinical working hours if SMT evaluation and reporting/pushing is set to on, either use Client Pushing or contact the Administrator
systemmonitor.smtOnOrOff=Set SMT Evaluation & Reporting On/Off
systemmonitor.smtOnOrOff=Set SMT Evaluation & Reporting On/Off
${project.parent.artifactId}.activityMonitor=Activity Monitor
${project.parent.artifactId}.activityMonitor.cpu=CPU
${project.parent.artifactId}.activityMonitor.memory=Memory
${project.parent.artifactId}.activityMonitor.uptime=Uptime & Downtime
3 changes: 1 addition & 2 deletions omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
</dependency>

<!-- Begin OpenMRS core -->

<dependency>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<type>jar</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public Map<String, String> getLinks() {
map.put("/module/systemmonitor/configurations.form", "systemmonitor.configurations");
map.put("/module/systemmonitor/localReport.form", "systemmonitor.localReport");
map.put("/module/systemmonitor/runAsSoonAsStarted.form", "systemmonitor.runAsSoonAsStarted");
map.put("/module/systemmonitor/activityMonitor.form", "systemmonitor.activityMonitor");
return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@
*/
package org.openmrs.module.systemmonitor.web.controller;

import java.lang.management.ManagementFactory;
import java.util.Calendar;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.json.JSONObject;
import org.openmrs.api.context.Context;
import org.openmrs.module.systemmonitor.ConfigureGPs;
import org.openmrs.module.systemmonitor.api.SystemMonitorService;
import org.openmrs.module.systemmonitor.distributions.RwandaSPHStudyEMT;
import org.openmrs.module.systemmonitor.indicators.OSAndHardwareIndicators;
import org.openmrs.module.systemmonitor.memory.MemoryAggregation;
import org.openmrs.module.systemmonitor.uptime.OpenmrsUpAndDownTracker;
import org.openmrs.module.systemmonitor.uptime.UpOrDownTimeInterval;
import org.openmrs.web.WebConstants;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* The main controller.
Expand Down Expand Up @@ -78,7 +87,9 @@ public void renderLocalReport(ModelMap model) {

model.addAttribute("orgUnit", Context.getService(SystemMonitorService.class).getDHISConfiguredOrgUnitName());
model.addAttribute("reportData",
emt.generatedDHISDataValueSetJSON().getJSONObject("allData").getJSONArray("dataValues"));
emt.generatedDHISDataValueSetJSON() != null
? emt.generatedDHISDataValueSetJSON().getJSONObject("allData").getJSONArray("dataValues")
: "undefined");
}

@RequestMapping(value = "/module/systemmonitor/runAsSoonAsStarted", method = RequestMethod.GET)
Expand All @@ -90,7 +101,62 @@ public void postAutoRun(ModelMap model, HttpServletRequest request) {
Context.getService(SystemMonitorService.class).transferDHISMappingsAndMetadataFileToDataDirectory();
Context.getService(SystemMonitorService.class).updateLocallyStoredDHISMetadata();
Context.getService(SystemMonitorService.class).rebootSystemMonitorTasks();

request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "systemmonitor.runAsSoonAsStarted.success");
}

@RequestMapping(value = "/module/systemmonitor/activityMonitorInfo", method = RequestMethod.GET)
public @ResponseBody String getActiveMonitorInfo() {
JSONObject json = createClientActivityMonitorInfor();

return json.toString();
}

private JSONObject createClientActivityMonitorInfor() {
JSONObject json = new JSONObject();
OSAndHardwareIndicators oshi = new OSAndHardwareIndicators();
Double systemLoad = ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage();
Double cpuTemperature = oshi.CPU_TEMPERATURE;
Double cpuVoltage = oshi.CPU_VOLTAGE;
Long processorUpTime = oshi.PROCESSOR_SYSTEM_UPTIME;
Integer openmrsUpTime = Context.getService(SystemMonitorService.class).getOpenMRSSystemUpTime().intValue();
Long totalMemory = oshi.MEMORY_TOTAL;
Long usedMemory = MemoryAggregation.getAggregatedUsedMemory();
Long availableMemory = oshi.MEMORY_AVAILABLE;
Integer openingHour = Integer.parseInt(Context.getService(SystemMonitorService.class).getConfiguredOpeningHour()
.getPropertyValue().substring(0, 2));
Integer closingHour = Integer.parseInt(Context.getService(SystemMonitorService.class).getConfiguredClosingHour()
.getPropertyValue().substring(0, 2));
Calendar date = Calendar.getInstance();
date.setTime(Context.getService(SystemMonitorService.class).getEvaluationAndReportingDate());
Integer workingMinutesDifference = ((closingHour - openingHour) - 1) * 60;
Object[] openmrsUpAndDownTime = OpenmrsUpAndDownTracker.calculateOpenMRSUpAndDowntimeBy(date.getTime(), null);
Integer openmrsUptime = (Integer) openmrsUpAndDownTime[0];
Integer openmrsDowntime = (Integer) openmrsUpAndDownTime[1];
List<UpOrDownTimeInterval> upIntervals = (List<UpOrDownTimeInterval>) openmrsUpAndDownTime[2];
List<UpOrDownTimeInterval> downIntervals = (List<UpOrDownTimeInterval>) openmrsUpAndDownTime[3];
Integer openMRsUpTimePercentage = openmrsUptime != null ? (openmrsUptime * 100) / workingMinutesDifference
: null;
Integer openMRsDownTimePercentage = openmrsDowntime != null ? (openmrsDowntime * 100) / workingMinutesDifference
: null;

json.put("systemLoad", systemLoad);
json.put("cpuTemperature", cpuTemperature);
json.put("cpuVoltage", cpuVoltage);
json.put("processorUpTime", processorUpTime);
json.put("openmrsUpTime", openmrsUpTime);
json.put("totalMemory", totalMemory);
json.put("usedMemory", usedMemory);
json.put("availableMemory", availableMemory);
json.put("openMRsUpTimePercentage", openMRsUpTimePercentage);
json.put("openMRsDownTimePercentage", openMRsDownTimePercentage);

return json;
}

@RequestMapping(value = "/module/systemmonitor/activityMonitor", method = RequestMethod.GET)
public void getActiveMonitor(ModelMap model) {
model.put("activityMonitorInfo", createClientActivityMonitorInfor());
}

}
Loading

0 comments on commit 98beb41

Please sign in to comment.