Skip to content

Commit

Permalink
Migrate azure-batch-compute to azure-json (Azure#40961)
Browse files Browse the repository at this point in the history
* Fix BatchNodeReimageOption

* Add azure-json to dependency.

* Fix BatchTaskListSubtasksResult

* Fix changes in CloudConfiguration

* Fix constructor error CloudServiceConfiguration

* Add revapi suppression.

* Fix javadoc warning.

* Update json version.
  • Loading branch information
conniey authored Aug 6, 2024
1 parent 4597c72 commit 11efb41
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,11 @@
"old" : "method T com.azure.identity.AadCredentialBuilderBase<T extends com.azure.identity.AadCredentialBuilderBase<T>>::clientId(java.lang.String) @ com.azure.identity.DeviceCodeCredentialBuilder",
"new" : "method com.azure.identity.DeviceCodeCredentialBuilder com.azure.identity.DeviceCodeCredentialBuilder::clientId(java.lang.String)",
"justification": "Override flags this as a potential binary breaking change, but it isn't."
},
{
"code": "java\\.annotation\\.removed",
"old": ".*? com\\.azure\\.compute\\.batch\\.models.*",
"justification": "Removing Jackson annotations from Azure Batch in transition to stream-style."
}
]
}
Expand Down
12 changes: 12 additions & 0 deletions sdk/batch/azure-compute-batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jacoco.skip>true</jacoco.skip>

<!-- Configures the Java 9+ run to perform the required module exports, opens, and reads that are necessary for testing but shouldn't be part of the module-info. -->
<javaModulesSurefireArgLine>
--add-exports com.azure.core/com.azure.core.implementation.util=ALL-UNNAMED
--add-exports com.azure.core/com.azure.core.implementation.http=ALL-UNNAMED
</javaModulesSurefireArgLine>
</properties>
<dependencies>
<dependency>
Expand All @@ -56,6 +62,12 @@
<artifactId>azure-core-http-netty</artifactId>
<version>1.15.3</version> <!-- {x-version-update;com.azure:azure-core-http-netty;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-json</artifactId>
<version>1.2.0</version> <!-- {x-version-update;com.azure:azure-json;dependency} -->
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.azure.core.annotation.Generated;
import com.azure.core.util.ExpandableStringEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.Collection;

/**
Expand Down Expand Up @@ -58,7 +57,6 @@ public BatchNodeReimageOption() {
* @return the corresponding BatchNodeReimageOption.
*/
@Generated
@JsonCreator
public static BatchNodeReimageOption fromString(String name) {
return fromString(name, BatchNodeReimageOption.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;

import java.io.IOException;
import java.util.List;

/** The result of listing the subtasks of a Task. */
@Immutable
public final class BatchTaskListSubtasksResult {
public final class BatchTaskListSubtasksResult implements JsonSerializable<BatchTaskListSubtasksResult> {

/*
* The list of subtasks.
*/
@Generated
@JsonProperty(value = "value")
private List<BatchSubtask> value;

/** Creates an instance of BatchTaskListSubtasksResult class. */
Expand All @@ -32,4 +36,46 @@ private BatchTaskListSubtasksResult() {}
public List<BatchSubtask> getValue() {
return this.value;
}

/**
* Creates a representation of this object as JSON.
*
* @param jsonWriter Where the JSON representation is written to.
*
* @throws IOException Error while writing to JsonWriter.
* @return The JsonWriter with the JSON representation of this object.
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeArrayField("value", this.value, (writer, element) -> element.toJson(writer));
jsonWriter.writeEndObject();
return jsonWriter;
}

/**
* Creates a {@link BatchTaskListSubtasksResult} from its JSON representation.
*
* @param jsonReader Where the JSON read from to deserialize the object.
*
* @throws IOException Error while reading from JsonReader.
* @return Instance read from the JsonReader.
*/
public static BatchTaskListSubtasksResult fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
BatchTaskListSubtasksResult result = new BatchTaskListSubtasksResult();
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();

if ("value".equals(fieldName)) {
result.value = reader.readArray(r -> BatchSubtask.fromJson(r));
} else {
reader.skipChildren();
}
}

return result;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@

import com.azure.core.annotation.Fluent;
import com.azure.core.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;

import java.io.IOException;

/**
* The configuration for Compute Nodes in a Pool based on the Azure Cloud Services
* platform.
*/
@Fluent
public final class CloudServiceConfiguration {
public final class CloudServiceConfiguration implements JsonSerializable<CloudServiceConfiguration> {

/*
* Possible values are:
Expand All @@ -29,15 +33,13 @@ public final class CloudServiceConfiguration {
* (https://azure.microsoft.com/documentation/articles/cloud-services-guestos-update-matrix/#releases).
*/
@Generated
@JsonProperty(value = "osFamily")
private String osFamily;

/*
* The Azure Guest OS version to be installed on the virtual machines in the Pool. The default value is * which
* specifies the latest operating system version for the specified OS family.
*/
@Generated
@JsonProperty(value = "osVersion")
private String osVersion;

/**
Expand All @@ -46,8 +48,7 @@ public final class CloudServiceConfiguration {
* @param osFamily the osFamily value to set.
*/
@Generated
@JsonCreator
public CloudServiceConfiguration(@JsonProperty(value = "osFamily") String osFamily) {
public CloudServiceConfiguration(String osFamily) {
this.osFamily = osFamily;
}

Expand Down Expand Up @@ -94,4 +95,52 @@ public CloudServiceConfiguration setOsVersion(String osVersion) {
this.osVersion = osVersion;
return this;
}

/**
* Creates a representation of this object as JSON.
*
* @param jsonWriter Where the JSON representation is written to.
*
* @throws IOException Error while writing to JsonWriter.
* @return The JsonWriter with the JSON representation of this object.
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("osFamily", osFamily);
jsonWriter.writeStringField("osVersion", osVersion);
jsonWriter.writeEndObject();

return jsonWriter;
}

/**
* Creates a new instance from its JSON representation.
*
* @param jsonReader Where the JSON read from to deserialize the object.
*
* @throws IOException Error while reading from JsonReader.
* @return Instance read from the JsonReader.
*/
public static CloudServiceConfiguration fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String family = null;
String version = null;

while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();

if ("osFamily".equals(fieldName)) {
family = reader.getString();
} else if ("osVersion".equals(fieldName)) {
version = reader.getString();
} else {
reader.skipChildren();
}
}

return new CloudServiceConfiguration(family).setOsVersion(version);
});
}
}

0 comments on commit 11efb41

Please sign in to comment.