public static Result <ProjectTask> Create(string name, Project project, string?priority = null, string?description = null) { var task = new ProjectTask(); var nameResult = Name.Create(name); if (nameResult.Failure) { return(new Result <ProjectTask>(null, false, nameResult.Error)); } task.Name = nameResult.Value; var priorityResult = Priority.Create(priority); if (priorityResult.Failure) { return(new Result <ProjectTask>(null, false, priorityResult.Error)); } task.Priority = priorityResult.Value; task.Project = project; task.ProjectId = project.Id; task.Status = Status.Create("ToDo").Value; task.Description = description; return(new Result <ProjectTask>(task, true)); }
public void Configure(EntityTypeBuilder <Project> builder) { builder.ToTable("Project"); builder.HasKey(p => p.Id); var nameConverter = new ValueConverter <Name, string>( n => n.Value, n => Name.Create(n).Value); builder .Property(p => p.Name) .HasConversion(nameConverter) .HasColumnName("Name") .HasColumnType("text") .IsRequired(); var priorityConverter = new ValueConverter <Priority, string>( p => p.Value.ToString(), p => Priority.Create(p).Value); builder .Property(p => p.Priority) .HasConversion(priorityConverter) .HasColumnName("Priority") .HasColumnType("text") .IsRequired(); }
public Result UpdatePriority(string?priority) { var priorityResult = Priority.Create(priority); if (priorityResult.Failure) { return(new Result(false, priorityResult.Error)); } Priority = priorityResult.Value; return(new Result(true)); }
protected override void OnModelCreating( ModelBuilder builder) { builder?.Entity <UserStory>(b => { b.HasKey(e => e.Id); b.Property(e => e.Title) .IsRequired() .HasMaxLength(100); b.Property(e => e.Text) .HasMaxLength(int.MaxValue); b.Property(e => e.AcceptanceCriteria) .HasMaxLength(int.MaxValue); // 'string' ist possible too, for more see https://medium.com/agilix/entity-framework-core-enums-ee0f8f4063f2 b.Property(c => c.Importance) .HasConversion <int>(); b.HasMany(e => e.StoryTasks) .WithOne() .OnDelete(DeleteBehavior.Cascade); b.HasOne(e => e.BusinessValue).WithMany(); // Mapping for ValueObject b.Property(e => e.Priority) .HasConversion(p => p.Value, p => Priority.Create(p).Value); b.HasQueryFilter(x => x.OwnedBy == _userId); }); builder?.Entity <StoryTask>(b => { b.Property(e => e.Description) .HasMaxLength(int.MaxValue); }); builder?.Entity <BusinessValue>(b => { b.Property(p => p.Name); b.HasData(new { Id = 1, Name = "Business Value 1000", OwnedBy = "Admin" }); b.HasData(new { Id = 2, Name = "Business Value 900", OwnedBy = "Admin" }); }); }
public void Configure(EntityTypeBuilder <ProjectTask> builder) { builder.ToTable("Task"); builder.HasKey(t => t.Id); var nameConverter = new ValueConverter <Name, string>( n => n.Value, n => Name.Create(n).Value); builder .Property(t => t.Name) .HasConversion(nameConverter) .HasColumnName("Name") .HasColumnType("text") .IsRequired(); var priorityConverter = new ValueConverter <Priority, string>( p => p.Value.ToString(), p => Priority.Create(p).Value); builder .Property(t => t.Priority) .HasConversion(priorityConverter) .HasColumnName("Priority") .HasColumnType("text") .IsRequired(); var statusConverter = new ValueConverter <Status, string>( s => s.Value.ToString(), s => Status.Create(s).Value); builder .Property(t => t.Status) .HasConversion(statusConverter) .HasColumnName("Status") .HasColumnType("text") .IsRequired(); }
public virtual void TestResourceAllocation() { Log.Info("--- START: testResourceAllocation ---"); int memory = 4 * 1024; int vcores = 4; // Register node1 string host1 = "host1"; NodeManager nm1 = RegisterNode(host1, 1234, 2345, NetworkTopology.DefaultRack, Resources .CreateResource(memory, vcores)); // Register node2 string host2 = "host2"; NodeManager nm2 = RegisterNode(host2, 1234, 2345, NetworkTopology.DefaultRack, Resources .CreateResource(memory / 2, vcores / 2)); // Submit an application Application application = new Application("user1", resourceManager); application.Submit(); application.AddNodeManager(host1, 1234, nm1); application.AddNodeManager(host2, 1234, nm2); // Application resource requirements int memory1 = 1024; Org.Apache.Hadoop.Yarn.Api.Records.Resource capability1 = Resources.CreateResource (memory1, 1); Priority priority1 = Priority.Create(1); application.AddResourceRequestSpec(priority1, capability1); Task t1 = new Task(application, priority1, new string[] { host1, host2 }); application.AddTask(t1); int memory2 = 2048; Org.Apache.Hadoop.Yarn.Api.Records.Resource capability2 = Resources.CreateResource (memory2, 1); Priority priority0 = Priority.Create(0); // higher application.AddResourceRequestSpec(priority0, capability2); // Send resource requests to the scheduler application.Schedule(); // Send a heartbeat to kick the tires on the Scheduler NodeUpdate(nm1); // Get allocations from the scheduler application.Schedule(); CheckResourceUsage(nm1, nm2); Log.Info("Adding new tasks..."); Task t2 = new Task(application, priority1, new string[] { host1, host2 }); application.AddTask(t2); Task t3 = new Task(application, priority0, new string[] { ResourceRequest.Any }); application.AddTask(t3); // Send resource requests to the scheduler application.Schedule(); CheckResourceUsage(nm1, nm2); // Send heartbeats to kick the tires on the Scheduler NodeUpdate(nm2); NodeUpdate(nm2); NodeUpdate(nm1); NodeUpdate(nm1); // Get allocations from the scheduler Log.Info("Trying to allocate..."); application.Schedule(); CheckResourceUsage(nm1, nm2); // Complete tasks Log.Info("Finishing up tasks..."); application.FinishTask(t1); application.FinishTask(t2); application.FinishTask(t3); // Notify scheduler application is finished. AppAttemptRemovedSchedulerEvent appRemovedEvent1 = new AppAttemptRemovedSchedulerEvent (application.GetApplicationAttemptId(), RMAppAttemptState.Finished, false); resourceManager.GetResourceScheduler().Handle(appRemovedEvent1); CheckResourceUsage(nm1, nm2); Log.Info("--- END: testResourceAllocation ---"); }
// @Test /// <exception cref="System.Exception"/> public virtual void TestFifoScheduler() { Log.Info("--- START: testFifoScheduler ---"); int Gb = 1024; // Register node1 string host_0 = "host_0"; NodeManager nm_0 = RegisterNode(host_0, 1234, 2345, NetworkTopology.DefaultRack, Resources.CreateResource(4 * Gb, 1)); nm_0.Heartbeat(); // Register node2 string host_1 = "host_1"; NodeManager nm_1 = RegisterNode(host_1, 1234, 2345, NetworkTopology.DefaultRack, Resources.CreateResource(2 * Gb, 1)); nm_1.Heartbeat(); // ResourceRequest priorities Priority priority_0 = Priority.Create(0); Priority priority_1 = Priority.Create(1); // Submit an application Application application_0 = new Application("user_0", resourceManager); application_0.Submit(); application_0.AddNodeManager(host_0, 1234, nm_0); application_0.AddNodeManager(host_1, 1234, nm_1); Org.Apache.Hadoop.Yarn.Api.Records.Resource capability_0_0 = Resources.CreateResource (Gb); application_0.AddResourceRequestSpec(priority_1, capability_0_0); Org.Apache.Hadoop.Yarn.Api.Records.Resource capability_0_1 = Resources.CreateResource (2 * Gb); application_0.AddResourceRequestSpec(priority_0, capability_0_1); Task task_0_0 = new Task(application_0, priority_1, new string[] { host_0, host_1 }); application_0.AddTask(task_0_0); // Submit another application Application application_1 = new Application("user_1", resourceManager); application_1.Submit(); application_1.AddNodeManager(host_0, 1234, nm_0); application_1.AddNodeManager(host_1, 1234, nm_1); Org.Apache.Hadoop.Yarn.Api.Records.Resource capability_1_0 = Resources.CreateResource (3 * Gb); application_1.AddResourceRequestSpec(priority_1, capability_1_0); Org.Apache.Hadoop.Yarn.Api.Records.Resource capability_1_1 = Resources.CreateResource (4 * Gb); application_1.AddResourceRequestSpec(priority_0, capability_1_1); Task task_1_0 = new Task(application_1, priority_1, new string[] { host_0, host_1 }); application_1.AddTask(task_1_0); // Send resource requests to the scheduler Log.Info("Send resource requests to the scheduler"); application_0.Schedule(); application_1.Schedule(); // Send a heartbeat to kick the tires on the Scheduler Log.Info("Send a heartbeat to kick the tires on the Scheduler... " + "nm0 -> task_0_0 and task_1_0 allocated, used=4G " + "nm1 -> nothing allocated"); nm_0.Heartbeat(); // task_0_0 and task_1_0 allocated, used=4G nm_1.Heartbeat(); // nothing allocated // Get allocations from the scheduler application_0.Schedule(); // task_0_0 CheckApplicationResourceUsage(Gb, application_0); application_1.Schedule(); // task_1_0 CheckApplicationResourceUsage(3 * Gb, application_1); nm_0.Heartbeat(); nm_1.Heartbeat(); CheckNodeResourceUsage(4 * Gb, nm_0); // task_0_0 (1G) and task_1_0 (3G) CheckNodeResourceUsage(0 * Gb, nm_1); // no tasks, 2G available Log.Info("Adding new tasks..."); Task task_1_1 = new Task(application_1, priority_1, new string[] { ResourceRequest .Any }); application_1.AddTask(task_1_1); Task task_1_2 = new Task(application_1, priority_1, new string[] { ResourceRequest .Any }); application_1.AddTask(task_1_2); Task task_1_3 = new Task(application_1, priority_0, new string[] { ResourceRequest .Any }); application_1.AddTask(task_1_3); application_1.Schedule(); Task task_0_1 = new Task(application_0, priority_1, new string[] { host_0, host_1 }); application_0.AddTask(task_0_1); Task task_0_2 = new Task(application_0, priority_1, new string[] { host_0, host_1 }); application_0.AddTask(task_0_2); Task task_0_3 = new Task(application_0, priority_0, new string[] { ResourceRequest .Any }); application_0.AddTask(task_0_3); application_0.Schedule(); // Send a heartbeat to kick the tires on the Scheduler Log.Info("Sending hb from " + nm_0.GetHostName()); nm_0.Heartbeat(); // nothing new, used=4G Log.Info("Sending hb from " + nm_1.GetHostName()); nm_1.Heartbeat(); // task_0_3, used=2G // Get allocations from the scheduler Log.Info("Trying to allocate..."); application_0.Schedule(); CheckApplicationResourceUsage(3 * Gb, application_0); application_1.Schedule(); CheckApplicationResourceUsage(3 * Gb, application_1); nm_0.Heartbeat(); nm_1.Heartbeat(); CheckNodeResourceUsage(4 * Gb, nm_0); CheckNodeResourceUsage(2 * Gb, nm_1); // Complete tasks Log.Info("Finishing up task_0_0"); application_0.FinishTask(task_0_0); // Now task_0_1 application_0.Schedule(); application_1.Schedule(); nm_0.Heartbeat(); nm_1.Heartbeat(); CheckApplicationResourceUsage(3 * Gb, application_0); CheckApplicationResourceUsage(3 * Gb, application_1); CheckNodeResourceUsage(4 * Gb, nm_0); CheckNodeResourceUsage(2 * Gb, nm_1); Log.Info("Finishing up task_1_0"); application_1.FinishTask(task_1_0); // Now task_0_2 application_0.Schedule(); // final overcommit for app0 caused here application_1.Schedule(); nm_0.Heartbeat(); // final overcommit for app0 occurs here nm_1.Heartbeat(); CheckApplicationResourceUsage(4 * Gb, application_0); CheckApplicationResourceUsage(0 * Gb, application_1); //checkNodeResourceUsage(1*GB, nm_0); // final over-commit -> rm.node->1G, test.node=2G CheckNodeResourceUsage(2 * Gb, nm_1); Log.Info("Finishing up task_0_3"); application_0.FinishTask(task_0_3); // No more application_0.Schedule(); application_1.Schedule(); nm_0.Heartbeat(); nm_1.Heartbeat(); CheckApplicationResourceUsage(2 * Gb, application_0); CheckApplicationResourceUsage(0 * Gb, application_1); //checkNodeResourceUsage(2*GB, nm_0); // final over-commit, rm.node->1G, test.node->2G CheckNodeResourceUsage(0 * Gb, nm_1); Log.Info("Finishing up task_0_1"); application_0.FinishTask(task_0_1); application_0.Schedule(); application_1.Schedule(); nm_0.Heartbeat(); nm_1.Heartbeat(); CheckApplicationResourceUsage(1 * Gb, application_0); CheckApplicationResourceUsage(0 * Gb, application_1); Log.Info("Finishing up task_0_2"); application_0.FinishTask(task_0_2); // now task_1_3 can go! application_0.Schedule(); application_1.Schedule(); nm_0.Heartbeat(); nm_1.Heartbeat(); CheckApplicationResourceUsage(0 * Gb, application_0); CheckApplicationResourceUsage(4 * Gb, application_1); Log.Info("Finishing up task_1_3"); application_1.FinishTask(task_1_3); // now task_1_1 application_0.Schedule(); application_1.Schedule(); nm_0.Heartbeat(); nm_1.Heartbeat(); CheckApplicationResourceUsage(0 * Gb, application_0); CheckApplicationResourceUsage(3 * Gb, application_1); Log.Info("Finishing up task_1_1"); application_1.FinishTask(task_1_1); application_0.Schedule(); application_1.Schedule(); nm_0.Heartbeat(); nm_1.Heartbeat(); CheckApplicationResourceUsage(0 * Gb, application_0); CheckApplicationResourceUsage(3 * Gb, application_1); Log.Info("--- END: testFifoScheduler ---"); }