Vijava 学习笔记之数据中心下(集群和非集群的资源池和ESXI)树形结构展示
来源:互联网 发布:oracle创建表的sql语句 编辑:程序博客网 时间:2024/05/21 10:27
实体对象:DtreeObj.java
package com.vmware.pojo;/** * Created by vixuan-008 on 2015/6/27. */public class DtreeObj { private int id;//编号 private String name;//name private int pid;//父类id private int type;//设备类型 public int getId() { return id; } public void setId(int id) { this.id = id; } public int getPid() { return pid; } public void setPid(int pid) { this.pid = pid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getType() { return type; } public void setType(int type) { this.type = type; }}
逻辑方法:ClusetDemo.java
package com.vmware.tree;import com.vmware.pojo.DtreeObj;import com.vmware.util.Session;import com.vmware.vim25.mo.*;import java.util.ArrayList;import java.util.List;/** * Created by vixuan-008 on 2015/6/27. */public class ClusetDemo { public static void main(String[] args) throws Exception{ List<DtreeObj> list=new ArrayList<DtreeObj>(); ServiceInstance serviceInstance = null; //ServiceInstance----服务实例 //serviceInstance = Session.getInstance("192.168.0.22", "administrator@vsphere.local", "Vixuan12#"); serviceInstance = Session.getInstance("172.16.1.20","root","vmware"); list=getTree(serviceInstance); if(list.size()>0){ for(int i=0;i<list.size();i++){ DtreeObj obj=list.get(i); System.out.println("id is:" + obj.getId() + ";name is:" + obj.getName() + ";pid is:" + obj.getPid() + ";type is:" + obj.getType()); System.out.println("-----------------------------------------------"); } } } public static List<String> getdifference(List<String> a,List<String> b){ List<String> content=new ArrayList<String>(); if(a !=null && b!=null){ if(a.size()>0 && b.size()>0){ for(int i=0;i<a.size();i++){ boolean target=false;//默认在b集合中不存在 String diffA=a.get(i); //判断是否字符串在指定的集合当中 for(int j=0;j<b.size();j++){ String diffB=b.get(j); if(diffA.equalsIgnoreCase(diffB)){ target=true; } } //返回相关数据集合 if(!target){ content.add(diffA); } } } } return content; } public static List<DtreeObj> getTree( ServiceInstance serviceInstance) throws Exception{ List<DtreeObj> list=new ArrayList<DtreeObj>(); //数据中心关联HostSystem List<String> allhost=new ArrayList<String>(); //已经存在HostSystem List<String> hostList=new ArrayList<String>(); //非集群HostSystem List<String> noClusterHostList=null; //rootFolder-------根文件夹 Folder rootFolder = serviceInstance.getRootFolder(); System.out.println("datacenter is:"+rootFolder.getName()); int counterInt=1; int rootId=0; DtreeObj root=new DtreeObj(); root.setId(rootId); root.setName(rootFolder.getName()); root.setPid(-1); root.setType(4); list.add(root); //inventoryNavigator----文件夹目录 InventoryNavigator inventoryNavigator =new InventoryNavigator(rootFolder); //hostEntities--------查询实体对象(esxi) ManagedEntity[] hostEntities=inventoryNavigator.searchManagedEntities("HostSystem"); if(hostEntities!=null && hostEntities.length>0){ for(int i=0;i<hostEntities.length;i++){ HostSystem hostSystem=(HostSystem)hostEntities[i]; allhost.add(hostSystem.getName()); } } //managedEntities------查询实体对象 ManagedEntity[] managedEntities=inventoryNavigator.searchManagedEntities("ClusterComputeResource"); if(managedEntities!=null && managedEntities.length>0){ for(int i=0;i<managedEntities.length;i++){ ClusterComputeResource cluster = (ClusterComputeResource)managedEntities[i]; counterInt=counterInt+i;//统计数增加 int clusterId=counterInt;//集群Id DtreeObj clusterObj=new DtreeObj(); clusterObj.setId(clusterId); clusterObj.setName(cluster.getName()); clusterObj.setPid(rootId); clusterObj.setType(1); list.add(clusterObj); //集群关联服务器 HostSystem[] hostSystems=cluster.getHosts(); if(hostSystems!=null && hostSystems.length>0){ for(int j=0;j<hostSystems.length;j++){ HostSystem system=hostSystems[j]; int a=j+1; counterInt=counterInt+(a);//统计数增加 int hostId=counterInt;//服务器Id DtreeObj hostObj=new DtreeObj(); hostObj.setId(hostId); hostObj.setName(system.getName()); hostObj.setPid(clusterId); hostObj.setType(3); hostList.add(system.getName()); list.add(hostObj); } } //集群关联资源池 ResourcePool resourcePool=cluster.getResourcePool(); if(resourcePool!=null){ ResourcePool[] resourcePools=resourcePool.getResourcePools(); if(resourcePools!=null && resourcePools.length>0){ for(int k=0;k<resourcePools.length;k++){ ResourcePool pool=resourcePools[k]; int b=k+1; counterInt=counterInt+(b);//统计数增加 int poolId=counterInt;//资源池Id DtreeObj poolObj=new DtreeObj(); poolObj.setId(poolId); poolObj.setName(pool.getName()); poolObj.setPid(clusterId); poolObj.setType(2); // poolList.add(pool.getName()); list.add(poolObj); } } } } } //处理非集群HostSystem noClusterHostList=getdifference(allhost,hostList); if(noClusterHostList!=null && noClusterHostList.size()>0){ for(int i=0;i<noClusterHostList.size();i++){ String content=noClusterHostList.get(i); int b=i+1; counterInt=counterInt+(b); int nohostId=counterInt; DtreeObj nohostObj=new DtreeObj(); nohostObj.setId(nohostId); nohostObj.setName(content); nohostObj.setPid(rootId); nohostObj.setType(3); list.add(nohostObj); } } return list; }}
0 0
- Vijava 学习笔记之数据中心下(集群和非集群的资源池和ESXI)树形结构展示
- Vijava 学习笔记之(Datacenter 关联集群、资源池和ESXI)
- vCenter初始化数据中心和集群
- Vijava 学习笔记之VirtualMachine(CPU 利用率和Memory 利用率)
- 试用vSphere 6(四):配置数据中心(添加ESXi主机、新建数据中心\集群等)
- 17. 试用vSphere 6(四):配置数据中心(添加ESXi主机、新建数据中心\集群等)
- Vijava 学习笔记CustomizationWinOptions 和CustomizationSysprepRebootOption
- Vijava学习笔记之(HostSystem 内存(总容量和已使用))
- Vijava 学习笔记之(虚拟机可扩容CPU核数、内存大小和关联DataStore)
- Vijava 学习笔记之(VirtualMachineRelocateSpec类)
- Vijava 学习笔记之(Cluster 关联资源信息:CPU、内存、Datastore容量信息)
- 非结构化数据激增下的集群存储机会
- Vijava 学习笔记之模板
- Vijava 学习笔记之(VirtualMachineCloneSpec)
- Vijava 学习笔记之CustomizationPassword
- Vijava 学习笔记之 VirtualMachine操作(关机、待机和重新加载)
- Vijava 学习笔记之 HostSystem(内存总大小、内存已使用容量和CPU个数)
- Vijava 学习笔记之 VirtualMachine(虚拟磁盘已用容量和空闲容量)
- 析构函数
- 自定义View(视图)的创建、添加、移除细节分析
- flash声音导入
- uva 10047 The Monocycle
- C Prime plus 第六章习题
- Vijava 学习笔记之数据中心下(集群和非集群的资源池和ESXI)树形结构展示
- Eclipse安装SVN插件
- Linux网络配置相关
- 设计模式系列--观察者模式基本
- Java基础——对象加载顺序
- c++显示调用析构函数(转csdn)
- Android自定义控件实现登陆界面以及SharedPreferences实现记住密码功能
- 泛型程序设计
- 通过click事件动态改变引用的CSS文件,在不同浏览器下的表现