Skip to content

Commit 4078fc7

Browse files
author
Dilshat Aliev
committed
#2642 added check if peer can provide requested amount of resources for local environments
1 parent 6fcd666 commit 4078fc7

File tree

1 file changed

+53
-8
lines changed
  • management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl

1 file changed

+53
-8
lines changed

management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/EnvironmentManagerImpl.java

+53-8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import io.subutai.common.environment.EnvironmentNotFoundException;
4646
import io.subutai.common.environment.EnvironmentPeer;
4747
import io.subutai.common.environment.EnvironmentStatus;
48+
import io.subutai.common.environment.Node;
49+
import io.subutai.common.environment.Nodes;
4850
import io.subutai.common.environment.Topology;
4951
import io.subutai.common.exception.ActionFailedException;
5052
import io.subutai.common.host.ContainerHostInfo;
@@ -440,6 +442,24 @@ Environment createEnvironment( final Topology topology, final boolean async, Tra
440442

441443
throw new EnvironmentCreationException( String.format( "Peer %s is offline", peer.getName() ) );
442444
}
445+
446+
447+
try
448+
{
449+
if ( !peer.canAccommodate( new Nodes( topology.getPeerNodes( peer.getId() ) ) ) )
450+
{
451+
operationTracker.addLogFailed(
452+
String.format( "Peer %s can not accommodate the requested containers", peer.getName() ) );
453+
454+
throw new EnvironmentCreationException(
455+
String.format( "Peer %s can not accommodate the requested containers", peer.getName() ) );
456+
}
457+
}
458+
catch ( PeerException e )
459+
{
460+
operationTracker.addLogFailed( e.getMessage() );
461+
throw new EnvironmentCreationException( e.getMessage() );
462+
}
443463
}
444464

445465

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

603623
throw new EnvironmentModificationException( String.format( "Peer %s is offline", peer.getName() ) );
604624
}
625+
626+
Set<Node> newNodes = topology == null ? Sets.<Node>newHashSet() : topology.getPeerNodes( peer.getId() );
627+
Map<String, ContainerQuota> changedQuotas =
628+
getPeerChangedContainers( peer.getId(), changedContainers, environment );
629+
630+
//check if peer can accommodate the requested nodes
631+
if ( ( hasContainerCreation && !newNodes.isEmpty() ) || ( hasQuotaModification && !changedQuotas
632+
.isEmpty() ) )
633+
{
634+
try
635+
{
636+
if ( !peer.canAccommodate( new Nodes( newNodes, changedQuotas ) ) )
637+
{
638+
operationTracker.addLogFailed(
639+
String.format( "Peer %s can not accommodate the requested containers",
640+
peer.getName() ) );
641+
642+
throw new EnvironmentModificationException(
643+
String.format( "Peer %s can not accommodate the requested containers",
644+
peer.getName() ) );
645+
}
646+
}
647+
catch ( PeerException e )
648+
{
649+
operationTracker.addLogFailed( e.getMessage() );
650+
651+
throw new EnvironmentModificationException( e.getMessage() );
652+
}
653+
}
605654
}
606655

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

669718

670719
private Map<String, ContainerQuota> getPeerChangedContainers( final String peerId,
671-
final Map<String, ContainerQuota>
672-
allChangedContainers,
720+
final Map<String, ContainerQuota> allChangedContainers,
673721
final LocalEnvironment environment )
674722
throws EnvironmentModificationException
675723
{
@@ -1552,8 +1600,7 @@ PGPSecretKeyRing createEnvironmentKeyPair( EnvironmentId envId ) throws Environm
15521600
protected P2PSecretKeyModificationWorkflow getP2PSecretKeyModificationWorkflow( final LocalEnvironment environment,
15531601
final String p2pSecretKey,
15541602
final long p2pSecretKeyTtlSec,
1555-
final TrackerOperation
1556-
operationTracker )
1603+
final TrackerOperation operationTracker )
15571604
{
15581605
return new P2PSecretKeyModificationWorkflow( environment, p2pSecretKey, p2pSecretKeyTtlSec, operationTracker,
15591606
this );
@@ -1596,8 +1643,7 @@ protected EnvironmentModifyWorkflow getEnvironmentModifyingWorkflow( final Local
15961643
final Topology topology,
15971644
final TrackerOperation operationTracker,
15981645
final List<String> removedContainers,
1599-
final Map<String, ContainerQuota>
1600-
changedContainers )
1646+
final Map<String, ContainerQuota> changedContainers )
16011647

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

16071653

16081654
protected EnvironmentDestructionWorkflow getEnvironmentDestructionWorkflow( final LocalEnvironment environment,
1609-
final TrackerOperation
1610-
operationTracker )
1655+
final TrackerOperation operationTracker )
16111656
{
16121657
return new EnvironmentDestructionWorkflow( this, environment, operationTracker );
16131658
}

0 commit comments

Comments
 (0)