Skip to content

Commit

Permalink
implement agent-less for DockerCluster
Browse files Browse the repository at this point in the history
  • Loading branch information
wayerr committed Feb 7, 2017
1 parent c671b2e commit e576248
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.codeabovelab.dm.cluman.cluster.docker.management.DockerServiceEvent;
import com.codeabovelab.dm.cluman.cluster.docker.management.argument.GetContainersArg;
import com.codeabovelab.dm.cluman.cluster.docker.model.EventType;
import com.codeabovelab.dm.cluman.ds.SwarmUtils;
import com.codeabovelab.dm.cluman.ds.nodes.NodeStorage;
import com.codeabovelab.dm.cluman.model.*;
import com.codeabovelab.dm.common.mb.Subscriptions;
Expand All @@ -46,7 +45,6 @@
@Slf4j
@Component
class ContainerInfoUpdater implements SmartLifecycle {
private static final long DELAY = 60_000L;
private final ContainerStorageImpl containerStorage;
private final ConcurrentMap<String, RescheduledTask> scheduledNodes;
private final ScheduledExecutorService scheduledService;
Expand Down Expand Up @@ -208,7 +206,7 @@ private void onNodeEvent(NodeEvent nodeEvent) {
}
}

@Scheduled(fixedDelayString = SwarmUtils.EXPR_NODES_UPDATE_MS)
@Scheduled(fixedDelay = 5L * 60_000L /* 5 min */)
public void update() {
try(TempAuth ta = TempAuth.asSystem()) {
log.info("Begin update containers list");
Expand All @@ -218,7 +216,6 @@ public void update() {
if(nodeService == null) {
continue;
}
nodeStorage.updateNode(node, ((int)DELAY/1000) * 2, null);
updateForNode(nodeService);
}
log.info("End update containers list");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class NodeRegistrationImpl implements NodeRegistration, AutoCloseable {
.build());
}

void init() {
renewDocker();
}

/**
* Invoke updating state (save into KV-storage) of node with specified ttl.
* @param ttl in seconds
Expand Down Expand Up @@ -235,13 +239,17 @@ DockerService setAddress(String address) {
if(docker != null && docker.getAddress().equals(address)) {
return getDocker();
}
unsubscribe();
this.docker = this.nodeStorage.createNodeService(this);
subscribe();
renewDocker();
return getDocker();
}
}

private void renewDocker() {
unsubscribe();
this.docker = this.nodeStorage.createNodeService(this);
subscribe();
}

private void subscribe() {
log.info("Begin register node for fetching logs {}", name);
DockerEventsConfig cfg = nodeStorage.getDockerEventConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,19 @@ private void onDockerServiceEvent(DockerServiceEvent e) {
private void checkNodes() {
// periodically check online status of nodes
try(TempAuth ta = TempAuth.asSystem()) {
log.info("Begin update list of nodes");
for(NodeRegistrationImpl nr: nodes.values()) {
log.info("Update node '{}' of '{}' cluster", nr.getName(), nr.getCluster());
nr.getNodeInfo();
}
log.info("End update list of nodes");
}
}

NodeRegistrationImpl newRegistration(NodeInfo nodeInfo) {
return new NodeRegistrationImpl(this, persistentBusFactory, nodeInfo);
NodeRegistrationImpl nr = new NodeRegistrationImpl(this, persistentBusFactory, nodeInfo);
nr.init();
return nr;
}

public boolean hasNode(Predicate<Object> predicate, String nodeId) {
Expand Down

0 comments on commit e576248

Please sign in to comment.