Java Code Examples for com.microsoft.azure.management.sql.SqlServer

The following examples show how to use com.microsoft.azure.management.sql.SqlServer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public Observable<SqlFailoverGroup> listBySqlServerAsync(final SqlServer sqlServer) {
    return sqlServer.manager().inner().failoverGroups()
        .listByServerAsync(sqlServer.resourceGroupName(), sqlServer.name())
        .flatMap(new Func1<Page<FailoverGroupInner>, Observable<FailoverGroupInner>>() {
            @Override
            public Observable<FailoverGroupInner> call(Page<FailoverGroupInner> failoverGroupInnerPage) {
                return Observable.from(failoverGroupInnerPage.items());
            }
        })
        .map(new Func1<FailoverGroupInner, SqlFailoverGroup>() {
            @Override
            public SqlFailoverGroup call(FailoverGroupInner failoverGroupInner) {
                return new SqlFailoverGroupImpl(failoverGroupInner.name(), (SqlServerImpl) sqlServer, failoverGroupInner, sqlServer.manager());
            }
        });
}
 
Example 2
@Override
public Observable<SqlEncryptionProtector> listBySqlServerAsync(final SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    return sqlServer.manager().inner().encryptionProtectors()
        .listByServerAsync(sqlServer.resourceGroupName(), sqlServer.name())
        .flatMap(new Func1<Page<EncryptionProtectorInner>, Observable<EncryptionProtectorInner>>() {
            @Override
            public Observable<EncryptionProtectorInner> call(Page<EncryptionProtectorInner> encryptionProtectorInnerPage) {
                return Observable.from(encryptionProtectorInnerPage.items());
            }
        })
        .map(new Func1<EncryptionProtectorInner, SqlEncryptionProtector>() {
            @Override
            public SqlEncryptionProtector call(EncryptionProtectorInner encryptionProtectorInner) {
                return new SqlEncryptionProtectorImpl((SqlServerImpl) sqlServer, encryptionProtectorInner, sqlServer.manager());
            }
        });
}
 
Example 3
@Override
public Observable<SqlServerDnsAlias> listBySqlServerAsync(final SqlServer sqlServer) {
    return sqlServer.manager().inner().serverDnsAliases()
        .listByServerAsync(sqlServer.resourceGroupName(), sqlServer.name())
        .flatMap(new Func1<Page<ServerDnsAliasInner>, Observable<ServerDnsAliasInner>>() {
            @Override
            public Observable<ServerDnsAliasInner> call(Page<ServerDnsAliasInner> serverDnsAliasInnerPage) {
                return Observable.from(serverDnsAliasInnerPage.items());
            }
        })
        .map(new Func1<ServerDnsAliasInner, SqlServerDnsAlias>() {
            @Override
            public SqlServerDnsAlias call(ServerDnsAliasInner serverDnsAliasInner) {
                return new SqlServerDnsAliasImpl(serverDnsAliasInner.name(), (SqlServerImpl) sqlServer, serverDnsAliasInner, sqlServer.manager());
            }
        });
}
 
Example 4
Source Project: azure-libraries-for-java   Source File: SqlServerImpl.java    License: MIT License 6 votes vote down vote up
@Override
public SqlServer.DefinitionStages.WithCreate withActiveDirectoryAdministrator(final String userLogin, final String objectId) {
    final SqlServerImpl self = this;
    sqlADAdminCreator = new FunctionalTaskItem() {
        @Override
        public Observable<Indexable> call(final Context context) {
            ServerAzureADAdministratorInner serverAzureADAdministratorInner = new ServerAzureADAdministratorInner()
                .withLogin(userLogin)
                .withSid(UUID.fromString(objectId))
                .withTenantId(UUID.fromString(self.manager().tenantId()));

            return self.manager().inner().serverAzureADAdministrators()
                .createOrUpdateAsync(self.resourceGroupName(), self.name(), serverAzureADAdministratorInner)
                .flatMap(new Func1<ServerAzureADAdministratorInner, Observable<Indexable>>() {
                    @Override
                    public Observable<Indexable> call(ServerAzureADAdministratorInner serverAzureADAdministratorInner) {
                        return context.voidObservable();
                    }
                });
        }
    };
    return this;
}
 
Example 5
@Override
public Observable<SqlServerKey> listBySqlServerAsync(final SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    return sqlServer.manager().inner().serverKeys()
        .listByServerAsync(sqlServer.resourceGroupName(), sqlServer.name())
        .flatMap(new Func1<Page<ServerKeyInner>, Observable<ServerKeyInner>>() {
            @Override
            public Observable<ServerKeyInner> call(Page<ServerKeyInner> serverKeyInnerPage) {
                return Observable.from(serverKeyInnerPage.items());
            }
        })
        .map(new Func1<ServerKeyInner, SqlServerKey>() {
            @Override
            public SqlServerKey call(ServerKeyInner serverKeyInner) {
                return new SqlServerKeyImpl(serverKeyInner.name(), (SqlServerImpl) sqlServer, serverKeyInner, sqlServer.manager());
            }
        });
}
 
Example 6
Source Project: azure-libraries-for-java   Source File: TestSql.java    License: MIT License 6 votes vote down vote up
@Override
public SqlServer updateResource(SqlServer sqlServer) throws Exception {
    sqlServer = sqlServer.update()
            .withoutDatabase("database1")
            .withoutDatabase("databaseInEP")
            .withoutElasticPool("elasticPool1")
            .apply();

    Assert.assertNotNull(sqlServer.inner());
    // Just master database
    Assert.assertEquals(1, sqlServer.databases().list().size());
    Assert.assertEquals(0, sqlServer.elasticPools().list().size());
    Assert.assertEquals(2, sqlServer.firewallRules().list().size());

    return sqlServer;
}
 
Example 7
Source Project: pacbot   Source File: SQLDatabaseInventoryCollector.java    License: Apache License 2.0 5 votes vote down vote up
private void firewallRule(SqlServer sqlServer, SQLDatabaseVH sqlDatabaseVH) {
	List<Map<String, String>> firewallRuleList = new ArrayList<>();
	Map<String, String> firewallMap;
	for (SqlFirewallRule sqlFirewallRule : sqlServer.firewallRules().list()) {
		firewallMap = new HashMap<>();
		firewallMap.put("name", sqlFirewallRule.name());
		firewallMap.put("startIPAddress", sqlFirewallRule.startIPAddress());
		firewallMap.put("endIPAddress", sqlFirewallRule.endIPAddress());
		firewallRuleList.add(firewallMap);

	}
	for (SqlVirtualNetworkRule sqlVirtualNetworkRule : sqlServer.virtualNetworkRules().list()) {
		firewallMap = new HashMap<>();

		firewallMap.put("virtualNetworkRuleName",
				sqlVirtualNetworkRule.name() != null ? sqlVirtualNetworkRule.name() : "");
		firewallMap.put("virtualNetworkSubnetId",
				sqlVirtualNetworkRule.subnetId() != null ? sqlVirtualNetworkRule.subnetId() : "");
		firewallMap.put("virtualNetworkResourceGroupName",
				sqlVirtualNetworkRule.resourceGroupName() != null ? sqlVirtualNetworkRule.resourceGroupName() : "");
		firewallMap.put("virtualNetworkState",
				sqlVirtualNetworkRule.state() != null ? sqlVirtualNetworkRule.state() : "");

		firewallRuleList.add(firewallMap);
	}
	sqlDatabaseVH.setFirewallRuleDetails(firewallRuleList);
}
 
Example 8
Source Project: pacbot   Source File: SQLServerInventoryCollector.java    License: Apache License 2.0 5 votes vote down vote up
public List<SQLServerVH> fetchSQLServerDetails(SubscriptionVH subscription,
		Map<String, Map<String, String>> tagMap) {

	List<SQLServerVH> sqlServerList = new ArrayList<>();
	Azure azure = azureCredentialProvider.getClient(subscription.getTenant(),subscription.getSubscriptionId());
	PagedList<SqlServer> sqlServers = azure.sqlServers().list();
	for (SqlServer sqlServer : sqlServers) {
		SQLServerVH sqlServerVH = new SQLServerVH();
		sqlServerVH.setSubscription(subscription.getSubscriptionId());
		sqlServerVH.setSubscriptionName(subscription.getSubscriptionName());
		sqlServerVH.setId(sqlServer.id());
		sqlServerVH.setKind(sqlServer.kind());
		sqlServerVH.setName(sqlServer.name());
		sqlServerVH.setRegionName(sqlServer.regionName());
		sqlServerVH.setState(sqlServer.state());
		sqlServerVH.setSystemAssignedManagedServiceIdentityPrincipalId(
				sqlServer.systemAssignedManagedServiceIdentityPrincipalId());
		sqlServerVH.setSystemAssignedManagedServiceIdentityTenantId(
				sqlServer.systemAssignedManagedServiceIdentityTenantId());
		sqlServerVH.setTags(Util.tagsList(tagMap, sqlServer.resourceGroupName(), sqlServer.tags()));
		sqlServerVH.setVersion(sqlServer.version());
		sqlServerVH.setAdministratorLogin(sqlServer.administratorLogin());
		firewallRule(sqlServer, sqlServerVH);
		getElasticPoolList(sqlServer.elasticPools().list(), sqlServerVH);
		getFailoverGroupList(sqlServer.failoverGroups().list(), sqlServerVH);
		sqlServerList.add(sqlServerVH);
	}
	log.info("Target Type : {}  Total: {} ","SqlServer",sqlServerList.size());
	return sqlServerList;

}
 
Example 9
Source Project: pacbot   Source File: SQLServerInventoryCollector.java    License: Apache License 2.0 5 votes vote down vote up
private void firewallRule(SqlServer sqlServer, SQLServerVH sqlServerVH) {
	List<Map<String, String>> firewallRuleList = new ArrayList<>();
	Map<String, String> firewallMap;
	for (SqlFirewallRule sqlFirewallRule : sqlServer.firewallRules().list()) {
		firewallMap = new HashMap<>();
		firewallMap.put("name", sqlFirewallRule.name());
		firewallMap.put("startIPAddress", sqlFirewallRule.startIPAddress());
		firewallMap.put("endIPAddress", sqlFirewallRule.endIPAddress());
		firewallRuleList.add(firewallMap);

	}
	for (SqlVirtualNetworkRule sqlVirtualNetworkRule : sqlServer.virtualNetworkRules().list()) {
		firewallMap = new HashMap<>();

		firewallMap.put("virtualNetworkRuleName",
				sqlVirtualNetworkRule.name() != null ? sqlVirtualNetworkRule.name() : "");
		firewallMap.put("virtualNetworkSubnetId",
				sqlVirtualNetworkRule.subnetId() != null ? sqlVirtualNetworkRule.subnetId() : "");
		firewallMap.put("virtualNetworkResourceGroupName",
				sqlVirtualNetworkRule.resourceGroupName() != null ? sqlVirtualNetworkRule.resourceGroupName() : "");
		firewallMap.put("virtualNetworkState",
				sqlVirtualNetworkRule.state() != null ? sqlVirtualNetworkRule.state() : "");

		firewallRuleList.add(firewallMap);
	}
	sqlServerVH.setFirewallRuleDetails(firewallRuleList);
}
 
Example 10
@Override
public SqlFailoverGroup getBySqlServer(SqlServer sqlServer, String name) {
    Objects.requireNonNull(sqlServer);
    FailoverGroupInner failoverGroupInner = sqlServer.manager().inner().failoverGroups()
        .get(sqlServer.resourceGroupName(), sqlServer.name(), name);
    return failoverGroupInner != null ? new SqlFailoverGroupImpl(name, (SqlServerImpl) sqlServer, failoverGroupInner, sqlServer.manager()) : null;
}
 
Example 11
@Override
public Observable<SqlFailoverGroup> getBySqlServerAsync(final SqlServer sqlServer, final String name) {
    Objects.requireNonNull(sqlServer);
    return sqlServer.manager().inner().failoverGroups()
        .getAsync(sqlServer.resourceGroupName(), sqlServer.name(), name)
        .map(new Func1<FailoverGroupInner, SqlFailoverGroup>() {
            @Override
            public SqlFailoverGroup call(FailoverGroupInner failoverGroupInner) {
                return new SqlFailoverGroupImpl(name, (SqlServerImpl) sqlServer, failoverGroupInner, sqlServer.manager());
            }
        });
}
 
Example 12
@Override
public SqlEncryptionProtector getBySqlServer(SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    EncryptionProtectorInner encryptionProtectorInner = sqlServer.manager().inner().encryptionProtectors()
        .get(sqlServer.resourceGroupName(), sqlServer.name());
    return encryptionProtectorInner != null ? new SqlEncryptionProtectorImpl((SqlServerImpl) sqlServer, encryptionProtectorInner, sqlServer.manager()) : null;
}
 
Example 13
@Override
public Observable<SqlEncryptionProtector> getBySqlServerAsync(final SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    return sqlServer.manager().inner().encryptionProtectors()
        .getAsync(sqlServer.resourceGroupName(), sqlServer.name())
        .map(new Func1<EncryptionProtectorInner, SqlEncryptionProtector>() {
            @Override
            public SqlEncryptionProtector call(EncryptionProtectorInner encryptionProtectorInner) {
                return new SqlEncryptionProtectorImpl((SqlServerImpl) sqlServer, encryptionProtectorInner, sqlServer.manager());
            }
        });
}
 
Example 14
@Override
public SqlServerDnsAlias getBySqlServer(SqlServer sqlServer, String name) {
    Objects.requireNonNull(sqlServer);
    ServerDnsAliasInner serverDnsAliasInner = sqlServer.manager().inner().serverDnsAliases()
        .get(sqlServer.resourceGroupName(), sqlServer.name(), name);
    return serverDnsAliasInner != null ? new SqlServerDnsAliasImpl(name, (SqlServerImpl) sqlServer, serverDnsAliasInner, sqlServer.manager()) : null;
}
 
Example 15
@Override
public Observable<SqlServerDnsAlias> getBySqlServerAsync(final SqlServer sqlServer, final String name) {
    Objects.requireNonNull(sqlServer);
    return sqlServer.manager().inner().serverDnsAliases()
        .getAsync(sqlServer.resourceGroupName(), sqlServer.name(), name)
        .map(new Func1<ServerDnsAliasInner, SqlServerDnsAlias>() {
            @Override
            public SqlServerDnsAlias call(ServerDnsAliasInner serverDnsAliasInner) {
                return new SqlServerDnsAliasImpl(name, (SqlServerImpl) sqlServer, serverDnsAliasInner, sqlServer.manager());
            }
        });
}
 
Example 16
Source Project: azure-libraries-for-java   Source File: SqlElasticPoolImpl.java    License: MIT License 5 votes vote down vote up
@Override
public SqlElasticPoolImpl withExistingSqlServer(SqlServer sqlServer) {
    this.resourceGroupName = sqlServer.resourceGroupName();
    this.sqlServerName = sqlServer.name();
    this.sqlServerLocation = sqlServer.regionName();

    return this;
}
 
Example 17
@Override
public SqlElasticPool getBySqlServer(SqlServer sqlServer, String name) {
    if (sqlServer == null) {
        return null;
    }
    ElasticPoolInner inner = this.manager.inner().elasticPools().get(sqlServer.resourceGroupName(), sqlServer.name(), name);
    return (inner != null) ? new SqlElasticPoolImpl(inner.name(), (SqlServerImpl) sqlServer, inner, manager) : null;
}
 
Example 18
@Override
public List<SqlElasticPool> listBySqlServer(SqlServer sqlServer) {
    List<SqlElasticPool> elasticPoolSet = new ArrayList<>();
    if (sqlServer != null) {
        for (ElasticPoolInner inner : this.manager.inner().elasticPools().listByServer(sqlServer.resourceGroupName(), sqlServer.name())) {
            elasticPoolSet.add(new SqlElasticPoolImpl(inner.name(), (SqlServerImpl) sqlServer, inner, manager));
        }
    }
    return Collections.unmodifiableList(elasticPoolSet);
}
 
Example 19
@Override
public List<SqlFirewallRule> listBySqlServer(SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    List<SqlFirewallRule> firewallRuleSet = new ArrayList<>();
    for (FirewallRuleInner inner : sqlServer.manager().inner().firewallRules().listByServer(sqlServer.resourceGroupName(), sqlServer.name())) {
        firewallRuleSet.add(new SqlFirewallRuleImpl(inner.name(), (SqlServerImpl) sqlServer, inner, sqlServer.manager()));
    }
    return Collections.unmodifiableList(firewallRuleSet);
}
 
Example 20
@Override
public SqlServerSecurityAlertPolicyImpl withExistingSqlServer(SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    this.resourceGroupName = sqlServer.resourceGroupName();
    this.sqlServerName = sqlServer.name();
    return this;
}
 
Example 21
Source Project: azure-libraries-for-java   Source File: SqlServerDnsAliasImpl.java    License: MIT License 5 votes vote down vote up
@Override
public SqlServerDnsAliasImpl withExistingSqlServer(SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    this.resourceGroupName = sqlServer.resourceGroupName();
    this.sqlServerName = sqlServer.name();
    return this;
}
 
Example 22
@Override
public SqlServerSecurityAlertPolicy getBySqlServer(SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    ServerSecurityAlertPolicyInner serverSecurityAlertPolicyInner = sqlServer.manager().inner().serverSecurityAlertPolicies()
        .get(sqlServer.resourceGroupName(), sqlServer.name());
    return serverSecurityAlertPolicyInner != null ? new SqlServerSecurityAlertPolicyImpl((SqlServerImpl) sqlServer, serverSecurityAlertPolicyInner, sqlServer.manager()) : null;
}
 
Example 23
@Override
public Observable<SqlServerSecurityAlertPolicy> getBySqlServerAsync(final SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    return sqlServer.manager().inner().serverSecurityAlertPolicies()
        .getAsync(sqlServer.resourceGroupName(), sqlServer.name())
        .map(new Func1<ServerSecurityAlertPolicyInner, SqlServerSecurityAlertPolicy>() {
            @Override
            public SqlServerSecurityAlertPolicy call(ServerSecurityAlertPolicyInner serverSecurityAlertPolicyInner) {
                return new SqlServerSecurityAlertPolicyImpl((SqlServerImpl) sqlServer, serverSecurityAlertPolicyInner, sqlServer.manager());
            }
        });
}
 
Example 24
@Override
public SqlVirtualNetworkRule getBySqlServer(SqlServer sqlServer, String name) {
    if (sqlServer == null) {
        return null;
    }
    VirtualNetworkRuleInner inner = this.sqlServerManager.inner().virtualNetworkRules()
        .get(sqlServer.resourceGroupName(), sqlServer.name(), name);
    return (inner != null) ? new SqlVirtualNetworkRuleImpl(inner.name(), (SqlServerImpl) sqlServer, inner, sqlServerManager) : null;
}
 
Example 25
@Override
public List<SqlVirtualNetworkRule> listBySqlServer(SqlServer sqlServer) {
    List<SqlVirtualNetworkRule> virtualNetworkRuleSet = new ArrayList<>();
    if (sqlServer != null) {
        for (VirtualNetworkRuleInner inner : this.sqlServerManager.inner().virtualNetworkRules().listByServer(sqlServer.resourceGroupName(), sqlServer.name())) {
            virtualNetworkRuleSet.add(new SqlVirtualNetworkRuleImpl(inner.name(), (SqlServerImpl) sqlServer, inner, this.sqlServerManager));
        }
    }
    return Collections.unmodifiableList(virtualNetworkRuleSet);
}
 
Example 26
Source Project: azure-libraries-for-java   Source File: SqlDatabaseImpl.java    License: MIT License 5 votes vote down vote up
@Override
public SqlDatabaseImpl withExistingSqlServer(SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    this.resourceGroupName = sqlServer.resourceGroupName();
    this.sqlServerName = sqlServer.name();
    this.sqlServerLocation = sqlServer.regionName();

    return this;
}
 
Example 27
@Override
public SqlDatabase getBySqlServer(SqlServer sqlServer, String name) {
    if (sqlServer == null) {
        return null;
    }
    DatabaseInner inner = this.manager.inner().databases().get(sqlServer.resourceGroupName(), sqlServer.name(), name);
    return (inner != null) ? new SqlDatabaseImpl(inner.name(), (SqlServerImpl) sqlServer, inner, manager) : null;
}
 
Example 28
@Override
public List<SqlDatabase> listBySqlServer(SqlServer sqlServer) {
    List<SqlDatabase> firewallRuleSet = new ArrayList<>();
    if (sqlServer != null) {
        for (DatabaseInner inner : this.manager.inner().databases().listByServer(sqlServer.resourceGroupName(), sqlServer.name())) {
            firewallRuleSet.add(new SqlDatabaseImpl(inner.name(), (SqlServerImpl) sqlServer, inner, manager));
        }
    }
    return Collections.unmodifiableList(firewallRuleSet);
}
 
Example 29
Source Project: azure-libraries-for-java   Source File: SqlServerKeyImpl.java    License: MIT License 5 votes vote down vote up
@Override
public SqlServerKeyImpl withExistingSqlServer(SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    this.resourceGroupName = sqlServer.resourceGroupName();
    this.sqlServerName = sqlServer.name();
    return this;
}
 
Example 30
Source Project: azure-libraries-for-java   Source File: SqlServerImpl.java    License: MIT License 5 votes vote down vote up
@Override
public Observable<SqlServer> createResourceAsync() {
    final SqlServer self = this;
    return this.manager().inner().servers().createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner())
        .map(new Func1<ServerInner, SqlServer>() {
            @Override
            public SqlServer call(ServerInner serverInner) {
                setInner(serverInner);
                return self;
            }
        });
}