示例#1
0
func prettyPrint(encrypted []byte, key string, label string) {
	var decrypted, err = decrypt(encrypted, key, label)

	if err != nil {
		return
	}

	var model1 models.DesiredLRPRunInfo
	err = model1.Unmarshal(decrypted)
	if err != nil {
		// NOP
	} else {
		pretty.Println(model1)
		return
	}

	var model2 models.DesiredLRPSchedulingInfo
	err = model2.Unmarshal(decrypted)
	if err != nil {
		// NOP
	} else {
		pretty.Println(model2)
		return
	}

	var model3 models.ActualLRP
	err = model3.Unmarshal(decrypted)
	if err != nil {
		// NOP
	} else {
		pretty.Println(model3)
		return
	}

	var model4 models.Task
	err = model4.Unmarshal(decrypted)
	if err != nil {
		// NOP
	} else {
		pretty.Println(model4)
		return
	}

	var model5 models.DesiredLRP
	err = model5.Unmarshal(decrypted)
	if err != nil {
		log.Println("Unknown data type: ", string(decrypted))
	} else {
		pretty.Println(model5)
		return
	}
}
示例#2
0
		fakeServer = ghttp.NewServer()

		logger = lagertest.NewTestLogger("test")
		logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.INFO))
	})

	AfterEach(func() {
		fakeServer.Close()
	})

	Describe("HandleCompletedTask", func() {
		var (
			callbackURL string
			taskDB      *dbfakes.FakeTaskDB
			statusCodes chan int
			reqCount    chan struct{}
			task        *models.Task

			httpClient *http.Client
		)

		BeforeEach(func() {
			httpClient = cf_http.NewClient()
			statusCodes = make(chan int)
			reqCount = make(chan struct{})

			fakeServer.RouteToHandler("POST", "/the-callback/url", func(w http.ResponseWriter, req *http.Request) {
				w.WriteHeader(<-statusCodes)
			})

			callbackURL = fakeServer.URL() + "/the-callback/url"
示例#3
0
func demoteToCompleted(task *models.Task) *models.Task {
	task.State = models.Task_Completed
	return task
}
示例#4
0
		Context("when the rootfs is not preloaded", func() {
			BeforeEach(func() {
				desiredLRP.RootFs = "docker://cloudfoundry/test"
			})

			It("uses TotalDiskLimit as the disk scope", func() {
				runReq, err := rep.NewRunRequestFromDesiredLRP(containerGuid, desiredLRP, &actualLRP.ActualLRPKey, &actualLRP.ActualLRPInstanceKey)
				Expect(err).NotTo(HaveOccurred())
				Expect(runReq.DiskScope).To(Equal(executor.TotalDiskLimit))
			})
		})
	})

	Describe("NewRunRequestFromTask", func() {
		var task *models.Task
		BeforeEach(func() {
			task = model_helpers.NewValidTask("task-guid")
			task.RootFs = "preloaded://rootfs"
		})

		It("returns a valid run request", func() {
			runReq, err := rep.NewRunRequestFromTask(task)
			Expect(err).NotTo(HaveOccurred())
			Expect(runReq.Tags).To(Equal(executor.Tags{
				rep.ResultFileTag: task.ResultFile,
			}))

			Expect(runReq.RunInfo).To(Equal(executor.RunInfo{
				DiskScope:  executor.ExclusiveDiskLimit,
				CPUWeight:  uint(task.CpuWeight),
示例#5
0
文件: etcd_db.go 项目: timani/bbs
func TaskSchemaPath(task *models.Task) string {
	return TaskSchemaPathByGuid(task.GetTaskGuid())
}
示例#6
0
package models_test

import (
	"strings"
	"time"

	"github.com/cloudfoundry-incubator/bbs/models"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Task", func() {
	var taskPayload string
	var task models.Task

	BeforeEach(func() {
		taskPayload = `{
		"task_guid":"some-guid",
		"domain":"some-domain",
		"rootfs": "docker:///docker.com/docker",
		"env":[
			{
				"name":"ENV_VAR_NAME",
				"value":"an environmment value"
			}
		],
		"cell_id":"cell",
		"action": {
			"download":{
				"from":"old_location",
				"to":"new_location",
示例#7
0
文件: task_test.go 项目: timani/bbs
import (
	"encoding/json"
	"strings"
	"time"

	"github.com/cloudfoundry-incubator/bbs/format"
	"github.com/cloudfoundry-incubator/bbs/models"
	"github.com/gogo/protobuf/proto"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Task", func() {
	var taskPayload string
	var task models.Task

	BeforeEach(func() {
		taskPayload = `{
		"task_guid":"some-guid",
		"domain":"some-domain",
		"rootfs": "docker:///docker.com/docker",
		"env":[
			{
				"name":"ENV_VAR_NAME",
				"value":"an environmment value"
			}
		],
		"cell_id":"cell",
		"action": {
			"download":{
	"github.com/cloudfoundry-incubator/bbs/models/test/model_helpers"
	"github.com/cloudfoundry-incubator/rep"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/pivotal-golang/lager/lagertest"
)

var _ = Describe("Task Handlers", func() {
	var (
		logger               *lagertest.TestLogger
		fakeTaskDB           *dbfakes.FakeTaskDB
		fakeAuctioneerClient *auctioneerfakes.FakeClient
		responseRecorder     *httptest.ResponseRecorder
		exitCh               chan struct{}

		handler *handlers.TaskHandler

		task1 models.Task
		task2 models.Task

		requestBody interface{}
	)

	BeforeEach(func() {
		fakeTaskDB = new(dbfakes.FakeTaskDB)
		fakeAuctioneerClient = new(auctioneerfakes.FakeClient)
		logger = lagertest.NewTestLogger("test")
		responseRecorder = httptest.NewRecorder()
		exitCh = make(chan struct{}, 1)
		handler = handlers.NewTaskHandler(logger, fakeTaskDB, nil, fakeAuctioneerClient, fakeServiceClient, fakeRepClientFactory, exitCh)
	})
	Describe("Version", func() {
		It("returns the timestamp from which it was created", func() {
			Expect(migration.Version()).To(BeEquivalentTo(1451635200))
		})
	})

	Describe("Down", func() {
		It("returns a not implemented error", func() {
			Expect(migration.Down(logger)).To(HaveOccurred())
		})
	})

	Describe("Up", func() {
		var (
			task         *models.Task
			migrationErr error
		)

		Describe("Task Migration", func() {
			BeforeEach(func() {
				task = model_helpers.NewValidTask("task-guid-1")
				task.Action = models.WrapAction(&models.TimeoutAction{Action: model_helpers.NewValidAction(),
					DeprecatedTimeoutNs: 5 * int64(time.Second),
				})
			})

			JustBeforeEach(func() {
				taskData, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, task)
				Expect(err).NotTo(HaveOccurred())
				_, err = storeClient.Set(etcddb.TaskSchemaPath(task), taskData, 0)
				Expect(err).NotTo(HaveOccurred())
		responseRecorder *httptest.ResponseRecorder
		handler          *handlers.TaskHandler
		request          *http.Request
	)

	BeforeEach(func() {
		fakeClient = &fake_bbs.FakeClient{}
		logger = lager.NewLogger("test")
		logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.DEBUG))
		responseRecorder = httptest.NewRecorder()
		handler = handlers.NewTaskHandler(fakeClient, logger)
	})

	Describe("Create", func() {
		var validCreateRequest receptor.TaskCreateRequest
		var expectedTask *models.Task

		BeforeEach(func() {
			validCreateRequest = receptor.TaskCreateRequest{
				TaskGuid:   "task-guid-1",
				Domain:     "test-domain",
				RootFS:     "docker://docker",
				Action:     models.WrapAction(&models.RunAction{User: "******", Path: "/bin/bash", Args: []string{"echo", "hi"}}),
				MemoryMB:   24,
				DiskMB:     12,
				CPUWeight:  10,
				LogGuid:    "guid",
				LogSource:  "source-name",
				ResultFile: "result-file",
				Annotation: "some annotation",
				Privileged: true,
示例#11
0
package serialization_test

import (
	"github.com/cloudfoundry-incubator/bbs/models"
	"github.com/cloudfoundry-incubator/receptor"
	"github.com/cloudfoundry-incubator/receptor/serialization"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Task Serialization", func() {
	Describe("TaskToResponse", func() {
		var task *models.Task

		BeforeEach(func() {
			task = &models.Task{
				TaskGuid:      "the-task-guid",
				Domain:        "the-domain",
				CellId:        "the-cell-id",
				CreatedAt:     1234,
				FailureReason: "the-failure-reason",
				Failed:        true,
				Result:        "the-result",
				State:         models.Task_Invalid,
				TaskDefinition: &models.TaskDefinition{
					RootFs: "the-rootfs",
					Action: models.WrapAction(&models.UploadAction{
						From: "from",
						To:   "to",
					}),