Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Commit 4faadf3

Browse files
committed
Enable build in batch repo.
1 parent f249299 commit 4faadf3

File tree

7 files changed

+491
-17
lines changed

7 files changed

+491
-17
lines changed

.gitignore

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
*.class
2+
3+
# Auth files
4+
*.auth
5+
*.azureauth
6+
7+
# Local checkstyle
8+
*.checkstyle
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.ear
17+
18+
# Azure Tooling #
19+
node_modules
20+
packages
21+
22+
# Eclipse #
23+
*.pydevproject
24+
.project
25+
.metadata
26+
bin/**
27+
tmp/**
28+
tmp/**/*
29+
*.tmp
30+
*.bak
31+
*.swp
32+
*~.nib
33+
local.properties
34+
.classpath
35+
.settings/
36+
.loadpath
37+
38+
# Other Tooling #
39+
.classpath
40+
.project
41+
target
42+
.idea
43+
*.iml
44+
45+
# Mac OS #
46+
.DS_Store
47+
.DS_Store?
48+
49+
# Windows #
50+
Thumbs.db
51+
52+
# reduced pom files should not be included
53+
dependency-reduced-pom.xml

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: java
2+
sudo: false
3+
jdk:
4+
- oraclejdk7
5+
- oraclejdk8
6+
- openjdk7
7+
script:
8+
- mvn install -DskipTests=true
9+
- mvn package javadoc:aggregate -DskipTests=true

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Microsoft
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
[![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)
2+
3+
#Azure Batch Libraries for Java
4+
5+
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)
6+
7+
The Azure Batch Libraries for Java is a higher-level, object-oriented API for interacting with the Azure Batch service.
8+
9+
10+
> **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.
11+
12+
**Azure Batch Authentication**
13+
14+
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.
15+
The `BatchClient` class is the simplest entry point for creating and interacting with Azure Batch objects.
16+
17+
```java
18+
BatchSharedKeyCredentials cred = new BatchSharedKeyCredentials(batchUri, batchAccount, batchKey);
19+
BatchClient client = BatchClient.Open(cred);
20+
```
21+
22+
**Create a pool using an Azure Marketplace image**
23+
24+
You can create a pool of Azure virtual machines which can be used to execute tasks.
25+
26+
```java
27+
System.out.println("Created a pool using an Azure Marketplace image.");
28+
29+
VirtualMachineConfiguration configuration = new VirtualMachineConfiguration();
30+
configuration.setNodeAgentSKUId(skuId).setImageReference(imageRef);
31+
client.getPoolOperations().createPool(poolId, poolVMSize, configuration, poolVMCount);
32+
33+
System.out.println("Created an IaaS Pool: " + poolId);
34+
```
35+
36+
**Create a Job**
37+
38+
You can create a job by using the recently created pool.
39+
40+
```java
41+
PoolInformation poolInfo = new PoolInformation();
42+
poolInfo.setPoolId(poolId);
43+
client.getJobOperations().createJob(jobId, poolInfo);
44+
```
45+
46+
#Sample Code
47+
48+
You can find sample code that illustrates Batch usage scenarios in https://github.com/azure/azure-batch-samples
49+
50+
51+
# Download
52+
53+
54+
**1.0.0-beta2**
55+
56+
If you are using released builds from 1.0.0-beta2, add the following to your POM file:
57+
58+
```xml
59+
<dependency>
60+
<groupId>com.microsoft.azure</groupId>
61+
<artifactId>azure-batch</artifactId>
62+
<version>1.0.0-beta2</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>com.microsoft.rest</groupId>
66+
<artifactId>client-runtime</artifactId>
67+
<version>1.0.0-beta2</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>com.microsoft.azure</groupId>
71+
<artifactId>azure-client-runtime</artifactId>
72+
<version>1.0.0-beta2</version>
73+
</dependency>
74+
```
75+
76+
#Pre-requisites
77+
78+
- A Java Developer Kit (JDK), v 1.7 or later
79+
- Maven
80+
- Azure Service Principal - see [how to create authentication info](./AUTH.md).
81+
82+
83+
## Help
84+
85+
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).
86+
87+
#Contribute Code
88+
89+
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).
90+
91+
1. Fork it
92+
2. Create your feature branch (`git checkout -b my-new-feature`)
93+
3. Commit your changes (`git commit -am 'Add some feature'`)
94+
4. Push to the branch (`git push origin my-new-feature`)
95+
5. Create new Pull Request
96+
97+
#More Information
98+
* [Javadoc](http://azure.github.io/azure-sdk-for-java)
99+
* [http://azure.com/java](http://azure.com/java)
100+
* If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212)
101+
102+
**Previous Releases and Corresponding Repo Branches**
103+
104+
| Version | SHA1 | Remarks |
105+
|-------------------|-------------------------------------------------------------------------------------------|-------------------------------------------------------|
106+
| 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 |
107+
| 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 |
108+
| 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 |
109+
| 0.9.x-SNAPSHOTS | [0.9](https://github.com/Azure/azure-sdk-for-java/tree/0.9) | Maintenance branch for service management libraries |
110+
| 0.9.3 | [v0.9.3](https://github.com/Azure/azure-sdk-for-java/tree/v0.9.3) | Latest release for service management libraries |
111+
112+
---
113+
114+
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 [[email protected]](mailto:[email protected]) with any additional questions or comments.

gulpfile.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
var gulp = require('gulp');
2+
var args = require('yargs').argv;
3+
var colors = require('colors');
4+
var exec = require('child_process').exec;
5+
var fs = require('fs');
6+
7+
var mappings = {
8+
'batchService': {
9+
'source': 'batch/2016-07-01.3.1/swagger/BatchService.json',
10+
'package': 'com.microsoft.azure.batch.protocol',
11+
'fluent': false,
12+
'args': '-FT 1'
13+
}
14+
};
15+
16+
gulp.task('default', function() {
17+
console.log("Usage: gulp codegen [--spec-root <swagger specs root>] [--autorest <autorest info>] [--modeler <modeler name>] [--autorest-args <AutoRest arguments>]\n");
18+
console.log("--spec-root");
19+
console.log("\tRoot location of Swagger API specs, default value is \"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master\"");
20+
console.log("--autorest\n\tThe version of AutoRest. E.g. 0.15.0, or the location of AutoRest repo, E.g. E:\\repo\\autorest");
21+
console.log("--modeler\n\tSpecifies which modeler to use. Default is 'Swagger'");
22+
console.log("--autorest-args\n\tPasses additional argument to AutoRest generator");
23+
});
24+
25+
var isWindows = (process.platform.lastIndexOf('win') === 0);
26+
var isLinux= (process.platform.lastIndexOf('linux') === 0);
27+
var isMac = (process.platform.lastIndexOf('darwin') === 0);
28+
29+
var specRoot = args['spec-root'] || "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master";
30+
var projects = 'batchService'; // default
31+
var autoRestVersion = '0.17.0-Nightly20160706'; // default
32+
if (args['autorest'] !== undefined) {
33+
autoRestVersion = args['autorest'];
34+
}
35+
var modeler = 'Swagger'; // default
36+
if (args['modeler'] !== undefined) {
37+
modeler = args['modeler'];
38+
}
39+
var autoRestArgs = args['autorest-args'];
40+
var autoRestExe;
41+
42+
gulp.task('codegen', function(cb) {
43+
var nugetSource = 'https://www.myget.org/F/autorest/api/v2';
44+
if (autoRestVersion.match(/[0-9]+\.[0-9]+\.[0-9]+.*/)) {
45+
autoRestExe = 'packages\\autorest.' + autoRestVersion + '\\tools\\AutoRest.exe';
46+
exec('tools\\nuget.exe install AutoRest -Source ' + nugetSource + ' -Version ' + autoRestVersion + ' -o packages', function(err, stdout, stderr) {
47+
console.log(stdout);
48+
console.error(stderr);
49+
handleInput(projects, cb);
50+
});
51+
} else {
52+
autoRestExe = autoRestVersion + "/" + GetAutoRestFolder() + "AutoRest.exe";
53+
if (!isWindows) {
54+
autoRestExe = "mono " + autoRestExe;
55+
}
56+
handleInput(projects, cb);
57+
}
58+
59+
});
60+
61+
var handleInput = function(projects, cb) {
62+
if (projects === undefined) {
63+
Object.keys(mappings).forEach(function(proj) {
64+
codegen(proj, cb);
65+
});
66+
} else {
67+
projects.split(",").forEach(function(proj) {
68+
proj = proj.replace(/\ /g, '');
69+
if (mappings[proj] === undefined) {
70+
console.error('Invalid project name "' + proj + '"!');
71+
process.exit(1);
72+
}
73+
codegen(proj, cb);
74+
});
75+
}
76+
}
77+
78+
var codegen = function(project, cb) {
79+
var outputDir = 'src/main/java/' + mappings[project].package.replace(/\./g, '/');
80+
deleteFolderRecursive(outputDir);
81+
console.log('Generating "' + project + '" from spec file ' + specRoot + '/' + mappings[project].source);
82+
var generator = 'Azure.Java.Fluent';
83+
if (mappings[project].fluent !== null && mappings[project].fluent === false) {
84+
generator = 'Azure.Java';
85+
}
86+
cmd = autoRestExe + ' -Modeler ' + modeler +
87+
' -CodeGenerator ' + generator +
88+
' -Namespace ' + mappings[project].package +
89+
' -Input ' + specRoot + '/' + mappings[project].source +
90+
' -outputDirectory ' + 'src/main/java/' + mappings[project].package.replace(/\./g, '/') +
91+
' -Header MICROSOFT_MIT_NO_CODEGEN' +
92+
' -' + autoRestArgs;
93+
if (mappings[project].args !== undefined) {
94+
cmd = cmd + ' ' + mappings[project].args;
95+
}
96+
console.log('Command: ' + cmd);
97+
exec(cmd, function(err, stdout, stderr) {
98+
console.log(stdout);
99+
console.error(stderr);
100+
});
101+
};
102+
103+
var deleteFolderRecursive = function(path) {
104+
var header = "Code generated by Microsoft (R) AutoRest Code Generator";
105+
if(fs.existsSync(path)) {
106+
fs.readdirSync(path).forEach(function(file, index) {
107+
var curPath = path + "/" + file;
108+
if(fs.lstatSync(curPath).isDirectory()) { // recurse
109+
deleteFolderRecursive(curPath);
110+
} else { // delete file
111+
var content = fs.readFileSync(curPath).toString('utf8');
112+
if (content.indexOf(header) > -1) {
113+
fs.unlinkSync(curPath);
114+
}
115+
}
116+
});
117+
}
118+
};
119+
120+
function GetAutoRestFolder() {
121+
if (isWindows) {
122+
return "src/core/AutoRest/bin/Debug/net451/win7-x64/";
123+
}
124+
if( isMac ) {
125+
return "src/core/AutoRest/bin/Debug/net451/osx.10.11-x64/";
126+
}
127+
if( isLinux ) {
128+
return "src/core/AutoRest/bin/Debug/net451/ubuntu.14.04-x64/"
129+
}
130+
throw new Error("Unknown platform?");
131+
}

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "azure-batch-sdk-for-java-codegen",
3+
"version": "0.0.1",
4+
"description": "Tools for Azure Batch SDK for Java build processes",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/Azure/azure-batch-sdk-for-java.git"
8+
},
9+
"keywords": [
10+
"azure"
11+
],
12+
"author": "Microsoft Corporation",
13+
"license": "MIT",
14+
"bugs": {
15+
"url": "https://github.com/Azure/azure-batch-sdk-for-java/issues"
16+
},
17+
"homepage": "https://github.com/Azure/azure-batch-sdk-for-java#readme",
18+
"devDependencies": {
19+
"colors": "1.1.2",
20+
"gulp": "^3.9.0",
21+
"gulp-exec": "2.1.2",
22+
"yargs": "3.29.0"
23+
}
24+
}

0 commit comments

Comments
 (0)