/// <summary>
        ///     Create hosted service deployment
        /// </summary>
        /// <param name="hostedServiceName"></param>
        /// <param name="input"></param>
        /// <param name="deploymentSlot"></param>
        /// <returns></returns>
        public DeploymentGetResponse CreateDeployment(string hostedServiceName, DeploymentCreateParameters input,
            DeploymentSlot deploymentSlot = DeploymentSlot.Production)
        {
            TestEasyLog.Instance.Info(string.Format("Creating Deployment... Name: '{0}', Label: '{1}'", input.Name, input.Label));

            ComputeManagementClient.Deployments.CreateAsync(hostedServiceName,
                deploymentSlot,
                input,
                new CancellationToken()).Wait();

            var result = GetDeployment(hostedServiceName, input.Name);

            Dependencies.TestResourcesCollector.Remember(
                AzureResourceType.Deployment,
                result.Name,
                new DeploymentInfo { Deployment = result, HostedService = hostedServiceName });

            return result;
        }
 private void CreateDeployment(string serviceName, DeploymentSlot slot,
                               DeploymentCreateParameters createParameters)
 {
     var service = Services.First(s => s.Name == serviceName);
     service.AddDeployment(d =>
     {
         d.Name = createParameters.Name;
         d.Slot = slot;
     });
 }
 /// <summary>
 ///     Create or update hosted service deployment
 /// </summary>
 /// <param name="hostedServiceName"></param>
 /// <param name="input"></param>
 /// <param name="deploymentSlot"></param>
 /// <returns></returns>
 public DeploymentGetResponse CreateOrUpdateDeployment(string hostedServiceName,
                                        DeploymentCreateParameters input,
                                        DeploymentSlot deploymentSlot = DeploymentSlot.Production)
 {
     return GetDeployment(hostedServiceName, input.Name) ?? CreateDeployment(hostedServiceName, input, deploymentSlot);
 }
 /// <summary>
 /// The Begin Creating Deployment operation uploads a new service
 /// package and creates a new deployment in the staging or production
 /// environments. This operation is an asynchronous operation. To
 /// determine whether the management service has finished processing
 /// the request, call Get Operation Status. For more information on
 /// asynchronous operations, see Tracking Asynchronous Service
 /// Management Requests at
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460791.aspx.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460813.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IDeploymentOperations.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The cloud service to create a deployment for.
 /// </param>
 /// <param name='deploymentSlot'>
 /// Required. The slot to create a deployment for.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Creating Deployment
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse BeginCreating(this IDeploymentOperations operations, string serviceName, DeploymentSlot deploymentSlot, DeploymentCreateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IDeploymentOperations)s).BeginCreatingAsync(serviceName, deploymentSlot, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// The Begin Creating Deployment operation uploads a new service
 /// package and creates a new deployment in the staging or production
 /// environments. This operation is an asynchronous operation. To
 /// determine whether the management service has finished processing
 /// the request, call Get Operation Status. For more information on
 /// asynchronous operations, see Tracking Asynchronous Service
 /// Management Requests at
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460791.aspx.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460813.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IDeploymentOperations.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The cloud service to create a deployment for.
 /// </param>
 /// <param name='deploymentSlot'>
 /// Required. The slot to create a deployment for.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Creating Deployment
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> BeginCreatingAsync(this IDeploymentOperations operations, string serviceName, DeploymentSlot deploymentSlot, DeploymentCreateParameters parameters)
 {
     return operations.BeginCreatingAsync(serviceName, deploymentSlot, parameters, CancellationToken.None);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Deploys a service.
        /// </summary>
        /// <remarks>
        /// Note that the service specification must already have been created.
        /// </remarks>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="deploymentName">Name of this deployment.</param>
        /// <param name="deploymentSlot">Environment for this deployment (e.g. Production or Staging).</param>
        /// <param name="configuration">Deployment configuration information (i.e. .cscfg file contents).</param>
        /// <param name="packageBlob">URI for blob containing package (i.e. .cspkg) file contents.</param>
        /// <param name="startImmediately">Whether to start the deployment immediately after it is created.</param>
        public void DeployService(
            string serviceName,
            string deploymentName,
            DeploymentSlot deploymentSlot,
            string configuration,
            Uri packageBlob,
            bool startImmediately = true)
        {
            // Required: Configuration, Label, Name, PackageUri.
            // Optional: ExtendedProperties, ExtensionConfiguration, StartDeployment, TreatWarningsAsError.
            DeploymentCreateParameters parameters = new DeploymentCreateParameters();
            parameters.Configuration = configuration;  // Contents of .cscfg file.
            parameters.Label = serviceName;  // Name for hosted service.  Does not need to match serviceName.
            parameters.Name = deploymentName;  // Unique name for this particular deployment.
            parameters.PackageUri = packageBlob;  // URI for blob containing .cspkg file.
            parameters.StartDeployment = startImmediately;  // Whether to start the deployment immediately after it is created.

            this.computeManager.Deployments.Create(serviceName, deploymentSlot, parameters);
        }
 /// <summary>
 /// The Create Deployment operation uploads a new service package and
 /// creates a new deployment in the staging or production
 /// environments. This operation is an asynchronous operation. To
 /// determine whether the management service has finished processing
 /// the request, call Get Operation Status. For more information on
 /// asynchronous operations, see Tracking Asynchronous Service
 /// Management Requests at
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460791.aspx.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460813.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IDeploymentOperations.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The cloud service to create a deployment for.
 /// </param>
 /// <param name='deploymentSlot'>
 /// Required. The slot to create a deployment for.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Deployment operation.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is inprogress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request and error information regarding
 /// the failure.
 /// </returns>
 public static Task<OperationStatusResponse> CreateAsync(this IDeploymentOperations operations, string serviceName, DeploymentSlot deploymentSlot, DeploymentCreateParameters parameters)
 {
     return operations.CreateAsync(serviceName, deploymentSlot, parameters, CancellationToken.None);
 }
Exemplo n.º 8
0
        public virtual void NewPaaSDeploymentProcess()
        {
            bool removePackage = false;

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

            var storageName = Profile.Context.Subscription.GetStorageAccountName();

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

                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)));
                    }
                }

                Func<DeploymentSlot, DeploymentGetResponse> func = t =>
                {
                    DeploymentGetResponse d = null;
                    try
                    {
                        d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, t);
                    }
                    catch (CloudException ex)
                    {
                        if (ex.Response.StatusCode != HttpStatusCode.NotFound && IsVerbose() == false)
                        {
                            WriteExceptionError(ex);
                        }
                    }

                    return d;
                };

                var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);
                DeploymentGetResponse currentDeployment = null;
                InvokeInOperationContext(() => currentDeployment = func(slotType));

                var peerSlottype = slotType == DeploymentSlot.Production ? DeploymentSlot.Staging : DeploymentSlot.Production;
                DeploymentGetResponse peerDeployment = null;
                InvokeInOperationContext(() => peerDeployment = func(peerSlottype));

                ExtensionManager extensionMgr = new ExtensionManager(this, ServiceName);
                extConfig = extensionMgr.Set(currentDeployment, peerDeployment, 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)
                {
                    WriteExceptionError(ex);
                }
            });
        }
Exemplo n.º 9
0
        private void CreateDeployment(PublishContext context)
        {
            Uri packageUri = UploadPackageIfNeeded(context);

            var deploymentParams = new DeploymentCreateParameters
            {
                PackageUri = packageUri,
                Configuration = GeneralUtilities.GetConfiguration(context.CloudConfigPath),
                Label = context.ServiceName,
                Name = context.DeploymentName,
                StartDeployment = true
            };

            WriteVerboseWithTimestamp(Resources.PublishStartingMessage);

            ServiceCertificateListResponse uploadedCertificates = ComputeClient.ServiceCertificates.List(context.ServiceName);
            AddCertificates(uploadedCertificates, context);

            ComputeClient.Deployments.Create(context.ServiceName, GetSlot(context.ServiceSettings.Slot),
                deploymentParams);
        }
 /// <summary>
 /// The Create Deployment operation uploads a new service package and
 /// creates a new deployment in the staging or production
 /// environments.  The Create Deployment operation is an asynchronous
 /// operation. To determine whether the management service has
 /// finished processing the request, call Get Operation Status. For
 /// more information on asynchronous operations, see Tracking
 /// Asynchronous Service Management Requests.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460813.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IDeploymentOperations.
 /// </param>
 /// <param name='serviceName'>
 /// The cloud service to create a deployment for.
 /// </param>
 /// <param name='deploymentSlot'>
 /// The slot to create a deployment for.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create Deployment operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse BeginCreating(this IDeploymentOperations operations, string serviceName, DeploymentSlot deploymentSlot, DeploymentCreateParameters parameters)
 {
     try
     {
         return operations.BeginCreatingAsync(serviceName, deploymentSlot, parameters).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
        protected PSArgument[] CreateDeploymentCreateParameters()
        {
            string serviceName = string.Empty;
            DeploymentSlot deploymentSlot = new DeploymentSlot();
            DeploymentCreateParameters parameters = new DeploymentCreateParameters();

            return ConvertFromObjectsToArguments(new string[] { "ServiceName", "DeploymentSlot", "Parameters" }, new object[] { serviceName, deploymentSlot, parameters });
        }
Exemplo n.º 12
0
 public async Task<OperationStatusResponse> CreateDeployment(DeploymentCreateParameters createParameters, DeploymentSlot slot = DeploymentSlot.Production)
 {
     return await _computeClient.Value.Deployments.CreateAsync(this.ServiceName, slot, createParameters);
 }