Esempio n. 1
0
func (storageCassandra *StorageCassandra) LoadImageRecord(imageInformationName string, version string) (*ImageRecord, error) {
	session, err := cassandra.CassandraClient.GetSession()
	if err != nil {
		log.Error("Get session error %s", err)
		return nil, err
	}
	imageRecord := new(ImageRecord)
	var uuid gocql.UUID
	err = session.Query("SELECT image_information, version, path, version_info, environment, description, created_time FROM image_record WHERE image_information = ? AND version = ?", imageInformationName, version).Scan(
		&imageRecord.ImageInformation,
		&imageRecord.Version,
		&imageRecord.Path,
		&imageRecord.VersionInfo,
		&imageRecord.Environment,
		&imageRecord.Description,
		&uuid,
	)
	if err != nil {
		log.Error("Load ImageRecord %s version %s error: %s", imageInformationName, version, err)
		return nil, err
	} else {
		imageRecord.CreatedTime = uuid.Time()
		return imageRecord, nil
	}
}
Esempio n. 2
0
func (storageCassandra *StorageCassandra) LoadImageRecordWithImageInformationName(imageInformationName string) ([]ImageRecord, error) {
	session, err := cassandra.CassandraClient.GetSession()
	if err != nil {
		log.Error("Get session error %s", err)
		return nil, err
	}
	iter := session.Query("SELECT image_information, version, path, version_info, environment, description, created_time FROM image_record WHERE image_information = ?", imageInformationName).Iter()

	imageRecordSlice := make([]ImageRecord, 0)
	imageRecord := new(ImageRecord)
	var uuid gocql.UUID

	for iter.Scan(&imageRecord.ImageInformation, &imageRecord.Version, &imageRecord.Path, &imageRecord.VersionInfo, &imageRecord.Environment, &imageRecord.Description, &uuid) {
		imageRecord.CreatedTime = uuid.Time()
		imageRecordSlice = append(imageRecordSlice, *imageRecord)
		imageRecord = new(ImageRecord)
	}

	err = iter.Close()
	if err != nil {
		log.Error("Load ImageRecord %s error: %s", imageInformationName, err)
		return nil, err
	} else {
		return imageRecordSlice, nil
	}
}
Esempio n. 3
0
// Returns all oinks, from newest to oldest
func (r *CQLOinkRepo) All() ([]model.Oink, error) {
	r.lock.RLock()
	defer r.lock.RUnlock()
	if !r.initialized {
		return nil, errors.New("Uninitialized repo")
	}

	iter := r.session.Query(
		"SELECT id, content, created_at, handle FROM oinker.oinks "+
			"WHERE kind = ? ORDER BY created_at DESC",
		"oink",
	).Iter()
	var (
		id, content, handle string
		creationTime        gocql.UUID
	)
	oinks := make([]model.Oink, 0)
	for iter.Scan(&id, &content, &creationTime, &handle) {
		oink := model.Oink{
			ID:           id,
			Content:      content,
			CreationTime: creationTime.Time(),
			Handle:       handle,
		}
		oinks = append(oinks, oink)
	}
	if err := iter.Close(); err != nil {
		return nil, fmt.Errorf("Selecting oink (id: %s): %s", id, err)
	}

	return oinks, nil
}
Esempio n. 4
0
func (r *CQLOinkRepo) FindByID(id string) (model.Oink, bool, error) {
	r.lock.RLock()
	defer r.lock.RUnlock()
	if !r.initialized {
		return model.Oink{}, false, errors.New("Uninitialized repo")
	}

	iter := r.session.Query("SELECT content, created_at, handle FROM oinker.oinks WHERE id = ?", id).Iter()
	var (
		content      string
		creationTime gocql.UUID
		handle       string
	)
	oink := model.Oink{
		ID: id,
	}
	if iter.Scan(&content, &creationTime, &handle) {
		oink.Content = content
		oink.CreationTime = creationTime.Time()
		oink.Handle = handle
	}
	if err := iter.Close(); err != nil {
		return model.Oink{}, false, fmt.Errorf("Selecting oink (id: %s): %s", id, err)
	}

	return oink, false, nil
}
Esempio n. 5
0
func (r *CQLOinkRepo) FindByID(id string) (Oink, bool, error) {
	session, err := r.cluster.CreateSession()
	if err != nil {
		return Oink{}, false, fmt.Errorf("Creating CQL Session: %s", err)
	}
	defer session.Close()

	iter := session.Query("SELECT content, created_at, handle FROM oinks WHERE id = ?", id).Iter()
	var (
		content      string
		creationTime gocql.UUID
		handle       string
	)
	oink := Oink{
		ID: id,
	}
	if iter.Scan(&content, &creationTime, &handle) {
		oink.Content = content
		oink.CreationTime = creationTime.Time()
		oink.Handle = handle
	}
	if err := iter.Close(); err != nil {
		return Oink{}, false, fmt.Errorf("Selecting oink (id: %s): %s", id, err)
	}

	return oink, false, nil
}
Esempio n. 6
0
// Returns all oinks, from newest to oldest
func (r *CQLOinkRepo) All() ([]Oink, error) {
	session, err := r.cluster.CreateSession()
	if err != nil {
		return nil, fmt.Errorf("Creating CQL Session: %s", err)
	}
	defer session.Close()

	iter := session.Query(
		"SELECT id, content, created_at, handle FROM oinks "+
			"WHERE kind = ? ORDER BY created_at DESC",
		"oink",
	).Iter()
	var (
		id, content, handle string
		creationTime        gocql.UUID
	)
	oinks := make([]Oink, 0)
	for iter.Scan(&id, &content, &creationTime, &handle) {
		oink := Oink{
			ID:           id,
			Content:      content,
			CreationTime: creationTime.Time(),
			Handle:       handle,
		}
		oinks = append(oinks, oink)
	}
	if err := iter.Close(); err != nil {
		return nil, fmt.Errorf("Selecting oink (id: %s): %s", id, err)
	}

	return oinks, nil
}
Esempio n. 7
0
File: order.go Progetto: arkxu/cqlc
func main() {

	session := integration.TestSession("127.0.0.1", "cqlc")
	integration.Truncate(session, SIGNIFICANT_EVENTS)

	result := "FAILED"

	ctx := cqlc.NewContext()
	batch := gocql.NewBatch(gocql.LoggedBatch)

	events := 100

	var first, last gocql.UUID

	for i := 0; i < events; i++ {
		ts := gocql.TimeUUID()
		ctx.Upsert(SIGNIFICANT_EVENTS).
			SetInt64(SIGNIFICANT_EVENTS.SENSOR, 100).
			SetTimeUUID(SIGNIFICANT_EVENTS.TIMESTAMP, ts).
			SetInt32(SIGNIFICANT_EVENTS.SIGNIFICANCE, int32(i/10)).
			SetFloat32(SIGNIFICANT_EVENTS.TEMPERATURE, 19.8).
			SetInt32(SIGNIFICANT_EVENTS.PRESSURE, 357).
			Batch(batch)
		switch i {
		case 0:
			first = ts
		case events - 1:
			last = ts
		}
	}

	if err := session.ExecuteBatch(batch); err != nil {
		log.Fatalf("Could not execute batch: %v", err)
		os.Exit(1)
	}

	count, err := checkOrdering(session, SIGNIFICANT_EVENTS.TIMESTAMP)

	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	if count == events {

		count, err = checkOrdering(session, SIGNIFICANT_EVENTS.TIMESTAMP.Desc())

		if err != nil {
			log.Fatal(err)
			os.Exit(1)
		}

		if count == events {

			firstRead, err := checkOrderedLimit(session, SIGNIFICANT_EVENTS.TIMESTAMP, SIGNIFICANT_EVENTS.SIGNIFICANCE)
			if err != nil {
				log.Fatal(err)
				os.Exit(1)
			}

			lastRead, err := checkOrderedLimit(session, SIGNIFICANT_EVENTS.TIMESTAMP.Desc())
			if err != nil {
				log.Fatal(err)
				os.Exit(1)
			}

			if first == firstRead {
				if last == lastRead {
					result = "PASSED"
				} else {
					result = fmt.Sprintf("Expected last %v; got %v", last.Time(), lastRead.Time())
				}

			} else {
				result = fmt.Sprintf("Expected first %v; got %v", first.Time(), firstRead.Time())
			}
		}

	} else {
		result = fmt.Sprintf("Expected %d rows; got %d rows", events, count)
	}

	os.Stdout.WriteString(result)
}