Java Code Examples for com.microsoft.azure.management.resources.fluentcore.utils.SdkContext#randomUuid()
The following examples show how to use
com.microsoft.azure.management.resources.fluentcore.utils.SdkContext#randomUuid() .
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: RoleAssignmentTests.java From azure-libraries-for-java with MIT License | 6 votes |
@Test public void canCRUDRoleAssignment() throws Exception { String roleAssignmentName = SdkContext.randomUuid(); String spName = SdkContext.randomResourceName("sp", 20); ServicePrincipal sp = graphRbacManager.servicePrincipals().define(spName) .withNewApplication("http://" + spName) .create(); SdkContext.sleep(15000); RoleAssignment roleAssignment = graphRbacManager.roleAssignments() .define(roleAssignmentName) .forServicePrincipal(sp) .withBuiltInRole(BuiltInRole.CONTRIBUTOR) .withSubscriptionScope(resourceManager.subscriptionId()) .create(); Assert.assertNotNull(roleAssignment); }
Example 2
Source File: RoleAssignmentHelper.java From azure-libraries-for-java with MIT License | 5 votes |
/** * Specifies that applications running on an Azure service with this identity requires * the given access role with scope of access limited to the ARM resource identified by * the resource ID specified in the scope parameter. * * @param scope scope of the access represented in ARM resource ID format * @param asRole access role to assigned to the identity * @return RoleAssignmentHelper */ public RoleAssignmentHelper withAccessTo(final String scope, final BuiltInRole asRole) { FunctionalTaskItem creator = new FunctionalTaskItem() { @Override public Observable<Indexable> call(final Context cxt) { final String principalId = idProvider.principalId(); if (principalId == null) { return cxt.voidObservable(); } final String roleAssignmentName = SdkContext.randomUuid(); final String resourceScope; if (scope == CURRENT_RESOURCE_GROUP_SCOPE) { resourceScope = resourceGroupId(idProvider.resourceId()); } else { resourceScope = scope; } return rbacManager .roleAssignments() .define(roleAssignmentName) .forObjectId(principalId) .withBuiltInRole(asRole) .withScope(resourceScope) .createAsync() .last() .onErrorResumeNext(new Func1<Throwable, Observable<Indexable>>() { @Override public Observable<Indexable> call(Throwable throwable) { if (isRoleAssignmentExists(throwable)) { return cxt.voidObservable(); } return Observable.<Indexable>error(throwable); } }); } }; this.preRunTaskGroup.addPostRunDependent(creator); return this; }
Example 3
Source File: RoleAssignmentHelper.java From azure-libraries-for-java with MIT License | 5 votes |
/** * Specifies that applications running on an Azure service with this identity requires * the access described in the given role definition with scope of access limited * to an ARM resource. * * @param scope scope of the access represented in ARM resource ID format * @param roleDefinitionId access role definition to assigned to the identity * @return RoleAssignmentHelper */ public RoleAssignmentHelper withAccessTo(final String scope, final String roleDefinitionId) { FunctionalTaskItem creator = new FunctionalTaskItem() { @Override public Observable<Indexable> call(final Context cxt) { final String principalId = idProvider.principalId(); if (principalId == null) { return cxt.voidObservable(); } final String roleAssignmentName = SdkContext.randomUuid(); final String resourceScope; if (scope == CURRENT_RESOURCE_GROUP_SCOPE) { resourceScope = resourceGroupId(idProvider.resourceId()); } else { resourceScope = scope; } return rbacManager .roleAssignments() .define(roleAssignmentName) .forObjectId(principalId) .withRoleDefinition(roleDefinitionId) .withScope(resourceScope) .createAsync() .last() .onErrorResumeNext(new Func1<Throwable, Observable<Indexable>>() { @Override public Observable<Indexable> call(Throwable throwable) { if (isRoleAssignmentExists(throwable)) { return cxt.voidObservable(); } return Observable.<Indexable>error(throwable); } }); } }; this.preRunTaskGroup.addPostRunDependent(creator); return this; }
Example 4
Source File: ExecutableImpl.java From azure-libraries-for-java with MIT License | 4 votes |
/** * Creates ExecutableImpl. */ protected ExecutableImpl() { this(SdkContext.randomUuid()); }
Example 5
Source File: IndexableTaskItem.java From azure-libraries-for-java with MIT License | 4 votes |
/** * Creates a TaskItem which is index-able using a random UUID. */ public IndexableTaskItem() { this(SdkContext.randomUuid()); }
Example 6
Source File: SqlDatabaseImportExportResponseImpl.java From azure-libraries-for-java with MIT License | 4 votes |
protected SqlDatabaseImportExportResponseImpl(ImportExportResponseInner innerObject) { super(innerObject); this.key = SdkContext.randomUuid(); }
Example 7
Source File: SqlServerOperationsTests.java From azure-libraries-for-java with MIT License | 4 votes |
@Test public void canChangeSqlServerAndDatabaseAutomaticTuning() throws Exception { String rgName = RG_NAME; String sqlServerName = SQL_SERVER_NAME; String sqlServerAdminName = "sqladmin"; String sqlServerAdminPassword = "N0t@P@ssw0rd!"; String databaseName = "db-from-sample"; String id = SdkContext.randomUuid(); String storageName = SdkContext.randomResourceName(SQL_SERVER_NAME, 22); // Create SqlServer sqlServer = sqlServerManager .sqlServers() .define(sqlServerName) .withRegion(Region.US_EAST) .withNewResourceGroup(rgName) .withAdministratorLogin(sqlServerAdminName) .withAdministratorPassword(sqlServerAdminPassword) .defineDatabase(databaseName) .fromSample(SampleName.ADVENTURE_WORKS_LT) .withBasicEdition() .attach() .create(); SqlDatabase dbFromSample = sqlServer.databases().get(databaseName); Assert.assertNotNull(dbFromSample); Assert.assertEquals(DatabaseEdition.BASIC, dbFromSample.edition()); SqlServerAutomaticTuning serverAutomaticTuning = sqlServer.getServerAutomaticTuning(); Assert.assertEquals(AutomaticTuningServerMode.UNSPECIFIED, serverAutomaticTuning.desiredState()); Assert.assertEquals(AutomaticTuningServerMode.UNSPECIFIED, serverAutomaticTuning.actualState()); Assert.assertEquals(4, serverAutomaticTuning.tuningOptions().size()); serverAutomaticTuning.update() .withAutomaticTuningMode(AutomaticTuningServerMode.AUTO) .withAutomaticTuningOption("createIndex", AutomaticTuningOptionModeDesired.OFF) .withAutomaticTuningOption("dropIndex", AutomaticTuningOptionModeDesired.ON) .withAutomaticTuningOption("forceLastGoodPlan", AutomaticTuningOptionModeDesired.DEFAULT) .apply(); Assert.assertEquals(AutomaticTuningServerMode.AUTO, serverAutomaticTuning.desiredState()); Assert.assertEquals(AutomaticTuningServerMode.AUTO, serverAutomaticTuning.actualState()); Assert.assertEquals(AutomaticTuningOptionModeDesired.OFF, serverAutomaticTuning.tuningOptions().get("createIndex").desiredState()); Assert.assertEquals(AutomaticTuningOptionModeActual.OFF, serverAutomaticTuning.tuningOptions().get("createIndex").actualState()); Assert.assertEquals(AutomaticTuningOptionModeDesired.ON, serverAutomaticTuning.tuningOptions().get("dropIndex").desiredState()); Assert.assertEquals(AutomaticTuningOptionModeActual.ON, serverAutomaticTuning.tuningOptions().get("dropIndex").actualState()); Assert.assertEquals(AutomaticTuningOptionModeDesired.DEFAULT, serverAutomaticTuning.tuningOptions().get("forceLastGoodPlan").desiredState()); SqlDatabaseAutomaticTuning databaseAutomaticTuning = dbFromSample.getDatabaseAutomaticTuning(); Assert.assertEquals(4, databaseAutomaticTuning.tuningOptions().size()); // The following results in "InternalServerError" at the moment databaseAutomaticTuning.update() .withAutomaticTuningMode(AutomaticTuningMode.AUTO) .withAutomaticTuningOption("createIndex", AutomaticTuningOptionModeDesired.OFF) .withAutomaticTuningOption("dropIndex", AutomaticTuningOptionModeDesired.ON) .withAutomaticTuningOption("forceLastGoodPlan", AutomaticTuningOptionModeDesired.DEFAULT) .apply(); Assert.assertEquals(AutomaticTuningMode.AUTO, databaseAutomaticTuning.desiredState()); Assert.assertEquals(AutomaticTuningMode.AUTO, databaseAutomaticTuning.actualState()); Assert.assertEquals(AutomaticTuningOptionModeDesired.OFF, databaseAutomaticTuning.tuningOptions().get("createIndex").desiredState()); Assert.assertEquals(AutomaticTuningOptionModeActual.OFF, databaseAutomaticTuning.tuningOptions().get("createIndex").actualState()); Assert.assertEquals(AutomaticTuningOptionModeDesired.ON, databaseAutomaticTuning.tuningOptions().get("dropIndex").desiredState()); Assert.assertEquals(AutomaticTuningOptionModeActual.ON, databaseAutomaticTuning.tuningOptions().get("dropIndex").actualState()); Assert.assertEquals(AutomaticTuningOptionModeDesired.DEFAULT, databaseAutomaticTuning.tuningOptions().get("forceLastGoodPlan").desiredState()); // cleanup dbFromSample.delete(); sqlServerManager.sqlServers().deleteByResourceGroup(rgName, sqlServerName); }
Example 8
Source File: SqlServerOperationsTests.java From azure-libraries-for-java with MIT License | 4 votes |
@Test public void canCRUDSqlServerWithImportDatabase() throws Exception { if (isPlaybackMode()) { // The test makes calls to the Azure Storage data plane APIs which are not mocked at this time. return; } // Create String rgName = RG_NAME; String sqlServerName = SQL_SERVER_NAME; String sqlServerAdminName = "sqladmin"; String sqlServerAdminPassword = "N0t@P@ssw0rd!"; String id = SdkContext.randomUuid(); String storageName = SdkContext.randomResourceName(SQL_SERVER_NAME, 22); SqlServer sqlServer = sqlServerManager .sqlServers() .define(sqlServerName) .withRegion(Region.US_EAST) .withNewResourceGroup(rgName) .withAdministratorLogin(sqlServerAdminName) .withAdministratorPassword(sqlServerAdminPassword) .withActiveDirectoryAdministrator("DSEng", id) .create(); SqlDatabase dbFromSample = sqlServer.databases().define("db-from-sample") .fromSample(SampleName.ADVENTURE_WORKS_LT) .withBasicEdition() .withTag("tag1", "value1") .create(); Assert.assertNotNull(dbFromSample); Assert.assertEquals(DatabaseEdition.BASIC, dbFromSample.edition()); SqlDatabaseImportExportResponse exportedDB; StorageAccount storageAccount = storageManager.storageAccounts().getByResourceGroup(sqlServer.resourceGroupName(), storageName); if (storageAccount == null) { Creatable<StorageAccount> storageAccountCreatable = storageManager.storageAccounts() .define(storageName) .withRegion(sqlServer.regionName()) .withExistingResourceGroup(sqlServer.resourceGroupName()); exportedDB = dbFromSample.exportTo(storageAccountCreatable, "from-sample", "dbfromsample.bacpac") .withSqlAdministratorLoginAndPassword(sqlServerAdminName, sqlServerAdminPassword) .execute(); storageAccount = storageManager.storageAccounts().getByResourceGroup(sqlServer.resourceGroupName(), storageName); } else { exportedDB = dbFromSample.exportTo(storageAccount, "from-sample", "dbfromsample.bacpac") .withSqlAdministratorLoginAndPassword(sqlServerAdminName, sqlServerAdminPassword) .execute(); } SqlDatabase dbFromImport = sqlServer.databases().define("db-from-import") .defineElasticPool("ep1") .withBasicPool() .attach() .importFrom(storageAccount, "from-sample", "dbfromsample.bacpac") .withSqlAdministratorLoginAndPassword(sqlServerAdminName, sqlServerAdminPassword) .withTag("tag2", "value2") .create(); Assert.assertNotNull(dbFromImport); Assert.assertEquals("ep1", dbFromImport.elasticPoolName()); dbFromImport.delete(); dbFromSample.delete(); sqlServer.elasticPools().delete("ep1"); sqlServerManager.sqlServers().deleteByResourceGroup(rgName, sqlServerName); }
Example 9
Source File: SqlServerOperationsTests.java From azure-libraries-for-java with MIT License | 4 votes |
@Test public void canCRUDSqlServerWithFirewallRule() throws Exception { // Create String rgName = RG_NAME; String sqlServerName = SQL_SERVER_NAME; String sqlServerAdminName = "sqladmin"; String id = SdkContext.randomUuid(); SqlServer sqlServer = sqlServerManager .sqlServers() .define(SQL_SERVER_NAME) .withRegion(Region.US_EAST) .withNewResourceGroup(RG_NAME) .withAdministratorLogin(sqlServerAdminName) .withAdministratorPassword("N0t@P@ssw0rd!") .withActiveDirectoryAdministrator("DSEng", id) .withoutAccessFromAzureServices() .defineFirewallRule("somefirewallrule1") .withIPAddress("0.0.0.1") .attach() .withTag("tag1", "value1") .create(); Assert.assertEquals(sqlServerAdminName, sqlServer.administratorLogin()); Assert.assertEquals("v12.0", sqlServer.kind()); Assert.assertEquals("12.0", sqlServer.version()); sqlServer = sqlServerManager.sqlServers().getByResourceGroup(RG_NAME, SQL_SERVER_NAME); Assert.assertEquals(sqlServerAdminName, sqlServer.administratorLogin()); Assert.assertEquals("v12.0", sqlServer.kind()); Assert.assertEquals("12.0", sqlServer.version()); SqlActiveDirectoryAdministrator sqlADAdmin = sqlServer.getActiveDirectoryAdministrator(); Assert.assertNotNull(sqlADAdmin); Assert.assertEquals("DSEng", sqlADAdmin.signInName()); Assert.assertNotNull(sqlADAdmin.id()); Assert.assertEquals("ActiveDirectory", sqlADAdmin.administratorType()); sqlADAdmin = sqlServer.setActiveDirectoryAdministrator("DSEngAll", id); Assert.assertNotNull(sqlADAdmin); Assert.assertEquals("DSEngAll", sqlADAdmin.signInName()); Assert.assertNotNull(sqlADAdmin.id()); Assert.assertEquals("ActiveDirectory", sqlADAdmin.administratorType()); sqlServer.removeActiveDirectoryAdministrator(); sqlADAdmin = sqlServer.getActiveDirectoryAdministrator(); Assert.assertNull(sqlADAdmin); SqlFirewallRule firewallRule = sqlServerManager.sqlServers().firewallRules().getBySqlServer(RG_NAME, SQL_SERVER_NAME, "somefirewallrule1"); Assert.assertEquals("0.0.0.1", firewallRule.startIPAddress()); Assert.assertEquals("0.0.0.1", firewallRule.endIPAddress()); firewallRule = sqlServerManager.sqlServers().firewallRules().getBySqlServer(RG_NAME, SQL_SERVER_NAME, "AllowAllWindowsAzureIps"); Assert.assertNull(firewallRule); sqlServer.enableAccessFromAzureServices(); firewallRule = sqlServerManager.sqlServers().firewallRules().getBySqlServer(RG_NAME, SQL_SERVER_NAME, "AllowAllWindowsAzureIps"); Assert.assertEquals("0.0.0.0", firewallRule.startIPAddress()); Assert.assertEquals("0.0.0.0", firewallRule.endIPAddress()); sqlServer.update() .withNewFirewallRule("0.0.0.2", "0.0.0.2", "newFirewallRule1") .apply(); sqlServer.firewallRules().delete("newFirewallRule2"); Assert.assertNull(sqlServer.firewallRules().get("newFirewallRule2")); firewallRule = sqlServerManager.sqlServers().firewallRules() .define("newFirewallRule2") .withExistingSqlServer(RG_NAME, SQL_SERVER_NAME) .withIPAddress("0.0.0.3") .create(); Assert.assertEquals("0.0.0.3", firewallRule.startIPAddress()); Assert.assertEquals("0.0.0.3", firewallRule.endIPAddress()); firewallRule = firewallRule.update().withStartIPAddress("0.0.0.1").apply(); Assert.assertEquals("0.0.0.1", firewallRule.startIPAddress()); Assert.assertEquals("0.0.0.3", firewallRule.endIPAddress()); sqlServer.firewallRules().delete("somefirewallrule1"); firewallRule = sqlServerManager.sqlServers().firewallRules().getBySqlServer(RG_NAME, SQL_SERVER_NAME, "somefirewallrule1"); Assert.assertNull(firewallRule); firewallRule = sqlServer.firewallRules().define("somefirewallrule2") .withIPAddress("0.0.0.4") .create(); Assert.assertEquals("0.0.0.4", firewallRule.startIPAddress()); Assert.assertEquals("0.0.0.4", firewallRule.endIPAddress()); firewallRule.delete(); }
Example 10
Source File: CreatableUpdatableImpl.java From azure-libraries-for-java with MIT License | 2 votes |
/** * Creates CreatableUpdatableImpl. * * @param name the name of the model * @param innerObject the inner model object */ protected CreatableUpdatableImpl(String name, InnerModelT innerObject) { this(name, SdkContext.randomUuid(), innerObject); }