Exemplo n.º 1
0
        private async Task OSBBootstrap(string OSBEndpoint, string OSBUser, string OSBPassword, string serviceType, string servicePlan)
        {
            var catalog = await OSBClient.CatalogAsync(OSBEndpoint, OSBUser, OSBPassword);

            var brokeredService = catalog.FirstOrDefault(s => s.Name == serviceType || s.Id == serviceType);

            if (brokeredService != null)
            {
                var plan = brokeredService.Plans.FirstOrDefault(p => p.Name == servicePlan || p.Id == servicePlan);
                if (plan != null)
                {
                    var response = await OSBClient.ProvisionAsync(OSBEndpoint, OSBUser, OSBPassword, brokeredService.Id, plan.Id, this.Id.GetStringId());

                    mUpdateTimer = RegisterTimer(
                        OSBCheckProvisionState,
                        new string[] { OSBEndpoint, OSBUser, OSBPassword, this.Id.GetStringId(), brokeredService.Id, plan.Id },
                        TimeSpan.FromMilliseconds(1),
                        TimeSpan.FromMilliseconds(5));
                }
            }
        }
Exemplo n.º 2
0
        public async Task <HandlerResult> OnCreated(string id, string entityJson, Dictionary <string, string> switches)
        {
            try
            {
                var instance = JsonConvert.DeserializeObject <ServiceInstance>(entityJson);
                instance.InstanceId = id;

                var services = await OSBClient.CatalogAsync(switches["OSBEndpoint"], switches["OSBUser"], switches["OSBPassword"]);

                var service = services.FirstOrDefault(s => s.Id == instance.ServiceId);
                if (service == null)
                {
                    return new HandlerResult
                           {
                               Succeeded    = false,
                               ErrorMessage = string.Format("Service Id {0} is not found.", instance.ServiceId)
                           }
                }
                ;
                var plan = service.Plans.FirstOrDefault(p => p.Id == instance.PlanId);
                if (plan == null)
                {
                    return(new HandlerResult
                    {
                        Succeeded = false,
                        ErrorMessage = string.Format("Plan Id {0} is not found.", instance.PlanId)
                    });
                }

                var response = await OSBClient.ProvisionAsync(switches["OSBEndpoint"], switches["OSBUser"], switches["OSBPassword"],
                                                              instance.ServiceId, instance.PlanId, id, instance.Parameters);

                if (response.StatusCode == System.Net.HttpStatusCode.OK ||
                    response.StatusCode == System.Net.HttpStatusCode.Created ||
                    response.StatusCode == System.Net.HttpStatusCode.Accepted)
                {
                    return(new HandlerResult
                    {
                        Succeeded = true,
                        UpdatedEntity = JsonConvert.SerializeObject(instance),
                        UpdatedState = await response.Content.ReadAsStringAsync(),
                        HTTPStatus = response.StatusCode,
                        ErrorMessage = null
                    });
                }
                else
                {
                    return(new HandlerResult
                    {
                        Succeeded = false,
                        HTTPStatus = response.StatusCode,
                        //UpdatedEntity = await response.Content.ReadAsStringAsync(),
                        ErrorMessage = response.ReasonPhrase
                    });
                }
            }
            catch (Exception exp)
            {
                return(new HandlerResult
                {
                    Succeeded = false,
                    ErrorMessage = exp.Message,
                    HTTPStatus = System.Net.HttpStatusCode.InternalServerError
                });
            }
        }