Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
dilshat committed Nov 21, 2017
2 parents 6205df1 + baa15b8 commit 05a4b3d
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class ProxyEnvironmentContainer extends EnvironmentContainerImpl

ProxyEnvironmentContainer( JsonNode json, EnvironmentManagerImpl environmentManager, Set<String> localContainerIds )
{

//TODO pass env id and vlan from Hub
super( Common.HUB_ID, json.get( "peerId" ).asText(),
new ContainerHostInfoModel( json.get( "id" ).asText(), json.get( "hostName" ).asText(),
json.get( "name" ).asText(), initHostInterfaces( json ), HostArchitecture.AMD64,
ContainerHostState.RUNNING ), json.get( "templateId" ).asText(),
ContainerHostState.RUNNING, null, null ), json.get( "templateId" ).asText(),
json.get( "domainName" ).asText(), new ContainerQuota( parseSize( json ) ),
json.get( "hostId" ).asText() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public class EnvironmentContainerImpl implements EnvironmentContainerHost
@JsonProperty( "containerName" )
private String containerName;

@Column( name = "vlan" )
@JsonProperty( "vlan" )
private Integer vlan;


@Column( name = "creator_peer_id", nullable = false )
@JsonIgnore
Expand Down Expand Up @@ -186,6 +190,7 @@ public EnvironmentContainerImpl( final String initiatorPeerId, final String peer
this.domainName = domainName;
this.containerSize = containerQuota.getContainerSize();
this.resourceHostId = resourceHostId;
this.vlan = hostInfo.getVlan();
setHostInterfaces( hostInfo.getHostInterfaces() );
}

Expand All @@ -206,6 +211,13 @@ public Quota getRawQuota()
}


@Override
public Integer getVlan()
{
return vlan;
}


@Override
public Integer getDomainPort()
{
Expand Down Expand Up @@ -263,6 +275,13 @@ public EnvironmentId getEnvironmentId()
}


@Override
public String getEnvId()
{
return parent.getId();
}


@Override
public ContainerHostState getState()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected EnvironmentContainerImpl buildContainerEntity( final String peerId, fi
final ContainerHostInfoModel infoModel =
new ContainerHostInfoModel( cloneResponse.getContainerId(), cloneResponse.getHostname(),
cloneResponse.getContainerName(), interfaces, cloneResponse.getTemplateArch(),
ContainerHostState.RUNNING );
ContainerHostState.RUNNING, environment.getId(), cloneResponse.getVlan() );

return new EnvironmentContainerImpl( localPeerId, peerId, infoModel, cloneResponse.getTemplateId(),
defaultDomain, cloneResponse.getContainerQuota(), cloneResponse.getResourceHostId() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class EnvironmentContainerImplTest
private static final String HOSTNAME = "container1";
private static final ContainerHostState STATE = ContainerHostState.RUNNING;
private static final String TAG = "tag";
private static final int PID = 123;
private static final int VLAN = 123;


private EnvironmentContainerImpl environmentContainer;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void setUp() throws Exception

ContainerHostInfoModel containerHostInfoModel =
new ContainerHostInfoModel( CONTAINER_ID, HOSTNAME, HOSTNAME, hostInterfaces, HostArchitecture.AMD64,
STATE );
STATE, ENV_ID, VLAN );

environmentContainer =
spy( new EnvironmentContainerImpl( INITIATOR_ID, PEER_ID, containerHostInfoModel, TEMPLATE_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public class ContainerInfoImpl implements ContainerInfo
@Expose
private Integer vlan;

@Column( name = "envId" )
@Expose
private String envId;

@Column( name = "gateway" )
@Expose
private String gateway = "";
Expand Down Expand Up @@ -115,6 +119,7 @@ public ContainerInfoImpl( ContainerInfo hostInfo )
this.status = hostInfo.getStatus();
this.publicKey = hostInfo.getPublicKey();
this.gateway = hostInfo.getGateway();
this.envId = hostInfo.getEnvId();
if ( arch == null )
{
arch = HostArchitecture.AMD64;
Expand Down Expand Up @@ -234,6 +239,13 @@ public Integer getVlan()
}


@Override
public String getEnvId()
{
return envId;
}


@Override
public String getGateway()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ContainerInfoJson implements ContainerInfo
private String hostname;
private String name;
private Integer vlan;
private String envId;
private String templateName;
private Set<HostInterfaceJson> interfaces = new HashSet<>();
private HostArchitecture arch;
Expand All @@ -44,6 +45,7 @@ public class ContainerInfoJson implements ContainerInfo
this.gateway = hostInfo.getGateway();
this.state = hostInfo.getState();
this.quota = hostInfo.getRawQuota();
this.envId = hostInfo.getEnvId();
if ( arch == null )
{
arch = HostArchitecture.AMD64;
Expand Down Expand Up @@ -135,6 +137,13 @@ public Integer getVlan()
}


@Override
public String getEnvId()
{
return envId;
}


@Override
public String getPublicKey()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.google.common.base.Preconditions;

import io.subutai.common.host.ContainerHostInfo;
import io.subutai.common.host.HostInterface;
import io.subutai.common.host.ResourceHostInfo;
import io.subutai.common.settings.Common;
import io.subutai.core.hostregistry.api.HostRegistry;
Expand Down Expand Up @@ -58,10 +57,10 @@ protected Object doExecute() throws Exception
containerHostInfo.getHostname() :
containerHostInfo.getHostname() + " [ " + containerHostInfo.getContainerName() + " ]";

System.out.println( String.format( "\t\t%s\t%s\t%s\t%s", hostname,
System.out.println( String.format( "\t\t%s\t%s\t%s\t%s\t%s", hostname,
abbreviate ? StringUtils.abbreviate( containerHostInfo.getId(), 7 ) : containerHostInfo.getId(),
containerHostInfo.getHostInterfaces().findByName( Common.DEFAULT_CONTAINER_INTERFACE ).getIp(),
containerHostInfo.getState() ) );
containerHostInfo.getState(), containerHostInfo.getVlan() ) );
}

System.out.println( "-------" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1150,13 +1150,14 @@ public CreateEnvironmentContainersResponse createEnvironmentContainers(
request.getHostname(), request.getTemplateArch(), interfaces,
request.getContainerName(), request.getTemplateId(),
requestGroup.getEnvironmentId(), requestGroup.getOwnerId(),
requestGroup.getInitiatorPeerId(), request.getContainerQuota() );
requestGroup.getInitiatorPeerId(), request.getContainerQuota(),
reservedNetworkResource.getVlan() );

registerContainer( request.getResourceHostId(), containerHostEntity );
}
}

return new CreateEnvironmentContainersResponse( cloneResults );
return new CreateEnvironmentContainersResponse( cloneResults, reservedNetworkResource );
}
finally
{
Expand Down Expand Up @@ -3898,17 +3899,11 @@ private void removeStaleContainers()
{
ContainerHostInfo lostContainer = iterator.next();

//TODO: use container-name and ip as a workaround for now to figure out environment containers,
//TODO: until env-id is present in container metadata from heartbeat
//filter out containers created by system, not by user
try
{
if ( !( lostContainer.getContainerName().matches( ".*-\\d+-\\d+" )

&& lostContainer.getHostInterfaces()

.findByName( Common.DEFAULT_CONTAINER_INTERFACE ).getIp()
.startsWith( "172" ) ) )
//system containers should have both vlan and envId
if ( lostContainer.getVlan() == null || lostContainer.getEnvId() == null )
{
iterator.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class ContainerHostEntity extends AbstractSubutaiHost implements Containe
@Column( name = "env_id", nullable = true )
private String environmentId;

@Column( name = "vlan", nullable = true )
private Integer vlan;

@Column( name = "initiator_peer_id", nullable = true )
private String initiatorPeerId;

Expand Down Expand Up @@ -99,6 +102,20 @@ protected ContainerHostEntity()
}


@Override
public Integer getVlan()
{
return vlan;
}


@Override
public String getEnvId()
{
return environmentId;
}


@Override
public HostId getResourceHostId()
{
Expand All @@ -116,8 +133,8 @@ public String getContainerName()
public ContainerHostEntity( final String peerId, final String hostId, final String hostname,
HostArchitecture architecture, HostInterfaces hostInterfaces,
final String containerName, final String templateId, final String environmentId,
final String ownerId, final String initiatorPeerId,
final ContainerQuota containerQuota )
final String ownerId, final String initiatorPeerId, final ContainerQuota containerQuota,
final Integer vlan )
{
super( peerId, hostId, hostname, architecture );
this.containerName = containerName;
Expand All @@ -126,6 +143,7 @@ public ContainerHostEntity( final String peerId, final String hostId, final Stri
this.initiatorPeerId = initiatorPeerId;
this.ownerId = ownerId;
this.containerSize = containerQuota.getContainerSize();
this.vlan = vlan;
setSavedHostInterfaces( hostInterfaces );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ public void updateHostInfo( final HostInfo hostInfo )
info.getHostInterfaces(), info.getContainerName(),
getLocalPeer().getTemplateByName( Common.MANAGEMENT_HOSTNAME ).getId(),
Common.MANAGEMENT_HOSTNAME, null, null,
new ContainerQuota( ContainerSize.SMALL ) );
new ContainerQuota( ContainerSize.SMALL ), info.getVlan() );

addContainerHost( containerHost );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;

import io.subutai.common.network.NetworkResource;
import io.subutai.common.task.CloneRequest;
import io.subutai.common.task.CloneResponse;
import io.subutai.common.util.HostUtil;
Expand Down Expand Up @@ -34,7 +35,7 @@ public CreateEnvironmentContainersResponse( @JsonProperty( value = "messages" )
}


public CreateEnvironmentContainersResponse( HostUtil.Results results )
public CreateEnvironmentContainersResponse( HostUtil.Results results, NetworkResource networkResource )
{
Preconditions.checkNotNull( results );

Expand All @@ -48,7 +49,8 @@ public CreateEnvironmentContainersResponse( HostUtil.Results results )
{
responses.add( new CloneResponse( task.getHost().getId(), request.getHostname(),
request.getContainerName(), request.getTemplateId(), request.getTemplateArch(), request.getIp(),
cloneContainerTask.getResult(), task.getDuration(), request.getContainerQuota() ) );
cloneContainerTask.getResult(), task.getDuration(), request.getContainerQuota(),
networkResource.getVlan() ) );

this.messages.add( String
.format( "Task (%s) succeeded on host %s [%s]", task.name(), task.getHost().getHostname(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ public interface ContainerHostInfo extends HostInfo
* Returns network interfaces of host
*/
HostInterfaces getHostInterfaces();

String getEnvId();

Integer getVlan();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,51 @@ public class ContainerHostInfoModel extends HostInfoModel implements ContainerHo
@SerializedName( "interfaces" )
@JsonProperty( "interfaces" )
protected Set<HostInterfaceModel> hostInterfaces = new HashSet<>();


@Override
public Quota getRawQuota()
{
return quota;
}
@JsonProperty( "envId" )
protected String envId;
@JsonProperty( "vlan" )
protected Integer vlan;


public ContainerHostInfoModel( @JsonProperty( "id" ) final String id,
@JsonProperty( "hostname" ) final String hostname,
@JsonProperty( "containerName" ) final String containerName,
@JsonProperty( "interfaces" ) final HostInterfaces hostInterfaces,
@JsonProperty( "arch" ) final HostArchitecture hostArchitecture,
@JsonProperty( "status" ) final ContainerHostState state )
@JsonProperty( "status" ) final ContainerHostState state,
@JsonProperty( "envId" ) final String envId,
@JsonProperty( "vlan" ) final Integer vlan )
{
super( id, hostname, hostArchitecture );
this.state = state;
this.name = containerName;
this.envId = envId;
this.vlan = vlan;
setHostInterfaces( hostInterfaces );
}


@Override
public Quota getRawQuota()
{
return quota;
}


@Override
public String getEnvId()
{
return envId;
}


@Override
public Integer getVlan()
{
return vlan;
}


@Override
public HostInterfaces getHostInterfaces()
{
Expand Down Expand Up @@ -91,7 +113,7 @@ public String toString()
{
return MoreObjects.toStringHelper( this ).add( "id", id ).add( "hostname", hostname )
.add( "interfaces", hostInterfaces ).add( "status", state ).add( "arch", hostArchitecture )
.toString();
.add( "environmentId", envId ).add( "vlan", vlan ).toString();
}


Expand Down
Loading

0 comments on commit 05a4b3d

Please sign in to comment.