public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); // ensure the name and email address are set var profile = userProfileRepository.GetUserProfileByUserName(model.UserName); profile.Name = model.FullName; profile.EmailAddress = model.EmailAddress; userProfileRepository.UpdateUserProfile(profile); var conference = conferenceLoader.LoadConference(); var registeredModel = new RegisteredModel { UserName = model.UserName, CanSubmitSessions = conference.CanSubmit() }; return(View("Registered", registeredModel)); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return(View(model)); }
///<inheritdoc cref="IRunRepository"/> public async Task CreateRegisteredModelAsync(Guid experimentId, Guid runArtifactId, string registeredBy) { using var db = this.contextFactory.CreateDbContext(); var runArtifact = db.RunArtifacts.FirstOrDefault(x => x.RunArtifactId == runArtifactId); if (runArtifact == null) { throw new InvalidOperationException($"The RunArtifact with id {runArtifactId} does not exist. Unable to register a model"); } var run = db.Runs.FirstOrDefault(x => x.RunId == runArtifact.RunId); var registeredModels = db.RegisteredModels.Where(x => x.ExperimentId == experimentId); var version = registeredModels.Count() > 0 ? registeredModels.Max(x => x.Version) + 1 : 1; var registeredModel = new RegisteredModel { RunArtifactId = runArtifactId, RegisteredBy = registeredBy, RegisteredDate = this.clock.UtcNow, Version = version, ExperimentId = experimentId, RunId = run.RunId }; db.RegisteredModels.Add(registeredModel); await db.SaveChangesAsync(); }
public async Task GetDeploymentUri_GivenADeployedModel_ShouldReturnAValidUri() { //Arrange var runId = Guid.NewGuid(); var experiment = new Experiment("ExperimentName"); await sut.UploadModelAsync(runId, @"Data/model.txt"); var registeredModel = new RegisteredModel { RunId = runId, ExperimentId = experiment.ExperimentId }; var deploymentTarget = new DeploymentTarget("Test"); await sut.DeployModelAsync(deploymentTarget, registeredModel, experiment); //Act var uri = sut.GetDeploymentUri(experiment, deploymentTarget); //Assert var client = new HttpClient(); var response = await client.GetAsync(uri); response.StatusCode.Should().Be(HttpStatusCode.OK); response.Content.Headers.ContentLength.Should().BeGreaterThan(0); }
public IActionResult Registered(RegisteredModel model) { if ((ModelState.IsValid) && model.IsValid()) { return(View(model)); } return(RedirectToAction("Error")); }
public async Task <ActionResult> Registered([FromBody] RegisteredModel model) { //var a = mapper.Map<User>(model); var u = mapper.Map <User>(model); u.Password = Utility.Utility.PasswordEncoding(u.Password); u.SetupTime = DateTime.Now; context.User.Add(u); await context.SaveChangesAsync(); return(Ok(new BaseResponse(true, "", null))); }
public async Task DeployModel_NoSourceFileExists_ShouldThrowException() { var experiment = new Experiment("ExperimentName"); var registeredModel = new RegisteredModel { RunId = Guid.NewGuid(), }; var deploymentTarget = new DeploymentTarget("Test"); // Act await sut.DeployModelAsync(deploymentTarget, registeredModel, experiment); }
private async Task <string> DeployModelAsync(DeploymentTarget deploymentTarget) { var runId = Guid.NewGuid(); var experiment = new Experiment("ExperimentName"); await sut.UploadModelAsync(runId, @"Data/model.txt"); var registeredModel = new RegisteredModel { RunId = runId, ExperimentId = experiment.ExperimentId }; return(await sut.DeployModelAsync(deploymentTarget, registeredModel, experiment)); }
public async Task DeployModel_NoSourceFileExist_ShouldThrowException() { var experiment = new Experiment("ExperimentName"); var registeredModel = new RegisteredModel { RunId = Guid.NewGuid(), ExperimentId = experiment.ExperimentId }; var deploymentTarget = new DeploymentTarget("Test"); var blobClientMock = new Mock <BlobClient>(); var responseMock = new Mock <Response <bool> >(); blobClientMock.Setup(x => x.Exists(default)).Returns(responseMock.Object);
public async Task DeployModel_GivenAnExistingModel_ShouldDeployModelToDeploymentTargetFolder() { //Arrange var experiment = new Experiment("ExperimentName"); var registeredModel = new RegisteredModel { RunId = Guid.NewGuid(), ExperimentId = experiment.ExperimentId, }; var deploymentTarget = new DeploymentTarget("Test"); await sut.UploadModelAsync(registeredModel.RunId, @"Data/model.txt"); //Act var deployedPath = await sut.DeployModelAsync(deploymentTarget, registeredModel, experiment); //Assert File.Exists(deployedPath).Should().BeTrue(); }
public async Task GetDeploymentUri_GivenADeployedModel_ShouldReturnAValidUri() { //Arrange var runId = Guid.NewGuid(); await sut.UploadModelAsync(runId, @"Data/model.txt"); var experiment = new Experiment("ExperimentName"); var registeredModel = new RegisteredModel { RunId = runId }; var deploymentTarget = new DeploymentTarget("Test"); await sut.DeployModelAsync(deploymentTarget, registeredModel, experiment); //Act var deployedPath = sut.GetDeploymentUri(experiment, deploymentTarget); //Assert File.Exists(deployedPath).Should().BeTrue(); }
public async Task DeployModel_GivenAnAlreadyDeployedModel_ShouldOverwriteTheExistingModel() { //Arrange var experiment = new Experiment("ExperimentName"); var registeredModel = new RegisteredModel { RunId = Guid.NewGuid(), ExperimentId = experiment.ExperimentId, }; var registeredModel1 = new RegisteredModel { RunId = Guid.NewGuid(), ExperimentId = experiment.ExperimentId, }; var deploymentTarget = new DeploymentTarget("Test"); await sut.UploadModelAsync(registeredModel.RunId, @"Data/model.txt"); await sut.UploadModelAsync(registeredModel1.RunId, @"Data/model.txt"); var deployedPath = await sut.DeployModelAsync(deploymentTarget, registeredModel, experiment); var fileInfo = new FileInfo(deployedPath); var lastUpdateTime = fileInfo.LastAccessTime; //Act deployedPath = await sut.DeployModelAsync(deploymentTarget, registeredModel1, experiment); //Assert fileInfo.Refresh(); var lastUpdateTimeNewModel = fileInfo.LastAccessTime; File.Exists(deployedPath).Should().BeTrue(); lastUpdateTime.Ticks.Should().BeLessThan(lastUpdateTimeNewModel.Ticks); }
public async Task DeployModel_ShouldReturnCorrectDeploymentPath() { var folderPath = mockFileSystem.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".mlops"); var experiment = new Experiment("ExperimentName"); var registeredModel = new RegisteredModel { RunId = Guid.NewGuid(), }; var deploymentTarget = new DeploymentTarget("Test"); var expectedPath = Path.Combine(folderPath, "deployment", "ExperimentName", "Test", $"{"ExperimentName"}.zip"); var sourcePath = Path.Combine(folderPath, "model-repository", $"{registeredModel.RunId}.zip"); mockFileSystem.AddFile(sourcePath, new MockFileData("test")); // Act var deployedPath = await sut.DeployModelAsync(deploymentTarget, registeredModel, experiment); // Assert deployedPath.Should().Be(expectedPath); }
private void PopulateRegisteredModel(IMLOpsDbContext db, RegisteredModel registeredModel) { registeredModel.RunArtifact = db.RunArtifacts.First(x => x.RunArtifactId == registeredModel.RunArtifactId); registeredModel.Run = db.Runs.First(x => x.RunId == registeredModel.RunId); registeredModel.Experiment = db.Experiments.First(x => x.ExperimentId == registeredModel.ExperimentId); }
public async Task <string> DeployModelAsync(DeploymentTarget deploymentTarget, RegisteredModel registeredModel, Experiment experiment) { var deploymentUri = GetDeploymentUri(experiment, deploymentTarget); CreateDeploymentFolder(deploymentUri); var modelName = this.modelPathGenerator.GetModelName(registeredModel.RunId); var sourceFilePath = this.fileSystem.Path.Combine(modelRepository, modelName); if (!this.fileSystem.File.Exists(sourceFilePath)) { throw new InvalidOperationException("The model to be deployed does not exist"); } await Task.Run(() => this.fileSystem.File.Copy(sourceFilePath, deploymentUri, overwrite: true)); return(deploymentUri); }
/// <summary> /// Deploys a registered model /// </summary> /// <param name="deploymentTarget"></param> /// <param name="registeredModel"></param> /// <param name="deployedBy"></param> /// <returns>A deployment</returns> /// <returns></returns> public async Task <Deployment> DeployModelAsync(DeploymentTarget deploymentTarget, RegisteredModel registeredModel, string deployedBy) { var experiment = this.experimentRepository.GetExperiment(registeredModel.ExperimentId); var deploymentUri = await this.modelRepository.DeployModelAsync(deploymentTarget, registeredModel, experiment); return(await this.deploymentRepository.CreateDeploymentAsync(deploymentTarget, registeredModel, deployedBy, deploymentUri)); }
///<inheritdoc cref="IDeploymentRepository"/> public async Task <Deployment> CreateDeploymentAsync(DeploymentTarget deploymentTarget, RegisteredModel registeredModel, string deployedBy, string deploymentUri) { using var db = this.contextFactory.CreateDbContext(); var deployment = new Deployment() { DeploymentDate = this.clock.UtcNow, DeployedBy = deployedBy, DeploymentTargetId = deploymentTarget.DeploymentTargetId, RegisteredModelId = registeredModel.RegisteredModelId, DeploymentUri = deploymentUri }; db.Deployments.Add(deployment); await db.SaveChangesAsync(); return(deployment); }
public async Task <string> DeployModelAsync(DeploymentTarget deploymentTarget, RegisteredModel registeredModel, Experiment experiment) { var deploymentPath = this.modelPathGenerator.GetDeploymentPath(deploymentTarget, experiment.ExperimentName); var sourceModelBlob = this.modelRepositoryClient.GetBlobClient(this.modelPathGenerator.GetModelName(registeredModel.RunId)); var deployedModelBlob = this.deploymentClient.GetBlobClient(deploymentPath); if (!sourceModelBlob.Exists()) { throw new InvalidOperationException("The model to be deployed does not exist"); } await deployedModelBlob.StartCopyFromUriAsync(sourceModelBlob.Uri); return(deployedModelBlob.Uri.ToString()); }
public async Task <string> DeployModelAsync(DeploymentTarget deploymentTarget, RegisteredModel registeredModel, Experiment experiment) { var deploymentPath = this.modelPathGenerator.GetDeploymentPath(deploymentTarget, experiment.ExperimentName); await CreateBucketAsync(this.s3Client, deploymentRepositoryBucket, isPublic : true); var copyObjectRequest = new CopyObjectRequest { SourceBucket = modelRepositoryBucket, SourceKey = this.modelPathGenerator.GetModelName(registeredModel.RunId), DestinationBucket = deploymentRepositoryBucket, DestinationKey = deploymentPath }; await this.s3Client.CopyObjectAsync(copyObjectRequest); return(GetDeploymentUri(experiment, deploymentTarget)); }