Source:
private void snapshotMachines(Map<String, DockerMachine> machines) { List<SnapshotImpl> newSnapshots = new ArrayList<>(); final RuntimeIdentity identity = getContext().getIdentity(); String devMachineName; Optional<String> devMachineNameOpt = WsAgentMachineFinderUtil.getWsAgentInstallerMachine(getContext().getEnvironment()); if (!devMachineNameOpt.isPresent()) { LOG.error("Dev machine is not found"); return; } devMachineName = devMachineNameOpt.get(); for (Map.Entry<String, DockerMachine> dockerMachineEntry : machines.entrySet()) { SnapshotImpl snapshot = SnapshotImpl.builder() .generateId() .setType("docker") .setWorkspaceId(identity.getWorkspaceId()) .setDescription(identity.getEnvName()) .setDev(devMachineName.equals(dockerMachineEntry.getKey())) .setEnvName(identity.getEnvName()) .setMachineName(dockerMachineEntry.getKey()) .useCurrentCreationDate() .build(); try { ProgressMonitor monitor = loggers.newProgressMonitor(dockerMachineEntry.getKey(), identity); DockerMachineSource machineSource = dockerMachineEntry.getValue().saveToSnapshot(monitor); snapshot.setMachineSource(new MachineSourceImpl(machineSource)); newSnapshots.add(snapshot); } catch (SnapshotException e) { LOG.error( format( "Error occurs on snapshotting of docker machine '%s' in workspace '%s'. Container '%s'", dockerMachineEntry.getKey(), identity.getWorkspaceId(), dockerMachineEntry.getValue().getContainer()), e); } } try { List<SnapshotImpl> removed = snapshotDao.replaceSnapshots( identity.getWorkspaceId(), identity.getEnvName(), newSnapshots); if (!removed.isEmpty()) { LOG.info( "Removing old snapshots binaries, workspace id '{}', snapshots to remove '{}'", identity.getWorkspaceId(), removed.size()); removeBinaries(removed); } } catch (SnapshotException e) { LOG.error( format( "Couldn't remove existing snapshots metadata for workspace '%s'", identity.getWorkspaceId()), e); removeBinaries(newSnapshots); } }

Target:
private void snapshotMachines(Map<String, DockerMachine> machines) throws InternalInfrastructureException { List<SnapshotImpl> newSnapshots = new ArrayList<>(); final RuntimeIdentity identity = getContext().getIdentity(); String devMachineName = WsAgentMachineFinderUtil.getWsAgentServerMachine(getContext().getEnvironment()) .orElseThrow( () -> new InternalInfrastructureException("Machine with wsagent is not found")); for (Map.Entry<String, DockerMachine> dockerMachineEntry : machines.entrySet()) { SnapshotImpl snapshot = SnapshotImpl.builder() .generateId() .setType("docker") .setWorkspaceId(identity.getWorkspaceId()) .setDescription(identity.getEnvName()) .setDev(devMachineName.equals(dockerMachineEntry.getKey())) .setEnvName(identity.getEnvName()) .setMachineName(dockerMachineEntry.getKey()) .useCurrentCreationDate() .build(); try { ProgressMonitor monitor = loggers.newProgressMonitor(dockerMachineEntry.getKey(), identity); DockerMachineSource machineSource = dockerMachineEntry.getValue().saveToSnapshot(monitor); snapshot.setMachineSource(new MachineSourceImpl(machineSource)); newSnapshots.add(snapshot); } catch (SnapshotException e) { LOG.error( format( "Error occurs on snapshotting of docker machine '%s' in workspace '%s'. Container '%s'", dockerMachineEntry.getKey(), identity.getWorkspaceId(), dockerMachineEntry.getValue().getContainer()), e); } } try { List<SnapshotImpl> removed = snapshotDao.replaceSnapshots( identity.getWorkspaceId(), identity.getEnvName(), newSnapshots); if (!removed.isEmpty()) { LOG.info( "Removing old snapshots binaries, workspace id '{}', snapshots to remove '{}'", identity.getWorkspaceId(), removed.size()); removeBinaries(removed); } } catch (SnapshotException e) { LOG.error( format( "Couldn't remove existing snapshots metadata for workspace '%s'", identity.getWorkspaceId()), e); removeBinaries(newSnapshots); } }