public virtual void TestAppBlockRenderWithNullCurrentAppAttempt() { ApplicationId AppId = ApplicationId.NewInstance(1234L, 0); Injector injector; // init app RMApp app = Org.Mockito.Mockito.Mock <RMApp>(); Org.Mockito.Mockito.When(app.GetTrackingUrl()).ThenReturn("http://host:123"); Org.Mockito.Mockito.When(app.GetState()).ThenReturn(RMAppState.Failed); Org.Mockito.Mockito.When(app.GetApplicationId()).ThenReturn(AppId); Org.Mockito.Mockito.When(app.GetApplicationType()).ThenReturn("Type"); Org.Mockito.Mockito.When(app.GetUser()).ThenReturn("user"); Org.Mockito.Mockito.When(app.GetName()).ThenReturn("Name"); Org.Mockito.Mockito.When(app.GetQueue()).ThenReturn("queue"); Org.Mockito.Mockito.When(app.GetDiagnostics()).ThenReturn(new StringBuilder()); Org.Mockito.Mockito.When(app.GetFinalApplicationStatus()).ThenReturn(FinalApplicationStatus .Failed); Org.Mockito.Mockito.When(app.GetFinalApplicationStatus()).ThenReturn(FinalApplicationStatus .Failed); Org.Mockito.Mockito.When(app.GetStartTime()).ThenReturn(0L); Org.Mockito.Mockito.When(app.GetFinishTime()).ThenReturn(0L); Org.Mockito.Mockito.When(app.CreateApplicationState()).ThenReturn(YarnApplicationState .Failed); RMAppMetrics appMetrics = new RMAppMetrics(Resource.NewInstance(0, 0), 0, 0, 0, 0 ); Org.Mockito.Mockito.When(app.GetRMAppMetrics()).ThenReturn(appMetrics); // initialize RM Context, and create RMApp, without creating RMAppAttempt RMContext rmContext = TestRMWebApp.MockRMContext(15, 1, 2, 8); rmContext.GetRMApps()[AppId] = app; injector = WebAppTests.CreateMockInjector <RMContext>(rmContext, new _Module_76(rmContext )); AppBlock instance = injector.GetInstance <AppBlock>(); instance.Set(YarnWebParams.ApplicationId, AppId.ToString()); instance.Render(); }
public AppInfo(ResourceManager rm, RMApp app, bool hasAccess, string schemePrefix ) { // these are ok for any user to see // these are only allowed if acls allow // preemption info fields // JAXB needs this this.schemePrefix = schemePrefix; if (app != null) { string trackingUrl = app.GetTrackingUrl(); this.state = app.CreateApplicationState(); this.trackingUrlIsNotReady = trackingUrl == null || trackingUrl.IsEmpty() || YarnApplicationState .New == this.state || YarnApplicationState.NewSaving == this.state || YarnApplicationState .Submitted == this.state || YarnApplicationState.Accepted == this.state; this.trackingUI = this.trackingUrlIsNotReady ? "UNASSIGNED" : (app.GetFinishTime( ) == 0 ? "ApplicationMaster" : "History"); if (!trackingUrlIsNotReady) { this.trackingUrl = WebAppUtils.GetURLWithScheme(schemePrefix, trackingUrl); this.trackingUrlPretty = this.trackingUrl; } else { this.trackingUrlPretty = "UNASSIGNED"; } this.applicationId = app.GetApplicationId(); this.applicationType = app.GetApplicationType(); this.appIdNum = app.GetApplicationId().GetId().ToString(); this.id = app.GetApplicationId().ToString(); this.user = app.GetUser().ToString(); this.name = app.GetName().ToString(); this.queue = app.GetQueue().ToString(); this.progress = app.GetProgress() * 100; this.diagnostics = app.GetDiagnostics().ToString(); if (diagnostics == null || diagnostics.IsEmpty()) { this.diagnostics = string.Empty; } if (app.GetApplicationTags() != null && !app.GetApplicationTags().IsEmpty()) { this.applicationTags = Joiner.On(',').Join(app.GetApplicationTags()); } this.finalStatus = app.GetFinalApplicationStatus(); this.clusterId = ResourceManager.GetClusterTimeStamp(); if (hasAccess) { this.startedTime = app.GetStartTime(); this.finishedTime = app.GetFinishTime(); this.elapsedTime = Times.Elapsed(app.GetStartTime(), app.GetFinishTime()); RMAppAttempt attempt = app.GetCurrentAppAttempt(); if (attempt != null) { Container masterContainer = attempt.GetMasterContainer(); if (masterContainer != null) { this.amContainerLogsExist = true; this.amContainerLogs = WebAppUtils.GetRunningLogURL(schemePrefix + masterContainer .GetNodeHttpAddress(), ConverterUtils.ToString(masterContainer.GetId()), app.GetUser ()); this.amHostHttpAddress = masterContainer.GetNodeHttpAddress(); } ApplicationResourceUsageReport resourceReport = attempt.GetApplicationResourceUsageReport (); if (resourceReport != null) { Resource usedResources = resourceReport.GetUsedResources(); allocatedMB = usedResources.GetMemory(); allocatedVCores = usedResources.GetVirtualCores(); runningContainers = resourceReport.GetNumUsedContainers(); } resourceRequests = ((AbstractYarnScheduler)rm.GetRMContext().GetScheduler()).GetPendingResourceRequestsForAttempt (attempt.GetAppAttemptId()); } } // copy preemption info fields RMAppMetrics appMetrics = app.GetRMAppMetrics(); numAMContainerPreempted = appMetrics.GetNumAMContainersPreempted(); preemptedResourceMB = appMetrics.GetResourcePreempted().GetMemory(); numNonAMContainerPreempted = appMetrics.GetNumNonAMContainersPreempted(); preemptedResourceVCores = appMetrics.GetResourcePreempted().GetVirtualCores(); memorySeconds = appMetrics.GetMemorySeconds(); vcoreSeconds = appMetrics.GetVcoreSeconds(); } }