Esempio n. 1
0
func (tl *transactionEventLogger) logEvent(eventType string, resource *schema.Resource, version int64) error {
	schemaManager := schema.GetManager()
	eventSchema, ok := schemaManager.Schema("event")
	if !ok {
		return fmt.Errorf("event schema not found")
	}

	if resource.Schema().Metadata["nosync"] == true {
		log.Debug("skipping event logging for schema: %s", resource.Schema().ID)
		return nil
	}
	body, err := resource.JSONString()
	if err != nil {
		return fmt.Errorf("Error during event resource deserialisation: %s", err.Error())
	}
	eventResource, err := schema.NewResource(eventSchema, map[string]interface{}{
		"type":      eventType,
		"path":      resource.Path(),
		"version":   version,
		"body":      body,
		"timestamp": int64(time.Now().Unix()),
	})
	tl.eventLogged = true
	return tl.Transaction.Create(eventResource)
}
Esempio n. 2
0
			Expect(err).ToNot(HaveOccurred())
			Expect(tx.Create(networkResource)).To(Succeed())
			Expect(tx.Commit()).To(Succeed())
		})

		Describe("Updating state", func() {
			Context("Invoked correctly", func() {
				It("Should work", func() {
					possibleEvent = gohan_sync.Event{
						Action: "this is ignored here",
						Data: map[string]interface{}{
							"version": float64(1),
							"error":   "",
							"state":   "Ni malvarmetas",
						},
						Key: statePrefix + networkResource.Path(),
					}
					Expect(srv.StateUpdate(&possibleEvent, server)).To(Succeed())

					tx, err := wrappedTestDB.Begin()
					Expect(err).ToNot(HaveOccurred())
					defer tx.Close()
					afterState, err := tx.StateFetch(networkSchema, networkResource.ID(), nil)
					Expect(err).ToNot(HaveOccurred())
					Expect(tx.Commit()).To(Succeed())
					Expect(afterState.ConfigVersion).To(Equal(int64(1)))
					Expect(afterState.StateVersion).To(Equal(int64(1)))
					Expect(afterState.State).To(Equal("Ni malvarmetas"))
					Expect(afterState.Error).To(Equal(""))
					Expect(afterState.Monitoring).To(Equal(""))
				})
Esempio n. 3
0
				"shared":            false,
				"route_targets":     []string{"1000:10000", "2000:20000"},
				"providor_networks": map[string]interface{}{"segmentation_id": 10, "segmentation_type": "vlan"}}
			networkResource2, err = manager.LoadResource("network", network2)
			Expect(err).ToNot(HaveOccurred())

			subnet := map[string]interface{}{
				"id":          "subnetRed",
				"name":        "SubnetRed",
				"description": "A crimson subnet",
				"tenant_id":   "red",
				"cidr":        "10.0.0.0/24"}
			subnetResource, err = manager.LoadResource("subnet", subnet)
			Expect(err).ToNot(HaveOccurred())
			subnetResource.SetParentID("networkRed")
			Expect(subnetResource.Path()).To(Equal("/v2.0/subnets/subnetRed"))

			server := map[string]interface{}{
				"id":          "serverRed",
				"name":        "serverRed",
				"tenant_id":   "red",
				"network_id":  "networkRed",
				"description": "red server",
				"cidr":        "10.0.0.0/24"}
			serverResource, err = manager.LoadResource("server", server)
			Expect(err).ToNot(HaveOccurred())
		})

		JustBeforeEach(func() {
			os.Remove(conn)
			dataStore, err = db.ConnectDB(dbType, conn, db.DefaultMaxOpenConn)