Esempio n. 1
0
        public string[] GetSkeletonBoneNames()
        {
            JSONArray array = json.GetJSONObject("skeleton").GetJSONArray("bones");
            int       size  = array.Length();

            string[] result = new string[size];
            for (int i = 0; i < size; ++i)
            {
                result[i] = array.GetJSONObject(i).GetString("name");
            }
            return(result);
        }
Esempio n. 2
0
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        /// <exception cref="System.Exception"/>
        private void VerifyClusterScheduler(JSONObject json)
        {
            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject info = json.GetJSONObject("scheduler");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, info.Length());
            info = info.GetJSONObject("schedulerInfo");
            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 2, info.Length());
            JSONObject rootQueue = info.GetJSONObject("rootQueue");

            NUnit.Framework.Assert.AreEqual("root", rootQueue.GetString("queueName"));
        }
Esempio n. 3
0
        public virtual void TestTaskAttemptIdCounters()
        {
            WebResource r = Resource();
            IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext
                                                                                      .GetAllJobs();

            foreach (JobId id in jobsMap.Keys)
            {
                string jobId = MRApps.ToString(id);
                foreach (Task task in jobsMap[id].GetTasks().Values)
                {
                    string tid = MRApps.ToString(task.GetID());
                    foreach (TaskAttempt att in task.GetAttempts().Values)
                    {
                        TaskAttemptId  attemptid = att.GetID();
                        string         attid     = MRApps.ToString(attemptid);
                        ClientResponse response  = r.Path("ws").Path("v1").Path("history").Path("mapreduce"
                                                                                                ).Path("jobs").Path(jobId).Path("tasks").Path(tid).Path("attempts").Path(attid).
                                                   Path("counters").Accept(MediaType.ApplicationJson).Get <ClientResponse>();
                        NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                                        );
                        JSONObject json = response.GetEntity <JSONObject>();
                        NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
                        JSONObject info = json.GetJSONObject("jobTaskAttemptCounters");
                        VerifyHsJobTaskAttemptCounters(info, att);
                    }
                }
            }
        }
Esempio n. 4
0
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        public virtual void VerifyHsTaskAttempts(JSONObject json, Task task)
        {
            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject attempts = json.GetJSONObject("taskAttempts");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONArray arr = attempts.GetJSONArray("taskAttempt");

            foreach (TaskAttempt att in task.GetAttempts().Values)
            {
                TaskAttemptId id    = att.GetID();
                string        attid = MRApps.ToString(id);
                bool          found = false;
                for (int i = 0; i < arr.Length(); i++)
                {
                    JSONObject info = arr.GetJSONObject(i);
                    if (attid.Matches(info.GetString("id")))
                    {
                        found = true;
                        VerifyHsTaskAttempt(info, att, task.GetType());
                    }
                }
                NUnit.Framework.Assert.IsTrue("task attempt with id: " + attid + " not in web service output"
                                              , found);
            }
        }
Esempio n. 5
0
        public virtual void TestMultipleContainers()
        {
            ApplicationId        appId        = ApplicationId.NewInstance(0, 1);
            ApplicationAttemptId appAttemptId = ApplicationAttemptId.NewInstance(appId, 1);
            WebResource          r            = Resource();
            ClientResponse       response     = r.Path("ws").Path("v1").Path("applicationhistory").Path
                                                    ("apps").Path(appId.ToString()).Path("appattempts").Path(appAttemptId.ToString()
                                                                                                             ).Path("containers").QueryParam("user.name", Users[round]).Accept(MediaType.ApplicationJson
                                                                                                                                                                               ).Get <ClientResponse>();

            if (round == 1)
            {
                NUnit.Framework.Assert.AreEqual(ClientResponse.Status.Forbidden, response.GetClientResponseStatus
                                                    ());
                return;
            }
            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject containers = json.GetJSONObject("containers");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, containers.Length
                                                ());
            JSONArray array = containers.GetJSONArray("container");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 5, array.Length()
                                            );
        }
Esempio n. 6
0
 private string getVideoConstraints(string mediaConstraintsString)
 {
     try
     {
         JSONObject json = new JSONObject(mediaConstraintsString);
         // Tricksy handling of values that are allowed to be (boolean or
         // MediaTrackConstraints) by the getUserMedia() spec.  There are three
         // cases below.
         if (!json.Has("video") || !json.OptBoolean("video", true))
         {
             // Case 1: "video" is not present, or is an explicit "false" boolean.
             return(null);
         }
         if (json.OptBoolean("video", false))
         {
             // Case 2: "video" is an explicit "true" boolean.
             return("{\"mandatory\": {}, \"optional\": []}");
         }
         // Case 3: "video" is an object.
         return(json.GetJSONObject("video").ToString());
     }
     catch (JSONException e)
     {
         throw new Exception("Error", e);
     }
 }
        public virtual void TestNodeAppsStateInvalidDefault()
        {
            WebResource r = Resource();

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = new MockApp(1);
            nmContext.GetApplications()[app.GetAppId()] = app;
            AddAppContainers(app);
            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app2 = new MockApp("foo", 1234, 2);
            nmContext.GetApplications()[app2.GetAppId()] = app2;
            AddAppContainers(app2);
            try
            {
                r.Path("ws").Path("v1").Path("node").Path("apps").QueryParam("state", "FOO_STATE"
                                                                             ).Get <JSONObject>();
                NUnit.Framework.Assert.Fail("should have thrown exception on invalid user query");
            }
            catch (UniformInterfaceException ue)
            {
                ClientResponse response = ue.GetResponse();
                NUnit.Framework.Assert.AreEqual(ClientResponse.Status.BadRequest, response.GetClientResponseStatus
                                                    ());
                NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                                );
                JSONObject msg       = response.GetEntity <JSONObject>();
                JSONObject exception = msg.GetJSONObject("RemoteException");
                NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length
                                                    ());
                string message   = exception.GetString("message");
                string type      = exception.GetString("exception");
                string classname = exception.GetString("javaClassName");
                VerifyStateInvalidException(message, type, classname);
            }
        }
        public virtual void TestQueryAll()
        {
            WebResource r   = Resource();
            MockNM      nm1 = rm.RegisterNode("h1:1234", 5120);
            MockNM      nm2 = rm.RegisterNode("h2:1235", 5121);
            MockNM      nm3 = rm.RegisterNode("h3:1236", 5122);

            rm.SendNodeStarted(nm1);
            rm.SendNodeStarted(nm3);
            rm.NMwaitForState(nm1.GetNodeId(), NodeState.Running);
            rm.NMwaitForState(nm2.GetNodeId(), NodeState.New);
            rm.SendNodeLost(nm3);
            ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").QueryParam
                                          ("states", Joiner.On(',').Join(EnumSet.AllOf <NodeState>())).Accept(MediaType.ApplicationJson
                                                                                                              ).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json  = response.GetEntity <JSONObject>();
            JSONObject nodes = json.GetJSONObject("nodes");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodes.Length()
                                            );
            JSONArray nodeArray = nodes.GetJSONArray("node");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, nodeArray.Length
                                                ());
        }
        public virtual void TestSingleNodeQueryStateLost()
        {
            WebResource r   = Resource();
            MockNM      nm1 = rm.RegisterNode("h1:1234", 5120);
            MockNM      nm2 = rm.RegisterNode("h2:1234", 5120);

            rm.SendNodeStarted(nm1);
            rm.SendNodeStarted(nm2);
            rm.NMwaitForState(nm1.GetNodeId(), NodeState.Running);
            rm.NMwaitForState(nm2.GetNodeId(), NodeState.Running);
            rm.SendNodeLost(nm1);
            rm.SendNodeLost(nm2);
            ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").Path
                                          ("h2:1234").Accept(MediaType.ApplicationJson).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();
            JSONObject info = json.GetJSONObject("node");
            string     id   = info.Get("id").ToString();

            NUnit.Framework.Assert.AreEqual("Incorrect Node Information.", "h2:1234", id);
            RMNode rmNode = rm.GetRMContext().GetInactiveRMNodes()["h2"];

            WebServicesTestUtils.CheckStringMatch("nodeHTTPAddress", string.Empty, info.GetString
                                                      ("nodeHTTPAddress"));
            WebServicesTestUtils.CheckStringMatch("state", rmNode.GetState().ToString(), info
                                                  .GetString("state"));
        }
Esempio n. 10
0
        public virtual void TestJobsQueryState()
        {
            WebResource r = Resource();
            // we only create 3 jobs and it cycles through states so we should have 3 unique states
            IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext
                                                                                      .GetAllJobs();
            string queryState = "BOGUS";
            JobId  jid        = null;

            foreach (KeyValuePair <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> entry in
                     jobsMap)
            {
                jid        = entry.Value.GetID();
                queryState = entry.Value.GetState().ToString();
                break;
            }
            ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce"
                                                                                   ).Path("jobs").QueryParam("state", queryState).Accept(MediaType.ApplicationJson)
                                      .Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject jobs = json.GetJSONObject("jobs");
            JSONArray  arr  = jobs.GetJSONArray("job");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, arr.Length());
            JSONObject info = arr.GetJSONObject(0);

            Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job = appContext.GetPartialJob(jid);
            VerifyJobsUtils.VerifyHsJobPartial(info, job);
        }
Esempio n. 11
0
        public virtual void TestJobsQueryStateInvalid()
        {
            WebResource    r        = Resource();
            ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce"
                                                                                   ).Path("jobs").QueryParam("state", "InvalidState").Accept(MediaType.ApplicationJson
                                                                                                                                             ).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(ClientResponse.Status.BadRequest, response.GetClientResponseStatus
                                                ());
            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject msg       = response.GetEntity <JSONObject>();
            JSONObject exception = msg.GetJSONObject("RemoteException");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length
                                                ());
            string message   = exception.GetString("message");
            string type      = exception.GetString("exception");
            string classname = exception.GetString("javaClassName");

            WebServicesTestUtils.CheckStringContains("exception message", "org.apache.hadoop.mapreduce.v2.api.records.JobState.InvalidState"
                                                     , message);
            WebServicesTestUtils.CheckStringMatch("exception type", "IllegalArgumentException"
                                                  , type);
            WebServicesTestUtils.CheckStringMatch("exception classname", "java.lang.IllegalArgumentException"
                                                  , classname);
        }
Esempio n. 12
0
        /*****************************    读取Json数据             *************************/
        private bool readJson(String arrayData)
        {
            try
            {
                dictData.Clear();

                protocolNumber = (int)TCPPROTOCOL.INVALID;

                JSONObject jsonObject = new JSONObject(arrayData);

                JSONObject jsonData = jsonObject.GetJSONObject("data");

                foreach (String key in jsonData.GetKeys())
                {
                    dictData[key] = jsonData.GetString(key);
                }

                protocolNumber = Convert.ToInt32(dictData["protocol"]);

                dictData.Remove("protocol");

                return(true);
            }
            catch (JSONException e)
            {
                return(false);
            }
        }
Esempio n. 13
0
        public virtual void TestJobsQueryFinishTimeEndInvalidformat()
        {
            WebResource    r        = Resource();
            ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce"
                                                                                   ).Path("jobs").QueryParam("finishedTimeEnd", "efsd").Accept(MediaType.ApplicationJson
                                                                                                                                               ).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(ClientResponse.Status.BadRequest, response.GetClientResponseStatus
                                                ());
            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject msg       = response.GetEntity <JSONObject>();
            JSONObject exception = msg.GetJSONObject("RemoteException");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length
                                                ());
            string message   = exception.GetString("message");
            string type      = exception.GetString("exception");
            string classname = exception.GetString("javaClassName");

            WebServicesTestUtils.CheckStringMatch("exception message", "java.lang.Exception: Invalid number format: For input string: \"efsd\""
                                                  , message);
            WebServicesTestUtils.CheckStringMatch("exception type", "BadRequestException", type
                                                  );
            WebServicesTestUtils.CheckStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException"
                                                  , classname);
        }
Esempio n. 14
0
        public virtual void TestJobsQueryFinishTimeBeginEnd()
        {
            WebResource r = Resource();
            IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext
                                                                                      .GetAllJobs();
            int size = jobsMap.Count;
            // figure out the mid end time - we expect atleast 3 jobs
            AList <long> finishTime = new AList <long>(size);

            foreach (KeyValuePair <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> entry in
                     jobsMap)
            {
                finishTime.AddItem(entry.Value.GetReport().GetFinishTime());
            }
            finishTime.Sort();
            NUnit.Framework.Assert.IsTrue("Error we must have atleast 3 jobs", size >= 3);
            long           midFinishTime = finishTime[size - 2];
            ClientResponse response      = r.Path("ws").Path("v1").Path("history").Path("mapreduce"
                                                                                        ).Path("jobs").QueryParam("finishedTimeBegin", 40000.ToString()).QueryParam("finishedTimeEnd"
                                                                                                                                                                    , midFinishTime.ToString()).Accept(MediaType.ApplicationJson).Get <ClientResponse
                                                                                                                                                                                                                                       >();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject jobs = json.GetJSONObject("jobs");
            JSONArray  arr  = jobs.GetJSONArray("job");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", size - 1, arr.Length
                                                ());
        }
        public async void FindRouteAsync(string source, string destrination) // radi sa primerom https://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&mode=transit&key=AIzaSyDY8RF7Oa9h5IeD7DX6l_GtGPnjT6J7k4U
        {
            client = new HttpClient();
            // string default_for_every_query = "https://maps.googleapis.com/maps/api/directions/json?";

            HttpResponseMessage response = await client.GetAsync("https://maps.googleapis.com/maps/api/directions/json?origin=" + source + "&destination=" + destrination + "&mode=transit&key=AIzaSyDY8RF7Oa9h5IeD7DX6l_GtGPnjT6J7k4U");

            if (response.StatusCode == HttpStatusCode.OK)
            {
                HttpContent content = response.Content;
                var         json    = await content.ReadAsStringAsync();

                Console.WriteLine(json.ToString());

                JSONObject    jsonresoult       = new JSONObject(json);
                JSONArray     routesArray       = jsonresoult.GetJSONArray("routes");
                JSONObject    routes            = routesArray.GetJSONObject(0);
                JSONObject    overviewPolylines = routes.GetJSONObject("overview_polyline");
                String        encodedString     = overviewPolylines.GetString("points");
                List <LatLng> list = decodePoly(encodedString);

                PolylineOptions po = new PolylineOptions();
                //treba i < list.Count zasto puca sa tim?

                for (int i = 0; i < list.Count; i++)
                {
                    po.Add(list[i]).InvokeWidth(10).InvokeColor(0x66FF0000);//red color
                }

                gmap.AddPolyline(po);
            }
        }
        public virtual void TestNonexistNodeDefault()
        {
            rm.RegisterNode("h1:1234", 5120);
            rm.RegisterNode("h2:1235", 5121);
            WebResource r = Resource();

            try
            {
                r.Path("ws").Path("v1").Path("cluster").Path("nodes").Path("node_invalid:99").Get
                <JSONObject>();
                NUnit.Framework.Assert.Fail("should have thrown exception on non-existent nodeid"
                                            );
            }
            catch (UniformInterfaceException ue)
            {
                ClientResponse response = ue.GetResponse();
                NUnit.Framework.Assert.AreEqual(ClientResponse.Status.NotFound, response.GetClientResponseStatus
                                                    ());
                NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                                );
                JSONObject msg       = response.GetEntity <JSONObject>();
                JSONObject exception = msg.GetJSONObject("RemoteException");
                NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length
                                                    ());
                string message   = exception.GetString("message");
                string type      = exception.GetString("exception");
                string classname = exception.GetString("javaClassName");
                VerifyNonexistNodeException(message, type, classname);
            }
            finally
            {
                rm.Stop();
            }
        }
Esempio n. 17
0
        public virtual void TestNodeAppsState()
        {
            WebResource r = Resource();

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = new MockApp(1);
            nmContext.GetApplications()[app.GetAppId()] = app;
            AddAppContainers(app);
            MockApp app2 = new MockApp("foo", 1234, 2);

            nmContext.GetApplications()[app2.GetAppId()] = app2;
            Dictionary <string, string> hash2 = AddAppContainers(app2);

            app2.SetState(ApplicationState.Running);
            ClientResponse response = r.Path("ws").Path("v1").Path("node").Path("apps").QueryParam
                                          ("state", ApplicationState.Running.ToString()).Accept(MediaType.ApplicationJson)
                                      .Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();
            JSONObject info = json.GetJSONObject("apps");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, info.Length());
            JSONArray appInfo = info.GetJSONArray("app");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, appInfo.Length
                                                ());
            VerifyNodeAppInfo(appInfo.GetJSONObject(0), app2, hash2);
        }
        public virtual void TestNodesQueryNew()
        {
            WebResource r   = Resource();
            MockNM      nm1 = rm.RegisterNode("h1:1234", 5120);
            MockNM      nm2 = rm.RegisterNode("h2:1235", 5121);

            rm.SendNodeStarted(nm1);
            rm.NMwaitForState(nm1.GetNodeId(), NodeState.Running);
            rm.NMwaitForState(nm2.GetNodeId(), NodeState.New);
            ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").QueryParam
                                          ("states", NodeState.New.ToString()).Accept(MediaType.ApplicationJson).Get <ClientResponse
                                                                                                                      >();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject nodes = json.GetJSONObject("nodes");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodes.Length()
                                            );
            JSONArray nodeArray = nodes.GetJSONArray("node");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodeArray.Length
                                                ());
            JSONObject info = nodeArray.GetJSONObject(0);

            VerifyNodeInfo(info, nm2);
        }
Esempio n. 19
0
        public void ParseMapJsonData(List <MapDownloadResource> maps, Dictionary <String, String> mapsItemsCodes, Dictionary <String, String> regionItemsCodes, InputStream inputStream)
        {
            Console.WriteLine("Catalin ; start parsing !!!");
            long       startTime    = DemoUtils.CurrentTimeMillis();
            JSONObject reader       = new JSONObject(convertJSONFileContentToAString(inputStream));
            JSONArray  regionsArray = reader.GetJSONArray(REGIONS_ID);

            if (regionsArray != null)
            {
                readUSRegionsHierarchy(regionItemsCodes, regionsArray);
            }
            JSONArray packagesArray = reader.GetJSONArray(PACKAGES_ID);

            if (packagesArray != null)
            {
                readMapsPackages(maps, packagesArray);
            }
            JSONObject worldObject = reader.GetJSONObject(WORLD_ID);

            if (worldObject != null)
            {
                JSONArray continentsArray = worldObject.GetJSONArray(CONTINENTS_ID);
                if (continentsArray != null)
                {
                    readWorldHierarchy(mapsItemsCodes, continentsArray);
                }
            }

            /*-for (Map.Entry<String, String> currentEntry : mapsItemsCodes.entrySet()) {
             *  System.out.println("Catalin ; key = " + currentEntry.getKey() + " ; value = " + currentEntry.getValue());
             * }*/
            Console.WriteLine("Catalin ; total loading time = " + (DemoUtils.CurrentTimeMillis() - startTime) + " ; maps size = " + maps.Count);
        }
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestNodeHelper(string path, string media)
        {
            WebResource r = Resource();

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = new MockApp(1);
            nmContext.GetApplications()[app.GetAppId()] = app;
            AddAppContainers(app);
            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app2 = new MockApp(2);
            nmContext.GetApplications()[app2.GetAppId()] = app2;
            AddAppContainers(app2);
            ClientResponse response = r.Path("ws").Path("v1").Path("node").Path(path).Accept(
                media).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();
            JSONObject info = json.GetJSONObject("containers");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, info.Length());
            JSONArray conInfo = info.GetJSONArray("container");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 4, conInfo.Length
                                                ());
            for (int i = 0; i < conInfo.Length(); i++)
            {
                VerifyNodeContainerInfo(conInfo.GetJSONObject(i), nmContext.GetContainers()[ConverterUtils
                                                                                            .ToContainerId(conInfo.GetJSONObject(i).GetString("id"))]);
            }
        }
Esempio n. 21
0
        public virtual void TestSingleApp()
        {
            ApplicationId  appId    = ApplicationId.NewInstance(0, 1);
            WebResource    r        = Resource();
            ClientResponse response = r.Path("ws").Path("v1").Path("applicationhistory").Path
                                          ("apps").Path(appId.ToString()).QueryParam("user.name", Users[round]).Accept(MediaType
                                                                                                                       .ApplicationJson).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject app = json.GetJSONObject("app");

            NUnit.Framework.Assert.AreEqual(appId.ToString(), app.GetString("appId"));
            NUnit.Framework.Assert.AreEqual("test app", app.Get("name"));
            NUnit.Framework.Assert.AreEqual(round == 0 ? "test diagnostics info" : string.Empty
                                            , app.Get("diagnosticsInfo"));
            NUnit.Framework.Assert.AreEqual("test queue", app.Get("queue"));
            NUnit.Framework.Assert.AreEqual("user1", app.Get("user"));
            NUnit.Framework.Assert.AreEqual("test app type", app.Get("type"));
            NUnit.Framework.Assert.AreEqual(FinalApplicationStatus.Undefined.ToString(), app.
                                            Get("finalAppStatus"));
            NUnit.Framework.Assert.AreEqual(YarnApplicationState.Finished.ToString(), app.Get
                                                ("appState"));
        }
Esempio n. 22
0
        public virtual void TestSingleAttempt()
        {
            ApplicationId        appId        = ApplicationId.NewInstance(0, 1);
            ApplicationAttemptId appAttemptId = ApplicationAttemptId.NewInstance(appId, 1);
            WebResource          r            = Resource();
            ClientResponse       response     = r.Path("ws").Path("v1").Path("applicationhistory").Path
                                                    ("apps").Path(appId.ToString()).Path("appattempts").Path(appAttemptId.ToString()
                                                                                                             ).QueryParam("user.name", Users[round]).Accept(MediaType.ApplicationJson).Get <ClientResponse
                                                                                                                                                                                            >();

            if (round == 1)
            {
                NUnit.Framework.Assert.AreEqual(ClientResponse.Status.Forbidden, response.GetClientResponseStatus
                                                    ());
                return;
            }
            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject appAttempt = json.GetJSONObject("appAttempt");

            NUnit.Framework.Assert.AreEqual(appAttemptId.ToString(), appAttempt.GetString("appAttemptId"
                                                                                          ));
            NUnit.Framework.Assert.AreEqual("test host", appAttempt.GetString("host"));
            NUnit.Framework.Assert.AreEqual("test diagnostics info", appAttempt.GetString("diagnosticsInfo"
                                                                                          ));
            NUnit.Framework.Assert.AreEqual("test tracking url", appAttempt.GetString("trackingUrl"
                                                                                      ));
            NUnit.Framework.Assert.AreEqual(YarnApplicationAttemptState.Finished.ToString(),
                                            appAttempt.Get("appAttemptState"));
        }
Esempio n. 23
0
        public virtual void TestJobsQueryStartTimeNegative()
        {
            WebResource    r        = Resource();
            ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce"
                                                                                   ).Path("jobs").QueryParam("startedTimeBegin", (-1000).ToString()).Accept(MediaType
                                                                                                                                                            .ApplicationJson).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(ClientResponse.Status.BadRequest, response.GetClientResponseStatus
                                                ());
            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject msg       = response.GetEntity <JSONObject>();
            JSONObject exception = msg.GetJSONObject("RemoteException");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length
                                                ());
            string message   = exception.GetString("message");
            string type      = exception.GetString("exception");
            string classname = exception.GetString("javaClassName");

            WebServicesTestUtils.CheckStringMatch("exception message", "java.lang.Exception: startedTimeBegin must be greater than 0"
                                                  , message);
            WebServicesTestUtils.CheckStringMatch("exception type", "BadRequestException", type
                                                  );
            WebServicesTestUtils.CheckStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException"
                                                  , classname);
        }
 public virtual void TestPerUserResourcesJSON()
 {
     //Start RM so that it accepts app submissions
     rm.Start();
     try
     {
         rm.SubmitApp(10, "app1", "user1", null, "b1");
         rm.SubmitApp(20, "app2", "user2", null, "b1");
         //Get JSON
         WebResource    r        = Resource();
         ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("scheduler/"
                                                                                ).Accept(MediaType.ApplicationJson).Get <ClientResponse>();
         NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                         );
         JSONObject json          = response.GetEntity <JSONObject>();
         JSONObject schedulerInfo = json.GetJSONObject("scheduler").GetJSONObject("schedulerInfo"
                                                                                  );
         JSONObject b1 = GetSubQueue(GetSubQueue(schedulerInfo, "b"), "b1");
         //Check users user1 and user2 exist in b1
         JSONArray users = b1.GetJSONObject("users").GetJSONArray("user");
         for (int i = 0; i < 2; ++i)
         {
             JSONObject user = users.GetJSONObject(i);
             NUnit.Framework.Assert.IsTrue("User isn't user1 or user2", user.GetString("username"
                                                                                       ).Equals("user1") || user.GetString("username").Equals("user2"));
             user.GetInt("numActiveApplications");
             user.GetInt("numPendingApplications");
             CheckResourcesUsed(user);
         }
     }
     finally
     {
         rm.Stop();
     }
 }
Esempio n. 25
0
 public static TcpPayload FromJson(JSONObject obj)
 {
     var payload = new TcpPayload
     {
         Contact = ContactInfo.FromJson(obj.GetJSONObject("contact")),
         Message = obj.GetString("message")
     };
     return payload;
 }
Esempio n. 26
0
        }        //contactRequest

        public String[] getUserDeets(String token)
        {
            Console.WriteLine("into the belly of it m8");
            String output = httpRequest(token, "https://www.yammer.com/api/v1/users/current.json");

            Console.WriteLine("we dun it now");
            if (output != "")
            {
                //JSONArray jObject = new JSONArray (output); // json
                String[] details;

                JSONObject data, tmp;
                //String[] items;
                String uid, fname, lname, email, phone = "", org, profilepicture;
                //maybe use less memory because im using heaps apparently

                data = new JSONObject(output);                  // get data object

                uid            = data.GetString("id");
                fname          = data.GetString("first_name");
                lname          = data.GetString("last_name");
                email          = data.GetString("email");
                profilepicture = data.GetString("mugshot_url_template");
                profilepicture = profilepicture.Replace("{width}x{height}", "300x300");

                tmp   = data.GetJSONObject("contact");
                phone = tmp.GetString("phone_numbers");

                try {
                    tmp   = new JSONArray(phone).GetJSONObject(0);
                    phone = tmp.GetString("number");
                } catch {
                    phone = "";
                }

                org = data.GetString("network_name");

                details = new String[] { fname, lname, email, phone, org, uid, profilepicture };
                tmp.Dispose();
                data.Dispose();

                fname          = "";
                lname          = "";
                email          = "";
                phone          = "";
                org            = "";
                uid            = "";
                profilepicture = "";

                //jObject.Dispose ();

                return(details);
            }
            String[] gg = null;
            return(gg);
        }        //getuserdeets
Esempio n. 27
0
        protected String OnInput(Stream _in)
        {
            StringBuilder sb      = new StringBuilder();
            Scanner       scanner = new Scanner(_in);

            while (scanner.HasNext)
            {
                sb.Append(scanner.Next());
            }

            JSONObject root       = new JSONObject(sb.ToString());
            String     id         = root.GetJSONObject("data").GetString("id");
            String     deletehash = root.GetJSONObject("data").GetString("deletehash");

            uploadLink = "http://imgur.com/" + id;

            Log.Info(TAG, "new imgur url: http://imgur.com/" + id + " (delete hash: " + deletehash + ")");
            return(id);
        }
        public void OnCompleted(JSONObject jsonObject, GraphResponse response)
        {
            var id         = string.Empty;
            var first_name = string.Empty;
            var last_name  = string.Empty;
            var email      = string.Empty;
            var pictureUrl = string.Empty;

            if (jsonObject.Has("id"))
            {
                id = jsonObject.GetString("id");
            }

            if (jsonObject.Has("first_name"))
            {
                first_name = jsonObject.GetString("first_name");
            }

            if (jsonObject.Has("last_name"))
            {
                last_name = jsonObject.GetString("last_name");
            }

            if (jsonObject.Has("email"))
            {
                email = jsonObject.GetString("email");
            }

            if (jsonObject.Has("picture"))
            {
                var picture = jsonObject.GetJSONObject("picture");
                if (picture.Has("data"))
                {
                    var data = picture.GetJSONObject("data");
                    if (data.Has("url"))
                    {
                        pictureUrl = data.GetString("url");
                    }
                }
            }

            var fbUser = new FBUser()
            {
                Id        = id,
                Email     = email,
                FirstName = first_name,
                LastName  = last_name,
                PicUrl    = pictureUrl,
                Token     = AccessToken.CurrentAccessToken.Token
            };

            _onLoginComplete?.Invoke(fbUser, string.Empty);
        }
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        /// <exception cref="System.Exception"/>
        private void VerifyClusterScheduler(JSONObject json)
        {
            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject info = json.GetJSONObject("scheduler");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, info.Length());
            info = info.GetJSONObject("schedulerInfo");
            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 6, info.Length());
            VerifyClusterSchedulerGeneric(info.GetString("type"), (float)info.GetDouble("usedCapacity"
                                                                                        ), (float)info.GetDouble("capacity"), (float)info.GetDouble("maxCapacity"), info
                                          .GetString("queueName"));
            JSONArray arr = info.GetJSONObject("queues").GetJSONArray("queue");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 2, arr.Length());
            // test subqueues
            for (int i = 0; i < arr.Length(); i++)
            {
                JSONObject obj = arr.GetJSONObject(i);
                string     q   = CapacitySchedulerConfiguration.Root + "." + obj.GetString("queueName");
                VerifySubQueue(obj, q, 100, 100);
            }
        }
Esempio n. 30
0
        public virtual void TestHS()
        {
            WebResource    r        = Resource();
            ClientResponse response = r.Path("ws").Path("v1").Path("history").Accept(MediaType
                                                                                     .ApplicationJson).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            VerifyHSInfo(json.GetJSONObject("historyInfo"), appContext);
        }