45
45
import io .subutai .common .environment .EnvironmentNotFoundException ;
46
46
import io .subutai .common .environment .EnvironmentPeer ;
47
47
import io .subutai .common .environment .EnvironmentStatus ;
48
+ import io .subutai .common .environment .Node ;
49
+ import io .subutai .common .environment .Nodes ;
48
50
import io .subutai .common .environment .Topology ;
49
51
import io .subutai .common .exception .ActionFailedException ;
50
52
import io .subutai .common .host .ContainerHostInfo ;
@@ -440,6 +442,24 @@ Environment createEnvironment( final Topology topology, final boolean async, Tra
440
442
441
443
throw new EnvironmentCreationException ( String .format ( "Peer %s is offline" , peer .getName () ) );
442
444
}
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
+ }
443
463
}
444
464
445
465
@@ -602,6 +622,35 @@ public EnvironmentCreationRef modifyEnvironment( final String environmentId, fin
602
622
603
623
throw new EnvironmentModificationException ( String .format ( "Peer %s is offline" , peer .getName () ) );
604
624
}
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
+ }
605
654
}
606
655
607
656
if ( environment .getStatus () == EnvironmentStatus .UNDER_MODIFICATION
@@ -668,8 +717,7 @@ public void run()
668
717
669
718
670
719
private Map <String , ContainerQuota > getPeerChangedContainers ( final String peerId ,
671
- final Map <String , ContainerQuota >
672
- allChangedContainers ,
720
+ final Map <String , ContainerQuota > allChangedContainers ,
673
721
final LocalEnvironment environment )
674
722
throws EnvironmentModificationException
675
723
{
@@ -1552,8 +1600,7 @@ PGPSecretKeyRing createEnvironmentKeyPair( EnvironmentId envId ) throws Environm
1552
1600
protected P2PSecretKeyModificationWorkflow getP2PSecretKeyModificationWorkflow ( final LocalEnvironment environment ,
1553
1601
final String p2pSecretKey ,
1554
1602
final long p2pSecretKeyTtlSec ,
1555
- final TrackerOperation
1556
- operationTracker )
1603
+ final TrackerOperation operationTracker )
1557
1604
{
1558
1605
return new P2PSecretKeyModificationWorkflow ( environment , p2pSecretKey , p2pSecretKeyTtlSec , operationTracker ,
1559
1606
this );
@@ -1596,8 +1643,7 @@ protected EnvironmentModifyWorkflow getEnvironmentModifyingWorkflow( final Local
1596
1643
final Topology topology ,
1597
1644
final TrackerOperation operationTracker ,
1598
1645
final List <String > removedContainers ,
1599
- final Map <String , ContainerQuota >
1600
- changedContainers )
1646
+ final Map <String , ContainerQuota > changedContainers )
1601
1647
1602
1648
{
1603
1649
return new EnvironmentModifyWorkflow ( Common .DEFAULT_DOMAIN_NAME , identityManager , peerManager , securityManager ,
@@ -1606,8 +1652,7 @@ protected EnvironmentModifyWorkflow getEnvironmentModifyingWorkflow( final Local
1606
1652
1607
1653
1608
1654
protected EnvironmentDestructionWorkflow getEnvironmentDestructionWorkflow ( final LocalEnvironment environment ,
1609
- final TrackerOperation
1610
- operationTracker )
1655
+ final TrackerOperation operationTracker )
1611
1656
{
1612
1657
return new EnvironmentDestructionWorkflow ( this , environment , operationTracker );
1613
1658
}
0 commit comments