+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2019 Nordix Foundation.
- ================================================================================
- 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.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.oran.nearric</groupId>
- <artifactId>nearric-simulator</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </parent>
- <artifactId>nearric-service</artifactId>
- <name>${project.artifactId}</name>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <okhttp-version>2.7.5</okhttp-version>
- <gson-version>2.8.1</gson-version>
- <dockerfile-maven-version>1.4.2</dockerfile-maven-version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.oran.nearric</groupId>
- <artifactId>a1-med-api</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-jpa</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-jaxrs</artifactId>
- <version>1.5.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.studio</groupId>
- <artifactId>org.apache.commons.io</artifactId>
- <version>2.4</version>
- </dependency>
- <dependency>
- <groupId>com.googlecode.json-simple</groupId>
- <artifactId>json-simple</artifactId>
- <version>1.1.1</version>
- </dependency>
-
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>2.6.1</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger2</artifactId>
- <version>2.6.1</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- </dependency>
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- </dependency>
- <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>1.9.3</version>
- </dependency>
- <dependency>
- <groupId>org.modelmapper</groupId>
- <artifactId>modelmapper</artifactId>
- <version>2.3.0</version>
- </dependency>
- <dependency>
- <groupId>com.squareup.okio</groupId>
- <artifactId>okio</artifactId>
- <version>1.13.0</version>
- </dependency>
- <dependency>
- <groupId>com.squareup.okhttp</groupId>
- <artifactId>okhttp</artifactId>
- <version>${okhttp-version}</version>
- </dependency>
- <dependency>
- <groupId>com.squareup.okhttp</groupId>
- <artifactId>logging-interceptor</artifactId>
- <version>${okhttp-version}</version>
- </dependency>
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>${gson-version}</version>
- </dependency>
- <dependency>
- <groupId>com.github.java-json-tools</groupId>
- <artifactId>json-schema-validator</artifactId>
- <version>2.2.11</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <configuration>
- <mainClass>org.onap.nearric.simulator.config.NearRicApplication</mainClass>
- </configuration>
- <executions>
- <execution>
- <goals>
- <goal>repackage</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>io.fabric8</groupId>
- <artifactId>docker-maven-plugin</artifactId>
- <version>0.30.0</version>
- <configuration>
- <verbose>true</verbose>
- <!-- environment variables supplied by Jenkins -->
- <pushRegistry>${env.CONTAINER_PUSH_REGISTRY}</pushRegistry>
- <images>
- <image>
- <!-- Specify a tag to avoid default tag "latest" -->
- <!-- Avoid maven artifact name here -->
- <name>o-ran-sc/nonrtric-nearric-simulator:${project.version}</name>
- <build>
- <from>openjdk:11-jre-slim</from>
- <tags>
- <!-- Add tag with build number -->
- <tag>${project.version}</tag>
- </tags>
- <assembly>
- <descriptorRef>artifact</descriptorRef>
- </assembly>
- <cmd>
- <!-- Include maven dir on classpath for prop files -->
- <exec>
- <arg>java</arg>
- <arg>-Xms128m</arg>
- <arg>-Xmx256m</arg>
- <arg>-cp</arg>
- <arg>maven:maven/${project.artifactId}-${project.version}.${project.packaging}</arg>
- <arg>-Dloader.main=org.onap.nearric.simulator.config.NearRicApplication</arg>
- <arg>-Djava.security.egd=file:/dev/./urandom</arg>
- <arg>org.springframework.boot.loader.PropertiesLauncher</arg>
- </exec>
- </cmd>
- </build>
- </image>
- </images>
- </configuration>
- <!-- build Docker images in install phase, push in deploy phase -->
- <executions>
- <execution>
- <goals>
- <goal>build</goal>
- <goal>push</goal>
- </goals>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>javax.activation</groupId>
- <artifactId>activation</artifactId>
- <version>1.1.1</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
-</project>
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.nearric.simulator.config;
-
-import java.util.HashMap;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * This class provides all the configuration for the Spring boot application
- *
- * @author lathishbabu.ganesan@est.tech
- *
- */
-@Configuration
-public class ApplicationConfig {
-
- private final HashMap<Integer, Object> policyTypeCache = new HashMap<>();
-
- @Bean
- public HashMap<Integer, Object> getPolicyTypeCache() {
- return policyTypeCache;
- }
-
-}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.nearric.simulator.config;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cache.annotation.EnableCaching;
-import org.springframework.context.annotation.ComponentScan;
-
-/**
- * This is the Spring Boot Application
- *
- * @author lathishbabu.ganesan@est.tech
- *
- */
-
-@SpringBootApplication
-@ComponentScan({"org.oransc", "org.onap"})
-@EnableCaching
-public class NearRicApplication {
- public static void main(final String[] args) {
- SpringApplication.run(NearRicApplication.class, args);
- }
-}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.nearric.simulator.config;
-
-import org.onap.nearric.simulator.controller.A1PApiController;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import springfox.documentation.builders.PathSelectors;
-import springfox.documentation.builders.RequestHandlerSelectors;
-import springfox.documentation.spi.DocumentationType;
-import springfox.documentation.spring.web.plugins.Docket;
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
-
-/**
- * This class provides all the configuration for the Spring boot application
- *
- * @author lathishbabu.ganesan@est.tech
- *
- */
-@Configuration
-@EnableSwagger2
-public class SwaggerConfiguration {
- @Bean
- public Docket apiDocket() {
- return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage("org.onap.nearric.simulator"))
- .paths(PathSelectors.any()).build();
- }
-
-}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-/**
- * NOTE: This class is auto generated by the swagger code generator program (3.0.8).
- * https://github.com/swagger-api/swagger-codegen
- * Do not edit the class manually.
- */
-package org.onap.nearric.simulator.controller;
-
-import org.oransc.ric.a1med.api.model.InlineResponse200;
-import org.oransc.ric.a1med.api.model.PolicyTypeSchema;
-import io.swagger.annotations.*;
-import org.springframework.http.ResponseEntity;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RequestPart;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.validation.Valid;
-import javax.validation.constraints.*;
-import java.util.List;
-import java.util.Map;
-@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2019-10-04T13:41:42.802+01:00[Europe/Dublin]")
-@Api(value = "a1-p", description = "the a1-p API")
-public interface A1PApi {
-
- @ApiOperation(value = "", nickname = "a1ControllerCreateOrReplacePolicyInstance", notes = "Create or replace a policy instance of type policy_type_id. The schema of the PUT body is defined by the create_schema field of the policy type. ", tags={ "A1 Mediator", })
- @ApiResponses(value = {
- @ApiResponse(code = 201, message = "Policy instance created "),
- @ApiResponse(code = 400, message = "Bad PUT body for this policy instance "),
- @ApiResponse(code = 404, message = "There is no policy type with this policy_type_id ") })
- @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}",
- consumes = { "application/json" },
- method = RequestMethod.PUT)
- ResponseEntity<Void> a1ControllerCreateOrReplacePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId,@ApiParam(value = "" ) @Valid @RequestBody Object body);
-
-
- @ApiOperation(value = "", nickname = "a1ControllerCreatePolicyType", notes = "Create a new policy type . Replace is not currently allowed; to replace, for now do a DELETE and then a PUT again. ", tags={ "A1 Mediator", })
- @ApiResponses(value = {
- @ApiResponse(code = 201, message = "policy type successfully created"),
- @ApiResponse(code = 400, message = "illegal ID, or object already existed") })
- @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}",
- consumes = { "application/json" },
- method = RequestMethod.PUT)
- ResponseEntity<Void> a1ControllerCreatePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "" ) @Valid @RequestBody PolicyTypeSchema body);
-
-
- @ApiOperation(value = "", nickname = "a1ControllerDeletePolicyInstance", notes = "Delete this policy instance ", tags={ "A1 Mediator", })
- @ApiResponses(value = {
- @ApiResponse(code = 204, message = "policy instance successfully deleted "),
- @ApiResponse(code = 404, message = "there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id ") })
- @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}",
- method = RequestMethod.DELETE)
- ResponseEntity<Void> a1ControllerDeletePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId);
-
-
- @ApiOperation(value = "", nickname = "a1ControllerDeletePolicyType", notes = "Delete this policy type. Can only be performed if there are no instances of this type ", tags={ "A1 Mediator", })
- @ApiResponses(value = {
- @ApiResponse(code = 204, message = "policy type successfully deleted "),
- @ApiResponse(code = 400, message = "Policy type cannot be deleted because there are instances All instances must be removed before a policy type can be deleted "),
- @ApiResponse(code = 404, message = "policy type not found ") })
- @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}",
- method = RequestMethod.DELETE)
- ResponseEntity<Void> a1ControllerDeletePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId);
-
-
- @ApiOperation(value = "", nickname = "a1ControllerGetAllInstancesForType", notes = "get a list of all policy instance ids for this policy type id", response = String.class, responseContainer = "List", tags={ "A1 Mediator", })
- @ApiResponses(value = {
- @ApiResponse(code = 200, message = "list of all policy instance ids for this policy type id", response = String.class, responseContainer = "List") })
- @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}/policies",
- produces = { "application/json" },
- method = RequestMethod.GET)
- ResponseEntity<List<String>> a1ControllerGetAllInstancesForType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId);
-
-
- @ApiOperation(value = "", nickname = "a1ControllerGetAllPolicyTypes", notes = "Get a list of all registered policy type ids", response = Integer.class, responseContainer = "List", tags={ "A1 Mediator", })
- @ApiResponses(value = {
- @ApiResponse(code = 200, message = "list of all registered policy type ids", response = Integer.class, responseContainer = "List") })
- @RequestMapping(value = "/a1-p/policytypes/",
- produces = { "application/json" },
- method = RequestMethod.GET)
- ResponseEntity<List<Integer>> a1ControllerGetAllPolicyTypes();
-
-
- @ApiOperation(value = "", nickname = "a1ControllerGetHealthcheck", notes = "Perform a healthcheck on a1 ", tags={ "A1 Mediator", })
- @ApiResponses(value = {
- @ApiResponse(code = 200, message = "A1 is healthy. Anything other than a 200 should be considered a1 as failing ") })
- @RequestMapping(value = "/a1-p/healthcheck",
- method = RequestMethod.GET)
- ResponseEntity<Void> a1ControllerGetHealthcheck();
-
-
- @ApiOperation(value = "", nickname = "a1ControllerGetPolicyInstance", notes = "Retrieve the policy instance ", response = Object.class, tags={ "A1 Mediator", })
- @ApiResponses(value = {
- @ApiResponse(code = 200, message = "The policy instance. the schema of this object is defined by the create_schema field of the policy type ", response = Object.class),
- @ApiResponse(code = 404, message = "there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id ") })
- @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}",
- produces = { "application/json" },
- method = RequestMethod.GET)
- ResponseEntity<Object> a1ControllerGetPolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId);
-
-
- @ApiOperation(value = "", nickname = "a1ControllerGetPolicyInstanceStatus", notes = "Retrieve the policy instance status across all handlers of the policy ", response = InlineResponse200.class, responseContainer = "List", tags={ "A1 Mediator", })
- @ApiResponses(value = {
- @ApiResponse(code = 200, message = "The policy instance status. Returns a vector of statuses, where each contains a handler_id (opaque id of a RIC component that implements this policy) and the policy status as returned by that handler ", response = InlineResponse200.class, responseContainer = "List"),
- @ApiResponse(code = 404, message = "there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id ") })
- @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}/status",
- produces = { "application/json" },
- method = RequestMethod.GET)
- ResponseEntity<List<InlineResponse200>> a1ControllerGetPolicyInstanceStatus(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId);
-
-
- @ApiOperation(value = "", nickname = "a1ControllerGetPolicyType", notes = "Get this policy type ", response = PolicyTypeSchema.class, tags={ "A1 Mediator", })
- @ApiResponses(value = {
- @ApiResponse(code = 200, message = "policy type successfully found", response = PolicyTypeSchema.class),
- @ApiResponse(code = 404, message = "policy type not found ") })
- @RequestMapping(value = "/a1-p/policytypes/{policy_type_id}",
- produces = { "application/json" },
- method = RequestMethod.GET)
- ResponseEntity<PolicyTypeSchema> a1ControllerGetPolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId);
-
-}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.nearric.simulator.controller;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import javax.validation.Valid;
-
-import org.apache.commons.beanutils.BeanUtils;
-import org.onap.nearric.simulator.model.PolicyType;
-import org.onap.nearric.simulator.service.A1PApiServiceImpl;
-import org.oransc.ric.a1med.api.model.InlineResponse200;
-import org.oransc.ric.a1med.api.model.PolicyTypeSchema;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RestController;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-
-import io.swagger.annotations.ApiParam;
-
-/**
- * This class provides all the operation performed by A1 API.
- *
- * @author lathishbabu.ganesan@est.tech
- *
- */
-@RestController
-public class A1PApiController implements A1PApi {
-
- private static final Logger log = LoggerFactory.getLogger(A1PApiController.class);
-
- private final ObjectMapper objectMapper;
-
- private final HttpServletRequest request;
-
- //@Autowired
- private A1PApiServiceImpl a1pApiService;
- //private A1PApiService a1pApiService;
-
- @Autowired
- public A1PApiController(ObjectMapper objectMapper, HttpServletRequest request) {
- this.objectMapper = objectMapper;
- this.request = request;
- a1pApiService = new A1PApiServiceImpl();
- a1pApiService.set(objectMapper, request);
- }
-
- //Reset policy db
- @RequestMapping(value = "reset",
- method = RequestMethod.GET)
- public void reset() {
- a1pApiService.reset();
- }
-
- public ResponseEntity<Void> a1ControllerCreateOrReplacePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId,@ApiParam(value = "" ) @Valid @RequestBody Object body) {
- return a1pApiService.createReplaceInstance(policyTypeId, policyInstanceId, body);
- }
-
- public ResponseEntity<Void> a1ControllerCreatePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "" ) @Valid @RequestBody PolicyTypeSchema body) {
- return a1pApiService.createReplaceType(policyTypeId, body);
- }
-
- public ResponseEntity<Void> a1ControllerDeletePolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) {
- return a1pApiService.deleteInstance(policyTypeId, policyInstanceId);
- }
-
- public ResponseEntity<Void> a1ControllerDeletePolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) {
- return a1pApiService.deleteType(policyTypeId);
- }
-
- public ResponseEntity<List<String>> a1ControllerGetAllInstancesForType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) {
- return a1pApiService.getAllInstanceForType(policyTypeId);
- }
-
- public ResponseEntity<List<Integer>> a1ControllerGetAllPolicyTypes() {
- return a1pApiService.getAllTypes();
- }
-
- public ResponseEntity<Void> a1ControllerGetHealthcheck() {
- return new ResponseEntity<Void>(HttpStatus.OK);
- }
-
- public ResponseEntity<Object> a1ControllerGetPolicyInstance(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) {
- return a1pApiService.getPolicyInstance(policyTypeId, policyInstanceId);
- }
-
- public ResponseEntity<List<InlineResponse200>> a1ControllerGetPolicyInstanceStatus(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId,@ApiParam(value = "",required=true) @PathVariable("policy_instance_id") String policyInstanceId) {
- return a1pApiService.getStatus(policyTypeId, policyInstanceId);
- }
-
- public ResponseEntity<PolicyTypeSchema> a1ControllerGetPolicyType(@ApiParam(value = "",required=true) @PathVariable("policy_type_id") Integer policyTypeId) {
- return a1pApiService.getPolicyTypeSchema(policyTypeId);
- }
-
-}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.nearric.simulator.model;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-
- public class PolicyInstance implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = -4903894058377154039L;
- private String policyInstanceId;
- private Object jsonObject;
-
- public PolicyInstance(String policyInstanceId, Object jsonObject) {
- this.policyInstanceId = policyInstanceId;
- this.jsonObject = jsonObject;
- }
-
- public Object getJson() {
- return jsonObject;
- }
-
- public String getInstanceId() {
- return policyInstanceId;
- }
-}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.nearric.simulator.model;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Set;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import org.oransc.ric.a1med.api.model.PolicyTypeSchema;
-
-public class PolicyType implements Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 8719589957000170141L;
- private Integer policyTypeId;
- private PolicyTypeSchema policyTypeSchema;
- private HashMap<String, PolicyInstance> policyInstances = new HashMap<String, PolicyInstance>();
-
- public PolicyType(Integer policyTypeId, PolicyTypeSchema policyTypeSchema) {
- this.policyTypeId = policyTypeId;
- this.policyTypeSchema = policyTypeSchema;
- }
-
- public int getNumberInstances() {
- return policyInstances.size();
- }
-
- public PolicyInstance getInstance(String policyInstanceId) {
- return policyInstances.get(policyInstanceId);
- }
-
- public void delete(String policyInstanceId) {
- policyInstances.remove(policyInstanceId);
- }
-
- public PolicyTypeSchema getSchema() {
- return policyTypeSchema;
- }
-
- public void createReplaceInstance(String policyTypeId, PolicyInstance policyInstance) {
- policyInstances.put(policyTypeId, policyInstance);
- }
-
- public Set<String> getInstances() {
- return policyInstances.keySet();
- }
-
- public Integer getTypeId() {
- return policyTypeId;
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.nearric.simulator.service;
-
-import org.onap.nearric.simulator.model.PolicyType;
-import org.oransc.ric.a1med.api.model.PolicyTypeSchema;
-
-/**
- * @author lathishbabu.ganesan@est.tech
- *
- */
-
-public interface A1PApiService {
-
- public void getHealthCheck();
-
- public void getPolicyTypes();
-
- public PolicyType getPolicyType(Integer policyTypeId);
-
- public void deletePolicyTypeId();
-
- public void putPolicyType(Integer policyTypeId, PolicyTypeSchema policyTypeSchema);
-
- public void getPolicyInstances();
-
- public void getPolicyInstanceId();
-
- public void deletePolicyInstanceId();
-
- public void putPolicyInstance(Integer policyTypeId, String policyInstanceId, Object body);
-
- public void getPolicyInstanceIdStatus();
-
-}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.nearric.simulator.service;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.onap.nearric.simulator.model.PolicyInstance;
-import org.onap.nearric.simulator.model.PolicyType;
-import org.oransc.ric.a1med.api.model.InlineResponse200;
-import org.oransc.ric.a1med.api.model.PolicyTypeSchema;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Service;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.github.fge.jackson.JsonLoader;
-import com.github.fge.jsonschema.core.exceptions.ProcessingException;
-import com.github.fge.jsonschema.core.report.ProcessingMessage;
-import com.github.fge.jsonschema.core.report.ProcessingReport;
-import com.github.fge.jsonschema.main.JsonSchema;
-import com.github.fge.jsonschema.main.JsonSchemaFactory;
-
-/**
- * This class provides the service implementation of all the A1 operation
- *
- * @author lathishbabu.ganesan@est.tech
- *
- */
-
-@Service
-public class A1PApiServiceImpl {
-
- private static final Logger log = LoggerFactory.getLogger(A1PApiServiceImpl.class);
-
- private HashMap<String, PolicyType> policyTypes = new HashMap<String, PolicyType>();
-
- private ObjectMapper objectMapper = null;
-
- private HttpServletRequest request = null;
-
- public boolean validateSchema(String jsonData, String jsonSchema) {
- ProcessingReport report = null;
- boolean result = false;
- try {
- log.info("Applying schema: @<@<" + jsonSchema + ">@>@ to data: #<#<" + jsonData + ">#>#");
- JsonNode schemaNode = JsonLoader.fromString(jsonSchema);
- JsonNode data = JsonLoader.fromString(jsonData);
- JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
- JsonSchema schema = factory.getJsonSchema(schemaNode);
- report = schema.validate(data);
- } catch (JsonParseException jpex) {
- log.info("Error. Something went wrong trying to parse json data: #<#<" + jsonData
- + ">#># or json schema: @<@<" + jsonSchema + ">@>@. Are the double quotes included? "
- + jpex.getMessage());
- } catch (ProcessingException pex) {
- log.info("Error. Something went wrong trying to process json data: #<#<" + jsonData
- + ">#># with json schema: @<@<" + jsonSchema + ">@>@ " + pex.getMessage());
- } catch (IOException e) {
- log.info("Error. Something went wrong trying to read json data: #<#<" + jsonData
- + ">#># or json schema: @<@<" + jsonSchema + ">@>@");
- }
- if (report != null) {
- Iterator<ProcessingMessage> iter = report.iterator();
- while (iter.hasNext()) {
- ProcessingMessage pm = iter.next();
- log.info("Processing Message: " + pm.getMessage());
- }
- result = report.isSuccess();
- }
- log.info("Result=" + result);
- return result;
- }
-
- public A1PApiServiceImpl() {
- }
-
- public void set(ObjectMapper objectMapper, HttpServletRequest request) {
- this.objectMapper = objectMapper;
- this.request = request;
- }
-
- public void reset() {
- log.info("Resetting db");
- policyTypes.clear();
- }
-
- public ResponseEntity<Void> createReplaceType(Integer policyTypeId, PolicyTypeSchema policyTypeSchema) {
- log.info("createReplaceType - policyTypeId: " + policyTypeId);
- log.info("createReplaceType - policyTypeSchema: " + policyTypeSchema);
-
- if (policyTypeId == null || policyTypeSchema == null || policyTypeSchema.getName() == null) {
- log.info("createReplaceType - bad parameters");
- return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
- }
-
- if (policyTypeSchema.getPolicyTypeId().intValue() != policyTypeId.intValue()) {
- log.info("createReplaceType - policytype id mismatch between request and policyTypeSchema");
- return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
- }
-
- if (policyTypes.containsKey(policyTypeId.toString())) {
- log.info("createReplaceType - policytype already exists");
- return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
- }
-
- PolicyType policyType = new PolicyType(policyTypeId, policyTypeSchema);
- policyTypes.put(policyTypeId.toString(), policyType);
- log.info("createReplaceType - created ok");
-
- return new ResponseEntity<Void>(HttpStatus.CREATED);
- }
-
- public ResponseEntity<Void> deleteType(Integer policyTypeId) {
- log.info("deleteType - policyTypeId: " + policyTypeId);
-
- if (policyTypeId == null) {
- log.info("deleteType - bad parameter");
- return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
- }
-
- PolicyType policyType = policyTypes.get(policyTypeId.toString());
-
- if (policyType == null) {
- log.info("deleteType - policytype does not exists");
- return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
- }
-
- if (policyType.getNumberInstances() > 0) {
- log.info("deleteType - cannot delete, instances exists");
- return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
- }
- policyTypes.remove(policyTypeId.toString());
-
- log.info("deleteType - deleted ok");
- return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
- }
-
- public ResponseEntity<Void> deleteInstance(Integer policyTypeId, String policyInstanceId) {
-
- log.info("deleteInstance - policyTypeId: " + policyTypeId);
- log.info("deleteInstance - policyInstanceId: " + policyInstanceId);
-
- if (policyTypeId == null || policyInstanceId == null) {
- log.info("deleteInstance - bad parameters");
- return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
- }
-
- PolicyType policyType = policyTypes.get(policyTypeId.toString());
-
- if (policyType == null) {
- log.info("deleteType - policytype does not exists");
- return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
- }
- PolicyInstance policyInstance = policyType.getInstance(policyInstanceId);
- if (policyInstance == null) {
- log.info("deleteType - instance does not exists");
- return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
- }
- policyType.delete(policyInstanceId);
-
- log.info("deleteInstance - deleted ok");
- return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
-
- }
-
- public ResponseEntity<PolicyTypeSchema> getPolicyTypeSchema(Integer policyTypeId) {
- log.info("getPolicyTypeSchema - policyTypeId: " + policyTypeId);
-
- if (policyTypeId == null) {
- log.info("getPolicyTypeSchema - bad parameter");
- return new ResponseEntity<PolicyTypeSchema>(HttpStatus.NOT_FOUND);
- }
-
- String accept = request.getHeader("Accept");
- if (accept != null && accept.contains("application/json")) {
- String res = null;
- try {
- PolicyType policyType = policyTypes.get(policyTypeId.toString());
-
- if (policyType == null) {
- log.info("getPolicyTypeSchema - policytype does not exists");
- return new ResponseEntity<PolicyTypeSchema>(HttpStatus.NOT_FOUND);
- }
-
- String json = null;
- PolicyTypeSchema schema = policyType.getSchema();
- String createSchema = "{}";
- try {
- // Convert Map to JSON
- json = objectMapper.writeValueAsString(schema);
- // Print JSON output
- log.info("getPolicyTypeSchema - schema: " + json);
-
- createSchema = objectMapper.writeValueAsString(schema.getCreateSchema());
- log.info("getPolicyTypeSchema - createSchema: " + createSchema);
- } catch (Exception e) {
- e.printStackTrace();
- log.info("getPolicyTypeSchema - schema corrupt");
- return new ResponseEntity<PolicyTypeSchema>(HttpStatus.INTERNAL_SERVER_ERROR);
- }
- res = "{\n \"name\" : \"" + schema.getName() + "\",\n \"description\" : \"" + schema.getDescription()
- + "\",\n \"create_schema\" : " + createSchema + ",\n \"policy_type_id\" : "
- + schema.getPolicyTypeId().intValue() + "\n}";
- log.info("getPolicyTypeSchema - json schema: " + res);
- return new ResponseEntity<PolicyTypeSchema>(objectMapper.readValue(res, PolicyTypeSchema.class),
- HttpStatus.OK);
- } catch (Exception e) {
- e.printStackTrace();
- log.info("getPolicyTypeSchema - Couldn't serialize response for content type application/json");
- return new ResponseEntity<PolicyTypeSchema>(HttpStatus.INTERNAL_SERVER_ERROR);
- }
- }
- log.info("getPolicyTypeSchema - not implemented");
- return new ResponseEntity<PolicyTypeSchema>(HttpStatus.NOT_IMPLEMENTED);
- }
-
- public ResponseEntity<List<Integer>> getAllTypes() {
- log.info("getAllTypes");
-
- String accept = request.getHeader("Accept");
- if (accept != null && accept.contains("application/json")) {
- try {
- Set<String> types = policyTypes.keySet();
- String res = "";
- for (Iterator<String> iterator = types.iterator(); iterator.hasNext();) {
- String tid = (String) iterator.next();
- if (res.length() > 0) {
- res = res + ",";
- }
- res = res + tid;
- }
- return new ResponseEntity<List<Integer>>(objectMapper.readValue("[" + res + "]", List.class),
- HttpStatus.OK);
- } catch (IOException e) {
- e.printStackTrace();
- log.info("getAllTypes - Couldn't serialize response for content type application/json");
- return new ResponseEntity<List<Integer>>(HttpStatus.INTERNAL_SERVER_ERROR);
- }
- }
- log.info("getAllTypes - not implemented");
- return new ResponseEntity<List<Integer>>(HttpStatus.NOT_IMPLEMENTED);
- }
-
- public ResponseEntity<Void> createReplaceInstance(Integer policyTypeId, String policyInstanceId, Object body) {
- log.info("createReplaceInstance - policyTypeId:" + policyTypeId);
- log.info("createReplaceInstance - policyInstanceId:" + policyInstanceId);
- log.info("createReplaceInstance - body:" + body);
-
- if (policyTypeId == null || policyInstanceId == null || body == null) {
- log.info("createReplaceInstance - bad parameter");
- return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
- }
-
- log.info("createReplaceInstance - bodyclass:" + body.getClass().toString());
-
- PolicyType policyType = policyTypes.get(policyTypeId.toString());
-
- if (policyType == null) {
- log.info("createReplaceInstance - policytype does not exists");
- return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
- }
-
- // Create json string from schema
- String createSchema = null;
- try {
- PolicyTypeSchema schema = policyType.getSchema();
- // Convert Map to JSON
- String json = objectMapper.writeValueAsString(schema);
- // Print JSON output
- log.info("createReplaceInstance - schema - json: " + json);
- createSchema = objectMapper.writeValueAsString(schema.getCreateSchema());
- log.info("createReplaceInstance - createSchema - string: " + createSchema);
- } catch (Exception e) {
- e.printStackTrace();
- log.info("createReplaceInstance - schema corrupt");
- return new ResponseEntity<Void>(HttpStatus.INTERNAL_SERVER_ERROR);
- }
-
- // Create json string from instance
- String jsonInstance = null;
- try {
- log.info("createReplaceInstance - raw: " + body);
- // Convert Map to JSON
- jsonInstance = objectMapper.writeValueAsString(body);
- // Print JSON output
- log.info("createReplaceInstance - instance: " + jsonInstance);
-
- } catch (Exception e) {
- e.printStackTrace();
- log.info("createReplaceInstance - instancce corrupt");
- return new ResponseEntity<Void>(HttpStatus.INTERNAL_SERVER_ERROR);
- }
-
- if (!validateSchema(jsonInstance, createSchema)) {
- log.info("createReplaceInstance - schema validation failed");
- return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
- }
- PolicyInstance policyInstance = new PolicyInstance(policyInstanceId, body);
- policyType.createReplaceInstance(policyInstanceId, policyInstance);
-
- log.info("createReplaceInstance - created/replaced ok");
- return new ResponseEntity<Void>(HttpStatus.CREATED);
-
- }
-
- public ResponseEntity<List<String>> getAllInstanceForType(Integer policyTypeId) {
- log.info("getAllInstanceForType - policyTypeId:" + policyTypeId);
-
- if (policyTypeId == null) {
- log.info("getAllInstanceForType - bad parameter");
- return new ResponseEntity<List<String>>(HttpStatus.NOT_FOUND);
- }
-
- String accept = request.getHeader("Accept");
- if (accept != null && accept.contains("application/json")) {
- try {
- PolicyType policyType = policyTypes.get(policyTypeId.toString());
- if (policyType == null) {
- log.info("getAllInstanceForType - policytype does not exists");
- return new ResponseEntity<List<String>>(HttpStatus.NOT_FOUND);
- }
- Set<String> instances = policyType.getInstances();
- String res = "";
- for (Iterator iterator = instances.iterator(); iterator.hasNext();) {
- String iid = (String) iterator.next();
- iid = "\"" + iid + "\"";
- if (res.length() > 0) {
- res = res + ",";
- }
- res = res + iid;
- }
- log.info("getAllInstanceForType - " + res);
- return new ResponseEntity<List<String>>(objectMapper.readValue("[" + res + "]", List.class),
- HttpStatus.OK);
- } catch (IOException e) {
- e.printStackTrace();
- log.info("getAllInstanceForType - Couldn't serialize response for content type application/json");
- return new ResponseEntity<List<String>>(HttpStatus.INTERNAL_SERVER_ERROR);
- }
- }
- log.info("getAllInstanceForType - not implemented");
- return new ResponseEntity<List<String>>(HttpStatus.NOT_IMPLEMENTED);
-
- }
-
- public ResponseEntity<Object> getPolicyInstance(Integer policyTypeId, String policyInstanceId) {
- log.info("getPolicyInstance - policyTypeId:" + policyTypeId);
- log.info("getPolicyInstance - policyInstanceId:" + policyInstanceId);
-
- if (policyTypeId == null || policyInstanceId == null) {
- log.info("getPolicyInstance - bad parameter");
- return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
- }
-
- String accept = request.getHeader("Accept");
- if (accept != null && accept.contains("application/json")) {
- try {
- PolicyType policyType = policyTypes.get(policyTypeId.toString());
- if (policyType == null) {
- log.info("getPolicyInstance - policytype does not exists");
- return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
- }
- PolicyInstance policyInstance = policyType.getInstance(policyInstanceId);
- if (policyInstance == null) {
- log.info("getPolicyInstance - policyinstance does not exists");
- return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
- }
-
- String json = null;
- try {
- log.info("getPolicyInstance - rawschema: " + policyInstance.getJson());
- // Convert Map to JSON
- json = objectMapper.writeValueAsString(policyInstance.getJson());
- // Print JSON output
- log.info("getPolicyInstance - schema: " + json);
-
- } catch (Exception e) {
- e.printStackTrace();
- log.info("getPolicyInstance - schema corrupt");
- return new ResponseEntity<Object>(HttpStatus.INTERNAL_SERVER_ERROR);
- }
-
- return new ResponseEntity<Object>(objectMapper.readValue(json, Object.class), HttpStatus.OK);
- } catch (IOException e) {
- e.printStackTrace();
- log.info("getPolicyInstance - policyinstance corrupt");
- return new ResponseEntity<Object>(HttpStatus.INTERNAL_SERVER_ERROR);
- }
- }
-
- return new ResponseEntity<Object>(HttpStatus.NOT_IMPLEMENTED);
- }
-
- public ResponseEntity<List<InlineResponse200>> getStatus(Integer policyTypeId, String policyInstanceId) {
- log.info("getStatus - policyTypeId:" + policyTypeId);
- log.info("getStatus - policyInstanceId:" + policyInstanceId);
-
- if (policyTypeId == null || policyInstanceId == null) {
- log.info("getStatus - bad parameters");
- return new ResponseEntity<List<InlineResponse200>>(HttpStatus.NOT_FOUND);
- }
-
- String accept = request.getHeader("Accept");
- if (accept != null && accept.contains("application/json")) {
- try {
- PolicyType policyType = policyTypes.get(policyTypeId.toString());
- if (policyType == null) {
- log.info("getStatus - policytype does not exists");
- return new ResponseEntity<List<InlineResponse200>>(HttpStatus.NOT_FOUND);
- }
- PolicyInstance policyInstance = policyType.getInstance(policyInstanceId);
- if (policyInstance == null) {
- log.info("getStatus - policyinstance does not exists");
- return new ResponseEntity<List<InlineResponse200>>(HttpStatus.NOT_FOUND);
- }
-
- return new ResponseEntity<List<InlineResponse200>>(
- objectMapper.readValue("[ {\n \"handler_id\" : \"NearRTRIC-1\",\n \"status\" : \"enforced\"\n} ]",
- List.class),
- HttpStatus.OK);
- } catch (IOException e) {
- e.printStackTrace();
- log.info("getStatus - Couldn't serialize response for content type application/json");
- return new ResponseEntity<List<InlineResponse200>>(HttpStatus.INTERNAL_SERVER_ERROR);
- }
- }
-
- return new ResponseEntity<List<InlineResponse200>>(HttpStatus.NOT_IMPLEMENTED);
- }
-
-}
+++ /dev/null
-# ========================LICENSE_START=================================
-# %%
-# Copyright (C) 2019 Nordix Foundation
-# %%
-# 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===================================
-spring.security.user.name=admin
-spring.security.user.password=admin
-spring.jackson.property-naming-strategy=SNAKE_CASE
\ No newline at end of file
+++ /dev/null
-{ "scope": {"ue_id": "1","flow_id": "3"},
- "statement" : {"gfbr": "l", "mfbr": "2", "priority_level": "3", "pdb": "4"},
- "policy_id": "pi-XXXX"
-}
\ No newline at end of file
+++ /dev/null
-#!/bin/bash
-
-echo "Usage: populate.sh [<host:port>]"
-
-HOST_PORT="localhost:8080"
-
-if [ $# == 1 ]; then
- echo "Setting host and port from cmd line: "$1
- HOST_PORT=$1
-fi
-
-echo "======================================="
-echo "Using host and port:" $HOST_PORT
-echo "======================================="
-
-
-PT_MAX=10
-PI_MAX=20
-PI_ID=0
-pt=0
-while [ $pt -lt $PT_MAX ]; do
- pi=0
- PATTERN="s/XXXX/${pt}/g"
- sed $PATTERN pt-template.json > .tmp.json
- curl -v -X PUT --header 'Content-Type: application/json' --header 'Accept: */*' -d @.tmp.json 'http://'$HOST_PORT'/a1-p/policytypes/'$pt
- while [ $pi -lt $PI_MAX ]; do
- echo $pt"--"$pi"-"$PI_ID
-
- PATTERN="s/XXXX/${PI_ID}/g"
- sed $PATTERN pi-template.json > .tmp.json
- curl -v -X PUT --header 'Content-Type: application/json' --header 'Accept: */*' -d @.tmp.json 'http://'$HOST_PORT'/a1-p/policytypes/'$pt'/policies/'$PI_ID
- let pi=pi+1
- let PI_ID=PI_ID+1
- done
- let pt=pt+1
-done
-
-curl -v --header 'Accept: application/json' 'http://'$HOST_PORT'/a1-p/policytypes/'
-curl -v --header 'Accept: application/json' 'http://'$HOST_PORT'/a1-p/policytypes/1/policies'
+++ /dev/null
-{
- "description": "Policy type XXXX",
- "name": "PT XXXX",
- "policy_type_id": XXXX,
- "create_schema":
-
-
- {
- "$id": "https://est.tech/policy-type.schema.json",
- "$schema": "http://json-schema.org/draft-07/schema#",
- "title": "Policy type schema XXXX",
- "description": "Policy type schema for qos",
- "type": "object",
- "properties": {
- "policy_id": {
- "description": "Identity of the policy",
- "type": "string"},
- "scope": {
- "type": "object",
- "properties": {
- "ue_id": {
- "description": "User identity",
- "type": "string"},
- "flow_id": {
- "description": "Identity of the flow",
- "type": "string"}
- }, "required": ["ue_id", "flow_id"]
- },
- "statement": {
- "type": "object",
- "properties": {
- "gfbr": {
- "description": "Guaranteed Flow Bit Rate",
- "type": "string"},
- "mfbr": {
- "description": "Maximum Flow Bit Rate",
- "type": "string"},
- "priority_level": {
- "description": "Priority Level",
- "type": "string"},
- "pdb": {
- "description": "Packet Delay Budget",
- "type": "string"}
- }, "required": ["gfbr", "mfbr", "priority_level", "pdb"]
- }
- }, "required": ["policy_id", "scope", "statement"]
- }
-
-}
+++ /dev/null
-#!/bin/bash
-
-#Script for basic testing of the A1 simulator API
-#Note: policy is reset before test
-
-HOST_PORT="localhost:8080"
-
-echo "Usage: populate.sh [<host:port>]"
-
-HOST_PORT="localhost:8080"
-
-if [ $# == 1 ]; then
- echo "Setting host and port from cmd line: "$1
- HOST_PORT=$1
-fi
-
-echo "======================================="
-echo "Using host and port:" $HOST_PORT
-echo "======================================="
-
-echo "======================================="
-echo "Resetting db"
-curl 'http://'$HOST_PORT'/reset'
-echo "======================================="
-
-#Create a policy type
-create_pt() {
- PATTERN="s/XXXX/${1}/g"
- sed $PATTERN pt-template.json > .tmp.json
- res=$(curl -sw "%{http_code}" -X PUT --header 'Content-Type: application/json' --header 'Accept: */*' -d @.tmp.json 'http://'${HOST_PORT}'/a1-p/policytypes/'$1)
- http_code="${res:${#res}-3}"
- echo "Response code: " $http_code
-}
-
-get_pt() {
- res=$(curl -sw "%{http_code}" --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/'$1)
- http_code="${res:${#res}-3}"
- echo "Response code: " $http_code
- echo "Response: " ${res:0:${#res}-3}
-}
-
-get_pts() {
- res=$(curl -sw "%{http_code}" --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/')
- http_code="${res:${#res}-3}"
- echo "Response code: " $http_code
- echo "Response: " ${res:0:${#res}-3}
-}
-
-del_pt() {
- res=$(curl -sw "%{http_code}" -X DELETE --header 'Accept: */*' 'http://'${HOST_PORT}'/a1-p/policytypes/'$1)
- http_code="${res:${#res}-3}"
- echo "Response code: " $http_code
-}
-
-get_pis() {
- res=$(curl -sw "%{http_code}" --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies')
- http_code="${res:${#res}-3}"
- echo "Response code: " $http_code
- echo "Response: " ${res:0:${#res}-3}
-}
-
-create_pi() {
- PATTERN="s/XXXX/${2}/g"
- sed $PATTERN pi-template.json > .tmp.json
- res=$(curl -sw "%{http_code}" -X PUT --header 'Content-Type: application/json' --header 'Accept: */*' -d @.tmp.json 'http://'${HOST_PORT}'/a1-p/policytypes/'$1'/policies/'$2)
- http_code="${res:${#res}-3}"
- echo "Response code: " $http_code
-}
-
-get_pi() {
- res=$(curl -sw "%{http_code}" --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies/'$2)
- http_code="${res:${#res}-3}"
- echo "Response code: " $http_code
- echo "Response: " ${res:0:${#res}-3}
-}
-
-del_pi() {
- res=$(curl -sw "%{http_code}" -X DELETE --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies/'$2)
- http_code="${res:${#res}-3}"
- echo "Response code: " $http_code
-}
-
-stat_pi() {
- res=$(curl -sw "%{http_code}" --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies/'$2'/status')
- http_code="${res:${#res}-3}"
- echo "Response code: " $http_code
- echo "Response: " ${res:0:${#res}-3}
-}
-
-
-echo "== Create policy type 23"
-create_pt 23
-echo "== Get policy type 23"
-get_pt 23
-echo "== Create policy type 23 again"
-create_pt 23
-echo "== Create policy type 24"
-create_pt 24
-echo "== Get all policy types"
-get_pts
-echo "== Delete policy type 24"
-del_pt 24
-echo "== Delete policy type 24 again"
-del_pt 24
-echo "== Get all policy types"
-get_pts
-echo "== Get all policy instancess for type 23"
-get_pis 23
-echo "== Create policy instance 16 for type 23"
-create_pi 23 16
-echo "== Create policy instance 16 for type 23 again"
-create_pi 23 16
-echo "== Get policy instance 16 for type 23"
-get_pi 23 16
-echo "== Get missing policy instance 17 for type 23"
-get_pi 23 17
-echo "== Create policy instance 18 for type 23"
-create_pi 23 18
-echo "== Get all policy instances for type 23"
-get_pis 23
-echo "== Delete policy instance 18 for type 23"
-del_pi 23 18
-echo "== Get all policy instances for type 23"
-get_pis 23
-echo "== Get status for policy instance 16 for type 23"
-stat_pi 23 16
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2019 Nordix Foundation.
- ================================================================================
- 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.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.oran.nearric</groupId>
- <artifactId>nearric-simulator</artifactId>
- <version>1.0.1-SNAPSHOT</version>
- <packaging>pom</packaging>
- <name>${project.artifactId}</name>
-
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.1.9.RELEASE</version>
- <relativePath />
- </parent>
-
- <properties>
- <spring.boot.version>2.1.9.RELEASE</spring.boot.version>
- <java.version>11</java.version>
- <docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
- </properties>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-dependencies</artifactId>
- <version>${spring.boot.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <release>${java.version}</release>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
<modules>
<module>policy-agent</module>
<module>sdnc-a1-controller</module>
- <module>near-rt-ric-simulator</module>
</modules>
<build>
<plugins>
file=" --data-binary "$payload
fi
#urlencode the request url since it will be carried by send-request url
- requestUrl=$(python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "$2")
+ requestUrl=$(python -c "from __future__ import print_function; import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$2")
url=" "${ADAPTER}"/send-request?url="${requestUrl}"&operation="${oper}
curlString="curl -X POST${timeout}${httpcode}${content}${url}${file}"
echo " CMD: "$curlString >> $HTTPLOG