예제 #1
0
파일: etcd.go 프로젝트: ycaille/gru
// Processes new tasks
func (m *etcdMinion) processTask(t *task.Task) error {
	defer func() {
		t.TimeProcessed = time.Now().Unix()
		m.SaveTaskResult(t)
	}()

	// Sync the module and data files, then process the task
	err := m.Sync()
	if err != nil {
		msg := fmt.Sprintf("Unable to sync site directory: %s\n", err)
		log.Printf(msg)
		t.State = task.TaskStateSkipped
		t.Result = msg
		return err
	}

	// Switch to the specified environment
	if err := m.setEnvironment(t.Environment); err != nil {
		msg := fmt.Sprintf("Unable to set environment: %s\n", err)
		log.Printf(msg)
		t.State = task.TaskStateSkipped
		t.Result = msg
		return err
	}

	t.State = task.TaskStateProcessing
	m.SaveTaskResult(t)

	// Create the catalog and process it
	var buf bytes.Buffer

	L := lua.NewState()
	defer L.Close()

	config := &catalog.Config{
		Module:   t.Command,
		DryRun:   t.DryRun,
		Logger:   log.New(&buf, "", log.LstdFlags),
		SiteRepo: m.gitRepo.Path,
		L:        L,
	}

	katalog := catalog.New(config)
	if err := katalog.Load(); err != nil {
		t.State = task.TaskStateUnknown
		t.Result = err.Error()
		return err
	}

	err = katalog.Run()
	t.Result = buf.String()

	if err != nil {
		t.State = task.TaskStateFailed
	} else {
		t.State = task.TaskStateSuccess
	}

	return err
}
예제 #2
0
파일: apply.go 프로젝트: ycaille/gru
// Executes the "apply" command
func execApplyCommand(c *cli.Context) error {
	if len(c.Args()) < 1 {
		return cli.NewExitError(errNoModuleName.Error(), 64)
	}

	L := lua.NewState()
	defer L.Close()
	config := &catalog.Config{
		Module:   c.Args()[0],
		DryRun:   c.Bool("dry-run"),
		Logger:   resource.DefaultLogger,
		SiteRepo: c.String("siterepo"),
		L:        L,
	}

	katalog := catalog.New(config)
	if err := katalog.Load(); err != nil {
		if err != nil {
			return cli.NewExitError(err.Error(), 1)
		}
	}

	if err := katalog.Run(); err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	return nil
}
예제 #3
0
파일: graph.go 프로젝트: dnaeon/gru
// Executes the "graph" command
func execGraphCommand(c *cli.Context) error {
	if len(c.Args()) < 1 {
		return cli.NewExitError(errNoModuleName.Error(), 64)
	}

	L := lua.NewState()
	defer L.Close()

	module := c.Args()[0]
	config := &catalog.Config{
		Module:   module,
		DryRun:   true,
		Logger:   log.New(os.Stdout, "", log.LstdFlags),
		SiteRepo: c.String("siterepo"),
		L:        L,
	}

	katalog := catalog.New(config)
	resource.LuaRegisterBuiltin(L)
	if err := L.DoFile(module); err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	collection, err := resource.CreateCollection(katalog.Unsorted)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	g, err := collection.DependencyGraph()
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	g.AsDot("resources", os.Stdout)
	g.Reversed().AsDot("reversed", os.Stdout)

	sorted, err := g.Sort()
	if err == graph.ErrCircularDependency {
		circular := graph.New()
		circular.AddNode(sorted...)
		circular.AsDot("circular", os.Stdout)
		return cli.NewExitError(graph.ErrCircularDependency.Error(), 1)
	}

	return nil
}
예제 #4
0
파일: apply.go 프로젝트: dnaeon/gru
// Executes the "apply" command
func execApplyCommand(c *cli.Context) error {
	if len(c.Args()) < 1 {
		return cli.NewExitError(errNoModuleName.Error(), 64)
	}

	concurrency := c.Int("concurrency")
	if concurrency < 0 {
		concurrency = runtime.NumCPU()
	}

	L := lua.NewState()
	defer L.Close()

	logger := log.New(os.Stdout, "", log.LstdFlags)

	config := &catalog.Config{
		Module:      c.Args()[0],
		DryRun:      c.Bool("dry-run"),
		Logger:      logger,
		SiteRepo:    c.String("siterepo"),
		L:           L,
		Concurrency: concurrency,
	}

	katalog := catalog.New(config)
	if err := katalog.Load(); err != nil {
		if err != nil {
			return cli.NewExitError(err.Error(), 1)
		}
	}

	status := katalog.Run()
	status.Summary(logger)

	return nil
}