Skip to content

Instantly share code, notes, and snippets.

@ypujante
Created December 12, 2011 18:33
Show Gist options
  • Save ypujante/1468479 to your computer and use it in GitHub Desktop.
Save ypujante/1468479 to your computer and use it in GitHub Desktop.
RFC glu plugin
/*
* 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.
*/
package org.linkedin.glu.console.provisioner.services
import java.security.AccessControlException
/**
* @author [email protected] */
public class MyPlugin
{
// spring application context used by grails to initialize the application
def applicationContext
// the defaults from the console config file
def defaults
/**
* This closure is called (if present) to initialize the plugin
*
* @param args.applicationContext spring application context used by grails to initialize the application
* @param args.defaults the defaults section from the console config file
*/
def PluginService_initialize = { args ->
println "instantiating MyPlugin!"
applicationContext = args.applicationContext
defaults = args.defaults
}
/**
* This closure is called right before executing a plan (you can prevent the execution by throwing
* an <code>AccessControlException</code> exception). This is the perfect place to add your own
* set of checks and/or logging.
*
* @param args.model the <code>SystemModel</code> used to generate the plan
* @param args.plan the <code>Plan</code> that will be executed
* @param args.description the description
*/
def DeploymentService_pre_executeDeploymentPlan = { args ->
println "from plugin DeploymentService_pre_executeDeploymentPlan => ${args}"
String username = applicationContext.getBean('authorizationService').executingPrincipal
if(username == 'glur')
throw new AccessControlException("glur is not authorized to execute a plan...")
}
/**
* This closure is called when the deployment plan completes. This is the perfect place to hook
* your own reporting (like sending an email)
*
* @param args.model the <code>SystemModel</code> used to generate the plan
* @param args.plan the <code>Plan</code> that will be executed
* @param args.description the description
* @param args.serviceResult the <code>IPlanExecution</code> which contains the details of the execution
*/
def DeploymentService_post_executeDeploymentPlan = { args ->
println "from plugin DeploymentService_post_executeDeploymentPlan => ${args}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment