aboutsummaryrefslogtreecommitdiffstats
path: root/tapisimulator/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'tapisimulator/src/main')
-rw-r--r--tapisimulator/src/main/java/org/onap/tapisimulator/Application.java33
-rw-r--r--tapisimulator/src/main/java/org/onap/tapisimulator/controller/TapiController.java73
-rw-r--r--tapisimulator/src/main/java/org/onap/tapisimulator/model/Name.java39
-rw-r--r--tapisimulator/src/main/java/org/onap/tapisimulator/model/Sip.java49
-rw-r--r--tapisimulator/src/main/java/org/onap/tapisimulator/model/SipList.java36
-rw-r--r--tapisimulator/src/main/java/org/onap/tapisimulator/service/TapiService.java156
-rw-r--r--tapisimulator/src/main/java/org/onap/tapisimulator/utils/Utils.java64
-rw-r--r--tapisimulator/src/main/resources/application.properties0
-rw-r--r--tapisimulator/src/main/resources/logback.xml28
9 files changed, 478 insertions, 0 deletions
diff --git a/tapisimulator/src/main/java/org/onap/tapisimulator/Application.java b/tapisimulator/src/main/java/org/onap/tapisimulator/Application.java
new file mode 100644
index 0000000..fede151
--- /dev/null
+++ b/tapisimulator/src/main/java/org/onap/tapisimulator/Application.java
@@ -0,0 +1,33 @@
+/*
+ * ============LICENSE_START=======================================================
+ * TAPI-SIMULATOR
+ * ================================================================================
+ * Copyright (C) 2020 Fujitsu Limited. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.tapisimulator;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+}
diff --git a/tapisimulator/src/main/java/org/onap/tapisimulator/controller/TapiController.java b/tapisimulator/src/main/java/org/onap/tapisimulator/controller/TapiController.java
new file mode 100644
index 0000000..4b246ef
--- /dev/null
+++ b/tapisimulator/src/main/java/org/onap/tapisimulator/controller/TapiController.java
@@ -0,0 +1,73 @@
+/*
+ * ============LICENSE_START=======================================================
+ * TAPI-SIMULATOR
+ * ================================================================================
+ * Copyright (C) 2020 Fujitsu Limited. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.tapisimulator.controller;
+
+import org.onap.tapisimulator.model.SipList;
+import org.onap.tapisimulator.service.TapiService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class TapiController {
+
+ @Autowired
+ TapiService tapiService;
+
+ @GetMapping("/cxf/tapi/v2/connectivities/service-interface-points/{connection-point}")
+ public SipList getTapiServiceInterfacePoint(@PathVariable("connection-point") String cep) {
+
+ return tapiService.getServiceInterfacePoints(cep);
+
+ }
+
+ @PostMapping("/cxf/tapi/v2/connectivities/create-service/{service-name}")
+ public String createTapiService(@PathVariable("service-name") String name, @RequestBody String requestbody) {
+ tapiService.processService(requestbody);
+ return "Service created Successfully";
+ }
+
+ @GetMapping("/cxf/tapi/v2/connectivities/get-service/{service-name}")
+ public String getTapiService(@PathVariable("service-name") String name) {
+
+ return tapiService.returnService(name);
+
+ }
+
+ @DeleteMapping("/cxf/tapi/v2/connectivities/delete-service/{service-name}")
+ public String deleteTapiService(@PathVariable("service-name") String name) {
+ tapiService.processDeleteService(name);
+ return "Service deleted successfully";
+
+ }
+
+ @GetMapping("/cxf/tapi/v2/connectivities/topology")
+ public String getTapiTopology() {
+
+ return tapiService.getTopology();
+
+ }
+
+}
diff --git a/tapisimulator/src/main/java/org/onap/tapisimulator/model/Name.java b/tapisimulator/src/main/java/org/onap/tapisimulator/model/Name.java
new file mode 100644
index 0000000..e5a6441
--- /dev/null
+++ b/tapisimulator/src/main/java/org/onap/tapisimulator/model/Name.java
@@ -0,0 +1,39 @@
+/*
+ * ============LICENSE_START=======================================================
+ * TAPI-SIMULATOR
+ * ================================================================================
+ * Copyright (C) 2020 Fujitsu Limited. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.tapisimulator.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class Name {
+
+ @JsonProperty(value = "value-name")
+ private String valueName;
+
+ private String value;
+
+}
diff --git a/tapisimulator/src/main/java/org/onap/tapisimulator/model/Sip.java b/tapisimulator/src/main/java/org/onap/tapisimulator/model/Sip.java
new file mode 100644
index 0000000..fb39855
--- /dev/null
+++ b/tapisimulator/src/main/java/org/onap/tapisimulator/model/Sip.java
@@ -0,0 +1,49 @@
+/*
+ * ============LICENSE_START=======================================================
+ * TAPI-SIMULATOR
+ * ================================================================================
+ * Copyright (C) 2020 Fujitsu Limited. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.tapisimulator.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.List;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class Sip {
+
+ @JsonProperty(value = "administrative-state")
+ private String administrativeState;
+
+ @JsonProperty(value = "lifecycle-state")
+ private String lifecycleState;
+
+ @JsonProperty(value = "layer-protocol-name")
+ private String layerProtocolName;
+
+ private List<Name> name;
+
+ private String uuid;
+
+}
diff --git a/tapisimulator/src/main/java/org/onap/tapisimulator/model/SipList.java b/tapisimulator/src/main/java/org/onap/tapisimulator/model/SipList.java
new file mode 100644
index 0000000..3a75be9
--- /dev/null
+++ b/tapisimulator/src/main/java/org/onap/tapisimulator/model/SipList.java
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START=======================================================
+ * TAPI-SIMULATOR
+ * ================================================================================
+ * Copyright (C) 2020 Fujitsu Limited. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.tapisimulator.model;
+
+import java.util.List;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class SipList {
+
+ private List<Sip> sip;
+
+}
diff --git a/tapisimulator/src/main/java/org/onap/tapisimulator/service/TapiService.java b/tapisimulator/src/main/java/org/onap/tapisimulator/service/TapiService.java
new file mode 100644
index 0000000..49b5689
--- /dev/null
+++ b/tapisimulator/src/main/java/org/onap/tapisimulator/service/TapiService.java
@@ -0,0 +1,156 @@
+/*
+ * ============LICENSE_START=======================================================
+ * TAPI-SIMULATOR
+ * ================================================================================
+ * Copyright (C) 2020 Fujitsu Limited. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.tapisimulator.service;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.onap.tapisimulator.model.Sip;
+import org.onap.tapisimulator.model.SipList;
+import org.onap.tapisimulator.utils.Utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class TapiService {
+
+ private static Logger log = LoggerFactory.getLogger(TapiService.class);
+
+ private volatile Map<String, String> serviceMap = new HashMap<>();
+
+ @Autowired
+ ObjectMapper mapper;
+
+ @Autowired
+ Utils utils;
+
+ private SipList siplist = null;
+
+ private List<Sip> sip = null;
+
+ private String topology;
+
+ @PostConstruct
+ public void init() throws IOException {
+ String domainController = System.getenv("Controller");
+ String servicePoints = "";
+ if (domainController.equals("TAPI1")) {
+ servicePoints = utils.readFromFile("/opt/onap/tapisimulator/templates/tapi1-siplist.json");
+ topology = utils.readFromFile("/opt/onap/tapisimulator/templates/tapi1-topology.json");
+ siplist = mapper.readValue(servicePoints, SipList.class);
+ sip = siplist.getSip();
+ log.debug("Inside init method of TapiService class");
+ } else if (domainController.equals("TAPI2")) {
+ servicePoints = utils.readFromFile("/opt/onap/tapisimulator/templates/tapi2-siplist.json");
+ topology = utils.readFromFile("/opt/onap/tapisimulator/templates/tapi2-topology.json");
+ siplist = mapper.readValue(servicePoints, SipList.class);
+ sip = siplist.getSip();
+ log.debug("Inside init method of TapiService class");
+ }
+
+ }
+
+ public SipList getServiceInterfacePoints(String connectionPoint) {
+
+ List<Sip> curSip = sip.stream().filter(c -> c.getUuid().equals(connectionPoint)).collect(Collectors.toList());
+
+ SipList newSip = new SipList();
+ newSip.setSip(curSip);
+ return newSip;
+ }
+
+ public Map<String, String> getServiceMap() {
+ return serviceMap;
+ }
+
+ public void setServiceMap(String key, String value) {
+ serviceMap.put(key, value);
+ }
+
+ public void processService(String request) {
+ JSONObject json = new JSONObject(request);
+ JSONArray conectivityList = json.getJSONArray("create-connectivity-service-input-list");
+ JSONObject connec = conectivityList.getJSONObject(0);
+ JSONArray eplist = connec.getJSONArray("end-point");
+ JSONArray name = connec.getJSONArray("name");
+ String serviceName = name.getJSONObject(0).getString("value");
+
+ createSErviceMap(eplist, serviceName, name);
+
+ }
+
+ public String returnService(String name) {
+
+ return serviceMap.get(name);
+
+ }
+
+ public String processDeleteService(String name) {
+
+ return serviceMap.remove(name);
+
+ }
+
+ public String getTopology() {
+
+ return topology;
+
+ }
+
+ private void createSErviceMap(JSONArray eplist, String serviceName, JSONArray name) {
+ JSONObject serviceEntry = new JSONObject();
+ serviceEntry.put("end-point", eplist);
+ serviceEntry.put("topology-constraint", new JSONArray());
+ serviceEntry.put("routing-constraint", new JSONObject());
+ serviceEntry.put("connectivity-constraint", new JSONObject());
+ serviceEntry.put("uuid", UUID.randomUUID().toString());
+ serviceEntry.put("layer-protocol-name", "ODU");
+ serviceEntry.put("direction", "BIDIRECTIONAL");
+ serviceEntry.put("administrative-state", "UNLOCKED");
+ serviceEntry.put("operational-state", "ENABLED");
+ JSONArray connection = new JSONArray();
+ JSONObject connectionObject = new JSONObject();
+ connectionObject.put("connection-uuid", UUID.randomUUID().toString());
+ connection.put(0, connectionObject);
+ serviceEntry.put("connection", connection);
+ serviceEntry.put("name", name);
+
+ JSONObject service = new JSONObject();
+ JSONArray serviceList = new JSONArray();
+ serviceList.put(0, serviceEntry);
+ service.put("service", serviceList);
+
+ serviceMap.put(serviceName, service.toString());
+ }
+
+}
diff --git a/tapisimulator/src/main/java/org/onap/tapisimulator/utils/Utils.java b/tapisimulator/src/main/java/org/onap/tapisimulator/utils/Utils.java
new file mode 100644
index 0000000..8d2ac4d
--- /dev/null
+++ b/tapisimulator/src/main/java/org/onap/tapisimulator/utils/Utils.java
@@ -0,0 +1,64 @@
+/*
+ * ============LICENSE_START=======================================================
+ * TAPI-SIMULATOR
+ * ================================================================================
+ * Copyright (C) 2020 Fujitsu Limited. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.tapisimulator.utils;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import org.springframework.stereotype.Component;
+import org.springframework.util.ResourceUtils;
+
+@Component
+public class Utils {
+
+ public void readFileclasspath() throws IOException {
+ File file = ResourceUtils.getFile("classpath:config/sample.txt");
+
+ // File is found
+ System.out.println("File Found : " + file.exists());
+
+ // Read File Content
+ String content = new String(Files.readAllBytes(file.toPath()));
+ System.out.println(content);
+ }
+
+ public String readFromFile(String file) {
+ String content = "";
+ try {
+
+ BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
+ content = bufferedReader.readLine();
+ String temp;
+ while ((temp = bufferedReader.readLine()) != null) {
+ content = content.concat(temp);
+ }
+ content = content.trim();
+ bufferedReader.close();
+ } catch (Exception e) {
+ content = null;
+ }
+ return content;
+ }
+
+}
diff --git a/tapisimulator/src/main/resources/application.properties b/tapisimulator/src/main/resources/application.properties
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tapisimulator/src/main/resources/application.properties
diff --git a/tapisimulator/src/main/resources/logback.xml b/tapisimulator/src/main/resources/logback.xml
new file mode 100644
index 0000000..10f7ccf
--- /dev/null
+++ b/tapisimulator/src/main/resources/logback.xml
@@ -0,0 +1,28 @@
+<configuration>
+ <appender name="FILE-THREAD" class="ch.qos.logback.classic.sift.SiftingAppender">
+ <discriminator>
+ <key>logFileName</key>
+ <defaultValue>dcasim</defaultValue>
+ </discriminator>
+
+ <sift>
+ <appender name="file-${logFileName}" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>/var/log/onap/dcasimulator/${logFileName}.log</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${logFileName}.%i.log.zip</fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>5</maxIndex>
+ </rollingPolicy>
+ <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>5MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} %magenta([%thread]) %highlight(%-5level) %logger{36}.%M - %msg%n</pattern>
+ </encoder>
+ </appender>
+ </sift>
+ </appender>
+ <root level="debug">
+ <appender-ref ref="FILE-THREAD" />
+ </root>
+</configuration>