@Override public LayoutConstraint deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); Set<Set<String>> servicesThatMustCoexist = context.deserialize(jsonObj.get("mustcoexist"), new TypeToken<Set<Set<String>>>() { }.getType()); Set<Set<String>> servicesThatMustNotCoexist = context.deserialize(jsonObj.get("cantcoexist"), new TypeToken<Set<Set<String>>>() { }.getType()); return new LayoutConstraint(servicesThatMustCoexist, servicesThatMustNotCoexist); } }
@Override public JsonElement serialize(LayoutConstraint layoutConstraint, Type type, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("mustcoexist", context.serialize(layoutConstraint.getServicesThatMustCoexist())); jsonObj.add("cantcoexist", context.serialize(layoutConstraint.getServicesThatMustNotCoexist())); return jsonObj; }
private static boolean satisfiesCantCoexist(Set<String> serviceSet, LayoutConstraint layoutConstraint) { // a valid service set must not be a superset of any of the cant coexist constraints for (Set<String> cantCoexist : layoutConstraint.getServicesThatMustNotCoexist()) { if (serviceSet.containsAll(cantCoexist)) { return false; } } return true; }
private static boolean satisfiesMustCoexist(Set<String> serviceSet, LayoutConstraint layoutConstraint, Set<String> clusterServices) { // if the service set contains at least one service in a must coexist constraint, but not all clusterServices in the // constraint, then it is invalid. Ignore clusterServices that are not on the cluster. for (Set<String> mustCoexist : layoutConstraint.getServicesThatMustCoexist()) { Set<String> trueMustCoexist = Sets.intersection(mustCoexist, clusterServices); if (containsOne(serviceSet, trueMustCoexist) && !serviceSet.containsAll(trueMustCoexist)) { return false; } } return true; }
Set<String> findUnconstrainedServices() { Set<String> unconstrained = Sets.newHashSet(); Map<String, ServiceConstraint> serviceConstraints = clusterTemplate.getConstraints().getServiceConstraints(); LayoutConstraint layoutConstraint = clusterTemplate.getConstraints().getLayoutConstraint(); Set<Set<String>> mustCoexistServices = layoutConstraint.getServicesThatMustCoexist(); Set<Set<String>> mustNotCoexistServices = layoutConstraint.getServicesThatMustNotCoexist(); for (String service : clusterServices) { if (!serviceConstraints.containsKey(service) && !inSetOfSets(service, mustCoexistServices) && !inSetOfSets(service, mustNotCoexistServices)) { unconstrained.add(service); } } return unconstrained; }
private void copyFullProps(AbstractTemplate from, AbstractTemplate to, Set<String> immutables) throws TemplateImmutabilityException { copyMainProps(from, to, immutables, false); //merge constraints if(!from.constraints.equals(Constraints.EMPTY_CONSTRAINTS)) { Map<String, ServiceConstraint> serviceConstraint = mergeMap(to.constraints.serviceConstraints, from.constraints.serviceConstraints); Set<Set<String>> servicesThatMustCoexist = mergeSet(to.constraints.layoutConstraint.servicesThatMustCoexist, from.constraints.layoutConstraint.servicesThatMustCoexist); Set<Set<String>> servicesThatMustNotCoexist = mergeSet(to.constraints.layoutConstraint.servicesThatMustNotCoexist, from.constraints.layoutConstraint.servicesThatMustNotCoexist); to.constraints = new Constraints(serviceConstraint, new LayoutConstraint(servicesThatMustCoexist, servicesThatMustNotCoexist), from.constraints.sizeConstraint); } //merge admin lease duration if (!from.administration.equals(Administration.EMPTY_ADMINISTRATION)) { to.administration = from.administration; } }
@Test public void test_06_resolveTemplateTest() throws Exception { ClusterTemplate rt = clusterService.resolveTemplate(account, secureTemplate); Assert.assertEquals(secureTemplate.getIncludes(), rt.getIncludes()); Assert.assertEquals(secureTemplate.getParent(), rt.getParent()); Assert.assertEquals(secureTemplate.getName(), rt.getName()); Assert.assertEquals(secureTemplate.getDescription(), rt.getDescription()); Assert.assertEquals(defaultsServices, rt.getClusterDefaults().getServices()); Assert.assertEquals(16, rt.getClusterDefaults().getConfig().entrySet().size()); Assert.assertEquals("rackspace", rt.getClusterDefaults().getProvider()); Assert.assertEquals("standard-large", rt.getClusterDefaults().getHardwaretype()); Assert.assertEquals("centos6", rt.getClusterDefaults().getImagetype()); Assert.assertEquals("example.com", rt.getClusterDefaults().getDnsSuffix()); Assert.assertEquals(2, rt.getConstraints().getLayoutConstraint().getServicesThatMustCoexist().size()); Assert.assertEquals(2, rt.getConstraints().getLayoutConstraint().getServicesThatMustNotCoexist().size()); Assert.assertEquals(serviceConstraints, rt.getConstraints().getServiceConstraints()); Assert.assertEquals(43200000, rt.getAdministration().getLeaseDuration().getInitial()); Assert.assertEquals(43200000, rt.getAdministration().getLeaseDuration().getStep()); Assert.assertEquals(compatibilitiesHardwaretypes, rt.getCompatibilities().getHardwaretypes()); Assert.assertEquals(compatibilitiesImagetypes, rt.getCompatibilities().getImagetypes()); Assert.assertEquals(compatibilitiesServices, rt.getCompatibilities().getServices()); //overrides in child Assert.assertEquals("ldap.correct.com", rt.getClusterDefaults().getConfig().get("ldap") .getAsJsonObject().get("endpoint").getAsString()); Assert.assertNull(rt.getLabel()); Assert.assertNull(rt.getIcon()); Assert.assertEquals("cdap-distributed-secure-hadoop", rt.getName()); Assert.assertEquals("Cask DAP (CDAP) with Security and Secure Hadoop cluster with single master", rt.getDescription()); }
@BeforeClass public static void beforeClass() { constraints = new Constraints( ImmutableMap.<String, ServiceConstraint>of( "master1", new ServiceConstraint( ImmutableSet.of("large"), ImmutableSet.of("centos6", "ubuntu12"), 1, 1), "slave1", new ServiceConstraint( ImmutableSet.of("medium"), ImmutableSet.of("centos6", "ubuntu12"), 1, 50), "slave2", new ServiceConstraint( ImmutableSet.of("medium"), ImmutableSet.of("centos6", "ubuntu12"), 1, 50) ), new LayoutConstraint( ImmutableSet.<Set<String>>of( ImmutableSet.of("slave1", "slave2") ), ImmutableSet.<Set<String>>of( ImmutableSet.of("master1", "slave1"), ImmutableSet.of("master1", "slave2") ) ), SizeConstraint.EMPTY ); } }
null, 1, 5) ), new LayoutConstraint( ImmutableSet.<Set<String>>of( ImmutableSet.of("datanode", "nodemanager", "regionserver"),
null, 1, 5) ), new LayoutConstraint( ImmutableSet.<Set<String>>of( ImmutableSet.of("datanode", "nodemanager", "regionserver"),
ImmutableSet.of("centos6", "ubuntu12"), 1, 50) ), new LayoutConstraint( ImmutableSet.<Set<String>>of( ImmutableSet.of("slave1", "slave2")
@Test public void testNodesMustHaveServices() throws Exception { Set<String> services = ImmutableSet.of("svc1", "svc2", "svc3"); ClusterTemplate template = ClusterTemplate.builder() .setName("simple") .setDescription("all services on all nodes template") .setClusterDefaults(ClusterDefaults.builder().setServices(services).setProvider("joyent").build()) .setCompatibilities(Compatibilities.builder().setServices(services).build()) .setConstraints(new Constraints( ImmutableMap.<String, ServiceConstraint>of("svc1", new ServiceConstraint(null, null, 1, 1)), new LayoutConstraint( ImmutableSet.<Set<String>>of(ImmutableSet.of("svc1", "svc2", "svc3")), ImmutableSet.<Set<String>>of() ), SizeConstraint.EMPTY )).build(); List<NodeLayout> expected = ImmutableList.of( new NodeLayout("small", "centos6", ImmutableSet.of("svc1", "svc2", "svc3")) ); NodeLayoutGenerator nodeLayoutGenerator = new NodeLayoutGenerator(template, services, ImmutableSet.<String>of("small"), ImmutableSet.<String>of("centos6")); List<NodeLayout> actual = nodeLayoutGenerator.generateNodeLayoutPreferences(); Assert.assertEquals(expected, actual); }
@Test public void testNoSolutionReturnsNull() { Set<String> services = ImmutableSet.of("svc1", "svc2", "svc3"); ClusterTemplate template = ClusterTemplate.builder() .setName("simple") .setDescription("all services on all nodes template") .setClusterDefaults(ClusterDefaults.builder().setServices(services).setProvider("joyent").build()) .setCompatibilities(Compatibilities.builder().setServices(services).build()) .setConstraints(new Constraints( ImmutableMap.<String, ServiceConstraint>of("svc1", new ServiceConstraint(null, null, 1, 1)), new LayoutConstraint( ImmutableSet.<Set<String>>of(ImmutableSet.of("svc1", "svc2", "svc3")), ImmutableSet.<Set<String>>of() ), SizeConstraint.EMPTY)) .build(); List<NodeLayout> nodePreferences = ImmutableList.of( new NodeLayout("small", "centos6", ImmutableSet.of("svc1", "svc2", "svc3")) ); ClusterLayoutFinder finder = new ClusterLayoutFinder(nodePreferences, template, services, 2); Assert.assertNull(finder.findValidNodeCounts()); }
null, 1, 5) ), new LayoutConstraint( ImmutableSet.<Set<String>>of( ImmutableSet.of("datanode", "nodemanager", "regionserver"),
null, 1, 5) ), new LayoutConstraint( ImmutableSet.<Set<String>>of( ImmutableSet.of("datanode", "nodemanager", "regionserver"),
null, 1, 5) ), new LayoutConstraint( ImmutableSet.<Set<String>>of( ImmutableSet.of("datanode", "nodemanager", "regionserver"),