}
String statusPath = Paths.build(Paths.STREAM_DEPLOYMENTS, stream.getName(), Paths.STATUS);
// assert that the deployment status has been correctly set to "deploying"
DeploymentUnitStatus deployingStatus = null;
try {
deployingStatus = new DeploymentUnitStatus(ZooKeeperUtils.bytesToMap(
client.getData().forPath(statusPath)));
}
catch (Exception e) {
// an exception indicates that the status has not been set
}
Assert.state(deployingStatus != null
&& deployingStatus.getState() == DeploymentUnitStatus.State.deploying,
String.format("Expected 'deploying' status for stream '%s'; current status: %s",
stream.getName(), deployingStatus));
try {
Collection<ModuleDeploymentStatus> deploymentStatuses = new ArrayList<ModuleDeploymentStatus>();
DefaultModuleDeploymentPropertiesProvider deploymentPropertiesProvider =
new DefaultModuleDeploymentPropertiesProvider(stream);
for (Iterator<ModuleDescriptor> descriptors = stream.getDeploymentOrderIterator(); descriptors.hasNext();) {
ModuleDescriptor descriptor = descriptors.next();
ModuleDeploymentProperties deploymentProperties = deploymentPropertiesProvider.propertiesForDescriptor(descriptor);
// write out all of the required modules for this stream (including runtime properties);
// this does not actually perform a deployment...this data is used in case there are not
// enough containers to deploy the stream
StreamRuntimePropertiesProvider partitionPropertiesProvider =
new StreamRuntimePropertiesProvider(stream, deploymentPropertiesProvider);
int moduleCount = deploymentProperties.getCount();
if (moduleCount == 0) {
createModuleDeploymentRequestsPath(client, descriptor,
partitionPropertiesProvider.propertiesForDescriptor(descriptor));
}
else {
for (int i = 0; i < moduleCount; i++) {
createModuleDeploymentRequestsPath(client, descriptor,
partitionPropertiesProvider.propertiesForDescriptor(descriptor));
}
}
try {
// find the containers that can deploy these modules
Collection<Container> containers = containerMatcher.match(descriptor, deploymentProperties,
containerRepository.findAll());
// write out the deployment requests targeted to the containers obtained above;
// a new instance of StreamPartitionPropertiesProvider is created since this
// object is responsible for generating unique sequence ids for modules
StreamRuntimePropertiesProvider deploymentRuntimeProvider =
new StreamRuntimePropertiesProvider(stream, deploymentPropertiesProvider);
deploymentStatuses.addAll(moduleDeploymentWriter.writeDeployment(
descriptor, deploymentRuntimeProvider, containers));
}
catch (NoContainerException e) {
logger.warn("No containers available for deployment of module '{}' for stream '{}'",
descriptor.getModuleLabel(), stream.getName());
}
}
DeploymentUnitStatus status = stateCalculator.calculate(stream, deploymentPropertiesProvider,
deploymentStatuses);
logger.info("Deployment status for stream '{}': {}", stream.getName(), status);
client.setData().forPath(statusPath, ZooKeeperUtils.mapToBytes(status.toMap()));
}
catch (InterruptedException e) {
throw e;
}
catch (Exception e) {