示例#1
0
        /// <summary>
        /// Creates a deplopment based on the specific criteria specified in the DeploymentManager
        /// </summary>
        /// <param name="packageLocation">Where the package is left</param>
        private void CreateDeployment(string packageLocation)
        {
            bool deleted = false;

            if (!_blobClient.CheckStorageAccountHasResolved())
            {
                throw new ApplicationException("unable to proceed storage account cannot be resolved after default 5 minute timeout");
            }

            if (!_manager.UseExistingHostedService)
            {
                var hostedServiceCreate = new CreateCloudServiceCommand(_manager.HostedServiceName, _manager.Description ?? "Deployed by Fluent Management", _manager.Location)
                {
                    Certificate    = _manager.ManagementCertificate,
                    SubscriptionId = _manager.SubscriptionId
                };
                hostedServiceCreate.Execute();
                _manager.WriteComplete(EventPoint.HostedServiceCreated, "Hosted service with name " + _manager.HostedServiceName + " created");
            }

            // send up service certificate - whatever happens we want the certificate up there - sometimes we may get a request but not need to alter the config of the SSL
            if (_manager.EnableSsl)
            {
                byte[] export = _manager.ServiceCertificate.Certificate.Export(X509ContentType.Pkcs12, _manager.ServiceCertificate.PvkPassword);

                var addCertificate =
                    new AddServiceCertificateCommand(export, _manager.ServiceCertificate.PvkPassword, _manager.HostedServiceName)
                {
                    SubscriptionId = _manager.SubscriptionId,
                    Certificate    = _manager.ManagementCertificate
                };
                addCertificate.Execute();
            }

            // read in the enum value for the additional params
            bool startImmediately = true, treatErrorsAsWarnings = false;

            if (_manager.DeploymentParams.HasValue)
            {
                startImmediately      = (_manager.DeploymentParams.Value & DeploymentParams.StartImmediately) == DeploymentParams.StartImmediately;
                treatErrorsAsWarnings = (_manager.DeploymentParams.Value & DeploymentParams.WarningsAsErrors) == DeploymentParams.WarningsAsErrors;
            }
            // read in the config and convert Base64
            var deployment = new CreateDeploymentCommand(_manager.HostedServiceName, _manager.DeploymentName, packageLocation,
                                                         _manager.Base64CsfgFile, _manager.DeploymentSlot, startImmediately, treatErrorsAsWarnings)
            {
                Certificate    = _manager.ManagementCertificate,
                SubscriptionId = _manager.SubscriptionId
            };

            try
            {
                deployment.Execute();
                _manager.WriteComplete(EventPoint.DeploymentCreated, "Deployment " + _manager.DeploymentName + " created");
            }
            catch (Exception)
            {
                DeleteDeployment();
                deleted = true;
            }
            finally
            {
                if (deleted)
                {
                    deployment.Execute();
                    _manager.WriteComplete(EventPoint.DeploymentCreated, "Deployment " + _manager.DeploymentName + " created");
                }
                // check here and execute on a timer to see if the role are ready and running
                if (_manager.WaitUntilAllRoleInstancesAreRunning)
                {
                    var command = new GetAggregateDeploymentStatusCommand(_manager.HostedServiceName, _manager.DeploymentSlot)
                    {
                        Certificate    = _manager.ManagementCertificate,
                        SubscriptionId = _manager.SubscriptionId
                    };
                    while (!command.AllDeploymentNodesRunning)
                    {
                        command.Execute();
                        // TODO: put a 5 second timer in here for now but replace with a timeout and exception method if over a certain value
                        Thread.Sleep(5000);
                    }
                }
            }
        }