Example #1
0
        private void OnImportInstance(string msg, string reply, string subject)
        {
            Logger.Debug(Strings.OnImportInstanceDebugLogMessage, ServiceDescription(), msg, reply);
            object[] credentials = new object[0];
            credentials = JsonConvertibleObject.DeserializeFromJsonArray(msg);

            ProvisionedServicePlanType plan = (ProvisionedServicePlanType)Enum.Parse(typeof(ProvisionedServicePlanType), JsonConvertibleObject.ObjectToValue <string>(credentials[0]));

            ServiceCredentials prov_cred     = new ServiceCredentials();
            ServiceCredentials binding_creds = new ServiceCredentials();

            prov_cred.FromJsonIntermediateObject(credentials[1]);
            binding_creds.FromJsonIntermediateObject(credentials[2]);

            prov_cred.ServiceWorkFactory.StartNew(
                () =>
            {
                try
                {
                    string instance  = prov_cred.Name;
                    string file_path = this.GetMigrationFolder(instance);

                    bool result = this.ImportInstance(prov_cred, binding_creds, file_path, plan);
                    NodeNats.Publish(reply, null, result.ToString());
                }
                catch (Exception ex)
                {
                    Logger.Warning(ex.ToString());
                }
            });
        }
Example #2
0
        private void OnProvision(string msg, string reply, string subject)
        {
            Logger.Debug(Strings.OnProvisionRequestDebugLogMessage, ServiceDescription(), msg, reply);
            ProvisionResponse response      = new ProvisionResponse();
            ProvisionRequest  provision_req = new ProvisionRequest();

            provision_req.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(msg));

            ProvisionedServicePlanType plan        = provision_req.Plan;
            ServiceCredentials         credentials = provision_req.Credentials;

            if (credentials == null)
            {
                credentials = GenerateCredentials();
            }

            credentials.ServiceWorkFactory.StartNew(
                () =>
            {
                try
                {
                    ServiceCredentials credential = Provision(plan, credentials);

                    credential.NodeId = this.nodeId;

                    response.Credentials = credential;

                    Logger.Debug(
                        Strings.OnProvisionSuccessDebugLogMessage,
                        ServiceDescription(),
                        msg,
                        response.SerializeToJson());

                    NodeNats.Publish(reply, null, EncodeSuccess(response));
                }
                catch (Exception ex)
                {
                    Logger.Warning(ex.ToString());
                    NodeNats.Publish(reply, null, EncodeFailure(response));
                }
            });
        }
Example #3
0
        /// <summary>
        /// Provisions an MS Sql Server database.
        /// </summary>
        /// <param name="planRequest">The payment plan for the service.</param>
        /// <param name="credentials">Existing credentials for the service.</param>
        /// <returns>
        /// Credentials for the provisioned service.
        /// </returns>
        protected override ServiceCredentials Provision(ProvisionedServicePlanType planRequest, ServiceCredentials credentials)
        {
            //// todo: chek for plan
            ProvisionedService provisioned_service = new ProvisionedService();

            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }

            try
            {
                string name     = credentials.Name;
                string user     = credentials.User;
                string password = credentials.Password;
                provisioned_service.Name     = name;
                provisioned_service.User     = user;
                provisioned_service.Password = password;
                provisioned_service.Plan     = planRequest;

                this.CreateDatabase(provisioned_service);

                if (!ProvisionedService.Save())
                {
                    Logger.Error(Strings.SqlNodeCannotSaveProvisionedServicesErrorMessage, provisioned_service.SerializeToJson());
                    throw new MSSqlErrorException(MSSqlErrorException.MSSqlLocalDBError);
                }

                ServiceCredentials response = this.GenerateCredential(provisioned_service.Name, provisioned_service.User, provisioned_service.Password);
                this.provisionServed += 1;
                return(response);
            }
            catch (Exception)
            {
                this.DeleteDatabase(provisioned_service);
                throw;
            }
        }
Example #4
0
        /// <summary>
        /// Provisions an MS Sql Server database.
        /// </summary>
        /// <param name="planRequest">The payment plan for the service.</param>
        /// <param name="credentials">Existing credentials for the service.</param>
        /// <returns>
        /// Credentials for the provisioned service.
        /// </returns>
        protected override ServiceCredentials Provision(ProvisionedServicePlanType planRequest, ServiceCredentials credentials)
        {
            //// todo: chek for plan
            ProvisionedService provisioned_service = new ProvisionedService();
            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }

            try
            {
                string name = credentials.Name;
                string user = credentials.User;
                string password = credentials.Password;
                provisioned_service.Name = name;
                provisioned_service.User = user;
                provisioned_service.Password = password;
                provisioned_service.Plan = planRequest;

                this.CreateDatabase(provisioned_service);

                if (!ProvisionedService.Save())
                {
                    Logger.Error(Strings.SqlNodeCannotSaveProvisionedServicesErrorMessage, provisioned_service.SerializeToJson());
                    throw new MSSqlErrorException(MSSqlErrorException.MSSqlLocalDBError);
                }

                ServiceCredentials response = this.GenerateCredential(provisioned_service.Name, provisioned_service.User, provisioned_service.Password);
                this.provisionServed += 1;
                return response;
            }
            catch (Exception)
            {
                this.DeleteDatabase(provisioned_service);
                throw;
            }
        }
Example #5
0
 /// <summary>
 /// Provisions an MS Sql Server database.
 /// </summary>
 /// <param name="planRequest">The payment plan for the service.</param>
 /// <returns>
 /// Credentials for the provisioned service.
 /// </returns>
 protected override ServiceCredentials Provision(ProvisionedServicePlanType planRequest)
 {
     return Provision(planRequest, null);
 }
Example #6
0
 /// <summary>
 /// Imports an instance from a path.
 /// </summary>
 /// <param name="provisionedCredential">The provisioned credential.</param>
 /// <param name="bindingCredentials">The binding credentials.</param>
 /// <param name="filePath">The file path from which to import the service.</param>
 /// <param name="planRequest">The payment plan.</param>
 /// <returns>
 /// A bool indicating whether the request was successful.
 /// </returns>
 protected override bool ImportInstance(ServiceCredentials provisionedCredential, ServiceCredentials bindingCredentials, string filePath, ProvisionedServicePlanType planRequest)
 {
     // todo: vladi: Replace with code for odbc object for SQL Server
     return false;
 }
Example #7
0
 /// <summary>
 /// Subclasses have to implement this in order to import an instance.
 /// </summary>
 /// <param name="provisionedCredential">The provisioned credential.</param>
 /// <param name="bindingCredentials">The binding credentials.</param>
 /// <param name="filePath">The file path from which to import the service.</param>
 /// <param name="planRequest">The payment plan.</param>
 /// <returns>A bool indicating whether the request was successful.</returns>
 protected abstract bool ImportInstance(ServiceCredentials provisionedCredential, ServiceCredentials bindingCredentials, string filePath, ProvisionedServicePlanType planRequest);
Example #8
0
 /// <summary>
 /// Subclasses have to implement this in order to provision services.
 /// </summary>
 /// <param name="planRequest">The payment plan for the service.</param>
 /// <param name="credentials">Existing credentials for the service.</param>
 /// <returns>Credentials for the provisioned service.</returns>
 protected abstract ServiceCredentials Provision(ProvisionedServicePlanType planRequest, ServiceCredentials credentials);
Example #9
0
 /// <summary>
 /// Subclasses have to implement this in order to provision services.
 /// </summary>
 /// <param name="planRequest">The payment plan for the service.</param>
 /// <param name="credentials">Existing credentials for the service.</param>
 /// <returns>Credentials for the provisioned service.</returns>
 protected abstract ServiceCredentials Provision(ProvisionedServicePlanType planRequest, ServiceCredentials credentials);
Example #10
0
 /// <summary>
 /// Subclasses have to implement this in order to import an instance.
 /// </summary>
 /// <param name="provisionedCredential">The provisioned credential.</param>
 /// <param name="bindingCredentials">The binding credentials.</param>
 /// <param name="filePath">The file path from which to import the service.</param>
 /// <param name="planRequest">The payment plan.</param>
 /// <returns>A bool indicating whether the request was successful.</returns>
 protected abstract bool ImportInstance(ServiceCredentials provisionedCredential, ServiceCredentials bindingCredentials, string filePath, ProvisionedServicePlanType planRequest);
Example #11
0
 /// <summary>
 /// Provisions an MS Sql Server database.
 /// </summary>
 /// <param name="planRequest">The payment plan for the service.</param>
 /// <returns>
 /// Credentials for the provisioned service.
 /// </returns>
 protected override ServiceCredentials Provision(ProvisionedServicePlanType planRequest)
 {
     return(Provision(planRequest, null));
 }
Example #12
0
 /// <summary>
 /// Imports an instance from a path.
 /// </summary>
 /// <param name="provisionedCredential">The provisioned credential.</param>
 /// <param name="bindingCredentials">The binding credentials.</param>
 /// <param name="filePath">The file path from which to import the service.</param>
 /// <param name="planRequest">The payment plan.</param>
 /// <returns>
 /// A bool indicating whether the request was successful.
 /// </returns>
 protected override bool ImportInstance(ServiceCredentials provisionedCredential, ServiceCredentials bindingCredentials, string filePath, ProvisionedServicePlanType planRequest)
 {
     // todo: vladi: Replace with code for odbc object for SQL Server
     return(false);
 }