Skip to content

Commit

Permalink
Merge pull request #303 from atomix/partitions
Browse files Browse the repository at this point in the history
Atomix 2 partitioning
  • Loading branch information
kuujo committed Nov 8, 2017
2 parents c4d31af + 764384f commit 57fbc1f
Show file tree
Hide file tree
Showing 250 changed files with 4,439 additions and 1,086 deletions.
76 changes: 76 additions & 0 deletions cluster/pom.xml
@@ -0,0 +1,76 @@
<!--
~ Copyright 2017-present Open Networking Foundation
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.atomix</groupId>
<artifactId>atomix-parent</artifactId>
<version>2.0.7-SNAPSHOT</version>
</parent>

<packaging>bundle</packaging>
<artifactId>atomix-cluster</artifactId>
<name>Atomix Cluster</name>

<dependencies>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-event</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-messaging</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-failure-detection</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-kryo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-utils</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>
io.atomix.*
</Export-Package>
<Import-Package>
!sun.nio.ch,!sun.misc,*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Expand Up @@ -32,27 +32,22 @@ public enum Type {
/**
* Signifies that a new cluster instance has been administratively added.
*/
INSTANCE_ADDED,
NODE_ADDED,

/**
* Signifies that a cluster instance has been administratively removed.
*/
INSTANCE_REMOVED,
NODE_REMOVED,

/**
* Signifies that a cluster instance became active.
*/
INSTANCE_ACTIVATED,

/**
* Signifies that a cluster instance became ready.
*/
INSTANCE_READY,
NODE_ACTIVATED,

/**
* Signifies that a cluster instance became inactive.
*/
INSTANCE_DEACTIVATED
NODE_DEACTIVATED
}

/**
Expand Down
155 changes: 155 additions & 0 deletions cluster/src/main/java/io/atomix/cluster/ClusterMetadata.java
@@ -0,0 +1,155 @@
/*
* Copyright 2017-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.atomix.cluster;

import io.atomix.cluster.Node.Type;
import io.atomix.cluster.impl.DefaultNode;

import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;

import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;

/**
* Cluster metadata.
*/
public class ClusterMetadata {

/**
* Returns a new cluster metadata builder.
*
* @return a new cluster metadata builder
*/
public static Builder newBuilder() {
return new Builder();
}

private final String name;
private final Node localNode;
private final Collection<Node> bootstrapNodes;

protected ClusterMetadata(
String name,
Node localNode,
Collection<Node> bootstrapNodes) {
this.name = checkNotNull(name, "name cannot be null");
this.localNode = ((DefaultNode) localNode).setType(bootstrapNodes.contains(localNode) ? Type.CORE : Type.CLIENT);
this.bootstrapNodes = bootstrapNodes.stream()
.map(node -> ((DefaultNode) node).setType(Type.CORE))
.collect(Collectors.toList());
}

/**
* Returns the cluster name.
*
* @return the cluster name
*/
public String name() {
return name;
}

/**
* Returns the local node.
*
* @return the local node
*/
public Node localNode() {
return localNode;
}

/**
* Returns the collection of bootstrap nodes.
*
* @return the collection of bootstrap nodes
*/
public Collection<Node> bootstrapNodes() {
return bootstrapNodes;
}

@Override
public String toString() {
return toStringHelper(this)
.add("name", name)
.add("localNode", localNode)
.toString();
}

/**
* Cluster metadata builder.
*/
public static class Builder implements io.atomix.utils.Builder<ClusterMetadata> {
private static final String DEFAULT_CLUSTER_NAME = "atomix";
protected String name = DEFAULT_CLUSTER_NAME;
protected Node localNode;
protected Collection<Node> bootstrapNodes;

/**
* Sets the cluster name.
*
* @param name the cluster name
* @return the cluster metadata builder
* @throws NullPointerException if the name is null
*/
public Builder withClusterName(String name) {
this.name = checkNotNull(name, "name cannot be null");
return this;
}

/**
* Sets the local node metadata.
*
* @param localNode the local node metadata
* @return the cluster metadata builder
*/
public Builder withLocalNode(Node localNode) {
this.localNode = checkNotNull(localNode, "localNode cannot be null");
return this;
}

/**
* Sets the bootstrap nodes.
*
* @param bootstrapNodes the nodes from which to bootstrap the cluster
* @return the cluster metadata builder
* @throws NullPointerException if the bootstrap nodes are {@code null}
*/
public Builder withBootstrapNodes(Node... bootstrapNodes) {
return withBootstrapNodes(Arrays.asList(checkNotNull(bootstrapNodes)));
}

/**
* Sets the bootstrap nodes.
*
* @param bootstrapNodes the nodes from which to bootstrap the cluster
* @return the cluster metadata builder
* @throws NullPointerException if the bootstrap nodes are {@code null}
*/
public Builder withBootstrapNodes(Collection<Node> bootstrapNodes) {
this.bootstrapNodes = checkNotNull(bootstrapNodes, "bootstrapNodes cannot be null");
return this;
}

@Override
public ClusterMetadata build() {
return new ClusterMetadata(
name,
localNode,
bootstrapNodes);
}
}
}
Expand Up @@ -30,31 +30,21 @@ public interface ClusterService extends ListenerService<ClusterEvent, ClusterEve
*
* @return local controller node
*/
Node getLocalNode();
Node localNode();

/**
* Returns the set of current cluster members.
*
* @return set of cluster members
*/
Set<Node> getNodes();
Set<Node> nodes();

/**
* Returns the specified controller node.
*
* @param nodeId controller node identifier
* @return controller node
*/
Node getNode(NodeId nodeId);

/**
* Returns the availability state of the specified controller node. Note
* that this does not imply that all the core and application components
* have been fully activated; only that the node has joined the cluster.
*
* @param nodeId controller node identifier
* @return availability state
*/
Node.State getState(NodeId nodeId);
Node node(NodeId nodeId);

}
Expand Up @@ -15,18 +15,10 @@
*/
package io.atomix.cluster;

import io.atomix.time.Timestamp;
import io.atomix.utils.Managed;

/**
* Logical clock service.
* Managed cluster.
*/
public interface LogicalClockService {

/**
* Returns the current logical timestamp.
*
* @return the current logical timestamp
*/
Timestamp getTimestamp();

public interface ManagedClusterService extends ClusterService, Managed<ClusterService> {
}

0 comments on commit 57fbc1f

Please sign in to comment.