本文整理汇总了Golang中github.com/evergreen-ci/evergreen/model/distro.Distro类的典型用法代码示例。如果您正苦于以下问题:Golang Distro类的具体用法?Golang Distro怎么用?Golang Distro使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Distro类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: addDistro
func (uis *UIServer) addDistro(w http.ResponseWriter, r *http.Request) {
id, hasId := mux.Vars(r)["distro_id"]
u := MustHaveUser(r)
b, err := ioutil.ReadAll(r.Body)
if err != nil {
message := fmt.Sprintf("error adding distro: %v", err)
PushFlash(uis.CookieStore, r, w, NewErrorFlash(message))
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
defer r.Body.Close()
var d distro.Distro
if err = json.Unmarshal(b, &d); err != nil {
message := fmt.Sprintf("error adding distro: %v", err)
PushFlash(uis.CookieStore, r, w, NewErrorFlash(message))
http.Error(w, message, http.StatusBadRequest)
return
}
if hasId {
d.Id = id
}
vErrs, err := validator.CheckDistro(&d, &uis.Settings, true)
if err != nil {
message := fmt.Sprintf("error retrieving distroIds: %v", err)
PushFlash(uis.CookieStore, r, w, NewErrorFlash(message))
http.Error(w, message, http.StatusInternalServerError)
return
}
if len(vErrs) != 0 {
for _, e := range vErrs {
PushFlash(uis.CookieStore, r, w, NewErrorFlash(e.Error()))
}
uis.WriteJSON(w, http.StatusBadRequest, vErrs)
return
}
if err = d.Insert(); err != nil {
message := fmt.Sprintf("error inserting distro '%v': %v", d.Id, err)
PushFlash(uis.CookieStore, r, w, NewErrorFlash(message))
uis.WriteJSON(w, http.StatusInternalServerError, err)
return
}
event.LogDistroAdded(d.Id, u.Username(), d)
PushFlash(uis.CookieStore, r, w, NewSuccessFlash(fmt.Sprintf("Distro %v successfully added.", d.Id)))
uis.WriteJSON(w, http.StatusOK, "distro successfully added")
}
开发者ID:tychoish,项目名称:evergreen,代码行数:55,代码来源:distros.go
示例2: TestAverageStatistics
func TestAverageStatistics(t *testing.T) {
testutil.HandleTestingErr(db.ClearCollections(task.Collection), t, "couldnt reset host")
Convey("With a distro sampleDistro inserted", t, func() {
d := distro.Distro{
Id: "sampleDistro",
}
err := d.Insert()
So(err, ShouldBeNil)
distroId := d.Id
Convey("With a set of tasks that have different scheduled -> start times over a given time period", func() {
now := time.Now()
bucketSize := 10 * time.Second
numberBuckets := 3
task1 := task.Task{Id: "task1", ScheduledTime: now,
StartTime: now.Add(time.Duration(5) * time.Second), Status: evergreen.TaskStarted, DistroId: distroId}
So(task1.Insert(), ShouldBeNil)
task2 := task.Task{Id: "task2", ScheduledTime: now,
StartTime: now.Add(time.Duration(20) * time.Second), Status: evergreen.TaskStarted, DistroId: distroId}
So(task2.Insert(), ShouldBeNil)
task3 := task.Task{Id: "task3", ScheduledTime: now.Add(time.Duration(10) * time.Second),
StartTime: now.Add(time.Duration(20) * time.Second), Status: evergreen.TaskStarted, DistroId: distroId}
So(task3.Insert(), ShouldBeNil)
frameBounds := FrameBounds{
StartTime: now,
EndTime: now.Add(time.Duration(numberBuckets) * bucketSize),
NumberBuckets: numberBuckets,
BucketSize: bucketSize,
}
avgBuckets, err := AverageStatistics(distroId, frameBounds)
So(err, ShouldBeNil)
So(avgBuckets[0].AverageTime, ShouldEqual, 5*time.Second)
So(avgBuckets[1].AverageTime, ShouldEqual, 0)
So(avgBuckets[2].AverageTime, ShouldEqual, 15*time.Second)
Convey("if the distro id given does not exist, it shoud return an empty list", func() {
_, err := AverageStatistics("noId", frameBounds)
So(err, ShouldNotBeNil)
})
})
})
}
开发者ID:tychoish,项目名称:evergreen,代码行数:49,代码来源:scheduler_stats_test.go
示例3: TestStoreRepositoryRevisions
func TestStoreRepositoryRevisions(t *testing.T) {
dropTestDB(t)
testutil.ConfigureIntegrationTest(t, testConfig, "TestStoreRepositoryRevisions")
Convey("When storing revisions gotten from a repository...", t, func() {
err := testutil.CreateTestLocalConfig(testConfig, "mci-test", "")
So(err, ShouldBeNil)
repoTracker := RepoTracker{testConfig, projectRef, NewGithubRepositoryPoller(projectRef,
testConfig.Credentials["github"])}
// insert distros used in testing.
d := distro.Distro{Id: "test-distro-one"}
So(d.Insert(), ShouldBeNil)
d.Id = "test-distro-two"
So(d.Insert(), ShouldBeNil)
Convey("On storing a single repo revision, we expect a version to be created"+
" in the database for this project, which should be retrieved when we search"+
" for this project's most recent version", func() {
createTime := time.Now()
revisionOne := *createTestRevision("firstRevision", createTime)
revisions := []model.Revision{revisionOne}
resultVersion, err := repoTracker.StoreRevisions(revisions)
testutil.HandleTestingErr(err, t, "Error storing repository revisions %v")
newestVersion, err := version.FindOne(version.ByMostRecentForRequester(projectRef.String(), evergreen.RepotrackerVersionRequester))
testutil.HandleTestingErr(err, t, "Error retreiving newest version %v")
So(resultVersion, ShouldResemble, newestVersion)
})
Convey("On storing several repo revisions, we expect a version to be created "+
"for each revision", func() {
createTime := time.Now()
laterCreateTime := createTime.Add(time.Duration(4 * time.Hour))
revisionOne := *createTestRevision("one", laterCreateTime)
revisionTwo := *createTestRevision("two", createTime)
revisions := []model.Revision{revisionOne, revisionTwo}
_, err := repoTracker.StoreRevisions(revisions)
testutil.HandleTestingErr(err, t, "Error storing repository revisions %v")
versionOne, err := version.FindOne(version.ByProjectIdAndRevision(projectRef.Identifier, revisionOne.Revision))
testutil.HandleTestingErr(err, t, "Error retrieving first stored version %v")
versionTwo, err := version.FindOne(version.ByProjectIdAndRevision(projectRef.Identifier, revisionTwo.Revision))
testutil.HandleTestingErr(err, t, "Error retreiving second stored version %v")
So(versionOne.Revision, ShouldEqual, revisionOne.Revision)
So(versionTwo.Revision, ShouldEqual, revisionTwo.Revision)
})
Reset(func() {
dropTestDB(t)
})
})
Convey("When storing versions from repositories with remote configuration files...", t, func() {
project := createTestProject(nil, nil)
revisions := []model.Revision{
*createTestRevision("foo", time.Now().Add(1*time.Minute)),
}
poller := NewMockRepoPoller(project, revisions)
repoTracker := RepoTracker{
testConfig,
&model.ProjectRef{
Identifier: "testproject",
BatchTime: 10,
},
poller,
}
// insert distros used in testing.
d := distro.Distro{Id: "test-distro-one"}
So(d.Insert(), ShouldBeNil)
d.Id = "test-distro-two"
So(d.Insert(), ShouldBeNil)
Convey("We should not fetch configs for versions we already have stored.",
func() {
So(poller.ConfigGets, ShouldBeZeroValue)
// Store revisions the first time
_, err := repoTracker.StoreRevisions(revisions)
So(err, ShouldBeNil)
// We should have fetched the config once for each revision
So(poller.ConfigGets, ShouldEqual, len(revisions))
// Store them again
_, err = repoTracker.StoreRevisions(revisions)
So(err, ShouldBeNil)
// We shouldn't have fetched the config any additional times
// since we have already stored these versions
So(poller.ConfigGets, ShouldEqual, len(revisions))
},
)
//.........这里部分代码省略.........
开发者ID:himanshugpt,项目名称:evergreen,代码行数:101,代码来源:repotracker_test.go
示例4: TestBatchTimes
func TestBatchTimes(t *testing.T) {
dropTestDB(t)
Convey("When deciding whether or not to activate variants for the most recently stored version", t, func() {
// We create a version with an activation time of now so that all the bvs have a last activation time of now.
previouslyActivatedVersion := version.Version{
Id: "previously activated",
Identifier: "testproject",
BuildVariants: []version.BuildStatus{
{
BuildVariant: "bv1",
Activated: true,
ActivateAt: time.Now(),
},
{
BuildVariant: "bv2",
Activated: true,
ActivateAt: time.Now(),
},
},
RevisionOrderNumber: 0,
Requester: evergreen.RepotrackerVersionRequester,
}
So(previouslyActivatedVersion.Insert(), ShouldBeNil)
// insert distros used in testing.
d := distro.Distro{Id: "test-distro-one"}
So(d.Insert(), ShouldBeNil)
d.Id = "test-distro-two"
So(d.Insert(), ShouldBeNil)
Convey("If the project's batch time has not elapsed, and no buildvariants "+
"have overriden their batch times, no variants should be activated", func() {
project := createTestProject(nil, nil)
revisions := []model.Revision{
*createTestRevision("foo", time.Now()),
}
repoTracker := RepoTracker{
testConfig,
&model.ProjectRef{
Identifier: "testproject",
BatchTime: 1,
},
NewMockRepoPoller(project, revisions),
}
v, err := repoTracker.StoreRevisions(revisions)
So(v, ShouldNotBeNil)
So(err, ShouldBeNil)
So(len(v.BuildVariants), ShouldEqual, 2)
So(repoTracker.activateElapsedBuilds(v), ShouldBeNil)
So(v.BuildVariants[0].Activated, ShouldBeFalse)
So(v.BuildVariants[1].Activated, ShouldBeFalse)
})
Convey("If the project's batch time has elapsed, and no buildvariants "+
"have overridden their batch times, all variants should be activated", func() {
project := createTestProject(nil, nil)
revisions := []model.Revision{
*createTestRevision("bar", time.Now().Add(time.Duration(-6*time.Minute))),
}
repoTracker := RepoTracker{
testConfig,
&model.ProjectRef{
Identifier: "testproject",
BatchTime: 0,
},
NewMockRepoPoller(project, revisions),
}
version, err := repoTracker.StoreRevisions(revisions)
So(version, ShouldNotBeNil)
So(err, ShouldBeNil)
So(repoTracker.activateElapsedBuilds(version), ShouldBeNil)
bv1, found := findStatus(version, "bv1")
So(found, ShouldBeTrue)
So(bv1.Activated, ShouldBeTrue)
bv2, found := findStatus(version, "bv2")
So(found, ShouldBeTrue)
So(bv2.Activated, ShouldBeTrue)
})
Convey("If the project's batch time has elapsed, but both variants "+
"have overridden their batch times (which have not elapsed)"+
", no variants should be activated", func() {
// need to assign pointer vals
twoforty := 240
onetwenty := 120
project := createTestProject(&twoforty, &onetwenty)
revisions := []model.Revision{
*createTestRevision("baz", time.Now()),
}
repoTracker := RepoTracker{
testConfig,
&model.ProjectRef{
Identifier: "testproject",
BatchTime: 60,
},
//.........这里部分代码省略.........
开发者ID:himanshugpt,项目名称:evergreen,代码行数:101,代码来源:repotracker_test.go
示例5: TestSpawnHosts
func TestSpawnHosts(t *testing.T) {
Convey("When spawning hosts", t, func() {
distroIds := []string{"d1", "d2", "d3"}
schedulerInstance := &Scheduler{
schedulerTestConf,
&MockTaskFinder{},
&MockTaskPrioritizer{},
&MockTaskDurationEstimator{},
&MockTaskQueuePersister{},
&MockHostAllocator{},
}
Convey("if there are no hosts to be spawned, the Scheduler should not"+
" make any calls to the CloudManager", func() {
newHostsNeeded := map[string]int{
distroIds[0]: 0,
distroIds[1]: 0,
distroIds[2]: 0,
}
newHostsSpawned, err := schedulerInstance.spawnHosts(newHostsNeeded)
So(err, ShouldBeNil)
So(len(newHostsSpawned[distroIds[0]]), ShouldEqual, 0)
So(len(newHostsSpawned[distroIds[1]]), ShouldEqual, 0)
So(len(newHostsSpawned[distroIds[2]]), ShouldEqual, 0)
})
Convey("if there are hosts to be spawned, the Scheduler should make"+
" one call to the CloudManager for each host, and return the"+
" results bucketed by distro", func() {
newHostsNeeded := map[string]int{
distroIds[0]: 3,
distroIds[1]: 0,
distroIds[2]: 1,
}
for _, id := range distroIds {
d := distro.Distro{Id: id, PoolSize: 1, Provider: mock.ProviderName}
So(d.Insert(), ShouldBeNil)
}
newHostsSpawned, err := schedulerInstance.spawnHosts(newHostsNeeded)
So(err, ShouldBeNil)
distroZeroHosts := newHostsSpawned[distroIds[0]]
distroOneHosts := newHostsSpawned[distroIds[1]]
distroTwoHosts := newHostsSpawned[distroIds[2]]
So(len(distroZeroHosts), ShouldEqual, 3)
So(distroZeroHosts[0].Distro.Id, ShouldEqual, distroIds[0])
So(distroZeroHosts[1].Distro.Id, ShouldEqual, distroIds[0])
So(distroZeroHosts[2].Distro.Id, ShouldEqual, distroIds[0])
So(len(distroOneHosts), ShouldEqual, 0)
So(len(distroTwoHosts), ShouldEqual, 1)
So(distroTwoHosts[0].Distro.Id, ShouldEqual, distroIds[2])
})
Reset(func() {
db.Clear(distro.Collection)
})
})
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:66,代码来源:scheduler_test.go
示例6: TestCheckDistro
func TestCheckDistro(t *testing.T) {
Convey("When validating a distro", t, func() {
Convey("if a new distro passes all of the validation tests, no errors should be returned", func() {
d := &distro.Distro{Id: "a", Arch: "a", User: "a", SSHKey: "a", WorkDir: "a",
Provider: ec2.OnDemandProviderName,
ProviderSettings: &map[string]interface{}{
"ami": "a",
"key_name": "a",
"instance_type": "a",
"security_group": "a",
"mount_points": nil,
},
}
So(CheckDistro(d, conf, true), ShouldResemble, []ValidationError{})
})
Convey("if a new distro fails a validation test, an error should be returned", func() {
d := &distro.Distro{Id: "a", Arch: "a", User: "a", SSHKey: "a", WorkDir: "a",
Provider: ec2.OnDemandProviderName,
ProviderSettings: &map[string]interface{}{
"ami": "a",
"key_name": "a",
"instance_type": "a",
"security_group": "a",
"mount_points": nil,
},
}
// simulate duplicate id
dupe := distro.Distro{Id: "a"}
So(dupe.Insert(), ShouldBeNil)
So(CheckDistro(d, conf, true), ShouldNotResemble, []ValidationError{})
})
Convey("if an existing distro passes all of the validation tests, no errors should be returned", func() {
d := &distro.Distro{Id: "a", Arch: "a", User: "a", SSHKey: "a", WorkDir: "a",
Provider: ec2.OnDemandProviderName,
ProviderSettings: &map[string]interface{}{
"ami": "a",
"key_name": "a",
"instance_type": "a",
"security_group": "a",
"mount_points": nil,
},
}
So(CheckDistro(d, conf, false), ShouldResemble, []ValidationError{})
})
Convey("if an existing distro fails a validation test, an error should be returned", func() {
d := &distro.Distro{Id: "a", Arch: "a", User: "a", SSHKey: "a", WorkDir: "a",
Provider: ec2.OnDemandProviderName,
ProviderSettings: &map[string]interface{}{
"ami": "",
"key_name": "a",
"instance_type": "a",
"security_group": "a",
"mount_points": nil,
},
}
// empty ami for provider
So(CheckDistro(d, conf, false), ShouldNotResemble, []ValidationError{})
})
Reset(func() {
db.Clear(distro.Collection)
})
})
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:70,代码来源:distro_validator_test.go
示例7: TestDeficitBasedHostAllocator
func TestDeficitBasedHostAllocator(t *testing.T) {
var taskIds []string
var runningTaskIds []string
var hostIds []string
var dist distro.Distro
var hostAllocator *DeficitBasedHostAllocator
Convey("With a deficit based host allocator,"+
" determining the number of new hosts to spin up...", t, func() {
hostAllocator = &DeficitBasedHostAllocator{}
taskIds = []string{"t1", "t2", "t3", "t4", "t5"}
runningTaskIds = []string{"t1", "t2", "t3", "t4", "t5"}
hostIds = []string{"h1", "h2", "h3", "h4", "h5"}
dist = distro.Distro{Provider: "ec2"}
Convey("if there are no tasks to run, no new hosts should be needed",
func() {
hosts := []host.Host{
{Id: hostIds[0]},
{Id: hostIds[1]},
{Id: hostIds[2]},
}
dist.PoolSize = len(hosts) + 5
hostAllocatorData := &HostAllocatorData{
existingDistroHosts: map[string][]host.Host{
"": hosts,
},
distros: map[string]distro.Distro{
"": dist,
},
}
So(hostAllocator.numNewHostsForDistro(hostAllocatorData,
dist, hostAllocatorTestConf), ShouldEqual, 0)
})
Convey("if the number of existing hosts equals the max hosts, no new"+
" hosts can be spawned", func() {
taskQueueItems := []model.TaskQueueItem{
{Id: taskIds[0]},
{Id: taskIds[1]},
{Id: taskIds[2]},
{Id: taskIds[3]},
}
dist.PoolSize = 0
hostAllocatorData := &HostAllocatorData{
existingDistroHosts: map[string][]host.Host{},
distros: map[string]distro.Distro{
"": dist,
},
}
So(hostAllocator.numNewHostsForDistro(hostAllocatorData, dist, hostAllocatorTestConf),
ShouldEqual, 0)
hosts := []host.Host{
{Id: hostIds[0]},
}
dist.PoolSize = len(hosts)
hostAllocatorData = &HostAllocatorData{
taskQueueItems: map[string][]model.TaskQueueItem{
"": taskQueueItems,
},
existingDistroHosts: map[string][]host.Host{
"": hosts,
},
distros: map[string]distro.Distro{
"": dist,
},
}
So(hostAllocator.numNewHostsForDistro(hostAllocatorData, dist, hostAllocatorTestConf),
ShouldEqual, 0)
})
Convey("if the number of existing hosts exceeds the max hosts, no new"+
" hosts can be spawned", func() {
taskQueueItems := []model.TaskQueueItem{
{Id: taskIds[0]},
{Id: taskIds[1]},
{Id: taskIds[2]},
{Id: taskIds[3]},
}
hosts := []host.Host{
{Id: hostIds[0]},
{Id: hostIds[1]},
}
dist.PoolSize = 1
hostAllocatorData := &HostAllocatorData{
taskQueueItems: map[string][]model.TaskQueueItem{
"": taskQueueItems,
},
existingDistroHosts: map[string][]host.Host{
"": hosts,
},
//.........这里部分代码省略.........
开发者ID:tychoish,项目名称:evergreen,代码行数:101,代码来源:deficit_based_host_allocator_test.go
示例8: TestDurationBasedHostAllocator
func TestDurationBasedHostAllocator(t *testing.T) {
var taskIds []string
var runningTaskIds []string
var hostIds []string
var dist distro.Distro
var testTaskDuration time.Duration
var taskDurations model.ProjectTaskDurations
var durationBasedHostAllocator *DurationBasedHostAllocator
Convey("With a duration based host allocator,"+
" determining the number of new hosts to spin up", t, func() {
durationBasedHostAllocator = &DurationBasedHostAllocator{}
taskIds = []string{"t1", "t2", "t3", "t4", "t5"}
runningTaskIds = []string{"t1", "t2", "t3", "t4", "t5"}
hostIds = []string{"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "h9"}
dist = distro.Distro{Provider: "ec2"}
testTaskDuration = time.Duration(2) * time.Minute
taskDurations = model.ProjectTaskDurations{
TaskDurationByProject: map[string]*model.BuildVariantTaskDurations{
"": &model.BuildVariantTaskDurations{
TaskDurationByBuildVariant: map[string]*model.TaskDurations{
"": &model.TaskDurations{
TaskDurationByDisplayName: map[string]time.Duration{
"": testTaskDuration,
},
},
},
},
},
}
So(db.Clear(task.Collection), ShouldBeNil)
Convey("if there are no tasks to run, no new hosts should be needed",
func() {
hosts := []host.Host{
host.Host{Id: hostIds[0]},
host.Host{Id: hostIds[1]},
host.Host{Id: hostIds[2]},
}
dist.PoolSize = len(hosts) + 5
hostAllocatorData := &HostAllocatorData{
existingDistroHosts: map[string][]host.Host{
"": hosts,
},
distros: map[string]distro.Distro{
"": dist,
},
}
tasksAccountedFor := make(map[string]bool)
distroScheduleData := make(map[string]DistroScheduleData)
newHosts, err := durationBasedHostAllocator.
numNewHostsForDistro(hostAllocatorData, dist,
tasksAccountedFor, distroScheduleData, hostAllocatorTestConf)
So(err, ShouldBeNil)
So(newHosts, ShouldEqual, 0)
})
Convey("if the number of existing hosts equals the max hosts, no new"+
" hosts can be spawned", func() {
taskQueueItems := []model.TaskQueueItem{
model.TaskQueueItem{Id: taskIds[0]},
model.TaskQueueItem{Id: taskIds[1]},
model.TaskQueueItem{Id: taskIds[2]},
model.TaskQueueItem{Id: taskIds[3]},
}
dist.PoolSize = 0
hostAllocatorData := &HostAllocatorData{
existingDistroHosts: map[string][]host.Host{},
distros: map[string]distro.Distro{
"": dist,
},
}
tasksAccountedFor := make(map[string]bool)
distroScheduleData := make(map[string]DistroScheduleData)
newHosts, err := durationBasedHostAllocator.
numNewHostsForDistro(hostAllocatorData, dist,
tasksAccountedFor, distroScheduleData, hostAllocatorTestConf)
So(err, ShouldBeNil)
So(newHosts, ShouldEqual, 0)
hosts := []host.Host{
host.Host{Id: hostIds[0]},
}
dist.PoolSize = len(hosts)
hostAllocatorData = &HostAllocatorData{
taskQueueItems: map[string][]model.TaskQueueItem{
"": taskQueueItems,
},
existingDistroHosts: map[string][]host.Host{
"": hosts,
},
distros: map[string]distro.Distro{
//.........这里部分代码省略.........
开发者ID:sr527,项目名称:evergreen,代码行数:101,代码来源:duration_based_host_allocator_test.go
注:本文中的github.com/evergreen-ci/evergreen/model/distro.Distro类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论