TEST_F(TestApplicationClient,TestGetApplicationReport){
	ApplicationId appId;
	ApplicationReport report = client->getApplicationReport(appId);
	EXPECT_EQ(report.getUser(), "postgres");
	EXPECT_EQ(report.getQueue(), "default");
	EXPECT_EQ(report.getName(), "hawq");
	EXPECT_EQ(report.getHost(), "master");
	EXPECT_EQ(report.getRpcPort(), 8090);
	EXPECT_FLOAT_EQ(report.getProgress(), 0.5);
}
	TestApplicationClient(){
		string user("postgres");
		string rmHost("localhost");
		string rmPort("8032");
		string tokenService = "";
		Yarn::Config config;
		Yarn::Internal::SessionConfig sessionConfig(config);
		MockApplicationClientProtocol *protocol = new MockApplicationClientProtocol(user,rmHost,rmPort,tokenService, sessionConfig);

		ApplicationId appId;
		appId.setId(100);
		appId.setClusterTimestamp(1454307175682);
		GetNewApplicationResponse getNewApplicationResponse;
		getNewApplicationResponse.setApplicationId(appId);
		EXPECT_CALL((*protocol),getNewApplication(_)).Times(AnyNumber()).WillOnce(Return(getNewApplicationResponse));
		EXPECT_CALL((*protocol),submitApplication(_)).Times(AnyNumber()).WillOnce(Return());

		ApplicationReport appReport;
		appReport.setApplicationId(appId);
		appReport.setUser(user);
		string queue("default");
		string appName("hawq");
		string hostname("master");
		appReport.setQueue(queue);
		appReport.setName(appName);
		appReport.setHost(hostname);
		appReport.setRpcPort(8090);
		appReport.setProgress(0.5);
		GetApplicationReportResponse appReportResponse;
		appReportResponse.setApplicationReport(appReport);
		EXPECT_CALL((*protocol),getApplicationReport(_)).Times(AnyNumber()).WillOnce(Return(appReportResponse));

		ContainerId containerId;
		containerId.setId(501);
		containerId.setApplicationId(appId);
		Resource resource;
		resource.setMemory(1024);
		resource.setVirtualCores(1);
		Priority priority;
		priority.setPriority(1);
		ContainerReport report;
		report.setId(containerId);
		report.setResource(resource);
		report.setPriority(priority);
		list<ContainerReport> reportList;
		reportList.push_back(report);
		GetContainersResponse getContainersResponse;
		getContainersResponse.setContainersReportList(reportList);
		EXPECT_CALL((*protocol),getContainers(_)).Times(AnyNumber()).WillOnce(Return(getContainersResponse));

		NodeId nodeId;
		string nodeHost("node1");
		nodeId.setHost(nodeHost);
		nodeId.setPort(9983);
		NodeReport nodeReport;
		nodeReport.setNodeId(nodeId);
		string rackName("default-rack");
		nodeReport.setRackName(rackName);
		nodeReport.setNumContainers(8);
		Resource nodeResource;
		nodeResource.setMemory(2048*8);
		nodeResource.setVirtualCores(8);
		nodeReport.setResourceCapablity(nodeResource);
		nodeReport.setNodeState(NodeState::NS_RUNNING);
		list<NodeReport> nodeReportList;
		nodeReportList.push_back(nodeReport);
		GetClusterNodesResponse getClusterNodesResponse;
		getClusterNodesResponse.setNodeReports(nodeReportList);
		EXPECT_CALL((*protocol),getClusterNodes(_)).Times(AnyNumber()).WillOnce(Return(getClusterNodesResponse));

		QueueInfo queueInfo;
		queueInfo.setQueueName(queue);
		queueInfo.setCapacity(0.67);
		queueInfo.setMaximumCapacity(0.95);
		queueInfo.setCurrentCapacity(0.5);
		queueInfo.setQueueState(QueueState::Q_RUNNING);
		QueueInfo childQueue;
		string childQueueName("hawq-queue");
		childQueue.setQueueName(childQueueName);
		childQueue.setCapacity(0.33);
		childQueue.setMaximumCapacity(0.5);
		childQueue.setCurrentCapacity(0.25);
		list<QueueInfo> childQueueList;
		childQueueList.push_back(childQueue);
		queueInfo.setChildQueues(childQueueList);
		list<ApplicationReport> appReportList;
		appReportList.push_back(appReport);
		queueInfo.setApplicationReports(appReportList);
		GetQueueInfoResponse getQueueInfoResponse;
		getQueueInfoResponse.setQueueInfo(queueInfo);
		EXPECT_CALL((*protocol),getQueueInfo(_)).Times(AnyNumber()).WillOnce(Return(getQueueInfoResponse));

		KillApplicationResponseProto killApplicationResponseProto;
		EXPECT_CALL((*protocol),forceKillApplication(_)).Times(AnyNumber()).WillOnce(Return(KillApplicationResponse(killApplicationResponseProto)));

		YarnClusterMetrics metrics;
		metrics.setNumNodeManagers(10);
		GetClusterMetricsResponse clusterMetricsResponse;
		clusterMetricsResponse.setClusterMetrics(metrics);
		EXPECT_CALL((*protocol),getClusterMetrics(_)).Times(AnyNumber()).WillOnce(Return(clusterMetricsResponse));

		GetApplicationsResponse applicationsResponse;
		applicationsResponse.setApplicationList(appReportList);
		EXPECT_CALL((*protocol),getApplications(_)).Times(AnyNumber()).WillOnce(Return(applicationsResponse));

		QueueUserACLInfo aclInfo;
		aclInfo.setQueueName(queue);
		list<QueueACL> queueACLList;
		QueueACL acl1 = QueueACL::QACL_ADMINISTER_QUEUE;
		QueueACL acl2 = QueueACL::QACL_SUBMIT_APPLICATIONS;
		queueACLList.push_back(acl1);
		queueACLList.push_back(acl2);
		aclInfo.setUserAcls(queueACLList);
		list<QueueUserACLInfo> aclInfoList;
		aclInfoList.push_back(aclInfo);
		GetQueueUserAclsInfoResponse queueUserAclsInfoResponse;
		queueUserAclsInfoResponse.setUserAclsInfoList(aclInfoList);
		EXPECT_CALL((*protocol),getQueueAclsInfo(_)).Times(AnyNumber()).WillOnce(Return(queueUserAclsInfoResponse));

		client = new ApplicationClient(protocol);
	}
예제 #3
0
	int getApplicationReport(LibYarnClient_t *client,char *jobId,
							LibYarnApplicationReport_t **applicationReport) {
		string jobIdStr(jobId);
		ApplicationReport applicationReportCpp;
		int result = client->getApplicationReport(jobIdStr,applicationReportCpp);
		if (result == FUNCTION_SUCCEEDED){
			*applicationReport = (LibYarnApplicationReport_t *) malloc(sizeof (LibYarnApplicationReport_t));
			(*applicationReport)->appId = applicationReportCpp.getApplicationId().getId();
			(*applicationReport)->user = strdup(applicationReportCpp.getUser().c_str());
			(*applicationReport)->queue = strdup(applicationReportCpp.getQueue().c_str());
			(*applicationReport)->name = strdup(applicationReportCpp.getName().c_str());
			(*applicationReport)->host = strdup(applicationReportCpp.getHost().c_str());
			(*applicationReport)->port = applicationReportCpp.getRpcPort();
			(*applicationReport)->url = strdup(applicationReportCpp.getTrackingUrl().c_str());
			(*applicationReport)->status = applicationReportCpp.getYarnApplicationState();
			(*applicationReport)->diagnostics = strdup(applicationReportCpp.getDiagnostics().c_str());
			(*applicationReport)->startTime = applicationReportCpp.getStartTime();
			(*applicationReport)->progress = applicationReportCpp.getProgress();
			return FUNCTION_SUCCEEDED;
		} else{
			setErrorMessage(client->getErrorMessage());
			return FUNCTION_FAILED;
		}
	}
void GetApplicationReportResponse::setApplicationReport(ApplicationReport &appReport) {
	ApplicationReportProto *proto = new ApplicationReportProto();
	proto->CopyFrom(appReport.getProto());
	responseProto.set_allocated_application_report(proto);
}