Skip to content

Commit

Permalink
#2642 added check if peer can provide requested amount of resources f…
Browse files Browse the repository at this point in the history
…or local environments
  • Loading branch information
Dilshat Aliev committed Sep 10, 2018
1 parent 6fcd666 commit 4078fc7
Showing 1 changed file with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import io.subutai.common.environment.EnvironmentNotFoundException;
import io.subutai.common.environment.EnvironmentPeer;
import io.subutai.common.environment.EnvironmentStatus;
import io.subutai.common.environment.Node;
import io.subutai.common.environment.Nodes;
import io.subutai.common.environment.Topology;
import io.subutai.common.exception.ActionFailedException;
import io.subutai.common.host.ContainerHostInfo;
Expand Down Expand Up @@ -440,6 +442,24 @@ Environment createEnvironment( final Topology topology, final boolean async, Tra

throw new EnvironmentCreationException( String.format( "Peer %s is offline", peer.getName() ) );
}


try
{
if ( !peer.canAccommodate( new Nodes( topology.getPeerNodes( peer.getId() ) ) ) )
{
operationTracker.addLogFailed(
String.format( "Peer %s can not accommodate the requested containers", peer.getName() ) );

throw new EnvironmentCreationException(
String.format( "Peer %s can not accommodate the requested containers", peer.getName() ) );
}
}
catch ( PeerException e )
{
operationTracker.addLogFailed( e.getMessage() );
throw new EnvironmentCreationException( e.getMessage() );
}
}


Expand Down Expand Up @@ -602,6 +622,35 @@ public EnvironmentCreationRef modifyEnvironment( final String environmentId, fin

throw new EnvironmentModificationException( String.format( "Peer %s is offline", peer.getName() ) );
}

Set<Node> newNodes = topology == null ? Sets.<Node>newHashSet() : topology.getPeerNodes( peer.getId() );
Map<String, ContainerQuota> changedQuotas =
getPeerChangedContainers( peer.getId(), changedContainers, environment );

//check if peer can accommodate the requested nodes
if ( ( hasContainerCreation && !newNodes.isEmpty() ) || ( hasQuotaModification && !changedQuotas
.isEmpty() ) )
{
try
{
if ( !peer.canAccommodate( new Nodes( newNodes, changedQuotas ) ) )
{
operationTracker.addLogFailed(
String.format( "Peer %s can not accommodate the requested containers",
peer.getName() ) );

throw new EnvironmentModificationException(
String.format( "Peer %s can not accommodate the requested containers",
peer.getName() ) );
}
}
catch ( PeerException e )
{
operationTracker.addLogFailed( e.getMessage() );

throw new EnvironmentModificationException( e.getMessage() );
}
}
}

if ( environment.getStatus() == EnvironmentStatus.UNDER_MODIFICATION
Expand Down Expand Up @@ -668,8 +717,7 @@ public void run()


private Map<String, ContainerQuota> getPeerChangedContainers( final String peerId,
final Map<String, ContainerQuota>
allChangedContainers,
final Map<String, ContainerQuota> allChangedContainers,
final LocalEnvironment environment )
throws EnvironmentModificationException
{
Expand Down Expand Up @@ -1552,8 +1600,7 @@ PGPSecretKeyRing createEnvironmentKeyPair( EnvironmentId envId ) throws Environm
protected P2PSecretKeyModificationWorkflow getP2PSecretKeyModificationWorkflow( final LocalEnvironment environment,
final String p2pSecretKey,
final long p2pSecretKeyTtlSec,
final TrackerOperation
operationTracker )
final TrackerOperation operationTracker )
{
return new P2PSecretKeyModificationWorkflow( environment, p2pSecretKey, p2pSecretKeyTtlSec, operationTracker,
this );
Expand Down Expand Up @@ -1596,8 +1643,7 @@ protected EnvironmentModifyWorkflow getEnvironmentModifyingWorkflow( final Local
final Topology topology,
final TrackerOperation operationTracker,
final List<String> removedContainers,
final Map<String, ContainerQuota>
changedContainers )
final Map<String, ContainerQuota> changedContainers )

{
return new EnvironmentModifyWorkflow( Common.DEFAULT_DOMAIN_NAME, identityManager, peerManager, securityManager,
Expand All @@ -1606,8 +1652,7 @@ protected EnvironmentModifyWorkflow getEnvironmentModifyingWorkflow( final Local


protected EnvironmentDestructionWorkflow getEnvironmentDestructionWorkflow( final LocalEnvironment environment,
final TrackerOperation
operationTracker )
final TrackerOperation operationTracker )
{
return new EnvironmentDestructionWorkflow( this, environment, operationTracker );
}
Expand Down

0 comments on commit 4078fc7

Please sign in to comment.