コード例 #1
0
ファイル: node.go プロジェクト: sanmiguel/riak-mesos
func (frn *FrameworkRiakNode) ApplyReservedOffer(offerHelper *common.OfferHelper, sc *SchedulerCore) bool {
	taskAsk := []*mesos.Resource{}
	execAsk := []*mesos.Resource{}
	if sc.compatibilityMode {
		if !offerHelper.CanFitUnreserved(frn.Cpus+CPUS_PER_EXECUTOR, frn.Mem+MEM_PER_EXECUTOR, frn.Disk, frn.Ports) {
			return false
		}
		taskAsk = offerHelper.ApplyUnreserved(frn.Cpus, frn.Mem, frn.Disk, frn.Ports)
		execAsk = offerHelper.ApplyUnreserved(CPUS_PER_EXECUTOR, MEM_PER_EXECUTOR, 0, 0)
	} else {
		if !offerHelper.CanFitReserved(frn.Cpus, frn.Mem, frn.Disk, 0) ||
			!offerHelper.CanFitUnreserved(CPUS_PER_EXECUTOR, MEM_PER_EXECUTOR, 0, frn.Ports) {
			return false
		}
		taskAsk = offerHelper.ApplyReserved(frn.Cpus, frn.Mem, frn.Disk, 0, *frn.Principal, *frn.Role, frn.PersistenceID(), frn.ContainerPath)
		taskAsk = append(taskAsk, offerHelper.ApplyUnreserved(0, 0, 0, frn.Ports)...)
		execAsk = offerHelper.ApplyUnreserved(CPUS_PER_EXECUTOR, MEM_PER_EXECUTOR, 0, 0)
	}

	log.Infof("Found an offer for a launchable node. OfferID: %+v, NodeID: %+v", offerHelper.OfferIDStr, frn.CurrentID())

	frn.SlaveID = offerHelper.MesosOffer.SlaveId
	frn.Hostname = offerHelper.MesosOffer.GetHostname()
	frn.Generation = frn.Generation + 1
	frn.TaskStatus = nil
	frn.CurrentState = process_state.Starting

	taskId := frn.CreateTaskID()
	nodename := frn.CurrentID() + "@" + frn.Hostname
	if !strings.Contains(frn.Hostname, ".") {
		nodename = nodename + "."
	}
	ports := common.PortIterator(taskAsk)

	taskData := common.TaskData{
		FullyQualifiedNodeName: nodename,
		Host:           frn.Hostname,
		Zookeepers:     sc.zookeepers,
		FrameworkName:  sc.frameworkName,
		URI:            sc.schedulerHTTPServer.GetURI(),
		ClusterName:    frn.ClusterName,
		UseSuperChroot: os.Getenv("USE_SUPER_CHROOT") != "false",
		HTTPPort:       <-ports,
		PBPort:         <-ports,
		DisterlPort:    <-ports,
	}
	frn.TaskData = taskData

	binTaskData, err := taskData.Serialize()
	if err != nil {
		log.Panic(err)
	}

	execName := fmt.Sprintf("%s Executor", frn.CurrentID())
	taskInfo := &mesos.TaskInfo{
		Name:    proto.String(frn.Name()),
		TaskId:  taskId,
		SlaveId: frn.SlaveID,
		Executor: &mesos.ExecutorInfo{
			ExecutorId: frn.CreateExecutorID(),
			Name:       proto.String(execName),
			Source:     proto.String(frn.FrameworkName),
			Command: &mesos.CommandInfo{
				Value: proto.String(ExecutorValue()),
				Uris: []*mesos.CommandInfo_URI{
					&mesos.CommandInfo_URI{
						Value:      &(sc.schedulerHTTPServer.hostURI),
						Executable: proto.Bool(false),
					},
					&mesos.CommandInfo_URI{
						Value:      &(sc.schedulerHTTPServer.riakURI),
						Executable: proto.Bool(false),
					},
					&mesos.CommandInfo_URI{
						Value:      &(sc.schedulerHTTPServer.cepmdURI),
						Executable: proto.Bool(true),
					},
				},
				Shell:     proto.Bool(ExecutorShell()),
				Arguments: ExecutorArgs(frn.CurrentID()),
			},
			Resources: execAsk,
		},
		Resources: taskAsk,
		Data:      binTaskData,
	}

	offerHelper.TasksToLaunch = append(offerHelper.TasksToLaunch, taskInfo)

	return true
}
コード例 #2
0
func (frn *FrameworkRiakNode) PrepareForLaunchAndGetNewTaskInfo(sc *SchedulerCore, offer *mesos.Offer, executorAsk []*mesos.Resource, taskAsk []*mesos.Resource) *mesos.TaskInfo {
	// THIS IS A MUTATING CALL
	if frn.CurrentState != process_state.Shutdown && frn.CurrentState != process_state.Failed && frn.CurrentState != process_state.Unknown {
		log.Panicf("Trying to generate Task Info while node is up. ZK FRN State: %v", frn.CurrentState)
	}
	frn.Generation = frn.Generation + 1
	frn.TaskStatus = nil
	frn.CurrentState = process_state.Starting
	frn.LastOfferUsed = offer

	executorUris := []*mesos.CommandInfo_URI{
		&mesos.CommandInfo_URI{
			Value:      &(sc.schedulerHTTPServer.hostURI),
			Executable: proto.Bool(true),
		},
	}
	//executorUris = append(executorUris,
	//	&mesos.CommandInfo_URI{Value: &(frn.frc.sc.schedulerHTTPServer.hostURI), Executable: proto.Bool(true)})

	exec := &mesos.ExecutorInfo{
		//No idea is this is the "right" way to do it, but I think so?
		ExecutorId: util.NewExecutorID(frn.ExecutorID()),
		Name:       proto.String("Executor (Go)"),
		Source:     proto.String("Riak Mesos Framework (Go)"),
		Command: &mesos.CommandInfo{
			Value:     proto.String(sc.schedulerHTTPServer.executorName),
			Uris:      executorUris,
			Shell:     proto.Bool(false),
			Arguments: []string{sc.schedulerHTTPServer.executorName, "-logtostderr=true", "-taskinfo", frn.CurrentID()},
		},
		Resources: executorAsk,
	}
	taskId := &mesos.TaskID{
		Value: proto.String(frn.CurrentID()),
	}

	nodename := frn.CurrentID() + "@" + offer.GetHostname()

	if !strings.Contains(offer.GetHostname(), ".") {
		nodename = nodename + "."
	}

	taskData := common.TaskData{
		FullyQualifiedNodeName:    nodename,
		RexFullyQualifiedNodeName: "rex-" + nodename,
		Zookeepers:                sc.zookeepers,
		NodeID:                    frn.UUID.String(),
		FrameworkName:             sc.frameworkName,
		URI:                       sc.schedulerHTTPServer.GetURI(),
		ClusterName:               frn.ClusterName,
	}
	frn.TaskData = taskData

	binTaskData, err := taskData.Serialize()

	if err != nil {
		log.Panic(err)
	}

	taskInfo := &mesos.TaskInfo{
		Name:      proto.String(frn.CurrentID()),
		TaskId:    taskId,
		SlaveId:   offer.SlaveId,
		Executor:  exec,
		Resources: taskAsk,
		Data:      binTaskData,
	}
	frn.LastTaskInfo = taskInfo

	return taskInfo
}