Skip to content

Commit

Permalink
Add year check to Presto server startup
Browse files Browse the repository at this point in the history
* Rename PrestoJvmRequirements to PrestoServerRequirements
* Verify that the year is current, to avoid issues with third party
  libraries

Testing: mvn clean install; manually verified on server with incorrect year
  • Loading branch information
cawallin authored and cberner committed Jul 14, 2015
1 parent cb2dece commit 77f198a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Expand Up @@ -46,7 +46,8 @@
import java.util.Map;
import java.util.Set;

import static com.facebook.presto.server.PrestoJvmRequirements.verifyJvmRequirements;
import static com.facebook.presto.server.PrestoSystemRequirements.verifyJvmRequirements;
import static com.facebook.presto.server.PrestoSystemRequirements.verifySystemTimeIsReasonable;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.nullToEmpty;
import static io.airlift.discovery.client.ServiceAnnouncement.ServiceAnnouncementBuilder;
Expand Down Expand Up @@ -76,6 +77,7 @@ public PrestoServer(SqlParserOptions sqlParserOptions)
public void run()
{
verifyJvmRequirements();
verifySystemTimeIsReasonable();

Logger log = Logger.get(PrestoServer.class);

Expand Down
Expand Up @@ -16,12 +16,13 @@
import com.google.common.base.StandardSystemProperty;
import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import org.joda.time.DateTime;

import java.nio.ByteOrder;

final class PrestoJvmRequirements
final class PrestoSystemRequirements
{
private PrestoJvmRequirements() {}
private PrestoSystemRequirements() {}

public static void verifyJvmRequirements()
{
Expand Down Expand Up @@ -75,6 +76,18 @@ private static void verifySlice()
}
}

/**
* Perform a sanity check to make sure that the year is reasonably current, to guard against
* issues in third party libraries.
*/
public static void verifySystemTimeIsReasonable()
{
int currentYear = DateTime.now().year().get();
if (currentYear < 2015) {
failRequirement("Presto requires the system time to be current (found year %s)", currentYear);
}
}

private static void failRequirement(String format, Object... args)
{
System.err.println(String.format(format, args));
Expand Down
Expand Up @@ -15,14 +15,22 @@

import org.testng.annotations.Test;

import static com.facebook.presto.server.PrestoJvmRequirements.verifyJvmRequirements;
import static com.facebook.presto.server.PrestoSystemRequirements.verifyJvmRequirements;
import static com.facebook.presto.server.PrestoSystemRequirements.verifySystemTimeIsReasonable;

public class TestPrestoJvmRequirements
public class TestPrestoSystemRequirements
{
@Test
public void testVerifyJvmRequirements()
throws Exception
{
verifyJvmRequirements();
}

@Test
public void testSystemTimeSanityCheck()
throws Exception
{
verifySystemTimeIsReasonable();
}
}

0 comments on commit 77f198a

Please sign in to comment.