diff --git a/management/server/core/environment-manager/environment-manager-api/src/main/java/io/subutai/core/environment/api/EnvironmentManager.java b/management/server/core/environment-manager/environment-manager-api/src/main/java/io/subutai/core/environment/api/EnvironmentManager.java index 115e829e1e8..87eb41e4bb9 100644 --- a/management/server/core/environment-manager/environment-manager-api/src/main/java/io/subutai/core/environment/api/EnvironmentManager.java +++ b/management/server/core/environment-manager/environment-manager-api/src/main/java/io/subutai/core/environment/api/EnvironmentManager.java @@ -2,7 +2,6 @@ import java.util.Collection; -import java.util.List; import java.util.Map; import java.util.Set; @@ -75,7 +74,7 @@ Set growEnvironment( final String environmentId, final * new quota * @param async true - env will be created in background, false - caller will block */ - EnvironmentCreationRef modifyEnvironment( String environmentId, Topology topology, List removedContainers, + EnvironmentCreationRef modifyEnvironment( String environmentId, Topology topology, Set removedContainers, Map changedContainers, boolean async ) throws EnvironmentModificationException, EnvironmentNotFoundException; diff --git a/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/EnvironmentManagerImpl.java b/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/EnvironmentManagerImpl.java index aa69b7f1dcf..522e4449d9b 100644 --- a/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/EnvironmentManagerImpl.java +++ b/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/EnvironmentManagerImpl.java @@ -577,7 +577,7 @@ public Set growEnvironment( final String environmentId @Override public EnvironmentCreationRef modifyEnvironment( final String environmentId, final Topology topology, - final List removedContainers, + final Set removedContainers, final Map changedContainers, final boolean async ) throws EnvironmentModificationException, EnvironmentNotFoundException @@ -633,7 +633,7 @@ public EnvironmentCreationRef modifyEnvironment( final String environmentId, fin { try { - if ( !peer.canAccommodate( new Nodes( newNodes, changedQuotas ) ) ) + if ( !peer.canAccommodate( new Nodes( newNodes, removedContainers, changedQuotas ) ) ) { operationTracker.addLogFailed( String.format( "Peer %s can not accommodate the requested containers", @@ -716,33 +716,64 @@ public void run() } + private Map getPeerRemovedQuotas( final String peerId, final List removedNodes, + final LocalEnvironment environment ) + throws EnvironmentModificationException + { + + if ( CollectionUtil.isCollectionEmpty( removedNodes ) ) + { + return Maps.newHashMap(); + } + + try + { + Map peerRemovedNodes = Maps.newHashMap(); + + for ( String containerId : removedNodes ) + { + final ContainerHost containerHost = environment.getContainerHostById( containerId ); + + if ( Objects.equals( containerHost.getPeerId(), peerId ) ) + { + peerRemovedNodes.put( containerHost.getResourceHostId().getId(), containerHost.getQuota() ); + } + } + + return peerRemovedNodes; + } + catch ( Exception e ) + { + throw new EnvironmentModificationException( e ); + } + } + + private Map getPeerChangedContainers( final String peerId, final Map allChangedContainers, final LocalEnvironment environment ) throws EnvironmentModificationException { + if ( allChangedContainers == null ) + { + return Maps.newHashMap(); + } + try { - if ( allChangedContainers == null ) - { - return Maps.newHashMap(); - } - else - { - Map peerChangedContainers = Maps.newHashMap(); + Map peerChangedContainers = Maps.newHashMap(); - for ( Map.Entry entry : allChangedContainers.entrySet() ) + for ( Map.Entry entry : allChangedContainers.entrySet() ) + { + String containerId = entry.getKey(); + EnvironmentContainerHost containerHost = environment.getContainerHostById( containerId ); + if ( Objects.equals( containerHost.getPeerId(), peerId ) ) { - String containerId = entry.getKey(); - EnvironmentContainerHost containerHost = environment.getContainerHostById( containerId ); - if ( Objects.equals( containerHost.getPeerId(), peerId ) ) - { - peerChangedContainers.put( containerId, entry.getValue() ); - } + peerChangedContainers.put( containerId, entry.getValue() ); } - - return peerChangedContainers; } + + return peerChangedContainers; } catch ( Exception e ) { @@ -1642,7 +1673,7 @@ protected EnvironmentCreationWorkflow getEnvironmentCreationWorkflow( final Loca protected EnvironmentModifyWorkflow getEnvironmentModifyingWorkflow( final LocalEnvironment environment, final Topology topology, final TrackerOperation operationTracker, - final List removedContainers, + final Set removedContainers, final Map changedContainers ) { diff --git a/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/EnvironmentManagerSecureProxy.java b/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/EnvironmentManagerSecureProxy.java index 36985087891..838565d2b6f 100644 --- a/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/EnvironmentManagerSecureProxy.java +++ b/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/EnvironmentManagerSecureProxy.java @@ -259,7 +259,7 @@ public EnvironmentCreationRef createEnvironment( final Topology topology, final @Override @RolesAllowed( "Environment-Management|Write" ) public EnvironmentCreationRef modifyEnvironment( final String environmentId, final Topology topology, - final List removedContainers, + final Set removedContainers, final Map changedContainers, final boolean async ) throws EnvironmentModificationException, EnvironmentNotFoundException diff --git a/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/workflow/modification/EnvironmentModifyWorkflow.java b/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/workflow/modification/EnvironmentModifyWorkflow.java index caff0dfcec4..9044e9e1ab5 100644 --- a/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/workflow/modification/EnvironmentModifyWorkflow.java +++ b/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/workflow/modification/EnvironmentModifyWorkflow.java @@ -2,8 +2,8 @@ import java.util.HashMap; -import java.util.List; import java.util.Map; +import java.util.Set; import io.subutai.common.environment.EnvironmentStatus; import io.subutai.common.environment.Topology; @@ -34,7 +34,7 @@ public class EnvironmentModifyWorkflow extends CancellableWorkflow removedContainers; + private Set removedContainers; private Map changedContainers; private final String defaultDomain; private final TrackerOperation operationTracker; @@ -59,7 +59,7 @@ public enum EnvironmentGrowingPhase public EnvironmentModifyWorkflow( String defaultDomain, IdentityManager identityManager, PeerManager peerManager, SecurityManager securityManager, LocalEnvironment environment, Topology topology, - List removedContainers, Map changedContainers, + Set removedContainers, Map changedContainers, TrackerOperation operationTracker, EnvironmentManagerImpl environmentManager ) { diff --git a/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/workflow/modification/steps/DestroyContainersStep.java b/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/workflow/modification/steps/DestroyContainersStep.java index 2e586033ce0..7ac7aa95dee 100644 --- a/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/workflow/modification/steps/DestroyContainersStep.java +++ b/management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/workflow/modification/steps/DestroyContainersStep.java @@ -1,7 +1,7 @@ package io.subutai.core.environment.impl.workflow.modification.steps; -import java.util.List; +import java.util.Set; import io.subutai.common.environment.ContainerHostNotFoundException; import io.subutai.common.environment.Environment; @@ -22,13 +22,13 @@ public class DestroyContainersStep { private final LocalEnvironment environment; private final EnvironmentManagerImpl environmentManager; - private final List removedContainers; + private final Set removedContainers; private final TrackerOperation trackerOperation; protected TaskUtil destroyUtil = new TaskUtil<>(); public DestroyContainersStep( final LocalEnvironment environment, final EnvironmentManagerImpl environmentManager, - final List removedContainers, TrackerOperation trackerOperation ) + final Set removedContainers, TrackerOperation trackerOperation ) { this.environment = environment; this.environmentManager = environmentManager; diff --git a/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/EnvironmentManagerImplTest.java b/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/EnvironmentManagerImplTest.java index ab334092e44..06743fc3c33 100644 --- a/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/EnvironmentManagerImplTest.java +++ b/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/EnvironmentManagerImplTest.java @@ -1,7 +1,6 @@ package io.subutai.core.environment.impl; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -98,9 +97,9 @@ import static junit.framework.TestCase.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyList; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyMap; +import static org.mockito.Matchers.anySet; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isA; @@ -449,20 +448,20 @@ public void testGrowEnvironment() throws Exception { doReturn( environmentCreationRef ).when( environmentManager ) - .modifyEnvironment( eq( TestHelper.ENV_ID ), eq( topology ), anyList(), + .modifyEnvironment( eq( TestHelper.ENV_ID ), eq( topology ), anySet(), anyMap(), anyBoolean() ); environmentManager.growEnvironment( TestHelper.ENV_ID, topology, false ); verify( environmentManager ) - .modifyEnvironment( eq( TestHelper.ENV_ID ), eq( topology ), anyList(), anyMap(), anyBoolean() ); + .modifyEnvironment( eq( TestHelper.ENV_ID ), eq( topology ), anySet(), anyMap(), anyBoolean() ); } @Test public void testModifyEnvironment() throws Exception { - List removedContainers = Lists.newArrayList( TestHelper.CONTAINER_ID ); + Set removedContainers = Sets.newHashSet( TestHelper.CONTAINER_ID ); Map changedContainers = Maps.newHashMap(); changedContainers.put( TestHelper.CONTAINER_ID, new ContainerQuota( ContainerSize.LARGE ) ); EnvironmentModifyWorkflow environmentModifyWorkflow = mock( EnvironmentModifyWorkflow.class ); diff --git a/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/EnvironmentManagerSecureProxyTest.java b/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/EnvironmentManagerSecureProxyTest.java index 45e790b3cd4..333fe2370d9 100644 --- a/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/EnvironmentManagerSecureProxyTest.java +++ b/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/EnvironmentManagerSecureProxyTest.java @@ -12,7 +12,6 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -245,11 +244,11 @@ public void testModifyEnvironment() throws Exception Map changedContainers = Maps.newHashMap(); changedContainers.put( TestHelper.CONTAINER_ID, new ContainerQuota( ContainerSize.LARGE ) ); - proxy.modifyEnvironment( TestHelper.ENV_ID, topology, Lists.newArrayList( TestHelper.CONTAINER_ID ), + proxy.modifyEnvironment( TestHelper.ENV_ID, topology, Sets.newHashSet( TestHelper.CONTAINER_ID ), changedContainers, true ); verify( environmentManager ) - .modifyEnvironment( TestHelper.ENV_ID, topology, Lists.newArrayList( TestHelper.CONTAINER_ID ), + .modifyEnvironment( TestHelper.ENV_ID, topology, Sets.newHashSet( TestHelper.CONTAINER_ID ), changedContainers, true ); } diff --git a/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/workflow/modification/EnvironmentModifyWorkflowTest.java b/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/workflow/modification/EnvironmentModifyWorkflowTest.java index b442683eb3f..7fb82c73713 100644 --- a/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/workflow/modification/EnvironmentModifyWorkflowTest.java +++ b/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/workflow/modification/EnvironmentModifyWorkflowTest.java @@ -1,8 +1,8 @@ package io.subutai.core.environment.impl.workflow.modification; -import java.util.List; import java.util.Map; +import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -10,8 +10,8 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import io.subutai.common.environment.Topology; import io.subutai.common.peer.Peer; @@ -46,7 +46,7 @@ class EnvironmentModifyWorkflowSUT extends EnvironmentModifyWorkflow public EnvironmentModifyWorkflowSUT( final String defaultDomain, final IdentityManager identityManager, final PeerManager peerManager, final SecurityManager securityManager, final LocalEnvironment environment, final Topology topology, - final List removedContainers, + final Set removedContainers, final Map changedContainers, final TrackerOperation operationTracker, final EnvironmentManagerImpl environmentManager ) @@ -94,8 +94,8 @@ public void setUp() throws Exception changedContainers.put( TestHelper.CONTAINER_ID, new ContainerQuota( ContainerSize.LARGE ) ); workflow = new EnvironmentModifyWorkflowSUT( Common.DEFAULT_DOMAIN_NAME, identityManager, peerManager, - securityManager, environment, topology, Lists.newArrayList( TestHelper.CONTAINER_ID ), - changedContainers, trackerOperation, environmentManager ); + securityManager, environment, topology, Sets.newHashSet( TestHelper.CONTAINER_ID ), changedContainers, + trackerOperation, environmentManager ); doReturn( environment ).when( environmentManager ).update( environment ); doReturn( environmentContainer ).when( environment ).getContainerHostById( TestHelper.CONTAINER_ID ); diff --git a/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/workflow/modification/steps/DestroyContainersStepTest.java b/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/workflow/modification/steps/DestroyContainersStepTest.java index b8b03a9b624..b91789fc0e6 100644 --- a/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/workflow/modification/steps/DestroyContainersStepTest.java +++ b/management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/workflow/modification/steps/DestroyContainersStepTest.java @@ -7,7 +7,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import io.subutai.common.security.relation.RelationManager; import io.subutai.common.tracker.TrackerOperation; @@ -49,8 +49,8 @@ public class DestroyContainersStepTest @Before public void setUp() throws Exception { - step = new DestroyContainersStep( environment, environmentManager, - Lists.newArrayList( TestHelper.CONTAINER_ID ), trackerOperation ); + step = new DestroyContainersStep( environment, environmentManager, Sets.newHashSet( TestHelper.CONTAINER_ID ), + trackerOperation ); step.destroyUtil = taskUtil; TestHelper.bind( taskUtil, taskResults, taskResult ); doReturn( task ).when( taskResult ).getTask(); diff --git a/management/server/core/environment-manager/environment-manager-rest-ui/src/main/java/io/subutai/core/environment/rest/ui/RestServiceImpl.java b/management/server/core/environment-manager/environment-manager-rest-ui/src/main/java/io/subutai/core/environment/rest/ui/RestServiceImpl.java index 52fc5cb319a..2c59f286d3d 100644 --- a/management/server/core/environment-manager/environment-manager-rest-ui/src/main/java/io/subutai/core/environment/rest/ui/RestServiceImpl.java +++ b/management/server/core/environment-manager/environment-manager-rest-ui/src/main/java/io/subutai/core/environment/rest/ui/RestServiceImpl.java @@ -357,7 +357,7 @@ public Response modify( final String environmentId, final String topologyJson, f } - List removedContainersList = JsonUtil.fromJson( removedContainers, new TypeToken>() + Set removedContainersList = JsonUtil.fromJson( removedContainers, new TypeToken>() { }.getType() ); @@ -418,7 +418,7 @@ public Response modifyAdvanced( final String environmentId, final String topolog topology.addAllNodePlacement( nodes ); - List containersToRemove = JsonUtil.fromJson( removedContainers, new TypeToken>() + Set containersToRemove = JsonUtil.fromJson( removedContainers, new TypeToken>() { }.getType() ); diff --git a/management/server/core/hub-manager/hub-manager-impl/src/main/java/io/subutai/core/hubmanager/impl/environment/state/change/ContainerStateHandler.java b/management/server/core/hub-manager/hub-manager-impl/src/main/java/io/subutai/core/hubmanager/impl/environment/state/change/ContainerStateHandler.java index c668a533068..23c98fcf7c8 100644 --- a/management/server/core/hub-manager/hub-manager-impl/src/main/java/io/subutai/core/hubmanager/impl/environment/state/change/ContainerStateHandler.java +++ b/management/server/core/hub-manager/hub-manager-impl/src/main/java/io/subutai/core/hubmanager/impl/environment/state/change/ContainerStateHandler.java @@ -1,7 +1,7 @@ package io.subutai.core.hubmanager.impl.environment.state.change; -import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import io.subutai.common.environment.Environment; import io.subutai.common.peer.ContainerId; @@ -76,7 +76,7 @@ else if ( nodeDto.getState().equals( ContainerStateDto.ABORTING ) ) if ( envDto.isCreatedOnSS() ) { ctx.envManager.modifyEnvironment( nodeDto.getEnvironmentId(), null, - Lists.newArrayList( nodeDto.getContainerId() ), null, false ); + Sets.newHashSet( nodeDto.getContainerId() ), null, false ); } else { @@ -117,7 +117,7 @@ else if ( nodeDto.getState().equals( ContainerStateDto.ABORTING ) ) if ( envDto.isCreatedOnSS() ) { ctx.envManager.modifyEnvironment( nodeDto.getEnvironmentId(), null, - Lists.newArrayList( nodeDto.getContainerId() ), null, false ); + Sets.newHashSet( nodeDto.getContainerId() ), null, false ); } nodeDto.setState( ContainerStateDto.FROZEN ); diff --git a/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/LocalPeerImpl.java b/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/LocalPeerImpl.java index 1bab702a93f..767dc9ea1f0 100644 --- a/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/LocalPeerImpl.java +++ b/management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/LocalPeerImpl.java @@ -885,37 +885,50 @@ public boolean canAccommodate( final Nodes nodes ) throws PeerException { Preconditions.checkArgument( nodes != null && ( !CollectionUtil.isMapEmpty( nodes.getQuotas() ) || !CollectionUtil - .isCollectionEmpty( nodes.getNodes() ) ), "Invalid nodes" ); + .isCollectionEmpty( nodes.getNewNodes() ) ), "Invalid nodes" ); Map requestedResources = Maps.newHashMap(); for ( ContainerHostInfo containerHostInfo : hostRegistry.getContainerHostsInfo() ) { - //use new quota instead of current if present - ContainerQuota newQuota = null; - if ( nodes.getQuotas() != null ) + double requestedRam = 0, requestedCpu = 0, requestedDisk = 0; + + //exclude container from calculations if it is included into removed containers + if ( nodes.getRemovedContainers() != null && nodes.getRemovedContainers() + .contains( containerHostInfo.getId() ) ) { - newQuota = nodes.getQuotas().get( containerHostInfo.getId() ); + LOG.debug( "Skipping removed container {}", containerHostInfo.getContainerName() ); } + else + { + //use container quotas as amount of used resources in calculations + + //use new quota instead of current if present + ContainerQuota newQuota = null; + if ( nodes.getQuotas() != null ) + { + newQuota = nodes.getQuotas().get( containerHostInfo.getId() ); + } - //use current quota as requested amount unless the container has a change of quota - //note: we use 0 for containers that have unset quota since we don't know what the effective limit is - double requestedRam = newQuota != null ? newQuota.getContainerSize().getRamQuota() : - containerHostInfo.getRawQuota() == null - || containerHostInfo.getRawQuota().getRam() == null ? 0 : - UnitUtil.convert( containerHostInfo.getRawQuota().getRam(), UnitUtil.Unit.MB, - UnitUtil.Unit.B ); - - double requestedCpu = newQuota != null ? newQuota.getContainerSize().getCpuQuota() : - containerHostInfo.getRawQuota() == null - || containerHostInfo.getRawQuota().getCpu() == null ? 0 : - containerHostInfo.getRawQuota().getCpu(); - - double requestedDisk = newQuota != null ? newQuota.getContainerSize().getDiskQuota() : - containerHostInfo.getRawQuota() == null - || containerHostInfo.getRawQuota().getDisk() == null ? 0 : - UnitUtil.convert( containerHostInfo.getRawQuota().getDisk(), UnitUtil.Unit.GB, - UnitUtil.Unit.B ); + //use current quota as requested amount unless the container has a change of quota + //note: we use 0 for containers that have unset quota since we don't know what the effective limit is + requestedRam = newQuota != null ? newQuota.getContainerSize().getRamQuota() : + containerHostInfo.getRawQuota() == null + || containerHostInfo.getRawQuota().getRam() == null ? 0 : + UnitUtil.convert( containerHostInfo.getRawQuota().getRam(), UnitUtil.Unit.MB, + UnitUtil.Unit.B ); + + requestedCpu = newQuota != null ? newQuota.getContainerSize().getCpuQuota() : + containerHostInfo.getRawQuota() == null + || containerHostInfo.getRawQuota().getCpu() == null ? 0 : + containerHostInfo.getRawQuota().getCpu(); + + requestedDisk = newQuota != null ? newQuota.getContainerSize().getDiskQuota() : + containerHostInfo.getRawQuota() == null + || containerHostInfo.getRawQuota().getDisk() == null ? 0 : + UnitUtil.convert( containerHostInfo.getRawQuota().getDisk(), UnitUtil.Unit.GB, + UnitUtil.Unit.B ); + } //figure out current container resource consumption based on historical metrics Calendar cal = Calendar.getInstance(); @@ -988,9 +1001,9 @@ public boolean canAccommodate( final Nodes nodes ) throws PeerException } //new nodes - if ( nodes.getNodes() != null ) + if ( nodes.getNewNodes() != null ) { - for ( Node node : nodes.getNodes() ) + for ( Node node : nodes.getNewNodes() ) { double requestedRam = node.getQuota().getContainerSize().getRamQuota(); double requestedDisk = node.getQuota().getContainerSize().getDiskQuota(); @@ -3024,6 +3037,7 @@ public io.subutai.common.host.Quota getRawQuota( final ContainerId containerId ) } + //TODO review this method @Override public ContainerQuota getQuota( final ContainerId containerId ) throws PeerException { @@ -3062,6 +3076,8 @@ public ContainerQuota getQuota( final ContainerId containerId ) throws PeerExcep containerQuota.add( new Quota( containerResource, quotaOutput.getThreshold() ) ); } + + //todo here adjust disk quota by dividing by 2 } } catch ( Exception e ) diff --git a/management/server/core/local-peer/local-peer-rest/src/main/java/io/subutai/core/localpeer/rest/RestServiceImpl.java b/management/server/core/local-peer/local-peer-rest/src/main/java/io/subutai/core/localpeer/rest/RestServiceImpl.java index ccbcfa7f61d..78a5a9329f0 100644 --- a/management/server/core/local-peer/local-peer-rest/src/main/java/io/subutai/core/localpeer/rest/RestServiceImpl.java +++ b/management/server/core/local-peer/local-peer-rest/src/main/java/io/subutai/core/localpeer/rest/RestServiceImpl.java @@ -245,11 +245,12 @@ public Integer reserveNetResources( final NetworkResourceImpl networkResource ) @Override public Boolean canAccommodate( final Nodes nodes ) { + //TODO try { Preconditions.checkArgument( nodes != null && ( !CollectionUtil.isMapEmpty( nodes.getQuotas() ) || !CollectionUtil - .isCollectionEmpty( nodes.getNodes() ) ), "Invalid nodes" ); + .isCollectionEmpty( nodes.getNewNodes() ) ), "Invalid nodes" ); return localPeer.canAccommodate( nodes ); } diff --git a/management/server/core/peer-manager/peer-manager-impl/src/main/java/io/subutai/core/peer/impl/RemotePeerImpl.java b/management/server/core/peer-manager/peer-manager-impl/src/main/java/io/subutai/core/peer/impl/RemotePeerImpl.java index 3d92443f680..302c4094408 100644 --- a/management/server/core/peer-manager/peer-manager-impl/src/main/java/io/subutai/core/peer/impl/RemotePeerImpl.java +++ b/management/server/core/peer-manager/peer-manager-impl/src/main/java/io/subutai/core/peer/impl/RemotePeerImpl.java @@ -633,9 +633,10 @@ protected MessageRequest sendRequestInternal( final T request, final String @Override public boolean canAccommodate( final Nodes nodes ) throws PeerException { + //TODO Preconditions.checkArgument( nodes != null && ( !CollectionUtil.isMapEmpty( nodes.getQuotas() ) || !CollectionUtil - .isCollectionEmpty( nodes.getNodes() ) ), "Invalid nodes" ); + .isCollectionEmpty( nodes.getNewNodes() ) ), "Invalid nodes" ); return peerWebClient.canAccommodate( nodes ); } diff --git a/management/server/subutai-common/src/main/java/io/subutai/common/environment/Nodes.java b/management/server/subutai-common/src/main/java/io/subutai/common/environment/Nodes.java index 043105235d5..e2dbab826f9 100644 --- a/management/server/subutai-common/src/main/java/io/subutai/common/environment/Nodes.java +++ b/management/server/subutai-common/src/main/java/io/subutai/common/environment/Nodes.java @@ -12,7 +12,9 @@ public class Nodes { @JsonProperty( value = "nodes" ) - private Set nodes; + private Set newNodes; + @JsonProperty( value = "removedContainers" ) + private Set removedContainers; @JsonProperty( value = "quotas" ) private Map quotas; @@ -23,16 +25,18 @@ public Nodes() } - public Nodes( final Set nodes ) + public Nodes( final Set newNodes ) { - this.nodes = nodes; + this.newNodes = newNodes; } - public Nodes( final Set nodes, final Map quotas ) + public Nodes( final Set newNodes, final Set removedContainers, + final Map quotas ) { - this.nodes = nodes; + this.newNodes = newNodes; this.quotas = quotas; + this.removedContainers = removedContainers; } @@ -42,8 +46,14 @@ public Map getQuotas() } - public Set getNodes() + public Set getNewNodes() { - return nodes; + return newNodes; + } + + + public Set getRemovedContainers() + { + return removedContainers; } }