Merge branch 'master' into sanjeevk/encryption
diff --git a/heron/keymgr/src/java/BUILD b/heron/keymgr/src/java/BUILD
new file mode 100644
index 0000000..bdff429
--- /dev/null
+++ b/heron/keymgr/src/java/BUILD
@@ -0,0 +1,51 @@
+licenses(["notice"])
+
+package(default_visibility = ["//visibility:public"])
+
+java_library(
+    name = "metricsmgr-java",
+    srcs = glob(
+        ["**/*.java"],
+        exclude = ["**/MetricManager.java"],
+    ),
+    deps = [
+        "//heron/api/src/java:api-java",
+        "//heron/common/src/java:basics-java",
+        "//heron/common/src/java:config-java",
+        "//heron/common/src/java:network-java",
+        "//heron/common/src/java:utils-java",
+        "//heron/spi/src/java:metricsmgr-spi-java",
+        "//heron/proto:proto_common_java",
+        "//heron/proto:proto_metrics_java",
+        "//heron/proto:proto_tmaster_java",
+        "//heron/metricsmgr/src/thrift:thrift_scribe_java",
+        "//third_party/java:guava", # only used in WebSink
+        "//third_party/java:jackson",
+        "//third_party/java:logging", # slf4j is only used for thrift in scribe-sink
+        "@com_google_protobuf_protobuf_java//jar",
+        "@org_apache_thrift_libthrift//jar",
+        "@org_yaml_snakeyaml//jar",
+    ],
+)
+
+java_binary(
+    name = "metricsmgr-unshaded",
+    srcs = glob(["**/MetricsManager.java"]),
+    deps = [
+        ":metricsmgr-java",
+        "//heron/api/src/java:api-java",
+        "//heron/common/src/java:basics-java",
+        "//heron/common/src/java:config-java",
+        "//heron/common/src/java:network-java",
+        "//heron/common/src/java:utils-java",
+        "//heron/spi/src/java:metricsmgr-spi-java",
+        "//heron/proto:proto_metrics_java",
+    ],
+)
+
+genrule(
+    name = "heron-metricsmgr",
+    srcs = [":metricsmgr-unshaded_deploy.jar"],
+    outs = ["heron-metricsmgr.jar"],
+    cmd  = "cp $< $@",
+)
diff --git a/heron/spi/src/java/BUILD b/heron/spi/src/java/BUILD
index f0577d5..33311ac 100644
--- a/heron/spi/src/java/BUILD
+++ b/heron/spi/src/java/BUILD
@@ -23,6 +23,7 @@
         "**/spi/utils/**/*.java",
         "**/spi/statemgr/**/*.java",
         "**/spi/metricsmgr/**/*.java",
+        "**/spi/keymgr/**/*.java",
     ]),
     javacopts = DOCLINT_HTML_AND_SYNTAX,
     deps = [
@@ -53,6 +54,7 @@
         ":statefulstorage-spi-java",
         ":packing-spi-java",
         ":metricsmgr-spi-java",
+        ":keymgr-spi-java",
         "//heron/common/src/java:basics-java",
         "//heron/common/src/java:config-java",
         "//heron/common/src/java:utils-java",
@@ -91,6 +93,10 @@
     "//heron/common/src/java:config-java",
 ]
 
+keymgr_deps_files = [
+    ":common-spi-java",
+]
+
 statemgr_deps_files = \
     heron_java_proto_files() + [
         ":common-spi-java",
@@ -194,6 +200,14 @@
     deps = statemgr_deps_files,
 )
 
+java_library(
+    name='keymgr-spi-java',
+    srcs = glob(
+        ["**/spi/keymgr/**/*.java"],
+    ),
+    deps = keymgr_deps_files,
+)
+
 java_binary(
     name = "spi-unshaded",
     srcs = glob([
@@ -205,6 +219,7 @@
         "**/spi/statemgr/**/*.java",
         "**/spi/uploader/**/*.java",
         "**/spi/utils/**/*.java",
+        "**/spi/keymgr/**/*.java",
     ]),
     deps = [
         "//heron/api/src/java:classification"
diff --git a/heron/spi/src/java/com/twitter/heron/spi/keymgr/KeyDownloader.java b/heron/spi/src/java/com/twitter/heron/spi/keymgr/KeyDownloader.java
new file mode 100644
index 0000000..eb31e93
--- /dev/null
+++ b/heron/spi/src/java/com/twitter/heron/spi/keymgr/KeyDownloader.java
@@ -0,0 +1,47 @@
+// Copyright 2016 Twitter. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.twitter.heron.spi.keymgr;
+
+import java.nio.file.Path;
+
+import com.twitter.heron.spi.common.Config;
+
+/**
+ * The KeyDownloader interface. <p>
+ * Implementations of this interface download the keys/certificate/truststore to paths
+ * passed in the various download interfaces.
+ */
+public interface KeyDownloader extends AutoCloseable {
+  /**
+   * Initialize the KeyDownloader
+   *
+   * @param config An unmodifiableMap containing basic configuration
+   */
+  void init(Config config);
+
+  /**
+   * download the certificate/keys/trustStore to file pointed
+   *
+   * @param certificateFile The file to download the certificate to
+   * @param keysFile The file to download the keys to
+   * @param trustStoreFile The file to download the trust Store to
+   */
+  void download(Path certificateFile, Path keysFile, Path trustStoreFile);
+
+  /**
+   * Any cleanups should be done here
+   */
+  void close();
+}
diff --git a/heron/spi/src/java/com/twitter/heron/spi/keymgr/KeyUploader.java b/heron/spi/src/java/com/twitter/heron/spi/keymgr/KeyUploader.java
new file mode 100644
index 0000000..8bf6616
--- /dev/null
+++ b/heron/spi/src/java/com/twitter/heron/spi/keymgr/KeyUploader.java
@@ -0,0 +1,47 @@
+// Copyright 2016 Twitter. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.twitter.heron.spi.keymgr;
+
+import java.nio.file.Path;
+
+import com.twitter.heron.spi.common.Config;
+
+/**
+ * The KeyUploader interface. <p>
+ * Implementations of this interface upload the keys/certificate/truststore wherever
+ * they want to store securely.
+ */
+public interface KeyUploader extends AutoCloseable {
+  /**
+   * Initialize the KeyUploader with the static config
+   *
+   * @param config An unmodifiableMap containing basic configuration
+   */
+  void init(Config config);
+
+  /**
+   * download the certificate to file pointed by destinationFile
+   *
+   * @param certificateFile The certificate file that needs to be uploaded
+   * @param keysFile The keys file that needs to be updated
+   * @param trustStoreFile The trustStore file that needs to be updated
+   */
+  void upload(Path certificateFile, Path keysFile, Path trustStoreFile);
+
+  /**
+   * Any cleanups should be done here
+   */
+  void close();
+}