public override OperationResult Test(AddonTestRequest _request) { var manifest = _request.Manifest; var devParameters = _request.DeveloperParameters; var devOptions = BMDeveloperOptions.Parse(devParameters, manifest); var testResult = new OperationResult { EndUserMessage = string.Empty, IsSuccess = false }; end_point = devOptions.api_url; bm_version = devOptions.api_version; try { var token = authenticate(devOptions.bluemixuser, devOptions.bluemixpass); var servicePlansURL = getServicePlansURL(token, devOptions.servicename); } catch (Exception ex) { var errorMessage = string.Format("BluemixAddon Testing Error: {0}\n{1}", ex, ex.StackTrace); log.Error(errorMessage); testResult.EndUserMessage = errorMessage; return(testResult); } testResult.EndUserMessage = "BluemixAddon Add-On was tested successfully"; testResult.IsSuccess = true; return(testResult); }
public override OperationResult Deprovision(AddonDeprovisionRequest _request) { var deprovisionResult = new OperationResult { EndUserMessage = string.Empty, IsSuccess = false }; var manifest = _request.Manifest; var devParameters = _request.DeveloperParameters; var devOptions = BMDeveloperOptions.Parse(devParameters, manifest); end_point = devOptions.api_url; bm_version = devOptions.api_version; try { var token = authenticate(devOptions.bluemixuser, devOptions.bluemixpass); string name = devOptions.name; var serviceGUID = getServiceGUID(token, name); var status = deleteServiceInstance(token, name, serviceGUID); log.Info("BluemixAddon Deprovisioned Successfully"); } catch (Exception ex) { var errorMessage = string.Format("BluemixAddon Deprovision Error: {0}\n{1}", ex, ex.StackTrace); log.Error(errorMessage); deprovisionResult.EndUserMessage = errorMessage; return(deprovisionResult); } deprovisionResult.IsSuccess = true; return(deprovisionResult); }
public static BMDeveloperOptions Parse(IEnumerable <AddonParameter> _developerParameters, AddonManifest manifest) { var options = new BMDeveloperOptions(); foreach (var parameter in manifest.Properties) { MapToOption(options, parameter.Key.ToLowerInvariant(), parameter.Value); } foreach (var parameter in _developerParameters) { MapToOption(options, parameter.Key.ToLowerInvariant(), parameter.Value); } return(options); }
private static void MapToOption(BMDeveloperOptions _options, string _key, string _value) { var _developerOptions = _options.GetType().GetProperties(); foreach (var prop in _developerOptions) { if (prop.Name.Equals(_key)) { prop.SetValue(_options, _value); return; } } log.Error(string.Format("The developer option '{0}' was not expected.", _key)); return; }
public override ProvisionAddOnResult Provision(AddonProvisionRequest _request) { var provisionResult = new ProvisionAddOnResult(string.Empty) { IsSuccess = false }; var manifest = _request.Manifest; var devParameters = _request.DeveloperParameters; var devOptions = BMDeveloperOptions.Parse(devParameters, manifest); end_point = devOptions.api_url; bm_version = devOptions.api_version; string instanceDetails = ""; try { var token = authenticate(devOptions.bluemixuser, devOptions.bluemixpass); var servicePlansURL = getServicePlansURL(token, devOptions.servicename); var servicePlanGUID = getServicePlanGUID(token, servicePlansURL); string name = devOptions.name; var spaceGUID = getSpaceGuid(token, devOptions.space); var serviceInstanceGUID = createServiceInstance(token, name, servicePlanGUID, spaceGUID); instanceDetails = createInstanceDetails(token, name, serviceInstanceGUID); log.Info("BluemixAddon Provisioned Successfully"); } catch (Exception ex) { var errorMessage = string.Format("BluemixAddon Provisioning Error: {0}\n{1}", ex, ex.StackTrace); log.Error(errorMessage); provisionResult.EndUserMessage = errorMessage; return(provisionResult); } provisionResult.IsSuccess = true; provisionResult.ConnectionData = instanceDetails; return(provisionResult); }