Beispiel #1
0
func (db *serviceClient) NewBBSLockRunner(logger lager.Logger, bbsPresence *models.BBSPresence, retryInterval, lockTTL time.Duration) (ifrit.Runner, error) {
	bbsPresenceJSON, err := models.ToJSON(bbsPresence)
	if err != nil {
		return nil, err
	}
	return locket.NewLock(logger, db.consulClient, locket.LockSchemaPath("bbs_lock"), bbsPresenceJSON, db.clock, retryInterval, lockTTL), nil
}
Beispiel #2
0
func (t *ConsulHelper) RegisterCell(cell models.CellPresence) {
	jsonBytes, err := models.ToJSON(cell)
	Expect(err).NotTo(HaveOccurred())

	err = t.consulSession.AcquireLock(consul.CellSchemaPath(cell.CellID), jsonBytes)
	Expect(err).NotTo(HaveOccurred())
}
Beispiel #3
0
func (db *serviceClient) NewCellPresenceRunner(logger lager.Logger, cellPresence *models.CellPresence, retryInterval time.Duration, lockTTL time.Duration) ifrit.Runner {
	payload, err := models.ToJSON(cellPresence)
	if err != nil {
		panic(err)
	}

	return locket.NewPresence(logger, db.consulClient, CellSchemaPath(cellPresence.CellId), payload, db.clock, retryInterval, lockTTL)
}
					BeforeEach(func() {
						cellPresence.Capacity.DiskMB = -1
					})
					It("returns an error", func() {
						err := cellPresence.Validate()
						Expect(err).To(HaveOccurred())
						Expect(err.Error()).To(ContainSubstring("disk_mb"))
					})
				})
			})
		})
	})

	Describe("ToJSON", func() {
		It("should JSONify", func() {
			json, err := models.ToJSON(&cellPresence)
			Expect(err).NotTo(HaveOccurred())
			Expect(string(json)).To(MatchJSON(payload))
		})
	})

	Describe("FromJSON", func() {
		It("returns a CellPresence with correct fields", func() {
			decodedCellPresence := &models.CellPresence{}
			err := models.FromJSON([]byte(payload), decodedCellPresence)
			Expect(err).NotTo(HaveOccurred())

			Expect(decodedCellPresence).To(Equal(&cellPresence))
		})

		Context("with an invalid payload", func() {
	BeforeEach(func() {
		rule = models.SecurityGroupRule{
			Protocol:     models.TCPProtocol,
			Destinations: []string{"1.2.3.4/16"},
			PortRange: &models.PortRange{
				Start: 1,
				End:   1024,
			},
			Log: false,
		}
	})

	Describe("To JSON", func() {
		It("should JSONify a rule", func() {
			json, err := models.ToJSON(&rule)
			Expect(err).NotTo(HaveOccurred())
			Expect(string(json)).To(MatchJSON(rulePayload))
		})

		It("should JSONify icmp info", func() {
			icmpRule := models.SecurityGroupRule{
				Protocol:     models.ICMPProtocol,
				Destinations: []string{"1.2.3.4/16"},
				IcmpInfo: &models.ICMPInfo{
					Type: 3,
					Code: 2,
				},
				Log: false,
			}
							User: "******",
						}),
						EgressRules: []*models.SecurityGroupRule{
							{Protocol: "invalid"},
						},
					},
				},
			},
		} {
			testValidatorErrorCase(testCase)
		}
	})

	Describe("Marshal", func() {
		It("should JSONify", func() {
			json, err := models.ToJSON(&task)
			Expect(err).NotTo(HaveOccurred())
			Expect(string(json)).To(MatchJSON(taskPayload))
		})
	})

	Describe("Unmarshal", func() {
		It("returns a Task with correct fields", func() {
			decodedTask := &models.Task{}
			err := models.FromJSON([]byte(taskPayload), decodedTask)
			Expect(err).NotTo(HaveOccurred())

			Expect(decodedTask).To(Equal(&task))
		})

		Context("with an invalid payload", func() {