/*
         * Provision a VDB
         * https://{{yourDelphixEnvironment}}/api/#database
         * Input Type: ProvisionParameters
         * Response Example:
         * {
         * "type": "OKResult",
         * "status": "OK",
         * "result": "MSSQL_DB_CONTAINER-82",
         * "job": "JOB-600",
         * "action": "ACTION-1620"
         * }
         */
        public DelphixResponse ProvisionVdb(DelphixEnvironment sourceEnv,     //Go through these and see what I can simplify.. ie: Shouldn't be passing sourceDbRef as a string and also the DelphixDb of the sourceDb
                                            DelphixSourceConfig sourceSourceConfig,
                                            DelphixRepository destinationRepo,
                                            DelphixTimeFlow snapshot,
                                            string sourceDbRef,
                                            DelphixDatabase sourceDb,
                                            string groupRefString,
                                            string displayDbName,
                                            bool wait = false
                                            )
        {
            //dbName = sourceDb.name.Substring(sourceDb.name.LastIndexOf('-') + 1).Trim();


            dynamic container = new JObject();

            container.name  = displayDbName; //Fix this
            container.type  = "MSSqlDatabaseContainer";
            container.group = groupRefString.ToString();

            dynamic source = new JObject();

            source.type   = "MSSqlVirtualSource";
            source.config = sourceSourceConfig.reference.ToString();
            source.allowAutoVDBRestartOnHostReboot = true;

            dynamic sourceConfig = new JObject();

            sourceConfig.type         = "MSSqlSIConfig";
            sourceConfig.databaseName = sourceDb.name.Substring(sourceDb.name.LastIndexOf('-') + 1).Trim(); //Fix this
            sourceConfig.repository   = destinationRepo.reference.ToString();

            dynamic timeflowPointParameters = new JObject();

            timeflowPointParameters.type      = "TimeflowPointSemantic";
            timeflowPointParameters.location  = "LATEST_SNAPSHOT";
            timeflowPointParameters.container = sourceDbRef;
            //timeflowPointParameters.timeflow = snapshot.reference;

            dynamic ProvisionParameters = new JObject();

            ProvisionParameters.container               = container;
            ProvisionParameters.source                  = source;
            ProvisionParameters.sourceConfig            = sourceConfig;
            ProvisionParameters.timeflowPointParameters = timeflowPointParameters;
            ProvisionParameters.type = "MSSqlProvisionParameters";


            ProvisionParameters = JsonConvert.SerializeObject(ProvisionParameters);
            var request = new RestRequest("resources/json/delphix/database/provision", Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddBody(ProvisionParameters);

            request.AddHeader("content-header", "application/json");
            request.AddCookie(Session.jSessionId.Name, Session.jSessionId.Value);
            logger.Info(request.ToString());
            try
            {
                var    result = Session.delphixClient.Post(request);
                string dbs    = result.Content;
                Console.WriteLine(ProvisionParameters);
                var response = JsonConvert.DeserializeObject <ProvisionVdbResponse>(dbs);
                if (response.status.Equals("OK"))
                {
                    var deserializedDbs = response.job;
                    logger.Info(deserializedDbs.ToString());

                    //If we want to wait until the Job is completed...
                    if (wait)
                    {
                        JobService jobHelper    = new JobService();
                        DelphixJob completedJob = jobHelper.GetJobByRefAndWait(deserializedDbs);
                        jobHelper.Dispose();
                        //return completedJob.parentActionState;
                        return(response);
                    }


                    return(response);
                }
                else
                {
                    var err = JsonConvert.DeserializeObject <DelphixResponseError>(result.Content);
                    //This means there was an error actually creating a job to provision a Vdb.  Check Request Body + if Delphix was reachable.
                    Console.WriteLine("The status returned from the ProvisionVDBs call was NOT OK");
                    logger.Error("There was an error creating a Job for the ProvisionVDB call.  The response status was: " + response.status + "Request Body:");
                    logger.Info(ProvisionParameters.ToString());
                    logger.Error(err.error.details);
                    //return response.status;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw ex;
            }
        }
        public DelphixResponse LinkVdb(string sqlUser, string sqlPassword,
                                       bool wait = false
                                       )
        {
            dynamic syncParameters = new JObject();

            syncParameters.type = "MSSqlExistingMostRecentBackupSyncParameters";

            dynamic operations = new JObject();

            operations.postSync = "ExternalBackupIngestionStrategy";
            operations.preSync  = "FULL_OR_DIFFERENTIAL";
            operations.type     = "LinkedSourceOperations";

            dynamic sourcingPolicy = new JObject();

            sourcingPolicy.logsyncEnabled = false;
            sourcingPolicy.type           = "SourcingPolicy";

            dynamic ingestionStrategy = new JObject();

            ingestionStrategy.type = "ExternalBackupIngestionStrategy";
            ingestionStrategy      = "FULL_OR_DIFFERENTIAL";

            dynamic dbCredential = new JObject();

            dbCredential.password = sqlPassword;
            dbCredential.type     = "PasswordCredential";

            dynamic linkData = new JObject();

            linkData.config                = "TimeflowPointSemantic";
            linkData.DbCredentials         = dbCredential;
            linkData.dbUser                = sqlUser;
            linkData.encryptionKey         = "";
            linkData.ingestionStrategy     = ingestionStrategy;
            linkData.mssqlCommvaultConfig  = null;
            linkData.mssqlNetbackupConfig  = null;
            linkData.operations            = operations;
            linkData.pptHostUser           = "******";
            linkData.pptRepository         = "";
            linkData.sharedBackupLocations = "";
            linkData.sourceHostUser        = "";
            linkData.sourcingPolicy        = sourcingPolicy;
            linkData.syncParameters        = syncParameters;
            linkData.name = "";
            linkData.type = "LinkParameters";

            dynamic ProvisionParameters = new JObject();

            ProvisionParameters.description = "";       // A description for this.
            ProvisionParameters.group       = "";       // The group to create this new dSource
            ProvisionParameters.linkData    = linkData; // All the info about the link to create



            //ProvisionParameters = JsonConvert.SerializeObject(ProvisionParameters);
            var request = new RestRequest("resources/json/delphix/database/provision", Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddBody(ProvisionParameters);

            request.AddHeader("content-header", "application/json");
            request.AddCookie(Session.jSessionId.Name, Session.jSessionId.Value);
            logger.Info(request.ToString());
            try
            {
                var    result = Session.delphixClient.Post(request);
                string dbs    = result.Content;
                Console.WriteLine(ProvisionParameters);
                var response = JsonConvert.DeserializeObject <ProvisionVdbResponse>(dbs);
                if (response.status.Equals("OK"))
                {
                    var deserializedDbs = response.job;
                    logger.Info(deserializedDbs.ToString());

                    //If we want to wait until the Job is completed...
                    if (wait)
                    {
                        JobService jobHelper    = new JobService();
                        DelphixJob completedJob = jobHelper.GetJobByRefAndWait(deserializedDbs);
                        jobHelper.Dispose();
                        //return completedJob.parentActionState;
                        return(response);
                    }


                    return(response);
                }
                else
                {
                    var err = JsonConvert.DeserializeObject <DelphixResponseError>(result.Content);
                    //This means there was an error actually creating a job to provision a Vdb.  Check Request Body + if Delphix was reachable.
                    Console.WriteLine("The status returned from the ProvisionVDBs call was NOT OK");
                    logger.Error("There was an error creating a Job for the ProvisionVDB call.  The response status was: " + response.status + "Request Body:");
                    logger.Info(ProvisionParameters.ToString());
                    logger.Error(err.error.details);
                    //return response.status;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw ex;
            }
        }
예제 #3
0
        public CreateEnvironmentResponse CreateTargetEnv(string sqlServerName, string sqlServerIp, string serverPassword, string serverUser, string buildNumber, bool wait = false)
        {
            dynamic hostEnvironment = new JObject();

            hostEnvironment.description          = "Generated by MultiRestore: " + buildNumber; //Fix this
            hostEnvironment.logCollectionEnabled = false;
            hostEnvironment.type = "WindowsHostEnvironment";
            hostEnvironment.name = "TARGET - " + sqlServerName;

            dynamic host = new JObject();

            host.address       = sqlServerIp;
            host.connectorPort = 9100;
            host.javaHome      = null;
            host.sshPort       = 22;
            host.type          = "WindowsHost";

            dynamic hostParameters = new JObject();

            hostParameters.type = "WindowsHostCreateParameters";
            hostParameters.host = host;

            dynamic credential = new JObject();

            credential.password = serverPassword;
            credential.type     = "PasswordCredential"; //Fix this

            dynamic primaryUser = new JObject();

            primaryUser.type       = "EnvironmentUser";
            primaryUser.name       = serverUser;
            primaryUser.credential = credential;

            dynamic ProvisionParameters = new JObject();

            ProvisionParameters.hostEnvironment      = hostEnvironment;
            ProvisionParameters.hostParameters       = hostParameters;
            ProvisionParameters.primaryUser          = primaryUser;
            ProvisionParameters.logCollectionEnabled = false;
            ProvisionParameters.type = "HostEnvironmentCreateParameters";



            ProvisionParameters = JsonConvert.SerializeObject(ProvisionParameters);
            var request = new RestRequest("resources/json/delphix/environment", Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddBody(ProvisionParameters);

            request.AddHeader("content-header", "application/json");
            request.AddCookie(Session.jSessionId.Name, Session.jSessionId.Value);
            logger.Info(request.ToString());
            try
            {
                var    result = Session.delphixClient.Post(request);
                string dbs    = result.Content;
                Console.WriteLine(ProvisionParameters);
                var response = JsonConvert.DeserializeObject <CreateEnvironmentResponse>(dbs);
                if (response.status.Equals("OK"))
                {
                    var deserializedDbs = response.job.ToString();
                    logger.Info(deserializedDbs);

                    //If we want to wait until the Job is completed...
                    if (wait)
                    {
                        JobService jobHelper    = new JobService();
                        DelphixJob completedJob = jobHelper.GetJobByRefAndWait(deserializedDbs);
                        jobHelper.Dispose();
                        //return completedJob.parentActionState;
                        return(response);
                    }
                    return(response);
                }
                else
                {
                    //This means there was an error actually creating a job to create a target.  Check Request Body + if Delphix was reachable.
                    Console.WriteLine("The status returned from the CreateTargetEnv call was NOT OK");
                    logger.Error("There was an error creating a Job for the CreateTargetEnv call.  The response status was: " + response.status + "Request Body:");
                    logger.Info(ProvisionParameters.ToString());

                    return(response);
                }
            }
            catch (Exception ex)
            {
                logger.Error("There was an error running CreateTargetEnvironments:" + ex);
                logger.Warn("JSON Body: " + ProvisionParameters);

                throw ex;
            }
        }