예제 #1
0
func main() {

	conf, _ := yarn_conf.NewYarnConfiguration()

	// Use the ApplicationClientProtocolService protocol
	appClient, err := hadoop_yarn.DialApplicationClientProtocolService(conf)
	if err != nil {
		log.Fatal("hadoop_yarn.DialApplicationClientProtocolService not found")
	}

	// ApplicationClientProtocol.getApplications
	applicationStates := []hadoop_yarn.YarnApplicationStateProto{hadoop_yarn.YarnApplicationStateProto_ACCEPTED, hadoop_yarn.YarnApplicationStateProto_RUNNING, hadoop_yarn.YarnApplicationStateProto_SUBMITTED}
	getAppsReqProto := hadoop_yarn.GetApplicationsRequestProto{ApplicationStates: applicationStates}
	getAppsResProto := hadoop_yarn.GetApplicationsResponseProto{}
	err = appClient.GetApplications(&getAppsReqProto, &getAppsResProto)
	if err != nil {
		log.Fatal("appClient.GetApplications failed", err)
	}
	log.Println("appClient.GetApplications response: ", getAppsResProto)

	// ApplicationClientProtocol.getNewApplication
	getNewAppReqProto := hadoop_yarn.GetNewApplicationRequestProto{}
	getNewAppResProto := hadoop_yarn.GetNewApplicationResponseProto{}

	err = appClient.GetNewApplication(&getNewAppReqProto, &getNewAppResProto)
	if err != nil {
		log.Fatal("appClient.GetNewApplication failed", err)
	}
	log.Println("appClient.GetNewApplication response: ", getNewAppResProto)
}
예제 #2
0
파일: client.go 프로젝트: pims/gohadoop
func main() {
	// Create YarnConfiguration
	conf, _ := yarn_conf.NewYarnConfiguration()

	// Create YarnClient
	yarnClient, _ := yarn_client.CreateYarnClient(conf)

	// Create new application to get ApplicationSubmissionContext
	_, asc, _ := yarnClient.CreateNewApplication()

	// Setup ContainerLaunchContext for the application
	clc := hadoop_yarn.ContainerLaunchContextProto{}
	clc.Command = []string{"go run /Users/acmurthy/dev/go/src/github.com/gohadoop/hadoop_yarn/examples/dist_shell/applicationmaster.go 1>/tmp/stdout 2>/tmp/stderr"}
	clc.Environment = getEnv()

	// Resource for ApplicationMaster
	var memory int32 = 1024
	resource := hadoop_yarn.ResourceProto{Memory: &memory}

	// Some useful information
	queue := "default"
	appName := "simple-go-yarn-app"
	appType := "GO_HADOOP"

	// Setup ApplicationSubmissionContext for the application
	asc.AmContainerSpec = &clc
	asc.Resource = &resource
	asc.ApplicationName = &appName
	asc.Queue = &queue
	asc.ApplicationType = &appType

	// Submit!
	err := yarnClient.SubmitApplication(asc)
	if err != nil {
		log.Fatal("yarnClient.SubmitApplication ", err)
	}
	log.Println("Successfully submitted application: ", asc.ApplicationId)

	appReport, err := yarnClient.GetApplicationReport(asc.ApplicationId)
	if err != nil {
		log.Fatal("yarnClient.GetApplicationReport ", err)
	}
	appState := appReport.GetYarnApplicationState()
	for appState != hadoop_yarn.YarnApplicationStateProto_FINISHED && appState != hadoop_yarn.YarnApplicationStateProto_KILLED && appState != hadoop_yarn.YarnApplicationStateProto_FAILED {
		log.Println("Application in state ", appState)
		time.Sleep(1 * time.Second)
		appReport, err = yarnClient.GetApplicationReport(asc.ApplicationId)
		appState = appReport.GetYarnApplicationState()
	}

	log.Println("Application finished in state: ", appState)
}