Skip to content

Commit

Permalink
adds the capability of adding new nodes after a deployment is started
Browse files Browse the repository at this point in the history
  • Loading branch information
arminbalalaie committed Mar 26, 2019
1 parent e1c9922 commit f8299e6
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 174 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ called when a specific stack trace is present.
pages/quickstart
pages/deterministic
pages/runseq
pages/newnode
pages/jvmservice
pages/docker
52 changes: 52 additions & 0 deletions docs/pages/newnode.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
============================
Adding New Nodes Dynamically
============================

It is possible to add new nodes dynamically after a defined deployment is started. New nodes can only be created out of
pre-defined services and they can't include any internal events. In the following code, ``service1`` service is first created
similar to the one in :doc:`quickstart`. Then, at line 31, a new node named ``n2`` is being created out of ``service1`` service.
``Node.limitedBuilder`` method returns an instance of ``Node.LimitedBuilder`` which then can be further customized by chaining the proper
method calls. This builder wouldn't allow the definition of internal events for the node. However, all the other node configurations
are available.

.. code-block:: java
:linenos:
public class SampleTestIT {
protected static FailifyRunner runner;
@BeforeClass
public static void before() throws RuntimeEngineException {
String projectVersion = "0.2.1";
Deployment deployment = Deployment.builder("sampleTest")
// Service Definition
.withService("service1")
.applicationPath("target/project.zip", "/project", PathAttr.COMPRESSED)
.startCommand("/project/bin/start.sh")
.dockerImage("project/sampleTest:" + projectVersion)
.dockerFileAddress("docker/Dockerfile", false)
.serviceType(ServiceType.JAVA).and()
// Node Definitions
.withNode("n1", "service1").and()
.build();
FailifyRunner runner = FailifyRunner.run(deployment);
}
@AfterClass
public static void after() {
if (runner != null) {
runner.stop();
}
}
public void test1() throws RuntimeEngineException {
..
runner.addNode(Node.limitedBuilder("n2", "s1"));
..
}
}
The current limitation of this capability is that if there is a network partition applied to the current deployment, the
new node wouldn't be included in that network partition. Introduction of new network partitions will include the new node
in generating blocking rules for iptables. This limitation will be removed in future releases.
7 changes: 7 additions & 0 deletions failify/src/main/java/io/failify/FailifyRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package io.failify;

import io.failify.dsl.entities.Node;
import io.failify.verification.DeploymentVerifier;
import io.failify.verification.InternalReferencesVerifier;
import io.failify.verification.RunSequenceVerifier;
Expand Down Expand Up @@ -194,6 +195,12 @@ public boolean isStopped() {
}
return runtimeEngine.isStopped();
}

public void addNode(Node.LimitedBuilder limitedBuilder) throws WorkspaceException, RuntimeEngineException {
Node node = limitedBuilder.build();
NodeWorkspace nodeWorkspace = workspaceManager.createNodeWorkspace(node);
runtimeEngine.addNewNode(node, nodeWorkspace);
}
}

class FailifyShutdownHook extends Thread {
Expand Down
4 changes: 4 additions & 0 deletions failify/src/main/java/io/failify/dsl/DeploymentEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public abstract static class BuilderBase<T extends DeploymentEntity, S extends B
protected S parentBuilder;

public BuilderBase(S parentBuilder, String name) {
if (name == null) {
throw new NullPointerException("A deployment entity name cannot be null");
}

this.name = name;
this.parentBuilder = parentBuilder;
}
Expand Down

0 comments on commit f8299e6

Please sign in to comment.