예제 #1
0
func (c *VcapComponent) Start() error {
	if c.Varz.Type == "" {
		err := errors.New("type is required")
		log.Error("Component type is required", err)
		return err
	}

	c.quitCh = make(chan struct{}, 1)
	c.Varz.StartTime = schema.Time(time.Now())
	uuid, err := GenerateUUID()
	if err != nil {
		return err
	}
	c.Varz.UUID = fmt.Sprintf("%d-%s", c.Varz.Index, uuid)

	if c.Varz.Host == "" {
		host, err := localip.LocalIP()
		if err != nil {
			log.Error("error-getting-localIP", err)
			return err
		}

		port, err := localip.LocalPort()
		if err != nil {
			log.Error("error-getting-localPort", err)
			return err
		}

		c.Varz.Host = fmt.Sprintf("%s:%d", host, port)
	}

	if c.Varz.Credentials == nil || len(c.Varz.Credentials) != 2 {
		user, err := GenerateUUID()
		if err != nil {
			return err
		}
		password, err := GenerateUUID()
		if err != nil {
			return err
		}

		c.Varz.Credentials = []string{user, password}
	}

	if c.Logger != nil {
		log = c.Logger
	}

	c.Varz.NumCores = runtime.NumCPU()

	procStat = NewProcessStatus()

	c.ListenAndServe()
	return nil
}
예제 #2
0
			d := schema.Duration(time.Hour*36 + time.Second*20)
			b, err := json.Marshal(d)
			Expect(err).ToNot(HaveOccurred())

			var dd schema.Duration
			dd.UnmarshalJSON(b)
			Expect(dd).To(Equal(d))
		})
	})

	Context("Time", func() {
		It("marshals JSON", func() {
			n := time.Now()
			f := "2006-01-02 15:04:05 -0700"

			t := schema.Time(n)
			b, e := json.Marshal(t)
			Expect(e).ToNot(HaveOccurred())
			Expect(string(b)).To(Equal(fmt.Sprintf(`"%s"`, n.Format(f))))
		})

		It("unmarshals JSON", func() {
			t := schema.Time(time.Unix(time.Now().Unix(), 0)) // The precision of Time is 'second'
			b, err := json.Marshal(t)
			Expect(err).ToNot(HaveOccurred())

			var tt schema.Time
			err = tt.UnmarshalJSON(b)
			Expect(err).ToNot(HaveOccurred())
			Expect(tt).To(Equal(t))
		})