Skip to content

Commit

Permalink
Merge pull request #2841 from subutai-io/dev
Browse files Browse the repository at this point in the history
Dev -> Master
  • Loading branch information
Dilshat authored Mar 30, 2019
2 parents 217ccd1 + 65741fb commit 0faaba9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,10 @@ public RequestBuilder getRecreateContainerCommand( final String containerName, f
containerName, ip, vlan, environmentId, containerToken, containerName, hostname ) )
.withTimeout( Common.CLONE_TIMEOUT_SEC );
}


public RequestBuilder getGetTimezonOffsetCommand()
{
return new RequestBuilder( "date +\"%z\"" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ public Snapshots listContainerHostSnapshots( final ContainerHost containerHost )
String.format( CONTAINER_EXCEPTION_MSG_FORMAT, containerHost.getHostname() ), e );
}

String timezoneOffset = getTimezoneOffset();

try
{
CommandResult commandResult = commandUtil
Expand Down Expand Up @@ -485,9 +487,9 @@ public Snapshots listContainerHostSnapshots( final ContainerHost containerHost )
if ( m.find() && m.groupCount() == 2 )
{

SimpleDateFormat parser = new SimpleDateFormat( "EEE MMM d H:mm yyyy zzz" );
SimpleDateFormat parser = new SimpleDateFormat( "EEE MMM d H:mm yyyy X" );

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

String partition = m.group( 1 );
if ( partition.equalsIgnoreCase( containerHost.getContainerName() ) )
Expand Down Expand Up @@ -515,6 +517,21 @@ public Snapshots listContainerHostSnapshots( final ContainerHost containerHost )
}


@Override
public String getTimezoneOffset() throws ResourceHostException
{
try
{
CommandResult result = commandUtil.execute( resourceHostCommands.getGetTimezonOffsetCommand(), this );
return result.getStdOut().trim();
}
catch ( CommandException e )
{
throw new ResourceHostException( String.format( "Error getting timezone offset: %s", e.getMessage() ), e );
}
}


@Override
public void removeContainerSnapshot( final ContainerHost containerHost, String partition, final String label )
throws ResourceHostException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.subutai.core.localpeer.impl;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -657,4 +660,16 @@ public void testIsReady()

assertTrue( localPeer.isReady() );
}


@Test
public void testTime() throws ParseException
{
SimpleDateFormat parser = new SimpleDateFormat( "EEE MMM d H:mm yyyy X" );

//date +"%z"
Date date = parser.parse( "Thu Mar 28 14:51 2019" + " +0000" );

System.out.println(date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ public void testListContainerHostSnapshots() throws Exception
+ "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();

Snapshots snapshots = resourceHostEntity.listContainerHostSnapshots( containerHost );

assertNotNull( snapshots );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,6 @@ boolean isPortMappingReserved( final Protocol protocol, final int externalPort,
boolean update();

boolean ping();

String getTimezoneOffset() throws ResourceHostException;
}

0 comments on commit 0faaba9

Please sign in to comment.