com.microsoft.azure.management.storage.StorageAccount Java Examples

The following examples show how to use com.microsoft.azure.management.storage.StorageAccount. 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: VirtualMachineImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public void beforeGroupCreateOrUpdate() {
    // [1]. StorageProfile: If implicit storage account creation is required then add Creatable<StorageAccount>.
    //
    if (creatableStorageAccountKey == null && existingStorageAccountToAssociate == null) {
        if (osDiskRequiresImplicitStorageAccountCreation()
                || dataDisksRequiresImplicitStorageAccountCreation()) {
            Creatable<StorageAccount> storageAccountCreatable = null;
            if (this.creatableGroup != null) {
                storageAccountCreatable = this.storageManager.storageAccounts()
                        .define(this.namer.randomName("stg", 24).replace("-", ""))
                        .withRegion(this.regionName())
                        .withNewResourceGroup(this.creatableGroup);
            } else {
                storageAccountCreatable = this.storageManager.storageAccounts()
                        .define(this.namer.randomName("stg", 24).replace("-", ""))
                        .withRegion(this.regionName())
                        .withExistingResourceGroup(this.resourceGroupName());
            }
            this.creatableStorageAccountKey = this.addDependency(storageAccountCreatable);
        }
    }
    // [2]. BootDiagnosticsProfile: If any implicit resource creation is required then add Creatable<?>.
    //
    this.bootDiagnosticsHandler.prepare();
}
 
Example #2
Source File: SqlDatabaseExportRequestImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public SqlDatabaseExportRequestImpl exportTo(final Creatable<StorageAccount> storageAccountCreatable, final String containerName, final String fileName) {
    if (this.inner == null) {
        this.inner = new ExportRequest();
    }
    this.addDependency(new FunctionalTaskItem() {
        @Override
        public Observable<Indexable> call(final Context context) {
            return storageAccountCreatable.createAsync()
                .last()
                .flatMap(new Func1<Indexable, Observable<Indexable>>() {
                    @Override
                    public Observable<Indexable> call(final Indexable storageAccount) {
                        return getOrCreateStorageAccountContainer((StorageAccount) storageAccount, containerName, fileName, context);
                    }
                });
        }
    });
    return this;
}
 
Example #3
Source File: SqlDatabaseImportRequestImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public SqlDatabaseImportRequestImpl importFrom(final StorageAccount storageAccount, final String containerName, final String fileName) {
    Objects.requireNonNull(storageAccount);
    Objects.requireNonNull(containerName);
    Objects.requireNonNull(fileName);
    if (this.inner == null) {
        this.inner = new ImportExtensionRequest();
    }
    final SqlDatabaseImportRequestImpl self = this;
    this.addDependency(new FunctionalTaskItem() {
        @Override
        public Observable<Indexable> call(final Context context) {
            return getOrCreateStorageAccountContainer(storageAccount, containerName, fileName, context);
        }
    });
    return this;
}
 
Example #4
Source File: SqlDatabaseImportRequestImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
private Observable<Indexable> getOrCreateStorageAccountContainer(final StorageAccount storageAccount, final String containerName, final String fileName, final FunctionalTaskItem.Context context) {
    final SqlDatabaseImportRequestImpl self = this;
    return storageAccount.getKeysAsync()
        .flatMap(new Func1<List<StorageAccountKey>, Observable<StorageAccountKey>>() {
            @Override
            public Observable<StorageAccountKey> call(List<StorageAccountKey> storageAccountKeys) {
                return Observable.from(storageAccountKeys).first();
            }
        })
        .flatMap(new Func1<StorageAccountKey, Observable<Indexable>>() {
            @Override
            public Observable<Indexable> call(StorageAccountKey storageAccountKey) {
                self.inner.withStorageUri(String.format("%s%s/%s", storageAccount.endPoints().primary().blob(), containerName, fileName));
                self.inner.withStorageKeyType(StorageKeyType.STORAGE_ACCESS_KEY);
                self.inner.withStorageKey(storageAccountKey.value());
                return context.voidObservable();
            }
        });
}
 
Example #5
Source File: ContainerGroupImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public ContainerGroupImpl withNewAzureFileShareVolume(String volumeName, String shareName) {
    if (this.newFileShares == null || this.creatableStorageAccountKey == null) {
        StorageAccount.DefinitionStages.WithGroup definitionWithGroup = this.storageManager
                .storageAccounts()
                .define(SdkContext.randomResourceName("fs", 24))
                .withRegion(this.regionName());
        Creatable<StorageAccount> creatable;
        if (this.creatableGroup != null) {
            creatable = definitionWithGroup.withNewResourceGroup(this.creatableGroup);
        } else {
            creatable = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName());
        }
        this.creatableStorageAccountKey = this.addDependency(creatable);
        this.newFileShares = new HashMap<>();
    }
    this.newFileShares.put(volumeName, shareName);

    return this;
}
 
Example #6
Source File: EventHubImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
private Observable<CloudStorageAccount> getCloudStorageAsync(final StorageAccount storageAccount) {
    return storageAccount.getKeysAsync()
            .flatMapIterable(new Func1<List<StorageAccountKey>, Iterable<StorageAccountKey>>() {
                @Override
                public Iterable<StorageAccountKey> call(List<StorageAccountKey> storageAccountKeys) {
                    return storageAccountKeys;
                }
            })
            .last()
            .map(new Func1<StorageAccountKey, CloudStorageAccount>() {
                @Override
                public CloudStorageAccount call(StorageAccountKey storageAccountKey) {
                    try {
                    return CloudStorageAccount.parse(Utils.getStorageConnectionString(storageAccount.name(), storageAccountKey.value(), manager().inner().restClient()));
                    } catch (URISyntaxException syntaxException) {
                        throw Exceptions.propagate(syntaxException);
                    } catch (InvalidKeyException keyException) {
                        throw Exceptions.propagate(keyException);
                    }
                }
            });
}
 
Example #7
Source File: AzureClient.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
public StorageAccount createStorageAccount(String resourceGroup, String storageName, String storageLocation, StorageAccountSkuType accType, Boolean encryted,
        Map<String, String> tags) {
    return handleAuthException(() -> {
        WithCreate withCreate = azure.storageAccounts()
                .define(storageName)
                .withRegion(storageLocation)
                .withExistingResourceGroup(resourceGroup)
                .withTags(tags)
                .withSku(accType)
                .withOnlyHttpsTraffic();
        if (encryted) {
            withCreate.withBlobEncryption();
        }

        return withCreate.create();
    });
}
 
Example #8
Source File: FunctionAppImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public FunctionAppImpl withNewStorageAccount(String name, com.microsoft.azure.management.storage.SkuName sku) {
    StorageAccount.DefinitionStages.WithGroup storageDefine = manager().storageManager().storageAccounts()
        .define(name)
        .withRegion(regionName());
    if (super.creatableGroup != null && isInCreateMode()) {
        storageAccountCreatable = storageDefine.withNewResourceGroup(super.creatableGroup)
            .withGeneralPurposeAccountKind()
            .withSku(sku);
    } else {
        storageAccountCreatable = storageDefine.withExistingResourceGroup(resourceGroupName())
            .withGeneralPurposeAccountKind()
            .withSku(sku);
    }
    this.addDependency(storageAccountCreatable);
    return this;
}
 
Example #9
Source File: EventHubImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
private Observable<Boolean> createContainerIfNotExistsAsync(final StorageAccount storageAccount,
                                                            final String containerName) {
    return getCloudStorageAsync(storageAccount)
            .flatMap(new Func1<CloudStorageAccount, Observable<Boolean>>() {
                @Override
                public Observable<Boolean> call(final CloudStorageAccount cloudStorageAccount) {
                    return Observable.fromCallable(new Callable<Boolean>() {
                        @Override
                        public Boolean call() {
                            CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient();
                            try {
                                return blobClient.getContainerReference(containerName).createIfNotExists();
                            } catch (StorageException stgException) {
                                throw Exceptions.propagate(stgException);
                            } catch (URISyntaxException syntaxException) {
                                throw Exceptions.propagate(syntaxException);
                            }
                        }
                    }).subscribeOn(SdkContext.getRxScheduler());
                }
            });
}
 
Example #10
Source File: VirtualMachineImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public VirtualMachineImpl withNewStorageAccount(Creatable<StorageAccount> creatable) {
    // This method's effect is NOT additive.
    if (this.creatableStorageAccountKey == null) {
        this.creatableStorageAccountKey = this.addDependency(creatable);
    }
    return this;
}
 
Example #11
Source File: AzureTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Test
public void createStorageAccount() throws Exception {
    String storageAccountName = generateRandomResourceName("testsa", 12);
    StorageAccount storageAccount = azure.storageAccounts().define(storageAccountName)
            .withRegion(Region.ASIA_EAST)
            .withNewResourceGroup()
            .withSku(SkuName.PREMIUM_LRS)
            .create();

    Assert.assertEquals(storageAccount.name(), storageAccountName);

    azure.resourceGroups().beginDeleteByName(storageAccount.resourceGroupName());
}
 
Example #12
Source File: StorageAccountImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public Observable<StorageAccount> refreshAsync() {
    return super.refreshAsync().map(new Func1<StorageAccount, StorageAccount>() {
        @Override
        public StorageAccount call(StorageAccount storageAccount) {
            StorageAccountImpl impl = (StorageAccountImpl) storageAccount;
            impl.clearWrapperProperties();
            return impl;
        }
    });
}
 
Example #13
Source File: VirtualMachineImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public VirtualMachineImpl withNewStorageAccount(String name) {
    StorageAccount.DefinitionStages.WithGroup definitionWithGroup = this.storageManager
            .storageAccounts()
            .define(name)
            .withRegion(this.regionName());
    Creatable<StorageAccount> definitionAfterGroup;
    if (this.creatableGroup != null) {
        definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup);
    } else {
        definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName());
    }
    return withNewStorageAccount(definitionAfterGroup);
}
 
Example #14
Source File: BatchAccountImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public BatchAccountImpl withNewStorageAccount(Creatable<StorageAccount> creatable) {
    // This method's effect is NOT additive.
    if (this.creatableStorageAccountKey == null) {
        this.creatableStorageAccountKey = this.addDependency(creatable);
    }
    this.existingStorageAccountToAssociate = null;
    return this;
}
 
Example #15
Source File: TestBatchAI.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private static String ensureStorageAccount(StorageAccounts storageAccounts, String saName, String rgName, String shareName) throws Exception {
    StorageAccount storageAccount = storageAccounts.define(saName)
            .withRegion(Region.US_WEST)
            .withExistingResourceGroup(rgName)
            .create();

    return storageAccount.getKeys().get(0).value();
}
 
Example #16
Source File: TestNetworkWatcher.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
StorageAccount ensureStorageAccount(StorageAccounts storageAccounts) {
    return  storageAccounts.define("sa" + TEST_ID)
            .withRegion(REGION)
            .withExistingResourceGroup(groupName)
            .withGeneralPurposeAccountKindV2()
            .create();
}
 
Example #17
Source File: RegistryImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public RegistryImpl withNewStorageAccount(Creatable<StorageAccount> creatable) {
    this.storageAccountId = null;

    if (this.creatableStorageAccountKey == null) {
        this.creatableStorageAccountKey = this.addDependency(creatable);
    }
    return this;
}
 
Example #18
Source File: VirtualMachineScaleSetImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public VirtualMachineScaleSetImpl withNewStorageAccount(String name) {
    StorageAccount.DefinitionStages.WithGroup definitionWithGroup = this.storageManager
            .storageAccounts()
            .define(name)
            .withRegion(this.regionName());
    Creatable<StorageAccount> definitionAfterGroup;
    if (this.creatableGroup != null) {
        definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup);
    } else {
        definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName());
    }
    return withNewStorageAccount(definitionAfterGroup);
}
 
Example #19
Source File: VirtualMachineScaleSetImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
BootDiagnosticsHandler withBootDiagnostics(Creatable<StorageAccount> creatable) {
    // Diagnostics storage uri will be set later by this.handleDiagnosticsSettings(..)
    //
    this.enableDisable(true);
    this.creatableDiagnosticsStorageAccountKey = this.vmssImpl.addDependency(creatable);
    return this;
}
 
Example #20
Source File: AzureStorageAccountScanner.java    From clouditor with Apache License 2.0 5 votes vote down vote up
@Override
protected Asset transform(StorageAccount account) throws ScanException {
  var asset = super.transform(account);

  // TODO: support maps instead of just lists
  asset.setProperty(
      "encryptionStatuses",
      MAPPER.convertValue(account.encryptionStatuses(), AssetProperties.class));

  asset.setProperty("isAccessAllowedFromAllNetworks", account.isAccessAllowedFromAllNetworks());

  asset.setProperty("isAccessAllowedFromAzureServices", account.canAccessFromAzureServices());

  var isKeyRegenerated = false;

  /*List<EventData> accountLogs =
      this.api
          .monitor()
          .activityLogs()
          .defineQuery()
          .startingFrom(new DateTime().minus(90 * 24 * 3600 * 1000L))
          .endsBefore(new DateTime())
          .withAllPropertiesInResponse()
          .filterByResource(account.id())
          .execute();

  for (var data : accountLogs) {
    if (data.operationName()
        .value()
        .equals("Microsoft.Storage/storageAccounts/regenerateKey/action")) {
      isKeyRegenerated = true;
      break;
    }
  }

  map.put("keyRegenerated", isKeyRegenerated);*/

  return asset;
}
 
Example #21
Source File: StorageAccountInventoryCollector.java    From pacbot with Apache License 2.0 5 votes vote down vote up
public List<StorageAccountVH> fetchStorageAccountDetails(SubscriptionVH subscription,
		Map<String, Map<String, String>> tagMap) {
	List<StorageAccountVH> storageAccountList = new ArrayList<StorageAccountVH>();

	Azure azure = azureCredentialProvider.getClient(subscription.getTenant(),subscription.getSubscriptionId());
	PagedList<StorageAccount> storageAccounts = azure.storageAccounts().list();
	for (StorageAccount storageAccount : storageAccounts) {
		StorageAccountVH storageAccountVH = new StorageAccountVH();
		storageAccountVH.setResourceGroupName(storageAccount.resourceGroupName());
		storageAccountVH.setKind(storageAccount.kind().toString());
		storageAccountVH.setCanAccessFromAzureServices(storageAccount.canAccessFromAzureServices());
		storageAccountVH.setIpAddressesWithAccess(storageAccount.ipAddressesWithAccess());
		storageAccountVH.setId(storageAccount.id());
		storageAccountVH.setIpAddressRangesWithAccess(storageAccount.ipAddressRangesWithAccess());
		storageAccountVH.setAccessAllowedFromAllNetworks(storageAccount.isAccessAllowedFromAllNetworks());
		storageAccountVH.setAzureFilesAadIntegrationEnabled(storageAccount.isAzureFilesAadIntegrationEnabled());
		storageAccountVH.setHnsEnabled(storageAccount.isHnsEnabled());
		storageAccountVH.setName(storageAccount.name());
		storageAccountVH.setRegionName(storageAccount.regionName());
		storageAccountVH.setNetworkSubnetsWithAccess(storageAccount.networkSubnetsWithAccess());
		storageAccountVH.setSystemAssignedManagedServiceIdentityPrincipalId(
				storageAccount.systemAssignedManagedServiceIdentityPrincipalId());
		storageAccountVH.setSystemAssignedManagedServiceIdentityTenantId(
				storageAccount.systemAssignedManagedServiceIdentityTenantId());
		storageAccountVH.setTags(Util.tagsList(tagMap, storageAccount.resourceGroupName(), storageAccount.tags()));
		storageAccountVH.setSubscription(subscription.getSubscriptionId());
		storageAccountVH.setSubscriptionName(subscription.getSubscriptionName());
		endPointDetails(storageAccount.endPoints(), storageAccountVH);
		storageAccountList.add(storageAccountVH);
	}
	log.info("Target Type : {}  Total: {} ","Storage Account",storageAccountList.size());
	return storageAccountList;
}
 
Example #22
Source File: BatchAccountImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public BatchAccountImpl withNewStorageAccount(String storageAccountName) {
    StorageAccount.DefinitionStages.WithGroup definitionWithGroup = this.storageManager
            .storageAccounts()
            .define(storageAccountName)
            .withRegion(this.regionName());
    Creatable<StorageAccount> definitionAfterGroup;
    if (this.creatableGroup != null) {
        definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup);
    } else {
        definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName());
    }
    return withNewStorageAccount(definitionAfterGroup);
}
 
Example #23
Source File: VirtualMachineImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
void prepare() {
    DiagnosticsProfile diagnosticsProfile = this.vmInner().diagnosticsProfile();
    if (diagnosticsProfile == null
            || diagnosticsProfile.bootDiagnostics() == null
            || diagnosticsProfile.bootDiagnostics().storageUri() != null) {
        return;
    }
    boolean enableBD = Utils.toPrimitiveBoolean(diagnosticsProfile.bootDiagnostics().enabled());
    if (!enableBD) {
        return;
    }
    if (this.creatableDiagnosticsStorageAccountKey != null
            || this.vmImpl.creatableStorageAccountKey != null
            || this.vmImpl.existingStorageAccountToAssociate != null) {
        return;
    }
    String accountName = this.vmImpl.namer.randomName("stg", 24).replace("-", "");
    Creatable<StorageAccount> storageAccountCreatable;
    if (this.vmImpl.creatableGroup != null) {
        storageAccountCreatable = this.vmImpl.storageManager.storageAccounts()
                .define(accountName)
                .withRegion(this.vmImpl.regionName())
                .withNewResourceGroup(this.vmImpl.creatableGroup);
    } else {
        storageAccountCreatable = this.vmImpl.storageManager.storageAccounts()
                .define(accountName)
                .withRegion(this.vmImpl.regionName())
                .withExistingResourceGroup(this.vmImpl.resourceGroupName());
    }
    this.creatableDiagnosticsStorageAccountKey = this.vmImpl.addDependency(storageAccountCreatable);
}
 
Example #24
Source File: ITManagedStorageAccountKey.java    From azure-keyvault-java with MIT License 5 votes vote down vote up
private StorageAccount initStorageAccount(final String storageAccountName, final String roleAccountUUID) {
    StorageAccount storageAccount = storageManager.storageAccounts().define(storageAccountName)
            .withRegion(VAULT_REGION).withExistingResourceGroup(RESOURCE_GROUP).create();
    
    graphRbacManager.roleAssignments().define(roleAccountUUID).forObjectId("93c27d83-f79b-4cb2-8dd4-4aa716542e74")
            .withRoleDefinition(KEY_VAULT_ROLE.id()).withScope(storageAccount.id()).create();

    return storageAccount;
}
 
Example #25
Source File: EventHubImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
public CaptureSettings withExistingStorageAccountForCapturedData(final String storageAccountId, final String containerName) {
    this.ensureSettings().destination().withStorageAccountResourceId(storageAccountId);
    this.ensureSettings().destination().withBlobContainer(containerName);
    //
    // Schedule task to create container if not exists.
    //
    addDependency(new FunctionalTaskItem() {
        @Override
        public Observable<Indexable> call(final Context context) {
            return storageManager.storageAccounts().getByIdAsync(storageAccountId)
                    .last()
                    .flatMap(new Func1<StorageAccount, Observable<Indexable>>() {
                        @Override
                        public Observable<Indexable> call(StorageAccount storageAccount) {
                            if (storageAccount == null) {
                                return Observable.error(new Throwable(String.format("Storage account with id: %s not found (storing captured data)", storageAccountId)));
                            }
                            ensureSettings().destination().withStorageAccountResourceId(storageAccount.id());
                            return createContainerIfNotExistsAsync(storageAccount, containerName)
                                    .flatMap(new Func1<Boolean, Observable<Indexable>>() {
                                        @Override
                                        public Observable<Indexable> call(Boolean aBoolean) {
                                            return context.voidObservable();
                                        }
                                    });

                        }
                    });
        }
    });
    return this;
}
 
Example #26
Source File: EventHubImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
public CaptureSettings withNewStorageAccountForCapturedData(final Creatable<StorageAccount> creatableStorageAccount, final String containerName) {
    this.ensureSettings().destination().withStorageAccountResourceId("temp-id");
    this.ensureSettings().destination().withBlobContainer(containerName);
    //
    // Schedule task to create storage account and container.
    //
    addDependency(new FunctionalTaskItem() {
        @Override
        public Observable<Indexable> call(final Context context) {
            return creatableStorageAccount.createAsync()
                    .last()
                    .flatMap(new Func1<Indexable, Observable<Indexable>>() {
                        @Override
                        public Observable<Indexable> call(Indexable indexable) {
                            StorageAccount storageAccount = (StorageAccount) indexable;
                            ensureSettings().destination().withStorageAccountResourceId(storageAccount.id());
                            return createContainerIfNotExistsAsync(storageAccount, containerName)
                                    .flatMap(new Func1<Boolean, Observable<Indexable>>() {
                                        @Override
                                        public Observable<Indexable> call(Boolean aBoolean) {
                                            return context.voidObservable();
                                        }
                                    });

                        }
                    });
        }
    });
    return this;
}
 
Example #27
Source File: UnmanagedDataDiskImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
protected static void ensureDisksVhdUri(List<VirtualMachineUnmanagedDataDisk> dataDisks, StorageAccount storageAccount, String namePrefix) {
    for (VirtualMachineUnmanagedDataDisk dataDisk : dataDisks) {
        if (dataDisk.creationMethod() == DiskCreateOptionTypes.EMPTY
                || dataDisk.creationMethod() == DiskCreateOptionTypes.FROM_IMAGE) {
            //New empty and from image data disk requires Vhd Uri to be set
            if (dataDisk.inner().vhd() == null) {
                dataDisk.inner().withVhd(new VirtualHardDisk());
                dataDisk.inner().vhd().withUri(storageAccount.endPoints().primary().blob()
                        + "vhds/"
                        + namePrefix + "-data-disk-" + dataDisk.lun() + "-" + UUID.randomUUID().toString() + ".vhd");
            }
        }
    }
}
 
Example #28
Source File: VirtualMachineImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
void handleDiagnosticsSettings() {
    DiagnosticsProfile diagnosticsProfile = this.vmInner().diagnosticsProfile();
    if (diagnosticsProfile == null
            || diagnosticsProfile.bootDiagnostics() == null
            || diagnosticsProfile.bootDiagnostics().storageUri() != null) {
        return;
    }
    boolean enableBD = Utils.toPrimitiveBoolean(diagnosticsProfile.bootDiagnostics().enabled());
    if (!enableBD) {
        return;
    }
    StorageAccount storageAccount = null;
    if (creatableDiagnosticsStorageAccountKey != null) {
        storageAccount = this.vmImpl.<StorageAccount>taskResult(creatableDiagnosticsStorageAccountKey);
    } else if (this.vmImpl.creatableStorageAccountKey != null) {
        storageAccount = this.vmImpl.<StorageAccount>taskResult(this.vmImpl.creatableStorageAccountKey);
    } else if (this.vmImpl.existingStorageAccountToAssociate != null) {
        storageAccount = this.vmImpl.existingStorageAccountToAssociate;
    }
    if (storageAccount == null) {
        throw new IllegalStateException("Unable to retrieve expected storageAccount instance for BootDiagnostics");
    }
    vmInner()
            .diagnosticsProfile()
            .bootDiagnostics()
            .withStorageUri(storageAccount.endPoints().primary().blob());
}
 
Example #29
Source File: VirtualMachineBootDiagnosticsTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Test
public void bootDiagnosticsShouldUseUnManagedDisksExplicitStorage() {
    final String storageName = SdkContext.randomResourceName("st", 14);
    StorageAccount storageAccount = storageManager.storageAccounts()
            .define(storageName)
            .withRegion(REGION)
            .withNewResourceGroup(RG_NAME)
            .create();

    VirtualMachine virtualMachine = computeManager.virtualMachines()
            .define(VMNAME)
            .withRegion(REGION)
            .withNewResourceGroup(RG_NAME)
            .withNewPrimaryNetwork("10.0.0.0/28")
            .withPrimaryPrivateIPAddressDynamic()
            .withoutPrimaryPublicIPAddress()
            .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
            .withRootUsername("Foo12")
            .withRootPassword("abc!@#F0orL")
            .withUnmanagedDisks()
            .withBootDiagnostics()
            .withExistingStorageAccount(storageAccount) // This storage account must be shared by disk and boot diagnostics
            .create();

    Assert.assertNotNull(virtualMachine);
    Assert.assertTrue(virtualMachine.isBootDiagnosticsEnabled());
    Assert.assertNotNull(virtualMachine.bootDiagnosticsStorageUri());
    Assert.assertTrue(virtualMachine.bootDiagnosticsStorageUri().contains(storageName));
}
 
Example #30
Source File: SqlDatabaseImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public SqlDatabaseImpl importFrom(final StorageAccount storageAccount, final String containerName, final String fileName) {
    final SqlDatabaseImpl self = this;
    Objects.requireNonNull(storageAccount);
    this.initializeImportRequestInner();
    this.addDependency(new FunctionalTaskItem() {
        @Override
        public Observable<Indexable> call(final Context context) {
            return storageAccount.getKeysAsync()
                .flatMap(new Func1<List<StorageAccountKey>, Observable<StorageAccountKey>>() {
                    @Override
                    public Observable<StorageAccountKey> call(List<StorageAccountKey> storageAccountKeys) {
                        return Observable.from(storageAccountKeys).first();
                    }
                })
                .flatMap(new Func1<StorageAccountKey, Observable<Indexable>>() {
                    @Override
                    public Observable<Indexable> call(StorageAccountKey storageAccountKey) {
                        self.importRequestInner.withStorageUri(String.format("%s%s/%s", storageAccount.endPoints().primary().blob(), containerName, fileName));
                        self.importRequestInner.withStorageKeyType(StorageKeyType.STORAGE_ACCESS_KEY);
                        self.importRequestInner.withStorageKey(storageAccountKey.value());
                        return context.voidObservable();
                    }
                });
        }
    });
    return this;
}