@Override public Observable<DisasterRecoveryPairingAuthorizationRule> getByIdAsync(String id) { ResourceId resourceId = ResourceId.fromString(id); return this.getByNameAsync(resourceId.resourceGroupName(), resourceId.parent().name(), resourceId.parent().parent().name(), resourceId.name()); }
/** * @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()); }
/** * Returns parsed ResourceId object for a given resource id. * @param id of the resource * @return ResourceId object */ public static ResourceId fromString(String id) { return new ResourceId(id); }
/** * Extract resource group from a resource ID string. * @param id the resource ID string * @return the resource group name */ public static String groupFromResourceId(String id) { return (id != null) ? ResourceId.fromString(id).resourceGroupName() : null; }
/** * Extract name of the resource from a resource ID. * @param id the resource ID * @return the name of the resource */ public static String nameFromResourceId(String id) { return (id != null) ? ResourceId.fromString(id).name() : null; }
/** * Extract resource provider from a resource ID string. * @param id the resource ID string * @return the resource group name */ public static String resourceProviderFromResourceId(String id) { return (id != null) ? ResourceId.fromString(id).providerNamespace() : null; }
@Override public SqlFirewallRuleImpl withExistingSqlServerId(String sqlServerId) { Objects.requireNonNull(sqlServerId); ResourceId resourceId = ResourceId.fromString(sqlServerId); this.resourceGroupName = resourceId.resourceGroupName(); this.sqlServerName = resourceId.name(); return this; }
@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()); }
/** * 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; }
protected void setParentName(InnerModelT inner) { if (this.id() != null) { this.parentName = ResourceId.fromString(this.id()).parent().name(); } }
OneAncestor(ResourceId resourceId) { Objects.requireNonNull(resourceId); Objects.requireNonNull(resourceId.parent()); this.resourceGroupName = Objects.requireNonNull(resourceId.resourceGroupName()); this.ancestor1Name = Objects.requireNonNull(resourceId.parent().name()); }
@Override public SqlDatabase rename(String newDatabaseName) { ResourceId resourceId = ResourceId.fromString(this.id()); String newId = resourceId.parent().id() + "/databases/" + newDatabaseName; this.sqlServerManager.inner().databases() .rename(this.resourceGroupName, this.sqlServerName, this.name(), newId); return this.sqlServerManager.sqlServers().databases() .getBySqlServer(this.resourceGroupName, this.sqlServerName, newDatabaseName); }
/** * Extract resource type from a resource ID string. * @param id the resource ID string * @return the resource type */ public static String resourceTypeFromResourceId(String id) { return (id != null) ? ResourceId.fromString(id).resourceType() : null; }
/** * @return parent resource id of the resource if any, otherwise null. */ public ResourceId parent() { if (this.id == null || this.parentId == null) { return null; } else { return fromString(this.parentId); } }
/** * @return full type of the resource. */ public String fullResourceType() { if (this.parentId == null) { return this.providerNamespace + "/" + this.resourceType; } else { return this.parent().fullResourceType() + "/" + this.resourceType; } }
try { // Authorize the request. Credential credential = Auth.authorize(scopes, "addsubscription"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName( "youtube-cmdline-addsubscription-sample").build(); // We get the user selected channel to subscribe. // Retrieve the channel ID that the user is subscribing to. String channelId = getChannelId(); System.out.println("You chose " + channelId + " to subscribe."); // Create a resourceId that identifies the channel ID. ResourceId resourceId = new ResourceId(); resourceId.setChannelId(channelId); resourceId.setKind("youtube#channel"); // Create a snippet that contains the resourceId. SubscriptionSnippet snippet = new SubscriptionSnippet(); snippet.setResourceId(resourceId); // Create a request to add the subscription and send the request. // The request identifies subscription metadata to insert as well // as information that the API server should return in its response. Subscription subscription = new Subscription(); subscription.setSnippet(snippet); YouTube.Subscriptions.Insert subscriptionInsert = youtube.subscriptions().insert("snippet,contentDetails", subscription); Subscription returnedSubscription = subscriptionInsert.execute(); // Print information from the API response. System.out.println("\n================== Returned Subscription ==================\n"); System.out.println(" - Id: " + returnedSubscription.getId()); System.out.println(" - Title: " + returnedSubscription.getSnippet().getTitle()); }
@Override public SqlServerDnsAliasImpl withExistingSqlServerId(String sqlServerId) { Objects.requireNonNull(sqlServerId); ResourceId resourceId = ResourceId.fromString(sqlServerId); this.resourceGroupName = resourceId.resourceGroupName(); this.sqlServerName = resourceId.name(); return this; }
@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"); }
/** * 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; }