Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate ListingByTag into group & subscription level #1202

Merged
merged 3 commits into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.microsoft.azure.management.apigeneration.Fluent;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByTag;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingInGroupByTag;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing;

Expand All @@ -22,7 +22,7 @@
public interface GenericResources extends
SupportsListing<GenericResource>,
SupportsListingByGroup<GenericResource>,
SupportsListingByTag<GenericResource>,
SupportsListingInGroupByTag<GenericResource>,
SupportsGettingById<GenericResource>,
SupportsCreating<GenericResource.DefinitionStages.Blank> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListingByTag;

/**
* Entry point to resource group management API.
*/
@Fluent
public interface ResourceGroups extends
SupportsListing<ResourceGroup>,
SupportsListingByTag<ResourceGroup>,
SupportsGettingByName<ResourceGroup>,
SupportsCreating<ResourceGroup.DefinitionStages.Blank>,
SupportsDeleting,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* 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.fluentcore.arm.collection;

import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.apigeneration.LangDefinition.MethodConversion;

/**
* Provides access to listing Azure resources of a specific type based on their tag.
* <p>
* (Note: this interface is not intended to be implemented by user code)
*
* @param <T> the fluent type of the resource
*/
@LangDefinition(ContainerName = "CollectionActions", MethodConversionType = MethodConversion.OnlyMethod)
public interface SupportsListingInGroupByTag<T> {
/**
* Lists all the resources with the specified tag.
*
* @param resourceGroupName the name of the resource group
* @param tagName tag's name as the key
* @param tagValue tag's value
* @return list of resources
*/
PagedList<T> listByTag(String resourceGroupName, String tagName, String tagValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* license information.
*/

package com.microsoft.azure.management.resources.fluentcore.arm.collection;
package com.microsoft.azure.management.resources.fluentcore.collection;

import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.apigeneration.LangDefinition;
Expand All @@ -22,10 +22,9 @@ public interface SupportsListingByTag<T> {
/**
* Lists all the resources with the specified tag.
*
* @param resourceGroupName the name of the resource group
* @param tagName tag's name as the key
* @param tagValue tag's value
* @return list of resources
*/
PagedList<T> listByTag(String resourceGroupName, String tagName, String tagValue);
PagedList<T> listByTag(String tagName, String tagValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ public PagedList<ResourceGroup> list() {
return wrapList(client.list());
}

@Override
public PagedList<ResourceGroup> listByTag(String tagName, String tagValue) {
if (tagName == null) {
throw new IllegalArgumentException("tagName == null");
}
String odataFilter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you are splitting the code for listing at subscription and at resource group, I assume generating ODataFilter is common code at both locations. If that is the case can you create a utility to create the ODataFilter string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

if (tagValue == null) {
odataFilter = String.format("tagname eq '%s'", tagName);
} else {
odataFilter = String.format("tagname eq '%s' and tagvalue eq '%s'", tagName, tagValue);
}
return wrapList(client.list(
odataFilter, null));
}

@Override
public ResourceGroupImpl getByName(String name) {
return wrapModel(client.get(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void canCreateResourceGroup() throws Exception {
.create();
// List
ResourceGroup groupResult = null;
for (ResourceGroup rg : resourceGroups.list()) {
for (ResourceGroup rg : resourceGroups.listByTag("department", "finance")) {
if (rg.name().equals(rgName)) {
groupResult = rg;
break;
Expand Down