@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()); }
.setCompatibilities( Compatibilities.builder().setHardwaretypes("large-mem", "large-cpu", "large", "medium", "small").build()) .setConstraints(new Constraints( ImmutableMap.<String, ServiceConstraint>of( "namenode",
.setConfig(Entities.ClusterTemplateExample.clusterConf).build()) .setCompatibilities(Compatibilities.builder().setServices(services).build()) .setConstraints(new Constraints( ImmutableMap.<String, ServiceConstraint>of( "namenode",
.setCompatibilities( Compatibilities.builder().setHardwaretypes("large-mem", "large-cpu", "large", "medium", "small").build()) .setConstraints( new Constraints( ImmutableMap.<String, ServiceConstraint>of(
.setClusterDefaults(template.getClusterDefaults()) .setCompatibilities(newCompatibilities) .setConstraints(template.getConstraints()) .setAdministration(template.getAdministration()) .build();
.setClusterDefaults(template.getClusterDefaults()) .setCompatibilities(newCompatibilities) .setConstraints(template.getConstraints()) .setAdministration(template.getAdministration()) .build();
private ClusterTemplate copyWithNewCompatibilities(ClusterTemplate template, Compatibilities newCompatibilities) { return ClusterTemplate.builder() .setName(template.getName()) .setDescription(template.getDescription()) .setClusterDefaults(template.getClusterDefaults()) .setCompatibilities(newCompatibilities) .setConstraints(template.getConstraints()) .setAdministration(template.getAdministration()) .build(); }