Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#114: poc for plugin mechanism
- Loading branch information
Showing
11 changed files
with
402 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...engine/src/main/groovy/org/linkedin/glu/orchestration/engine/plugins/PluginService.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.orchestration.engine.plugins | ||
|
||
/** | ||
* @author yan@pongasoft.com */ | ||
public interface PluginService | ||
{ | ||
void initializePlugin(String pluginClassname, Map initParameters) | ||
|
||
void initializePlugin(Map plugin, Map initParameters) | ||
|
||
void executeMethod(Class targetService, String pluginMethod, Map pluginArgs) | ||
|
||
def executePrePostMethods(Class targetService, | ||
String pluginMethod, | ||
Map pluginArgs, | ||
Closure serviceClosure) | ||
} |
106 changes: 106 additions & 0 deletions
106
...ne/src/main/groovy/org/linkedin/glu/orchestration/engine/plugins/PluginServiceImpl.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* 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.orchestration.engine.plugins | ||
|
||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import org.linkedin.util.reflect.ReflectUtils | ||
|
||
/** | ||
* @author yan@pongasoft.com */ | ||
public class PluginServiceImpl implements PluginService | ||
{ | ||
public static final String MODULE = PluginService.class.getName(); | ||
public static final Logger log = LoggerFactory.getLogger(MODULE); | ||
|
||
def plugin | ||
|
||
@Override | ||
void initializePlugin(String pluginClassname, Map initParameters) | ||
{ | ||
if(pluginClassname) | ||
{ | ||
log.info("Initializing plugin [${pluginClassname}]") | ||
plugin = ReflectUtils.forName(pluginClassname).newInstance() | ||
executeMethod(PluginService, 'initialize', initParameters) | ||
} | ||
} | ||
|
||
@Override | ||
void initializePlugin(Map plugin, Map initParameters) | ||
{ | ||
log.info("Initializing plugin from map") | ||
this.plugin = plugin | ||
executeMethod(PluginService, 'initialize', initParameters) | ||
} | ||
|
||
@Override | ||
void executeMethod(Class targetService, String pluginMethod, Map pluginArgs) | ||
{ | ||
executePluginClosure("${targetService.simpleName}_${pluginMethod}", pluginArgs) | ||
} | ||
|
||
@Override | ||
def executePrePostMethods(Class targetService, | ||
String pluginMethod, | ||
Map pluginArgs, | ||
Closure serviceClosure) | ||
{ | ||
executePluginClosure("${targetService.simpleName}_pre_${pluginMethod}", pluginArgs) | ||
|
||
try | ||
{ | ||
def res = serviceClosure() | ||
|
||
def args = [:] | ||
if(pluginArgs) | ||
args.putAll(pluginArgs) | ||
args.serviceResult = res | ||
executePluginClosure("${targetService.simpleName}_post_${pluginMethod}", | ||
args) | ||
return res | ||
} | ||
catch(Throwable th) | ||
{ | ||
def args = [:] | ||
if(pluginArgs) | ||
args.putAll(pluginArgs) | ||
args.serviceException = th | ||
executePluginClosure("${targetService.simpleName}_post_${pluginMethod}", | ||
args) | ||
throw th | ||
} | ||
} | ||
|
||
private void executePluginClosure(String closureName, Map pluginArgs) | ||
{ | ||
def closure = null | ||
|
||
if(plugin instanceof Map) | ||
{ | ||
closure = plugin[closureName] | ||
} | ||
else | ||
{ | ||
if(plugin?.hasProperty(closureName)) | ||
closure = plugin."${closureName}" | ||
} | ||
|
||
if(closure) | ||
closure(pluginArgs) | ||
} | ||
} |
Oops, something went wrong.