Initial source code
[oam/tr069-adapter.git] / netconf-server / src / main / java / org / commscope / tr069adapter / netconf / operations / CustomOperationsCreator.java
diff --git a/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/operations/CustomOperationsCreator.java b/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/operations/CustomOperationsCreator.java
new file mode 100644 (file)
index 0000000..5323fd3
--- /dev/null
@@ -0,0 +1,102 @@
+/*\r
+ * ============LICENSE_START========================================================================\r
+ * ONAP : tr-069-adapter\r
+ * =================================================================================================\r
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
+ * =================================================================================================\r
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
+ * may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
+ * either express or implied. See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ===============LICENSE_END=======================================================================\r
+ */\r
+\r
+package org.commscope.tr069adapter.netconf.operations;\r
+\r
+import com.google.common.collect.Sets;\r
+\r
+import java.util.Optional;\r
+import java.util.Set;\r
+\r
+import org.commscope.tr069adapter.netconf.rpc.CreateSubscription;\r
+import org.commscope.tr069adapter.netconf.rpc.DeleteConfigOperation;\r
+import org.commscope.tr069adapter.netconf.rpc.GetConfigOperation;\r
+import org.commscope.tr069adapter.netconf.rpc.GetOperation;\r
+import org.commscope.tr069adapter.netconf.rpc.OperationCommit;\r
+import org.commscope.tr069adapter.netconf.rpc.OperationLock;\r
+import org.commscope.tr069adapter.netconf.rpc.OperationUnLock;\r
+import org.commscope.tr069adapter.netconf.rpc.SetConfigOperation;\r
+import org.commscope.tr069adapter.netconf.rpc.SoftwareActivateOperation;\r
+import org.commscope.tr069adapter.netconf.rpc.SoftwareDownloadOperation;\r
+import org.opendaylight.netconf.api.capability.Capability;\r
+import org.opendaylight.netconf.impl.SessionIdProvider;\r
+import org.opendaylight.netconf.mapping.api.NetconfOperation;\r
+import org.opendaylight.netconf.mapping.api.NetconfOperationService;\r
+import org.opendaylight.netconf.test.tool.operations.OperationsCreator;\r
+import org.opendaylight.netconf.test.tool.rpc.DataList;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public final class CustomOperationsCreator implements OperationsCreator {\r
+  private static final Logger logger = LoggerFactory.getLogger(CustomOperationsCreator.class);\r
+\r
+  private String macID = null;\r
+\r
+  private OperationService operationService;\r
+\r
+  public CustomOperationsCreator(String macID) {\r
+    this.macID = macID;\r
+  }\r
+\r
+  @Override\r
+  public NetconfOperationService getNetconfOperationService(final Set<Capability> caps,\r
+      final SessionIdProvider idProvider, final String netconfSessionIdForReporting) {\r
+    if (null == operationService) {\r
+      operationService = new OperationService(idProvider.getCurrentSessionId(), macID);\r
+    }\r
+    return operationService;\r
+  }\r
+\r
+  static class OperationService implements NetconfOperationService {\r
+\r
+    private final long currentSessionId;\r
+    private String macID;\r
+\r
+    OperationService(final long currentSessionId, String macID) {\r
+      this.currentSessionId = currentSessionId;\r
+      this.macID = macID;\r
+    }\r
+\r
+    @Override\r
+    public Set<NetconfOperation> getNetconfOperations() {\r
+      final DataList storage = new DataList();\r
+      final GetOperation oGet = new GetOperation(String.valueOf(currentSessionId), storage, macID);\r
+      final GetConfigOperation oGetConfig =\r
+          new GetConfigOperation(String.valueOf(currentSessionId), Optional.empty(), macID);\r
+      final SetConfigOperation oSetConfig =\r
+          new SetConfigOperation(String.valueOf(currentSessionId), macID);\r
+      final DeleteConfigOperation oDelConfig =\r
+          new DeleteConfigOperation(String.valueOf(currentSessionId), storage, macID);\r
+      final OperationCommit oCommit = new OperationCommit(String.valueOf(currentSessionId));\r
+      final OperationLock oLock = new OperationLock(String.valueOf(currentSessionId));\r
+      final OperationUnLock oUnlock = new OperationUnLock(String.valueOf(currentSessionId));\r
+      final CreateSubscription sCreateSubs =\r
+          new CreateSubscription(String.valueOf(currentSessionId), Optional.empty(), macID);\r
+      SoftwareDownloadOperation swDownloadOperation = new SoftwareDownloadOperation(macID);\r
+      SoftwareActivateOperation swActivateOperation = new SoftwareActivateOperation(macID);\r
+      return Sets.newHashSet(oGet, oGetConfig, oSetConfig, oDelConfig, oCommit, oLock, oUnlock,\r
+          sCreateSubs, swDownloadOperation, swActivateOperation);\r
+    }\r
+\r
+    @Override\r
+    public void close() {\r
+      logger.debug("close called on CustomOperationsCreator");\r
+    }\r
+\r
+  }\r
+}\r