PEKGenerationStep { public void execute() throws PeerException { PGPSecretKeyRing envSecKeyRing = getEnvironmentKeyRing(); Set<Peer> peers = peerManager.resolve( topology.getAllPeers() ); peers.remove( peerManager.getLocalPeer() ); PGPPublicKeyRing localPeerSignedPEK; try { RelationLinkDto envLink = new RelationLinkDto( environment ); PublicKeyContainer publicKeyContainer = peerManager.getLocalPeer().createPeerEnvironmentKeyPair( envLink ); PGPPublicKeyRing pubRing = readPublicKeyRing( publicKeyContainer ); localPeerSignedPEK = securityManager.getKeyManager().setKeyTrust( envSecKeyRing, pubRing, KeyTrustLevel.FULL.getId() ); peerManager.getLocalPeer() .updatePeerEnvironmentPubKey( environment.getEnvironmentId(), localPeerSignedPEK ); trackerOperation.addLog( "PEK generation succeeded on Local Peer" ); } catch ( Exception e ) { throw new PeerException( String.format( "Could not create PEK for %s: %s", peerManager.getLocalPeer().getId(), e.getMessage() ) ); } if ( peers.isEmpty() ) { return; } for ( final Peer peer : peers ) { pekUtil.addPeerTask( new PeerUtil.PeerTask<>( peer, new PeerEnvironmentKeyTask( peerManager.getLocalPeer(), envSecKeyRing, localPeerSignedPEK, environment, peer, securityManager.getKeyManager() ) ) ); } PeerUtil.PeerTaskResults<Object> pekResults = pekUtil.executeParallel(); for ( PeerUtil.PeerTaskResult pekResult : pekResults.getResults() ) { if ( pekResult.hasSucceeded() ) { trackerOperation.addLog( String.format( "PEK generation succeeded on peer %s", pekResult.getPeer().getName() ) ); } else { trackerOperation.addLog( String.format( "PEK generation failed on peer %s. Reason: %s", pekResult.getPeer().getName(), pekResult.getFailureReason() ) ); } } if ( pekResults.hasFailures() ) { throw new PeerException( "Failed to generate PEK across all peers" ); } } PEKGenerationStep( final Topology topology, final Environment environment, final PeerManager peerManager,
                              SecurityManager securityManager, TrackerOperation trackerOperation ); void execute();  }
@Test( expected = PeerException.class ) public void testExecute() throws Exception { doReturn( true ).when( peerTaskResult ).hasSucceeded(); step.execute(); verify( PEER_UTIL ).executeParallel(); doReturn( false ).when( peerTaskResult ).hasSucceeded(); doReturn( true ).when( peerTaskResults ).hasFailures(); step.execute(); }