public void recalculateStreamStates(CuratorFramework client, PathChildrenCache streamDeployments) throws Exception {
for (Iterator<String> iterator =
new ChildPathIterator<String>(ZooKeeperUtils.stripPathConverter, streamDeployments); iterator.hasNext();) {
String streamName = iterator.next();
String definitionPath = Paths.build(Paths.build(Paths.STREAM_DEPLOYMENTS, streamName));
Stream stream = DeploymentLoader.loadStream(client, streamName, streamFactory);
if (stream != null) {
String streamModulesPath = Paths.build(definitionPath, Paths.MODULES);
List<ModuleDeploymentStatus> statusList = new ArrayList<ModuleDeploymentStatus>();
try {
List<String> moduleDeployments = client.getChildren().forPath(streamModulesPath);
for (String moduleDeployment : moduleDeployments) {
StreamDeploymentsPath streamDeploymentsPath = new StreamDeploymentsPath(
Paths.build(streamModulesPath, moduleDeployment));
statusList.add(new ModuleDeploymentStatus(
streamDeploymentsPath.getContainer(),
streamDeploymentsPath.getModuleSequence(),
new ModuleDescriptor.Key(streamName,
ModuleType.valueOf(streamDeploymentsPath.getModuleType()),
streamDeploymentsPath.getModuleLabel()),
ModuleDeploymentStatus.State.deployed, null));
}
}
catch (KeeperException.NoNodeException e) {
// indicates there are no modules deployed for this stream;
// ignore as this will result in an empty statusList
}
DeploymentUnitStatus status = stateCalculator.calculate(stream,
new DefaultModuleDeploymentPropertiesProvider(stream), statusList);
logger.info("Deployment status for stream '{}': {}", stream.getName(), status);
String statusPath = Paths.build(Paths.STREAM_DEPLOYMENTS, stream.getName(), Paths.STATUS);
Stat stat = client.checkExists().forPath(statusPath);
if (stat != null) {
logger.trace("Found old status path {}; stat: {}", statusPath, stat);
client.delete().forPath(statusPath);
}