public StationGridAdapter(FragmentManager manager, IList<Station> stations, GeoPoint currentLocation, BikeActionStatus status)
     : base(manager)
 {
     this.stations = stations;
     this.currentLocation = currentLocation;
     this.status = status;
     this.background = ImageReference.ForDrawable (Resource.Drawable.pager_background);
     this.background2 = ImageReference.ForDrawable (Resource.Drawable.pager_background2);
 }
 /// <inheritdoc cref="ImageReference.DeleteAsync"/>
 public static void Delete(this ImageReference image)
 {
     image.DeleteAsync().ForceSynchronous();
 }
 /// <inheritdoc cref="Image.WaitUntilActiveAsync"/>
 public static void WaitUntilDeleted(this ImageReference image, TimeSpan?refreshDelay = null, TimeSpan?timeout = null, IProgress <bool> progress = null)
 {
     image.WaitUntilDeletedAsync(refreshDelay, timeout, progress).ForceSynchronous();
 }
 /// <inheritdoc cref="ImageReference.GetMetadataAsync"/>
 public static ImageMetadata GetMetadata(this ImageReference image)
 {
     return(image.GetMetadataAsync().ForceSynchronous());
 }
 /// <inheritdoc cref="ImageReference.GetMetadataItemAsync"/>
 public static string GetMetadataItem(this ImageReference image, string key)
 {
     return(image.GetMetadataItemAsync(key).ForceSynchronous());
 }
 public SkuAndImage(NodeAgentSku sku, ImageReference image)
 {
     this.Sku   = sku;
     this.Image = image;
 }
 /// <inheritdoc cref="ImageReference.GetImageAsync"/>
 public static Image GetImage(this ImageReference image)
 {
     return(image.GetImageAsync().ForceSynchronous());
 }
示例#8
0
 internal object GetIcon(ImageReference imgRef)
 {
     return(imageManager.GetImage(imgRef.Assembly, imgRef.Name, BackgroundType.TreeNode));
 }
示例#9
0
        public async Task TestVMScaleSetExtensionSequencing()
        {
            EnsureClientsInitialized(DefaultLocation);
            // Create resource group
            string rgName   = Recording.GenerateAssetName(TestPrefix) + 1;
            var    vmssName = Recording.GenerateAssetName("vmss");
            VirtualMachineScaleSet inputVMScaleSet;
            ImageReference         imageRef = await GetPlatformVMImage(useWindowsImage : false);

            VirtualMachineScaleSetExtensionProfile vmssExtProfile = GetTestVmssExtensionProfile();

            // Set extension sequencing (ext2 is provisioned after ext1)
            vmssExtProfile.Extensions[1].ProvisionAfterExtensions = new List <string> {
                vmssExtProfile.Extensions[0].Name
            };

            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName,
                vmssName,
                null,
                imageRef,
                extensionProfile : vmssExtProfile,
                createWithManagedDisks : true);

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            // Perform a Get operation on each extension
            VirtualMachineScaleSetExtension getVmssExtResponse = null;

            for (int i = 0; i < vmssExtProfile.Extensions.Count; i++)
            {
                getVmssExtResponse = await VirtualMachineScaleSetExtensionsOperations.GetAsync(rgName, vmssName, vmssExtProfile.Extensions[i].Name);

                ValidateVmssExtension(vmssExtProfile.Extensions[i], getVmssExtResponse);
            }

            // Add a new extension to the VMSS (ext3 is provisioned after ext2)
            VirtualMachineScaleSetExtension vmssExtension = GetTestVMSSVMExtension(name: "3", publisher: "Microsoft.CPlat.Core", type: "NullLinux", version: "4.0");

            vmssExtension.ProvisionAfterExtensions = new List <string> {
                vmssExtProfile.Extensions[1].Name
            };
            var response = await WaitForCompletionAsync(await VirtualMachineScaleSetExtensionsOperations.StartCreateOrUpdateAsync(rgName, vmssName, vmssExtension.Name, vmssExtension));

            ValidateVmssExtension(vmssExtension, response.Value);

            // Perform a Get operation on the extension
            getVmssExtResponse = await VirtualMachineScaleSetExtensionsOperations.GetAsync(rgName, vmssName, vmssExtension.Name);

            ValidateVmssExtension(vmssExtension, getVmssExtResponse);

            // Clear the sequencing in ext3
            vmssExtension.ProvisionAfterExtensions.Clear();
            var patchVmssExtsResponse = await WaitForCompletionAsync(await VirtualMachineScaleSetExtensionsOperations.StartCreateOrUpdateAsync(rgName, vmssName, vmssExtension.Name, vmssExtension));

            ValidateVmssExtension(vmssExtension, patchVmssExtsResponse.Value);

            // Perform a List operation on vmss extensions
            var listVmssExts         = VirtualMachineScaleSetExtensionsOperations.ListAsync(rgName, vmssName);
            var listVmssExtsResponse = await listVmssExts.ToEnumerableAsync();

            int installedExtensionsCount = listVmssExtsResponse.Count();

            Assert.AreEqual(3, installedExtensionsCount);
            VirtualMachineScaleSetExtension expectedVmssExt = null;

            for (int i = 0; i < installedExtensionsCount; i++)
            {
                if (i < installedExtensionsCount - 1)
                {
                    expectedVmssExt = vmssExtProfile.Extensions[i];
                }
                else
                {
                    expectedVmssExt = vmssExtension;
                }

                ValidateVmssExtension(expectedVmssExt, listVmssExtsResponse.ElementAt(i));
            }
        }
示例#10
0
        public void TestVMScaleSetExtensionSequencing()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                // Create resource group
                string rgName   = TestUtilities.GenerateName(TestPrefix) + 1;
                var    vmssName = TestUtilities.GenerateName("vmss");
                VirtualMachineScaleSet inputVMScaleSet;
                try
                {
                    EnsureClientsInitialized(context);
                    ImageReference imageRef = GetPlatformVMImage(useWindowsImage: false);
                    VirtualMachineScaleSetExtensionProfile vmssExtProfile = GetTestVmssExtensionProfile();
                    // Set extension sequencing (ext2 is provisioned after ext1)
                    vmssExtProfile.Extensions[1].ProvisionAfterExtensions = new List <string> {
                        vmssExtProfile.Extensions[0].Name
                    };

                    VirtualMachineScaleSet vmScaleSet = CreateVMScaleSet_NoAsyncTracking(
                        rgName,
                        vmssName,
                        null,
                        imageRef,
                        out inputVMScaleSet,
                        extensionProfile: vmssExtProfile,
                        createWithManagedDisks: true);

                    Assert.Equal("PT1H20M", vmScaleSet.VirtualMachineProfile.ExtensionProfile.ExtensionsTimeBudget);
                    // Perform a Get operation on each extension
                    VirtualMachineScaleSetExtension getVmssExtResponse = null;
                    for (int i = 0; i < vmssExtProfile.Extensions.Count; i++)
                    {
                        getVmssExtResponse = m_CrpClient.VirtualMachineScaleSetExtensions.Get(rgName, vmssName, vmssExtProfile.Extensions[i].Name);
                        ValidateVmssExtension(vmssExtProfile.Extensions[i], getVmssExtResponse);
                    }
                    // Add a new extension to the VMSS (ext3 is provisioned after ext2)
                    VirtualMachineScaleSetExtension vmssExtension = GetTestVMSSVMExtension(name: "3", publisher: "Microsoft.CPlat.Core", type: "NullLinux", version: "4.0");
                    vmssExtension.ProvisionAfterExtensions = new List <string> {
                        vmssExtProfile.Extensions[1].Name
                    };
                    var response = m_CrpClient.VirtualMachineScaleSetExtensions.CreateOrUpdate(rgName, vmssName, vmssExtension.Name, vmssExtension);
                    ValidateVmssExtension(vmssExtension, response);

                    // Perform a Get operation on the extension
                    getVmssExtResponse = m_CrpClient.VirtualMachineScaleSetExtensions.Get(rgName, vmssName, vmssExtension.Name);
                    ValidateVmssExtension(vmssExtension, getVmssExtResponse);

                    // Clear the sequencing in ext3
                    vmssExtension.ProvisionAfterExtensions.Clear();
                    var patchVmssExtsResponse = m_CrpClient.VirtualMachineScaleSetExtensions.CreateOrUpdate(rgName, vmssName, vmssExtension.Name, vmssExtension);
                    ValidateVmssExtension(vmssExtension, patchVmssExtsResponse);

                    // Perform a List operation on vmss extensions
                    var listVmssExtsResponse     = m_CrpClient.VirtualMachineScaleSetExtensions.List(rgName, vmssName);
                    int installedExtensionsCount = listVmssExtsResponse.Count();
                    Assert.Equal(3, installedExtensionsCount);
                    VirtualMachineScaleSetExtension expectedVmssExt = null;
                    for (int i = 0; i < installedExtensionsCount; i++)
                    {
                        if (i < installedExtensionsCount - 1)
                        {
                            expectedVmssExt = vmssExtProfile.Extensions[i];
                        }
                        else
                        {
                            expectedVmssExt = vmssExtension;
                        }

                        ValidateVmssExtension(expectedVmssExt, listVmssExtsResponse.ElementAt(i));
                    }
                }
                finally
                {
                    // Cleanup the created resources. But don't wait since it takes too long, and it's not the purpose
                    // of the test to cover deletion. CSM does persistent retrying over all RG resources.
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
示例#11
0
        public void TestVMScaleSetForceScaleinOperation()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");
                Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "eastus2euap");
                EnsureClientsInitialized(context);
                ImageReference imageReference = new ImageReference
                {
                    Publisher = "MicrosoftWindowsServer",
                    Offer     = "WindowsServer",
                    Sku       = "2016-Datacenter",
                    Version   = "latest"
                };
                // Create resource group
                var    rgName             = TestUtilities.GenerateName(TestPrefix);
                var    vmssName           = TestUtilities.GenerateName("vmss");
                string storageAccountName = TestUtilities.GenerateName(TestPrefix);
                VirtualMachineScaleSet inputVMScaleSet;
                try
                {
                    var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

                    m_CrpClient.VirtualMachineScaleSets.Delete(rgName, "VMScaleSetDoesNotExist");

                    var vmScaleSet = CreateVMScaleSet_NoAsyncTracking(rgName, vmssName, storageAccountOutput, imageReference, out inputVMScaleSet,
                                                                      createWithManagedDisks: true);

                    var getResponse = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmScaleSet.Name);
                    ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true);

                    // Scale In VMScaleSet with forceDeletion Enabled
                    inputVMScaleSet.Sku.Capacity  = 1;
                    inputVMScaleSet.ScaleInPolicy = new ScaleInPolicy
                    {
                        ForceDeletion = true
                    };
                    UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet);

                    getResponse = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmScaleSet.Name);
                    ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true);

                    // Scale Out VMScaleSet
                    inputVMScaleSet.Sku.Capacity = 3;
                    UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet);

                    getResponse = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmScaleSet.Name);
                    ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true);

                    // Scale In VMScaleSet with forceDeletion disabled
                    inputVMScaleSet.Sku.Capacity  = 1;
                    inputVMScaleSet.ScaleInPolicy = new ScaleInPolicy
                    {
                        ForceDeletion = false
                    };
                    UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet);

                    getResponse = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmScaleSet.Name);
                    ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true);

                    //m_CrpClient.VirtualMachineScaleSets.Delete(rgName, vmScaleSet.Name);
                }
                finally
                {
                    //Cleanup the created resources. But don't wait since it takes too long, and it's not the purpose
                    //of the test to cover deletion. CSM does persistent retrying over all RG resources.
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                    Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
                }
            }
        }
示例#12
0
        public void TestVMScaleSetPatchOperations()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                EnsureClientsInitialized(context);

                ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);
                // Create resource group
                var    rgName             = TestUtilities.GenerateName(TestPrefix);
                var    vmssName           = TestUtilities.GenerateName("vmss");
                string storageAccountName = TestUtilities.GenerateName(TestPrefix);
                VirtualMachineScaleSet inputVMScaleSet;
                try
                {
                    var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

                    m_CrpClient.VirtualMachineScaleSets.Delete(rgName, "VMScaleSetDoesNotExist");

                    var vmScaleSet = CreateVMScaleSet_NoAsyncTracking(rgName, vmssName, storageAccountOutput, imageRef, out inputVMScaleSet);

                    var getResponse = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmScaleSet.Name);
                    ValidateVMScaleSet(inputVMScaleSet, getResponse);

                    // Adding an extension to the VMScaleSet. We will use Patch to update this.
                    VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile()
                    {
                        Extensions = new List <VirtualMachineScaleSetExtension>()
                        {
                            GetTestVMSSVMExtension(autoUpdateMinorVersion: false),
                        }
                    };

                    VirtualMachineScaleSetUpdate patchVMScaleSet = new VirtualMachineScaleSetUpdate()
                    {
                        VirtualMachineProfile = new VirtualMachineScaleSetUpdateVMProfile()
                        {
                            ExtensionProfile = extensionProfile,
                        },
                    };
                    PatchVMScaleSet(rgName, vmssName, patchVMScaleSet);

                    // Update the inputVMScaleSet and then compare it with response to verify the result.
                    inputVMScaleSet.VirtualMachineProfile.ExtensionProfile = extensionProfile;
                    getResponse = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmScaleSet.Name);
                    ValidateVMScaleSet(inputVMScaleSet, getResponse);


                    // Scaling the VMScaleSet now to 3 instances
                    VirtualMachineScaleSetUpdate patchVMScaleSet2 = new VirtualMachineScaleSetUpdate()
                    {
                        Sku = new Sku()
                        {
                            Capacity = 3,
                        },
                    };
                    PatchVMScaleSet(rgName, vmssName, patchVMScaleSet2);

                    // Validate that ScaleSet Scaled to 3 instances
                    inputVMScaleSet.Sku.Capacity = 3;
                    getResponse = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmScaleSet.Name);
                    ValidateVMScaleSet(inputVMScaleSet, getResponse);

                    m_CrpClient.VirtualMachineScaleSets.Delete(rgName, vmScaleSet.Name);
                }
                finally
                {
                    //Cleanup the created resources. But don't wait since it takes too long, and it's not the purpose
                    //of the test to cover deletion. CSM does persistent retrying over all RG resources.
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
示例#13
0
 void Add(SearchType searchType, string name, ImageReference icon, string toolTip, VisibleMembersFlags flags) =>
 SearchTypeVMs.Add(new SearchTypeVM(searchType, name, toolTip, icon, flags));
示例#14
0
        public async static Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] RunICPRequest req, TraceWriter log)
        {
            try
            {
                var startTime = DateTimeOffset.Now;
                log.Info($"Dunction started: {startTime}");
                var timer = new Stopwatch();
                timer.Start();

                if (String.IsNullOrEmpty(BatchAccountName) ||
                    String.IsNullOrEmpty(BatchAccountKey) ||
                    String.IsNullOrEmpty(BatchAccountUrl) ||
                    String.IsNullOrEmpty(StorageAccountName) ||
                    String.IsNullOrEmpty(StorageAccountKey))
                {
                    throw new InvalidOperationException("One or more account credential strings have not been populated. Please ensure that your Batch and Storage account credentials have been specified.");
                }

                // Create batch job and task names
                var nameUnifier = startTime.ToUniversalTime().ToString("yyyyMMdd_HHmmss_ffff");
                var jobName     = JobNamePrefix + (CreateNewJobOnEveryRun ? $"__{nameUnifier}" : String.Empty);
                var taskName    = TaskNamePrefix + $"__{nameUnifier}";

                // Create Blob client
                var storageAccount = CloudStorageAccount.Parse(StorageConnectionString);
                var blobClient     = storageAccount.CreateCloudBlobClient();

                // Create input container
                var container = blobClient.GetContainerReference(InputContainerName);
                await container.CreateIfNotExistsAsync();

                // Upload the data files to Azure Storage. This is the data that will be processed by each of the tasks that are
                // executed on the compute nodes within the pool.
                var inputFiles = new List <ResourceFile>();

                var blobFileNamePrefix = $"{jobName}/{taskName}/";
                inputFiles.Add(await UploadStringToContainer(blobClient, InputContainerName, blobFileNamePrefix + ModelPointsFileName, ModelPointsFileName, req.ModelPoints));
                inputFiles.Add(await UploadStringToContainer(blobClient, InputContainerName, blobFileNamePrefix + ScanPointsFileName, ScanPointsFileName, req.ScanPoints));

                // Get a Batch client using account creds

                var batchCredentials = new BatchSharedKeyCredentials(BatchAccountUrl, BatchAccountName, BatchAccountKey);

                using (var batchClient = BatchClient.Open(batchCredentials))
                {
                    // Create a Batch pool, VM configuration, Windows Server image
                    log.Info("Creating pool [{PoolName}]...");

                    var imageReference = new ImageReference(
                        publisher: NodeOsPublisher,
                        offer: NodeOsOffer,
                        sku: NodeOsSku,
                        version: NodeOsVersion);

                    var virtualMachineConfiguration = new VirtualMachineConfiguration(
                        imageReference: imageReference,
                        nodeAgentSkuId: NodeAgentSkuId);

                    try
                    {
                        var pool = batchClient.PoolOperations.CreatePool(
                            poolId: PoolName,
                            virtualMachineSize: PoolVmSize,
                            virtualMachineConfiguration: virtualMachineConfiguration);

                        var startTaskCmd = "vc_redist.x64.exe /quiet /install";
                        var redistFile   = new ResourceFile(VCRedistributableUri, "vc_redist.x64.exe");
                        pool.StartTask = new StartTask(startTaskCmd)
                        {
                            ResourceFiles = new List <ResourceFile> {
                                redistFile
                            },
                            UserIdentity = new UserIdentity(new AutoUserSpecification(elevationLevel: ElevationLevel.Admin))
                        };

                        if (!String.IsNullOrEmpty(PoolAutoscaleFormula))
                        {
                            pool.AutoScaleEnabled            = true;
                            pool.AutoScaleFormula            = PoolAutoscaleFormula;
                            pool.AutoScaleEvaluationInterval = TimeSpan.FromMinutes(5);
                        }
                        else
                        {
                            pool.TargetDedicatedComputeNodes   = PoolDedicatedNodeCount;
                            pool.TargetLowPriorityComputeNodes = PoolLowPriorityNodeCount;
                        }

                        pool.MaxTasksPerComputeNode = PoolMaxTasksPerNodeCount;

                        pool.Commit();
                    }
                    catch (BatchException be)
                    {
                        // Accept the specific error code PoolExists as that is expected if the pool already exists
                        if (be.RequestInformation?.BatchError?.Code == BatchErrorCodeStrings.PoolExists)
                        {
                            log.Info($"The pool {PoolName} already existed when we tried to create it");
                        }
                        else
                        {
                            throw; // Any other exception is unexpected
                        }
                    }

                    // Create a Batch job
                    log.Info("Creating job [" + jobName + "]...");

                    try
                    {
                        CloudJob job = batchClient.JobOperations.CreateJob();
                        job.Id = jobName;
                        job.PoolInformation = new PoolInformation {
                            PoolId = PoolName
                        };

                        job.Commit();
                    }
                    catch (BatchException be)
                    {
                        // Accept the specific error code JobExists as that is expected if the job already exists
                        if (be.RequestInformation?.BatchError?.Code == BatchErrorCodeStrings.JobExists)
                        {
                            log.Info($"The job {JobNamePrefix} already existed when we tried to create it");
                        }
                        else
                        {
                            throw; // Any other exception is unexpected
                        }
                    }

                    // Adding task
                    var taskCommandLine = String.Format($"cmd /c %AZ_BATCH_APP_PACKAGE_ICP%\\ICP_PCL.exe %AZ_BATCH_TASK_WORKING_DIR% {ScanPointsFileName} {ModelPointsFileName} 1 1");
                    var task            = new CloudTask(taskName, taskCommandLine)
                    {
                        ResourceFiles = inputFiles,
                        ApplicationPackageReferences = new List <ApplicationPackageReference>
                        {
                            new ApplicationPackageReference {
                                ApplicationId = ApplicationPackageId
                            }
                        }
                    };

                    await batchClient.JobOperations.AddTaskAsync(jobName, task);

                    // Monitor task
                    var stateMonitor = batchClient.Utilities.CreateTaskStateMonitor();

                    task = batchClient.JobOperations.GetTask(jobName, taskName);
                    stateMonitor.WaitAll(new List <CloudTask> {
                        task
                    }, TaskState.Completed, timeout: TimeSpan.FromMinutes(5));


                    log.Info("Task completed");
                    try
                    {
                        var result = new RunICPResponse
                        {
                            Content = (await task.GetNodeFileAsync("wd\\" + ApplicationOutputFileName)).ReadAsString()
                        };

                        log.Info("Execution finished successfully");
                        return(new OkObjectResult(result));
                    }
                    catch (Exception e)
                    {
                        var stdout = (await task.GetNodeFileAsync("stdout.txt")).ReadAsString();
                        var stderr = (await task.GetNodeFileAsync("stderr.txt")).ReadAsString();
                        var stdall = $"stdout:\n{stdout}\n\nstderr:{stderr}";
                        log.Error($"File not found, app logs:\n\n\n\n{stdall}");
                        return(new NotFoundObjectResult(e));
                    }
                }
            }
            catch (Exception e)
            {
                log.Error("Unknown exception:", e);
                throw;
            }
        }