Skip to content

Commit

Permalink
iss #24: universal config
Browse files Browse the repository at this point in the history
  • Loading branch information
maizy committed Feb 20, 2017
2 parents 23bf7ce + dbb102d commit 567f73b
Show file tree
Hide file tree
Showing 143 changed files with 2,349 additions and 889 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Nikita Kovaliov, maizy.ru
Copyright (c) 2015-2016 Nikita Kovaliov, maizy.ru

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
Expand Down
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ java -jar ambient7-mt8057-agent-x.x.x.jar --writers=interactive
java -jar ambient7-mt8057-agent-x.x.x.jar --writers=influxdb \
--influxdb-database=ambient7 \
--influxdb-baseurl=http://localhost:8086/write \
--influxdb-baseurl=http://localhost:8086/ \
--influxdb-user=user --influxdb-password=123
```

Expand All @@ -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://127.0.0.1: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 567f73b

Please sign in to comment.