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

Commit 16594e2

Browse files
authored
Update SDK with latest 1.0.1 runtime (#14)
* Update SDK with latest 1.0.1 runtime * Fix GetFile bugs.
1 parent f324cd3 commit 16594e2

15 files changed

+193
-186
lines changed

gulpfile.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ gulp.task('default', function() {
2424

2525
var specRoot = args['spec-root'] || "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master";
2626
var projects = 'batchService'; // default
27-
var autoRestVersion = '1.0.0-Nightly20170129'; // default
27+
var autoRestVersion = '1.0.1-20170329-2300-nightly'; // default
2828
if (args['autorest'] !== undefined) {
2929
autoRestVersion = args['autorest'];
3030
}
@@ -36,14 +36,10 @@ var autoRestArgs = args['autorest-args'];
3636
var autoRestExe;
3737

3838
gulp.task('codegen', function(cb) {
39-
var nugetSource = 'https://www.myget.org/F/autorest/api/v2';
40-
if (autoRestVersion.match(/[0-9]+\.[0-9]+\.[0-9]+.*/)) {
41-
autoRestExe = 'packages\\autorest.' + autoRestVersion + '\\tools\\AutoRest.exe';
42-
exec('tools\\nuget.exe install AutoRest -Source ' + nugetSource + ' -Version ' + autoRestVersion + ' -o packages', function(err, stdout, stderr) {
43-
console.log(stdout);
44-
console.error(stderr);
45-
handleInput(projects, cb);
46-
});
39+
if (autoRestVersion.match(/[0-9]+\.[0-9]+\.[0-9]+.*/) ||
40+
autoRestVersion == 'latest') {
41+
autoRestExe = 'autorest ---version=' + autoRestVersion;
42+
handleInput(projects, cb);
4743
} else {
4844
autoRestExe = autoRestVersion + "/src/core/AutoRest/bin/Debug/netcoreapp1.0/AutoRest.dll";
4945
autoRestExe = "dotnet " + autoRestExe;

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>com.microsoft.azure</groupId>
4646
<artifactId>azure-client-runtime</artifactId>
47-
<version>1.0.0</version>
47+
<version>1.0.1</version>
4848
</dependency>
4949
<dependency>
5050
<groupId>com.microsoft.azure</groupId>

src/main/java/com/microsoft/azure/batch/ComputeNodeOperations.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
package com.microsoft.azure.batch;
88

9-
import com.google.common.io.CharStreams;
109
import com.microsoft.azure.batch.protocol.models.*;
1110
import org.joda.time.DateTime;
1211

12+
import java.io.ByteArrayOutputStream;
1313
import java.io.IOException;
14-
import java.io.InputStream;
15-
import java.io.InputStreamReader;
1614
import java.util.Collection;
1715
import java.util.List;
1816

@@ -441,14 +439,11 @@ public String getComputeNodeRemoteDesktop(String poolId, String nodeId, Iterable
441439
BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
442440
bhMgr.applyRequestBehaviors(options);
443441

444-
InputStream response = this._parentBatchClient.protocolLayer().computeNodes().getRemoteDesktop(poolId, nodeId, options);
445-
446-
if (response != null) {
447-
return CharStreams.toString(new InputStreamReader(response, "UTF-8"));
448-
}
449-
else {
450-
return null;
451-
}
442+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
443+
this._parentBatchClient.protocolLayer().computeNodes().getRemoteDesktop(poolId, nodeId, options, outputStream);
444+
String rdpContent = outputStream.toString("UTF-8");
445+
outputStream.close();
446+
return rdpContent;
452447
}
453448

454449
/**

src/main/java/com/microsoft/azure/batch/FileOperations.java

+12-54
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import com.microsoft.azure.batch.protocol.models.FileProperties;
2121
import com.microsoft.azure.batch.protocol.models.NodeFile;
2222
import com.microsoft.rest.ServiceResponseWithHeaders;
23-
import rx.exceptions.Exceptions;
24-
import rx.functions.Func1;
2523

2624
import java.io.*;
2725
import java.util.Collection;
@@ -261,12 +259,12 @@ public void deleteFileFromComputeNode(String poolId, String nodeId, String fileN
261259
* @param jobId The ID of the job containing the task.
262260
* @param taskId The ID of the task.
263261
* @param fileName The name of the file to download.
264-
* @return A stream into which the file contents will be written.
262+
* @param outputStream A stream into which the file contents will be written.
265263
* @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
266264
* @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
267265
*/
268-
public InputStream getFileFromTask(String jobId, String taskId, String fileName) throws BatchErrorException, IOException {
269-
return getFileFromTask(jobId, taskId, fileName, null);
266+
public void getFileFromTask(String jobId, String taskId, String fileName, OutputStream outputStream) throws BatchErrorException, IOException {
267+
getFileFromTask(jobId, taskId, fileName, null, outputStream);
270268
}
271269

272270
/**
@@ -276,36 +274,16 @@ public InputStream getFileFromTask(String jobId, String taskId, String fileName)
276274
* @param taskId The ID of the task.
277275
* @param fileName The name of the file to download.
278276
* @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
279-
* @return A stream into which the file contents will be written.
277+
* @param outputStream A stream into which the file contents will be written.
280278
* @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
281279
* @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
282280
*/
283-
public InputStream getFileFromTask(String jobId, String taskId, String fileName, Iterable<BatchClientBehavior> additionalBehaviors) throws BatchErrorException, IOException {
281+
public void getFileFromTask(String jobId, String taskId, String fileName, Iterable<BatchClientBehavior> additionalBehaviors, OutputStream outputStream) throws BatchErrorException, IOException {
284282
FileGetFromTaskOptions options = new FileGetFromTaskOptions();
285283
BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
286284
bhMgr.applyRequestBehaviors(options);
287285

288-
// Duplicate the stream due to AutoRest issue https://github.com/Azure/autorest/issues/1385
289-
ByteArrayOutputStream output = this._parentBatchClient.protocolLayer().files().getFromTaskAsync(jobId, taskId, fileName, options)
290-
.map(new Func1<InputStream, ByteArrayOutputStream>() {
291-
@Override
292-
public ByteArrayOutputStream call(InputStream input) {
293-
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
294-
byte[] data = new byte[16384];
295-
int nRead;
296-
try {
297-
while ((nRead = input.read(data, 0, data.length)) != -1) {
298-
buffer.write(data, 0, nRead);
299-
}
300-
buffer.flush();
301-
return buffer;
302-
} catch (IOException e) {
303-
throw Exceptions.propagate(e);
304-
}
305-
}
306-
}).toBlocking().single();
307-
308-
return new ByteArrayInputStream(output.toByteArray());
286+
this._parentBatchClient.protocolLayer().files().getFromTask(jobId, taskId, fileName, options, outputStream);
309287
}
310288

311289
/**
@@ -314,12 +292,12 @@ public ByteArrayOutputStream call(InputStream input) {
314292
* @param poolId The ID of the pool that contains the compute node.
315293
* @param nodeId The ID of the compute node.
316294
* @param fileName The name of the file to download.
317-
* @return A stream into which the file contents will be written.
295+
* @param outputStream A stream into which the file contents will be written.
318296
* @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
319297
* @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
320298
*/
321-
public InputStream getFileFromComputeNode(String poolId, String nodeId, String fileName) throws BatchErrorException, IOException {
322-
return getFileFromComputeNode(poolId, nodeId, fileName, null);
299+
public void getFileFromComputeNode(String poolId, String nodeId, String fileName, OutputStream outputStream) throws BatchErrorException, IOException {
300+
getFileFromComputeNode(poolId, nodeId, fileName, null, outputStream);
323301
}
324302

325303
/**
@@ -329,36 +307,16 @@ public InputStream getFileFromComputeNode(String poolId, String nodeId, String f
329307
* @param nodeId The ID of the compute node.
330308
* @param fileName The name of the file to download.
331309
* @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
332-
* @return A stream into which the file contents will be written.
310+
* @param outputStream A stream into which the file contents will be written.
333311
* @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
334312
* @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
335313
*/
336-
public InputStream getFileFromComputeNode(String poolId, String nodeId, String fileName, Iterable<BatchClientBehavior> additionalBehaviors) throws BatchErrorException, IOException {
314+
public void getFileFromComputeNode(String poolId, String nodeId, String fileName, Iterable<BatchClientBehavior> additionalBehaviors, OutputStream outputStream) throws BatchErrorException, IOException {
337315
FileGetFromComputeNodeOptions options = new FileGetFromComputeNodeOptions();
338316
BehaviorManager bhMgr = new BehaviorManager(this.customBehaviors(), additionalBehaviors);
339317
bhMgr.applyRequestBehaviors(options);
340318

341-
// Duplicate the stream due to AutoRest issue https://github.com/Azure/autorest/issues/1385
342-
ByteArrayOutputStream output = this._parentBatchClient.protocolLayer().files().getFromComputeNodeAsync(poolId, nodeId, fileName, options)
343-
.map(new Func1<InputStream, ByteArrayOutputStream>() {
344-
@Override
345-
public ByteArrayOutputStream call(InputStream input) {
346-
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
347-
byte[] data = new byte[16384];
348-
int nRead;
349-
try {
350-
while ((nRead = input.read(data, 0, data.length)) != -1) {
351-
buffer.write(data, 0, nRead);
352-
}
353-
buffer.flush();
354-
return buffer;
355-
} catch (IOException e) {
356-
throw Exceptions.propagate(e);
357-
}
358-
}
359-
}).toBlocking().single();
360-
361-
return new ByteArrayInputStream(output.toByteArray());
319+
this._parentBatchClient.protocolLayer().files().getFromComputeNode(poolId, nodeId, fileName, options, outputStream);
362320
}
363321

364322
/**

src/main/java/com/microsoft/azure/batch/protocol/ComputeNodes.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.microsoft.rest.ServiceResponseWithHeaders;
4848
import java.io.InputStream;
4949
import java.io.IOException;
50+
import java.io.OutputStream;
5051
import java.util.List;
5152
import rx.Observable;
5253

@@ -940,12 +941,12 @@ public interface ComputeNodes {
940941
*
941942
* @param poolId The ID of the pool that contains the compute node.
942943
* @param nodeId The ID of the compute node for which you want to get the Remote Desktop Protocol file.
944+
* @param outputStream The OutputStream object which data will be written to if successful.
943945
* @throws IllegalArgumentException thrown if parameters fail the validation
944946
* @throws BatchErrorException thrown if the request is rejected by server
945947
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
946-
* @return the InputStream object if successful.
947948
*/
948-
InputStream getRemoteDesktop(String poolId, String nodeId);
949+
void getRemoteDesktop(String poolId, String nodeId, OutputStream outputStream);
949950

950951
/**
951952
* Gets the Remote Desktop Protocol file for the specified compute node.
@@ -987,12 +988,12 @@ public interface ComputeNodes {
987988
* @param poolId The ID of the pool that contains the compute node.
988989
* @param nodeId The ID of the compute node for which you want to get the Remote Desktop Protocol file.
989990
* @param computeNodeGetRemoteDesktopOptions Additional parameters for the operation
991+
* @param outputStream The OutputStream object which data will be written to if successful.
990992
* @throws IllegalArgumentException thrown if parameters fail the validation
991993
* @throws BatchErrorException thrown if the request is rejected by server
992994
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
993-
* @return the InputStream object if successful.
994995
*/
995-
InputStream getRemoteDesktop(String poolId, String nodeId, ComputeNodeGetRemoteDesktopOptions computeNodeGetRemoteDesktopOptions);
996+
void getRemoteDesktop(String poolId, String nodeId, ComputeNodeGetRemoteDesktopOptions computeNodeGetRemoteDesktopOptions, OutputStream outputStream);
996997

997998
/**
998999
* Gets the Remote Desktop Protocol file for the specified compute node.

src/main/java/com/microsoft/azure/batch/protocol/Files.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.microsoft.rest.ServiceResponseWithHeaders;
3737
import java.io.InputStream;
3838
import java.io.IOException;
39+
import java.io.OutputStream;
3940
import java.util.List;
4041
import rx.Observable;
4142

@@ -149,12 +150,12 @@ public interface Files {
149150
* @param jobId The ID of the job that contains the task.
150151
* @param taskId The ID of the task whose file you want to retrieve.
151152
* @param filePath The path to the task file that you want to get the content of.
153+
* @param outputStream The OutputStream object which data will be written to if successful.
152154
* @throws IllegalArgumentException thrown if parameters fail the validation
153155
* @throws BatchErrorException thrown if the request is rejected by server
154156
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
155-
* @return the InputStream object if successful.
156157
*/
157-
InputStream getFromTask(String jobId, String taskId, String filePath);
158+
void getFromTask(String jobId, String taskId, String filePath, OutputStream outputStream);
158159

159160
/**
160161
* Returns the content of the specified task file.
@@ -196,12 +197,12 @@ public interface Files {
196197
* @param taskId The ID of the task whose file you want to retrieve.
197198
* @param filePath The path to the task file that you want to get the content of.
198199
* @param fileGetFromTaskOptions Additional parameters for the operation
200+
* @param outputStream The OutputStream object which data will be written to if successful.
199201
* @throws IllegalArgumentException thrown if parameters fail the validation
200202
* @throws BatchErrorException thrown if the request is rejected by server
201203
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
202-
* @return the InputStream object if successful.
203204
*/
204-
InputStream getFromTask(String jobId, String taskId, String filePath, FileGetFromTaskOptions fileGetFromTaskOptions);
205+
void getFromTask(String jobId, String taskId, String filePath, FileGetFromTaskOptions fileGetFromTaskOptions, OutputStream outputStream);
205206

206207
/**
207208
* Returns the content of the specified task file.
@@ -440,12 +441,12 @@ public interface Files {
440441
* @param poolId The ID of the pool that contains the compute node.
441442
* @param nodeId The ID of the compute node that contains the file.
442443
* @param filePath The path to the task file that you want to get the content of.
444+
* @param outputStream The OutputStream object which data will be written to if successful.
443445
* @throws IllegalArgumentException thrown if parameters fail the validation
444446
* @throws BatchErrorException thrown if the request is rejected by server
445447
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
446-
* @return the InputStream object if successful.
447448
*/
448-
InputStream getFromComputeNode(String poolId, String nodeId, String filePath);
449+
void getFromComputeNode(String poolId, String nodeId, String filePath, OutputStream outputStream);
449450

450451
/**
451452
* Returns the content of the specified task file.
@@ -487,12 +488,12 @@ public interface Files {
487488
* @param nodeId The ID of the compute node that contains the file.
488489
* @param filePath The path to the task file that you want to get the content of.
489490
* @param fileGetFromComputeNodeOptions Additional parameters for the operation
491+
* @param outputStream The OutputStream object which data will be written to if successful.
490492
* @throws IllegalArgumentException thrown if parameters fail the validation
491493
* @throws BatchErrorException thrown if the request is rejected by server
492494
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
493-
* @return the InputStream object if successful.
494495
*/
495-
InputStream getFromComputeNode(String poolId, String nodeId, String filePath, FileGetFromComputeNodeOptions fileGetFromComputeNodeOptions);
496+
void getFromComputeNode(String poolId, String nodeId, String filePath, FileGetFromComputeNodeOptions fileGetFromComputeNodeOptions, OutputStream outputStream);
496497

497498
/**
498499
* Returns the content of the specified task file.

0 commit comments

Comments
 (0)