@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()); }
)).build(); reactorTemplate2 = Entities.ClusterTemplateExample.REACTOR2;
.setProvider("rackspace") .build()) .setAdministration(new Administration(LeaseDuration.of("1s", "12s", "1s"))).build();
.setImagetypes("centos6", "ubuntu12") .setServices("namenode", "datanode").build()) .build(); entityStoreService.getView(account).writeClusterTemplate(simpleTemplate);
.setImagetypes(imageType.getName()) .setServices(service1.getName(), service2.getName()).build()) .build(); entityStoreView.writeClusterTemplate(basicTemplate);
.setConfig(Entities.ClusterTemplateExample.clusterConf).build()) .setCompatibilities(Compatibilities.builder().setServices("service1", "service2", "service3").build()) .build(); Service service1 = Service.builder().setName("service1").build();
@Test public void testClusterProlongForever() throws Exception { ClusterTemplate foreverTemplate = ClusterTemplate.builder() .setName("forever-template") .setClusterDefaults( ClusterDefaults.builder() .setServices("base") .setProvider("rackspace") .build()) .build(); long currentTime = 10000; Cluster foreverCluster = Cluster.builder() .setID("1002") .setAccount(USER1_ACCOUNT) .setName("prolong-test") .setCreateTime(currentTime) .setClusterTemplate(foreverTemplate) .build(); foreverCluster.setExpireTime(currentTime + 10000); foreverCluster.setStatus(Cluster.Status.ACTIVE); clusterStoreService.getView(USER1_ACCOUNT).writeCluster(foreverCluster); HttpResponse response = doPostExternalAPI("/clusters/" + foreverCluster.getId(), "{'expireTime' : 90000}", ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); foreverCluster = clusterStoreService.getView(USER1_ACCOUNT).getCluster(foreverCluster.getId()); Assert.assertEquals(90000, foreverCluster.getExpireTime()); }
.setConstraints(template.getConstraints()) .setAdministration(template.getAdministration()) .build(); entityStoreService.getView(Entities.ADMIN_ACCOUNT).writeClusterTemplate(updatedTemplate);
@Test(expected = IllegalArgumentException.class) public void testConflictingServicesThrowsException() throws Exception { Set<String> services = ImmutableSet.of("myapp-1"); ClusterTemplate template = ClusterTemplate.builder() .setName("name") .setClusterDefaults(ClusterDefaults.builder() .setServices(services) .setProvider("joyent") .setConfig(Entities.ClusterTemplateExample.clusterConf).build()) .setCompatibilities(Compatibilities.builder().setServices("myapp-1", "myapp-2").build()) .build(); Service myapp1 = Service.builder() .setName("myapp-1") .setDependencies(ServiceDependencies.builder().setProvides("myapp").setConflicts("myapp-2").build()) .build(); Service myapp2 = Service.builder() .setName("myapp-2") .setDependencies(ServiceDependencies.builder().setProvides("myapp").setConflicts("myapp-1").build()) .build(); entityStoreService.getView(account).writeService(myapp1); entityStoreService.getView(account).writeService(myapp2); Cluster cluster = getBaseBuilder() .setClusterTemplate(template) .setServices(ImmutableSet.of(myapp1.getName())) .build(); solver.validateServicesToAdd(cluster, ImmutableSet.of(myapp2.getName())); }
.setConstraints(template.getConstraints()) .setAdministration(template.getAdministration()) .build(); entityStoreService.getView(Entities.ADMIN_ACCOUNT).writeClusterTemplate(updatedTemplate);
@BeforeClass public static void initData() throws Exception { JsonObject defaultClusterConfig = new JsonObject(); defaultClusterConfig.addProperty("defaultconfig", "value1"); smallTemplate = ClusterTemplate.builder() .setName("one-machine") .setClusterDefaults( ClusterDefaults.builder() .setServices("zookeeper") .setProvider("rackspace") .setConfig(defaultClusterConfig) .build()) .setCompatibilities(Compatibilities.builder().setServices("zookeeper").build()) .setAdministration(new Administration(LeaseDuration.of("10s", "30s", "5s"))) .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(); }