String generateCodeToExecute ( String className , Instance instance , PuppetState puppetState , Import importChanged , boolean importAdded ) { // When executed by hand, the "apply" command would expect // this string to be returned to be between double quotes. // Example: "class{ 'roboconf_redis': ... }" // However, this does not work when executed from a Process builder. // The double quotes must be removed so that it works. StringBuilder sb = new StringBuilder ( ) ; sb . append ( "class{'" ) ; sb . append ( className ) ; sb . append ( "': runningState => " ) ; sb . append ( puppetState . toString ( ) . toLowerCase ( ) ) ; // Prepare the injection of variables into the Puppet receipt Map < String , String > exports = InstanceHelpers . findAllExportedVariables ( instance ) ; String args = formatExportedVariables ( exports ) ; String importedTypes = formatInstanceImports ( instance ) ; if ( ! Utils . isEmptyOrWhitespaces ( args ) ) sb . append ( ", " + args ) ; if ( ! Utils . isEmptyOrWhitespaces ( importedTypes ) ) sb . append ( ", " + importedTypes ) ; if ( importChanged != null ) { String componentName = importChanged . getComponentName ( ) ; sb . append ( ", importDiff => {" + ( importAdded ? "added => {" : "removed => {" ) + formatImport ( importChanged ) + "}, " + ( importAdded ? "removed => undef" : "added => undef" ) + ", component => " + ( componentName != null ? componentName : "undef" ) + "}" ) ; } sb . append ( "}" ) ; return sb . toString ( ) ; }
Generates the code to be injected by Puppet into the manifest .