コード例 #1
0
        public void ExecuteCommand()
        {
            string configString = string.Empty;

            if (!string.IsNullOrEmpty(Configuration))
            {
                configString = GeneralUtilities.GetConfiguration(Configuration);
            }

            ExtensionConfiguration extConfig = null;

            if (ExtensionConfiguration != null)
            {
                string errorConfigInput = null;
                if (!ExtensionManager.Validate(ExtensionConfiguration, out errorConfigInput))
                {
                    throw new Exception(string.Format(Resources.ServiceExtensionCannotApplyExtensionsInSameType, errorConfigInput));
                }

                foreach (ExtensionConfigurationInput context in ExtensionConfiguration)
                {
                    if (context != null && context.X509Certificate != null)
                    {
                        ExecuteClientActionNewSM(
                            null,
                            string.Format(Resources.ServiceExtensionUploadingCertificate, CommandRuntime, context.X509Certificate.Thumbprint),
                            () => this.ComputeClient.ServiceCertificates.Create(this.ServiceName, CertUtilsNewSM.Create(context.X509Certificate)));
                    }
                }

                var slotType            = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);
                DeploymentGetResponse d = null;
                InvokeInOperationContext(() =>
                {
                    try
                    {
                        d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, slotType);
                    }
                    catch (CloudException ex)
                    {
                        if (ex.Response.StatusCode != HttpStatusCode.NotFound && IsVerbose() == false)
                        {
                            this.WriteExceptionDetails(ex);
                        }
                    }
                });

                ExtensionManager extensionMgr = new ExtensionManager(this, ServiceName);
                extConfig = extensionMgr.Add(d, ExtensionConfiguration, this.Slot);
            }

            // Upgrade Parameter Set
            if (string.Compare(ParameterSetName, "Upgrade", StringComparison.OrdinalIgnoreCase) == 0)
            {
                bool removePackage = false;
                var  storageName   = Profile.Context.Subscription.GetProperty(AzureSubscription.Property.StorageAccount);

                Uri packageUrl = null;
                if (Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) ||
                    Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
                {
                    packageUrl = new Uri(Package);
                }
                else
                {
                    if (string.IsNullOrEmpty(storageName))
                    {
                        throw new ArgumentException(Resources.CurrentStorageAccountIsNotSet);
                    }

                    var progress = new ProgressRecord(0, Resources.WaitForUploadingPackage, Resources.UploadingPackage);
                    WriteProgress(progress);
                    removePackage = true;
                    InvokeInOperationContext(() => packageUrl = RetryCall(s => AzureBlob.UploadPackageToBlob(this.StorageClient, storageName, Package, null)));
                }

                DeploymentUpgradeMode upgradeMode;
                if (!Enum.TryParse <DeploymentUpgradeMode>(Mode, out upgradeMode))
                {
                    upgradeMode = DeploymentUpgradeMode.Auto;
                }

                var upgradeDeploymentInput = new DeploymentUpgradeParameters
                {
                    Mode                   = upgradeMode,
                    Configuration          = configString,
                    ExtensionConfiguration = extConfig,
                    PackageUri             = packageUrl,
                    Label                  = Label ?? ServiceName,
                    Force                  = Force.IsPresent
                };

                if (!string.IsNullOrEmpty(RoleName))
                {
                    upgradeDeploymentInput.RoleToUpgrade = RoleName;
                }

                InvokeInOperationContext(() =>
                {
                    try
                    {
                        ExecuteClientActionNewSM(
                            upgradeDeploymentInput,
                            CommandRuntime.ToString(),
                            () => this.ComputeClient.Deployments.UpgradeBySlot(
                                this.ServiceName,
                                (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true),
                                upgradeDeploymentInput));

                        if (removePackage == true)
                        {
                            this.RetryCall(s =>
                                           AzureBlob.DeletePackageFromBlob(
                                               this.StorageClient,
                                               storageName,
                                               packageUrl));
                        }
                    }
                    catch (CloudException ex)
                    {
                        this.WriteExceptionDetails(ex);
                    }
                });
            }
            else if (string.Compare(this.ParameterSetName, "Config", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Config parameter set
                var changeDeploymentStatusParams = new DeploymentChangeConfigurationParameters
                {
                    Configuration          = configString,
                    ExtensionConfiguration = extConfig
                };

                ExecuteClientActionNewSM(
                    changeDeploymentStatusParams,
                    CommandRuntime.ToString(),
                    () => this.ComputeClient.Deployments.ChangeConfigurationBySlot(
                        this.ServiceName,
                        (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true),
                        changeDeploymentStatusParams));
            }
            else
            {
                // Status parameter set
                var updateDeploymentStatusParams = new DeploymentUpdateStatusParameters
                {
                    Status = (UpdatedDeploymentStatus)Enum.Parse(typeof(UpdatedDeploymentStatus), this.NewStatus, true)
                };

                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.ComputeClient.Deployments.UpdateStatusByDeploymentSlot(
                        this.ServiceName,
                        (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true),
                        updateDeploymentStatusParams));
            }
        }
コード例 #2
0
        public void NewPaaSDeploymentProcess()
        {
            bool removePackage = false;

            AssertNoPersistenVmRoleExistsInDeployment(DeploymentSlotType.Production);
            AssertNoPersistenVmRoleExistsInDeployment(DeploymentSlotType.Staging);

            var storageName = CurrentSubscription.CurrentStorageAccount;

            Uri packageUrl;

            if (this.Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) ||
                this.Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
            {
                packageUrl = new Uri(this.Package);
            }
            else
            {
                var progress = new ProgressRecord(0, "Please wait...", "Uploading package to blob storage");
                WriteProgress(progress);
                removePackage = true;
                packageUrl    = this.RetryCall(s =>
                                               AzureBlob.UploadPackageToBlob(
                                                   this.Channel,
                                                   storageName,
                                                   s,
                                                   this.Package,
                                                   null));
            }

            var deploymentInput = new CreateDeploymentInput
            {
                PackageUrl           = packageUrl,
                Configuration        = General.GetConfiguration(this.Configuration),
                Label                = this.Label,
                Name                 = this.Name,
                StartDeployment      = !this.DoNotStart.IsPresent,
                TreatWarningsAsError = this.TreatWarningsAsError.IsPresent
            };

            using (new OperationContextScope(Channel.ToContextChannel()))
            {
                try
                {
                    var progress = new ProgressRecord(0, "Please wait...", "Creating the new deployment");
                    WriteProgress(progress);

                    ExecuteClientAction(deploymentInput, CommandRuntime.ToString(), s => this.Channel.CreateOrUpdateDeployment(s, this.ServiceName, this.Slot, deploymentInput));

                    if (removePackage == true)
                    {
                        this.RetryCall(s =>
                                       AzureBlob.DeletePackageFromBlob(
                                           this.Channel,
                                           storageName,
                                           s,
                                           packageUrl));
                    }
                }
                catch (ServiceManagementClientException ex)
                {
                    this.WriteErrorDetails(ex);
                }
            }
        }
コード例 #3
0
        public virtual void NewPaaSDeploymentProcess()
        {
            bool removePackage = false;

            AssertNoPersistenVmRoleExistsInDeployment(DeploymentSlotType.Production);
            AssertNoPersistenVmRoleExistsInDeployment(DeploymentSlotType.Staging);

            var storageName = CurrentSubscription.CurrentStorageAccountName;

            Uri packageUrl;

            if (this.Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) ||
                this.Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
            {
                packageUrl = new Uri(this.Package);
            }
            else
            {
                var progress = new ProgressRecord(0, Resources.WaitForUploadingPackage, Resources.UploadingPackage);
                WriteProgress(progress);
                removePackage = true;
                packageUrl    = this.RetryCall(s =>
                                               AzureBlob.UploadPackageToBlob(
                                                   this.StorageClient,
                                                   storageName,
                                                   this.Package,
                                                   null));
            }

            ExtensionConfiguration extConfig = null;

            if (ExtensionConfiguration != null)
            {
                string errorConfigInput = null;
                if (!ExtensionManager.Validate(ExtensionConfiguration, out errorConfigInput))
                {
                    throw new Exception(string.Format(Resources.ServiceExtensionCannotApplyExtensionsInSameType, errorConfigInput));
                }

                foreach (ExtensionConfigurationInput context in ExtensionConfiguration)
                {
                    if (context != null && context.X509Certificate != null)
                    {
                        ExecuteClientActionNewSM(
                            null,
                            string.Format(Resources.ServiceExtensionUploadingCertificate, CommandRuntime, context.X509Certificate.Thumbprint),
                            () => this.ComputeClient.ServiceCertificates.Create(this.ServiceName, CertUtilsNewSM.Create(context.X509Certificate)));
                    }
                }


                var slotType            = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);
                DeploymentGetResponse d = null;
                InvokeInOperationContext(() =>
                {
                    try
                    {
                        d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, slotType);
                    }
                    catch (CloudException ex)
                    {
                        if (ex.Response.StatusCode != HttpStatusCode.NotFound && IsVerbose() == false)
                        {
                            this.WriteExceptionDetails(ex);
                        }
                    }
                });

                ExtensionManager extensionMgr = new ExtensionManager(this, ServiceName);
                extConfig = extensionMgr.Set(d, ExtensionConfiguration, this.Slot);
            }

            var deploymentInput = new DeploymentCreateParameters
            {
                PackageUri             = packageUrl,
                Configuration          = GeneralUtilities.GetConfiguration(this.Configuration),
                ExtensionConfiguration = extConfig,
                Label                = this.Label,
                Name                 = this.Name,
                StartDeployment      = !this.DoNotStart.IsPresent,
                TreatWarningsAsError = this.TreatWarningsAsError.IsPresent,
            };

            InvokeInOperationContext(() =>
            {
                try
                {
                    var progress = new ProgressRecord(0, Resources.WaitForUploadingPackage, Resources.CreatingNewDeployment);
                    WriteProgress(progress);

                    ExecuteClientActionNewSM(
                        deploymentInput,
                        CommandRuntime.ToString(),
                        () => this.ComputeClient.Deployments.Create(
                            this.ServiceName,
                            (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true),
                            deploymentInput));

                    if (removePackage == true)
                    {
                        this.RetryCall(s => AzureBlob.DeletePackageFromBlob(
                                           this.StorageClient,
                                           storageName,
                                           packageUrl));
                    }
                }
                catch (CloudException ex)
                {
                    this.WriteExceptionDetails(ex);
                }
            });
        }
コード例 #4
0
        public void NewPaaSDeploymentProcess()
        {
            NewAzureDeploymentCommand.NewAzureDeploymentCommand variable = null;
            Func <string, Deployment> func    = null;
            Func <string, Uri>        func1   = null;
            Action <string>           action  = null;
            Action <string>           action1 = null;
            bool flag = false;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    new List <PersistentVMRoleContext>();
                    NewAzureDeploymentCommand newAzureDeploymentCommand = this;
                    if (func == null)
                    {
                        func = (string s) => base.Channel.GetDeploymentBySlot(s, this.ServiceName, "Production");
                    }
                    Deployment deployment = ((CmdletBase <IServiceManagement>)newAzureDeploymentCommand).RetryCall <Deployment>(func);
                    if (deployment.RoleList != null && string.Compare(deployment.RoleList[0].RoleType, "PersistentVMRole", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        throw new ArgumentException("Cannot Create New Deployment with Virtual Machines Present");
                    }
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    if (communicationException as EndpointNotFoundException == null && !base.IsVerbose())
                    {
                        this.WriteErrorDetails(communicationException);
                    }
                }
            }
            string currentStorageAccount = base.get_CurrentSubscription().get_CurrentStorageAccount();

            if (this.Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || this.Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
            {
                Uri uri = new Uri(this.Package);
            }
            else
            {
                ProgressRecord progressRecord = new ProgressRecord(0, "Please wait...", "Uploading package to blob storage");
                base.WriteProgress(progressRecord);
                flag = true;
                NewAzureDeploymentCommand.NewAzureDeploymentCommand variable1 = variable;
                NewAzureDeploymentCommand newAzureDeploymentCommand1          = this;
                if (func1 == null)
                {
                    func1 = (string s) => AzureBlob.UploadPackageToBlob(base.Channel, currentStorageAccount, s, this.Package);
                }
                variable1.packageUrl = ((CmdletBase <IServiceManagement>)newAzureDeploymentCommand1).RetryCall <Uri>(func1);
            }
            CreateDeploymentInput createDeploymentInput = new CreateDeploymentInput();

            createDeploymentInput.PackageUrl    = uri;
            createDeploymentInput.Configuration = Utility.GetConfiguration(this.Configuration);
            createDeploymentInput.Label         = ServiceManagementHelper.EncodeToBase64String(this.Label);
            createDeploymentInput.Name          = this.Name;
            SwitchParameter doNotStart = this.DoNotStart;

            createDeploymentInput.StartDeployment = new bool?(!doNotStart.IsPresent);
            SwitchParameter treatWarningsAsError = this.TreatWarningsAsError;

            createDeploymentInput.TreatWarningsAsError = new bool?(treatWarningsAsError.IsPresent);
            CreateDeploymentInput createDeploymentInput1 = createDeploymentInput;

            using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    ProgressRecord progressRecord1 = new ProgressRecord(0, "Please wait...", "Creating the new deployment");
                    base.WriteProgress(progressRecord1);
                    CmdletExtensions.WriteVerboseOutputForObject(this, createDeploymentInput1);
                    NewAzureDeploymentCommand newAzureDeploymentCommand2 = this;
                    if (action == null)
                    {
                        action = (string s) => this.Channel.CreateOrUpdateDeployment(s, this.ServiceName, this.Slot, this.deploymentInput);
                    }

                    ((CmdletBase <IServiceManagement>)newAzureDeploymentCommand2).RetryCall(action);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.OperationDescription = base.CommandRuntime.ToString();
                    managementOperationContext.OperationId          = operation.OperationTrackingId;
                    managementOperationContext.OperationStatus      = operation.Status;
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                    if (flag)
                    {
                        NewAzureDeploymentCommand newAzureDeploymentCommand3 = this;
                        if (action1 == null)
                        {
                            action1 = (string s) => AzureBlob.DeletePackageFromBlob(base.Channel, currentStorageAccount, s, uri);
                        }
                        ((CmdletBase <IServiceManagement>)newAzureDeploymentCommand3).RetryCall(action1);
                    }
                }
                catch (CommunicationException communicationException3)
                {
                    CommunicationException communicationException2 = communicationException3;
                    this.WriteErrorDetails(communicationException2);
                }
            }
        }
コード例 #5
0
        public void NewPaaSDeploymentProcess()
        {
            bool removePackage = false;

            AssertNoPersistenVmRoleExistsInDeployment(DeploymentSlotType.Production);
            AssertNoPersistenVmRoleExistsInDeployment(DeploymentSlotType.Staging);

            var storageName = CurrentSubscription.CurrentStorageAccount;

            Uri packageUrl;

            if (this.Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) ||
                this.Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
            {
                packageUrl = new Uri(this.Package);
            }
            else
            {
                var progress = new ProgressRecord(0, Resources.WaitForUploadingPackage, Resources.UploadingPackage);
                WriteProgress(progress);
                removePackage = true;
                packageUrl    = this.RetryCall(s =>
                                               AzureBlob.UploadPackageToBlob(
                                                   this.Channel,
                                                   storageName,
                                                   s,
                                                   this.Package,
                                                   null));
            }

            ExtensionConfiguration extConfig = null;

            if (ExtensionConfiguration != null)
            {
                var roleList = (from c in ExtensionConfiguration
                                where c != null
                                from r in c.Roles
                                select r).GroupBy(r => r.ToString()).Select(g => g.First());

                foreach (var role in roleList)
                {
                    var result = from c in ExtensionConfiguration
                                 where c != null && c.Roles.Any(r => r.ToString() == role.ToString())
                                 select string.Format("{0}.{1}", c.ProviderNameSpace, c.Type);

                    foreach (var s in result)
                    {
                        if (result.Count(t => t == s) > 1)
                        {
                            throw new Exception(string.Format(Resources.ServiceExtensionCannotApplyExtensionsInSameType, s));
                        }
                    }
                }

                ExtensionManager       extensionMgr              = new ExtensionManager(this, ServiceName);
                Deployment             currentDeployment         = null;
                ExtensionConfiguration deploymentExtensionConfig = null;
                using (new OperationContextScope(Channel.ToContextChannel()))
                {
                    try
                    {
                        currentDeployment         = this.RetryCall(s => this.Channel.GetDeploymentBySlot(s, this.ServiceName, Slot));
                        deploymentExtensionConfig = currentDeployment == null ? null : extensionMgr.GetBuilder(currentDeployment.ExtensionConfiguration).ToConfiguration();
                    }
                    catch (ServiceManagementClientException ex)
                    {
                        if (ex.HttpStatus != HttpStatusCode.NotFound && IsVerbose() == false)
                        {
                            this.WriteErrorDetails(ex);
                        }
                    }
                }
                ExtensionConfigurationBuilder configBuilder = extensionMgr.GetBuilder();
                foreach (ExtensionConfigurationInput context in ExtensionConfiguration)
                {
                    if (context != null)
                    {
                        if (context.X509Certificate != null)
                        {
                            var operationDescription = string.Format(Resources.ServiceExtensionUploadingCertificate, CommandRuntime, context.X509Certificate.Thumbprint);
                            ExecuteClientActionInOCS(null, operationDescription, s => this.Channel.AddCertificates(s, this.ServiceName, CertUtils.Create(context.X509Certificate)));
                        }

                        ExtensionConfiguration currentConfig = extensionMgr.InstallExtension(context, Slot, deploymentExtensionConfig);
                        foreach (var r in currentConfig.AllRoles)
                        {
                            if (currentDeployment == null || !extensionMgr.GetBuilder(currentDeployment.ExtensionConfiguration).ExistAny(r.Id))
                            {
                                configBuilder.AddDefault(r.Id);
                            }
                        }
                        foreach (var r in currentConfig.NamedRoles)
                        {
                            foreach (var e in r.Extensions)
                            {
                                if (currentDeployment == null || !extensionMgr.GetBuilder(currentDeployment.ExtensionConfiguration).ExistAny(e.Id))
                                {
                                    configBuilder.Add(r.RoleName, e.Id);
                                }
                            }
                        }
                    }
                }
                extConfig = configBuilder.ToConfiguration();
            }

            var deploymentInput = new CreateDeploymentInput
            {
                PackageUrl             = packageUrl,
                Configuration          = General.GetConfiguration(this.Configuration),
                ExtensionConfiguration = extConfig,
                Label                = this.Label,
                Name                 = this.Name,
                StartDeployment      = !this.DoNotStart.IsPresent,
                TreatWarningsAsError = this.TreatWarningsAsError.IsPresent
            };

            using (new OperationContextScope(Channel.ToContextChannel()))
            {
                try
                {
                    var progress = new ProgressRecord(0, Resources.WaitForUploadingPackage, Resources.CreatingNewDeployment);
                    WriteProgress(progress);

                    ExecuteClientAction(deploymentInput, CommandRuntime.ToString(), s => this.Channel.CreateOrUpdateDeployment(s, this.ServiceName, this.Slot, deploymentInput));

                    if (removePackage == true)
                    {
                        this.RetryCall(s =>
                                       AzureBlob.DeletePackageFromBlob(
                                           this.Channel,
                                           storageName,
                                           s,
                                           packageUrl));
                    }
                }
                catch (ServiceManagementClientException ex)
                {
                    this.WriteErrorDetails(ex);
                }
            }
        }
コード例 #6
0
        public void ExecuteCommand()
        {
            string configString = string.Empty;

            if (!string.IsNullOrEmpty(Configuration))
            {
                configString = General.GetConfiguration(Configuration);
            }

            // Upgrade Parameter Set
            if (string.Compare(ParameterSetName, "Upgrade", StringComparison.OrdinalIgnoreCase) == 0)
            {
                bool removePackage = false;
                CurrentSubscription = this.GetCurrentSubscription();
                var storageName = CurrentSubscription.CurrentStorageAccount;

                Uri packageUrl = null;
                if (Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) ||
                    Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
                {
                    packageUrl = new Uri(Package);
                }
                else
                {
                    if (string.IsNullOrEmpty(storageName))
                    {
                        throw new ArgumentException("CurrentStorageAccount is not set. Use Set-AzureSubscription subname -CurrentStorageAccount storageaccount to set it.");
                    }

                    var progress = new ProgressRecord(0, "Please wait...", "Uploading package to blob storage");
                    WriteProgress(progress);
                    removePackage = true;
                    InvokeInOperationContext(() => packageUrl = RetryCall(s => AzureBlob.UploadPackageToBlob(this.Channel, storageName, s, Package, null)));
                }

                var upgradeDeploymentInput = new UpgradeDeploymentInput
                {
                    Mode          = Mode ?? UpgradeType.Auto,
                    Configuration = configString,
                    PackageUrl    = packageUrl,
                    Label         = Label != null ? Label : ServiceName,
                    Force         = Force.IsPresent
                };

                if (!string.IsNullOrEmpty(RoleName))
                {
                    upgradeDeploymentInput.RoleToUpgrade = RoleName;
                }

                using (new OperationContextScope(Channel.ToContextChannel()))
                {
                    try
                    {
                        ExecuteClientAction(upgradeDeploymentInput, CommandRuntime.ToString(), s => this.Channel.UpgradeDeploymentBySlot(s, this.ServiceName, this.Slot, upgradeDeploymentInput));
                        if (removePackage == true)
                        {
                            this.RetryCall(s =>
                                           AzureBlob.DeletePackageFromBlob(
                                               this.Channel,
                                               storageName,
                                               s,
                                               packageUrl));
                        }
                    }
                    catch (ServiceManagementClientException ex)
                    {
                        this.WriteErrorDetails(ex);
                    }
                }
            }
            else if (string.Compare(this.ParameterSetName, "Config", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Config parameter set
                var changeConfiguration = new ChangeConfigurationInput
                {
                    Configuration = configString
                };

                ExecuteClientActionInOCS(changeConfiguration, CommandRuntime.ToString(), s => this.Channel.ChangeConfigurationBySlot(s, this.ServiceName, this.Slot, changeConfiguration));
            }

            else
            {
                // Status parameter set
                var updateDeploymentStatus = new UpdateDeploymentStatusInput()
                {
                    Status = this.NewStatus
                };

                ExecuteClientActionInOCS(null, CommandRuntime.ToString(), s => this.Channel.UpdateDeploymentStatusBySlot(s, this.ServiceName, this.Slot, updateDeploymentStatus));
            }
        }
コード例 #7
0
        public void SetDeploymentTmpProcess()
        {
            SetAzureDeploymentCommand.SetAzureDeploymentCommand variable = null;
            string mode;
            string base64String;
            string empty = string.Empty;

            if (!string.IsNullOrEmpty(this.Configuration))
            {
                empty = Utility.GetConfiguration(this.Configuration);
            }
            if (string.Compare(base.ParameterSetName, "Upgrade", StringComparison.OrdinalIgnoreCase) != 0)
            {
                if (string.Compare(base.ParameterSetName, "Config", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    Action <string>             action = null;
                    UpdateDeploymentStatusInput updateDeploymentStatusInput = new UpdateDeploymentStatusInput();
                    updateDeploymentStatusInput.Status = this.NewStatus;
                    UpdateDeploymentStatusInput updateDeploymentStatusInput1 = updateDeploymentStatusInput;
                    using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                    {
                        try
                        {
                            SetAzureDeploymentCommand setAzureDeploymentCommand = this;
                            if (action == null)
                            {
                                action = (string s) => base.Channel.UpdateDeploymentStatusBySlot(s, this.ServiceName, this.Slot, updateDeploymentStatusInput1);
                            }
                            ((CmdletBase <IServiceManagement>)setAzureDeploymentCommand).RetryCall(action);
                            Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                            ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                            managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                            managementOperationContext.set_OperationId(operation.OperationTrackingId);
                            managementOperationContext.set_OperationStatus(operation.Status);
                            ManagementOperationContext managementOperationContext1 = managementOperationContext;
                            base.WriteObject(managementOperationContext1, true);
                        }
                        catch (CommunicationException communicationException1)
                        {
                            CommunicationException communicationException = communicationException1;
                            this.WriteErrorDetails(communicationException);
                        }
                    }
                }
                else
                {
                    Action <string>          action1 = null;
                    ChangeConfigurationInput changeConfigurationInput = new ChangeConfigurationInput();
                    changeConfigurationInput.Configuration = empty;
                    ChangeConfigurationInput changeConfigurationInput1 = changeConfigurationInput;
                    using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                    {
                        try
                        {
                            CmdletExtensions.WriteVerboseOutputForObject(this, changeConfigurationInput1);
                            SetAzureDeploymentCommand setAzureDeploymentCommand1 = this;
                            if (action1 == null)
                            {
                                action1 = (string s) => base.Channel.ChangeConfigurationBySlot(s, this.ServiceName, this.Slot, changeConfigurationInput1);
                            }
                            ((CmdletBase <IServiceManagement>)setAzureDeploymentCommand1).RetryCall(action1);
                            Operation operation1 = base.WaitForOperation(base.CommandRuntime.ToString());
                            ManagementOperationContext managementOperationContext2 = new ManagementOperationContext();
                            managementOperationContext2.set_OperationDescription(base.CommandRuntime.ToString());
                            managementOperationContext2.set_OperationId(operation1.OperationTrackingId);
                            managementOperationContext2.set_OperationStatus(operation1.Status);
                            ManagementOperationContext managementOperationContext3 = managementOperationContext2;
                            base.WriteObject(managementOperationContext3, true);
                        }
                        catch (CommunicationException communicationException3)
                        {
                            CommunicationException communicationException2 = communicationException3;
                            this.WriteErrorDetails(communicationException2);
                        }
                    }
                }
            }
            else
            {
                Func <string, Uri> func    = null;
                Action <string>    action2 = null;
                Action <string>    action3 = null;
                bool flag = false;
                base.CurrentSubscription = CmdletSubscriptionExtensions.GetCurrentSubscription(this);
                string currentStorageAccount = base.CurrentSubscription.CurrentStorageAccount;
                if (this.Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || this.Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
                {
                    Uri uri = new Uri(this.Package);
                }
                else
                {
                    if (!string.IsNullOrEmpty(currentStorageAccount))
                    {
                        ProgressRecord progressRecord = new ProgressRecord(0, "Please wait...", "Uploading package to blob storage");
                        base.WriteProgress(progressRecord);
                        flag = true;
                        SetAzureDeploymentCommand variable1 = variable;
                        SetAzureDeploymentCommand setAzureDeploymentCommand2 = this;
                        if (func == null)
                        {
                            func = (string s) => AzureBlob.UploadPackageToBlob(this.CreateChannel(), currentStorageAccount, s, this.Package);
                        }
                        packageUrl = ((CmdletBase <IServiceManagement>)setAzureDeploymentCommand2).RetryCall <Uri>(func);
                    }
                    else
                    {
                        throw new ArgumentException("CurrentStorageAccount is not set. Use Set-AzureSubscription subname -CurrentStorageAccount storageaccount to set it.");
                    }
                }
                SetAzureDeploymentCommand variable2 = variable;
                UpgradeDeploymentInput    upgradeDeploymentInput  = new UpgradeDeploymentInput();
                UpgradeDeploymentInput    upgradeDeploymentInput1 = upgradeDeploymentInput;
                if (this.Mode == null)
                {
                    mode = "Auto";
                }
                else
                {
                    mode = this.Mode;
                }
                upgradeDeploymentInput1.Mode         = mode;
                upgradeDeploymentInput.Configuration = empty;
                upgradeDeploymentInput.PackageUrl    = uri;
                UpgradeDeploymentInput upgradeDeploymentInput2 = upgradeDeploymentInput;
                if (this.Label != null)
                {
                    base64String = ServiceManagementHelper.EncodeToBase64String(this.Label);
                }
                else
                {
                    base64String = ServiceManagementHelper.EncodeToBase64String(this.ServiceName);
                }
                upgradeDeploymentInput2.Label = base64String;
                SwitchParameter force = this.Force;
                upgradeDeploymentInput.Force     = new bool?(force.IsPresent);
                variable2.upgradeDeploymentInput = upgradeDeploymentInput;
                if (!string.IsNullOrEmpty(this.RoleName))
                {
                    UpgradeDeploymentInput roleName = this.RoleName;
                }
                using (OperationContextScope operationContextScope2 = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        CmdletExtensions.WriteVerboseOutputForObject(this, roleName);
                        SetAzureDeploymentCommand setAzureDeploymentCommand3 = this;
                        if (action2 == null)
                        {
                            action2 = (string s) => this.Channel.UpgradeDeploymentBySlot(s, this.ServiceName, this.Slot, this.upgradeDeploymentInput);
                        }
                        ((CmdletBase <IServiceManagement>)setAzureDeploymentCommand3).RetryCall(action2);
                        Operation operation2 = base.WaitForOperation(base.CommandRuntime.ToString());
                        ManagementOperationContext managementOperationContext4 = new ManagementOperationContext();
                        managementOperationContext4.OperationDescription = base.CommandRuntime.ToString();
                        managementOperationContext4.OperationId          = operation2.OperationTrackingId;
                        managementOperationContext4.OperationStatus      = operation2.Status;
                        ManagementOperationContext managementOperationContext5 = managementOperationContext4;
                        base.WriteObject(managementOperationContext5, true);
                        if (flag)
                        {
                            SetAzureDeploymentCommand setAzureDeploymentCommand4 = this;
                            if (action3 == null)
                            {
                                action3 = (string s) => AzureBlob.DeletePackageFromBlob(base.Channel, currentStorageAccount, s, uri);
                            }
                            ((CmdletBase <IServiceManagement>)setAzureDeploymentCommand4).RetryCall(action3);
                        }
                    }
                    catch (CommunicationException communicationException5)
                    {
                        CommunicationException communicationException4 = communicationException5;
                        this.WriteErrorDetails(communicationException4);
                    }
                }
            }
        }
コード例 #8
0
        public void ExecuteCommand()
        {
            string configString = string.Empty;

            if (!string.IsNullOrEmpty(Configuration))
            {
                configString = General.GetConfiguration(Configuration);
            }

            ExtensionConfiguration extConfig = null;

            if (ExtensionConfiguration != null)
            {
                var roleList = (from c in ExtensionConfiguration
                                where c != null
                                from r in c.Roles
                                select r).GroupBy(r => r.ToString()).Select(g => g.First());

                foreach (var role in roleList)
                {
                    var result = from c in ExtensionConfiguration
                                 where c != null && c.Roles.Any(r => r.ToString() == role.ToString())
                                 select string.Format("{0}.{1}", c.ProviderNameSpace, c.Type);

                    foreach (var s in result)
                    {
                        if (result.Count(t => t == s) > 1)
                        {
                            throw new Exception(string.Format(Resources.ServiceExtensionCannotApplyExtensionsInSameType, s));
                        }
                    }
                }

                Deployment       deployment   = Channel.GetDeploymentBySlot(CurrentSubscription.SubscriptionId, ServiceName, Slot);
                ExtensionManager extensionMgr = new ExtensionManager(Channel, CurrentSubscription.SubscriptionId, ServiceName);
                ExtensionConfigurationBuilder configBuilder = extensionMgr.GetBuilder();
                foreach (ExtensionConfigurationInput context in ExtensionConfiguration)
                {
                    if (context != null)
                    {
                        if (context.X509Certificate != null)
                        {
                            var operationDescription = string.Format(Resources.ServiceExtensionUploadingCertificate, CommandRuntime, context.X509Certificate.Thumbprint);
                            ExecuteClientActionInOCS(null, operationDescription, s => this.Channel.AddCertificates(s, this.ServiceName, CertUtils.Create(context.X509Certificate)));
                        }

                        ExtensionConfiguration currentConfig = extensionMgr.InstallExtension(context, Slot, deployment.ExtensionConfiguration);
                        foreach (var r in currentConfig.AllRoles)
                        {
                            if (!extensionMgr.GetBuilder(deployment.ExtensionConfiguration).ExistAny(r.Id))
                            {
                                configBuilder.AddDefault(r.Id);
                            }
                        }
                        foreach (var r in currentConfig.NamedRoles)
                        {
                            foreach (var e in r.Extensions)
                            {
                                if (!extensionMgr.GetBuilder(deployment.ExtensionConfiguration).ExistAny(e.Id))
                                {
                                    configBuilder.Add(r.RoleName, e.Id);
                                }
                            }
                        }
                    }
                }
                extConfig = configBuilder.ToConfiguration();
            }

            // Upgrade Parameter Set
            if (string.Compare(ParameterSetName, "Upgrade", StringComparison.OrdinalIgnoreCase) == 0)
            {
                bool removePackage = false;
                CurrentSubscription = this.GetCurrentSubscription();
                var storageName = CurrentSubscription.CurrentStorageAccount;

                Uri packageUrl = null;
                if (Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) ||
                    Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
                {
                    packageUrl = new Uri(Package);
                }
                else
                {
                    if (string.IsNullOrEmpty(storageName))
                    {
                        throw new ArgumentException(Resources.CurrentStorageAccountIsNotSet);
                    }

                    var progress = new ProgressRecord(0, Resources.WaitForUploadingPackage, Resources.UploadingPackage);
                    WriteProgress(progress);
                    removePackage = true;
                    InvokeInOperationContext(() => packageUrl = RetryCall(s => AzureBlob.UploadPackageToBlob(this.Channel, storageName, s, Package, null)));
                }

                var upgradeDeploymentInput = new UpgradeDeploymentInput
                {
                    Mode                   = Mode ?? UpgradeType.Auto,
                    Configuration          = configString,
                    ExtensionConfiguration = extConfig,
                    PackageUrl             = packageUrl,
                    Label                  = Label ?? ServiceName,
                    Force                  = Force.IsPresent
                };

                if (!string.IsNullOrEmpty(RoleName))
                {
                    upgradeDeploymentInput.RoleToUpgrade = RoleName;
                }

                using (new OperationContextScope(Channel.ToContextChannel()))
                {
                    try
                    {
                        ExecuteClientAction(upgradeDeploymentInput, CommandRuntime.ToString(), s => this.Channel.UpgradeDeploymentBySlot(s, this.ServiceName, this.Slot, upgradeDeploymentInput));
                        if (removePackage == true)
                        {
                            this.RetryCall(s =>
                                           AzureBlob.DeletePackageFromBlob(
                                               this.Channel,
                                               storageName,
                                               s,
                                               packageUrl));
                        }
                    }
                    catch (ServiceManagementClientException ex)
                    {
                        this.WriteErrorDetails(ex);
                    }
                }
            }
            else if (string.Compare(this.ParameterSetName, "Config", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Config parameter set
                var changeConfiguration = new ChangeConfigurationInput
                {
                    Configuration          = configString,
                    ExtensionConfiguration = extConfig
                };

                ExecuteClientActionInOCS(changeConfiguration, CommandRuntime.ToString(), s => this.Channel.ChangeConfigurationBySlot(s, this.ServiceName, this.Slot, changeConfiguration));
            }
            else
            {
                // Status parameter set
                var updateDeploymentStatus = new UpdateDeploymentStatusInput
                {
                    Status = this.NewStatus
                };

                ExecuteClientActionInOCS(null, CommandRuntime.ToString(), s => this.Channel.UpdateDeploymentStatusBySlot(s, this.ServiceName, this.Slot, updateDeploymentStatus));
            }
        }