Example #1
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <param name="opsReq"></param>
        /// <param name="ttl"></param>
        /// <returns></returns>
        ///
        //*********************************************************************

        bool HasTimedOut(Models.OpRequest opsReq, int ttl)
        {
            if (0 == ttl)
            {
                ttl = DefaultStateTtlMinutes;
            }

            if (null != opsReq.CurrentStateStartTime)
            {
                if (ttl < DateTime.UtcNow.Subtract(((DateTime)opsReq.CurrentStateStartTime)).TotalMinutes)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <param name="opsReq"></param>
        ///
        //*********************************************************************

        private void ProcessOp(Models.OpRequest opsReq)
        {
            try
            {
                //LogThis(EventLogEntryType.Information, "VmOp Request Submitted", 2, 1);

                var opcode = CmpInterfaceModel.Constants.VmOpcodeEnum.Undefined;

                var opSpec = CmpInterfaceModel.Utilities.DeSerialize(typeof(OpSpec), opsReq.Config) as OpSpec;

                if (null == opSpec)
                {
                    opsReq.StatusMessage = "Config of given Ops Request could not be deserialized";
                    opsReq.StatusCode    = Constants.StatusEnum.Exception.ToString();
                    return;
                }

                try
                {
                    opcode = (CmpInterfaceModel.Constants.VmOpcodeEnum)Enum.Parse(
                        typeof(CmpInterfaceModel.Constants.VmOpcodeEnum), opsReq.RequestType);
                }
                catch (Exception)
                {
                    opsReq.StatusMessage = "Unknown opcode '" + opsReq.RequestType + "'";
                    opsReq.StatusCode    = Constants.StatusEnum.Exception.ToString();
                    return;
                }

                CmpServiceLib.CmpService cmp = null;

                switch (opcode)
                {
                case CmpInterfaceModel.Constants.VmOpcodeEnum.START:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.VmStart(opSpec.TargetId);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.STOP:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.VmStop(opSpec.TargetId);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.DEALLOCATE:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.VmDeallocate(opSpec.TargetId);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.RESIZE:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.VmResize(opSpec.TargetId, opSpec.Vmsize);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.ADDISK:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.VmAddDisk(opSpec.TargetId, opSpec.Disks);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.RESTART:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.VmRestart(opSpec.TargetId);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.DELETE:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.VmDelete(opSpec.TargetId, false, false);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.DELETEFROMSTORAGE:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.VmDelete(opSpec.TargetId, true, false);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.DELETEONEXCEPTION:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.VmDelete(opSpec.TargetId, true, false);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.DETACH:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.DetachDisk(opSpec.TargetId, opSpec.Disks[0], false);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.DETACHANDDELETE:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.DetachDisk(opSpec.TargetId, opSpec.Disks[0], true);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.ATTACHEXISTING:
                    cmp = new CmpServiceLib.CmpService(_eventLog, _cmpDbConnectionString, null);
                    opsReq.ServiceProviderStatusCheckTag = cmp.AttachExistingDisk(opSpec.TargetId, opSpec.Disks[0]);
                    break;

                case CmpInterfaceModel.Constants.VmOpcodeEnum.Undefined:
                    break;
                }

                opsReq.StatusMessage = Constants.StatusEnum.Processing.ToString();
                opsReq.StatusCode    = Constants.StatusEnum.Processing.ToString();

                //LogThis(EventLogEntryType.Information, "VmOp Request Submitted OK", 2, 2);
            }
            catch (Exception ex)
            {
                LogThis(ex, EventLogEntryType.Error, "CmpWapExtension.OpsController.SubmitOp()", 100, 1);
                //throw new Microsoft.WindowsAzurePack.CmpWapExtension.Common.PortalException(ex1.Message);
                opsReq.StatusMessage    = Constants.StatusEnum.Exception.ToString();
                opsReq.StatusCode       = Constants.StatusEnum.Exception.ToString();
                opsReq.ExceptionMessage = "Exception in ProcessOp(): " + CmpInterfaceModel.Utilities.UnwindExceptionMessages(ex);
            }
        }