コード例 #1
0
ファイル: listener.go プロジェクト: rancher/convoy-agent
func ConnectToEventStream(conf Config) error {
	convoy, err := volume.NewConvoyClient(conf.Socket)
	log.Infof("Socket file: %v", conf.Socket)
	if err != nil {
		return err
	}

	vdh := volumeRemoveHandler{
		convoyClient: convoy,
	}
	nh := noopHandler{}
	ph := PingHandler{}

	eventHandlers := map[string]revents.EventHandler{
		"storage.volume.activate":   nh.Handler,
		"storage.volume.deactivate": nh.Handler,
		"storage.volume.remove":     vdh.Handler,
		"ping":                      ph.Handler,
	}

	router, err := revents.NewEventRouter("", 0, conf.CattleURL, conf.CattleAccessKey, conf.CattleSecretKey, nil, eventHandlers, "", conf.WorkerCount)
	if err != nil {
		return err
	}
	err = router.StartWithoutCreate(nil)
	return err
}
コード例 #2
0
ファイル: test_server.go プロジェクト: rancher/convoy-agent
func init() {
	var err error
	convoy, err = volume.NewConvoyClient(socketFile)
	if err != nil {
		panic(fmt.Sprintf("ERROR [%v]. Could not connect to convoy", err))
	}
}
コード例 #3
0
ファイル: handler_test.go プロジェクト: rancher/convoy-agent
func (s *TestSuite) TestVolumeDelete(c *check.C) {
	convoyClient, err := volume.NewConvoyClient(testSock)
	if err != nil {
		c.Fatal(err)
	}

	handler := volumeRemoveHandler{
		convoyClient: convoyClient,
	}

	name := "handlertest"
	err = convoyClient.CreateVolume(name)
	if err != nil {
		c.Fatal(err)
	}
	vols, err := convoyClient.GetCurrVolumes()
	if err != nil {
		c.Fatal(err)
	}
	found := false
	for _, vol := range vols {
		if vol.Name == name {
			found = true
			break
		}
	}
	if !found {
		c.Fatalf("Volume %v was not created.", name)
	}

	event := &revents.Event{
		ReplyTo: "event-1",
		Id:      "event-id-1",
		Data: map[string]interface{}{
			"volumeStoragePoolMap": &map[string]interface{}{
				"volume": &map[string]interface{}{
					"name":      name,
					"id":        1,
					"accountId": 1,
				},
			},
		},
	}

	err = handler.Handler(event, s.mockRClient)
	if err != nil {
		c.Fatal(err)
	}
	pub := <-s.publishChan
	c.Assert(pub.Name, check.Equals, "event-1")
	c.Assert(pub.PreviousIds, check.DeepEquals, []string{"event-id-1"})
	c.Assert(len(pub.Data), check.Equals, 0)

	// Assert that the event running a second time does not fail.
	err = handler.Handler(event, s.mockRClient)
	if err != nil {
		c.Fatal(err)
	}
	pub = <-s.publishChan
	c.Assert(pub.Name, check.Equals, "event-1")
	c.Assert(pub.PreviousIds, check.DeepEquals, []string{"event-id-1"})
	c.Assert(len(pub.Data), check.Equals, 0)
}