public bool Handle(BackgroundTask task, BackgroundTaskService.BackgroundTaskLog log)
        {
            bool res;

            try
            {
                var data = DatabaseDacPacUpdateTaskData.FromString(task.Data);
                log.LogInfo("DACPAC: " + data.DacPacName);
                var azureJobsCreds = new AzureSqlJobCredentials
                {
                    ServerName   = data.ServerName,
                    DatabaseName = data.DatabaseName,
                    Username     = data.Username,
                    Password     = data.Password
                };

                var work = Do(azureJobsCreds, log, data);
                work.Wait();
                res = work.Result;
            }
            catch (Exception ex)
            {
                log.LogError("Error during database update");
                log.LogException(ex);
                res = false;
            }
            return(res);
        }
Ejemplo n.º 2
0
        public ActionResult DatabaseDeploy()
        {
            if (!CompilerHelper.IsProduction)
            {
                return(Json(new ChalkableException("This method only applies to production envs")));
            }

            var dacPacContainer = ConfigurationManager.AppSettings["DatabaseDacPacContainer"];
            var dacPacName      = CompilerHelper.Version;
            var dacPacMasterUri = dacPacContainer + dacPacName + "/Chalkable.Database.Master.dacpac";
            var dacPacSchoolUri = dacPacContainer + dacPacName + "/Chalkable.Database.School.dacpac";

            var data = new DatabaseDacPacUpdateTaskData()
            {
                ServerName      = ConfigurationManager.AppSettings["AzureSqlJobs:ServerName"],
                DatabaseName    = ConfigurationManager.AppSettings["AzureSqlJobs:DatabaseName"],
                Username        = ConfigurationManager.AppSettings["AzureSqlJobs:Username"],
                Password        = ConfigurationManager.AppSettings["AzureSqlJobs:Passwd"],
                DacPacName      = dacPacName,
                MasterDacPacUri = dacPacMasterUri,
                SchoolDacPacUri = dacPacSchoolUri
            };

            var deployTask = MasterLocator.BackgroundTaskService.ScheduleTask(BackgroundTaskTypeEnum.DatabaseDacPacUpdate, DateTime.UtcNow, null, data.ToString(), BackgroundTask.GLOBAL_DOMAIN);

            return(Json(deployTask.Id));
        }
Ejemplo n.º 3
0
        public void Test()
        {
            AzureSqlJobCredentials creds = new AzureSqlJobCredentials()
            {
                DatabaseName = "edjb0d1a0ab363747abbc2ee",
                Password     = "******",
                ServerName   = "edjb0d1a0ab363747abbc2ee.database.windows.net",
                Username     = "******"
            };

            var id = Guid.NewGuid();

            Debug.WriteLine(id);
            BackgroundTaskService.BackgroundTaskLog log = new BackgroundTaskService.BackgroundTaskLog(id, 1);
            var data = DatabaseDacPacUpdateTaskData.FromString("{\"DacPacName\":\"0-7-1d38ca879106-2321\",\"MasterDacPacUri\":\"https://chalkablestat.blob.core.windows.net/artifacts-db/0-7-1d38ca879106-2321/Chalkable.Database.Master.dacpac\",\"SchoolDacPacUri\":\"https://chalkablestat.blob.core.windows.net/artifacts-db/0-7-1d38ca879106-2321/Chalkable.Database.School.dacpac\",\"ServerName\":\"edjb0d1a0ab363747abbc2ee.database.windows.net\",\"DatabaseName\":\"edjb0d1a0ab363747abbc2ee\",\"Username\":\"chalkadmin@edjb0d1a0ab363747abbc2ee\",\"Password\":\"Hellowebapps1!\"}");

            DatabaseDacPacUpdateTaskHandler.Test(creds, log, data).Wait();
        }
 public static Task <bool> Test(AzureSqlJobCredentials creds, BackgroundTaskService.BackgroundTaskLog log, DatabaseDacPacUpdateTaskData data)
 {
     return(Do(creds, log, data));
 }
        private async static Task <bool> Do(AzureSqlJobCredentials azureJobsCreds, BackgroundTaskService.BackgroundTaskLog log, DatabaseDacPacUpdateTaskData data)
        {
            var serviceLocator = ServiceLocatorFactory.CreateMasterSysAdmin();

            var masterTargets = new List <DatabaseTarget>
            {
                new DatabaseTarget(Settings.ChalkableSchoolDbServers.First(), Settings.MasterDbName)
            };

            log.LogInfo("Master DacPac deployment initated");

            if (!(await DeployDacPac(azureJobsCreds, data.DacPacName + "-master", data.MasterDacPacUri, masterTargets, log)))
            {
                return(false);
            }

            log.LogInfo("Preparing schools DacPac targets");

            var schoolTargets = new List <DatabaseTarget>(
                Settings.ChalkableSchoolDbServers.Select(x => new DatabaseTarget(x, Settings.SchoolTemplateDbName))
                .Concat(serviceLocator.DistrictService.GetDistricts().Select(x => new DatabaseTarget(x.ServerUrl, x.Id.ToString())))
                );

            log.LogInfo("Schools DacPac deployment initated");

            if (!(await DeployDacPac(azureJobsCreds, data.DacPacName + "-school", data.SchoolDacPacUri, schoolTargets, log)))
            {
                return(false);
            }

            log.LogInfo("Deploy success");

            return(true);
        }