Beispiel #1
0
        /// <summary>
        /// Gets a list of deployments for the specified resource group.
        /// </summary>
        /// <param name="customerId">Identifier of the customer.</param>
        /// <param name="resourceGroupName">Name of the resource group.</param>
        /// <param name="subscriptionId">Identifier of the subscription.</param>
        /// <returns>A list of <see cref="DeploymentModel"/>s that represents the deployments.</returns>
        private async Task <List <DeploymentModel> > GetDeploymentsAsync(string customerId, string resourceGroupName, string subscriptionId)
        {
            AuthenticationResult      token;
            List <DeploymentExtended> deployments;

            customerId.AssertNotEmpty(nameof(customerId));
            resourceGroupName.AssertNotEmpty(nameof(resourceGroupName));
            subscriptionId.AssertNotEmpty(nameof(subscriptionId));

            try
            {
                token = await GetAccessTokenAsync(
                    $"{Provider.Configuration.ActiveDirectoryEndpoint}/{customerId}").ConfigureAwait(false);

                using (AzureManagement manager = new AzureManagement(Provider, token.AccessToken))
                {
                    deployments = await manager.GetDeploymentsAsync(subscriptionId, resourceGroupName).ConfigureAwait(false);

                    return(deployments.Select(d => new DeploymentModel()
                    {
                        Id = d.Id,
                        Name = d.Name,
                        ProvisioningState = d.Properties.ProvisioningState,
                        Timestamp = d.Properties.Timestamp.Value
                    }).ToList());
                }
            }
            finally
            {
                deployments = null;
                token       = null;
            }
        }
Beispiel #2
0
        public AzureServiceBusInboundTransport([NotNull] IAzureServiceBusEndpointAddress address,
                                               [NotNull] ConnectionHandler <AzureServiceBusConnection> connectionHandler,
                                               [NotNull] AzureManagement management,
                                               [CanBeNull] IMessageNameFormatter formatter   = null,
                                               [CanBeNull] ReceiverSettings receiverSettings = null)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            if (connectionHandler == null)
            {
                throw new ArgumentNullException("connectionHandler");
            }
            if (management == null)
            {
                throw new ArgumentNullException("management");
            }

            _address           = address;
            _connectionHandler = connectionHandler;
            _management        = management;
            _formatter         = formatter ?? new AzureServiceBusMessageNameFormatter();
            _receiverSettings  = receiverSettings; // can be null all the way to usage in Receiver.

            _logger.DebugFormat("created new inbound transport for '{0}'", address);
        }
Beispiel #3
0
        public async Task <PartialViewResult> NewDeployment(NewDeploymentModel model)
        {
            AuthenticationResult   token;
            List <DeploymentModel> results;

            try
            {
                token = await GetAccessTokenAsync(
                    $"{Provider.Configuration.ActiveDirectoryEndpoint}/{model.CustomerId}").ConfigureAwait(false);

                using (AzureManagement manager = new AzureManagement(Provider, token.AccessToken))
                {
                    await manager.ApplyTemplateAsync(
                        model.SubscriptionId,
                        model.ResourceGroupName,
                        model.TemplateUri,
                        model.ParametersUri).ConfigureAwait(false);

                    results = await GetDeploymentsAsync(
                        model.CustomerId,
                        model.ResourceGroupName,
                        model.SubscriptionId).ConfigureAwait(false);

                    return(PartialView("Deployments", results));
                }
            }
            finally
            {
                results = null;
                token   = null;
            }
        }
Beispiel #4
0
        public async Task <JsonResult> ResourceGroups(string customerId, string subscriptionId)
        {
            AuthenticationResult token;
            List <ResourceGroup> groups;

            customerId.AssertNotEmpty(nameof(customerId));
            subscriptionId.AssertNotEmpty(nameof(subscriptionId));

            try
            {
                token = await GetAccessTokenAsync(
                    $"{Provider.Configuration.ActiveDirectoryEndpoint}/{customerId}").ConfigureAwait(false);

                using (AzureManagement manager = new AzureManagement(Provider, token.AccessToken))
                {
                    groups = await manager.GetResourceGroupsAsync(subscriptionId).ConfigureAwait(false);

                    return(Json(groups, JsonRequestBehavior.AllowGet));
                }
            }
            finally
            {
                groups = null;
                token  = null;
            }
        }
Beispiel #5
0
        public JsonResult Deploy(string azure, string data)
        {
            string dt = null;

            try
            {
                dynamic json = (new JsonReader()).Read(data);
                dynamic az   = (new JsonReader()).Read(azure);

                var app     = OdpiAppRepo.Apps.Where(a => a.Name == json.name).FirstOrDefault();
                var cfgName = CloudBackedStore.RootDir + "\\" + az.key + "\\Temp\\" + app.Name + "\\" + "ServiceConfiguration.cscfg";

                dt = AzureManagement.Deploy(az.subscriptionId, az.service, CertificateBuilder.GetPrivateKey(az.key), az.file, cfgName);
            }
            catch (Exception ex)
            {
                return(Json(new DeployStatusModel()
                {
                    Status = DeployStatusModelStatus.Error,
                    Stage = ODPI.Resources.Controllers.DeployResource.Error,
                    LogMessage = ex.Message,
                    StackTrace = ex.StackTrace
                }));
            }
            var ret = new DeployStatusModel()
            {
                Status     = DeployStatusModelStatus.Ok,
                Stage      = ODPI.Resources.Controllers.DeployResource.DeployingApplication,
                LogMessage = ODPI.Resources.Controllers.DeployResource.BeginningToUploadTheApplication,
                Data       = dt
            };

            return(Json(ret));
        }
        public string CreateVM()
        {
            AzureManagement test = new AzureManagement();

            test.Login();
            return("1");
        }
        public CosmosDBProvider(ContosoConfiguration contosoConfig, AzureManagement azureManagement)
        {
            _contosoConfig = contosoConfig;

            _client = new DocumentClient(new Uri($"https://{contosoConfig.DataAccountName}.documents.azure.com"), contosoConfig.DataAccountPassword, new ConnectionPolicy()
            {
                RetryOptions = new RetryOptions()
                {
                    MaxRetryAttemptsOnThrottledRequests = 20
                }
            });
        }
        public PurchaseServiceBusService(ContosoConfiguration contosoConfig, AzureManagement azureManagement)
        {
            _contosoConfig    = contosoConfig;
            _serviceBusClient = new Lazy <QueueClient>(() =>
            {
                ServiceBusConnectionStringBuilder connectionStringBuilder = new ServiceBusConnectionStringBuilder(_contosoConfig.ServiceConnectionString);
                return(new QueueClient(connectionStringBuilder, ReceiveMode.PeekLock, RetryPolicy.Default));

                /*
                 * Still in Preview
                 * var tokenProvider = TokenProvider.CreateManagedServiceIdentityTokenProvider();
                 * return new QueueClient($"sb://{Configuration.ServicesMiddlewareAccountName}.servicebus.windows.net/", Constants.QUEUENAME, tokenProvider);
                 */
            });
        }
		public InboundTransportImpl([NotNull] AzureServiceBusEndpointAddress address,
			[NotNull] ConnectionHandler<ConnectionImpl> connectionHandler,
			[NotNull] AzureManagement management, 
			[CanBeNull] IMessageNameFormatter formatter = null,
			[CanBeNull] ReceiverSettings receiverSettings = null)
		{
			if (address == null) throw new ArgumentNullException("address");
			if (connectionHandler == null) throw new ArgumentNullException("connectionHandler");
			if (management == null) throw new ArgumentNullException("management");

			_address = address;
			_connectionHandler = connectionHandler;
			_management = management;
			_formatter = formatter ?? new AzureMessageNameFormatter();
			_receiverSettings = receiverSettings; // can be null all the way to usage in Receiver.

			_logger.DebugFormat("created new inbound transport for '{0}'", address);
		}
Beispiel #10
0
        public JsonResult Status(string azure, string token)
        {
            string status = null;
            string xml    = "";

            try
            {
                dynamic az = (new JsonReader()).Read(azure);
                xml = AzureManagement.GetStatusUpdate(az.subscriptionId, CertificateBuilder.GetPrivateKey(az.key), token);
                XNamespace ns  = "http://schemas.microsoft.com/windowsazure";
                var        doc = XDocument.Parse(xml);
                var        op  = doc.Element(ns + "Operation");
                status = op.Element(ns + "Status").Value;
                if (status.ToLower().StartsWith("failed"))
                {
                    return(Json(new DeployStatusModel()
                    {
                        Status = DeployStatusModelStatus.Error,
                        Stage = ODPI.Resources.Controllers.DeployResource.Error,
                        LogMessage = xml
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new DeployStatusModel()
                {
                    Status = DeployStatusModelStatus.Error,
                    Stage = ODPI.Resources.Controllers.DeployResource.Error,
                    LogMessage = ex.Message,
                    StackTrace = ex.StackTrace,
                    Data = "xml: + " + xml + "\njson: " + azure
                }));
            }

            var ret = new DeployStatusModel()
            {
                Status     = status == "Succeeded" ? DeployStatusModelStatus.Ok : DeployStatusModelStatus.Inprogress,
                Stage      = ODPI.Resources.Controllers.DeployResource.DeployingApplication,
                LogMessage = StatusMessageConverter.Convert(status)
            };

            return(Json(ret));
        }
Beispiel #11
0
        public JsonResult DeployStatus(string azure, string token)
        {
            string status = null;

            try
            {
                dynamic    az  = (new JsonReader()).Read(azure);
                var        xml = AzureManagement.GetDeployStatusUpdate(az.subscriptionId, CertificateBuilder.GetPrivateKey(az.key), token);
                XDocument  doc = XDocument.Parse(xml);
                XNamespace ns  = "http://schemas.microsoft.com/windowsazure";
                status = doc.Descendants(ns + "RoleInstance").FirstOrDefault().Element(ns + "InstanceStatus").Value;
                if (status.ToLower().StartsWith("failed"))
                {
                    return(Json(new DeployStatusModel()
                    {
                        Status = DeployStatusModelStatus.Error,
                        Stage = ODPI.Resources.Controllers.DeployResource.Error,
                        LogMessage = xml
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new DeployStatusModel()
                {
                    Status = DeployStatusModelStatus.Error,
                    Stage = ODPI.Resources.Controllers.DeployResource.Error,
                    LogMessage = ex.Message,
                    StackTrace = ex.StackTrace
                }));
            }

            var ret = new DeployStatusModel()
            {
                Status     = status == "ReadyRole" ? DeployStatusModelStatus.Ok : DeployStatusModelStatus.Inprogress,
                Stage      = ODPI.Resources.Controllers.DeployResource.DeployingApplication,
                LogMessage = StatusMessageConverter.Convert(status)
            };

            return(Json(ret));
        }
Beispiel #12
0
        public JsonResult InitAzure(string id, string subId, string name, string key)
        {
            CheckMessage ret;
            string       errorMessage = null;

            if (string.IsNullOrEmpty(subId))
            {
                errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorSubscriptionId;
            }
            else if (string.IsNullOrEmpty(name))
            {
                errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorStorageAccountName;
            }
            else if (string.IsNullOrEmpty(key))
            {
                errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorPrimaryAccessKey;
            }

            if (string.IsNullOrEmpty(errorMessage))
            {
                try
                {
                    var creds = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", name, key);
                    CloudStorageAccount sa = CloudStorageAccount.Parse(creds);
                    CloudBlobClient     bc = sa.CreateCloudBlobClient();
                    bc.ListContainers();
                }
                catch (Exception e)
                {
                    errorMessage = string.Format(ODPI.Resources.Controllers.CheckResource.StorageAccountException, e.Message);
                }
            }

            string xml = null;

            if (string.IsNullOrEmpty(errorMessage))
            {
                try
                {
                    xml = AzureManagement.GetHostedServices(subId, CertificateBuilder.GetPrivateKey(id));
                    XNamespace xmlns = "http://schemas.microsoft.com/windowsazure";
                    var        doc   = XDocument.Parse(xml);

                    var services = from hs in doc.Descendants(xmlns + "HostedService")
                                   select hs.Element(xmlns + "ServiceName").Value;

                    if (services.Count() > 0)
                    {
                        ret = new CheckMessage()
                        {
                            Status = CheckMessageStatus.Ok,
                            Data   = new
                            {
                                Services = services.ToArray <string>()
                            }
                        };

                        return(Json(ret));
                    }
                    else
                    {
                        errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorNoHostedServiceFound;
                    }
                }
                catch (WebException we)
                {
                    var resp = we.Response as HttpWebResponse;

                    if (resp.StatusCode == HttpStatusCode.NotFound)
                    {
                        errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorCouldNotConnectToAzure;
                    }
                    if (resp.StatusCode == HttpStatusCode.Forbidden)
                    {
                        errorMessage = ODPI.Resources.Controllers.CheckResource.ErrorCouldNotMakeSecureConnection;
                    }
                }
                catch (Exception ex)
                {
                    errorMessage = ODPI.Resources.Controllers.CheckResource.UnknownError + ex.Message;
                }
            }



            ret = new CheckMessage()
            {
                Status  = CheckMessageStatus.Error,
                Message = errorMessage
            };

            return(Json(ret));
        }