Esempio n. 1
0
// Cassandra Driver URL format:
// cassandra://host:port/keyspace
//
// Example:
// cassandra://localhost/SpaceOfKeys
func (driver *Driver) Initialize(rawurl string) error {
	u, err := url.Parse(rawurl)

	cluster := gocql.NewCluster(u.Host)
	cluster.Keyspace = u.Path[1:len(u.Path)]
	cluster.Consistency = gocql.All
	cluster.Timeout = 1 * time.Minute

	// Check if url user struct is null
	if u.User != nil {
		password, passwordSet := u.User.Password()

		if passwordSet == false {
			return fmt.Errorf("Missing password. Please provide password.")
		}

		cluster.Authenticator = gocql.PasswordAuthenticator{
			Username: u.User.Username(),
			Password: password,
		}

	}

	driver.session, err = cluster.CreateSession()

	if err != nil {
		return err
	}

	if err := driver.ensureVersionTableExists(); err != nil {
		return err
	}
	return nil
}
Esempio n. 2
0
File: etcd.go Progetto: fkasper/core
func (n *ng) buildDbCluster() error {
	dbEndpoints := n.path("cassandra", "hosts")

	var cassandraPool *cassandraPool
	err := n.getJSONVal(dbEndpoints, &cassandraPool)
	if err != nil {
		return err
	}

	log.Infof("===> Syncing up Migrations with the cluster")
	allErr, ok := migrate.UpSync("cassandra://"+cassandraPool.Nodes[0]+"/"+cassandraPool.Keyspace, "./migrations")
	if !ok {
		return allErr[0]
	}
	log.Infof("===> Migrations are in sync")
	log.Infof("===> Connecting to the database cluster")

	db := gocql.NewCluster(cassandraPool.Nodes...)
	db.Keyspace = cassandraPool.Keyspace
	db.NumConns = cassandraPool.NumConns
	db.DiscoverHosts = true
	db.Discovery = gocql.DiscoveryConfig{
		DcFilter:   "",
		RackFilter: "",
		Sleep:      30 * time.Second,
	}
	n.Database = db
	log.Infof("===> Connected to the database cluster")

	return nil
}
Esempio n. 3
0
File: main.go Progetto: fkasper/core
func main() {
	app := cli.NewApp()
	app.Name = "XTOOLS for SITREP"
	app.Usage = "Tools for the SITREP Server Environment"
	app.Commands = []cli.Command{
		{
			Name:    "index",
			Aliases: []string{"i"},
			Usage:   "Re-Index everything into Elasticsearch",
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "cassandra, c",
					Value: "127.0.0.1",
					Usage: "Cassandra Endpoint",
				},
				cli.StringFlag{
					Name:  "keyspace, k",
					Value: "sitrep_dev",
					Usage: "SITREP ENDPOINT",
				},
				cli.StringFlag{
					Name:  "elastichost, e",
					Value: "elasticsearch.dev.docker",
					Usage: "Elasticsearch Host",
				},
			},
			Action: func(c *cli.Context) {
				db := gocql.NewCluster(c.String("cassandra"))
				db.Keyspace = "sitrep_dev"
				db.DiscoverHosts = true
				db.Discovery = gocql.DiscoveryConfig{
					DcFilter:   "",
					RackFilter: "",
					Sleep:      30 * time.Second,
				}
				session, _ := db.CreateSession()
				defer session.Close()

				news := NewsRecord{}
				cl := elastigo.NewConn()
				cl.Domain = c.String("elastichost")

				iter := session.Query(`SELECT url, newsid, content, media, postedat, previewcontent, title FROM newsstoriestable`).Iter()
				for iter.Scan(&news.Url,
					&news.NewsId,
					&news.Content,
					&news.Media,
					&news.PostedAt,
					&news.PreviewContent,
					&news.Title) {
					item := &Record{
						Title:    news.Title,
						Preview:  news.PreviewContent,
						Image:    *news.Media["preview"],
						Link:     "/news/flobama/" + news.Url,
						Content:  news.Content,
						PostedAt: news.PostedAt,
						Media:    news.Media,
					}
					cl.Index("sites", "news", news.Url, nil, item)
					fmt.Println("Indexed:", news.Url)
				}
				if err := iter.Close(); err != nil {
					log.Errorf(err.Error())
				}
				page := IntellipediaPage{}
				iter2 := session.Query(`SELECT url, content, image, mapimg, name FROM intellipediapagestable`).Iter()
				for iter2.Scan(&page.Url,
					&page.Content,
					&page.Image,
					&page.PreviewContent,
					&page.Title) {
					item := &Record{
						Title:   page.Title,
						Preview: page.PreviewContent,
						Image:   page.Image,
						Link:    "/intellipedia/" + page.Url,
						Content: page.Content,
					}
					cl.Index("sites", "intellipedia", page.Url, nil, item)
					fmt.Println("Indexed:", page.Url)
				}
				if err := iter2.Close(); err != nil {
					log.Errorf(err.Error())
				}
				site := SocialSite{}
				iter3 := session.Query(`SELECT name, link, tile FROM categoriestable`).Iter()
				for iter3.Scan(&site.Name,
					&site.Link,
					&site.Tile) {
					item := &Record{
						Title:   site.Name,
						Preview: "",
						Image:   site.Tile,
						Link:    site.Link,
					}
					cl.Index("sites", "sites", strings.Replace(site.Name, " ", "-", -1), nil, item)
					fmt.Println("Indexed:", site.Name)
				}
				if err := iter3.Close(); err != nil {
					log.Errorf(err.Error())
				}
			},
		},
		{
			Name:    "complete",
			Aliases: []string{"c"},
			Usage:   "complete a task on the list",
			Action: func(c *cli.Context) {
				println("completed task: ", c.Args().First())
			},
		},
		{
			Name:    "template",
			Aliases: []string{"r"},
			Usage:   "options for task templates",
			Subcommands: []cli.Command{
				{
					Name:  "add",
					Usage: "add a new template",
					Action: func(c *cli.Context) {
						println("new task template: ", c.Args().First())
					},
				},
				{
					Name:  "remove",
					Usage: "remove an existing template",
					Action: func(c *cli.Context) {
						println("removed task template: ", c.Args().First())
					},
				},
			},
		},
	}

	app.Run(os.Args)
}