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

你可能感兴趣的:(Cloudera Manager API操作Yarn/Impala队列资源)