From 3bdae60a11a5f154500b4e7c5de4090326af1f98 Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Thu, 28 Nov 2019 10:58:54 +0100 Subject: [PATCH] Policy-agent skeleton Change-Id: I23ffaf459b2f5f2685ad81ad6726556491b8b3b7 Issue-ID: NONRTRIC-76 Signed-off-by: PatrikBuhr --- policy-agent/config/application.yaml | 19 ++ policy-agent/config/application_configuration.json | 6 + policy-agent/eclipse-formatter.xml | 315 +++++++++++++++++++++ policy-agent/pom.xml | 142 ++++++++++ .../java/org/oransc/policyagent/Application.java | 32 +++ .../configuration/ApplicationConfig.java | 111 ++++++++ .../configuration/ApplicationConfigLoader.java | 92 ++++++ .../configuration/ApplicationConfigParser.java | 58 ++++ .../policyagent/configuration/Environment.java | 98 +++++++ .../policyagent/controllers/PolicyController.java | 66 +++++ .../policyagent/exceptions/ServiceException.java | 33 +++ policy-agent/src/main/resources/keystore.jks | Bin 0 -> 2627 bytes .../org/oransc/policyagent/ApplicationTest.java | 49 ++++ 13 files changed, 1021 insertions(+) create mode 100644 policy-agent/config/application.yaml create mode 100644 policy-agent/config/application_configuration.json create mode 100644 policy-agent/eclipse-formatter.xml create mode 100644 policy-agent/pom.xml create mode 100644 policy-agent/src/main/java/org/oransc/policyagent/Application.java create mode 100644 policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java create mode 100644 policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigLoader.java create mode 100644 policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java create mode 100644 policy-agent/src/main/java/org/oransc/policyagent/configuration/Environment.java create mode 100644 policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java create mode 100644 policy-agent/src/main/java/org/oransc/policyagent/exceptions/ServiceException.java create mode 100644 policy-agent/src/main/resources/keystore.jks create mode 100644 policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java diff --git a/policy-agent/config/application.yaml b/policy-agent/config/application.yaml new file mode 100644 index 00000000..73f280a1 --- /dev/null +++ b/policy-agent/config/application.yaml @@ -0,0 +1,19 @@ +spring: + profiles: + active: prod +management: + endpoints: + web: + exposure: + include: "loggers,logfile,health,info,metrics" + +logging: + level: + ROOT: ERROR + org.springframework: ERROR + org.springframework.data: ERROR + org.springframework.web.reactive.function.client.ExchangeFunctions: ERROR + org.onap.dcaegen2.collectors.datafile: WARN + file: /var/log/ONAP/application.log +app: + filepath: /opt/app/policy-agent/config/application_configuration.json diff --git a/policy-agent/config/application_configuration.json b/policy-agent/config/application_configuration.json new file mode 100644 index 00000000..ccde671e --- /dev/null +++ b/policy-agent/config/application_configuration.json @@ -0,0 +1,6 @@ +{ + "config": { + "//description": "Application configuration", + "exampleProperty": "test" + } +} \ No newline at end of file diff --git a/policy-agent/eclipse-formatter.xml b/policy-agent/eclipse-formatter.xml new file mode 100644 index 00000000..7339434a --- /dev/null +++ b/policy-agent/eclipse-formatter.xml @@ -0,0 +1,315 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/policy-agent/pom.xml b/policy-agent/pom.xml new file mode 100644 index 00000000..c4992432 --- /dev/null +++ b/policy-agent/pom.xml @@ -0,0 +1,142 @@ + + + + + 4.0.0 + org.springframework + policy-agent + 0.0.0 + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + org.springframework.boot + spring-boot-starter-parent + 2.1.6.RELEASE + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.boot + spring-boot-devtools + true + + + org.springframework + spring-webflux + + + io.swagger.core.v3 + swagger-jaxrs2 + 2.0.0 + + + io.swagger.core.v3 + swagger-jaxrs2-servlet-initializer + 2.0.0 + + + org.immutables + value + ${immutable.version} + provided + + + org.immutables + gson + ${immutable.version} + + + + org.springframework.boot + spring-boot-starter-test + test + + + + io.springfox + springfox-swagger2 + ${springfox.version} + + + io.springfox + springfox-swagger-ui + ${springfox.version} + + + + 11 + 2.8.0 + 2.7.1 + + + + + org.springframework.boot + spring-boot-maven-plugin + + + net.revelc.code.formatter + formatter-maven-plugin + 2.8.1 + + ${project.basedir}/eclipse-formatter.xml + + + + + com.diffplug.spotless + spotless-maven-plugin + 1.18.0 + + + + + com,java,javax,org + + + + + + + + diff --git a/policy-agent/src/main/java/org/oransc/policyagent/Application.java b/policy-agent/src/main/java/org/oransc/policyagent/Application.java new file mode 100644 index 00000000..717a734e --- /dev/null +++ b/policy-agent/src/main/java/org/oransc/policyagent/Application.java @@ -0,0 +1,32 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * 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=================================== + */ +package org.oransc.policyagent; + +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/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java new file mode 100644 index 00000000..c7ab0ce5 --- /dev/null +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java @@ -0,0 +1,111 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * 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=================================== + */ + +package org.oransc.policyagent.configuration; + +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; +import com.google.gson.TypeAdapterFactory; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Properties; +import java.util.ServiceLoader; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +import org.oransc.policyagent.exceptions.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +@Component +@EnableConfigurationProperties +@ConfigurationProperties("app") +public class ApplicationConfig { + private static final Logger logger = LoggerFactory.getLogger(ApplicationConfig.class); + + @Value("#{systemEnvironment}") + Properties systemEnvironment; + + @NotEmpty + private String filepath; + + @Autowired + public ApplicationConfig() { + } + + public synchronized void setFilepath(String filepath) { + this.filepath = filepath; + } + + /** + * Reads the cloud configuration. + */ + public void initialize() { + loadConfigurationFromFile(); + } + + Mono getEnvironment(Properties systemEnvironment) { + return Environment.readEnvironmentVariables(systemEnvironment); + } + + /** + * Reads the configuration from file. + */ + void loadConfigurationFromFile() { + GsonBuilder gsonBuilder = new GsonBuilder(); + ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory); + + try (InputStream inputStream = createInputStream(filepath)) { + JsonParser parser = new JsonParser(); + JsonObject rootObject = getJsonElement(parser, inputStream).getAsJsonObject(); + if (rootObject == null) { + throw new JsonSyntaxException("Root is not a json object"); + } + ApplicationConfigParser appParser = new ApplicationConfigParser(); + appParser.parse(rootObject); + logger.info("Local configuration file loaded: {}", filepath); + } catch (JsonSyntaxException | ServiceException | IOException e) { + logger.trace("Local configuration file not loaded: {}", filepath, e); + } + } + + JsonElement getJsonElement(JsonParser parser, InputStream inputStream) { + return parser.parse(new InputStreamReader(inputStream)); + } + + InputStream createInputStream(@NotNull String filepath) throws IOException { + return new BufferedInputStream(new FileInputStream(filepath)); + } + +} diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigLoader.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigLoader.java new file mode 100644 index 00000000..f3d6d303 --- /dev/null +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigLoader.java @@ -0,0 +1,92 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * 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=================================== + */ + +package org.oransc.policyagent.configuration; + +import io.swagger.annotations.ApiOperation; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ScheduledFuture; + +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.TaskScheduler; +import org.springframework.scheduling.annotation.EnableScheduling; +import reactor.core.publisher.Mono; + +@Configuration +@EnableScheduling +public class ApplicationConfigLoader { + + private static final Logger logger = LoggerFactory.getLogger(ApplicationConfigLoader.class); + private static List> scheduledFutureList = new ArrayList<>(); + private static final Duration CONFIGURATION_REFRESH_INTERVAL = Duration.ofSeconds(15); + + private final TaskScheduler taskScheduler; + private final ApplicationConfig configuration; + + @Autowired + public ApplicationConfigLoader(TaskScheduler taskScheduler, ApplicationConfig configuration) { + this.taskScheduler = taskScheduler; + this.configuration = configuration; + } + + /** + * Function which have to stop tasks execution. + * + * @return response entity about status of cancellation operation + */ + @ApiOperation(value = "Get response on stopping task execution") + public synchronized Mono> getResponseFromCancellationOfTasks() { + scheduledFutureList.forEach(x -> x.cancel(false)); + scheduledFutureList.clear(); + logger.info("Stopped"); + return Mono.just(new ResponseEntity<>("Service has already been stopped!", HttpStatus.CREATED)); + } + + @PostConstruct + @ApiOperation(value = "Start task if possible") + public synchronized boolean start() { + logger.info("Start scheduling Datafile workflow"); + configuration.initialize(); + + if (scheduledFutureList.isEmpty()) { + scheduledFutureList + .add(taskScheduler.scheduleWithFixedDelay(this::refreshConfiguration, CONFIGURATION_REFRESH_INTERVAL)); + return true; + } else { + return false; + } + } + + private void refreshConfiguration() { + // TBD + + } + +} diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java new file mode 100644 index 00000000..487c3a99 --- /dev/null +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java @@ -0,0 +1,58 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * 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=================================== + */ + +package org.oransc.policyagent.configuration; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import org.oransc.policyagent.exceptions.ServiceException; + +public class ApplicationConfigParser { + + private static final String CONFIG = "config"; + + public ApplicationConfigParser() { + } + + String example; + + public void parse(JsonObject root) throws ServiceException { + JsonObject config = root.getAsJsonObject(CONFIG); + example = getAsString(config, "exampleProperty"); + } + + private static JsonElement get(JsonObject obj, String memberName) throws ServiceException { + JsonElement elem = obj.get(memberName); + if (elem == null) { + throw new ServiceException("Could not find member: " + memberName + " in: " + obj); + } + return elem; + } + + private static String getAsString(JsonObject obj, String memberName) throws ServiceException { + return get(obj, memberName).getAsString(); + } + + private static JsonObject getAsJson(JsonObject obj, String memberName) throws ServiceException { + return get(obj, memberName).getAsJsonObject(); + } + +} diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/Environment.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/Environment.java new file mode 100644 index 00000000..a6a328ec --- /dev/null +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/Environment.java @@ -0,0 +1,98 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * 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=================================== + */ + +package org.oransc.policyagent.configuration; + +import java.util.Optional; +import java.util.Properties; + +import org.oransc.policyagent.exceptions.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import reactor.core.publisher.Mono; + +class Environment { + + public static class Variables { + + public final String consulHost; + public final Integer consulPort; + public final String cbsName; + public final String appName; + + public Variables(String consulHost, Integer consulPort, String cbsName, String appName) { + this.consulHost = consulHost; + this.consulPort = consulPort; + this.cbsName = cbsName; + this.appName = appName; + } + } + + private static final int DEFAULT_CONSUL_PORT = 8500; + private static final Logger logger = LoggerFactory.getLogger(Environment.class); + + private Environment() { + } + + static Mono readEnvironmentVariables(Properties systemEnvironment) { + logger.trace("Loading system environment variables"); + + try { + Variables envProperties = new Variables(getConsulHost(systemEnvironment) // + , getConsultPort(systemEnvironment) // + , getConfigBindingService(systemEnvironment) // + , getService(systemEnvironment)); // + + logger.trace("Evaluated environment system variables {}", envProperties); + return Mono.just(envProperties); + } catch (ServiceException e) { + return Mono.error(e); + } + } + + private static String getConsulHost(Properties systemEnvironments) throws ServiceException { + return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_HOST")) + .orElseThrow(() -> new ServiceException("$CONSUL_HOST environment has not been defined")); + } + + private static Integer getConsultPort(Properties systemEnvironments) { + return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_PORT")) // + .map(Integer::valueOf) // + .orElseGet(Environment::getDefaultPortOfConsul); + } + + private static String getConfigBindingService(Properties systemEnvironments) throws ServiceException { + return Optional.ofNullable(systemEnvironments.getProperty("CONFIG_BINDING_SERVICE")) // + .orElseThrow(() -> new ServiceException("$CONFIG_BINDING_SERVICE environment has not been defined")); + } + + private static String getService(Properties systemEnvironments) throws ServiceException { + return Optional + .ofNullable(Optional.ofNullable(systemEnvironments.getProperty("HOSTNAME")) + .orElse(systemEnvironments.getProperty("SERVICE_NAME"))) + .orElseThrow(() -> new ServiceException( + "Neither $HOSTNAME/$SERVICE_NAME have not been defined as system environment")); + } + + private static Integer getDefaultPortOfConsul() { + logger.warn("$CONSUL_PORT variable will be set to default port {}", DEFAULT_CONSUL_PORT); + return DEFAULT_CONSUL_PORT; + } +} diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java new file mode 100644 index 00000000..ebe833b9 --- /dev/null +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java @@ -0,0 +1,66 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * 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=================================== + */ +package org.oransc.policyagent.controllers; + +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +import java.net.http.HttpHeaders; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +@RestController +public class PolicyController { + + // http://localhost:8080/policy?type=type3&instance=xxx + @GetMapping("/policy") + public String getPolicy(@RequestParam(name = "type", required = false, defaultValue = "type1") String typeName, + @RequestParam(name = "instance", required = false, defaultValue = "new") String instanceId) { + System.out.println("**** getPolicy " + typeName); + + return "policy" + typeName + instanceId; + } + + public String getHello() { + return "Howdy"; + } + + @GetMapping("/status") + @ApiOperation(value = "Returns status and statistics of DATAFILE service") + @ApiResponses( + value = { // + @ApiResponse(code = 200, message = "DATAFILE service is living"), + @ApiResponse(code = 401, message = "You are not authorized to view the resource"), + @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"), + @ApiResponse(code = 404, message = "The resource you were trying to reach is not found") // + }) + public Mono> getStatus(@RequestHeader HttpHeaders headers) { + Mono> response = Mono.just(new ResponseEntity<>("hunky dory", HttpStatus.OK)); + return response; + } + +} diff --git a/policy-agent/src/main/java/org/oransc/policyagent/exceptions/ServiceException.java b/policy-agent/src/main/java/org/oransc/policyagent/exceptions/ServiceException.java new file mode 100644 index 00000000..c3443ede --- /dev/null +++ b/policy-agent/src/main/java/org/oransc/policyagent/exceptions/ServiceException.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START====================================================================== + * Copyright (C) 2019 Nordix Foundation. 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.oransc.policyagent.exceptions; + +public class ServiceException extends Exception { + + private static final long serialVersionUID = 1L; + + public ServiceException(String message) { + super(message); + } + + public ServiceException(String message, Exception originalException) { + super(message, originalException); + } + +} diff --git a/policy-agent/src/main/resources/keystore.jks b/policy-agent/src/main/resources/keystore.jks new file mode 100644 index 0000000000000000000000000000000000000000..574a585b9b53e52cd97821d3e2f02e184939767f GIT binary patch literal 2627 zcmY+Ec{~%0AICRlHfJ{XG567OY~)&`Iiq-J$dQ<1Ow3hovP~n$a+WJ3N3In0B#B(f z^%5mVjwaMna^#l%JipiP_dKuXkMHaI`F_6N&-c$aio#{Y24qK3pgUkFl6IE1%?soN zmQtWh5Cyt;WHV3{j<|oVI7lE0hyRgHI4Vyt_y1BnTtK!`3TPii0d1p>gSq~1A3c`< z3GyT4xK-V&T1{Tc+Z-P-FVA!Q7{$g8=&}V-KyREn3@h%P;L9lFCo|&fZn{6qA4V|! zM6|DqXqt`Ba6Ohx%N%WJvY5@}78a`qnZG8#@z_%I#yCiw-%f(Xj5Ub46eu)qPe1yx z4CiW?81jp}DYl>Jh2urqR3|&+UrJO~NY`Ly7gV)DuX3l%w|H`U?wPZ2Yx^>RwWhIM z{bdu*uZl_OjvbDP3%arf9!5bUo(I)AEdil@|MR@~}QGZF7joacjuT9~W zL@mYDFM=hL=jgR-Tox?WnWCEONGSAJGq2U6!uMi-K+l7yT{C6+uc~+&%Z!@Q4 z;B!18F7qR*Uuh2zAVFgQWaH6_gQ?Fc?qvfvfbve8yNGLe}7W5dBSCP{(^OBAFMq{UB0LP1UuV=?r}ns zBMT=4+^9~^51IlOE#Ad5Uh!tsZzjwhG^^&m=1SXMeK;kfyP5u4+^hp%x-z^l3alK& zvS+gIzwjepuS+vs{(ioVAxQ;0-%D1*^^6!SLXI6I)8&CUO?oB?8X1Z?( z@g8g5JBfi0*zWlTOLvs{xP}XUo7c7G&Y7QcF@q0lc9&i=9g`zR2n?D>e~4^{n&Wyf z&tnj}y5O-7#0yIox1R>kKpYvy<1zofGeTh*kbGjq1|Yg5tCJEely&fXP2 zpSXey!NlCzy9uuYJaZ%lK?X<^_;{JD>0*ziXwxEUl-@bGP%ZA zewSO=o+UyDt8QKHb4A6+08@DbC#8jToCJdAhU_b6RBP|KW90xDD4#M7Oo-LFKw?_< zY)rDROtRLhdgic>njZ!ip~u3lAB^v(vA%c}lv*+bzV)~yuLvl6>j?q8R8no*qj%hA zRh^twV;kSQRavSe)KxDk5=mD^+)RLN8a3dj-=T;CwXB>o&L@ganuPl7@U5mEI;Bgt z)o6MrH9Uz7Est>U@y7S*huaTKO$!rY5l)P_me~m)`W_=jvyW2FVqBH+T{ir@I@KKg z(=`{W#Gl`CC?0K!AH;C#H>PXRiy`?X^7hC&1Sq$^xWd{PZT)j}b!e%D`GL8lKG_z! z29fD~`y5H%R*=LVfM?sm!E}4OV4jPLCPq^ezDbyviI@s zCEI85zj%3o0xtihZUO}aiCcc;o2Ws$AN(xbQyEr=*RtKP$HvsfJ3VTkqAqIP@NbE` z2bC^Qrfdmscq}4i`tc5lMc8}^`_T>N!}QLJfz3V9ds$R^?1+1|WMJs}0Yf;RP?l8x z10=bvZHPei#jS70x1Ys>R@i1)7>c#BUaAt2XL0L z38{N3w1^V_tP6slO`>tcKG$b6aX;6?CobCibhqG^-NkKJ@$TZe{%H)0WGlt0Dt0u* zZQSPYlU9Qk+KPyYLXA^Tr)C_ZnlIxB-|8mM@5*O0SBQn@MfCWE3pw5f#>6PssHv0; z@w|fL$MsSxkUQnYx#ryAKjMi)qig9~H_>XP|000`6;dKT=ifaP=vK z4;!M^cFuOC3uTc@)U{)N5W9ugd{;VwDZmS>;?cpsdT9A>W#+(9!3@8Z=^d&>Pax2! z5ohpkLaVwYq^f@_>@j`=I>J&U5{*MTb(Yk=82do#TYYMY=VYw8q~Q{_j2OL4qe)9U z5IK_P7$fhZwVLd1_b1nK&PFkl%BusiaBa1Ko3dAKA`lgE?FpdUH}GT8Oi*$`*vnQ? zr|XAuZ=lmXPZ^C=h4=T@9l}nNiey|I!RJ!1vp1#48)X*#T%(>5QOMo04z8?;xnUv& zYVb6~G@t%dLdFWr6qR^CB}^@D&#{ z!((I80(BZCi-LkVPVlj_iE{uzf-TuZ@jv$UJOM73D4!2%l3g9jgF%AaBhr6f^NQKO VdwV{6&{+5+r}5$%8#|Cz`X6mWrDXsB literal 0 HcmV?d00001 diff --git a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java new file mode 100644 index 00000000..32d7fe64 --- /dev/null +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@ -0,0 +1,49 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * 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=================================== + */ +package org.oransc.policyagent; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +public class ApplicationTest { + + @LocalServerPort + private int port; + + private RestTemplate restTemplate = new RestTemplate(); + + @Test + public void getPolicy() throws Exception { + String cmd = "/policy?type=type3&instance=xxx"; + String rsp = this.restTemplate.getForObject("http://localhost:" + port + cmd, String.class); + System.out.println("*** rsp " + rsp); + assertThat(rsp).contains("type3"); + } + +} -- 2.16.6