use of com.microsoft.azure.management.Azure in project photon-model by vmware.
the class AzureStorageEnumerationAdapterService method disassociateDiskStates.
/*
* Disassociate local disk states that no longer exist in Azure
*
* The logic works by recording a timestamp when enumeration starts. This timestamp is used to
* lookup resources which haven't been touched as part of current enumeration cycle. The other
* data point this method uses is the blob discovered as part of get blob call.
*
* A disassociate on a disk state is invoked only if it meets two criteria: - Timestamp older
* than current enumeration cycle. - blob is not present on Azure.
*/
private void disassociateDiskStates(StorageEnumContext context, StorageEnumStages next) {
Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(DiskState.class).addFieldClause(DiskState.FIELD_NAME_COMPUTE_HOST_LINK, context.parentCompute.documentSelfLink).addRangeClause(DiskState.FIELD_NAME_UPDATE_TIME_MICROS, QueryTask.NumericRange.createLessThanRange(context.enumerationStartTimeInMicros));
Query.Builder typeFilterQuery = Query.Builder.create(Occurance.MUST_OCCUR);
Query blobFilter = Query.Builder.create(Occurance.SHOULD_OCCUR).addFieldClause(AZURE_STORAGE_TYPE, AZURE_STORAGE_BLOBS).build();
QueryTask.Query diskFilter = QueryTask.Query.Builder.create(QueryTask.Query.Occurance.SHOULD_OCCUR).addFieldClause(AZURE_STORAGE_TYPE, AZURE_STORAGE_DISKS).build();
typeFilterQuery.addClause(blobFilter);
typeFilterQuery.addClause(diskFilter);
qBuilder.addClause(typeFilterQuery.build());
QueryByPages<DiskState> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), DiskState.class, context.parentCompute.tenantLinks, context.request.endpointLink).setMaxPageSize(getQueryResultLimit());
queryLocalStates.setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
List<DeferredResult<Operation>> ops = new ArrayList<>();
queryLocalStates.queryDocuments(ds -> {
if (context.blobIds.contains(ds.id)) {
return;
}
ops.add(disassociateIfNotAttachedToCompute(context, ds));
}).thenCompose(r -> DeferredResult.allOf(ops)).whenComplete((r, e) -> {
logFine(() -> "Finished disassociation of disk states for Azure");
context.subStage = next;
handleSubStage(context);
});
}
use of com.microsoft.azure.management.Azure in project photon-model by vmware.
the class TestAzureDeleteTask method setupStorageAccount.
@Before
public final void setupStorageAccount() throws Throwable {
if (this.isMock) {
return;
}
// Create Resource Group
Azure azure = getAzureSdkClients().getAzureClient();
resourceGroupName = SdkContext.randomResourceName(azureVMName, azureVMName.length() + 5);
azure.resourceGroups().define(resourceGroupName).withRegion(AZURE_RESOURCE_GROUP_LOCATION).create();
// Create Storage Account
storageAccountName = azureVMName.replace("_", "") + "teststorageacc";
azure.storageAccounts().define(storageAccountName).withRegion(AZURE_RESOURCE_GROUP_LOCATION).withExistingResourceGroup(resourceGroupName).create();
}
use of com.microsoft.azure.management.Azure in project cloudbreak by hortonworks.
the class TagsUtil method checkTagsAzure.
protected static void checkTagsAzure(String accesKey, String tenantId, String secretKey, String subscriptionId, CharSequence stackName, Map<String, String> tagsToCheckMap) {
ApplicationTokenCredentials serviceClientCredentials = new ApplicationTokenCredentials(accesKey, tenantId, secretKey, null);
Azure azure = Azure.authenticate(serviceClientCredentials).withSubscription(subscriptionId);
PagedList<VirtualMachine> virtualMachinesList = azure.virtualMachines().list();
for (VirtualMachine vm : virtualMachinesList) {
if (vm.name().contains(stackName)) {
Map<String, String> extractedTags = vm.tags();
checkTags(tagsToCheckMap, extractedTags);
}
}
}
use of com.microsoft.azure.management.Azure in project cloudbreak by hortonworks.
the class AzureRmUseAnExistingSubnetInAnExistingVpcNetworkTest method createNetwork.
@Test
@Parameters({ "networkName", "description", "publicInAccount", "regionName", "resourceGroupName", "vpcName", "vpcSubnet" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount, String regionName, @Optional("it-vpc-resource-group") String resourceGroupName, @Optional("it-vpc") String vpcName, @Optional("it-vpc-subnet") String vpcSubnet) {
ApplicationTokenCredentials serviceClientCredentials = new ApplicationTokenCredentials(defaultAccesKey, defaultTenantId, defaultSecretKey, null);
Azure azure = Azure.authenticate(serviceClientCredentials).withSubscription(defaultSubscriptionId);
azure.networks().define(vpcName).withRegion(regionName).withNewResourceGroup(resourceGroupName).withAddressSpace("10.0.0.0/16").withSubnet(vpcSubnet, "10.0.0.0/16").create();
NetworkRequest networkRequest = new NetworkRequest();
networkRequest.setName(networkName);
networkRequest.setDescription(description);
Map<String, Object> map = new HashMap<>();
map.put("networkId", vpcName);
map.put("subnetId", vpcSubnet);
map.put("resourceGroupName", resourceGroupName);
networkRequest.setParameters(map);
networkRequest.setCloudPlatform("AZURE");
String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
use of com.microsoft.azure.management.Azure in project cloudbreak by hortonworks.
the class AzureDeleteVpcTest method deleteNetwork.
@AfterSuite
@Parameters({ "resourceGroupName", "vpcName" })
public void deleteNetwork(@Optional("it-vpc-resource-group") String resourceGroupName, @Optional("it-vpc") String vpcName) throws Exception {
springTestContextPrepareTestInstance();
ApplicationTokenCredentials serviceClientCredentials = new ApplicationTokenCredentials(defaultAccesKey, defaultTenantId, defaultSecretKey, null);
Azure azure = Azure.authenticate(serviceClientCredentials).withSubscription(defaultSubscriptionId);
azure.networks().deleteByResourceGroup(resourceGroupName, vpcName);
}
Aggregations