public virtual void TestInvalidValidWhenOldRemoved()
        {
            AMRMClientImpl <AMRMClient.ContainerRequest> client = new AMRMClientImpl <AMRMClient.ContainerRequest
                                                                                      >();
            Configuration conf = new Configuration();

            conf.SetClass(CommonConfigurationKeysPublic.NetTopologyNodeSwitchMappingImplKey,
                          typeof(TestAMRMClientContainerRequest.MyResolver), typeof(DNSToSwitchMapping));
            client.Init(conf);
            Resource capability = Resource.NewInstance(1024, 1);

            AMRMClient.ContainerRequest request1 = new AMRMClient.ContainerRequest(capability
                                                                                   , new string[] { "host1", "host2" }, null, Priority.NewInstance(1), false);
            client.AddContainerRequest(request1);
            client.RemoveContainerRequest(request1);
            AMRMClient.ContainerRequest request2 = new AMRMClient.ContainerRequest(capability
                                                                                   , new string[] { "host3" }, null, Priority.NewInstance(1), true);
            client.AddContainerRequest(request2);
            client.RemoveContainerRequest(request2);
            AMRMClient.ContainerRequest request3 = new AMRMClient.ContainerRequest(capability
                                                                                   , new string[] { "host1", "host2" }, null, Priority.NewInstance(1), false);
            client.AddContainerRequest(request3);
            client.RemoveContainerRequest(request3);
            AMRMClient.ContainerRequest request4 = new AMRMClient.ContainerRequest(capability
                                                                                   , null, new string[] { "rack1" }, Priority.NewInstance(1), true);
            client.AddContainerRequest(request4);
        }
Example #2
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        private ICollection <Container> AllocateContainers(AMRMClientImpl <AMRMClient.ContainerRequest
                                                                           > rmClient, int num)
        {
            // setup container request
            Resource capability = Resource.NewInstance(1024, 0);
            Priority priority   = Priority.NewInstance(0);
            string   node       = nodeReports[0].GetNodeId().GetHost();
            string   rack       = nodeReports[0].GetRackName();

            string[] nodes = new string[] { node };
            string[] racks = new string[] { rack };
            for (int i = 0; i < num; ++i)
            {
                rmClient.AddContainerRequest(new AMRMClient.ContainerRequest(capability, nodes, racks
                                                                             , priority));
            }
            int containersRequestedAny = rmClient.remoteRequestsTable[priority][ResourceRequest
                                                                                .Any][capability].remoteRequest.GetNumContainers();
            // RM should allocate container within 2 calls to allocate()
            int allocatedContainerCount        = 0;
            int iterationsLeft                 = 2;
            ICollection <Container> containers = new TreeSet <Container>();

            while (allocatedContainerCount < containersRequestedAny && iterationsLeft > 0)
            {
                AllocateResponse allocResponse = rmClient.Allocate(0.1f);
                allocatedContainerCount += allocResponse.GetAllocatedContainers().Count;
                foreach (Container container in allocResponse.GetAllocatedContainers())
                {
                    containers.AddItem(container);
                }
                if (!allocResponse.GetNMTokens().IsEmpty())
                {
                    foreach (NMToken token in allocResponse.GetNMTokens())
                    {
                        rmClient.GetNMTokenCache().SetToken(token.GetNodeId().ToString(), token.GetToken(
                                                                ));
                    }
                }
                if (allocatedContainerCount < containersRequestedAny)
                {
                    // sleep to let NM's heartbeat to RM and trigger allocations
                    Sleep(1000);
                }
                --iterationsLeft;
            }
            return(containers);
        }
        public virtual void TestDisableLocalityRelaxation()
        {
            AMRMClientImpl <AMRMClient.ContainerRequest> client = new AMRMClientImpl <AMRMClient.ContainerRequest
                                                                                      >();
            Configuration conf = new Configuration();

            conf.SetClass(CommonConfigurationKeysPublic.NetTopologyNodeSwitchMappingImplKey,
                          typeof(TestAMRMClientContainerRequest.MyResolver), typeof(DNSToSwitchMapping));
            client.Init(conf);
            Resource capability = Resource.NewInstance(1024, 1);

            AMRMClient.ContainerRequest nodeLevelRequest = new AMRMClient.ContainerRequest(capability
                                                                                           , new string[] { "host1", "host2" }, null, Priority.NewInstance(1), false);
            client.AddContainerRequest(nodeLevelRequest);
            VerifyResourceRequest(client, nodeLevelRequest, ResourceRequest.Any, false);
            VerifyResourceRequest(client, nodeLevelRequest, "/rack1", false);
            VerifyResourceRequest(client, nodeLevelRequest, "host1", true);
            VerifyResourceRequest(client, nodeLevelRequest, "host2", true);
            // Make sure we don't get any errors with two node-level requests at the
            // same priority
            AMRMClient.ContainerRequest nodeLevelRequest2 = new AMRMClient.ContainerRequest(capability
                                                                                            , new string[] { "host2", "host3" }, null, Priority.NewInstance(1), false);
            client.AddContainerRequest(nodeLevelRequest2);
            AMRMClient.ContainerRequest rackLevelRequest = new AMRMClient.ContainerRequest(capability
                                                                                           , null, new string[] { "/rack3", "/rack4" }, Priority.NewInstance(2), false);
            client.AddContainerRequest(rackLevelRequest);
            VerifyResourceRequest(client, rackLevelRequest, ResourceRequest.Any, false);
            VerifyResourceRequest(client, rackLevelRequest, "/rack3", true);
            VerifyResourceRequest(client, rackLevelRequest, "/rack4", true);
            // Make sure we don't get any errors with two rack-level requests at the
            // same priority
            AMRMClient.ContainerRequest rackLevelRequest2 = new AMRMClient.ContainerRequest(capability
                                                                                            , null, new string[] { "/rack4", "/rack5" }, Priority.NewInstance(2), false);
            client.AddContainerRequest(rackLevelRequest2);
            AMRMClient.ContainerRequest bothLevelRequest = new AMRMClient.ContainerRequest(capability
                                                                                           , new string[] { "host3", "host4" }, new string[] { "rack1", "/otherrack" }, Priority
                                                                                           .NewInstance(3), false);
            client.AddContainerRequest(bothLevelRequest);
            VerifyResourceRequest(client, bothLevelRequest, ResourceRequest.Any, false);
            VerifyResourceRequest(client, bothLevelRequest, "rack1", true);
            VerifyResourceRequest(client, bothLevelRequest, "/otherrack", true);
            VerifyResourceRequest(client, bothLevelRequest, "host3", true);
            VerifyResourceRequest(client, bothLevelRequest, "host4", true);
            // Make sure we don't get any errors with two both-level requests at the
            // same priority
            AMRMClient.ContainerRequest bothLevelRequest2 = new AMRMClient.ContainerRequest(capability
                                                                                            , new string[] { "host4", "host5" }, new string[] { "rack1", "/otherrack2" }, Priority
                                                                                            .NewInstance(3), false);
            client.AddContainerRequest(bothLevelRequest2);
        }
        public virtual void TestFillInRacks()
        {
            AMRMClientImpl <AMRMClient.ContainerRequest> client = new AMRMClientImpl <AMRMClient.ContainerRequest
                                                                                      >();
            Configuration conf = new Configuration();

            conf.SetClass(CommonConfigurationKeysPublic.NetTopologyNodeSwitchMappingImplKey,
                          typeof(TestAMRMClientContainerRequest.MyResolver), typeof(DNSToSwitchMapping));
            client.Init(conf);
            Resource capability = Resource.NewInstance(1024, 1);

            AMRMClient.ContainerRequest request = new AMRMClient.ContainerRequest(capability,
                                                                                  new string[] { "host1", "host2" }, new string[] { "/rack2" }, Priority.NewInstance
                                                                                      (1));
            client.AddContainerRequest(request);
            VerifyResourceRequest(client, request, "host1", true);
            VerifyResourceRequest(client, request, "host2", true);
            VerifyResourceRequest(client, request, "/rack1", true);
            VerifyResourceRequest(client, request, "/rack2", true);
            VerifyResourceRequest(client, request, ResourceRequest.Any, true);
        }