cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Han,Meng" <meng...@ufl.edu>
Subject Re: [GSoC] CloudMonkey index out of range error
Date Sun, 08 Sep 2013 23:44:12 GMT
On Fri, 6 Sep 2013 23:19:49 +0530, Rohit Yadav wrote:
> On Fri, Sep 6, 2013 at 8:54 PM, Han,Meng <menghan@ufl.edu> wrote:
>
>> On Fri, 6 Sep 2013 03:09:46 -0400, Sebastien Goasguen wrote:
>>
>>> On Aug 28, 2013, at 11:16 PM, "Han,Meng" <menghan@ufl.edu> wrote:
>>>
>>>  Hi Sebasiten,
>>>>
>>>> This type of error happens even when I define a very simple api, 
>>>> e.g.
>>>> output the whirr version.
>>>>
>>>>
>>>> 2013-08-27 17:56:48,662 - requester.py:45 - [DEBUG] ======== START
>>>> Request ========
>>>> 2013-08-27 17:56:48,662 - requester.py:45 - [DEBUG] Requesting
>>>> command=launchCluster, args={'config': '1'}
>>>> 2013-08-27 17:56:48,663 - requester.py:45 - [DEBUG] Request sent:
>>>> 
>>>> http://localhost:8080/client/**api?apiKey=**3lwqSg6E1yS4vvF37mz7HshOp_**
>>>> 3N9rHoDoXMoWsRcbaisMz5-_**WnnwgzHaAeUi49cMMtb8GbzkPzvBA3**
>>>> WEqzMw&command=launchCluster&**config=1&response=json&**
>>>> 
>>>> signature=xCb%2BX06aGT5%**2Bd0iDQR3BbIBdYhM%3D<http://localhost:8080/client/api?apiKey=3lwqSg6E1yS4vvF37mz7HshOp_3N9rHoDoXMoWsRcbaisMz5-_WnnwgzHaAeUi49cMMtb8GbzkPzvBA3WEqzMw&command=launchCluster&config=1&response=json&signature=xCb%2BX06aGT5%2Bd0iDQR3BbIBdYhM%3D>
>>>> 2013-08-27 17:56:52,254 - requester.py:45 - [DEBUG] Response 
>>>> received: {
>>>> "launchCluster" :  { "launchCluster" : {"output":"Apache Whirr
>>>> ${project.version}jclouds 1.6.1-incubatingnull"} }  }
>>>> 2013-08-27 17:56:52,254 - requester.py:45 - [DEBUG] ======== END 
>>>> Request
>>>> ========
>>>>
>>>
> Hi Han, I read the output and checked the code. The issue is with 
> your
> implementation of API and let me help you understand how it works 
> briefly
> and how you may fix it.
>
> The response object is not correct. It should send the output in a 
> response
> key. It breaks because it assumes there would be a "response" key in 
> the
> received response json. Likely the issue is incorrect use of 
> annotations in
> your response class. Please check against other API response classes, 
> the
> result should be in a key which has response word, for example:
>
> { "deployvirtualmachineresponse" :
> 
> {"id":"d795f1d5-7f2c-446a-a5a4-9e374eb96590","jobid":"8910c383-8e96-443f-b3af-6e0171b33934"}
> }
>

Hi Yadav,

Thank you very much for your replay and detailed explanation. It's true 
that I didn't define response object correctly. The cloudmonkey error  
below also point that I didn't defind the response key.
response key = filter(lambda x: 'response' in x, response.keys())[0]
>>>>>> IndexError: list index out of range

I add one sentence "response.setResponseName(getCommandName());" and 
set the Command Name to launchclusterresponse. Now the error is cleared 
:)
The json object returned is
2013-09-08 19:43:14,524 - requester.py:45 - [DEBUG] Response received: 
{ "launchclusterresponse" :  { "launchCluster" : {"output":"Apache Whirr 
${project.version}jclouds 1.6.1-incubating"} }  }


Thank you again Yadav!



> In the above response example, the serialized object is returned as 
> json,
> cloudmonkey looks for a key that has "response", in this case
> "deployvirtualmachineresponse", and outputs using one of its display
> methods (table, json or default/key-value outputs).
>
> Hope this helps.
>
> Regards.
>
>
>>
>>>> The following is the response object:
>>>>
>>>> public class LaunchClusterResponse extends BaseResponse {
>>>>    @SerializedName(ApiConstants.**IS_ASYNC) @Param(description = 
>>>> "true
>>>> if api is asynchronous")
>>>>    private Boolean isAsync;
>>>>    @SerializedName("output") @Param(description = "whirr output")
>>>>    private String output;
>>>>
>>>>    public LaunchClusterResponse(){
>>>>
>>>>    }
>>>>    public void setAsync(Boolean isAsync) {
>>>>        this.isAsync = isAsync;
>>>>    }
>>>>
>>>>    public boolean getAsync() {
>>>>        return isAsync;
>>>>    }
>>>>    public void setOutPut(String output) {
>>>>        this.output = output;
>>>>    }
>>>>     public String getOutput(){
>>>>        return output;
>>>>    }
>>>>
>>>> }
>>>>
>>>>
>>>> The following is the execute method of the command object.
>>>>
>>>> public void execute()  {
>>>>        LaunchClusterResponse response = new 
>>>> LaunchClusterResponse();
>>>>        response.setObjectName("**launchCluster");
>>>>        response.setResponseName(**getCommandName());
>>>>
>>>>        String cmdToExec;
>>>>        cmdToExec = "whirr version ";
>>>>        try {
>>>>           Process proc = Runtime.getRuntime().exec(**cmdToExec);
>>>>           BufferedReader stdInput = new BufferedReader(new
>>>> InputStreamReader(proc.**getInputStream()));
>>>>           BufferedReader stdError = new BufferedReader(new
>>>> InputStreamReader(proc.**getErrorStream()));
>>>>
>>>>           String stdout = "",stderr = "",s;
>>>>           while ((s = stdInput.readLine()) != null) {
>>>>                stdout=stdout+s;
>>>>           }
>>>>           while ((s = stdInput.readLine()) != null) {
>>>>                stderr=stderr+s;
>>>>           }
>>>>           output = stdout+stderr;
>>>>        } catch (IOException ex) {
>>>>            
>>>> Logger.getLogger(**LaunchClusterCmd.class.**getName()).log(Level.SEVERE,
>>>> null, ex);
>>>>        }
>>>>
>>>>        response.setOutPut(output);
>>>>        this.setResponseObject(**response);
>>>>    }
>>>>
>>>>
>>>> Thanks!
>>>>
>>>
>>> So what do you get in cloudmonkey, can you send the json ?
>>>
>>
>> Sebastien, below  is what I get in CloudMonkey:
>>
>>
>> 2013-08-27 17:56:48,662 - requester.py:45 - [DEBUG] ======== START 
>> Request
>> ========
>> 2013-08-27 17:56:48,662 - requester.py:45 - [DEBUG] Requesting
>> command=launchCluster, args={'config': '1'}
>> 2013-08-27 17:56:48,663 - requester.py:45 - [DEBUG] Request sent:
>> 
>> http://localhost:8080/client/**api?apiKey=**3lwqSg6E1yS4vvF37mz7HshOp_**
>> 3N9rHoDoXMoWsRcbaisMz5-_**WnnwgzHaAeUi49cMMtb8GbzkPzvBA3**
>> WEqzMw&command=launchCluster&**config=1&response=json&**
>> 
>> signature=xCb%2BX06aGT5%**2Bd0iDQR3BbIBdYhM%3D<http://localhost:8080/client/api?apiKey=3lwqSg6E1yS4vvF37mz7HshOp_3N9rHoDoXMoWsRcbaisMz5-_WnnwgzHaAeUi49cMMtb8GbzkPzvBA3WEqzMw&command=launchCluster&config=1&response=json&signature=xCb%2BX06aGT5%2Bd0iDQR3BbIBdYhM%3D>
>> 2013-08-27 17:56:52,254 - requester.py:45 - [DEBUG] Response 
>> received: {
>> "launchCluster" :  { "launchCluster" : {"output":"Apache Whirr
>> ${project.version}jclouds 1.6.1-incubatingnull"} }  }
>> 2013-08-27 17:56:52,254 - requester.py:45 - [DEBUG] ======== END 
>> Request
>> ========
>>
>>
>> Thank you!
>>
>>
>>
>>>
>>>
>>>> On Wed, 28 Aug 2013 03:10:31 -0400, Sebastien Goasguen wrote:
>>>>
>>>>> On Aug 27, 2013, at 6:08 PM, "Han,Meng" <menghan@ufl.edu> wrote:
>>>>>
>>>>>  Hi folks,
>>>>>>
>>>>>> I am adding an api (launch cluster) to CloudStack and  using
>>>>>> CloudMonkey to test the api.
>>>>>>
>>>>>> From the CloudMonkey log file I can see that the request was 
>>>>>> executed
>>>>>> on the server side and return correct response, however, 
>>>>>> CloudMonkey was
>>>>>> forced to quit because the following error:
>>>>>>
>>>>>>
>>>>>>  launchCluster config=hadoop.properties
>>>>>>>
>>>>>> Traceback (most recent call last):
>>>>>> File "/usr/bin/cloudmonkey", line 9, in <module>
>>>>>>   load_entry_point('cloudmonkey=**=5.0.0', 'console_scripts',
>>>>>> 'cloudmonkey')()
>>>>>> File 
>>>>>> "/usr/lib/python2.6/site-**packages/cloudmonkey/**cloudmonkey.py",
>>>>>> line 536, in main
>>>>>>   shell.cmdloop()
>>>>>> File 
>>>>>> "/usr/lib/python2.6/site-**packages/cloudmonkey/**cloudmonkey.py",
>>>>>> line 106, in cmdloop
>>>>>>   super(CloudMonkeyShell, self).cmdloop(intro="")
>>>>>> File "/usr/lib64/python2.6/cmd.py", line 142, in cmdloop
>>>>>>   stop = self.onecmd(line)
>>>>>> File "/usr/lib64/python2.6/cmd.py", line 218, in onecmd
>>>>>>   return self.default(line)
>>>>>> File 
>>>>>> "/usr/lib/python2.6/site-**packages/cloudmonkey/**cloudmonkey.py",
>>>>>> line 303, in default
>>>>>>   result = self.make_request(apiname, args_dict, isasync)
>>>>>> File 
>>>>>> "/usr/lib/python2.6/site-**packages/cloudmonkey/**cloudmonkey.py",
>>>>>> line 257, in make_request
>>>>>>   self.timeout, self.protocol, self.path)
>>>>>> File 
>>>>>> "/usr/lib/python2.6/site-**packages/cloudmonkey/**requester.py",
>>>>>> line 121, in monkeyrequest
>>>>>>   response key = filter(lambda x: 'response' in x, 
>>>>>> response.keys())[0]
>>>>>> IndexError: list index out of range
>>>>>>
>>>>>>
>>>>> Meng, this actually might be an issue with your response object 
>>>>> in
>>>>> java, make sure that it is properly defined.
>>>>>
>>>>> You can also send us the json that's returned via cloudmonkey
>>>>>
>>>>>
>>>>>> Could someone give me  a pointer why this is happening?
>>>>>>
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>> Cheers,
>>>>>> Meng
>>>>>>
>>>>>
>>>>
>>


Mime
View raw message