StorageGroup { public void getConfig(StorDistributionConfig.Group.Builder builder) { builder.index(index == null ? "invalid" : index); builder.name(name == null ? "invalid" : name); if (partitions.isPresent()) builder.partitions(partitions.get()); for (StorageNode node : nodes) { StorDistributionConfig.Group.Nodes.Builder nb = new StorDistributionConfig.Group.Nodes.Builder(); nb.index(node.getDistributionKey()); nb.retired(node.isRetired()); builder.nodes.add(nb); } builder.capacity(getCapacity()); } private  StorageGroup(boolean isHosted, String name, String index, Optional<String> partitions,
                         boolean useCpuSocketAffinity, Optional<Long> mmapNoCoreLimit, Optional<Boolean> coreOnOOM,
                         Optional<String> noVespaMalloc, Optional<String> vespaMalloc,
                         Optional<String> vespaMallocDebug, Optional<String> vespaMallocDebugStackTrace); private  StorageGroup(boolean isHosted, String name, String index); String getName(); List<StorageGroup> getSubgroups(); List<StorageNode> getNodes(); boolean isHosted(); String getIndex(); Optional<String> getPartitions(); boolean useCpuSocketAffinity(); Optional<Long> getMmapNoCoreLimit(); Optional<Boolean> getCoreOnOOM(); Optional<String> getNoVespaMalloc(); Optional<String> getVespaMalloc(); Optional<String> getVespaMallocDebug(); Optional<String> getVespaMallocDebugStackTrace(); List<StorageNode> recursiveGetNodes(); Collection<StorDistributionConfig.Group.Builder> getGroupStructureConfig(); void getConfig(StorDistributionConfig.Group.Builder builder); int getNumberOfLeafGroups(); double getCapacity(); int countNodes(); @Override boolean equals(Object obj); @Override int hashCode(); static Map<HostResource, ClusterMembership> provisionHosts(NodesSpecification nodesSpecification, 
                                                                      String clusterIdString, 
                                                                      HostSystem hostSystem, 
                                                                      DeployLogger logger);  }
@Test public void testSingleGroup() throws Exception { StorDistributionConfig.Builder builder = new StorDistributionConfig.Builder(); ContentCluster cluster = parse( "<content id=\"storage\">\n" + " <documents/>" + " <group>\n" + " <node hostalias=\"mockhost\" distribution-key=\"0\"/>\n" + " <node hostalias=\"mockhost\" distribution-key=\"1\"/>\n" + " </group>\n" + "</content>" ); cluster.getConfig(builder); assertEquals("content", cluster.getStorageNodes().getChildren().get("0").getServicePropertyString("clustertype")); assertEquals("storage", cluster.getStorageNodes().getChildren().get("0").getServicePropertyString("clustername")); assertEquals("0", cluster.getStorageNodes().getChildren().get("0").getServicePropertyString("index")); assertEquals("content", cluster.getDistributorNodes().getChildren().get("0").getServicePropertyString("clustertype")); assertEquals("storage", cluster.getDistributorNodes().getChildren().get("0").getServicePropertyString("clustername")); assertEquals("0", cluster.getDistributorNodes().getChildren().get("0").getServicePropertyString("index")); StorDistributionConfig config = new StorDistributionConfig(builder); assertEquals(1, config.group().size()); assertEquals("invalid", config.group(0).index()); assertEquals("invalid", config.group(0).name()); assertEquals(2, config.group(0).nodes().size()); assertEquals(0, config.group(0).nodes(0).index()); assertEquals(1, config.group(0).nodes(1).index()); }
@Test public void testNestedGroups() throws Exception { StorDistributionConfig.Builder builder = new StorDistributionConfig.Builder(); parse( "<content version=\"1.0\" id=\"storage\">\n" + " <redundancy>4</redundancy>" + " <documents/>" + " <group>\n" + " <distribution partitions=\"1|*\"/>\n" + " <group distribution-key=\"0\" name=\"sub1\">\n" + " <node hostalias=\"mockhost\" distribution-key=\"0\"/>\n" + " <node hostalias=\"mockhost\" distribution-key=\"1\"/>\n" + " </group>\n" + " <group distribution-key=\"1\" name=\"sub2\">\n" + " <distribution partitions=\"1|*\"/>\n" + " <group distribution-key=\"0\" name=\"sub3\">\n" + " <node hostalias=\"mockhost\" distribution-key=\"2\"/>\n" + " <node hostalias=\"mockhost\" distribution-key=\"3\"/>\n" + " </group>\n" + " <group distribution-key=\"1\" name=\"sub4\">\n" + " <node hostalias=\"mockhost\" distribution-key=\"4\"/>\n" + " <node hostalias=\"mockhost\" distribution-key=\"5\"/>\n" + " </group>\n" + " </group>\n" + " </group>\n" + "</content>" ).getConfig(builder); StorDistributionConfig config = new StorDistributionConfig(builder); assertEquals(5, config.group().size()); assertEquals("invalid", config.group(0).index()); assertEquals("0", config.group(1).index()); assertEquals("1", config.group(2).index()); assertEquals("1.0", config.group(3).index()); assertEquals("1.1", config.group(4).index()); assertEquals("invalid", config.group(0).name()); assertEquals("sub1", config.group(1).name()); assertEquals("sub2", config.group(2).name()); assertEquals("sub3", config.group(3).name()); assertEquals("sub4", config.group(4).name()); assertEquals(2, config.group(1).nodes().size()); assertEquals(0, config.group(1).nodes(0).index()); assertEquals(1, config.group(1).nodes(1).index()); assertEquals(0, config.group(2).nodes().size()); assertEquals(2, config.group(3).nodes().size()); assertEquals(2, config.group(3).nodes(0).index()); assertEquals(3, config.group(3).nodes(1).index()); assertEquals(2, config.group(4).nodes().size()); assertEquals(4, config.group(4).nodes(0).index()); assertEquals(5, config.group(4).nodes(1).index()); assertEquals("1|*", config.group(0).partitions()); }
@Test public void testGroupCapacity() throws Exception { StorDistributionConfig.Builder builder = new StorDistributionConfig.Builder(); parse( "<content version=\"1.0\" id=\"storage\">\n" + " <redundancy>2</redundancy>" + " <documents/>" + " <group>\n" + " <distribution partitions=\"1|*\"/>\n" + " <group distribution-key=\"0\" name=\"sub1\">\n" + " <node hostalias=\"mockhost\" capacity=\"0.5\" distribution-key=\"0\"/>\n" + " <node hostalias=\"mockhost\" capacity=\"1.5\" distribution-key=\"1\"/>\n" + " </group>\n" + " <group distribution-key=\"1\" name=\"sub2\">\n" + " <node hostalias=\"mockhost\" capacity=\"2.0\" distribution-key=\"2\"/>\n" + " <node hostalias=\"mockhost\" capacity=\"1.5\" distribution-key=\"3\"/>\n" + " </group>\n" + " </group>\n" + "</content>" ).getConfig(builder); StorDistributionConfig config = new StorDistributionConfig(builder); assertEquals(3, config.group().size()); assertEquals(5.5, config.group(0).capacity(), 0.001); assertEquals(2, config.group(1).capacity(), 0.001); assertEquals(3.5, config.group(2).capacity(), 0.001); }