Skip to content

Commit

Permalink
issue #82 - added a code to convert monitors->collectors on save
Browse files Browse the repository at this point in the history
  • Loading branch information
oshai committed Jan 22, 2015
1 parent 1f1c0f6 commit 76a8726
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/web_server/codeine/ConfigurationManagerServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import org.apache.log4j.Logger;

import codeine.configuration.ConfigurationReadManagerServer;
import codeine.configuration.NodeMonitor;
import codeine.configuration.PathHelper;
import codeine.db.ProjectsConfigurationConnector;
import codeine.db.mysql.connectors.ProjectConfigurationDatabaseConnectorListProvider;
import codeine.executer.ThreadPoolUtils;
import codeine.jsons.collectors.CollectorInfo;
import codeine.jsons.collectors.CollectorInfo.CollectorType;
import codeine.jsons.project.ProjectJson;
import codeine.model.Constants;
import codeine.utils.ExceptionUtils;
Expand Down Expand Up @@ -78,6 +81,7 @@ public ThreadPoolExecutor call() throws Exception {

public boolean updateProject(final ProjectJson updatedProject) {
log.info("updating project " + updatedProject);
changeMonitorsToCollectors(updatedProject);
String file = pathHelper.getProjectsDir() + "/" + updatedProject.name() + "/" + Constants.PROJECT_CONF_FILE;
jsonFileUtils.setContent(file, updatedProject);
final ProjectJson previousProject = projects().put(updatedProject.name(), updatedProject);
Expand All @@ -87,6 +91,17 @@ public boolean updateProject(final ProjectJson updatedProject) {
return null != previousProject;
}

private void changeMonitorsToCollectors(ProjectJson updatedProject) {
for (NodeMonitor monitorInfo : updatedProject.monitors()) {
String name = monitorInfo.name();
CollectorType type = CollectorType.Monitor;
int minInterval = monitorInfo.minInterval() == null ? 0 : monitorInfo.minInterval();
CollectorInfo collectorInfo = new CollectorInfo(name, monitorInfo.script_content(), minInterval, monitorInfo.credentials(), type, monitorInfo.notification_enabled());
updatedProject.collectors().add(collectorInfo);
}
updatedProject.monitors().clear();
}

public void updateDb() {
for (ProjectJson project : projects().values()) {
updateProjectInDb(project);
Expand Down

0 comments on commit 76a8726

Please sign in to comment.