-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mitigate bug related to dot and flatten from azure-client-runtime (#1380
- Loading branch information
1 parent
044a7fe
commit 90f932d
Showing
9 changed files
with
438 additions
and
3 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/TagOperations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.azure.management.resources; | ||
|
||
import com.microsoft.azure.management.resources.fluentcore.arm.models.HasManager; | ||
import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; | ||
import com.microsoft.azure.management.resources.implementation.ResourceManager; | ||
import rx.Observable; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Entry point to tag management API. | ||
*/ | ||
public interface TagOperations extends HasManager<ResourceManager> { | ||
|
||
/** | ||
* Updates the tags of the Azure resource. | ||
* | ||
* @param resource the Azure resource to have its tags updated | ||
* @param tags the tags | ||
* @return the resource with updated tags | ||
*/ | ||
TagResource updateTags(Resource resource, Map<String, String> tags); | ||
|
||
/** | ||
* Updates the tags of the Azure resource. | ||
* | ||
* @param resourceId the ID of the Azure resource to have its tags updated | ||
* @param tags the tags | ||
* @return the resource with updated tags | ||
*/ | ||
TagResource updateTags(String resourceId, Map<String, String> tags); | ||
|
||
/** | ||
* Updates the tags of the Azure resource. | ||
* | ||
* @param resource the Azure resource to have its tags updated | ||
* @param tags the tags | ||
* @return the resource with updated tags | ||
*/ | ||
Observable<TagResource> updateTagsAsync(Resource resource, Map<String, String> tags); | ||
|
||
/** | ||
* Updates the tags of the Azure resource. | ||
* | ||
* @param resourceId the ID of the Azure resource to have its tags updated | ||
* @param tags the tags | ||
* @return the resource with updated tags | ||
*/ | ||
Observable<TagResource> updateTagsAsync(String resourceId, Map<String, String> tags); | ||
} |
32 changes: 32 additions & 0 deletions
32
azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/TagResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.azure.management.resources; | ||
|
||
|
||
import com.microsoft.azure.management.resources.fluentcore.arm.models.HasId; | ||
import com.microsoft.azure.management.resources.fluentcore.arm.models.HasName; | ||
import com.microsoft.azure.management.resources.fluentcore.model.HasInner; | ||
import com.microsoft.azure.management.resources.implementation.TagsResourceInner; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* An immutable client-side representation of an Azure resource with tags. | ||
*/ | ||
public interface TagResource extends | ||
HasId, HasName, HasInner<TagsResourceInner> { | ||
|
||
/** | ||
* @return the type of the resource | ||
*/ | ||
String type(); | ||
|
||
/** | ||
* @return the tags for the resource | ||
*/ | ||
Map<String, String> tags(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
.../main/java/com/microsoft/azure/management/resources/implementation/TagOperationsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.azure.management.resources.implementation; | ||
|
||
import com.microsoft.azure.management.resources.TagOperations; | ||
import com.microsoft.azure.management.resources.TagResource; | ||
import com.microsoft.azure.management.resources.Tags; | ||
import com.microsoft.azure.management.resources.TagsPatchOperation; | ||
import com.microsoft.azure.management.resources.TagsPatchResource; | ||
import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; | ||
import rx.Observable; | ||
import rx.functions.Func1; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.TreeMap; | ||
|
||
class TagOperationsImpl implements TagOperations { | ||
|
||
private final ResourceManager myManager; | ||
|
||
TagOperationsImpl(ResourceManager resourceManager) { | ||
this.myManager = resourceManager; | ||
} | ||
|
||
@Override | ||
public TagResource updateTags(Resource resource, Map<String, String> tags) { | ||
return this.updateTagsAsync(resource, tags).toBlocking().last(); | ||
} | ||
|
||
@Override | ||
public TagResource updateTags(String resourceId, Map<String, String> tags) { | ||
return this.updateTagsAsync(resourceId, tags).toBlocking().last(); | ||
} | ||
|
||
@Override | ||
public Observable<TagResource> updateTagsAsync(Resource resource, Map<String, String> tags) { | ||
return this.updateTagsAsync(Objects.requireNonNull(resource).id(), tags); | ||
} | ||
|
||
@Override | ||
public Observable<TagResource> updateTagsAsync(String resourceId, Map<String, String> tags) { | ||
TagsPatchResource parameters = new TagsPatchResource() | ||
.withOperation(TagsPatchOperation.REPLACE) | ||
.withProperties(new Tags().withTags(new TreeMap<>(tags))); | ||
return this.manager().inner().tagOperations() | ||
.updateAtScopeAsync(resourceId, parameters) | ||
.map(new Func1<TagsResourceInner, TagResource>() { | ||
@Override | ||
public TagResource call(TagsResourceInner inner) { | ||
return new TagResourceImpl(inner); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public ResourceManager manager() { | ||
return this.myManager; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...rc/main/java/com/microsoft/azure/management/resources/implementation/TagResourceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.azure.management.resources.implementation; | ||
|
||
import com.microsoft.azure.management.resources.TagResource; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
final class TagResourceImpl implements TagResource { | ||
|
||
private final TagsResourceInner innerObject; | ||
|
||
TagResourceImpl(TagsResourceInner inner) { | ||
this.innerObject = inner; | ||
} | ||
|
||
@Override | ||
public TagsResourceInner inner() { | ||
return this.innerObject; | ||
} | ||
|
||
@Override | ||
public String id() { | ||
return this.inner().id(); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return this.inner().name(); | ||
} | ||
|
||
@Override | ||
public String type() { | ||
return this.inner().type(); | ||
} | ||
|
||
@Override | ||
public Map<String, String> tags() { | ||
return this.inner().properties() == null | ||
? Collections.<String, String>emptyMap() | ||
: Collections.unmodifiableMap(this.inner().properties().tags()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/TagsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.azure.management.resources; | ||
|
||
import com.microsoft.azure.management.resources.implementation.TypeSerializationTests; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class TagsTests extends ResourceManagerTestBase { | ||
|
||
@Test | ||
public void canUpdateTag() throws Exception { | ||
// assume there is a resource | ||
GenericResource resource = resourceClient.genericResources().list().iterator().next(); | ||
|
||
Map<String, String> originalTags = resource.tags(); | ||
if (originalTags == null) { | ||
originalTags = new HashMap<>(); | ||
} | ||
|
||
TagResource updatedTags = resourceClient.tagOperations().updateTags(resource, new TypeSerializationTests.Map1<>("tag.1", "value.1")); | ||
Assert.assertEquals(1, updatedTags.tags().size()); | ||
Assert.assertTrue(updatedTags.tags().containsKey("tag.1")); | ||
Assert.assertEquals("value.1", updatedTags.tags().get("tag.1")); | ||
|
||
updatedTags = resourceClient.tagOperations().updateTags(resource, new HashMap<String, String>()); | ||
Assert.assertEquals(0, updatedTags.tags().size()); | ||
|
||
updatedTags = resourceClient.tagOperations().updateTags(resource, originalTags); | ||
Assert.assertEquals(originalTags, updatedTags.tags()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.