/** * Extract the subscription ID from a resource ID string. * @param id the resource ID string * @return the subscription ID */ public static String subscriptionFromResourceId(String id) { return (id != null) ? ResourceId.fromString(id).subscriptionId() : null; }
/** * Extract the subscription ID from a resource ID string. * @param id the resource ID string * @return the subscription ID */ public static String subscriptionFromResourceId(String id) { return (id != null) ? ResourceId.fromString(id).subscriptionId() : null; }
/** * This method returns ARM id of the resource group from the given ARM id of a resource * in the resource group. * * @param id ARM id * @return the ARM id of resource group */ private static String resourceGroupId(String id) { final ResourceId resourceId = ResourceId.fromString(id); final StringBuilder builder = new StringBuilder(); builder.append("/subscriptions/") .append(resourceId.subscriptionId()) .append("/resourceGroups/") .append(resourceId.resourceGroupName()); return builder.toString(); }
@Override public Map<String, String> toProperties() { final Map<String, String> properties = new HashMap<>(); properties.put(AppInsightsConstants.SubscriptionId, ResourceId.fromString(this.virtualMachine.id()).subscriptionId()); properties.put(AppInsightsConstants.Region, this.virtualMachine.regionName()); return properties; }
/** * @param id resource id * @return resource group id for the resource id provided */ public static String resourceGroupId(String id) { final ResourceId resourceId = ResourceId.fromString(id); return String.format("/subscriptions/%s/resourceGroups/%s", resourceId.subscriptionId(), resourceId.resourceGroupName()); }
@Override public Map<String, String> toProperties() { final Map<String, String> properties = new HashMap<>(); properties.put(AppInsightsConstants.SubscriptionId, ResourceId.fromString(this.storageAccount.id()).subscriptionId()); properties.put(AppInsightsConstants.Region, this.storageAccount.regionName()); return properties; }
private static String resourceGroupId(String id) { final ResourceId resourceId = ResourceId.fromString(id); return String.format("/subscriptions/%s/resourceGroups/%s", resourceId.subscriptionId(), resourceId.resourceGroupName()); }
/** * @param id resource id * @return resource group id for the resource id provided */ public static String resourceGroupId(String id) { final ResourceId resourceId = ResourceId.fromString(id); return String.format("/subscriptions/%s/resourceGroups/%s", resourceId.subscriptionId(), resourceId.resourceGroupName()); }
@Override public Map<String, String> toProperties() { final Map<String, String> properties = new HashMap<>(); properties.put(AppInsightsConstants.SubscriptionId, ResourceId.fromString(this.storageAccount.id()).subscriptionId()); properties.put(AppInsightsConstants.Region, this.storageAccount.regionName()); return properties; }
@Override public Map<String, String> toProperties() { final Map<String, String> properties = new HashMap<>(); properties.put(AppInsightsConstants.SubscriptionId, ResourceId.fromString(this.storageAccount.id()).subscriptionId()); properties.put(AppInsightsConstants.Region, this.storageAccount.regionName()); return properties; }
try { addChildNode(new WebAppNode(WebAppModule.this, ResourceId.fromString(webAppDetails.webApp.id()).subscriptionId(), webAppDetails.webApp.id(), webAppDetails.webApp.name(),
@Test public void resourceIdForTopLevelResourceWorksFine() { ResourceId resourceId = ResourceId.fromString("/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/resourceGroupName/providers/Microsoft.Network/applicationGateways/something"); Assert.assertEquals(resourceId.name(), "something"); Assert.assertEquals(resourceId.subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef"); Assert.assertEquals(resourceId.resourceGroupName(), "resourceGroupName"); Assert.assertEquals(resourceId.providerNamespace(), "Microsoft.Network"); Assert.assertEquals(resourceId.resourceType(), "applicationGateways"); Assert.assertEquals(resourceId.fullResourceType(), "Microsoft.Network/applicationGateways"); Assert.assertNull(resourceId.parent()); }
@Test public void resourceIdForChildLevelResourceWorksFine() { ResourceId resourceId = ResourceId.fromString("/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/resourceGroupName/providers/Microsoft.Network/applicationGateways/something/someChildType/childName"); Assert.assertEquals(resourceId.name(), "childName"); Assert.assertEquals(resourceId.subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef"); Assert.assertEquals(resourceId.resourceGroupName(), "resourceGroupName"); Assert.assertEquals(resourceId.providerNamespace(), "Microsoft.Network"); Assert.assertEquals(resourceId.resourceType(), "someChildType"); Assert.assertEquals(resourceId.fullResourceType(), "Microsoft.Network/applicationGateways/someChildType"); Assert.assertNotNull(resourceId.parent()); Assert.assertEquals(resourceId.parent().name(), "something"); Assert.assertEquals(resourceId.parent().subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef"); Assert.assertEquals(resourceId.parent().resourceGroupName(), "resourceGroupName"); Assert.assertEquals(resourceId.parent().name(), "something"); Assert.assertEquals(resourceId.parent().providerNamespace(), "Microsoft.Network"); Assert.assertEquals(resourceId.parent().resourceType(), "applicationGateways"); Assert.assertEquals(resourceId.parent().fullResourceType(), "Microsoft.Network/applicationGateways"); }
@Test public void resourceIdForGrandChildLevelResourceWorksFine() { ResourceId resourceId = ResourceId.fromString("/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/resourceGroupName/providers/Microsoft.Network/applicationGateways/something/someChildType/childName/grandChildType/grandChild"); Assert.assertEquals(resourceId.name(), "grandChild"); Assert.assertEquals(resourceId.subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef"); Assert.assertEquals(resourceId.resourceGroupName(), "resourceGroupName"); Assert.assertEquals(resourceId.providerNamespace(), "Microsoft.Network"); Assert.assertEquals(resourceId.resourceType(), "grandChildType"); Assert.assertEquals(resourceId.fullResourceType(), "Microsoft.Network/applicationGateways/someChildType/grandChildType"); Assert.assertNotNull(resourceId.parent()); Assert.assertEquals(resourceId.parent().name(), "childName"); Assert.assertEquals(resourceId.parent().subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef"); Assert.assertEquals(resourceId.parent().resourceGroupName(), "resourceGroupName"); Assert.assertEquals(resourceId.parent().providerNamespace(), "Microsoft.Network"); Assert.assertEquals(resourceId.parent().resourceType(), "someChildType"); Assert.assertEquals(resourceId.parent().fullResourceType(), "Microsoft.Network/applicationGateways/someChildType"); Assert.assertNotNull(resourceId.parent().parent()); Assert.assertEquals(resourceId.parent().parent().name(), "something"); Assert.assertEquals(resourceId.parent().parent().subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef"); Assert.assertEquals(resourceId.parent().parent().resourceGroupName(), "resourceGroupName"); Assert.assertEquals(resourceId.parent().parent().name(), "something"); Assert.assertEquals(resourceId.parent().parent().providerNamespace(), "Microsoft.Network"); Assert.assertEquals(resourceId.parent().parent().resourceType(), "applicationGateways"); Assert.assertEquals(resourceId.parent().parent().fullResourceType(), "Microsoft.Network/applicationGateways"); } }