Example #1
0
        static async Task ActionStop(ResourceActivity activity)
        {
            Console.WriteLine(string.Format("Stopping VM [{0}]", activity.MachineName));

            await activity.Provisioning.StartStopVirtualMachineAsync(activity.MachineName, activity.ServiceName, VirtualMachineAction.Stop);

            // stop command completed, need to poll for updated state
            Task <bool> monitorTask = Task.Run(() => activity.Provisioning.WaitForStatus(activity.MachineName, activity.ServiceName, "StoppedDeallocated"));
            // when the monitor completes, update resource status
            Task continuation = monitorTask.ContinueWith(async(antecedent) => {
                if (antecedent.Result) // if previous completed without timeout
                {
                    await _volatileStorageController.UpdateResourceState(activity.Resource.Id, ResourceState.Stopped);
                }
            });
        }
Example #2
0
        public async Task <IActionResult> Post(string groupId, string resourceId, string actionname, uint?duration = null)
        {
            ScampResource res = await _resourceRepository.GetResource(resourceId);

            if (res == null)
            {
                return(new HttpStatusCodeResult(404)); // not found
            }
            ResourceAction action   = WebJobController.GetAction(actionname);
            ResourceState  newState = ResourceState.Unknown;

            switch (action)
            {
            case ResourceAction.Start:
                newState = ResourceState.Starting;
                break;

            case ResourceAction.Stop:
                newState = ResourceState.Stopping;
                break;
            }

            if (await CanManageResource(res, action))
            {
                await _volatileStorageController.UpdateResourceState(resourceId, newState);

                _webJobController.SubmitActionInQueue(resourceId, action, duration);
            }

            return(new HttpStatusCodeResult(204));
        }