[ASTERIXDB-2207][CLUS] Introduce Coordination Service API

- user model changes: no
- storage format changes: no
- interface changes: yes
  - Add ICoordinationService to CC and NC
    application context.

Details:
- Add API to support coordination service.
- An initial no-op implementation of coordination
  service.

Change-Id: I8670e3498a141029d21826a2908033510c749838
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2244
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
index a0142d5..425cbe4 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
@@ -31,6 +31,7 @@
 
 import org.apache.asterix.active.ActiveManager;
 import org.apache.asterix.api.common.AppRuntimeContextProviderForRecovery;
+import org.apache.asterix.common.api.ICoordinationService;
 import org.apache.asterix.common.api.IDatasetLifecycleManager;
 import org.apache.asterix.common.api.IDatasetMemoryManager;
 import org.apache.asterix.common.api.INcApplicationContext;
@@ -76,6 +77,7 @@
 import org.apache.asterix.replication.recovery.RemoteRecoveryManager;
 import org.apache.asterix.replication.storage.ReplicaResourcesManager;
 import org.apache.asterix.runtime.transaction.GlobalResourceIdFactoryProvider;
+import org.apache.asterix.runtime.utils.NoOpCoordinationService;
 import org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository;
 import org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepositoryFactory;
 import org.apache.hyracks.api.application.INCServiceContext;
@@ -538,4 +540,9 @@
     public IIndexCheckpointManagerProvider getIndexCheckpointManagerProvider() {
         return indexCheckpointManagerProvider;
     }
+
+    @Override
+    public ICoordinationService getCoordinationService() {
+        return NoOpCoordinationService.INSTANCE;
+    }
 }
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/IApplicationContext.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/IApplicationContext.java
index 4e30d54..6b5b472 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/IApplicationContext.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/IApplicationContext.java
@@ -71,4 +71,9 @@
      *             if connection couldn't be established to cluster controller
      */
     IHyracksClientConnection getHcc() throws HyracksDataException;
+
+    /**
+     * @return the cluster coordination service.
+     */
+    ICoordinationService getCoordinationService();
 }
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/ICoordinationService.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/ICoordinationService.java
new file mode 100644
index 0000000..6f929b1
--- /dev/null
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/api/ICoordinationService.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.asterix.common.api;
+
+import java.util.Optional;
+
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public interface ICoordinationService {
+
+    /**
+     * Adds or updates the property with the name {@code key}
+     * with {@code value}
+     *
+     * @param key
+     * @param value
+     * @throws HyracksDataException
+     */
+    void put(String key, byte[] value) throws HyracksDataException;
+
+    /**
+     * Gets the value of the property with name {@code key} if exists.
+     *
+     * @param key
+     * @return optional with the value or {@link Optional#empty()}
+     * @throws HyracksDataException
+     */
+    Optional<byte[]> get(String key) throws HyracksDataException;
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java
index c3ef5b3..f991cd4 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.util.function.Supplier;
 
+import org.apache.asterix.common.api.ICoordinationService;
 import org.apache.asterix.common.api.IMetadataLockManager;
 import org.apache.asterix.common.api.INodeJobTracker;
 import org.apache.asterix.common.cluster.IClusterStateManager;
@@ -106,7 +107,6 @@
         extensionProperties = new ExtensionProperties(propertiesAccessor);
         replicationProperties = new ReplicationProperties(propertiesAccessor);
         this.ftStrategy = ftStrategy;
-        this.hcc = hcc;
         this.buildProperties = new BuildProperties(propertiesAccessor);
         this.messagingProperties = new MessagingProperties(propertiesAccessor);
         this.nodeProperties = new NodeProperties(propertiesAccessor);
@@ -260,4 +260,9 @@
     public INodeJobTracker getNodeJobTracker() {
         return nodeJobTracker;
     }
+
+    @Override
+    public ICoordinationService getCoordinationService() {
+        return NoOpCoordinationService.INSTANCE;
+    }
 }
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/NoOpCoordinationService.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/NoOpCoordinationService.java
new file mode 100644
index 0000000..ed29f4b
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/NoOpCoordinationService.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.asterix.runtime.utils;
+
+import java.util.Optional;
+
+import org.apache.asterix.common.api.ICoordinationService;
+
+public class NoOpCoordinationService implements ICoordinationService {
+
+    public static final NoOpCoordinationService INSTANCE = new NoOpCoordinationService();
+
+    private NoOpCoordinationService() {
+    }
+
+    @Override
+    public void put(String key, byte[] value) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Optional<byte[]> get(String key) {
+        throw new UnsupportedOperationException();
+    }
+}