예제 #1
0
파일: queue.go 프로젝트: 4eek/tsuru
func (t *runBs) Run(job monsterqueue.Job) {
	params := job.Parameters()
	dockerEndpoint := params["endpoint"].(string)
	machineID := params["machine"].(string)
	node := cluster.Node{Address: dockerEndpoint}
	err := t.waitDocker(dockerEndpoint)
	if err != nil {
		job.Error(err)
		t.destroyMachine(machineID)
		return
	}
	rawMetadata := params["metadata"].(monsterqueue.JobParams)
	metadata := make(map[string]string, len(rawMetadata))
	for key, value := range rawMetadata {
		metadata[key] = value.(string)
	}
	err = CreateContainer(dockerEndpoint, metadata["pool"], t.provisioner, true)
	if err != nil {
		node.CreationStatus = cluster.NodeCreationStatusError
		node.Metadata = map[string]string{"creationError": err.Error()}
		t.provisioner.Cluster().UpdateNode(node)
		job.Error(err)
		t.destroyMachine(machineID)
		return
	}
	node.CreationStatus = cluster.NodeCreationStatusCreated
	_, err = t.provisioner.Cluster().UpdateNode(node)
	if err != nil {
		job.Error(err)
		t.destroyMachine(machineID)
		return
	}
	job.Success(nil)
}
예제 #2
0
func (t *runBs) Run(job monsterqueue.Job) {
	params := job.Parameters()
	dockerEndpoint := params["endpoint"].(string)
	node := cluster.Node{Address: dockerEndpoint}
	err := t.waitDocker(dockerEndpoint)
	if err != nil {
		job.Error(err)
		return
	}
	node.CreationStatus = cluster.NodeCreationStatusCreated
	rawMetadata := params["metadata"].(monsterqueue.JobParams)
	metadata := make(map[string]string, len(rawMetadata))
	for key, value := range rawMetadata {
		metadata[key] = value.(string)
	}
	err = createContainer(dockerEndpoint, metadata["pool"], t.provisioner, true)
	if err != nil {
		t.provisioner.Cluster().UpdateNode(node)
		job.Error(err)
		return
	}
	node.Metadata = map[string]string{"LastSuccess": time.Now().Format(time.RFC3339)}
	_, err = t.provisioner.Cluster().UpdateNode(node)
	if err != nil {
		job.Error(err)
		return
	}
	job.Success(nil)
}
예제 #3
0
func TestUpdateNodeDoesNotExist(t *testing.T) {
	mongo, err := mongodb.Mongodb("mongodb://localhost:27017", "test-docker-node-update")
	if err != nil {
		t.Fatal(err)
	}
	clu, err := cluster.New(nil, mongo)
	if err != nil {
		t.Fatal(err)
	}
	node := cluster.Node{Address: "http://localhost:4243"}
	err = clu.Register(node)
	defer clu.Unregister("http://localhost:4243")
	nodeUpd := cluster.Node{Address: "http://localhost:4223"}
	nodeUpd.Metadata = map[string]string{"k1": "v1", "k2": "v2"}
	nodeUpd, err = clu.UpdateNode(nodeUpd)
	if err != storage.ErrNoSuchNode {
		t.Error("Expected: No such node in storage, got: ", err)
	}
}