Esempio n. 1
0
// Retrieve an individual applicants data.
func (m *MembershipDB) GetMembershipRequest(id, table, prefix string) (*MembershipAgreement, int64, error) {
	var uuid cassandra.UUID
	var member *MembershipAgreement = new(MembershipAgreement)
	var cp *cassandra.ColumnPath = cassandra.NewColumnPath()
	var r *cassandra.ColumnOrSuperColumn
	var err error

	if uuid, err = cassandra.ParseUUID(id); err != nil {
		return nil, 0, err
	}

	cp.ColumnFamily = table
	cp.Column = []byte("pb_data")

	// Retrieve the protobuf with all data from Cassandra.
	r, err = m.conn.Get(
		append([]byte(prefix), []byte(uuid)...),
		cp, cassandra.ConsistencyLevel_ONE)
	if err != nil {
		return nil, 0, err
	}

	// Decode the protobuf which was written to the column.
	err = proto.Unmarshal(r.Column.Value, member)
	return member, *r.Column.Timestamp, err
}
Esempio n. 2
0
func main() {
	var uuid cassandra.UUID
	var conn *cassandra.RetryCassandraClient
	var r *cassandra.ColumnOrSuperColumn
	var cp *cassandra.ColumnPath
	var err error

	var uuid_str, dbserver, dbname, columnfamily, column string

	flag.StringVar(&uuid_str, "uuid-string", "",
		"UUID string to look at")
	flag.StringVar(&dbserver, "cassandra-server", "localhost:9160",
		"Database server to look at")
	flag.StringVar(&dbname, "dbname", "sfmembersys",
		"Database name to look at")
	flag.StringVar(&columnfamily, "column-family", "",
		"Column family to look at")
	flag.StringVar(&column, "column-name", "",
		"Column name to look at")
	flag.Parse()

	uuid, err = cassandra.ParseUUID(uuid_str)
	if err != nil {
		log.Fatal(err)
	}

	conn, err = cassandra.NewRetryCassandraClient(dbserver)
	if err != nil {
		log.Fatal(err)
	}

	err = conn.SetKeyspace(dbname)
	if err != nil {
		log.Fatal(err)
	}

	cp = cassandra.NewColumnPath()
	cp.ColumnFamily = columnfamily
	cp.Column = []byte(column)

	r, err = conn.Get([]byte(uuid), cp,
		cassandra.ConsistencyLevel_ONE)
	if err != nil {
		log.Fatal(err)
	}

	log.Print(r.Column.Name, ": ", r.Column.Value, " (",
		r.Column.Timestamp, ")")
}
Esempio n. 3
0
// Retrieve a specific members detailed membership data.
func (m *MembershipDB) GetMemberDetail(id string) (*MembershipAgreement, error) {
	var member *MembershipAgreement = new(MembershipAgreement)
	var cp *cassandra.ColumnPath = cassandra.NewColumnPath()
	var r *cassandra.ColumnOrSuperColumn
	var err error

	cp.ColumnFamily = "members"
	cp.Column = []byte("pb_data")

	// Retrieve the protobuf with all data from Cassandra.
	r, err = m.conn.Get(
		append([]byte(memberPrefix), []byte(id)...),
		cp, cassandra.ConsistencyLevel_ONE)
	if err != nil {
		return nil, err
	}

	// Decode the protobuf which was written to the column.
	err = proto.Unmarshal(r.Column.Value, member)
	return member, err
}
Esempio n. 4
0
// Move a member record to the queue for getting their user account removed
// (e.g. when they leave us). Set the retention to 2 years instead of just
// 6 months, since they have been a member.
func (m *MembershipDB) MoveMemberToTrash(id, initiator, reason string) error {
	var now time.Time = time.Now()
	var now_long uint64 = uint64(now.Unix())
	var uuid cassandra.UUID
	var mmap map[string]map[string][]*cassandra.Mutation
	var member *MembershipAgreement

	var cp *cassandra.ColumnPath = cassandra.NewColumnPath()
	var cos *cassandra.ColumnOrSuperColumn
	var del *cassandra.Deletion = cassandra.NewDeletion()
	var mu *cassandra.Mutation
	var ts int64

	var err error

	cp.ColumnFamily = "members"
	cp.Column = []byte("pb_data")

	uuid, err = cassandra.GenTimeUUID(&now)
	if err != nil {
		return err
	}

	cos, err = m.conn.Get(
		[]byte(memberPrefix+id), cp, cassandra.ConsistencyLevel_QUORUM)
	if err != nil {
		return err
	}

	member = new(MembershipAgreement)
	err = proto.Unmarshal(cos.Column.Value, member)
	if err != nil {
		return err
	}

	del.Predicate = cassandra.NewSlicePredicate()
	del.Predicate.ColumnNames = allColumns
	del.Timestamp = cos.Column.Timestamp

	mu = cassandra.NewMutation()
	mu.Deletion = del

	mmap = make(map[string]map[string][]*cassandra.Mutation)
	mmap[memberPrefix+id] = make(map[string][]*cassandra.Mutation)
	mmap[memberPrefix+id]["members"] = []*cassandra.Mutation{mu}

	member.Metadata.GoodbyeInitiator = &initiator
	member.Metadata.GoodbyeTimestamp = &now_long
	member.Metadata.GoodbyeReason = &reason

	ts = now.UnixNano()
	cos.Column = cassandra.NewColumn()
	cos.Column.Name = []byte("pb_data")
	cos.Column.Timestamp = &ts
	cos.Column.Value, err = proto.Marshal(member)
	if err != nil {
		return err
	}

	mu = cassandra.NewMutation()
	mu.ColumnOrSupercolumn = cos

	mmap[dequeuePrefix+id] = make(map[string][]*cassandra.Mutation)
	mmap[dequeuePrefix+string([]byte(uuid))] =
		make(map[string][]*cassandra.Mutation)
	mmap[dequeuePrefix+string([]byte(uuid))]["membership_dequeue"] =
		[]*cassandra.Mutation{mu}

	err = m.conn.AtomicBatchMutate(
		mmap, cassandra.ConsistencyLevel_QUORUM)
	return err
}
Esempio n. 5
0
// Update the membership fee for the given user.
func (m *MembershipDB) SetMemberFee(id string, fee uint64, yearly bool) error {
	var now time.Time = time.Now()
	var mmap map[string]map[string][]*cassandra.Mutation
	var member *MembershipAgreement = new(MembershipAgreement)
	var cp *cassandra.ColumnPath = cassandra.NewColumnPath()
	var r *cassandra.ColumnOrSuperColumn

	var mu *cassandra.Mutation = cassandra.NewMutation()
	var ts int64 = now.UnixNano()
	var bdata []byte
	var err error

	cp.ColumnFamily = "members"
	cp.Column = []byte("pb_data")

	// Retrieve the protobuf with all data from Cassandra.
	r, err = m.conn.Get(
		append([]byte(memberPrefix), []byte(id)...),
		cp, cassandra.ConsistencyLevel_ONE)
	if err != nil {
		return err
	}

	// Decode the protobuf which was written to the column.
	err = proto.Unmarshal(r.Column.Value, member)
	if err != nil {
		return err
	}

	member.MemberData.Fee = &fee
	member.MemberData.FeeYearly = &yearly

	r.Column.Value, err = proto.Marshal(member)
	r.Column.Timestamp = &ts

	mmap = make(map[string]map[string][]*cassandra.Mutation)
	mmap[memberPrefix+id] = make(map[string][]*cassandra.Mutation)
	mmap[memberPrefix+id]["members"] = make([]*cassandra.Mutation, 0)

	mu.ColumnOrSupercolumn = cassandra.NewColumnOrSuperColumn()
	mu.ColumnOrSupercolumn.Column = r.Column
	mmap[memberPrefix+id]["members"] = append(
		mmap[memberPrefix+id]["members"], mu)

	bdata = make([]byte, 8)
	binary.BigEndian.PutUint64(bdata, fee)
	mu = newCassandraMutationBytes("fee", bdata, &now, 0)
	mmap[memberPrefix+id]["members"] = append(
		mmap[memberPrefix+id]["members"], mu)

	bdata = make([]byte, 1)
	if yearly {
		bdata[0] = 1
	} else {
		bdata[0] = 0
	}
	mu = newCassandraMutationBytes("fee_yearly", bdata, &now, 0)
	mmap[memberPrefix+id]["members"] = append(
		mmap[memberPrefix+id]["members"], mu)

	return m.conn.AtomicBatchMutate(
		mmap, cassandra.ConsistencyLevel_QUORUM)
}