Skip to content

Commit

Permalink
Initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhks committed Mar 1, 2019
1 parent 50b55b1 commit 23eb500
Show file tree
Hide file tree
Showing 24 changed files with 1,582 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
*.ipr
*.iws
*.iml
var/*
target/*
build/*
*/target/*
.gradle/*
out/*
dependency.txt
.tablesawcache
.idea
log/*
kairosdb.properties
lib/ivy/default/*
lib/ivy/test/*
.DS_Store
myivysettings.xml
tablesaw.properties
kairosdb.conf
queue
big_array
kairosdb_guid.properties
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# kairos-remote
Remote datastore that forwards data on to another Kairos instance
# Kairos Remote

This plugin used to ship as part of Kairos and was separated out for ease of maintenance.

The remote plugin is for forwarding metric data to a remote Kairos instance.
Metric data is gathered locally on the filesystem where it is compressed and uploaded to the
remote Kairos on specified intervals. (see kairos-remote.properties for options)

## Remote Datastore
The remote plugin can be loaded in one of two ways. The first is as the Kairos datastore:

```properties
kairosdb.service.datastore=org.kairosdb.plugin.remote.RemoteModule
```

This effectively makes the Kairos node write only. The node will not try to connect to
Cassandra or load the H2 database.

## Remote Listener
The second way to load the remote plugin is as a data point listener:

```properties
kairosdb.datastore.remote.service.remote=org.kairosdb.plugin.remote.ListenerModule
```

The `ListenerModule` adds a listener to the data point events going into the datastore and
forwards the events on to a remote Kairos instance. Effectively letting you fork the data.
229 changes: 229 additions & 0 deletions build.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import org.freecompany.redline.Builder
import org.freecompany.redline.header.Architecture
import org.freecompany.redline.header.Os
import org.freecompany.redline.header.RpmType
import org.freecompany.redline.payload.Directive
import tablesaw.*
import tablesaw.addons.GZipRule
import tablesaw.addons.TarRule
import tablesaw.addons.ivy.IvyAddon
import tablesaw.addons.ivy.PomRule
import tablesaw.addons.ivy.PublishRule
import tablesaw.addons.java.Classpath
import tablesaw.addons.java.JarRule
import tablesaw.addons.java.JavaCRule
import tablesaw.addons.java.JavaProgram
import tablesaw.addons.junit.JUnitRule
import tablesaw.definitions.Definition
import tablesaw.rules.CopyRule
import tablesaw.rules.DirectoryRule
import tablesaw.rules.Rule
import tablesaw.rules.SimpleRule

import javax.swing.*

println("===============================================")

saw.setProperty(Tablesaw.PROP_MULTI_THREAD_OUTPUT, Tablesaw.PROP_VALUE_ON)

programName = "kairos-kafka-monitor"
//Do not use '-' in version string, it breaks rpm uninstall.
version = "1.3.0"
release = saw.getProperty("KAIROS_RELEASE_NUMBER", "0.1beta") //package release number
summary = "KairosDB"
description = """\
KairosDB is a time series database that stores numeric values along
with key/value tags to a nosql data store. Currently supported
backends are Cassandra and H2. An H2 implementation is provided
for development work.
"""


saw = Tablesaw.getCurrentTablesaw()
saw.includeDefinitionFile("definitions.xml")


rpmDir = "build/rpm"
new DirectoryRule("build")
rpmDirRule = new DirectoryRule(rpmDir)

//Read pom file to get version out
def pom = new XmlSlurper().parseText(new File("pom.xml").text)
version = pom.version.text()

mvnRule = new SimpleRule("maven-package")
.setDescription("Run maven package build")
.setMakeAction("doMavenBuild")

def doMavenBuild(Rule rule)
{
saw.exec("mvn clean package")
}

//------------------------------------------------------------------------------
//Build zip deployable application
rpmFile = "$programName-$version-${release}.rpm"
srcRpmFile = "$programName-$version-${release}.src.rpm"
ivyFileSet = new SimpleFileSet()


libFileSets = [
new RegExFileSet("build/jar", ".*\\.jar"),
new RegExFileSet("lib", ".*\\.jar"),
ivyFileSet
]

scriptsFileSet = new RegExFileSet("src/scripts", ".*").addExcludeFile("kairosdb-env.sh")
webrootFileSet = new RegExFileSet("webroot", ".*").recurse()

zipLibDir = "$programName/lib"
zipBinDir = "$programName/bin"
zipConfDir = "$programName/conf"
zipConfLoggingDir = "$zipConfDir/logging"
zipWebRootDir = "$programName/webroot"
tarRule = new TarRule("build/${programName}-${version}-${release}.tar")
.addDepend(mvnRule)
.addFileSetTo(zipBinDir, scriptsFileSet)
.addFileSetTo(zipWebRootDir, webrootFileSet)
.addFileTo(zipConfDir, "src/main/resources", "kairosdb.conf")
.addFileTo(zipConfLoggingDir, "src/main/resources", "logback.xml")
.setFilePermission(".*\\.sh", 0755)

for (AbstractFileSet fs in libFileSets)
tarRule.addFileSetTo(zipLibDir, fs)


gzipRule = new GZipRule("package").setSource(tarRule.getTarget())
.setDescription("Create deployable tar file")
.setTarget("build/${programName}-${version}-${release}.tar.gz")
.addDepend(tarRule)

//------------------------------------------------------------------------------
//Build rpm file
rpmBaseInstallDir = "/opt/kairosdb"
rpmRule = new SimpleRule("package-rpm").setDescription("Build RPM Package")
.addDepend(mvnRule)
.addDepend(rpmDirRule)
.addTarget("$rpmDir/$rpmFile")
.setMakeAction("doRPM")
.setProperty("dependency", "on")


def doRPM(Rule rule)
{
//Build rpm using redline rpm library
host = InetAddress.getLocalHost().getHostName()
rpmBuilder = new Builder()
rpmBuilder.with
{
description = description
group = "System Environment/Daemons"
license = "license"
setPackage(programName, version, release)
setPlatform(Architecture.NOARCH, Os.LINUX)
summary = summary
type = RpmType.BINARY
url = "http://kairosdb.org"
vendor = "KairosDB"
provides = programName
//prefixes = rpmBaseInstallDir
buildHost = host
sourceRpm = srcRpmFile
}

rpmBuilder.addDependencyMore("kairosdb", "1.2.0")

addFileSetToRPM(rpmBuilder, "$rpmBaseInstallDir/lib/kafka-monitor", new RegExFileSet("target", ".*\\.jar"))
addFileSetToRPM(rpmBuilder, "$rpmBaseInstallDir/lib/kafka-monitor", new RegExFileSet("target/dependency", ".*\\.jar"))


rpmBuilder.addFile("$rpmBaseInstallDir/conf/kafka-monitor.properties",
new File("src/main/resources/kafka-monitor.properties"), 0644, new Directive(Directive.RPMFILE_CONFIG | Directive.RPMFILE_NOREPLACE))


println("Building RPM "+rule.getTarget())
outputFile = new FileOutputStream(rule.getTarget())
rpmBuilder.build(outputFile.channel)
outputFile.close()
}

def addFileSetToRPM(Builder builder, String destination, AbstractFileSet files)
{

for (AbstractFileSet.File file : files.getFiles())
{
File f = new File(file.getBaseDir(), file.getFile())
if (f.getName().endsWith(".sh"))
builder.addFile(destination + "/" +file.getFile(), f, 0755)
else
builder.addFile(destination + "/" + file.getFile(), f)
}
}

debRule = new SimpleRule("package-deb").setDescription("Build Deb Package")
.addDepend(rpmRule)
.setMakeAction("doDeb")

def doDeb(Rule rule)
{
//Prompt the user for the sudo password
//TODO: package using jdeb
def jpf = new JPasswordField()
def password = saw.getProperty("sudo")

if (password == null)
{
def resp = JOptionPane.showConfirmDialog(null,
jpf, "Enter sudo password:",
JOptionPane.OK_CANCEL_OPTION)

if (resp == 0)
password = jpf.getPassword()
}

if (password != null)
{
sudo = saw.createAsyncProcess(rpmDir, "sudo -S alien --bump=0 --to-deb $rpmFile")
sudo.run()
//pass the password to the process on stdin
sudo.sendMessage("$password\n")
sudo.waitForProcess()
if (sudo.getExitCode() != 0)
throw new TablesawException("Unable to run alien application")
}
}



//------------------------------------------------------------------------------
//Build notification
def printMessage(String title, String message) {
osName = saw.getProperty("os.name")

Definition notifyDef
if (osName.startsWith("Linux"))
{
notifyDef = saw.getDefinition("linux-notify")
}
else if (osName.startsWith("Mac"))
{
notifyDef = saw.getDefinition("mac-notify")
}

if (notifyDef != null)
{
notifyDef.set("title", title)
notifyDef.set("message", message)
saw.exec(notifyDef.getCommand())
}
}

def buildFailure(Exception e)
{
printMessage("Build Failure", e.getMessage())
}

def buildSuccess(String target)
{
printMessage("Build Success", target)
}
93 changes: 93 additions & 0 deletions definitions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" ?>

<definitions xmlns="http://www.cpmake.org">

<definition name="sun_javac" command="javac">

<mode>debug</mode>
<mode>release</mode>

<property name="compiler">Sun Java</property>

<option name="deprecation">-deprecation</option>
<option name="unchecked">-Xlint:unchecked</option>
<option name="fallthrough">-Xlint:fallthrough</option>
<option name="path" >-Xlint:path</option>
<option name="serial" >-Xlint:serial</option>
<option name="finally">-Xlint:finally</option>
<option name="lintall">-Xlint:all</option>
<option name="verbose">-verbose</option>

<option name="source" pattern="(.+)">-source $1</option>
<option name="target" pattern="(.+)">-target $1</option>

<option name="classpath"
pattern="(.+)">-classpath $1</option>

<option name="class_dir" pattern="(.+)">-d $1</option>

<option name="sourcepath" pattern="(.+)">-sourcepath $1</option>

<option name="encoding" pattern="(.+)">-encoding $1</option>

<option mode="debug">-g</option>
<option mode="release">-g:none</option>

<option name="sourcefile" pattern="(.+)">$1</option>

</definition>

<definition name="genormous" command="java">
<!-- <command name="genorm">java</command>
<command name="genquery">java</command> -->

<option name="classpath" pattern="(.+)">-cp $1</option>
<option name="genorm">org.agileclick.genorm.Genormous</option>
<option name="genquery">org.agileclick.genorm.QueryGen</option>

<option name="source" pattern="(.+)">-s $1</option>
</definition>

<!-- We are overriding the tablesaw defintion for junit so we can increase
memory needed for running tests -->
<definition name="junit4" command="java -Xmx500M">
<option name="jvm_arg" pattern="(.*)">$1</option>
<option name="debug" pattern="(.+)">-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,address=$1
</option>
<option name="classpath" pattern="(.+)">-cp $1</option>
<option>org.junit.runner.JUnitCore</option>
<option name="test_class" pattern="(.+)">$1</option>
</definition>

<!-- ======================================================================= -->
<definition name="testng" command="java">
<option name="classpath" pattern="(.+)">-cp $1</option>
</definition>

<!-- ======================================================================= -->
<definition name="linux-notify" command="notify-send">
<option name="title" pattern="(.+)">"$1"</option>
<option name="message" pattern="(.+)">"$1"</option>
</definition>

<definition name="mac-notify" command="osascript">
<option>-e "display notification</option>
<option name="message" pattern="(.+)">\\"$1\\"</option>
<option name="title" pattern="(.+)">with title \\"$1\\"</option>
<option>"</option>
</definition>

<definition name="kairos" command="java">
<option name="debug">-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005</option>
<option name="profile" pattern="(.+)">$1</option>
<option>-Dio.netty.epollBugWorkaround=true</option>
<option name="classpath" pattern="(.+)">-cp $1</option>
<option>org.kairosdb.core.Main</option>
<option name="command" pattern="(.+)">-c $1</option>
<option name="export_metric" pattern="(.+)">-n $1</option>
<option name="import_export_file" pattern="(.+)">-f $1</option>
<option name="properties" pattern="(.+)">-p $1</option>
</definition>

</definitions>
10 changes: 10 additions & 0 deletions how_to_build.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Building requires JDK 1.8 or later.

To build set your classpath to the tablesaw jar file like so:
>export CLASSPATH=tools/tablesaw-1.2.6.jar

Then to build type
>java make package-rpm

You can also get help on what targets are available by typing
>java make help
Loading

0 comments on commit 23eb500

Please sign in to comment.