Skip to content

Commit

Permalink
pongasoft#175: fixed client auth not working
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Oct 31, 2012
1 parent 499acca commit 6bf779c
Show file tree
Hide file tree
Showing 15 changed files with 477 additions and 85 deletions.
1 change: 1 addition & 0 deletions agent/org.linkedin.glu.agent-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {

runtime spec.external.ivy

testRuntime project(':utils:org.linkedin.glu.utils.log4j-test-config')
testRuntime spec.external.ivy
}

Expand Down
5 changes: 3 additions & 2 deletions agent/org.linkedin.glu.agent-server-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ dependencies {
compile project(':agent:org.linkedin.glu.agent-impl')
compile project(':agent:org.linkedin.glu.agent-rest-resources')
compile spec.external.restlet
compile spec.external.restletExtSimple
compile spec.external.simpleFramework
compile spec.external.restletExtJetty

groovy spec.external.groovy

Expand All @@ -33,4 +32,6 @@ dependencies {
runtime spec.external.commonsCli
runtime spec.external.slf4jLog4j
runtime spec.external.log4j

testRuntime project(':utils:org.linkedin.glu.utils.log4j-test-config')
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import org.linkedin.groovy.util.io.fs.FileSystemImpl
import org.linkedin.groovy.util.ivy.IvyURLHandler
import org.linkedin.groovy.util.net.GroovyNetUtils
import org.linkedin.groovy.util.net.SingletonURLStreamHandlerFactory
import org.linkedin.util.clock.Timespan
import org.linkedin.util.codec.Base64Codec
import org.linkedin.util.codec.Codec
import org.linkedin.util.codec.CodecUtils
Expand All @@ -53,8 +52,6 @@ import org.linkedin.zookeeper.client.LifecycleListener
import org.linkedin.zookeeper.client.ZooKeeperURLHandler
import org.restlet.util.Series
import org.restlet.routing.Router
import org.restlet.ext.simple.HttpsServerHelper
import org.restlet.ext.simple.HttpServerHelper
import org.linkedin.groovy.util.config.Config
import org.restlet.Component
import org.restlet.data.Protocol
Expand All @@ -81,8 +78,6 @@ class AgentMain implements LifecycleListener, Configurable
private static final OneWayCodec ONE_WAY_CODEC
private static final OneWayCodec ONE_WAY_CODEC_2

public static final Timespan PROCESS_TRACKER_HEARTBEAT = Timespan.parse('10s')

static {
String p0 = "gluos2way"
TWO_WAY_CODEC = new Base64Codec(p0)
Expand Down Expand Up @@ -431,6 +426,11 @@ class AgentMain implements LifecycleListener, Configurable
}

def start()
{
start(true)
}

def start(boolean withTerminationHandler)
{
_shutdown = new Shutdown()
_agent = new AgentImpl()
Expand Down Expand Up @@ -461,52 +461,55 @@ class AgentMain implements LifecycleListener, Configurable

startRestServer()

registerTerminationHandler()
if(withTerminationHandler)
registerTerminationHandler()

log.info 'Agent started.'
}

def registerTerminationHandler()
{
addShutdownHook {
log.info 'Shutting down...'

synchronized(_lock) {
_receivedShutdown = true
_lock.notify()
}
addShutdownHook(stop)
}

// first we make sure that no calls can come in and that all pending calls have
// gone through
_shutdown.shutdown()
_shutdown.waitForShutdown()
def stop = {
log.info 'Shutting down...'

if(_restServer)
{
log.info 'Stopping REST service...'
_restServer.stop()
log.info 'REST service stopped.'
}
synchronized(_lock) {
_receivedShutdown = true
_lock.notify()
}

if(_agent)
{
log.info 'Shutting down the agent...'
_agent.shutdown()
_agent.waitForShutdown()
log.info 'Agent shut down...'
}
// first we make sure that no calls can come in and that all pending calls have
// gone through
_shutdown.shutdown()
_shutdown.waitForShutdown()

if(_zkClient)
{
log.info 'Stopping ZooKeeper client...'
_zkClient.destroy()
_zkClient = null
log.info 'ZooKeeper client stopped.'
}
if(_restServer)
{
log.info 'Stopping REST service...'
_restServer.stop()
log.info 'REST service stopped.'
}

if(_agent)
{
log.info 'Shutting down the agent...'
_agent.shutdown()
_agent.waitForShutdown()
log.info 'Agent shut down...'
}

log.info 'Shutdown sequence complete.'
if(_zkClient)
{
log.info 'Stopping ZooKeeper client...'
_zkClient.destroy()
_zkClient = null
log.info 'ZooKeeper client stopped.'
}


log.info 'Shutdown sequence complete.'
}

def startRestServer()
Expand Down Expand Up @@ -557,9 +560,9 @@ class AgentMain implements LifecycleListener, Configurable
params.add('keyPassword', getPassword(_config, "${prefix}.agent.keyPassword"))

// truststore
def trustore = fetchFile(Config.getRequiredString(_config, "${prefix}.agent.truststorePath"),
Config.getRequiredString(_config, "${prefix}.agent.truststoreChecksum"))
params.add('truststorePath', trustore.path)
def truststore = fetchFile(Config.getRequiredString(_config, "${prefix}.agent.truststorePath"),
Config.getRequiredString(_config, "${prefix}.agent.truststoreChecksum"))
params.add('truststorePath', truststore.path)
params.add('truststorePassword', getPassword(_config, "${prefix}.agent.truststorePassword"))

params.add('sslContextFactory', 'org.restlet.engine.security.DefaultSslContextFactory')
Expand All @@ -571,14 +574,12 @@ class AgentMain implements LifecycleListener, Configurable

def server = _restServer.getServers().add(Protocol.HTTPS, port);
server.setContext(serverContext)
new HttpsServerHelper(server)

secure = '(secure)'
}
else
{
def server = _restServer.getServers().add(Protocol.HTTP, port);
new HttpServerHelper(server)
_restServer.getServers().add(Protocol.HTTP, port);
}

_restServer.start()
Expand Down Expand Up @@ -761,6 +762,12 @@ class AgentMain implements LifecycleListener, Configurable
}

protected def readConfig(url, Properties properties)
{
staticReadConfig(url, properties)
}

// creating a new method in order not to change the non static one
static def staticReadConfig(url, Properties properties)
{
if(url)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
package org.linkedin.glu.agent.server

import org.linkedin.glu.agent.rest.resources.AgentConfigResource
import org.linkedin.groovy.util.io.GroovyIOUtils
import org.linkedin.groovy.util.config.Config
import org.linkedin.util.clock.Timespan
import org.linkedin.util.collections.CollectionsUtils
import org.linkedin.util.lifecycle.Configurable
import org.linkedin.zookeeper.client.IZKClient
import org.linkedin.zookeeper.client.ZKClient
import org.restlet.ext.simple.HttpServerHelper
import org.restlet.routing.Router
import org.restlet.Component
import org.restlet.data.Protocol
Expand Down Expand Up @@ -125,7 +123,6 @@ class IZKClientFactory implements Configurable
attributes.put('configurable', this)
attributes.put('codec', codec)
component.getDefaultHost().attach(router);
new HttpServerHelper(server)
component.start()

def serverAddress = server.address ?: InetAddress.getLocalHost().canonicalHostName
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright (c) 2012 Yan Pujante
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package test.agent.server

import org.linkedin.groovy.util.io.fs.FileSystemImpl
import org.linkedin.glu.agent.server.AgentMain
import org.linkedin.util.lifecycle.Destroyable
import org.linkedin.glu.groovy.utils.GluGroovyLangUtils
import org.linkedin.zookeeper.server.StandaloneZooKeeperServer

/**
* @author yan@pongasoft.com */
public class AgentForTest implements Destroyable
{
FileSystemImpl fileSystem
StandaloneZooKeeperServer zookeeperServer
AgentMain agentMain
def args = []
def agentProperties

def zkClientPort = 2121
def agentPort = 13906

def shutdownSequence = []

void start()
{
start(null, null)
}

void start(String higherPriorityProperties, String lowerPriorityProperties)
{
initFileSystem()
args << saveProperties(higherPriorityProperties, lowerPriorityProperties)
agentProperties = AgentMain.staticReadConfig(args[0], new Properties())
initZooKeeper()
initAgent()
}

def getDefaultAgentProperties()
{
"""
# base properties on which everything else is built
glu.agent.apps=${fileSystem.toResource("/agent/server/apps").file.canonicalPath }
glu.agent.homeDir=${fileSystem.toResource("/agent/server/home").file.canonicalPath}
glu.agent.scriptRootDir=\${glu.agent.apps}
glu.agent.dataDir=\${glu.agent.homeDir}/data
glu.agent.logDir=\${glu.agent.dataDir}/logs
glu.agent.tempDir=\${glu.agent.dataDir}/tmp
glu.agent.scriptStateDir=\${glu.agent.dataDir}/scripts/state
glu.agent.rest.nonSecure.port=12907
glu.agent.persistent.properties=\${glu.agent.dataDir}/config/agent.properties
glu.agent.zkSessionTimeout=5s
glu.agent.version=test
org.linkedin.app.version=test
glu.agent.name=agent-1
glu.agent.fabric=test-fabric
glu.agent.port=${agentPort}
glu.agent.zkConnectString=localhost:${zkClientPort}
glu.agent.zookeeper.root=/org/glu
# security
glu.agent.sslEnabled=true
glu.agent.keystorePath=${devKeysDir.canonicalPath}/agent.keystore
glu.agent.keystoreChecksum=JSHZAn5IQfBVp1sy0PgA36fT_fD
glu.agent.keystorePassword=nacEn92x8-1
glu.agent.keyPassword=nWVxpMg6Tkv
glu.agent.truststorePath=${devKeysDir.canonicalPath}/console.truststore
glu.agent.truststoreChecksum=qUFMIePiJhz8i7Ow9lZmN5pyZjl
glu.agent.truststorePassword=nacEn92x8-1
""".toString()
}

File getDevKeysDir()
{
new File("../../dev-keys").canonicalFile
}

void initFileSystem()
{
fileSystem = FileSystemImpl.createTempFileSystem()

shutdownSequence << { fileSystem.destroy() }
}

void initZooKeeper()
{
zookeeperServer = new StandaloneZooKeeperServer(tickTime: 2000,
clientPort: zkClientPort,
dataDir: fileSystem.toResource("/zookeeper/server/data").file.canonicalPath)

zookeeperServer.start()

shutdownSequence << {
zookeeperServer.shutdown()
zookeeperServer.waitForShutdown(100)
}
}

void initAgent()
{
agentMain = new AgentMain()
agentMain.init(args)
agentMain.start(false)

shutdownSequence << { agentMain.stop() }
}

@Override
void destroy()
{
GluGroovyLangUtils.noException(shutdownSequence.reverse())
}

def saveProperties(String higherPriorityProperties, String lowerPriorityProperties)
{
def resource = fileSystem.toResource("/agent/server/conf/agentConfig.properties")
fileSystem.withOutputStream(resource) { OutputStream os ->
if(higherPriorityProperties)
os << higherPriorityProperties
os << "\n"
os << defaultAgentProperties
os << "\n"
if(lowerPriorityProperties)
os << lowerPriorityProperties
}


return resource.toURI().toString()
}
}
Loading

0 comments on commit 6bf779c

Please sign in to comment.