Repository: airavata Updated Branches: refs/heads/master aa27ce109 -> 97c7a7362
Adding python and re-arranging the script - AIRAVATA-1641 Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/c090519a Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/c090519a Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/c090519a Branch: refs/heads/master Commit: c090519ae2198c1d2624760c8200fb5ebf36b6be Parents: aa27ce1 Author: Suresh Marru <[email protected]> Authored: Tue Mar 24 05:05:22 2015 -0400 Committer: Suresh Marru <[email protected]> Committed: Tue Mar 24 05:05:22 2015 -0400 ---------------------------------------------------------------------- airavata-api/generate-thrift-files.sh | 256 +++++++++++++++++++---------- 1 file changed, 173 insertions(+), 83 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/c090519a/airavata-api/generate-thrift-files.sh ---------------------------------------------------------------------- diff --git a/airavata-api/generate-thrift-files.sh b/airavata-api/generate-thrift-files.sh index c8a000d..88d38ea 100755 --- a/airavata-api/generate-thrift-files.sh +++ b/airavata-api/generate-thrift-files.sh @@ -15,19 +15,62 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This script will regenerate the thrift code for Airavata Server Skeletons, Client Stubs and Data Model java beans. -# -# Credit: This script was created referring to Apache Accumulo project and tuned to Airavata Needs. +# This script will generate/regenerate the thrift code for Airavata Server Skeletons, Client Stubs +# and Data Model java beans in java, C++, PHP and Python. + +show_usage() { + echo -e "Usage: $0 [Languague to generate stubs]" + echo "" + echo "options:" + echo -e "\tjava Generate/Update Java Stubs" + echo -e "\tphp Generate/Update PHP Stubs" + echo -e "\tcpp Generate/Update C++ Stubs" + echo -e "\tpython Generate/Update Python Stubs." + echo -e "\tall Generate/Update all stubs (Java, PHP, C++, Python)." + echo -e "\t-h[elp] Print the usage options of this script" +} + +if [ $# -lt 1 ] +then + show_usage + exit 1 +fi + +if [[ $1 == "-h" ||$1 == "--help" ]] +then + show_usage + exit 0 +fi + +# Generation of thrift files will require installing Apache Thrift. Please add thrift to your path. +# Verify is thrift is installed, is in the path is at a specified version. -# Global Constants used across the script REQUIRED_THRIFT_VERSION='0.9.1' +THRIFT_EXEC=/usr/local/Cellar/thrift/0.9.1/bin/thrift + +VERSION=$($THRIFT_EXEC -version 2>/dev/null | grep -F "${REQUIRED_THRIFT_VERSION}" | wc -l) +if [ "$VERSION" -ne 1 ] ; then + echo -e "ERROR:\t Apache Thrift version ${REQUIRED_THRIFT_VERSION} is required." + echo -e "It is either not installed or is not in the path" + exit 1 +fi + +# Global Constants used across the script THRIFT_IDL_DIR='thrift-interface-descriptions' BASE_TARGET_DIR='target' DATAMODEL_SRC_DIR='airavata-data-models/src/main/java' JAVA_API_SDK_DIR='airavata-api-stubs/src/main/java' -CPP_SDK_DIR='airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/' PHP_SDK_DIR='airavata-client-sdks/airavata-php-sdk/src/main/resources/lib' -THRIFT_EXEC=/usr/local/Cellar/thrift/0.9.1/bin/thrift +CPP_SDK_DIR='airavata-client-sdks/airavata-cpp-sdk/src/main/resources/lib/airavata/' +PYTHON_SDK_DIR='airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/' + +# Initialize the thrift arguments. +# Since most of the Airavata API and Data Models have includes, use recursive option by default. +# Generate all the files in target directory +THRIFT_ARGS="-r -o ${BASE_TARGET_DIR}" +# Ensure the required target directories exists, if not create. +mkdir -p ${BASE_TARGET_DIR} + # The Function fail prints error messages on failure and quits the script. fail() { echo $@ @@ -94,116 +137,164 @@ copy_changed_files() { rsync -auv ${GENERATED_CODE_DIR}/ ${WORKSPACE_SRC_DIR} } -# Generation of thrift files will require installing Apache Thrift. Please add thrift to your path. -# Verify is thrift is installed, is in the path is at a specified version. -VERSION=$($THRIFT_EXEC -version 2>/dev/null | grep -F "${REQUIRED_THRIFT_VERSION}" | wc -l) -if [ "$VERSION" -ne 1 ] ; then - echo "****************************************************" - echo "*** thrift is not installed or is not in the path" - echo "*** expecting 'thrift -version' to return ${REQUIRED_THRIFT_VERSION}" - echo "*** generated code will not be updated" - fail "****************************************************" -fi - -# Initialize the thrift arguments. -# Since most of the Airavata API and Data Models have includes, use recursive option by default. -# Generate all the files in target directory -THRIFT_ARGS="-r -o ${BASE_TARGET_DIR}" -# Ensure the required target directories exists, if not create. -mkdir -p ${BASE_TARGET_DIR} - ####################################### # Generate/Update Airavata Data Model # ####################################### -#Java Beans generation directory -JAVA_BEAN_GEN_DIR=${BASE_TARGET_DIR}/gen-javabean +generate_java_stubs() { -# As a precaution remove and previously generated files if exists -rm -rf ${JAVA_BEAN_GEN_DIR} + #Java Beans generation directory + JAVA_BEAN_GEN_DIR=${BASE_TARGET_DIR}/gen-javabean -# Generate the Airavata Data Model using thrift Java Beans generator. This will take generate the classes in bean style -# with members being private and setters returning voids. -# The airavataDataModel.thrift includes rest of data models. -$THRIFT_EXEC ${THRIFT_ARGS} --gen java:beans ${THRIFT_IDL_DIR}/airavataDataModel.thrift || fail unable to generate java bean thrift classes on base data model + # As a precaution remove and previously generated files if exists + rm -rf ${JAVA_BEAN_GEN_DIR} -$THRIFT_EXEC ${THRIFT_ARGS} --gen java:beans ${THRIFT_IDL_DIR}/appCatalogModels.thrift || fail unable to generate java bean thrift classes on app catalog data models + # Generate the Airavata Data Model using thrift Java Beans generator. This will take generate the classes in bean style + # with members being private and setters returning voids. + # The airavataDataModel.thrift includes rest of data models. + $THRIFT_EXEC ${THRIFT_ARGS} --gen java:beans ${THRIFT_IDL_DIR}/airavataDataModel.thrift || fail unable to generate java bean thrift classes on base data model -$THRIFT_EXEC ${THRIFT_ARGS} --gen java:beans ${THRIFT_IDL_DIR}/workflowDataModel.thrift || fail unable to generate java bean thrift classes on app workflow data models + $THRIFT_EXEC ${THRIFT_ARGS} --gen java:beans ${THRIFT_IDL_DIR}/appCatalogModels.thrift || fail unable to generate java bean thrift classes on app catalog data models -# For the generated java beans add the ASF V2 License header -add_license_header $JAVA_BEAN_GEN_DIR + $THRIFT_EXEC ${THRIFT_ARGS} --gen java:beans ${THRIFT_IDL_DIR}/workflowDataModel.thrift || fail unable to generate java bean thrift classes on app workflow data models -# Compare the newly generated beans with existing sources and replace the changed ones. -copy_changed_files ${JAVA_BEAN_GEN_DIR} ${DATAMODEL_SRC_DIR} + # For the generated java beans add the ASF V2 License header + add_license_header $JAVA_BEAN_GEN_DIR -############################################################################### -# Generate/Update source used by Airavata Server Skeletons & Java Client Stubs # -# JAVA server and client both use generated api-boilerplate-code # -############################################################################### + # Compare the newly generated beans with existing sources and replace the changed ones. + copy_changed_files ${JAVA_BEAN_GEN_DIR} ${DATAMODEL_SRC_DIR} -#Java generation directory -JAVA_GEN_DIR=${BASE_TARGET_DIR}/gen-java + ############################################################################### + # Generate/Update source used by Airavata Server Skeletons & Java Client Stubs # + # JAVA server and client both use generated api-boilerplate-code # + ############################################################################### -# As a precaution remove and previously generated files if exists -rm -rf ${JAVA_GEN_DIR} + #Java generation directory + JAVA_GEN_DIR=${BASE_TARGET_DIR}/gen-java -# Using thrift Java generator, generate the java classes based on Airavata API. This -# The airavataAPI.thrift includes rest of data models. -$THRIFT_EXEC ${THRIFT_ARGS} --gen java ${THRIFT_IDL_DIR}/airavataAPI.thrift || fail unable to generate java thrift classes on AiravataAPI + # As a precaution remove and previously generated files if exists + rm -rf ${JAVA_GEN_DIR} -#$THRIFT_EXEC ${THRIFT_ARGS} --gen java ${THRIFT_IDL_DIR}/workflowAPI.thrift || fail unable to generate java thrift classes on WorkflowAPI + # Using thrift Java generator, generate the java classes based on Airavata API. This + # The airavataAPI.thrift includes rest of data models. + $THRIFT_EXEC ${THRIFT_ARGS} --gen java ${THRIFT_IDL_DIR}/airavataAPI.thrift || fail unable to generate java thrift classes on AiravataAPI -# For the generated java classes add the ASF V2 License header -add_license_header $JAVA_GEN_DIR + #$THRIFT_EXEC ${THRIFT_ARGS} --gen java ${THRIFT_IDL_DIR}/workflowAPI.thrift || fail unable to generate java thrift classes on WorkflowAPI -# Compare the newly generated classes with existing java generated skeleton/stub sources and replace the changed ones. -# Only copying the API related classes and avoiding copy of any data models which already exist in the data-models. -copy_changed_files ${JAVA_GEN_DIR}/org/apache/airavata/api ${JAVA_API_SDK_DIR}/org/apache/airavata/api + # For the generated java classes add the ASF V2 License header + add_license_header $JAVA_GEN_DIR + + # Compare the newly generated classes with existing java generated skeleton/stub sources and replace the changed ones. + # Only copying the API related classes and avoiding copy of any data models which already exist in the data-models. + copy_changed_files ${JAVA_GEN_DIR}/org/apache/airavata/api ${JAVA_API_SDK_DIR}/org/apache/airavata/api + + echo "Successfully generated new java sources, compared against exiting code and replaced the changed files" +} + +#################################### +# Generate/Update PHP Stubs # +#################################### + +generate_php_stubs() { + + #PHP generation directory + PHP_GEN_DIR=${BASE_TARGET_DIR}/gen-php + + # As a precaution remove and previously generated files if exists + rm -rf ${PHP_GEN_DIR} + + # Using thrift Java generator, generate the java classes based on Airavata API. This + # The airavataAPI.thrift includes rest of data models. + $THRIFT_EXEC ${THRIFT_ARGS} --gen php:autoload ${THRIFT_IDL_DIR}/airavataAPI.thrift || fail unable to generate PHP thrift classes + + #$THRIFT_EXEC ${THRIFT_ARGS} --gen php:autoload ${THRIFT_IDL_DIR}/workflowAPI.thrift || fail unable to generate PHP thrift classes for WorkflowAPI + # For the generated java classes add the ASF V2 License header + ## TODO Write PHP license parser + + # Compare the newly generated classes with existing java generated skeleton/stub sources and replace the changed ones. + # Only copying the API related classes and avoiding copy of any data models which already exist in the data-models. + copy_changed_files ${PHP_GEN_DIR} ${PHP_SDK_DIR} + +} #################################### # Generate/Update C++ Client Stubs # #################################### -#CPP generation directory -CPP_GEN_DIR=${BASE_TARGET_DIR}/gen-cpp +generate_cpp_stubs() { + + #CPP generation directory + CPP_GEN_DIR=${BASE_TARGET_DIR}/gen-cpp -# As a precaution remove and previously generated files if exists -rm -rf ${CPP_GEN_DIR} + # As a precaution remove and previously generated files if exists + rm -rf ${CPP_GEN_DIR} -# Using thrift Java generator, generate the java classes based on Airavata API. This -# The airavataAPI.thrift includes rest of data models. -/usr/local/Cellar/thrift/0.9.1/bin/thrift ${THRIFT_ARGS} --gen cpp ${THRIFT_IDL_DIR}/airavataAPI.thrift || fail unable to generate C++ thrift classes + # Using thrift Java generator, generate the java classes based on Airavata API. This + # The airavataAPI.thrift includes rest of data models. + $THRIFT_EXEC ${THRIFT_ARGS} --gen cpp ${THRIFT_IDL_DIR}/airavataAPI.thrift || fail unable to generate C++ thrift classes -#$THRIFT_EXEC ${THRIFT_ARGS} --gen cpp ${THRIFT_IDL_DIR}/workflowAPI.thrift || fail unable to generate C++ thrift classes for WorkflowAPI -# For the generated CPP classes add the ASF V2 License header -add_license_header $CPP_GEN_DIR + #$THRIFT_EXEC ${THRIFT_ARGS} --gen cpp ${THRIFT_IDL_DIR}/workflowAPI.thrift || fail unable to generate C++ thrift classes for WorkflowAPI + # For the generated CPP classes add the ASF V2 License header + add_license_header $CPP_GEN_DIR -# Compare the newly generated classes with existing java generated skeleton/stub sources and replace the changed ones. -# Only copying the API related classes and avoiding copy of any data models which already exist in the data-models. -copy_changed_files ${CPP_GEN_DIR} ${CPP_SDK_DIR} + # Compare the newly generated classes with existing java generated skeleton/stub sources and replace the changed ones. + # Only copying the API related classes and avoiding copy of any data models which already exist in the data-models. + copy_changed_files ${CPP_GEN_DIR} ${CPP_SDK_DIR} + +} #################################### -# Generate/Update PHP Stubs # +# Generate/Update C++ Client Stubs # #################################### -#PHP generation directory -PHP_GEN_DIR=${BASE_TARGET_DIR}/gen-php +generate_python_stubs() { -# As a precaution remove and previously generated files if exists -rm -rf ${PHP_GEN_DIR} + #Python generation directory + PYTHON_GEN_DIR=${BASE_TARGET_DIR}/gen-py -# Using thrift Java generator, generate the java classes based on Airavata API. This -# The airavataAPI.thrift includes rest of data models. -$THRIFT_EXEC ${THRIFT_ARGS} --gen php:autoload ${THRIFT_IDL_DIR}/airavataAPI.thrift || fail unable to generate PHP thrift classes + # As a precaution remove and previously generated files if exists + rm -rf ${PYTHON_GEN_DIR} -#$THRIFT_EXEC ${THRIFT_ARGS} --gen php:autoload ${THRIFT_IDL_DIR}/workflowAPI.thrift || fail unable to generate PHP thrift classes for WorkflowAPI -# For the generated java classes add the ASF V2 License header -## TODO Write PHP license parser + # Using thrift Python generator, generate the python classes based on Airavata API. This + # The airavataAPI.thrift includes rest of data models. + $THRIFT_EXEC ${THRIFT_ARGS} --gen py ${THRIFT_IDL_DIR}/airavataAPI.thrift || fail unable to generate Python thrift classes + + # For the generated CPP classes add the ASF V2 License header + #add_license_header #PYTHON_GEN_DIR + + # Compare the newly generated classes with existing java generated skeleton/stub sources and replace the changed ones. + # Only copying the API related classes and avoiding copy of any data models which already exist in the data-models. + copy_changed_files ${PYTHON_GEN_DIR} ${PYTHON_SDK_DIR} + +} -# Compare the newly generated classes with existing java generated skeleton/stub sources and replace the changed ones. -# Only copying the API related classes and avoiding copy of any data models which already exist in the data-models. -copy_changed_files ${PHP_GEN_DIR} ${PHP_SDK_DIR} +for arg in "$@" +do + case "$arg" in + all) echo "Generate all stubs (Java, PHP, C++, Python) Stubs" + generate_java_stubs + generate_php_stubs + generate_cpp_stubs + generate_python_stubs + ;; + java) echo "Generating Java Stubs" + generate_java_stubs + ;; + php) echo "Generate PHP Stubs" + generate_php_stubs + ;; + cpp) echo "Generate C++ Stubs" + generate_cpp_stubs + ;; + python) echo "Generate Python Stubs" + generate_python_stubs + ;; + *) echo "Invalid or unsupported option" + show_usage + exit 1 + ;; + esac +done #################### # Cleanup and Exit # @@ -211,5 +302,4 @@ copy_changed_files ${PHP_GEN_DIR} ${PHP_SDK_DIR} # CleanUp: Delete the base target build directory #rm -rf ${BASE_TARGET_DIR} -echo "Successfully generated new sources, compared against exiting code and replaced the changed files" exit 0
