Skip to content

Commit 94a84ca

Browse files
authored
Merge pull request #154 from vlingo/improvement/dynamic-cluster-nodes
Dynamic cluster nodes
2 parents b8448e9 + f790101 commit 94a84ca

File tree

11 files changed

+44
-141
lines changed

11 files changed

+44
-141
lines changed

src/e2e-test/java/io/vlingo/xoom/designer/codegen/e2e/java/bookstoreservice/BookData.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// one at https://mozilla.org/MPL/2.0/.
77
package io.vlingo.xoom.designer.codegen.e2e.java.bookstoreservice;
88

9+
import com.fasterxml.jackson.annotation.JsonCreator;
10+
import com.fasterxml.jackson.annotation.JsonProperty;
911
import org.apache.commons.lang3.builder.EqualsBuilder;
1012

1113
public class BookData {
@@ -27,15 +29,16 @@ public static BookData sampleOfChangedPrice() {
2729
return new BookData("", "IDDD", 987, (byte) 1, 478.25, 150, 10, true, 'a');
2830
}
2931

30-
private BookData(final String id,
31-
final String title,
32-
final int stockCode,
33-
final byte publicCode,
34-
final double price,
35-
final float weight,
36-
final long height,
37-
final boolean available,
38-
final char symbol) {
32+
@JsonCreator
33+
private BookData(@JsonProperty("id") final String id,
34+
@JsonProperty("title") final String title,
35+
@JsonProperty("stockCode") final int stockCode,
36+
@JsonProperty("publicCode") final byte publicCode,
37+
@JsonProperty("price") final double price,
38+
@JsonProperty("weight") final float weight,
39+
@JsonProperty("height") final long height,
40+
@JsonProperty("available") final boolean available,
41+
@JsonProperty("symbol") final char symbol) {
3942
this.id = id;
4043
this.title = title;
4144
this.stockCode = stockCode;

src/e2e-test/java/io/vlingo/xoom/designer/codegen/e2e/java/cargoshippingservices/ComponentData.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.vlingo.xoom.designer.codegen.e2e.java.cargoshippingservices;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
35
import org.apache.commons.lang3.builder.EqualsBuilder;
46
import org.apache.commons.lang3.builder.HashCodeBuilder;
57

@@ -12,7 +14,9 @@ public class ComponentData {
1214
public final String name;
1315
public final String cricalityLevel;
1416

15-
public ComponentData (final String name, final String cricalityLevel) {
17+
@JsonCreator
18+
public ComponentData (@JsonProperty("name") final String name,
19+
@JsonProperty("cricalityLevel") final String cricalityLevel) {
1620
this.name = name;
1721
this.cricalityLevel = cricalityLevel;
1822
}

src/e2e-test/java/io/vlingo/xoom/designer/codegen/e2e/java/cargoshippingservices/FreighterPartData.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.vlingo.xoom.designer.codegen.e2e.java.cargoshippingservices;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
35
import org.apache.commons.lang3.builder.EqualsBuilder;
46
import org.apache.commons.lang3.builder.HashCodeBuilder;
57

@@ -11,7 +13,9 @@ public class FreighterPartData {
1113
public final String partNumber;
1214
public final Set<ComponentData> dependentComponents = new HashSet<>();
1315

14-
public FreighterPartData (final String partNumber, final Set<ComponentData> dependentComponents) {
16+
@JsonCreator
17+
public FreighterPartData(@JsonProperty("partNumber") final String partNumber,
18+
@JsonProperty("dependentComponents") final Set<ComponentData> dependentComponents) {
1519
this.partNumber = partNumber;
1620
this.dependentComponents.addAll(dependentComponents);
1721
}

src/e2e-test/java/io/vlingo/xoom/designer/codegen/e2e/java/cargoshippingservices/MechanicalIncidentData.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.vlingo.xoom.designer.codegen.e2e.java.cargoshippingservices;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
35
import org.apache.commons.lang3.builder.EqualsBuilder;
46

57
import java.util.HashSet;
@@ -25,10 +27,11 @@ public static MechanicalIncidentData sampleOfIncidentWithRelatedPart(final Strin
2527
return incident;
2628
}
2729

28-
public MechanicalIncidentData (final String freighterId,
29-
final String freighterPartNumber,
30-
final Long occurredOn,
31-
final Set<FreighterPartData> relatedParts) {
30+
@JsonCreator
31+
public MechanicalIncidentData (@JsonProperty("freighterId") final String freighterId,
32+
@JsonProperty("freighterPartNumber") final String freighterPartNumber,
33+
@JsonProperty("occurredOn") final Long occurredOn,
34+
@JsonProperty("relatedParts") final Set<FreighterPartData> relatedParts) {
3235
this.freighterId = freighterId;
3336
this.freighterPartNumber = freighterPartNumber;
3437
this.occurredOn = occurredOn;

src/main/java/io/vlingo/xoom/designer/codegen/java/ClusterNode.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ public class ClusterNode {
2424

2525
public static List<ClusterNode> from(final Integer startPortRange,
2626
final Integer totalNodes) {
27-
final AtomicInteger resolvedStartPortRange =
28-
startPortRange > 0 ? new AtomicInteger(startPortRange) :
29-
new AtomicInteger(DEFAULT_START_PORT_RANGE);
27+
final AtomicInteger resolvedStartPortRange = startPortRange > 0
28+
? new AtomicInteger(startPortRange)
29+
: new AtomicInteger(DEFAULT_START_PORT_RANGE);
3030

31-
final Integer resolvedTotalNodes =
32-
(totalNodes > 0 ? totalNodes : DEFAULT_TOTAL_NODES) + 1;
31+
final Integer resolvedTotalNodes = (totalNodes > 0 ? totalNodes : DEFAULT_TOTAL_NODES) + 1;
3332

3433
return IntStream.range(1, resolvedTotalNodes)
3534
.mapToObj(nodeId -> new ClusterNode(nodeId, resolvedStartPortRange))

src/main/java/io/vlingo/xoom/designer/codegen/java/ClusterSettings.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@
77

88
package io.vlingo.xoom.designer.codegen.java;
99

10-
import java.util.List;
11-
import java.util.stream.Collectors;
12-
13-
import static java.util.Collections.unmodifiableList;
14-
1510
public class ClusterSettings {
1611

17-
public final String oneNode;
18-
public final String nodeNames;
19-
public final List<ClusterNode> nodes;
12+
public final int startPortRange;
2013
public final int nodeCount;
2114
public final int quorum;
2215
public final int seed;
@@ -28,10 +21,8 @@ public static ClusterSettings with(final int startPortRange,
2821

2922
private ClusterSettings(final int startPortRange,
3023
final int clusterTotalNodes) {
31-
this.nodes = unmodifiableList(ClusterNode.from(startPortRange, clusterTotalNodes));
32-
this.nodeCount = nodes.size();
33-
this.oneNode = nodes.get(0).name;
34-
this.nodeNames = nodes.stream().map(node -> node.name).collect(Collectors.joining(","));
24+
this.startPortRange = startPortRange;
25+
this.nodeCount = clusterTotalNodes;
3526
this.quorum = nodeCount / 2 + 1;
3627
this.seed = (int)Math.round (((double) nodeCount) / 3.0d + 0.5d);
3728
}

src/main/java/io/vlingo/xoom/designer/infrastructure/restapi/data/DeploymentSettingsData.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ public DeploymentSettingsData(final String type,
4444
}
4545

4646
public List<String> validate(List<String> errorStrings) {
47-
if(type==null) errorStrings.add("DeploymentSettingsData.type is null");
48-
if(type.equals(DeploymentType.DOCKER.name()) && dockerImage==null) errorStrings.add("DeploymentSettingsData.dockerImage is null");
49-
if(type.equals(DeploymentType.KUBERNETES.name())) {
50-
if(kubernetesImage==null) errorStrings.add("DeploymentSettingsData.kubernetesImage is null");
51-
if(kubernetesPod==null) errorStrings.add("DeploymentSettingsData.kubernetesPod is null");
47+
if (type == null) errorStrings.add("DeploymentSettingsData.type is null");
48+
if (type.equals(DeploymentType.DOCKER.name()) && dockerImage == null)
49+
errorStrings.add("DeploymentSettingsData.dockerImage is null");
50+
if (type.equals(DeploymentType.KUBERNETES.name())) {
51+
if (kubernetesImage == null) errorStrings.add("DeploymentSettingsData.kubernetesImage is null");
52+
if (kubernetesPod == null) errorStrings.add("DeploymentSettingsData.kubernetesPod is null");
5253
}
5354
return errorStrings;
5455
}

src/main/resources/codegen/java/ClusterSettings.ftl

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,11 @@ cluster.attributes.redistribution.retries = 20
3939
# interval at which each health check is scheduled
4040
cluster.health.check.interval = 2000
4141

42-
# currently all active nodes must be listed as seed nodes
4342
<#if (clusterSettings.nodeCount > 1)>
44-
# -- comment the following to disable developer single-node cluster
45-
cluster.nodes = ${clusterSettings.oneNode}
46-
4743
# -- uncomment the following to enable all cluster nodes
48-
# cluster.nodes = ${clusterSettings.nodeNames}
44+
# cluster.seeds = localhost:${clusterSettings.startPortRange?c}
4945
# cluster.nodes.quorum = ${clusterSettings.quorum}
5046
# cluster.startup.period = 5000
5147
<#else>
52-
cluster.nodes = ${clusterSettings.nodeNames}
53-
cluster.nodes.quorum = ${clusterSettings.quorum}
5448
cluster.startup.period = 5000
5549
</#if>
56-
57-
################################
58-
# individual node configurations
59-
################################
60-
61-
<#list clusterSettings.nodes as node>
62-
<#if (node.id > 1)>#</#if>node.${node.name}.id = ${node.id}
63-
<#if (node.id > 1)>#</#if>node.${node.name}.name = ${node.name}<#if (clusterSettings.seed - node.id >= 0)>
64-
<#if (node.id > 1)>#</#if>node.${node.name}.seed = true</#if>
65-
<#if (node.id > 1)>#</#if>node.${node.name}.host = localhost
66-
<#if (node.id > 1)>#</#if>node.${node.name}.op.port = ${node.operationalPort?c}
67-
<#if (node.id > 1)>#</#if>node.${node.name}.app.port = ${node.applicationPort?c}
68-
69-
</#list>

src/main/resources/xoom-cluster.properties

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,3 @@ cluster.attributes.redistribution.retries = 20
4747

4848
# interval at which each health check is scheduled
4949
cluster.health.check.interval = 2000
50-
51-
# currently all active nodes must be listed as seed nodes
52-
cluster.nodes = node1
53-
54-
################################
55-
# individual node configurations
56-
################################
57-
58-
node.node1.id = 1
59-
node.node1.name = node1
60-
node.node1.host = localhost
61-
node.node1.op.port = 49101
62-
node.node1.app.port = 49102

src/test/resources/text-expectations/java/custom-xoom-cluster.text

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,61 +39,7 @@ cluster.attributes.redistribution.retries = 20
3939
# interval at which each health check is scheduled
4040
cluster.health.check.interval = 2000
4141

42-
# currently all active nodes must be listed as seed nodes
43-
# -- comment the following to disable developer single-node cluster
44-
cluster.nodes = node1
45-
4642
# -- uncomment the following to enable all cluster nodes
47-
# cluster.nodes = node1,node2,node3,node4,node5,node6,node7
43+
# cluster.seeds = localhost:42333
4844
# cluster.nodes.quorum = 4
4945
# cluster.startup.period = 5000
50-
51-
################################
52-
# individual node configurations
53-
################################
54-
55-
node.node1.id = 1
56-
node.node1.name = node1
57-
node.node1.seed = true
58-
node.node1.host = localhost
59-
node.node1.op.port = 42333
60-
node.node1.app.port = 42334
61-
62-
#node.node2.id = 2
63-
#node.node2.name = node2
64-
#node.node2.seed = true
65-
#node.node2.host = localhost
66-
#node.node2.op.port = 42335
67-
#node.node2.app.port = 42336
68-
69-
#node.node3.id = 3
70-
#node.node3.name = node3
71-
#node.node3.seed = true
72-
#node.node3.host = localhost
73-
#node.node3.op.port = 42337
74-
#node.node3.app.port = 42338
75-
76-
#node.node4.id = 4
77-
#node.node4.name = node4
78-
#node.node4.host = localhost
79-
#node.node4.op.port = 42339
80-
#node.node4.app.port = 42340
81-
82-
#node.node5.id = 5
83-
#node.node5.name = node5
84-
#node.node5.host = localhost
85-
#node.node5.op.port = 42341
86-
#node.node5.app.port = 42342
87-
88-
#node.node6.id = 6
89-
#node.node6.name = node6
90-
#node.node6.host = localhost
91-
#node.node6.op.port = 42343
92-
#node.node6.app.port = 42344
93-
94-
#node.node7.id = 7
95-
#node.node7.name = node7
96-
#node.node7.host = localhost
97-
#node.node7.op.port = 42345
98-
#node.node7.app.port = 42346
99-

0 commit comments

Comments
 (0)