Commit d162d314e76de83666c80fd33a104c740dad4610

Authored by Derek Hulley
1 parent 30bff95fa7
Exists in master

Start schema check

src/main/java/org/alfresco/heartbeat/schema/DynamoDBSchemaCheck.java
... ... @@ -0,0 +1,54 @@
  1 +package org.alfresco.heartbeat.schema;
  2 +
  3 +import java.io.IOException;
  4 +import java.io.InputStream;
  5 +import java.util.Set;
  6 +import java.util.TreeSet;
  7 +
  8 +import com.amazonaws.services.dynamodbv2.document.DynamoDB;
  9 +import com.amazonaws.services.dynamodbv2.document.TableCollection;
  10 +import com.amazonaws.services.dynamodbv2.model.ListTablesResult;
  11 +import com.fasterxml.jackson.databind.JsonNode;
  12 +
  13 +/**
  14 + * Performs a schema difference between the expected and actual tables visible to this code.
  15 + *
  16 + * @author Derek Hulley
  17 + */
  18 +public class DynamoDBSchemaCheck
  19 +{
  20 + private String resourceLocation;
  21 + private TreeSet<String> tables;
  22 +
  23 + /**
  24 + * @param namespace a resource location containing the table definitions e.g. "org/alfresco/heartbeat"
  25 + * @param tables the names of all tables expected
  26 + */
  27 + public DynamoDBSchemaCheck(String resourceLocation, Set<String> tables)
  28 + {
  29 + this.resourceLocation = resourceLocation;
  30 + this.tables = new TreeSet<String>(tables);
  31 + // Check that we have access to the table definitions
  32 + for (String table : this.tables)
  33 + {
  34 + String tableResource = resourceLocation + "/" + table;
  35 + try (InputStream is = ClassLoader.getSystemResourceAsStream(tableResource))
  36 + {
  37 + if (is == null)
  38 + {
  39 + throw new IllegalStateException("Base definiton for table check not found: " + tableResource);
  40 + }
  41 + }
  42 + catch (IOException e)
  43 + {
  44 + throw new IllegalArgumentException("Unable to read table resource: " + tableResource);
  45 + }
  46 + }
  47 + }
  48 +//
  49 +// public JsonNode getSchemaDiff(DynamoDB db)
  50 +// {
  51 +// TableCollection<ListTablesResult> tables = db.listTables();
  52 +//
  53 +// }
  54 +}
... ...