private JSONObject renderCompute(String service_id, ServiceComponent sc, Integer index) throws JSONEncodingException { JSONObject json = new JSONObject(); try { json.put(KIND_TAG, KIND); JSONObject attrs = new JSONObject(); setAttribute(ServiceComponent.OCCI_COMPUTE_ARCHITECTURE, attrs, sc.getArchitecture()); setAttribute(ServiceComponent.OCCI_COMPUTE_CORES, attrs, sc.getCores()); setAttribute(ServiceComponent.OCCI_COMPUTE_MEMORY, attrs, sc.getMemory()); setAttribute(ServiceComponent.OCCI_COMPUTE_SPEED, attrs, sc.getSpeed()); setAttribute(ServiceComponent.OPTIMIS_VM_IMAGE, attrs, sc.getImage()); setAttribute(ServiceComponent.OPTIMIS_SERVICE_ID, attrs, service_id); json.put(ATTRIBUTES_TAG, attrs); json.put(ID_TAG, ID_PREFIX + index.toString()); } catch (JSONException e) { throw new JSONEncodingException( "There was an error while trying to convert a " + "ServiceComponent object into a JSON object"); } return json; }
public static void main(String[] args) { OCCI_RestClient cl = new OCCI_RestClient("", "", ""); List<ServiceComponent> scs = new ArrayList<ServiceComponent>(); ServiceComponent c1 = new ServiceComponent(); c1.setArchitecture("x86"); c1.setCores(2); c1.setMemory(2.5); c1.setSpeed(0.6); c1.setImage("image"); c1.setInstances(2); scs.add(c1); try { JSONObject obj = cl.renderCompute("a", c1, 1); System.out.println(obj.toString(1)); } catch (Exception e) { e.printStackTrace(); } }