Skip to content

Commit

Permalink
#56: fixed issues
Browse files Browse the repository at this point in the history
* fixed some issues with tagging
* fixed GString as a key in map issue
* made some classes more configurable
  • Loading branch information
ypujante committed May 11, 2011
1 parent ebb0cf2 commit 25f2123
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def class AgentImpl implements Agent, AgentContext, Shutdownable
boolean hasTags()
{
handleException {
return !_taggeable.hasTags()
return _taggeable.hasTags()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ class AgentRestClient implements Agent
def response = handleResponse(toMountPointReference(args)) { ClientResource client ->
client.post(toArgs([executeActionAndWaitForState: args]))
}
return getRes(response)
return getRes(response) as boolean
}

public boolean interruptAction(Object args)
{
def response = handleResponse(toMountPointReference(args)) { ClientResource client ->
client.post(toArgs([interruptAction: args]))
}
return getRes(response)
return getRes(response) as boolean
}

public getMountPoints()
Expand Down Expand Up @@ -388,10 +388,13 @@ class AgentRestClient implements Agent

private def getRes(def response)
{
if(response instanceof Status)
return null

if(response instanceof InputStream)
return response
else
return response?.res

return response?.res
}

private def handleResponse(Reference reference, Closure closure)
Expand Down
30 changes: 16 additions & 14 deletions agent/org.linkedin.glu.agent-server-impl/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/*
* Copyright (c) 2010-2010 LinkedIn, Inc
*
* 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.
*/
* Copyright (c) 2010-2010 LinkedIn, Inc
* Portions Copyright (c) 2011 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.
*/

apply plugin: 'groovy'
apply plugin: 'org.linkedin.release'
Expand All @@ -27,6 +28,7 @@ dependencies {
groovy spec.external.groovy

testCompile project(':agent:org.linkedin.glu.agent-rest-client')
testCompile spec.external.junit

runtime spec.external.commonsCli
runtime spec.external.slf4jLog4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
%{--
- Copyright (c) 2010-2010 LinkedIn, Inc
- Portions Copyright (c) 2011 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
Expand Down Expand Up @@ -47,10 +48,12 @@
<th>Error</th>
</tr>
<g:each in="${flash.errors}" var="error">
<tr>
<td>${error.key.encodeAsHTML()}</td>
<td>${error.value.message.encodeAsHTML()}
<div class="flash-stackTrace">${error.value.stackTrace.join('\n').encodeAsHTML()}</div>
</td>
</tr>
</g:each>
</table>
</g:if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<cl:withFabric>
div.env-${fabric.name} {
background-color: ${fabric.color};
background: -webkit-gradient(linear, left top, right top, from(${fabric.color}), to(#ffffff));
background: -webkit-gradient(linear, left top, right top, color-stop(.2, ${fabric.color}),color-stop(1, #ffffff)) fixed no-repeat 0 100%;
background: -moz-linear-gradient(left,${fabric.color} 20%,#ffffff) fixed no-repeat 0 100%;
}
</cl:withFabric>
div#footer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.linkedin.util.lang.LangUtils
import org.linkedin.glu.orchestration.engine.authorization.AuthorizationService
import org.linkedin.util.annotations.Initializable
import org.linkedin.glu.provisioner.impl.agent.DefaultDescriptionProvider
import org.linkedin.glu.provisioner.core.action.IDescriptionProvider

/**
* @author ypujante
Expand All @@ -63,6 +64,9 @@ class AgentsServiceImpl implements AgentsService
@Initializable
AuthorizationService authorizationService

@Initializable
IDescriptionProvider descriptionProvider = DefaultDescriptionProvider.INSTANCE

def getAllInfosWithAccuracy(Fabric fabric)
{
return trackerService.getAllInfosWithAccuracy(fabric)
Expand Down Expand Up @@ -140,7 +144,7 @@ class AgentsServiceImpl implements AgentsService
state = state.toList()
return agentPlanner.createTransitionPlan(installations,
state,
DefaultDescriptionProvider.INSTANCE,
descriptionProvider,
filter)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class DeltaServiceImpl implements DeltaService
@Initializable
AgentsService agentsService

@Initializable
Set<String> includedInVersionMismatch = null

@Initializable
Set<String> excludedInVersionMismatch = null

def computeDelta(Fabric fabric, SystemModel expectedSystem)
{
if(expectedSystem && expectedSystem.fabric != fabric.name)
Expand Down Expand Up @@ -97,17 +103,11 @@ class DeltaServiceImpl implements DeltaService
// here we have both currentEntry and expectedEntry...
emptyAgents.remove(cef.agent)

def initParameters = eef.keySet().findAll { it.startsWith("initParameters.") } +
cef.keySet().findAll { it.startsWith("initParameters.") }
// processing version mismatch
processVersionMismatch(eef, cef)

initParameters.each { n ->
if(eef[n] != cef[n])
{
cef.status = 'versionMismatch'
cef.statusInfo = "${n}:${eef[n]} != ${n}:${cef[n]}".toString()
cef.state = 'ERROR'
}
}
// a chance to add custom processing
processCustomDelta(eef, cef)

if(!cef.state)
{
Expand Down Expand Up @@ -167,6 +167,48 @@ class DeltaServiceImpl implements DeltaService
return entries
}

/**
* By default the version mismatch is computed by comparing all initParameters (+ script). You
* can tweak which ones are taken into account by initializing:
* <code>includedInVersionMismatch</code> or <code>excludedInVersionMismatch</code>.
*
* @param eef expected entry (flattened)
* @param cef current entry (flattened)
*/
protected void processVersionMismatch(Map eef, Map cef)
{
def initParameters = eef.keySet().findAll { it.startsWith("initParameters.") } +
cef.keySet().findAll { it.startsWith("initParameters.") }

initParameters << 'script'

if(includedInVersionMismatch != null)
initParameters = initParameters.findAll { includedInVersionMismatch.contains(it) }

if(excludedInVersionMismatch != null)
initParameters = initParameters.findAll { !excludedInVersionMismatch.contains(it) }

initParameters.each { n ->
if(eef[n] != cef[n])
{
cef.status = 'versionMismatch'
cef.statusInfo = "${n}:${eef[n]} != ${n}:${cef[n]}".toString()
cef.state = 'ERROR'
}
}
}

/**
* Nothing to do here. Subclasses can tweak the delta.
*
* @param eef expected entry (flattened)
* @param cef current entry (flattened)
*/
protected void processCustomDelta(Map eef, Map cef)
{
// nothing to do in this implementation
}

private void setTags(def entry, Collection<String> entryTags)
{
if(entry.key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.linkedin.util.annotations.Initializable
import org.linkedin.util.clock.Clock
import org.linkedin.util.clock.SystemClock
import org.linkedin.util.clock.Timespan
import org.linkedin.glu.provisioner.core.action.IDescriptionProvider

/**
* System service.
Expand Down Expand Up @@ -63,6 +64,9 @@ class DeploymentServiceImpl implements DeploymentService
@Initializable
AuthorizationService authorizationService

@Initializable
IDescriptionProvider descriptionProvider = DefaultDescriptionProvider.INSTANCE

private Map<String, CurrentDeployment> _deployments = [:]
private Map<String, Plan> _plans = [:]

Expand Down Expand Up @@ -253,10 +257,10 @@ class DeploymentServiceImpl implements DeploymentService
Environment expectedEnvironment,
Closure closure)
{
deploymentMgr.createPlan(name,
deploymentMgr.createPlan(name,
currentEnvironment,
expectedEnvironment,
DefaultDescriptionProvider.INSTANCE,
descriptionProvider,
closure)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ class FabricServiceImpl implements FabricService, Destroyable

def zkConnectString = findFabric(fabricName).zkConnectString
configurableFactory?.withRemoteConfigurable(agentName) { Configurable c ->
c.configure(["${prefix}.agent.zkConnectString": zkConnectString])
// YP note: using GString as a key in a map is a recipe for disaster => using string!
def config = [:]
config["${prefix}.agent.zkConnectString".toString()] = zkConnectString
c.configure(config)
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import org.linkedin.glu.agent.tracker.AgentInfo
import org.linkedin.glu.agent.tracker.MountPointInfo
import org.linkedin.glu.agent.api.MountPoint
import org.linkedin.util.annotations.Initializable
import org.linkedin.glu.agent.tracker.PrefixAgentInfoPropertyAccessor
import org.linkedin.glu.agent.tracker.AgentInfoPropertyAccessor

/**
* @author ypujante
Expand All @@ -48,6 +50,9 @@ class TrackerServiceImpl implements TrackerService, Destroyable
@Initializable
String zookeeperRoot = "/org/glu"

@Initializable
AgentInfoPropertyAccessor agentInfoPropertyAccessor = PrefixAgentInfoPropertyAccessor.DEFAULT

private final def _trackers = [:]

Map<String, AgentInfo> getAgentInfos(Fabric fabric)
Expand Down Expand Up @@ -95,6 +100,7 @@ class TrackerServiceImpl implements TrackerService, Destroyable
fabricService.withZkClient(fabric.name) { IZKClient zkClient ->
tracker = new AgentsTrackerImpl(zkClient,
"${zookeeperRoot}/agents/fabrics/${fabricName}".toString())
tracker.agentInfoPropertyAccessor = agentInfoPropertyAccessor
}

_trackers[fabricName] = [tracker: tracker, fabric: fabric]
Expand Down
Loading

0 comments on commit 25f2123

Please sign in to comment.