Skip to content

Commit

Permalink
Add separate bootstrap service for bootstrapping cluster configuratio…
Browse files Browse the repository at this point in the history
…ns and integrate broadcast service into cluster service.
  • Loading branch information
kuujo committed Apr 3, 2018
1 parent 95cd3c0 commit aef3c16
Show file tree
Hide file tree
Showing 22 changed files with 796 additions and 183 deletions.
@@ -0,0 +1,35 @@
/*
* Copyright 2018-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.messaging.Endpoint;

import java.util.Collection;
import java.util.concurrent.CompletableFuture;

/**
* Bootstrap metadata provider.
*/
public interface BootstrapMetadataProvider {

/**
* Returns a collection of endpoints from which to bootstrap the cluster.
*
* @return a collection of endpoints from which to bootstrap the cluster
*/
CompletableFuture<Collection<Endpoint>> bootstrap();

}
@@ -0,0 +1,22 @@
/*
* Copyright 2018-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;

/**
* Bootstrap metadata service.
*/
public interface BootstrapMetadataService extends ClusterMetadataService {
}
30 changes: 15 additions & 15 deletions cluster/src/main/java/io/atomix/cluster/ClusterMetadata.java
Expand Up @@ -38,10 +38,10 @@ public static Builder builder() {
return new Builder(); return new Builder();
} }


private final Collection<Node> bootstrapNodes; private final Collection<Node> nodes;


public ClusterMetadata(Collection<Node> bootstrapNodes) { public ClusterMetadata(Collection<Node> nodes) {
this.bootstrapNodes = bootstrapNodes.stream() this.nodes = nodes.stream()
.filter(node -> node.type() == Type.CORE) .filter(node -> node.type() == Type.CORE)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
Expand All @@ -51,22 +51,22 @@ public ClusterMetadata(Collection<Node> bootstrapNodes) {
* *
* @return the collection of bootstrap nodes * @return the collection of bootstrap nodes
*/ */
public Collection<Node> bootstrapNodes() { public Collection<Node> nodes() {
return bootstrapNodes; return nodes;
} }


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


/** /**
* Cluster metadata builder. * Cluster metadata builder.
*/ */
public static class Builder implements io.atomix.utils.Builder<ClusterMetadata> { public static class Builder implements io.atomix.utils.Builder<ClusterMetadata> {
protected Collection<Node> bootstrapNodes; protected Collection<Node> nodes;


/** /**
* Sets the bootstrap nodes. * Sets the bootstrap nodes.
Expand All @@ -75,25 +75,25 @@ public static class Builder implements io.atomix.utils.Builder<ClusterMetadata>
* @return the cluster metadata builder * @return the cluster metadata builder
* @throws NullPointerException if the bootstrap nodes are {@code null} * @throws NullPointerException if the bootstrap nodes are {@code null}
*/ */
public Builder withBootstrapNodes(Node... bootstrapNodes) { public Builder withNodes(Node... bootstrapNodes) {
return withBootstrapNodes(Arrays.asList(checkNotNull(bootstrapNodes))); return withNodes(Arrays.asList(checkNotNull(bootstrapNodes)));
} }


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


@Override @Override
public ClusterMetadata build() { public ClusterMetadata build() {
return new ClusterMetadata(bootstrapNodes); return new ClusterMetadata(nodes);
} }
} }
} }
22 changes: 22 additions & 0 deletions cluster/src/main/java/io/atomix/cluster/CoreMetadataService.java
@@ -0,0 +1,22 @@
/*
* Copyright 2018-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;

/**
* Core metadata service.
*/
public interface CoreMetadataService extends ClusterMetadataService {
}
@@ -0,0 +1,22 @@
/*
* Copyright 2018-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;

/**
* Managed bootstrap metadata service.
*/
public interface ManagedBootstrapMetadataService extends BootstrapMetadataService, ManagedClusterMetadataService {
}
Expand Up @@ -21,19 +21,4 @@
* Managed cluster metadata service. * Managed cluster metadata service.
*/ */
public interface ManagedClusterMetadataService extends ClusterMetadataService, Managed<ClusterMetadataService> { public interface ManagedClusterMetadataService extends ClusterMetadataService, Managed<ClusterMetadataService> {

/**
* Adds the given node to the cluster metadata.
*
* @param node the node to add to the cluster metadata
*/
void addNode(Node node);

/**
* Removes the given node from the cluster metadata.
*
* @param node the node to remove from the cluster metadata
*/
void removeNode(Node node);

} }
@@ -0,0 +1,37 @@
/*
* Copyright 2018-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;

/**
* Managed core metadata service.
*/
public interface ManagedCoreMetadataService extends CoreMetadataService, ManagedClusterMetadataService {

/**
* Adds the given node to the cluster metadata.
*
* @param node the node to add to the cluster metadata
*/
void addNode(Node node);

/**
* Removes the given node from the cluster metadata.
*
* @param node the node to remove from the cluster metadata
*/
void removeNode(Node node);

}
@@ -0,0 +1,76 @@
/*
* Copyright 2018-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.impl;

import io.atomix.cluster.ClusterMetadata;
import io.atomix.cluster.ClusterMetadataEventListener;
import io.atomix.cluster.ClusterMetadataService;
import io.atomix.cluster.ManagedBootstrapMetadataService;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;

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

/**
* Default bootstrap metadata service.
*/
public class DefaultBootstrapMetadataService implements ManagedBootstrapMetadataService {
private final ClusterMetadata metadata;
private final AtomicBoolean started = new AtomicBoolean();

public DefaultBootstrapMetadataService(ClusterMetadata metadata) {
this.metadata = metadata;
}

@Override
public ClusterMetadata getMetadata() {
return metadata;
}

@Override
public void addListener(ClusterMetadataEventListener listener) {

}

@Override
public void removeListener(ClusterMetadataEventListener listener) {

}

@Override
public CompletableFuture<ClusterMetadataService> start() {
started.set(true);
return CompletableFuture.completedFuture(this);
}

@Override
public boolean isRunning() {
return started.get();
}

@Override
public CompletableFuture<Void> stop() {
return CompletableFuture.completedFuture(null);
}

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

0 comments on commit aef3c16

Please sign in to comment.