Skip to content

Commit

Permalink
#58: refactored packaging to use MetaModel concept
Browse files Browse the repository at this point in the history
- added install script
  • Loading branch information
ypujante committed Jul 11, 2013
1 parent 1b29d08 commit 6e60354
Show file tree
Hide file tree
Showing 26 changed files with 275 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ package org.pongasoft.glu.packaging.setup

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

/**
* @author yan@pongasoft.com */
public class AgentCliPackager extends BasePackager
{
AgentCliMetaModel metaModel

@Override
Map<MetaModel, PackagedArtifact> createPackages()
{
[(metaModel): createPackage()]
}

PackagedArtifact createPackage()
{
String packageName = ensureVersion(metaModel.version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.pongasoft.glu.packaging.setup
import org.linkedin.util.io.resource.Resource
import org.pongasoft.glu.provisioner.core.metamodel.AgentMetaModel
import org.pongasoft.glu.provisioner.core.metamodel.GluMetaModel
import org.pongasoft.glu.provisioner.core.metamodel.MetaModel

/**
* @author yan@pongasoft.com */
Expand Down Expand Up @@ -60,15 +61,15 @@ public class AgentServerPackager extends BasePackager

AgentMetaModel metaModel

private def _packagedArtifacts = null
private Map<MetaModel, PackagedArtifact> _packagedArtifacts = null
private Map<String, String> _tokens = null

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

def computePackagedArtifacts()
Map<MetaModel, PackagedArtifact> computePackagedArtifacts()
{
if(!_packagedArtifacts)
{
Expand Down Expand Up @@ -129,22 +130,26 @@ public class AgentServerPackager extends BasePackager
Resource packagePath = outputFolder.createRelative(parts.join('-'))
Resource upgradePackagePath = outputFolder.createRelative(upgradeParts.join('-'))

_packagedArtifacts = [
agentServer: new PackagedArtifact(location: packagePath,
host: metaModel.host.resolveHostAddress(),
port: agentPort,
tokens: _tokens),
agentServerUpgrade: new PackagedArtifact(location: upgradePackagePath,
host: metaModel.host.resolveHostAddress(),
port: agentPort,
tokens: _tokens),
]
_packagedArtifacts = [:]

_packagedArtifacts[metaModel] =
new PackagedArtifact(location: packagePath,
host: metaModel.host.resolveHostAddress(),
port: agentPort,
tokens: _tokens)

_packagedArtifacts[metaModel.agentUpgrade] =
new PackagedArtifact(location: upgradePackagePath,
host: metaModel.host.resolveHostAddress(),
port: agentPort,
tokens: _tokens)
}

return _packagedArtifacts
}

def createPackage()
@Override
Map<MetaModel, PackagedArtifact> createPackages()
{
def packagedArtifacts = computePackagedArtifacts()

Expand All @@ -158,15 +163,15 @@ public class AgentServerPackager extends BasePackager

if(!dryMode)
{
copyInputPackage(packagedArtifacts.agentServer.location)
Resource serverRoot = configure(packagedArtifacts.agentServer.location, tokens)
copyInputPackage(packagedArtifacts[metaModel].location)
Resource serverRoot = configure(packagedArtifacts[metaModel].location, tokens)

if(metaModel.gluMetaModel.stateMachine)
generateStateMachineJarFile(metaModel.gluMetaModel.stateMachine,
serverRoot.createRelative('lib'))

shell.delete(packagedArtifacts.agentServerUpgrade.location)
shell.cp(serverRoot, packagedArtifacts.agentServerUpgrade.location)
shell.delete(packagedArtifacts[metaModel.agentUpgrade].location)
shell.cp(serverRoot, packagedArtifacts[metaModel.agentUpgrade].location)
}

return packagedArtifacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package org.pongasoft.glu.packaging.setup

import org.linkedin.glu.groovy.utils.io.GluGroovyIOUtils
import org.linkedin.glu.groovy.utils.shell.Shell
import org.linkedin.groovy.util.ant.AntUtils
import org.linkedin.groovy.util.io.GroovyIOUtils
import org.linkedin.util.io.resource.Resource
import org.pongasoft.glu.provisioner.core.metamodel.MetaModel
import org.pongasoft.glu.provisioner.core.metamodel.StateMachineMetaModel
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
* @author yan@pongasoft.com */
public class BasePackager
public abstract class BasePackager
{
public static final String MODULE = BasePackager.class.getName();
public static final Logger log = LoggerFactory.getLogger(MODULE);
Expand Down Expand Up @@ -44,6 +44,8 @@ public class BasePackager
fullPackageName - "-${version}"
}

abstract Map<MetaModel, PackagedArtifact> createPackages()

Shell getShell()
{
packagerContext.shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ package org.pongasoft.glu.packaging.setup

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

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

@Override
Map<MetaModel, PackagedArtifact> createPackages()
{
[(metaModel): createPackage()]
}

PackagedArtifact createPackage()
{
String packageName = ensureVersion(metaModel.version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.pongasoft.glu.packaging.setup

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

/**
* @author yan@pongasoft.com */
Expand Down Expand Up @@ -47,6 +48,12 @@ public class ConsoleServerPackager extends BasePackager
metaModel.configTokens
}

@Override
Map<MetaModel, PackagedArtifact> createPackages()
{
[(metaModel): createPackage()]
}

PackagedArtifact createPackage()
{
String packageName = ensureVersion(metaModel.version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ import org.linkedin.util.codec.HexaCodec
import org.linkedin.util.codec.OneWayCodec
import org.linkedin.util.codec.OneWayMessageDigestCodec
import org.linkedin.util.io.resource.Resource
import org.pongasoft.glu.provisioner.core.metamodel.AgentCliMetaModel
import org.pongasoft.glu.provisioner.core.metamodel.AgentMetaModel
import org.pongasoft.glu.provisioner.core.metamodel.ConsoleCliMetaModel
import org.pongasoft.glu.provisioner.core.metamodel.ConsoleMetaModel
import org.pongasoft.glu.provisioner.core.metamodel.GluMetaModel
import org.pongasoft.glu.provisioner.core.metamodel.MetaModel
import org.pongasoft.glu.provisioner.core.metamodel.ZooKeeperClusterMetaModel
import org.pongasoft.glu.provisioner.core.metamodel.ZooKeeperMetaModel
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Expand All @@ -51,11 +55,11 @@ public class GluPackager
Resource outputFolder
Resource keysRoot

def packagedArtifacts = [:]
Map<MetaModel, PackagedArtifact> packagedArtifacts = [:]

boolean dryMode = false

def packageAll()
Map<MetaModel, PackagedArtifact> packageAll()
{
packageAgents()
packageConsoles()
Expand All @@ -73,11 +77,13 @@ public class GluPackager
gluMetaModel.agents.each { AgentMetaModel model ->
AgentServerPackager packager = buildPackager(model)

def pas = packager.computePackagedArtifacts()
Map<MetaModel, PackagedArtifact> pas = packager.computePackagedArtifacts()

def checksum = computeChecksum(pas.agentServer)
PackagedArtifact agent = pas[model]

def packageName = pas.agentServer.location.filename
def checksum = computeChecksum(agent)

def packageName = agent.location.filename
def previousChecksum = checksums[packageName]

if(previousChecksum)
Expand All @@ -90,43 +96,51 @@ public class GluPackager
// no need to generate the package!
if(!dryMode)
{
log.info "Skipped agent package ${pas.agentServer.location} => ${pas.agentServer.host}:${pas.agentServer.port}"
log.info "Skipped agent package ${agent.location} => ${agent.host}:${agent.port}"
}
}
}
else
{
packager.createPackage()
if(!dryMode)
log.info "Generated agent package ${pas.agentServer.location} => ${pas.agentServer.host}:${pas.agentServer.port}"
packagedArtifacts.putAll(packager.createPackages())
displayPackagedArtifact(model, "agent package")
checksums[packageName] = checksum
}

packagedArtifacts[model] = pas
}
}

void packageConsoles()
{
gluMetaModel.consoles.values().each { ConsoleMetaModel model ->
PackagedArtifact pa = packageConsole(model)
packagedArtifacts[model] = pa
if(!dryMode)
log.info "Generated console package ${pa.location} => ${pa.host}:${pa.port}"
Map<MetaModel, PackagedArtifact> pas = packageConsole(model)
packagedArtifacts.putAll(pas)
displayPackagedArtifact(model, "console package")
}
}

void packageZooKeeperClusters()
{
gluMetaModel.zooKeeperClusters.values().each { ZooKeeperClusterMetaModel model ->
def pas = packageZooKeeperCluster(model)
packagedArtifacts[model] = pas
if(!dryMode)
Map<MetaModel, PackagedArtifact> pas = packageZooKeeperCluster(model)
packagedArtifacts.putAll(pas)
model.zooKeepers.each { ZooKeeperMetaModel zkm ->
displayPackagedArtifact(zkm, "ZooKeeper instance [${zkm.serverIdx}]")
}
displayPackagedArtifact(model, "ZooKeeper cluster [${model.name}]")
}
}

protected void displayPackagedArtifact(MetaModel metaModel, String displayName)
{
if(!dryMode)
{
PackagedArtifact pa = packagedArtifacts[metaModel]
if(pa)
{
pas.zooKeepers.each { zki ->
log.info "Generated ZooKeeper instance ${zki.location} => ${zki.host}:${zki.port}"
}
log.info "Generated ZooKeeper cluster ${pas.zooKeeperCluster.location} => ${model.zooKeeperConnectionString}"
String str = "Generated ${displayName} ${pa.location}"
if(pa.host)
str = "${str} => ${pa.host}:${pa.port}"
log.info str
}
}
}
Expand All @@ -145,7 +159,7 @@ public class GluPackager
return packager
}

protected PackagedArtifact packageConsole(ConsoleMetaModel consoleMetaModel)
protected Map<MetaModel, PackagedArtifact> packageConsole(ConsoleMetaModel consoleMetaModel)
{
def out = shell.mkdirs(outputFolder.createRelative('consoles'))
def packager =
Expand All @@ -156,10 +170,10 @@ public class GluPackager
configsRoots: configsRoots,
metaModel: consoleMetaModel,
dryMode: dryMode)
packager.createPackage()
packager.createPackages()
}

protected def packageZooKeeperCluster(ZooKeeperClusterMetaModel zooKeeperClusterMetaModel)
protected Map<MetaModel, PackagedArtifact> packageZooKeeperCluster(ZooKeeperClusterMetaModel zooKeeperClusterMetaModel)
{
def out = shell.mkdirs(outputFolder.createRelative('zookeeper-clusters'))
def packager =
Expand All @@ -170,57 +184,47 @@ public class GluPackager
configsRoots: configsRoots,
metaModel: zooKeeperClusterMetaModel,
dryMode: dryMode)
packager.createPackage()
packager.createPackages()
}

protected PackagedArtifact packageAgentCli()
protected void packageAgentCli()
{
AgentCliMetaModel agentCliMetaModel = gluMetaModel.agentCli

def out = shell.mkdirs(outputFolder.createRelative('agent-cli'))
def packager =
new AgentCliPackager(packagerContext: createPackagerContext(),
outputFolder: out,
inputPackage: getInputPackage('org.linkedin.glu.agent-cli',
gluMetaModel.gluVersion),
configsRoots: configsRoots,
metaModel: gluMetaModel,
metaModel: agentCliMetaModel,
dryMode: dryMode)

PackagedArtifact pa = packager.createPackage()

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

packagedArtifacts[gluMetaModel].agentCli = pa
packagedArtifacts.putAll(packager.createPackages())

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

return pa
println "Generated agent-cli package ${packagedArtifacts[agentCliMetaModel].location}"
}

protected PackagedArtifact packageConsoleCli()
protected void packageConsoleCli()
{
ConsoleCliMetaModel consoleCliMetaModel = gluMetaModel.consoleCli

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,
metaModel: consoleCliMetaModel,
dryMode: dryMode)

PackagedArtifact pa = packager.createPackage()

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

packagedArtifacts[gluMetaModel].consoleCli = pa
packagedArtifacts.putAll(packager.createPackages())

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

return pa
println "Generated console-cli package ${packagedArtifacts[consoleCliMetaModel].location}"
}

protected PackagerContext createPackagerContext()
Expand Down
Loading

0 comments on commit 6e60354

Please sign in to comment.