Skip to content

Commit

Permalink
Merge pull request #1 from cinterloper/update-deps
Browse files Browse the repository at this point in the history
update SUSE salt api and Vertx
  • Loading branch information
cinterloper committed Mar 24, 2016
2 parents 46d16aa + d255e87 commit 83b5f4f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
}
}

version = '3.2.0'
version = '3.2.1'
sourceCompatibility = '1.8'

dependencies {
Expand All @@ -23,8 +23,7 @@ dependencies {
compile "io.vertx:vertx-shell:$version"
compile "org.slf4j:slf4j-api:1.7.12"
compile 'org.glassfish.tyrus.bundles:tyrus-standalone-client-jdk:1.12'
compile 'com.suse.saltstack:saltstack-netapi-client:0.6.0'

compile 'com.suse.salt:salt-netapi-client:0.7.0'
}

mainClassName = 'io.vertx.core.Launcher'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.iowntheinter.saltReactor

import com.suse.saltstack.netapi.datatypes.Event;
import com.suse.salt.netapi.datatypes.Event;

/**
* Created by grant on 11/5/15.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package net.iowntheinter.saltReactor.impl

import com.suse.saltstack.netapi.client.SaltStackClient
import com.suse.saltstack.netapi.datatypes.Event
import com.suse.salt.netapi.client.SaltClient
import com.suse.salt.netapi.datatypes.Event
import io.vertx.core.json.JsonObject
import io.vertx.core.logging.Logger
import io.vertx.core.logging.LoggerFactory
import io.vertx.groovy.core.eventbus.EventBus

import io.vertx.groovy.core.shareddata.SharedData
import net.iowntheinter.saltReactor.SVXSubscriptionManager

/**
* Created by grant on 11/5/15.
*/
class SimplePipeSubscriptionManager implements SVXSubscriptionManager {
private SharedData sd
private EventBus eb
private Logger log
private subscriptionChannel
private SaltStackClient saltClient
private SaltClient saltClient

SimplePipeSubscriptionManager(EventBus e, SaltStackClient c) {
SimplePipeSubscriptionManager(SharedData s, EventBus e, SaltClient c) {
sd = s
eb = e
log = LoggerFactory.getLogger("saltReactor:subscriptionManager")
saltClient = c
Expand Down Expand Up @@ -69,28 +71,27 @@ class SimplePipeSubscriptionManager implements SVXSubscriptionManager {
eb.publish(channel, pkg)
} catch (e) {
ret = false
cb([status: ret, error: e.getMessage()])
cb([status:ret, error:e.getMessage()])
}
if (ret)
cb([status: ret, error: null])
cb([status:ret, error:null])
}

private boolean sendToSaltBus(tag, data, cb) {
def ret = true
try {

saltClient.sendEvent(tag, data) //we should switch this to sendEventAsync
} catch (e) {
ret = false
cb([status: ret, error: e.getMessage()])
cb([status:ret, error:e.getMessage()])
}
if (ret)
cb([status: ret, error: null])
cb([status:ret, error:null])
}

@Override
public boolean manage(String vxchannel) {
subscriptionChannel = eb.consumer(vxchannel)
def subscriptionChannel = eb.consumer(vxchannel)
subscriptionChannel.handler({ message ->
JsonObject jreq = new JsonObject()
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
package net.iowntheinter.saltReactor.impl

import com.suse.saltstack.netapi.client.SaltStackClient
import com.suse.salt.netapi.client.SaltClient

/**
* Created by grant on 10/20/15.
*/
import com.suse.saltstack.netapi.event.EventListener
import com.suse.salt.netapi.event.EventListener
import io.vertx.core.logging.Logger
import io.vertx.core.logging.LoggerFactory
import io.vertx.groovy.core.eventbus.EventBus
import io.vertx.groovy.core.shareddata.SharedData
import com.suse.saltstack.netapi.datatypes.Event;
import com.suse.salt.netapi.datatypes.Event;
import io.vertx.groovy.core.Vertx;
import io.vertx.core.json.JsonObject

import javax.websocket.CloseReason;

class saltReactor implements EventListener {
private Vertx vx
private SharedData sd
private EventBus eb
private JsonObject config
private Logger log
private SaltStackClient sc
private SaltClient sc
def mgr

saltReactor(Vertx v, JsonObject c, SaltStackClient s) {
saltReactor(Vertx v, JsonObject c, SaltClient s) {
vx = v;
sc = s
sd = v.sharedData()
config = c
eb = v.eventBus()
log = LoggerFactory.getLogger("saltReactor")
mgr = new SimplePipeSubscriptionManager(eb, sc)
mgr = new SimplePipeSubscriptionManager(sd, eb, sc)
}
CloseReason closeReason;


@Override
void notify(Event event) {

try{
mgr.process(event)
} catch(e){
Expand Down
21 changes: 7 additions & 14 deletions src/main/resources/saltConnection.groovy
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
/**
* Created by grant on 10/20/15.
*/

import com.google.gson.reflect.TypeToken
import com.suse.saltstack.netapi.calls.LocalCall
import com.suse.saltstack.netapi.config.ClientConfig
import com.suse.saltstack.netapi.event.EventListener
import com.suse.saltstack.netapi.event.EventStream
import com.suse.saltstack.netapi.client.SaltStackClient
import com.suse.saltstack.netapi.AuthModule
import com.suse.saltstack.netapi.datatypes.target.MinionList
import com.suse.salt.netapi.AuthModule
import com.suse.salt.netapi.client.SaltClient
import com.suse.salt.netapi.config.ClientConfig
import com.suse.salt.netapi.event.EventListener
import com.suse.salt.netapi.event.EventStream
import io.vertx.core.json.JsonObject
import io.vertx.core.logging.LoggerFactory
import net.iowntheinter.saltReactor.impl.saltReactor

println("hello slt")
//this should switch to https, but we need to register the ca with this lib to access it
URI uri = URI.create("http://127.0.0.1:8000");
SaltStackClient client = new SaltStackClient(uri);
SaltClient client = new SaltClient(uri);
cfg = client.getConfig()
cfg.put(ClientConfig.SOCKET_TIMEOUT , 0)
//auth as a unix user (PAM) on the salt-master system
def UN = "user"
def pass = "changeme"
def token;

def returnMap = [
"zfs.list":new TypeToken<Map<String,List>>(){},
"test.ping":new TypeToken<Boolean>(){},
"cmd.run":new TypeToken<String>(){}
]

token = client.login(UN, pass, AuthModule.PAM);
println("salt auth token: " + token.token + " Until: " + token.expire + " Perms : " + token.getPerms() )
Expand Down

0 comments on commit 83b5f4f

Please sign in to comment.