Skip to content

Commit

Permalink
iss #24: use universal config in ambient7-analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
maizy committed Feb 20, 2017
1 parent ebdec8a commit dbb102d
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 277 deletions.
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,15 @@ java -jar ambient7-analysis-x.x.x.jar --help
### Init or migrate DB

```
java -jar ambient7-analysis-x.x.x.jar init-db \
--db-user=ambient7 \
'--db-url=jdbc:h2:file:/path/to/database/analysis;AUTO_SERVER=TRUE'
java -jar ambient7-analysis-x.x.x.jar --config=ambient7.conf init-db
```

### Co2 hourly report

Add to crontab or any other scheduler the command:

```
java -jar ambient7-analysis-x.x.x.jar aggregate-co2 \
--influxdb-database=ambient7 \
--influxdb-agent-name=main \
'--influxdb-baseurl=http://localhost:8086/' \
--influxdb-user=ambient7_rw \
--influxdb-password=123 \
--influxdb-readonly-user=ambient7_ro \
--influxdb-readonly-password=123 \
--db-user=ambient7 \
'--db-url=jdbc:h2:file:/path/to/database/analysis;AUTO_SERVER=TRUE'
java -jar ambient7-analysis-x.x.x.jar --config=ambient7.conf aggregate-co2
```


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ru.maizy.ambient7.analysis

/**
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016-2017
* See LICENSE.txt for details.
*/

import ru.maizy.ambient7.analysis.command.{ AggregateCo2Command, InitDbCommand }
import ru.maizy.ambient7.core.config.ParsingError


object AnalysisAppLauncher extends App {

AnalysisConfigReader.readAppConfig(args) match {
case Left(parsingError) =>
analysisLogger.error(ParsingError.formatErrorsForLog(parsingError))
Console.err.println(ParsingError.formatErrorsAndUsage(parsingError))
System.exit(2)

case Right(opts) if opts.analysisSpecificOptions.isEmpty =>
Console.err.println("unknown command")
System.exit(2)

case Right(opts) =>
opts.analysisSpecificOptions.map(_.command).getOrElse("") match {
case Some("init-db") =>
opts.mainDb match {
case Some(dbOpts) =>
val res = InitDbCommand.run(dbOpts.url.getOrElse(""), dbOpts.user, dbOpts.password)
System.exit(res.systemExitCode)
case None =>
analysisLogger.error("db opts required")
System.exit(2)
}

case Some("aggregate-co2") =>
val res = AggregateCo2Command.run(opts)
System.exit(res.systemExitCode)

case _ =>
Console.err.println("Unknown command")
System.exit(2)
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.maizy.ambient7.analysis

import ru.maizy.ambient7.core.config.{ Ambient7Options, AnalysisSpecificOptions }
import ru.maizy.ambient7.core.config.reader.{ DevicesConfigReader, InfluxDbConfigReader, MainDbConfigReader }
import ru.maizy.ambient7.core.config.reader.UniversalConfigReader

/**
* Copyright (c) Nikita Kovaliov, maizy.ru, 2017
* See LICENSE.txt for details.
*/
object AnalysisConfigReader
extends UniversalConfigReader
with DevicesConfigReader
with InfluxDbConfigReader
with MainDbConfigReader
{
override def appName: String = "java -jar ambient7-analysis.jar"

private def setCommand(opts: Ambient7Options, command: String): Ambient7Options = {
val existingOpts = opts.analysisSpecificOptions.getOrElse(AnalysisSpecificOptions())
opts.copy(analysisSpecificOptions = Some(existingOpts.copy(command = Some(command))))
}

override def fillReader(): Unit = {
fillDevicesOptions()
fillConfigOptions(requireConfig = true)
fillInfluxDbOptions()
fillDbOptions()

cliParser.cmd("aggregate-co2")
.action { (_, opts) => setCommand(opts, "aggregate-co2") }
.text("\tcompute hourly co2 levels report")

cliParser.cmd("init-db")
.action { (_, opts) => setCommand(opts, "init-db") }
.text("\tinitialize or upgrade db")

()
}

fillReader()
}

This file was deleted.

Loading

0 comments on commit dbb102d

Please sign in to comment.