ContainerCloneStep { public Map<String, ContainerQuota> execute() throws EnvironmentCreationException, PeerException { Map<String, Set<Node>> placement = topology.getNodeGroupPlacement(); SubnetUtils cidr = new SubnetUtils( environment.getSubnetCidr() ); List<String> addresses = Lists.newArrayList( cidr.getInfo().getAllAddresses() ); addresses.remove( cidr.getInfo().getLowAddress() ); for ( ContainerHost containerHost : environment.getContainerHosts() ) { addresses.remove( containerHost.getIp() ); } int totalAvailableIpCount = addresses.size(); int requestedContainerCount = 0; for ( Set<Node> nodes : placement.values() ) { requestedContainerCount += nodes.size(); } if ( requestedContainerCount > totalAvailableIpCount ) { throw new EnvironmentCreationException( String.format( "Requested %d containers but only %d IP addresses available", requestedContainerCount, totalAvailableIpCount ) ); } int currentOffset = 0; for ( Map.Entry<String, Set<Node>> peerPlacement : placement.entrySet() ) { Peer peer = peerManager.getPeer( peerPlacement.getKey() ); cloneUtil.addPeerTask( new PeerUtil.PeerTask<>( peer, new CreatePeerEnvironmentContainersTask( identityManager, peer, peerManager.getLocalPeer(), environment, addresses.subList( currentOffset, currentOffset + peerPlacement.getValue().size() ), peerPlacement.getValue(), operationTracker ) ) ); currentOffset += peerPlacement.getValue().size(); } PeerUtil.PeerTaskResults<CreateEnvironmentContainersResponse> cloneResults = cloneUtil.executeParallel(); boolean succeeded = true; for ( PeerUtil.PeerTaskResult<CreateEnvironmentContainersResponse> cloneResult : cloneResults.getResults() ) { CreateEnvironmentContainersResponse response = cloneResult.getResult(); String peerId = cloneResult.getPeer().getId(); succeeded &= processResponse( response, peerId ); } if ( !succeeded ) { throw new EnvironmentCreationException( "There were errors during container creation." ); } return containerQuotas; } ContainerCloneStep( final String defaultDomain, final Topology topology, final LocalEnvironment environment,
                               final PeerManager peerManager, final IdentityManager identityManager,
                               final TrackerOperation operationTracker ); Map<String, ContainerQuota> execute();  }
@Test( expected = EnvironmentCreationException.class ) public void testExecute() throws Exception { doReturn( true ).when( step ).processResponse( any( CreateEnvironmentContainersResponse.class ), anyString() ); step.execute(); verify( PEER_UTIL ).addPeerTask( any( PeerUtil.PeerTask.class ) ); doReturn( false ).when( step ).processResponse( any( CreateEnvironmentContainersResponse.class ), anyString() ); step.execute(); }