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

The following examples show how to use com.microsoft.azure.management.sql.SqlServer. 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
Source File: TestSql.java    From azure-libraries-for-java with 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 #2
Source File: SqlServerKeyOperationsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@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 #3
Source File: SqlServerDnsAliasOperationsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@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 File: SqlServerImpl.java    From azure-libraries-for-java with 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
Source File: SqlFailoverGroupOperationsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@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 #6
Source File: SqlEncryptionProtectorOperationsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@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 #7
Source File: SqlDatabaseOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #8
Source File: SqlElasticPoolOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #9
Source File: SqlFirewallRuleOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #10
Source File: SqlServerSecurityAlertPolicyImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public SqlServerSecurityAlertPolicyImpl withExistingSqlServer(SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    this.resourceGroupName = sqlServer.resourceGroupName();
    this.sqlServerName = sqlServer.name();
    return this;
}
 
Example #11
Source File: SqlServerSecurityAlertPolicyOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #12
Source File: SqlServerSecurityAlertPolicyOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #13
Source File: SqlVirtualNetworkRuleOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #14
Source File: SqlVirtualNetworkRuleOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #15
Source File: SqlDatabaseImpl.java    From azure-libraries-for-java with 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 #16
Source File: SqlDatabaseOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #17
Source File: SqlServerDnsAliasImpl.java    From azure-libraries-for-java with 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 #18
Source File: SqlServerKeyImpl.java    From azure-libraries-for-java with 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 #19
Source File: SqlServerImpl.java    From azure-libraries-for-java with 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;
            }
        });
}
 
Example #20
Source File: SqlFailoverGroupImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public SqlFailoverGroupImpl withExistingSqlServer(SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    this.resourceGroupName = sqlServer.resourceGroupName();
    this.sqlServerName = sqlServer.name();
    this.sqlServerLocation = sqlServer.regionName();
    return this;
}
 
Example #21
Source File: SqlServerKeyOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public SqlServerKey getBySqlServer(final SqlServer sqlServer, final String name) {
    Objects.requireNonNull(sqlServer);
    ServerKeyInner serverKeyInner = sqlServer.manager().inner().serverKeys()
        .get(sqlServer.resourceGroupName(), sqlServer.name(), name);
    return serverKeyInner != null ? new SqlServerKeyImpl(name, (SqlServerImpl) sqlServer, serverKeyInner, sqlServer.manager()) : null;
}
 
Example #22
Source File: SqlServerKeyOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public Observable<SqlServerKey> getBySqlServerAsync(final SqlServer sqlServer, final String name) {
    Objects.requireNonNull(sqlServer);
    return sqlServer.manager().inner().serverKeys()
        .getAsync(sqlServer.resourceGroupName(), sqlServer.name(), name)
        .map(new Func1<ServerKeyInner, SqlServerKey>() {
            @Override
            public SqlServerKey call(ServerKeyInner serverKeyInner) {
                return new SqlServerKeyImpl(name, (SqlServerImpl) sqlServer, serverKeyInner, sqlServer.manager());
            }
        });
}
 
Example #23
Source File: TestSql.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public SqlServer createResource(SqlServers resources) throws Exception {
    final String sqlServerName = "sql" + this.testId;
    final SqlServer[] sqlServers = new SqlServer[1];
    final SettableFuture<SqlServer> future = SettableFuture.create();
    Observable<Indexable> resourceStream = resources.define(sqlServerName)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup()
            .withAdministratorLogin("admin32")
            .withAdministratorPassword("Password~1")
            .withNewDatabase("database1")
            .withNewElasticPool("elasticPool1", ElasticPoolEdition.STANDARD, "databaseInEP")
            .withNewFirewallRule("10.10.10.10")
            .withTag("mytag", "testtag")
            .createAsync();

    Utils.<SqlServer>rootResource(resourceStream)
            .subscribe(new Action1<SqlServer>() {
                @Override
                public void call(SqlServer sqlServer) {
                    future.set(sqlServer);
                }
            });

    sqlServers[0] = future.get();

    Assert.assertNotNull(sqlServers[0].inner());

    Assert.assertNotNull(sqlServers[0].inner());
    // Including master database
    Assert.assertEquals(sqlServers[0].databases().list().size(), 3);
    Assert.assertEquals(sqlServers[0].elasticPools().list().size(), 1);
    Assert.assertEquals(sqlServers[0].firewallRules().list().size(), 2);

    return sqlServers[0];
}
 
Example #24
Source File: Utils.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
/**
 * Prints information for passed SQL Server.
 * @param sqlServer sqlServer to be printed
 */
public static void print(SqlServer sqlServer) {
    StringBuilder builder = new StringBuilder().append("Sql Server: ").append(sqlServer.id())
            .append("Name: ").append(sqlServer.name())
            .append("\n\tResource group: ").append(sqlServer.resourceGroupName())
            .append("\n\tRegion: ").append(sqlServer.region())
            .append("\n\tSqlServer version: ").append(sqlServer.version())
            .append("\n\tFully qualified name for Sql Server: ").append(sqlServer.fullyQualifiedDomainName());
    System.out.println(builder.toString());
}
 
Example #25
Source File: SQLServerInventoryCollector.java    From pacbot with 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 #26
Source File: SqlFailoverGroupOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #27
Source File: SqlFailoverGroupOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #28
Source File: SqlElasticPoolImpl.java    From azure-libraries-for-java with 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 #29
Source File: SqlElasticPoolOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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 #30
Source File: SqlServerDnsAliasOperationsImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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());
            }
        });
}