Cloudera Manager API操作Yarn/Impala队列资源

直接上代码:
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.ezmorph.bean.MorphDynaBean;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.io.FileUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Test;


public class JavaNetURLRESTFulClient {

	private static final String targetURL = "http://172.21.2.125:7180/api/v11/clusters/cluster/services/yarn/config";
	private static final String config_strart="{\"items\" : [{\"name\":\"impala_scheduled_allocations\",\"value\":\"";
	private static final String config_root_start="{\\\"userMaxAppsDefault\\\": null, \\\"users\\\": [], \\\"fairSharePreemptionTimeout\\\": null, \\\"queues\\\": [{\\\"minSharePreemptionTimeout\\\": 1, \\\"name\\\": \\\"root\\\", \\\"schedulingPolicy\\\": \\\"fair\\\", \\\"aclSubmitApps\\\": \\\"*\\\", \\\"queues\\\": [";
	private static final String config_root_end="]}], \\\"queueMaxAppsDefault\\\": null, \\\"defaultMinSharePreemptionTimeout\\\": null, \\\"defaultQueueSchedulingPolicy\\\": \\\"drf\\\", \\\"queuePlacementRules\\\": [], \\\"queueMaxAMShareDefault\\\": null}";
	private static final String config_end="\"}]}";
	

	public static void main(String[] args) throws Exception{
//		List
   
   
    
     queues=complexJson(readYarnConfig());
//		StringBuffer sb=new StringBuffer();
//		for(Queue queue : queues){
			System.out.println(queue.toString()+",");
//			sb.append(queue.toString()+",");
//		}
//		String result=sb.toString();
//		result=result.substring(0, result.length()-1).replace("\"", "\\\"");
		System.out.println(result);
//		System.out.println(config_strart+config_root_start+result+config_root_end+config_end);
//		Gen gen=readJson();
//		System.out.println(JSONObject.fromObject(gen).toString());
//		String json="{\"aclAdministerApps\":\"anliang STQ\",\"aclSubmitApps\":\"anliang STQ\",\"minSharePreemptionTimeout\":\"\",\"name\":\"anliang\",\"queues\":[],\"schedulablePropertiesList\":[{\"impalaMaxMemory\":\"9600000\",\"impalaMaxQueuedQueries\":\"\",\"impalaMaxRunningQueries\":\"\",\"maxAMShare\":\"\",\"maxResources\":{\"memory\":\"5000000\",\"vcores\":\"1500\"},\"maxRunningApps\":\"500\",\"minResources\":{\"memory\":\"100000\",\"vcores\":\"60\"},\"scheduleName\":\"default\",\"weight\":\"10\"}],\"schedulingPolicy\":\"drf\"}";
//		putConfig("");
//		testToJson();
//		refreshPools();
		
		importKerberosPrincipal();
	}
	
	public static List
    
    
     
      complexJson(String json) throws Exception{
		JSONObject object=JSONObject.fromObject(json);
		JSONArray jsonArray=JSONArray.fromObject(object.get("items"));
		List
     
     
      
       queues=new ArrayList
      
      
       
       ();
		for(int i=0;i
       
       
         SchedulablePropertiesList=new ArrayList 
        
          (); JSONArray schedulableProperties_arr=JSONArray.fromObject(queue_obj.get("schedulablePropertiesList")); for(int k=0;k 
         
           configYarns=new ArrayList 
          
            (); String queues_str = ""; for(int i=0;i 
           
             root_gen_queue=new ArrayList 
            
              (); for(int j=0;j 
             
               root_q1=new ArrayList 
              
                (); for(int k=0;k 
               
                 schedulableProperties=new ArrayList 
                
                  (); JSONArray properties=JSONArray.fromObject(queue_obj.get("schedulablePropertiesList")); JSONArray properties_arr=JSONArray.fromObject(queue_obj.get("schedulablePropertiesList")); for(int l=0;l 
                  
                 
                
               
              
             
            
           
          
         
       
      
      
     
     
    
    
   
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值