Esempio n. 1
0
// Func NewApp OMIT
func NewApp() *App {
	a := &App{}
	a.keys = make(map[string]string)
	a.asyncManager = rest.NewAsyncHttpManager("/queue") // HL

	return a
}
Esempio n. 2
0
func NewApp(configIo io.Reader) *App {
	app := &App{}

	// Load configuration file
	app.conf = loadConfiguration(configIo)
	if app.conf == nil {
		return nil
	}

	// Setup asynchronous manager
	app.asyncManager = rest.NewAsyncHttpManager(ASYNC_ROUTE)

	// Setup executor
	switch {
	case app.conf.Executor == "mock":
		app.xo = mockexec.NewMockExecutor()
		app.executor = app.xo
	case app.conf.Executor == "ssh" || app.conf.Executor == "":
		app.executor = sshexec.NewSshExecutor(&app.conf.SshConfig)
	default:
		return nil
	}
	if app.executor == nil {
		return nil
	}
	logger.Info("Loaded %v executor", app.conf.Executor)

	// Set db is set in the configuration file
	if app.conf.DBfile != "" {
		dbfilename = app.conf.DBfile
	}

	// Setup BoltDB database
	var err error
	app.db, err = bolt.Open(dbfilename, 0600, &bolt.Options{Timeout: 3 * time.Second})
	if err != nil {
		logger.LogError("Unable to open database")
		return nil
	}

	err = app.db.Update(func(tx *bolt.Tx) error {
		// Create Cluster Bucket
		_, err := tx.CreateBucketIfNotExists([]byte(BOLTDB_BUCKET_CLUSTER))
		if err != nil {
			logger.LogError("Unable to create cluster bucket in DB")
			return err
		}

		// Create Node Bucket
		_, err = tx.CreateBucketIfNotExists([]byte(BOLTDB_BUCKET_NODE))
		if err != nil {
			logger.LogError("Unable to create cluster bucket in DB")
			return err
		}

		// Create Volume Bucket
		_, err = tx.CreateBucketIfNotExists([]byte(BOLTDB_BUCKET_VOLUME))
		if err != nil {
			logger.LogError("Unable to create cluster bucket in DB")
			return err
		}

		// Create Device Bucket
		_, err = tx.CreateBucketIfNotExists([]byte(BOLTDB_BUCKET_DEVICE))
		if err != nil {
			logger.LogError("Unable to create cluster bucket in DB")
			return err
		}

		// Create Brick Bucket
		_, err = tx.CreateBucketIfNotExists([]byte(BOLTDB_BUCKET_BRICK))
		if err != nil {
			logger.LogError("Unable to create cluster bucket in DB")
			return err
		}

		return nil

	})
	if err != nil {
		logger.Err(err)
		return nil
	}

	// Setup allocator
	switch {
	case app.conf.Allocator == "mock":
		app.allocator = NewMockAllocator(app.db)
	case app.conf.Allocator == "simple" || app.conf.Allocator == "":
		app.conf.Allocator = "simple"
		app.allocator = NewSimpleAllocatorFromDb(app.db)
	default:
		return nil
	}
	logger.Info("Loaded %v allocator", app.conf.Allocator)

	// Show application has loaded
	logger.Info("GlusterFS Application Loaded")

	return app
}