Source:
public ListenableFuture<Image> createImage(ImageTemplate template) { final CloneImageTemplate cloneTemplate = (CloneImageTemplate) template; final RegionAndId regionAndId = RegionAndId.fromSlashEncoded(cloneTemplate.getSourceNodeId()); ResourceGroup resourceGroup = resourceGroupMap.getUnchecked(regionAndId.region()); final String group = resourceGroup.name(); logger.debug(">> stopping node %s...", regionAndId.slashEncode()); api.getVirtualMachineApi(group).stop(regionAndId.id()); checkState(nodeSuspendedPredicate.create(group).apply(regionAndId.id()), "Node %s was not suspended within the configured time limit", regionAndId.slashEncode()); return userExecutor.submit(new Callable<Image>() { @Override public Image call() throws Exception { logger.debug(">> generalizing virtal machine %s...", regionAndId.id()); api.getVirtualMachineApi(group).generalize(regionAndId.id()); logger.debug(">> capturing virtual machine %s to container %s...", regionAndId.id(), CONTAINER_NAME); URI uri = api.getVirtualMachineApi(group) .capture(regionAndId.id(), cloneTemplate.getName(), CONTAINER_NAME); checkState(uri != null && imageAvailablePredicate.apply(uri), "Image %s was not created within the configured time limit", cloneTemplate.getName()); List<ResourceDefinition> definitions = api.getJobApi().captureStatus(uri); checkState(definitions.size() == 1, "Expected one resource definition after creating the image but %s were returned", definitions.size()); Image image = resourceDefinitionToImage.create(cloneTemplate.getSourceNodeId(), cloneTemplate.getName()) .apply(definitions.get(0)); logger.debug(">> created %s", image); return image; } }); }

Target:
public ListenableFuture<Image> createImage(ImageTemplate template) { final CloneImageTemplate cloneTemplate = (CloneImageTemplate) template; final RegionAndId regionAndId = RegionAndId.fromSlashEncoded(cloneTemplate.getSourceNodeId()); ResourceGroup resourceGroup = resourceGroupMap.getUnchecked(regionAndId.region()); final String resourceGroupName = resourceGroup.name(); logger.debug(">> stopping node %s...", regionAndId.slashEncode()); api.getVirtualMachineApi(resourceGroupName).stop(regionAndId.id()); checkState(nodeSuspendedPredicate.create(resourceGroupName).apply(regionAndId.id()), "Node %s was not suspended within the configured time limit", regionAndId.slashEncode()); return userExecutor.submit(new Callable<Image>() { @Override public Image call() throws Exception { logger.debug(">> generalizing virtal machine %s...", regionAndId.id()); api.getVirtualMachineApi(resourceGroupName).generalize(regionAndId.id()); logger.debug(">> capturing virtual machine %s to container %s...", regionAndId.id(), CONTAINER_NAME); URI uri = api.getVirtualMachineApi(resourceGroupName) .capture(regionAndId.id(), cloneTemplate.getName(), CONTAINER_NAME); checkState(uri != null && imageAvailablePredicate.apply(uri), "Image %s was not created within the configured time limit", cloneTemplate.getName()); List<ResourceDefinition> definitions = api.getJobApi().captureStatus(uri); checkState(definitions.size() == 1, "Expected one resource definition after creating the image but %s were returned", definitions.size()); Image image = resourceDefinitionToImage.create(cloneTemplate.getSourceNodeId(), cloneTemplate.getName()) .apply(definitions.get(0)); logger.debug(">> created %s", image); return image; } }); }