s1.persist();
s2.persist();
s3.persist();
ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE");
ServiceComponent sc2 = serviceComponentFactory.createNew(s1, "NAMENODE");
ServiceComponent sc3 = serviceComponentFactory.createNew(s3,
"HBASE_REGIONSERVER");
s1.addServiceComponent(sc1);
s1.addServiceComponent(sc2);
s3.addServiceComponent(sc3);
sc1.setDesiredState(State.UNINSTALLED);
sc3.setDesiredState(State.UNINSTALLED);
sc1.persist();
sc2.persist();
sc3.persist();
ServiceComponentHost sch1 = serviceComponentHostFactory.createNew(sc1, "h1");
ServiceComponentHost sch2 = serviceComponentHostFactory.createNew(sc1, "h2");
ServiceComponentHost sch3 = serviceComponentHostFactory.createNew(sc1, "h3");
ServiceComponentHost sch4 = serviceComponentHostFactory.createNew(sc2, "h1");
ServiceComponentHost sch5 = serviceComponentHostFactory.createNew(sc2, "h2");
ServiceComponentHost sch6 = serviceComponentHostFactory.createNew(sc3, "h3");
sc1.addServiceComponentHost(sch1);
sc1.addServiceComponentHost(sch2);
sc1.addServiceComponentHost(sch3);
sc2.addServiceComponentHost(sch4);
sc2.addServiceComponentHost(sch5);
sc3.addServiceComponentHost(sch6);
sch1.setDesiredState(State.INSTALLED);
sch2.setDesiredState(State.INIT);
sch4.setDesiredState(State.INSTALLED);
sch5.setDesiredState(State.UNINSTALLED);
sch1.persist();
sch2.persist();
sch3.persist();
sch4.persist();
sch5.persist();
sch6.persist();
ServiceComponentHostRequest r =
new ServiceComponentHostRequest(null, null, null, null, null);
try {
controller.getHostComponents(Collections.singleton(r));
fail("Expected failure for invalid cluster");
} catch (Exception e) {
// Expected
}
// all across cluster
r = new ServiceComponentHostRequest(c1.getClusterName(), null,
null, null, null);
Set<ServiceComponentHostResponse> resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(6, resps.size());
// all for service
r = new ServiceComponentHostRequest(c1.getClusterName(), s1.getName(),
null, null, null);
resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(5, resps.size());
// all for component
r = new ServiceComponentHostRequest(c1.getClusterName(), null,
sc3.getName(), null, null);
resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(1, resps.size());
// all for host
r = new ServiceComponentHostRequest(c1.getClusterName(), null,
null, "h2", null);
resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(2, resps.size());
// all across cluster with state filter
r = new ServiceComponentHostRequest(c1.getClusterName(), null,
null, null, State.UNINSTALLED.toString());
resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(1, resps.size());
// all for service with state filter
r = new ServiceComponentHostRequest(c1.getClusterName(), s1.getName(),
null, null, State.INIT.toString());
resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(2, resps.size());
// all for component with state filter
r = new ServiceComponentHostRequest(c1.getClusterName(), null,
sc3.getName(), null, State.INSTALLED.toString());
resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(0, resps.size());
// all for host with state filter
r = new ServiceComponentHostRequest(c1.getClusterName(), null,
null, "h2", State.INIT.toString());
resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(1, resps.size());
// for service and host
r = new ServiceComponentHostRequest(c1.getClusterName(), s3.getName(),
null, "h1", null);
resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(0, resps.size());
// single sch - given service and host and component
r = new ServiceComponentHostRequest(c1.getClusterName(), s3.getName(),
sc3.getName(), "h3", State.INSTALLED.toString());
resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(0, resps.size());
// single sch - given service and host and component
r = new ServiceComponentHostRequest(c1.getClusterName(), s3.getName(),
sc3.getName(), "h3", null);
resps = controller.getHostComponents(Collections.singleton(r));
Assert.assertEquals(1, resps.size());
ServiceComponentHostRequest r1, r2, r3;
r1 = new ServiceComponentHostRequest(c1.getClusterName(), null,
null, "h3", null);
r2 = new ServiceComponentHostRequest(c1.getClusterName(), s3.getName(),
sc3.getName(), "h2", null);
r3 = new ServiceComponentHostRequest(c1.getClusterName(), null,
null, "h2", null);
Set<ServiceComponentHostRequest> reqs =
new HashSet<ServiceComponentHostRequest>();
reqs.addAll(Arrays.asList(r1, r2, r3));