@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); } }
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; } }
@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"),