Skip to content

Commit

Permalink
Merge pull request #2846 from subutai-io/dev
Browse files Browse the repository at this point in the history
Dev -> Master
  • Loading branch information
Dilshat authored Apr 3, 2019
2 parents 0faaba9 + c95e432 commit 71c6cd4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -12,7 +13,6 @@
import io.subutai.common.peer.HostNotFoundException;
import io.subutai.common.peer.LocalPeer;
import io.subutai.common.peer.ResourceHost;
import io.subutai.common.peer.ResourceHostException;
import io.subutai.common.util.ServiceLocator;
import io.subutai.core.hostregistry.api.HostListener;

Expand Down Expand Up @@ -181,19 +181,14 @@ private void processHeartbeat( ResourceHostInfo oldRhInfo, ResourceHostInfo newR
try
{
ResourceHost resourceHost = localPeer.getResourceHostByContainerId( oldContainerInfo.getId() );

try
{
for ( String name : resourceHost.listExistingContainerNames() )
{
if ( oldContainerInfo.getContainerName().equalsIgnoreCase( name ) )
{
containerStillExists = true;
break;
}
}
//sleep 10 sec to let filesystem recover in case of snapshot rollback
TimeUnit.SECONDS.sleep( 10 );

containerStillExists = resourceHost.lxcExists( oldContainerInfo.getContainerName() );
}
catch ( ResourceHostException e )
catch ( Exception e )
{
//just in case skip container removal in this round since we can not check
containerStillExists = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,10 @@ public RequestBuilder getGetTimezonOffsetCommand()
{
return new RequestBuilder( "date +\"%z\"" );
}


public RequestBuilder getCheckLxcExistsCommand( String name )
{
return new RequestBuilder( String.format( "subutai exists %s", name ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public Snapshots listContainerHostSnapshots( final ContainerHost containerHost )
if ( m.find() && m.groupCount() == 2 )
{

SimpleDateFormat parser = new SimpleDateFormat( "EEE MMM d H:mm yyyy X" );
SimpleDateFormat parser = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS X" );

Date date = parser.parse( timestamp + " " + timezoneOffset );

Expand Down Expand Up @@ -1778,6 +1778,22 @@ public Set<String> listExistingContainerNames() throws ResourceHostException
}


@Override
public Boolean lxcExists( final String name ) throws ResourceHostException
{
try
{
CommandResult result = execute( resourceHostCommands.getCheckLxcExistsCommand( name ) );
return result.hasSucceeded();
}
catch ( CommandException e )
{
throw new ResourceHostException(
String.format( "Error checking lxc instance existence: %s", e.getMessage() ), e );
}
}


@Override
public Set<ContainerInfo> listExistingContainersInfo() throws ResourceHostException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,15 @@ public void testListContainerHostSnapshots() throws Exception
{
resourceHostEntity.addContainerHost( containerHost );

doReturn( "NAME CREATION\n"
+ "subutai/fs/Container1-pfe-1-2@my-snapshot Thu Feb 28 10:53 2019\n"
+ "\n"
+ " \n"
+ "subutai/fs/Container1-pfe-1-2/home@my-snapshot Thu Feb 28 10:53 2019\n"
+ "subutai/fs/Container1-pfe-1-2/opt@my-snapshot Thu Feb 28 10:53 2019\n"
+ "subutai/fs/Container1-pfe-1-2/rootfs@my-snapshot Thu Feb 28 10:53 2019\n"
+ "subutai/fs/Container1-pfe-1-2/var@my-snapshot Thu Feb 28 10:53 2019" ).when( commandResult ).getStdOut();

doReturn( "+0000" ).when( resourceHostEntity ).getTimezoneOffset();
doReturn( "NAME :CREATED\n"
+ "subutai/fs/Container1-xkb-1-2@first 2019-04-01T02:51:44.806\n"
+ "subutai/fs/Container1-xkb-1-2/home@first 2019-04-01T02:51:44.806\n"
+ "subutai/fs/Container1-xkb-1-2/opt@first 2019-04-01T02:51:44.806\n"
+ "subutai/fs/Container1-xkb-1-2/rootfs@first 2019-04-01T02:51:44.806\n"
+ "subutai/fs/Container1-xkb-1-2/var@first 2019-04-01T02:51:44.806\n" ).when( commandResult )
.getStdOut();

doReturn( "+0000" ).when( resourceHostEntity ).getTimezoneOffset();

Snapshots snapshots = resourceHostEntity.listContainerHostSnapshots( containerHost );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ void exportTemplate( String containerName, String templateName, String version,

Set<ContainerInfo> listExistingContainersInfo() throws ResourceHostException;

/**
* Checks if lxc instance exists
*
* @param name name of container or template
*/
Boolean lxcExists( String name ) throws ResourceHostException;


ReservedPorts getReservedPorts() throws ResourceHostException;

Expand Down

0 comments on commit 71c6cd4

Please sign in to comment.