public virtual void TestUpdateHeartbeatResponseForCleanup() { RMNodeImpl node = GetRunningNode(); NodeId nodeId = node.GetNodeID(); // Expire a container ContainerId completedContainerId = BuilderUtils.NewContainerId(BuilderUtils.NewApplicationAttemptId (BuilderUtils.NewApplicationId(0, 0), 0), 0); node.Handle(new RMNodeCleanContainerEvent(nodeId, completedContainerId)); NUnit.Framework.Assert.AreEqual(1, node.GetContainersToCleanUp().Count); // Finish an application ApplicationId finishedAppId = BuilderUtils.NewApplicationId(0, 1); node.Handle(new RMNodeCleanAppEvent(nodeId, finishedAppId)); NUnit.Framework.Assert.AreEqual(1, node.GetAppsToCleanup().Count); // Verify status update does not clear containers/apps to cleanup // but updating heartbeat response for cleanup does RMNodeStatusEvent statusEvent = GetMockRMNodeStatusEvent(); node.Handle(statusEvent); NUnit.Framework.Assert.AreEqual(1, node.GetContainersToCleanUp().Count); NUnit.Framework.Assert.AreEqual(1, node.GetAppsToCleanup().Count); NodeHeartbeatResponse hbrsp = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <NodeHeartbeatResponse >(); node.UpdateNodeHeartbeatResponseForCleanup(hbrsp); NUnit.Framework.Assert.AreEqual(0, node.GetContainersToCleanUp().Count); NUnit.Framework.Assert.AreEqual(0, node.GetAppsToCleanup().Count); NUnit.Framework.Assert.AreEqual(1, hbrsp.GetContainersToCleanup().Count); NUnit.Framework.Assert.AreEqual(completedContainerId, hbrsp.GetContainersToCleanup ()[0]); NUnit.Framework.Assert.AreEqual(1, hbrsp.GetApplicationsToCleanup().Count); NUnit.Framework.Assert.AreEqual(finishedAppId, hbrsp.GetApplicationsToCleanup()[0 ]); }
public virtual void TestStatusChange() { //Start the node node.Handle(new RMNodeStartedEvent(null, null, null)); //Add info to the queue first node.SetNextHeartBeat(false); ContainerId completedContainerId1 = BuilderUtils.NewContainerId(BuilderUtils.NewApplicationAttemptId (BuilderUtils.NewApplicationId(0, 0), 0), 0); ContainerId completedContainerId2 = BuilderUtils.NewContainerId(BuilderUtils.NewApplicationAttemptId (BuilderUtils.NewApplicationId(1, 1), 1), 1); RMNodeStatusEvent statusEvent1 = GetMockRMNodeStatusEvent(); RMNodeStatusEvent statusEvent2 = GetMockRMNodeStatusEvent(); ContainerStatus containerStatus1 = Org.Mockito.Mockito.Mock <ContainerStatus>(); ContainerStatus containerStatus2 = Org.Mockito.Mockito.Mock <ContainerStatus>(); Org.Mockito.Mockito.DoReturn(completedContainerId1).When(containerStatus1).GetContainerId (); Org.Mockito.Mockito.DoReturn(Sharpen.Collections.SingletonList(containerStatus1)) .When(statusEvent1).GetContainers(); Org.Mockito.Mockito.DoReturn(completedContainerId2).When(containerStatus2).GetContainerId (); Org.Mockito.Mockito.DoReturn(Sharpen.Collections.SingletonList(containerStatus2)) .When(statusEvent2).GetContainers(); Org.Mockito.Mockito.Verify(scheduler, Org.Mockito.Mockito.Times(1)).Handle(Matchers.Any <NodeUpdateSchedulerEvent>()); node.Handle(statusEvent1); node.Handle(statusEvent2); Org.Mockito.Mockito.Verify(scheduler, Org.Mockito.Mockito.Times(1)).Handle(Matchers.Any <NodeUpdateSchedulerEvent>()); NUnit.Framework.Assert.AreEqual(2, node.GetQueueSize()); node.Handle(new RMNodeEvent(node.GetNodeID(), RMNodeEventType.Expire)); NUnit.Framework.Assert.AreEqual(0, node.GetQueueSize()); }
public virtual void TestExpiredContainer() { // Start the node node.Handle(new RMNodeStartedEvent(null, null, null)); Org.Mockito.Mockito.Verify(scheduler).Handle(Matchers.Any <NodeAddedSchedulerEvent >()); // Expire a container ContainerId completedContainerId = BuilderUtils.NewContainerId(BuilderUtils.NewApplicationAttemptId (BuilderUtils.NewApplicationId(0, 0), 0), 0); node.Handle(new RMNodeCleanContainerEvent(null, completedContainerId)); NUnit.Framework.Assert.AreEqual(1, node.GetContainersToCleanUp().Count); // Now verify that scheduler isn't notified of an expired container // by checking number of 'completedContainers' it got in the previous event RMNodeStatusEvent statusEvent = GetMockRMNodeStatusEvent(); ContainerStatus containerStatus = Org.Mockito.Mockito.Mock <ContainerStatus>(); Org.Mockito.Mockito.DoReturn(completedContainerId).When(containerStatus).GetContainerId (); Org.Mockito.Mockito.DoReturn(Sharpen.Collections.SingletonList(containerStatus)). When(statusEvent).GetContainers(); node.Handle(statusEvent); /* Expect the scheduler call handle function 2 times * 1. RMNode status from new to Running, handle the add_node event * 2. handle the node update event */ Org.Mockito.Mockito.Verify(scheduler, Org.Mockito.Mockito.Times(2)).Handle(Matchers.Any <NodeUpdateSchedulerEvent>()); }
public static void SaveToFile(GeneratorOptions generatorOptions, string parentDir, string fileName, string content) { string path = GetBasePath(generatorOptions); path = Path.Combine(path, parentDir); BuilderUtils.CreateFile(path, fileName, content); }
private RMNodeImpl GetNewNode() { NodeId nodeId = BuilderUtils.NewNodeId("localhost", 0); RMNodeImpl node = new RMNodeImpl(nodeId, rmContext, null, 0, 0, null, null, null); return(node); }
public override void InjectTypeProperties() { var resolvedProperties = Context.ResolvedProperties; //resolving injection properties, which wheren't registered in the "PropertyInjections" var propsToInjectValue = Context.SourceType.GetProperties() .Select(Context.GetPropertyMappingInfo) .Where(x => !resolvedProperties.Contains(x)).ToArray(); foreach (var prop in propsToInjectValue) { var propKey = BuilderUtils.GetKey(prop); //mark ignored propertieswas as resolved if (Context.IgnoreProperties.Contains(propKey)) { resolvedProperties.Add(prop); continue; } var resolutionResult = ResolvePropertyInfo(prop); if (resolutionResult != null) { Context.MapProperty(prop, resolutionResult); } } }
public void ConnectShapes(ShapeWrapper shapeFrom, ShapeWrapper shapeTo, NodesBranchRelation nodesBranchRelation = NodesBranchRelation.SAME_BRANCH) { var connectionType = BuilderUtils.DefineConnectionType(shapeFrom, shapeTo, nodesBranchRelation); ConnectShapes(shapeFrom, shapeTo, nodesBranchRelation, connectionType); }
/////////////////////////////////////////////////////////////////////////////////////////// public static void AddBuildable() { BuilderUtils.AddBuildable(new CustomTechInfo() { getPrefab = HabitatControlPanel.GetPrefab, techType = (TechType)CustomTechType.HabitatControlPanel, techGroup = TechGroup.InteriorModules, techCategory = TechCategory.InteriorModule, knownAtStart = true, assetPath = "Submarine/Build/HabitatControlPanel", displayString = "Habitat Control Panel", tooltip = "TODO TOOLTIP", techTypeKey = CustomTechType.HabitatControlPanel.ToString(), sprite = new Atlas.Sprite(ImageUtils.LoadTexture(Mod.GetAssetPath("BlueprintIcon.png"))), recipe = new List <CustomIngredient> { new CustomIngredient() { techType = TechType.Titanium, amount = 1 }, new CustomIngredient() { techType = TechType.ComputerChip, amount = 1 }, new CustomIngredient() { techType = TechType.WiringKit, amount = 1 } } }); }
/// <exception cref="System.Exception"/> private ApplicationId SubmitAppAndGetAppId(string submitter, string queueName, bool setupACLs) { GetNewApplicationRequest newAppRequest = GetNewApplicationRequest.NewInstance(); ApplicationClientProtocol submitterClient = GetRMClientForUser(submitter); ApplicationId applicationId = submitterClient.GetNewApplication(newAppRequest).GetApplicationId (); Resource resource = BuilderUtils.NewResource(1024, 1); IDictionary <ApplicationAccessType, string> acls = CreateACLs(submitter, setupACLs ); ContainerLaunchContext amContainerSpec = ContainerLaunchContext.NewInstance(null, null, null, null, null, acls); ApplicationSubmissionContext appSubmissionContext = ApplicationSubmissionContext. NewInstance(applicationId, "applicationName", queueName, null, amContainerSpec, false, true, 1, resource, "applicationType"); appSubmissionContext.SetApplicationId(applicationId); appSubmissionContext.SetQueue(queueName); SubmitApplicationRequest submitRequest = SubmitApplicationRequest.NewInstance(appSubmissionContext ); submitterClient.SubmitApplication(submitRequest); resourceManager.WaitForState(applicationId, RMAppState.Accepted); return(applicationId); }
public void InjectNamedProperty <TProp>(Expression <Func <TClass, TProp> > poperty, string reristeredName) { var propInfo = TypeHelpers.GetPropertyInfo(poperty); var key = BuilderUtils.GetKey(propInfo); PropertyInjectionResolvers.Add(key, new KeyValuePair <string, Type>(reristeredName, propInfo.PropertyType)); }
private void AddResourceRequest(Priority priority, IDictionary <string, ResourceRequest > requests, string resourceName, Org.Apache.Hadoop.Yarn.Api.Records.Resource capability ) { lock (this) { ResourceRequest request = requests[resourceName]; if (request == null) { request = BuilderUtils.NewResourceRequest(priority, resourceName, capability, 1); requests[resourceName] = request; } else { request.SetNumContainers(request.GetNumContainers() + 1); } // Note this down for next interaction with ResourceManager ask.Remove(request); ask.AddItem(BuilderUtils.NewResourceRequest(request)); // clone to ensure the RM doesn't manipulate the same obj if (Log.IsDebugEnabled()) { Log.Debug("addResourceRequest: applicationId=" + applicationId.GetId() + " priority=" + priority.GetPriority() + " resourceName=" + resourceName + " capability=" + capability + " numContainers=" + request.GetNumContainers() + " #asks=" + ask.Count); } } }
public virtual void TestReconnect() { string hostname1 = "localhost1"; Resource capability = BuilderUtils.NewResource(1024, 1); RegisterNodeManagerRequest request1 = recordFactory.NewRecordInstance <RegisterNodeManagerRequest >(); NodeId nodeId1 = NodeId.NewInstance(hostname1, 0); request1.SetNodeId(nodeId1); request1.SetHttpPort(0); request1.SetResource(capability); resourceTrackerService.RegisterNodeManager(request1); NUnit.Framework.Assert.AreEqual(RMNodeEventType.Started, rmNodeEvents[0].GetType( )); rmNodeEvents.Clear(); resourceTrackerService.RegisterNodeManager(request1); NUnit.Framework.Assert.AreEqual(RMNodeEventType.Reconnected, rmNodeEvents[0].GetType ()); rmNodeEvents.Clear(); resourceTrackerService.RegisterNodeManager(request1); capability = BuilderUtils.NewResource(1024, 2); request1.SetResource(capability); NUnit.Framework.Assert.AreEqual(RMNodeEventType.Reconnected, rmNodeEvents[0].GetType ()); }
/// <exception cref="System.IO.IOException"/> private Dictionary <string, string> AddAppContainers(Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app) { Dispatcher dispatcher = new AsyncDispatcher(); ApplicationAttemptId appAttemptId = BuilderUtils.NewApplicationAttemptId(app.GetAppId (), 1); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container container1 = new MockContainer(appAttemptId, dispatcher, conf, app.GetUser(), app.GetAppId (), 1); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container container2 = new MockContainer(appAttemptId, dispatcher, conf, app.GetUser(), app.GetAppId (), 2); nmContext.GetContainers()[container1.GetContainerId()] = container1; nmContext.GetContainers()[container2.GetContainerId()] = container2; app.GetContainers()[container1.GetContainerId()] = container1; app.GetContainers()[container2.GetContainerId()] = container2; Dictionary <string, string> hash = new Dictionary <string, string>(); hash[container1.GetContainerId().ToString()] = container1.GetContainerId().ToString (); hash[container2.GetContainerId().ToString()] = container2.GetContainerId().ToString (); return(hash); }
/// <exception cref="System.Exception"/> private LogAggregationContext GetLogAggregationContextFromContainerToken(MockRM rm1 , MockNM nm1, LogAggregationContext logAggregationContext) { RMApp app2 = rm1.SubmitApp(200, logAggregationContext); MockAM am2 = MockRM.LaunchAndRegisterAM(app2, rm1, nm1); nm1.NodeHeartbeat(true); // request a container. am2.Allocate("127.0.0.1", 512, 1, new AList <ContainerId>()); ContainerId containerId = ContainerId.NewContainerId(am2.GetApplicationAttemptId( ), 2); rm1.WaitForState(nm1, containerId, RMContainerState.Allocated); // acquire the container. IList <Container> containers = am2.Allocate(new AList <ResourceRequest>(), new AList <ContainerId>()).GetAllocatedContainers(); NUnit.Framework.Assert.AreEqual(containerId, containers[0].GetId()); // container token is generated. NUnit.Framework.Assert.IsNotNull(containers[0].GetContainerToken()); ContainerTokenIdentifier token = BuilderUtils.NewContainerTokenIdentifier(containers [0].GetContainerToken()); return(token.GetLogAggregationContext()); }
public virtual void TestGetProxyUriFromPluginsReturnsNullIfNoPlugins() { ApplicationId id = BuilderUtils.NewApplicationId(6384623l, 5); IList <TrackingUriPlugin> list = Lists.NewArrayListWithExpectedSize(0); NUnit.Framework.Assert.IsNull(ProxyUriUtils.GetUriFromTrackingPlugins(id, list)); }
public virtual void TestNMWebApp() { Context nmContext = new NodeManager.NMContext(null, null, null, null, null); ResourceView resourceView = new _ResourceView_147(); Configuration conf = new Configuration(); conf.Set(YarnConfiguration.NmLocalDirs, testRootDir.GetAbsolutePath()); conf.Set(YarnConfiguration.NmLogDirs, testLogDir.GetAbsolutePath()); NodeHealthCheckerService healthChecker = new NodeHealthCheckerService(); healthChecker.Init(conf); LocalDirsHandlerService dirsHandler = healthChecker.GetDiskHandler(); WebServer server = new WebServer(nmContext, resourceView, new ApplicationACLsManager (conf), dirsHandler); server.Init(conf); server.Start(); // Add an application and the corresponding containers RecordFactory recordFactory = RecordFactoryProvider.GetRecordFactory(conf); Dispatcher dispatcher = new AsyncDispatcher(); string user = "******"; long clusterTimeStamp = 1234; ApplicationId appId = BuilderUtils.NewApplicationId(recordFactory, clusterTimeStamp , 1); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app = Org.Mockito.Mockito.Mock <Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application >(); Org.Mockito.Mockito.When(app.GetUser()).ThenReturn(user); Org.Mockito.Mockito.When(app.GetAppId()).ThenReturn(appId); nmContext.GetApplications()[appId] = app; ApplicationAttemptId appAttemptId = BuilderUtils.NewApplicationAttemptId(appId, 1 ); ContainerId container1 = BuilderUtils.NewContainerId(recordFactory, appId, appAttemptId , 0); ContainerId container2 = BuilderUtils.NewContainerId(recordFactory, appId, appAttemptId , 1); NodeManagerMetrics metrics = Org.Mockito.Mockito.Mock <NodeManagerMetrics>(); NMStateStoreService stateStore = new NMNullStateStoreService(); foreach (ContainerId containerId in new ContainerId[] { container1, container2 }) { // TODO: Use builder utils ContainerLaunchContext launchContext = recordFactory.NewRecordInstance <ContainerLaunchContext >(); long currentTime = Runtime.CurrentTimeMillis(); Token containerToken = BuilderUtils.NewContainerToken(containerId, "127.0.0.1", 1234 , user, BuilderUtils.NewResource(1024, 1), currentTime + 10000L, 123, Sharpen.Runtime.GetBytesForString ("password"), currentTime); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container container = new _ContainerImpl_214(conf, dispatcher, stateStore, launchContext, null, metrics , BuilderUtils.NewContainerTokenIdentifier(containerToken)); nmContext.GetContainers()[containerId] = container; //TODO: Gross hack. Fix in code. ApplicationId applicationId = containerId.GetApplicationAttemptId().GetApplicationId (); nmContext.GetApplications()[applicationId].GetContainers()[containerId] = container; WriteContainerLogs(nmContext, containerId, dirsHandler); } }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> public StartContainersResponse StartContainers(StartContainersRequest requests) { StartContainerRequest request = requests.GetStartContainerRequests()[0]; Log.Info("Container started by MyContainerManager: " + request); launched = true; IDictionary <string, string> env = request.GetContainerLaunchContext().GetEnvironment (); Token containerToken = request.GetContainerToken(); ContainerTokenIdentifier tokenId = null; try { tokenId = BuilderUtils.NewContainerTokenIdentifier(containerToken); } catch (IOException e) { throw RPCUtil.GetRemoteException(e); } ContainerId containerId = tokenId.GetContainerID(); containerIdAtContainerManager = containerId.ToString(); attemptIdAtContainerManager = containerId.GetApplicationAttemptId().ToString(); nmHostAtContainerManager = tokenId.GetNmHostAddress(); submitTimeAtContainerManager = long.Parse(env[ApplicationConstants.AppSubmitTimeEnv ]); maxAppAttempts = System.Convert.ToInt32(env[ApplicationConstants.MaxAppAttemptsEnv ]); return(StartContainersResponse.NewInstance(new Dictionary <string, ByteBuffer>(), new AList <ContainerId>(), new Dictionary <ContainerId, SerializedException>())); }
public virtual void TestGetPathApplicationId() { NUnit.Framework.Assert.AreEqual("/proxy/application_100_0001", ProxyUriUtils.GetPath (BuilderUtils.NewApplicationId(100l, 1))); NUnit.Framework.Assert.AreEqual("/proxy/application_6384623_0005", ProxyUriUtils. GetPath(BuilderUtils.NewApplicationId(6384623l, 5))); }
private IComparer <Schedulable> CreateComparator(int clusterMem, int clusterCpu) { DominantResourceFairnessPolicy policy = new DominantResourceFairnessPolicy(); policy.Initialize(BuilderUtils.NewResource(clusterMem, clusterCpu)); return(policy.GetComparator()); }
/////////////////////////////////////////////////////////////////////////////////////////// public static void AddBuildable() { BuilderUtils.AddBuildable(new CustomTechInfo() { getPrefab = VehicleStorageAccess.GetPrefab, techType = (TechType)CustomTechType.DockedVehicleStorageAccess, techGroup = TechGroup.InteriorModules, techCategory = TechCategory.InteriorModule, knownAtStart = true, assetPath = "Submarine/Build/DockedVehicleStorageAccess", displayString = "Docked Vehicle Storage Access", tooltip = "Wall locker that extracts items from any docked vehicle in the moonpool.", techTypeKey = CustomTechType.DockedVehicleStorageAccess.ToString(), sprite = new Atlas.Sprite(ImageUtils.LoadTexture(Mod.GetAssetPath("StorageAccess.png"))), recipe = new List <CustomIngredient> { new CustomIngredient() { techType = TechType.Titanium, amount = 2 }, new CustomIngredient() { techType = TechType.WiringKit, amount = 1 } } }); }
/// <exception cref="System.Exception"/> private ApplicationId SubmitAppAndGetAppId(AccessControlList viewACL, AccessControlList modifyACL) { SubmitApplicationRequest submitRequest = recordFactory.NewRecordInstance <SubmitApplicationRequest >(); ApplicationSubmissionContext context = recordFactory.NewRecordInstance <ApplicationSubmissionContext >(); ApplicationId applicationId = rmClient.GetNewApplication(recordFactory.NewRecordInstance <GetNewApplicationRequest>()).GetApplicationId(); context.SetApplicationId(applicationId); IDictionary <ApplicationAccessType, string> acls = new Dictionary <ApplicationAccessType , string>(); acls[ApplicationAccessType.ViewApp] = viewACL.GetAclString(); acls[ApplicationAccessType.ModifyApp] = modifyACL.GetAclString(); ContainerLaunchContext amContainer = recordFactory.NewRecordInstance <ContainerLaunchContext >(); Resource resource = BuilderUtils.NewResource(1024, 1); context.SetResource(resource); amContainer.SetApplicationACLs(acls); context.SetAMContainerSpec(amContainer); submitRequest.SetApplicationSubmissionContext(context); rmClient.SubmitApplication(submitRequest); resourceManager.WaitForState(applicationId, RMAppState.Accepted); return(applicationId); }
public void Null_IsForMember() { var property = typeof(ClassWithNullableDateTime).GetProperty("Property1"); var memberSetter = BuilderUtils.GetMemberSetter <object, object>(property, (o, b, s) => null, true); Assert.DoesNotThrow(() => memberSetter.IsForMember(null, null, null)); }
public virtual void TestNodeRegistrationVersionLessThanRM() { WriteToHostsFile("host2"); Configuration conf = new Configuration(); conf.Set(YarnConfiguration.RmNodesIncludeFilePath, hostFile.GetAbsolutePath()); conf.Set(YarnConfiguration.RmNodemanagerMinimumVersion, "EqualToRM"); rm = new MockRM(conf); rm.Start(); string nmVersion = "1.9.9"; ResourceTrackerService resourceTrackerService = rm.GetResourceTrackerService(); RegisterNodeManagerRequest req = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <RegisterNodeManagerRequest >(); NodeId nodeId = NodeId.NewInstance("host2", 1234); Resource capability = BuilderUtils.NewResource(1024, 1); req.SetResource(capability); req.SetNodeId(nodeId); req.SetHttpPort(1234); req.SetNMVersion(nmVersion); // trying to register a invalid node. RegisterNodeManagerResponse response = resourceTrackerService.RegisterNodeManager (req); NUnit.Framework.Assert.AreEqual(NodeAction.Shutdown, response.GetNodeAction()); NUnit.Framework.Assert.IsTrue("Diagnostic message did not contain: 'Disallowed NodeManager " + "Version " + nmVersion + ", is less than the minimum version'", response.GetDiagnosticsMessage ().Contains("Disallowed NodeManager Version " + nmVersion + ", is less than the minimum version " )); }
internal WrappedApplication(TestApplication _enclosing, int id, long timestamp, string user, int numContainers) { this._enclosing = _enclosing; Configuration conf = new Configuration(); this.dispatcher = new DrainDispatcher(); this.containerTokenIdentifierMap = new Dictionary <ContainerId, ContainerTokenIdentifier >(); this.dispatcher.Init(conf); this.localizerBus = Org.Mockito.Mockito.Mock <EventHandler>(); this.launcherBus = Org.Mockito.Mockito.Mock <EventHandler>(); this.monitorBus = Org.Mockito.Mockito.Mock <EventHandler>(); this.auxBus = Org.Mockito.Mockito.Mock <EventHandler>(); this.containerBus = Org.Mockito.Mockito.Mock <EventHandler>(); this.logAggregationBus = Org.Mockito.Mockito.Mock <EventHandler>(); this.dispatcher.Register(typeof(LocalizationEventType), this.localizerBus); this.dispatcher.Register(typeof(ContainersLauncherEventType), this.launcherBus); this.dispatcher.Register(typeof(ContainersMonitorEventType), this.monitorBus); this.dispatcher.Register(typeof(AuxServicesEventType), this.auxBus); this.dispatcher.Register(typeof(ContainerEventType), this.containerBus); this.dispatcher.Register(typeof(LogHandlerEventType), this.logAggregationBus); this.nmTokenSecretMgr = Org.Mockito.Mockito.Mock <NMTokenSecretManagerInNM>(); this.context = Org.Mockito.Mockito.Mock <Context>(); Org.Mockito.Mockito.When(this.context.GetContainerTokenSecretManager()).ThenReturn (new NMContainerTokenSecretManager(conf)); Org.Mockito.Mockito.When(this.context.GetApplicationACLsManager()).ThenReturn(new ApplicationACLsManager(conf)); Org.Mockito.Mockito.When(this.context.GetNMTokenSecretManager()).ThenReturn(this. nmTokenSecretMgr); // Setting master key MasterKey masterKey = new MasterKeyPBImpl(); masterKey.SetKeyId(123); masterKey.SetBytes(ByteBuffer.Wrap(new byte[] { (123) })); this.context.GetContainerTokenSecretManager().SetMasterKey(masterKey); this.user = user; this.appId = BuilderUtils.NewApplicationId(timestamp, id); this.app = new ApplicationImpl(this.dispatcher, this.user, this.appId, null, this .context); this.containers = new AList <Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container >(); for (int i = 0; i < numContainers; i++) { Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container container = this._enclosing.CreateMockedContainer(this.appId, i); this.containers.AddItem(container); long currentTime = Runtime.CurrentTimeMillis(); ContainerTokenIdentifier identifier = new ContainerTokenIdentifier(container.GetContainerId (), string.Empty, string.Empty, null, currentTime + 2000, masterKey.GetKeyId(), currentTime, Priority.NewInstance(0), 0); this.containerTokenIdentifierMap[identifier.GetContainerID()] = identifier; this.context.GetContainerTokenSecretManager().StartContainerSuccessful(identifier ); NUnit.Framework.Assert.IsFalse(this.context.GetContainerTokenSecretManager().IsValidStartContainerRequest (identifier)); } this.dispatcher.Start(); }
public void Set_PrivateMember_DoesntThrowException() { var privateMember = typeof(SingleReadonlyClass).GetMember("PrivateField", BindingFlags.NonPublic | BindingFlags.Instance).First(); Assert.Throws <BuilderException>(() => new Builder().AfterConstructionOf( BuilderUtils.GetMemberSetter <object, int>(privateMember, null, false))); }
public void Equality_SameObject_PropertyComparison() { var property1Property = typeof(GenericClassChild1).GetProperty("Property1"); var property1Member = BuilderUtils.GetMemberSetter <object, object>(property1Property, (o, b, s) => null, true); var property2Property = typeof(GenericClassChild1).GetProperty("Property1"); Assert.IsTrue(property1Member.IsForMember(property2Property, null, null)); }
public void InheritedProperty_ChildNotForParent() { var inheritedProperty = typeof(InheritsFromClassWithNullableDateTime).GetProperty("Property1"); var parentProperty = typeof(ClassWithNullableDateTime).GetProperty("Property1"); var inheritedMember = BuilderUtils.GetMemberSetter <InheritsFromClassWithNullableDateTime, object>(inheritedProperty, (o, b, s) => null, true); Assert.IsFalse(inheritedMember.IsForMember(parentProperty, null, null)); }
public void ConnectShapes(ShapeWrapper shapeFrom, ShapeWrapper shapeTo, NodesBranchRelation nodesBranchRelation = NodesBranchRelation.SAME_BRANCH) { var connectionType = BuilderUtils.DefineConnectionType(shapeFrom, shapeTo, nodesBranchRelation); var connectorMaster = GetConnectionMasterFromConnectionType(connectionType, nodesBranchRelation); BuilderUtils.GetCellsAlignsFromConnectionType(out var connectionFromType, out var connectionToType, connectionType); ConnectWithDynamicGlueAndConnector(shapeFrom, shapeTo, connectorMaster, connectionFromType, connectionToType); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> public static void StartContainer(NodeManager nm, ContainerId cId, FileContext localFS , FilePath scriptFileDir, FilePath processStartFile) { FilePath scriptFile = CreateUnhaltingScriptFile(cId, scriptFileDir, processStartFile ); ContainerLaunchContext containerLaunchContext = recordFactory.NewRecordInstance <ContainerLaunchContext >(); NodeId nodeId = BuilderUtils.NewNodeId(Sharpen.Extensions.GetAddressByName("localhost" ).ToString(), 12345); URL localResourceUri = ConverterUtils.GetYarnUrlFromPath(localFS.MakeQualified(new Path(scriptFile.GetAbsolutePath()))); LocalResource localResource = recordFactory.NewRecordInstance <LocalResource>(); localResource.SetResource(localResourceUri); localResource.SetSize(-1); localResource.SetVisibility(LocalResourceVisibility.Application); localResource.SetType(LocalResourceType.File); localResource.SetTimestamp(scriptFile.LastModified()); string destinationFile = "dest_file"; IDictionary <string, LocalResource> localResources = new Dictionary <string, LocalResource >(); localResources[destinationFile] = localResource; containerLaunchContext.SetLocalResources(localResources); IList <string> commands = Arrays.AsList(Shell.GetRunScriptCommand(scriptFile)); containerLaunchContext.SetCommands(commands); IPEndPoint containerManagerBindAddress = NetUtils.CreateSocketAddrForHost("127.0.0.1" , 12345); UserGroupInformation currentUser = UserGroupInformation.CreateRemoteUser(cId.ToString ()); Org.Apache.Hadoop.Security.Token.Token <NMTokenIdentifier> nmToken = ConverterUtils .ConvertFromYarn(nm.GetNMContext().GetNMTokenSecretManager().CreateNMToken(cId.GetApplicationAttemptId (), nodeId, user), containerManagerBindAddress); currentUser.AddToken(nmToken); ContainerManagementProtocol containerManager = currentUser.DoAs(new _PrivilegedAction_229 ()); StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext , TestContainerManager.CreateContainerToken(cId, 0, nodeId, user, nm.GetNMContext ().GetContainerTokenSecretManager())); IList <StartContainerRequest> list = new AList <StartContainerRequest>(); list.AddItem(scRequest); StartContainersRequest allRequests = StartContainersRequest.NewInstance(list); containerManager.StartContainers(allRequests); IList <ContainerId> containerIds = new AList <ContainerId>(); containerIds.AddItem(cId); GetContainerStatusesRequest request = GetContainerStatusesRequest.NewInstance(containerIds ); ContainerStatus containerStatus = containerManager.GetContainerStatuses(request). GetContainerStatuses()[0]; NUnit.Framework.Assert.AreEqual(ContainerState.Running, containerStatus.GetState( )); }
public void InheritedProperty_NotForSibling() { var child1Property = typeof(ClassChild1).GetProperty("Property1"); var child1PropertyMember = BuilderUtils.GetMemberSetter <ClassChild1, object>(child1Property, (o, b, s) => null, true); var child2Property = typeof(ClassChild2).GetProperty("Property1"); Assert.IsFalse(child1PropertyMember.IsForMember(child2Property, null, null)); }