@Override public ServiceConstraint deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); JsonObject quantities = jsonObj.get("quantities").getAsJsonObject(); Integer min = context.deserialize(quantities.get("min"), Integer.class); Integer max = context.deserialize(quantities.get("max"), Integer.class); Set<String> requiredHardwareTypes = context.deserialize(jsonObj.get("hardwaretypes"), new TypeToken<Set<String>>() { }.getType()); Set<String> requiredImageTypes = context.deserialize(jsonObj.get("imagetypes"), new TypeToken<Set<String>>() { }.getType()); return new ServiceConstraint(requiredHardwareTypes, requiredImageTypes, min, max); } }
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), "base", new ServiceConstraint( null, ImmutableSet.of("centos6", "ubuntu12"), 0, 50), "app", new ServiceConstraint( ImmutableSet.of("medium"), ImmutableSet.of("centos6", "ubuntu12"), 1, 50)
@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 ); } }
ImmutableMap.<String, ServiceConstraint>of( "namenode", new ServiceConstraint( ImmutableSet.of("large-mem"), ImmutableSet.of("centos6", "ubuntu12"), 1, 1), "datanode", new ServiceConstraint( ImmutableSet.of("medium", "large-cpu"), ImmutableSet.of("centos6", "ubuntu12"), 1, 50), "zookeeper", new ServiceConstraint( ImmutableSet.of("small", "medium"), ImmutableSet.of("centos6"), 1, 5), "reactor", new ServiceConstraint( ImmutableSet.of("medium", "large"), null, 1, 5)
ImmutableMap.<String, ServiceConstraint>of( "namenode", new ServiceConstraint( ImmutableSet.of("large-mem"), ImmutableSet.of("centos6", "ubuntu12"), 1, 1), "datanode", new ServiceConstraint( ImmutableSet.of("medium", "large-cpu"), ImmutableSet.of("centos6", "ubuntu12"), 1, 50), "zookeeper", new ServiceConstraint( ImmutableSet.of("small", "medium"), ImmutableSet.of("centos6"), 1, 5), "reactor", new ServiceConstraint( ImmutableSet.of("medium", "large"), null, 1, 5)
@BeforeClass public static void setupClusterServiceTests() throws Exception { clusterService = injector.getInstance(ClusterService.class); TenantProvisionerService tenantProvisionerService = injector.getInstance(TenantProvisionerService.class); // setup data tenantProvisionerService.writeProvisioner(new Provisioner("p1", "host", 50056, 100, null, null)); tenantProvisionerService.writeTenantSpecification(new TenantSpecification("tenantX", 10, 1, 10)); Tenant tenant = tenantStore.getTenantByName("tenantX"); account = new Account(Constants.ADMIN_USER, tenant.getId()); entityStoreView = entityStoreService.getView(account); serviceConstraints.put("mysql-server", new ServiceConstraint(null, null, 1, 1)); serviceConstraints.put("zookeeper-server", new ServiceConstraint(null, null, 1, 1)); }
@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()); }
ImmutableMap.<String, ServiceConstraint>of( "namenode", new ServiceConstraint( ImmutableSet.of("large-mem"), ImmutableSet.of("centos6", "ubuntu12"), 1, 1), "datanode", new ServiceConstraint( ImmutableSet.of("medium", "large-cpu"), ImmutableSet.of("centos6", "ubuntu12"), 1, 50), "zookeeper", new ServiceConstraint( ImmutableSet.of("small", "medium"), ImmutableSet.of("centos6"), 1, 5), "reactor", new ServiceConstraint( ImmutableSet.of("medium", "large"), null, 1, 5)
ImmutableMap.<String, ServiceConstraint>of( "namenode", new ServiceConstraint( ImmutableSet.of("large-mem"), ImmutableSet.of("centos6", "ubuntu12"), 1, 1), "datanode", new ServiceConstraint( ImmutableSet.of("medium", "large-cpu"), ImmutableSet.of("centos6", "ubuntu12"), 1, 50), "zookeeper", new ServiceConstraint( ImmutableSet.of("small", "medium"), ImmutableSet.of("centos6"), 1, 5), "reactor", new ServiceConstraint( ImmutableSet.of("medium", "large"), null, 1, 5)
ImmutableMap.<String, ServiceConstraint>of( "namenode", new ServiceConstraint( ImmutableSet.of("large-mem"), ImmutableSet.of("centos6", "ubuntu12"), 1, 1), "datanode", new ServiceConstraint( ImmutableSet.of("medium", "large-cpu"), ImmutableSet.of("centos6", "ubuntu12"), 1, 50), "zookeeper", new ServiceConstraint( ImmutableSet.of("small", "medium"), ImmutableSet.of("centos6"), 1, 5), "reactor", new ServiceConstraint( ImmutableSet.of("medium", "large"), null, 1, 5)