Skip to content

Commit baa15b8

Browse files
authored
Merge pull request #2130 from subutai-io/base-2128
Base 2128
2 parents 161aa9a + 54183cb commit baa15b8

File tree

14 files changed

+123
-33
lines changed

14 files changed

+123
-33
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ class ProxyEnvironmentContainer extends EnvironmentContainerImpl
4545

4646
ProxyEnvironmentContainer( JsonNode json, EnvironmentManagerImpl environmentManager, Set<String> localContainerIds )
4747
{
48-
48+
//TODO pass env id and vlan from Hub
4949
super( Common.HUB_ID, json.get( "peerId" ).asText(),
5050
new ContainerHostInfoModel( json.get( "id" ).asText(), json.get( "hostName" ).asText(),
5151
json.get( "name" ).asText(), initHostInterfaces( json ), HostArchitecture.AMD64,
52-
ContainerHostState.RUNNING ), json.get( "templateId" ).asText(),
52+
ContainerHostState.RUNNING, null, null ), json.get( "templateId" ).asText(),
5353
json.get( "domainName" ).asText(), new ContainerQuota( parseSize( json ) ),
5454
json.get( "hostId" ).asText() );
5555

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public class EnvironmentContainerImpl implements EnvironmentContainerHost
9595
@JsonProperty( "containerName" )
9696
private String containerName;
9797

98+
@Column( name = "vlan" )
99+
@JsonProperty( "vlan" )
100+
private Integer vlan;
101+
98102

99103
@Column( name = "creator_peer_id", nullable = false )
100104
@JsonIgnore
@@ -186,6 +190,7 @@ public EnvironmentContainerImpl( final String initiatorPeerId, final String peer
186190
this.domainName = domainName;
187191
this.containerSize = containerQuota.getContainerSize();
188192
this.resourceHostId = resourceHostId;
193+
this.vlan = hostInfo.getVlan();
189194
setHostInterfaces( hostInfo.getHostInterfaces() );
190195
}
191196

@@ -206,6 +211,13 @@ public Quota getRawQuota()
206211
}
207212

208213

214+
@Override
215+
public Integer getVlan()
216+
{
217+
return vlan;
218+
}
219+
220+
209221
@Override
210222
public Integer getDomainPort()
211223
{
@@ -263,6 +275,13 @@ public EnvironmentId getEnvironmentId()
263275
}
264276

265277

278+
@Override
279+
public String getEnvId()
280+
{
281+
return parent.getId();
282+
}
283+
284+
266285
@Override
267286
public ContainerHostState getState()
268287
{

management/server/core/environment-manager/environment-manager-impl/src/main/java/io/subutai/core/environment/impl/workflow/creation/steps/ContainerCloneStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ protected EnvironmentContainerImpl buildContainerEntity( final String peerId, fi
180180
final ContainerHostInfoModel infoModel =
181181
new ContainerHostInfoModel( cloneResponse.getContainerId(), cloneResponse.getHostname(),
182182
cloneResponse.getContainerName(), interfaces, cloneResponse.getTemplateArch(),
183-
ContainerHostState.RUNNING );
183+
ContainerHostState.RUNNING, environment.getId(), cloneResponse.getVlan() );
184184

185185
return new EnvironmentContainerImpl( localPeerId, peerId, infoModel, cloneResponse.getTemplateId(),
186186
defaultDomain, cloneResponse.getContainerQuota(), cloneResponse.getResourceHostId() );

management/server/core/environment-manager/environment-manager-impl/src/test/java/io/subutai/core/environment/impl/entity/EnvironmentContainerImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class EnvironmentContainerImplTest
5454
private static final String HOSTNAME = "container1";
5555
private static final ContainerHostState STATE = ContainerHostState.RUNNING;
5656
private static final String TAG = "tag";
57-
private static final int PID = 123;
57+
private static final int VLAN = 123;
5858

5959

6060
private EnvironmentContainerImpl environmentContainer;
@@ -85,7 +85,7 @@ public void setUp() throws Exception
8585

8686
ContainerHostInfoModel containerHostInfoModel =
8787
new ContainerHostInfoModel( CONTAINER_ID, HOSTNAME, HOSTNAME, hostInterfaces, HostArchitecture.AMD64,
88-
STATE );
88+
STATE, ENV_ID, VLAN );
8989

9090
environmentContainer =
9191
spy( new EnvironmentContainerImpl( INITIATOR_ID, PEER_ID, containerHostInfoModel, TEMPLATE_ID,

management/server/core/host-registration/host-registration-impl/src/main/java/io/subutai/core/registration/impl/entity/ContainerInfoImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public class ContainerInfoImpl implements ContainerInfo
6363
@Expose
6464
private Integer vlan;
6565

66+
@Column( name = "envId" )
67+
@Expose
68+
private String envId;
69+
6670
@Column( name = "gateway" )
6771
@Expose
6872
private String gateway = "";
@@ -115,6 +119,7 @@ public ContainerInfoImpl( ContainerInfo hostInfo )
115119
this.status = hostInfo.getStatus();
116120
this.publicKey = hostInfo.getPublicKey();
117121
this.gateway = hostInfo.getGateway();
122+
this.envId = hostInfo.getEnvId();
118123
if ( arch == null )
119124
{
120125
arch = HostArchitecture.AMD64;
@@ -234,6 +239,13 @@ public Integer getVlan()
234239
}
235240

236241

242+
@Override
243+
public String getEnvId()
244+
{
245+
return envId;
246+
}
247+
248+
237249
@Override
238250
public String getGateway()
239251
{

management/server/core/host-registration/host-registration-rest/src/main/java/io/subutai/core/registration/rest/transitional/ContainerInfoJson.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ContainerInfoJson implements ContainerInfo
2121
private String hostname;
2222
private String name;
2323
private Integer vlan;
24+
private String envId;
2425
private String templateName;
2526
private Set<HostInterfaceJson> interfaces = new HashSet<>();
2627
private HostArchitecture arch;
@@ -44,6 +45,7 @@ public class ContainerInfoJson implements ContainerInfo
4445
this.gateway = hostInfo.getGateway();
4546
this.state = hostInfo.getState();
4647
this.quota = hostInfo.getRawQuota();
48+
this.envId = hostInfo.getEnvId();
4749
if ( arch == null )
4850
{
4951
arch = HostArchitecture.AMD64;
@@ -135,6 +137,13 @@ public Integer getVlan()
135137
}
136138

137139

140+
@Override
141+
public String getEnvId()
142+
{
143+
return envId;
144+
}
145+
146+
138147
@Override
139148
public String getPublicKey()
140149
{

management/server/core/host-registry/host-registry-cli/src/main/java/io/subutai/core/hostregistry/cli/ListHostsCommand.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.google.common.base.Preconditions;
1111

1212
import io.subutai.common.host.ContainerHostInfo;
13-
import io.subutai.common.host.HostInterface;
1413
import io.subutai.common.host.ResourceHostInfo;
1514
import io.subutai.common.settings.Common;
1615
import io.subutai.core.hostregistry.api.HostRegistry;
@@ -58,10 +57,10 @@ protected Object doExecute() throws Exception
5857
containerHostInfo.getHostname() :
5958
containerHostInfo.getHostname() + " [ " + containerHostInfo.getContainerName() + " ]";
6059

61-
System.out.println( String.format( "\t\t%s\t%s\t%s\t%s", hostname,
60+
System.out.println( String.format( "\t\t%s\t%s\t%s\t%s\t%s", hostname,
6261
abbreviate ? StringUtils.abbreviate( containerHostInfo.getId(), 7 ) : containerHostInfo.getId(),
6362
containerHostInfo.getHostInterfaces().findByName( Common.DEFAULT_CONTAINER_INTERFACE ).getIp(),
64-
containerHostInfo.getState() ) );
63+
containerHostInfo.getState(), containerHostInfo.getVlan() ) );
6564
}
6665

6766
System.out.println( "-------" );

management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/LocalPeerImpl.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,13 +1150,14 @@ public CreateEnvironmentContainersResponse createEnvironmentContainers(
11501150
request.getHostname(), request.getTemplateArch(), interfaces,
11511151
request.getContainerName(), request.getTemplateId(),
11521152
requestGroup.getEnvironmentId(), requestGroup.getOwnerId(),
1153-
requestGroup.getInitiatorPeerId(), request.getContainerQuota() );
1153+
requestGroup.getInitiatorPeerId(), request.getContainerQuota(),
1154+
reservedNetworkResource.getVlan() );
11541155

11551156
registerContainer( request.getResourceHostId(), containerHostEntity );
11561157
}
11571158
}
11581159

1159-
return new CreateEnvironmentContainersResponse( cloneResults );
1160+
return new CreateEnvironmentContainersResponse( cloneResults, reservedNetworkResource );
11601161
}
11611162
finally
11621163
{
@@ -3898,17 +3899,11 @@ private void removeStaleContainers()
38983899
{
38993900
ContainerHostInfo lostContainer = iterator.next();
39003901

3901-
//TODO: use container-name and ip as a workaround for now to figure out environment containers,
3902-
//TODO: until env-id is present in container metadata from heartbeat
39033902
//filter out containers created by system, not by user
39043903
try
39053904
{
3906-
if ( !( lostContainer.getContainerName().matches( ".*-\\d+-\\d+" )
3907-
3908-
&& lostContainer.getHostInterfaces()
3909-
3910-
.findByName( Common.DEFAULT_CONTAINER_INTERFACE ).getIp()
3911-
.startsWith( "172" ) ) )
3905+
//system containers should have both vlan and envId
3906+
if ( lostContainer.getVlan() == null || lostContainer.getEnvId() == null )
39123907
{
39133908
iterator.remove();
39143909
}

management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/entity/ContainerHostEntity.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public class ContainerHostEntity extends AbstractSubutaiHost implements Containe
7272
@Column( name = "env_id", nullable = true )
7373
private String environmentId;
7474

75+
@Column( name = "vlan", nullable = true )
76+
private Integer vlan;
77+
7578
@Column( name = "initiator_peer_id", nullable = true )
7679
private String initiatorPeerId;
7780

@@ -99,6 +102,20 @@ protected ContainerHostEntity()
99102
}
100103

101104

105+
@Override
106+
public Integer getVlan()
107+
{
108+
return vlan;
109+
}
110+
111+
112+
@Override
113+
public String getEnvId()
114+
{
115+
return environmentId;
116+
}
117+
118+
102119
@Override
103120
public HostId getResourceHostId()
104121
{
@@ -116,8 +133,8 @@ public String getContainerName()
116133
public ContainerHostEntity( final String peerId, final String hostId, final String hostname,
117134
HostArchitecture architecture, HostInterfaces hostInterfaces,
118135
final String containerName, final String templateId, final String environmentId,
119-
final String ownerId, final String initiatorPeerId,
120-
final ContainerQuota containerQuota )
136+
final String ownerId, final String initiatorPeerId, final ContainerQuota containerQuota,
137+
final Integer vlan )
121138
{
122139
super( peerId, hostId, hostname, architecture );
123140
this.containerName = containerName;
@@ -126,6 +143,7 @@ public ContainerHostEntity( final String peerId, final String hostId, final Stri
126143
this.initiatorPeerId = initiatorPeerId;
127144
this.ownerId = ownerId;
128145
this.containerSize = containerQuota.getContainerSize();
146+
this.vlan = vlan;
129147
setSavedHostInterfaces( hostInterfaces );
130148
}
131149

management/server/core/local-peer/local-peer-impl/src/main/java/io/subutai/core/localpeer/impl/entity/ResourceHostEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ public void updateHostInfo( final HostInfo hostInfo )
10051005
info.getHostInterfaces(), info.getContainerName(),
10061006
getLocalPeer().getTemplateByName( Common.MANAGEMENT_HOSTNAME ).getId(),
10071007
Common.MANAGEMENT_HOSTNAME, null, null,
1008-
new ContainerQuota( ContainerSize.SMALL ) );
1008+
new ContainerQuota( ContainerSize.SMALL ), info.getVlan() );
10091009

10101010
addContainerHost( containerHost );
10111011
}

0 commit comments

Comments
 (0)