Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -165,13 +165,9 @@ public void canCRUDBatchAccount() throws Exception {
.parent()
.apply();
batchManager.batchAccounts().deleteByGroup(batchAccount.resourceGroupName(), batchAccount.name());
try {
batchManager.batchAccounts().getById(batchAccount.id());
Assert.assertTrue(false);
}
catch (CloudException exception) {
Assert.assertEquals(exception.getResponse().code(), 404);
}

batchAccount = batchManager.batchAccounts().getById(batchAccount.id());
Assert.assertNull(batchAccount);
}

@Test
Expand Down Expand Up @@ -217,12 +213,7 @@ public void canCreateBatchAccountWithApplication() throws Exception {
Assert.assertEquals(application.updatesAllowed(), allowUpdates);

batchManager.batchAccounts().deleteByGroup(batchAccount.resourceGroupName(), batchAccount.name());
try {
batchManager.batchAccounts().getById(batchAccount.id());
Assert.assertTrue(false);
}
catch (CloudException exception) {
Assert.assertEquals(exception.getResponse().code(), 404);
}
batchAccount = batchManager.batchAccounts().getById(batchAccount.id());
Assert.assertNull(batchAccount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

/**
* Provides access to getting a specific Azure resource based on its resource group and parent.
*
* @param <T> the type of the resource collection
*/
@LangDefinition(ContainerName = "CollectionActions", CreateAsyncMethods = true, MethodConversionType = LangDefinition.MethodConversion.OnlyMethod)
public interface SupportsDeletingByParent<T> {
public interface SupportsDeletingByParent {
/**
* Deletes a resource from Azure, identifying it by its name and its resource group.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class IndependentChildResourcesImpl<
SupportsGettingById<T>,
SupportsGettingByParent<T>,
SupportsListingByParent<T>,
SupportsDeletingByParent<T> {
SupportsDeletingByParent {
protected final InnerCollectionT innerCollection;
protected final ManagerT manager;

Expand All @@ -67,8 +67,6 @@ public PagedList<T> listByParent(GroupableResource parentResource) {
return listByParent(parentResource.resourceGroupName(), parentResource.name());
}



@Override
public void deleteByParent(String groupName, String parentName, String name) {
deleteByParentAsync(groupName, parentName, name).toBlocking().subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class IndependentChildrenImpl<
SupportsGettingByParent<T>,
SupportsListingByParent<T>,
SupportsDeletingById,
SupportsDeletingByParent<T> {
SupportsDeletingByParent {
protected final InnerCollectionT innerCollection;
protected final ManagerT manager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface SqlDatabases extends
SupportsDeletingById,
SupportsGettingById<SqlDatabase>,
SupportsBatchCreation<SqlDatabase>,
SupportsDeletingByParent<SqlDatabase> {
SupportsDeletingByParent {

/**
* Gets the SQLDatabase based on the resource group name, SQLServer name and SQLDatabase name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface SqlElasticPools extends
SupportsDeletingById,
SupportsGettingById<SqlElasticPool>,
SupportsBatchCreation<SqlElasticPool>,
SupportsDeletingByParent<SqlElasticPool> {
SupportsDeletingByParent {

/**
* Gets the SQLElasticPool based on the resource group name, SQLServer name and SQLElasticPool name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ public interface SqlFirewallRule extends

/**
* Container interface for all the definitions that need to be implemented.
* @param <CreateStageT> The final stage for which return creatable for FirewallRule
*/
interface Definition extends
SqlFirewallRule.DefinitionStages.Blank,
SqlFirewallRule.DefinitionStages.WithStartIpAddress,
SqlFirewallRule.DefinitionStages.WithEndIpAddress,
interface Definition<CreateStageT> extends
SqlFirewallRule.DefinitionStages.Blank<CreateStageT>,
SqlFirewallRule.DefinitionStages.WithStartIpAddress<CreateStageT>,
SqlFirewallRule.DefinitionStages.WithEndIpAddress<CreateStageT>,
SqlFirewallRule.DefinitionStages.Parentable,
SqlFirewallRule.DefinitionStages.WithCreate {
}

Expand All @@ -55,34 +57,37 @@ interface Definition extends
interface DefinitionStages {
/**
* The first stage of the SQL Server definition.
* @param <CreateStageT> The final stage for which return creatable for FirewallRule
*/
interface Blank extends SqlFirewallRule.DefinitionStages.WithStartIpAddress {
interface Blank<CreateStageT> extends SqlFirewallRule.DefinitionStages.WithStartIpAddress<CreateStageT> {
}

/**
* The SQL Firewall Rule definition to set the starting IP Address for the server.
* @param <CreateStageT> The final stage for which return creatable for FirewallRule
*/
interface WithStartIpAddress {
interface WithStartIpAddress<CreateStageT> {
/**
* Sets the starting IP address of SQL server's firewall rule.
*
* @param startIpAddress start IP address in IPv4 format.
* @return The next stage of definition.
*/
SqlFirewallRule.DefinitionStages.WithEndIpAddress withStartIpAddress(String startIpAddress);
SqlFirewallRule.DefinitionStages.WithEndIpAddress<CreateStageT> withStartIpAddress(String startIpAddress);
}

/**
* The SQL Firewall Rule definition to set the starting IP Address for the server.
* @param <CreateStageT> The final stage for which return creatable for FirewallRule
*/
interface WithEndIpAddress {
interface WithEndIpAddress<CreateStageT> {
/**
* Sets the ending IP address of SQL server's firewall rule.
*
* @param endIpAddress end IP address in IPv4 format.
* @return The next stage of definition.
*/
SqlFirewallRule.DefinitionStages.WithCreate withEndIpAddress(String endIpAddress);
CreateStageT withEndIpAddress(String endIpAddress);
}

/**
Expand Down Expand Up @@ -119,9 +124,17 @@ interface WithSqlServer {
* SQL Server in the cloud, but exposing additional optional inputs to
* specify.
*/
interface WithCreate extends
interface Parentable extends
SqlFirewallRule.DefinitionStages.WithSqlServer {
}

/**
* A SQL Server definition with sufficient inputs to create a new
* SQL Server in the cloud, but exposing additional optional inputs to
* specify.
*/
interface WithCreate extends Creatable<SqlFirewallRule> {
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByParent;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById;
import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeletingById;

/**
* Entry point to SQL FirewallRule management API.
*/
@Fluent
public interface SqlFirewallRules extends
SupportsCreating<SqlFirewallRule.DefinitionStages.Blank>,
SupportsDeletingById,
SupportsGettingById<SqlFirewallRule>,
SupportsDeletingByParent<SqlFirewallRule> {
SupportsDeletingByParent {

/**
* Gets the SQLDatabase based on the resource group name, SQLServer name and FirewallRule name.
Expand Down Expand Up @@ -59,4 +57,20 @@ public interface SqlFirewallRules extends
* @return the list of SQLDatabases in a SQLServer
*/
PagedList<SqlFirewallRule> listBySqlServer(GroupableResource sqlServer);

/**
* Entry point to SQL FirewallRule management API, which already have the SQLServer specified.
*/
interface SqlFirewallRulesCreatable extends SqlFirewallRules {
SqlFirewallRule.DefinitionStages.Blank<SqlFirewallRule.DefinitionStages.WithCreate> definedWithSqlServer(String resourceGroupName, String sqlServerName, String firewallRuleName);
}

/**
* Entry point to SQL FirewallRule management API, which does not have SqlServer specified yet.
*/
interface SqlFirewallRulesParentable extends SqlFirewallRules {
SqlFirewallRule.DefinitionStages.Blank<SqlFirewallRule.DefinitionStages.Parentable> define(String firewallRuleName);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.microsoft.azure.management.sql;

import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.apigeneration.Fluent;
import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource;
import com.microsoft.azure.management.resources.fluentcore.model.Appliable;
Expand Down Expand Up @@ -42,7 +43,45 @@ public interface SqlServer extends
*/
String adminLogin();

/**
* @return returns entry point to manage FirewallRules in SqlServer.
*/
FirewallRules firewallRules();

/**
* Entry point to access FirewallRules from the SQL Server.
*/
interface FirewallRules {
/**
* Gets a particular firewall rule.
*
* @param firewallRuleName name of the firewall rule to get
* @return Returns the SqlFirewall rule with in the SQL Server
*/
SqlFirewallRule get(String firewallRuleName);

/**
* Creates a new firewall rule in SQL Server.
*
* @param firewallRuleName name of the firewall rule to be created
* @return Returns a stage to specify arguments of the firewall rule
*/
SqlFirewallRule.DefinitionStages.Blank<SqlFirewallRule.DefinitionStages.WithCreate> define(String firewallRuleName);

/**
* Returns all the firewall rules for the server.
*
* @return list of firewall rules for the server.
*/
PagedList<SqlFirewallRule> list();

/**
* Delete specified firewall rule in the server.
*
* @param firewallRuleName name of the firewall rule to delete
*/
void delete(String firewallRuleName);
}
/**************************************************************
* Fluent interfaces to provision a SqlServer
**************************************************************/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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.sql.implementation;

import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.sql.SqlFirewallRule;
import com.microsoft.azure.management.sql.SqlFirewallRules;
import com.microsoft.azure.management.sql.SqlServer;

/**
* Implementation of SqlServer.FirewallRules, which enables the creating the firewall rules from the SQLServer directly.
*/
public class FirewallRulesImpl implements SqlServer.FirewallRules {

private final String resourceGroupName;
private final String sqlServerName;
private final SqlFirewallRules.SqlFirewallRulesCreatable sqlFirewallRules;

FirewallRulesImpl(ServersInner innerCollection, SqlServerManager manager, String resourceGroupName, String sqlServerName) {
this.resourceGroupName = resourceGroupName;
this.sqlServerName = sqlServerName;
this.sqlFirewallRules = new SqlFirewallRulesImpl(innerCollection, manager);

}

@Override
public SqlFirewallRule get(String firewallRuleName) {
return this.sqlFirewallRules.getBySqlServer(this.resourceGroupName, this.sqlServerName, firewallRuleName);
}

@Override
public SqlFirewallRule.DefinitionStages.Blank define(String firewallRuleName) {
return this.sqlFirewallRules.definedWithSqlServer(this.resourceGroupName, this.sqlServerName, firewallRuleName);
}

@Override
public PagedList<SqlFirewallRule> list() {
return this.sqlFirewallRules.listBySqlServer(this.resourceGroupName, this.sqlServerName);
}

@Override
public void delete(String firewallRuleName) {
this.sqlFirewallRules.deleteByParent(this.resourceGroupName, this.sqlServerName, firewallRuleName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public PagedList<SqlDatabase> listByParent(String resourceGroupName, String pare

@Override
protected SqlDatabaseImpl wrapModel(DatabaseInner inner) {
if (inner == null) {
return null;
}

return new SqlDatabaseImpl(inner.name(), inner, this.innerCollection, manager.sqlElasticPools());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public PagedList<SqlElasticPool> listByParent(String resourceGroupName, String p

@Override
protected SqlElasticPoolImpl wrapModel(ElasticPoolInner inner) {
if (inner == null) {
return null;
}

return new SqlElasticPoolImpl(inner.name(), inner, this.innerCollection);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

/**
* Implementation for SqlFirewallRule and its parent interfaces.
* @param <CreateStageT> The final stage for which return creatable for FirewallRule
*/
public class SqlFirewallRuleImpl
public class SqlFirewallRuleImpl<CreateStageT>
extends IndependentChildImpl<
SqlFirewallRule,
SqlServer,
FirewallRuleInner,
SqlFirewallRuleImpl>
SqlFirewallRuleImpl<CreateStageT>>
implements SqlFirewallRule,
SqlFirewallRule.Definition,
SqlFirewallRule.Definition<CreateStageT>,
SqlFirewallRule.Update,
IndependentChild.DefinitionStages.WithParentResource<SqlFirewallRule, SqlServer> {
private final ServersInner innerCollection;
Expand Down Expand Up @@ -99,15 +100,15 @@ public Creatable<SqlFirewallRule> withExistingSqlServer(SqlServer existingSqlSer
}

@Override
public SqlFirewallRule.DefinitionStages.WithEndIpAddress withStartIpAddress(String startIpAddress) {
public SqlFirewallRuleImpl<CreateStageT> withStartIpAddress(String startIpAddress) {
this.inner().withStartIpAddress(startIpAddress);
return this;
}

@Override
public SqlFirewallRule.DefinitionStages.WithCreate withEndIpAddress(String endIpAddress) {
public CreateStageT withEndIpAddress(String endIpAddress) {
this.inner().withEndIpAddress(endIpAddress);
return this;
return (CreateStageT) this;
}

@Override
Expand Down
Loading