func init() { cluster = gocql.NewCluster("127.0.0.1") // uncomment the following two lines if you want to use Cassandra 1.2 // cluster.ProtoVersion = 1 // cluster.CQLVersion = "3.0.0" session, _ = cluster.CreateSession() }
func fetchCards() (card CardPerso) { card = CardPerso{} cardInfo := Persod{} // connect to the cluster cluster := gocql.NewCluster(cassandraAddress) cluster.Keyspace = keyspaceName cluster.Consistency = gocql.One cluster.ProtoVersion = 1 session, err := cluster.CreateSession() if err != nil { log.Fatal(err) } defer session.Close() iter := session.Query(walletDataQuery).Iter() for iter.Scan(&cardInfo.WalletId, &cardInfo.DeviceProfileId, &cardInfo.SeProfileId, &cardInfo.AppletInstanceProfiles, &cardInfo.DeviceProfile, &cardInfo.IssuerId, &cardInfo.PackageProfiles, &cardInfo.RegistrationStatus, &cardInfo.RestrictedAids, &cardInfo.SdProfileId, &cardInfo.SecurityDomainServiceendPtnId, &cardInfo.SeProfile) { cardInfo.AppletJson = copyMapToJson(cardInfo.AppletInstanceProfiles) log.Printf("AppletInstanceProfiles = %s", cardInfo.AppletJson) cardInfo.PackageJson = copyMapToJson(cardInfo.PackageProfiles) log.Printf("%s", cardInfo.PackageJson) card.Perso = append(card.Perso, cardInfo) } if err := iter.Close(); err != nil { log.Fatal("scan problem:", err) } return card }
// NewQueueManager constructs a new QueueManager with a given name and // configuration. The QueueManagerConfig is copied by value, so attempts to // mutate a configuration already passed to NewQueueManager will have no // effect. func NewQueueManager(name string, config QueueManagerConfig) (*QueueManager, error) { cassCluster := gocql.NewCluster(config.CassandraHosts...) cassCluster.Keyspace = config.CassandraKeyspace cassSession, err := cassCluster.CreateSession() if err != nil { return nil, err } mgr := &QueueManager{ Name: name, config: config, writers: make(map[string]*queueWriter), db: cassSession, done: &sync.WaitGroup{}, stopKeepAlive: make(chan bool), } go mgr.keepAlive() return mgr, nil }
func main() { // Command line Args var ip = flag.String("c", "127.0.0.1", "IP address of Cluster") var ks = flag.String("k", "stress_keyspace", "Keyspace for stress (will be created if it does not exist)") var table = flag.String("t", "stress_table", "Table for stress (will be created if it does not exist)") var num_ops = flag.Int("n", 1000000, "Number of operations to preform") var parallel = flag.Int("p", 40, "Number of Parallel Operations") flag.Parse() fmt.Println("IP:", *ip) // connect to the cluster cluster := gocql.NewCluster(*ip) session, err := cluster.CreateSession() if err != nil { panic(fmt.Sprintf("Could not create Session: %v", err)) } defer session.Close() createks(session, *ks, *table) fmt.Println("Queing up Operations") go stress(*num_ops) for p := 0; p < *parallel; p++ { go insert(session) } // start selectors put a for loop here //go select(session, ops_select, done) c_done := 0 for x := range done { fmt.Println(x) c_done++ fmt.Println(c_done) if c_done == *parallel { close(done) } } }
//This test checks to make sure a valid error and a nil reference to //a session are returned when an empty array of hosts are provided //to the cluster configuration func TestEmptyHosts() error { empty := make([]string, 0) cfg := gocql.NewCluster(empty...) _, err := cfg.CreateSession() return err }
func Init() { cluster := c.NewCluster("127.0.0.1") cluster.Keyspace = "mykeyspace" cluster.Consistency = c.One Cl = cluster }
func main() { var in *os.File var err error var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") var event_file = flag.String("event_file", "", "event file") flag.Parse() if *event_file == "" { panic("must pass an event file") } if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { panic(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } init_globals() fmt.Printf("Opening event file %s....\n", *event_file) if in, err = os.Open(*event_file); err != nil { panic(err) } // connect to the cluster cluster := gocql.NewCluster("10.168.16.195", "10.168.16.196") cluster.Keyspace = "logs_ks" cluster.Consistency = gocql.Quorum session, _ := cluster.CreateSession() defer session.Close() scanner := bufio.NewScanner(in) line := "" var parts []string line_num := 0 var batch *gocql.Batch rowdata := make([]interface{}, len(columns)) for scanner.Scan() { line = scanner.Text() line_num++ parts = strings.SplitN(line, "\t", 7) if len(parts) != 7 { log.Printf("Bad line %d in event file: %s\n", line_num, *event_file) continue } if batch == nil { batch = gocql.NewBatch(gocql.LoggedBatch) } col_idx := 0 var val_fl float64 var val_bl bool var val_int int var ts time.Time for _, k := range columns { switch logfile_spec[k].data_type { case "integer": val_int, err = strconv.Atoi(parts[logfile_spec[k].indx]) if err == nil { val_int = 0 } rowdata[col_idx] = val_int case "float": val_fl, err = strconv.ParseFloat(parts[logfile_spec[k].indx], 32) if err == nil { val_fl = 0.0 } rowdata[col_idx] = float32(val_fl) case "boolean": val_bl, err = strconv.ParseBool(parts[logfile_spec[k].indx]) if err == nil { val_bl = false } rowdata[col_idx] = val_bl case "timestamp": // Reference MAGIC time: Mon Jan 2 15:04:05 -0700 MST 2006 ts, err = time.Parse("20060102150405", parts[logfile_spec[k].indx]) if err != nil { log.Printf("Bad time in line %d in event file: %s\n", line_num, *event_file) continue // can't make fake timestamp } rowdata[col_idx] = ts default: // strings varchar / ascii etc rowdata[col_idx] = parts[logfile_spec[k].indx] } col_idx += 1 } //log.Printf("parts = %v", parts) //log.Printf("rowdata = %v", rowdata) batch.Query(insert_query1, rowdata...) batch_count := len(batch.Entries) if batch_count >= 2000 { if err := session.ExecuteBatch(batch); err != nil { log.Printf("Failed to execute batch: %v", err) } batch = nil log.Printf("Done with batch of %d", batch_count) } } if batch != nil && len(batch.Entries) > 0 { batch_count := len(batch.Entries) if err := session.ExecuteBatch(batch); err != nil { log.Printf("Failed to execute batch: %v", err) } batch = nil log.Printf("Done with batch of %d", batch_count) } in.Close() }