Client { public Response createCluster(String clusterName, URL nodes, URL software, URL config) throws IOException { ClusterManifest cluster = new ClusterManifest(); cluster.setClusterName(clusterName); NodesManifest nodesM = new NodesManifest(); nodesM.setUrl(nodes); cluster.setNodes(nodesM); SoftwareManifest softwareM = new SoftwareManifest(); softwareM.setUrl(software); cluster.setSoftware(softwareM); ConfigManifest configM = new ConfigManifest(); configM.setUrl(config); cluster.setConfig(configM); return clientRunner.sendToController(new CreateClusterCommand(cluster)); }  static Options setupOptions(); Response createCluster(String clusterName, URL nodes, URL software, URL config); Response upgradeCluster(String clusterName, URL nodes, URL software, URL config); Response deleteCluster(String clusterName, URL config); CommandStatus queryCommandStatus(String id); void run(String[] args); static void usage(); static void main(String[] args);  }
@Test public void testCreateCluster() { try { File nodesXmlFile = File.createTempFile("nodes", ".xml"); nodesXmlFile.deleteOnExit(); File softwareXmlFile = File.createTempFile("software", ".xml"); softwareXmlFile.deleteOnExit(); File configXmlFile = File.createTempFile("config", ".xml"); configXmlFile.deleteOnExit(); String nodesXmlPath = nodesXmlFile.getAbsolutePath(); String softwareXmlPath = softwareXmlFile.getAbsolutePath(); String configXmlPath = configXmlFile.getAbsolutePath(); NodesManifest n = new NodesManifest(); List<Role> roles = new ArrayList<Role>(); Role role = new Role(); role.setName("namenode"); String [] hosts = { "localhost" }; role.setHosts(hosts); roles.add(role); n.setNodes(roles); FileWriter fstream = new FileWriter(nodesXmlPath); BufferedWriter out = new BufferedWriter(fstream); out.write( new String(JAXBUtil.write(n)).toCharArray()); out.close(); fstream.close(); SoftwareManifest sm = new SoftwareManifest(); sm.setName("hadoop"); sm.setVersion("0.20.203"); List<Role> softwareRoles = new ArrayList<Role>(); Role softwareRole = new Role(); softwareRole.setName("namenode"); PackageInfo[] packages = new PackageInfo[1]; packages[0]= new PackageInfo(); packages[0].setName("hadoop-0.20.203"); softwareRole.setPackages(packages); softwareRoles.add(softwareRole); sm.setRoles(softwareRoles); fstream = new FileWriter(softwareXmlPath); out = new BufferedWriter(fstream); out.write(new String(JAXBUtil.write(sm)).toCharArray()); out.close(); fstream.close(); PackageAction installHadoop = new PackageAction(); installHadoop.setPackages(packages); List<Action> actions = new ArrayList<Action>(); actions.add(installHadoop); ConfigManifest cm = new ConfigManifest(); cm.setActions(actions); fstream = new FileWriter(configXmlPath); out = new BufferedWriter(fstream); out.write(new String(JAXBUtil.write(cm)).toCharArray()); out.close(); fstream.close(); URL softwareUrl = new URL("file: URL nodeUrl = new URL("file: URL configUrl = new URL("file: ClusterManifest clusterM = new ClusterManifest(); NodesManifest nodes = new NodesManifest(); nodes.setUrl(nodeUrl); clusterM.setNodes(nodes); SoftwareManifest softwareM = new SoftwareManifest(); softwareM.setUrl(softwareUrl); clusterM.setSoftware(softwareM); ConfigManifest configM = new ConfigManifest(); configM.setUrl(configUrl); clusterM.setConfig(configM); clusterM.load(); NodesManifest actualNodeManifest = clusterM.getNodes(); for(Role actualRole: actualNodeManifest.getRoles()) { Assert.assertEquals(actualRole.getName(), role.getName()); for(String host : actualRole.getHosts()) { Assert.assertEquals(host, hosts[0]); } } SoftwareManifest actualSoftwareManifest = clusterM.getSoftware(); for(Role actualRole: actualSoftwareManifest.getRoles()) { Assert.assertEquals(actualRole.getName(), role.getName()); for(PackageInfo pi: actualRole.getPackages()) { Assert.assertEquals(pi.getName(), packages[0].getName()); } } Client client = new Client(); } catch (Exception e) { Assert.fail(ExceptionUtil.getStackTrace(e)); } }