Skip to content

Commit

Permalink
#58: added console-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Jul 7, 2013
1 parent bf1a0fb commit 0ec3d34
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
logging.basicConfig(
format='%(asctime)s [%(levelname)s] - %(name)s - %(message)s')

bin_path = os.path.abspath((os.path.dirname(sys.argv[0])))
bin_path = os.path.abspath((os.path.dirname(os.path.realpath(__file__))))
lib_path = os.path.join(os.path.dirname(bin_path), 'lib', 'python')
site.addsitedir(lib_path)
site.addsitedir(os.path.join(lib_path, 'site-packages'))
Expand Down
2 changes: 1 addition & 1 deletion packaging/org.linkedin.glu.packaging-all/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def dependentClis = [
':agent:org.linkedin.glu.agent-server': 'agent-server',
':agent:org.linkedin.glu.agent-cli': 'agent-cli',
':console:org.linkedin.glu.console-server': 'console-server',
// ':console:org.linkedin.glu.console-cli': 'console-cli',
':console:org.linkedin.glu.console-cli': 'console-cli',
':packaging:org.linkedin.glu.packaging-setup': 'setup'
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ init()
GLU_TUTORIAL_AGENT_ROOT=$GLU_TUTORIAL_DISTS/agents/org.linkedin.glu.agent-server-$GLU_TUTORIAL_AGENT_NAME-$GLU_TUTORIAL_ZOOKEEPER_CLUSTER_NAME-$GLU_VERSION
GLU_TUTORIAL_AGENT_CLI_ROOT=$GLU_TUTORIAL_DISTS/agent-cli/org.linkedin.glu.agent-cli-$GLU_VERSION
GLU_TUTORIAL_CONSOLE_ROOT=$GLU_TUTORIAL_DISTS/consoles/org.linkedin.glu.console-server-$GLU_TUTORIAL_CONSOLE_NAME-$GLU_VERSION
GLU_TUTORIAL_CONSOLE_CLI_ROOT=$GLU_TUTORIAL_DISTS/console-cli/org.linkedin.glu.console-cli-$GLU_VERSION
GLU_TUTORIAL_ZOOKEEPER_ROOT=$GLU_TUTORIAL_DISTS/zookeeper-clusters/zookeeper-cluster-$GLU_TUTORIAL_ZOOKEEPER_CLUSTER_NAME/org.linkedin.zookeeper-server-$ZOOKEEPER_VERSION

GLU_TUTORIAL_AGENT_LINK=$GLU_TUTORIAL_DIR/agent-server
GLU_TUTORIAL_AGENT_CLI_LINK=$GLU_TUTORIAL_DIR/agent-cli
GLU_TUTORIAL_CONSOLE_LINK=$GLU_TUTORIAL_DIR/console-server
GLU_TUTORIAL_CONSOLE_CLI_LINK=$GLU_TUTORIAL_DIR/console-cli
GLU_TUTORIAL_ZOOKEEPER_LINK=$GLU_TUTORIAL_DIR/zookeeper-server

}
Expand Down Expand Up @@ -82,6 +84,9 @@ setup()
ln -s $GLU_TUTORIAL_CONSOLE_ROOT $GLU_TUTORIAL_CONSOLE_LINK
ln -s $GLU_TUTORIAL_CONSOLE_LINK/bin/consolectl.sh $GLU_TUTORIAL_BIN/console-server.sh

ln -s $GLU_TUTORIAL_CONSOLE_CLI_ROOT $GLU_TUTORIAL_CONSOLE_CLI_LINK
ln -s $GLU_TUTORIAL_CONSOLE_CLI_LINK/bin/console-cli.py $GLU_TUTORIAL_BIN/console-cli.sh

ln -s $GLU_TUTORIAL_ZOOKEEPER_ROOT $GLU_TUTORIAL_ZOOKEEPER_LINK
ln -s $GLU_TUTORIAL_ZOOKEEPER_LINK/bin/zookeeperctl.sh $GLU_TUTORIAL_BIN/zookeeper-server.sh

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* the License.
*/



package org.pongasoft.glu.packaging.setup

import org.linkedin.util.io.resource.Resource
Expand All @@ -27,11 +25,6 @@ public class AgentCliPackager extends BasePackager
{
GluMetaModel metaModel

Map<String, String> getConfigTokens()
{
metaModel.configTokens
}

PackagedArtifact createPackage()
{
String packageName = inputPackage.filename
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2013 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 org.pongasoft.glu.packaging.setup

import org.linkedin.util.io.resource.Resource
import org.pongasoft.glu.provisioner.core.metamodel.GluMetaModel

/**
* @author yan@pongasoft.com */
public class ConsoleCliPackager extends BasePackager
{
GluMetaModel metaModel

PackagedArtifact createPackage()
{
String packageName = inputPackage.filename

def tokens = [
gluMetaModel: metaModel,
]
tokens[PACKAGER_CONTEXT_KEY] = packagerContext

Resource packagePath = outputFolder.createRelative(packageName)

if(!dryMode)
{
copyInputPackage(packagePath)
configure(packagePath, tokens)
}

return new PackagedArtifact(location: packagePath)
}

Resource configure(Resource packagePath, Map tokens)
{
processConfigs('console-cli', tokens, packagePath)
return packagePath
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class GluPackager
packageConsoles()
packageZooKeeperClusters()
packageAgentCli()
packageConsoleCli()
}

void packageAgents()
Expand Down Expand Up @@ -190,6 +191,31 @@ public class GluPackager
return pa
}

protected PackagedArtifact packageConsoleCli()
{
def out = shell.mkdirs(outputFolder.createRelative('console-cli'))
def packager =
new ConsoleCliPackager(packagerContext: createPackagerContext(),
outputFolder: out,
inputPackage: getInputPackage('org.linkedin.glu.console-cli',
gluMetaModel.gluVersion),
configsRoots: configsRoots,
metaModel: gluMetaModel,
dryMode: dryMode)

PackagedArtifact pa = packager.createPackage()

if(!packagedArtifacts[gluMetaModel])
packagedArtifacts[gluMetaModel] = [:]

packagedArtifacts[gluMetaModel].consoleCli = pa

if(!dryMode)
println "Generated console-cli package ${pa.location}"

return pa
}

protected PackagerContext createPackagerContext()
{
new PackagerContext(shell: shell,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
* the License.
*/


package test.setup

import org.linkedin.glu.groovy.utils.shell.Shell
import org.linkedin.glu.groovy.utils.shell.ShellImpl
import org.pongasoft.glu.packaging.setup.AgentCliPackager
import org.pongasoft.glu.packaging.setup.ConsoleServerPackager
import org.pongasoft.glu.packaging.setup.PackagedArtifact
import org.pongasoft.glu.provisioner.core.metamodel.ConsoleMetaModel

/**
* @author yan@pongasoft.com */
Expand All @@ -33,6 +30,8 @@ public class TestAgentCliPackager extends BasePackagerTest
ShellImpl.createTempShell { Shell shell ->

def inputPackage = shell.mkdirs("/dist/org.linkedin.glu.agent-cli-${GLU_VERSION}")
shell.saveContent(inputPackage.createRelative('README.md'), "this is the readme")
shell.saveContent(inputPackage.createRelative('lib/acme.jar'), "this is the jar")

def packager = new AgentCliPackager(packagerContext: createPackagerContext(shell),
outputFolder: shell.mkdirs('/out'),
Expand All @@ -48,6 +47,9 @@ public class TestAgentCliPackager extends BasePackagerTest

def expectedResources =
[
"/README.md": 'this is the readme',
"/lib": DIRECTORY,
"/lib/acme.jar": 'this is the jar',
"/conf": DIRECTORY,
"/conf/clientConfig.properties": """#
# Copyright (c) 2010-2010 LinkedIn, Inc
Expand Down Expand Up @@ -104,6 +106,9 @@ fabrics['f1'] = [ : ]

def inputPackage = shell.mkdirs("/dist/org.linkedin.glu.agent-cli-${GLU_VERSION}")

shell.saveContent(inputPackage.createRelative('README.md'), "this is the readme")
shell.saveContent(inputPackage.createRelative('lib/acme.jar'), "this is the jar")

def packager = new AgentCliPackager(packagerContext: createPackagerContext(shell),
outputFolder: shell.mkdirs('/out'),
inputPackage: inputPackage,
Expand All @@ -118,6 +123,9 @@ fabrics['f1'] = [ : ]

def expectedResources =
[
"/README.md": 'this is the readme',
"/lib": DIRECTORY,
"/lib/acme.jar": 'this is the jar',
"/conf": DIRECTORY,
"/conf/clientConfig.properties": """#
# Copyright (c) 2010-2010 LinkedIn, Inc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2013 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.setup

import org.linkedin.glu.groovy.utils.shell.Shell
import org.linkedin.glu.groovy.utils.shell.ShellImpl
import org.pongasoft.glu.packaging.setup.ConsoleCliPackager
import org.pongasoft.glu.packaging.setup.PackagedArtifact

/**
* @author yan@pongasoft.com */
public class TestConsoleCliPackager extends BasePackagerTest
{
public void testTutorialModel()
{
ShellImpl.createTempShell { Shell shell ->

def inputPackage = shell.mkdirs("/dist/org.linkedin.glu.console-cli-${GLU_VERSION}")
shell.saveContent(inputPackage.createRelative('README.md'), "this is the readme")
shell.saveContent(inputPackage.createRelative('lib/acme.py'), "this is the python")

def packager = new ConsoleCliPackager(packagerContext: createPackagerContext(shell),
outputFolder: shell.mkdirs('/out'),
inputPackage: inputPackage,
configsRoots: copyConfigs(shell.toResource('/configs')),
metaModel: testModel)

PackagedArtifact artifact = packager.createPackage()

assertEquals(shell.toResource("/out/org.linkedin.glu.console-cli-${GLU_VERSION}"), artifact.location)
assertNull(artifact.host)
assertEquals(0, artifact.port)

def expectedResources =
[
"/README.md": 'this is the readme',
"/lib": DIRECTORY,
"/lib/acme.py": 'this is the python',
]

checkPackageContent(expectedResources, artifact.location)
}
}
}

0 comments on commit 0ec3d34

Please sign in to comment.