Beispiel #1
0
func (rg *RecordGenerator) taskContextRecord(ctx context, task state.Task, f state.Framework, domain string, spec labels.Func, enumTask *EnumerableTask) {
	fname := labels.DomainFrag(f.Name, labels.Sep, spec)

	tail := "." + domain + "."

	// insert canonical A records
	canonical := ctx.taskName + "-" + ctx.taskID + "-" + ctx.slaveID + "." + fname
	arec := ctx.taskName + "." + fname

	rg.insertTaskRR(arec+tail, ctx.taskIP, A, enumTask)
	rg.insertTaskRR(canonical+tail, ctx.taskIP, A, enumTask)

	rg.insertTaskRR(arec+".slave"+tail, ctx.slaveIP, A, enumTask)
	rg.insertTaskRR(canonical+".slave"+tail, ctx.slaveIP, A, enumTask)

	// recordName generates records for ctx.taskName, given some generation chain
	recordName := func(gen chain) { gen("_" + ctx.taskName) }

	// asSRV is always the last link in a chain, it must insert RR's
	asSRV := func(target string) chain {
		return func(records ...string) {
			for i := range records {
				name := records[i] + tail
				rg.insertTaskRR(name, target, SRV, enumTask)
			}
		}
	}

	// Add RFC 2782 SRV records
	var subdomains []string
	if task.HasDiscoveryInfo() {
		subdomains = []string{"slave"}
	} else {
		subdomains = []string{"slave", domainNone}
	}

	slaveHost := canonical + ".slave" + tail
	for _, port := range task.Ports() {
		slaveTarget := slaveHost + ":" + port
		recordName(withProtocol(protocolNone, fname, spec,
			withSubdomains(subdomains, asSRV(slaveTarget))))
	}

	if !task.HasDiscoveryInfo() {
		return
	}

	for _, port := range task.DiscoveryInfo.Ports.DiscoveryPorts {
		target := canonical + tail + ":" + strconv.Itoa(port.Number)
		recordName(withProtocol(port.Protocol, fname, spec,
			withNamedPort(port.Name, spec, asSRV(target))))
	}
}
Beispiel #2
0
// frameworkRecords injects A and SRV records into the generator store:
//     frameworkname.domain.                 // resolves to IPs of each framework
//     _framework._tcp.frameworkname.domain. // resolves to the driver port and IP of each framework
func (rg *RecordGenerator) frameworkRecords(sj state.State, domain string, spec labels.Func) {
	for _, f := range sj.Frameworks {
		fname := labels.DomainFrag(f.Name, labels.Sep, spec)
		host, port := f.HostPort()
		if address, ok := hostToIP4(host); ok {
			a := fname + "." + domain + "."
			rg.insertRR(a, address, "A")
			if port != "" {
				srv := net.JoinHostPort(a, port)
				rg.insertRR("_framework._tcp."+a, srv, "SRV")
			}
		}
	}
}
Beispiel #3
0
// slaveRecords injects A and SRV records into the generator store:
//     slave.domain.      // resolves to IPs of all slaves
//     _slave._tc.domain. // resolves to the driver port and IP of all slaves
func (rg *RecordGenerator) slaveRecords(sj state.State, domain string, spec labels.Func) {
	for _, slave := range sj.Slaves {
		address, ok := hostToIP4(slave.PID.Host)
		if ok {
			a := "slave." + domain + "."
			rg.insertRR(a, address, "A")
			srv := net.JoinHostPort(a, slave.PID.Port)
			rg.insertRR("_slave._tcp."+domain+".", srv, "SRV")
		} else {
			logging.VeryVerbose.Printf("string '%q' for slave with id %q is not a valid IP address", address, slave.ID)
			address = labels.DomainFrag(address, labels.Sep, spec)
		}
		rg.SlaveIPs[slave.ID] = address
	}
}
Beispiel #4
0
func (rg *RecordGenerator) taskRecords(sj state.State, domain string, spec labels.Func) {
	for _, f := range sj.Frameworks {
		fname := labels.DomainFrag(f.Name, labels.Sep, spec)

		// insert taks records
		tail := fname + "." + domain + "."
		for _, task := range f.Tasks {
			hostIP, ok := rg.SlaveIPs[task.SlaveID]

			// skip not running or not discoverable tasks
			if !ok || (task.State != "TASK_RUNNING") {
				continue
			}

			ctx := struct{ TaskName, TaskID, SlaveID string }{
				spec(task.Name), hashString(task.ID), slaveIDTail(task.SlaveID),
			}

			// insert canonical A records
			trec := ctx.TaskName + "-" + ctx.TaskID + "-" + ctx.SlaveID + "." + tail
			arec := ctx.TaskName + "." + tail
			containerIP := task.ContainerIP()
			rg.insertRR(arec, hostIP, "A")
			rg.insertRR(trec, hostIP, "A")
			if containerIP != "" {
				rg.insertRR("_container."+arec, containerIP, "A")
				rg.insertRR("_container."+trec, containerIP, "A")
			}

			// Add RFC 2782 SRV records
			for _, port := range task.Ports() {
				srvHost := trec + ":" + port
				tcp := "_" + ctx.TaskName + "._tcp." + tail
				udp := "_" + ctx.TaskName + "._udp." + tail
				rg.insertRR(tcp, srvHost, "SRV")
				rg.insertRR(udp, srvHost, "SRV")
			}
		}
	}
}
Beispiel #5
0
func (rg *RecordGenerator) taskRecords(sj state.State, domain string, spec labels.Func, ipSources []string) {
	for _, f := range sj.Frameworks {
		fname := labels.DomainFrag(f.Name, labels.Sep, spec)

		// insert taks records
		tail := "." + domain + "."
		for _, task := range f.Tasks {
			var ok bool
			task.SlaveIP, ok = rg.SlaveIPs[task.SlaveID]

			// skip not running or not discoverable tasks
			if !ok || (task.State != "TASK_RUNNING") {
				continue
			}

			// define context
			ctx := struct{ taskName, taskID, slaveID, taskIP, slaveIP string }{
				spec(task.Name),
				hashString(task.ID),
				slaveIDTail(task.SlaveID),
				task.IP(ipSources...),
				task.SlaveIP,
			}

			// use DiscoveryInfo name if defined instead of task name
			if task.HasDiscoveryInfo() {
				ctx.taskName = task.DiscoveryInfo.Name
			}

			// insert canonical A records
			canonical := ctx.taskName + "-" + ctx.taskID + "-" + ctx.slaveID + "." + fname
			arec := ctx.taskName + "." + fname

			rg.insertRR(arec+tail, ctx.taskIP, "A")
			rg.insertRR(canonical+tail, ctx.taskIP, "A")

			rg.insertRR(arec+".slave"+tail, ctx.slaveIP, "A")
			rg.insertRR(canonical+".slave"+tail, ctx.slaveIP, "A")

			// Add RFC 2782 SRV records
			slaveHost := canonical + ".slave" + tail
			tcpName := "_" + ctx.taskName + "._tcp." + fname
			udpName := "_" + ctx.taskName + "._udp." + fname
			for _, port := range task.Ports() {
				slaveTarget := slaveHost + ":" + port

				if !task.HasDiscoveryInfo() {
					rg.insertRR(tcpName+tail, slaveTarget, "SRV")
					rg.insertRR(udpName+tail, slaveTarget, "SRV")
				}

				rg.insertRR(tcpName+".slave"+tail, slaveTarget, "SRV")
				rg.insertRR(udpName+".slave"+tail, slaveTarget, "SRV")
			}

			if !task.HasDiscoveryInfo() {
				continue
			}

			for _, port := range task.DiscoveryInfo.Ports.DiscoveryPorts {
				target := canonical + tail + ":" + strconv.Itoa(port.Number)

				// use protocol if defined, fallback to tcp+udp
				proto := spec(port.Protocol)
				if proto != "" {
					name := "_" + ctx.taskName + "._" + proto + "." + fname
					rg.insertRR(name+tail, target, "SRV")
				} else {
					rg.insertRR(tcpName+tail, target, "SRV")
					rg.insertRR(udpName+tail, target, "SRV")
				}
			}
		}
	}
}