<?xml version="1.0" encoding="UTF-8"?>
-<!-- * ========================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=================================== -->
+<!--
+* ========================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===================================
+-->
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
- <version>2.1.6.RELEASE</version>
+ <version>2.2.4.RELEASE</version>
<relativePath />
</parent>
<groupId>org.o-ran-sc.nonrtric</groupId>
import java.util.Vector;
import javax.validation.constraints.NotNull;
-
+import lombok.Getter;
import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
import org.oransc.policyagent.exceptions.ServiceException;
import org.springframework.http.MediaType;
.serializeNulls() //
.create(); //
- private Vector<RicConfig> ricConfig;
+ @Getter
+ private Vector<RicConfig> ricConfigs;
+ @Getter
private Properties dmaapPublisherConfig;
+ @Getter
private Properties dmaapConsumerConfig;
- public ApplicationConfigParser() {
- }
-
public void parse(JsonObject root) throws ServiceException {
- JsonObject ricConfigJson = root.getAsJsonObject(CONFIG);
- ricConfig = parseRics(ricConfigJson);
- JsonObject dmaapPublisherConfigJson = root.getAsJsonObject("streams_publishes");
+ JsonObject agentConfigJson = root.getAsJsonObject(CONFIG);
+ ricConfigs = parseRics(agentConfigJson);
+ JsonObject dmaapPublisherConfigJson = agentConfigJson.getAsJsonObject("streams_publishes");
if (dmaapPublisherConfigJson == null) {
dmaapPublisherConfig = new Properties();
} else {
dmaapPublisherConfig = parseDmaapConfig(dmaapPublisherConfigJson);
}
- JsonObject dmaapConsumerConfigJson = root.getAsJsonObject("streams_subscribes");
+ JsonObject dmaapConsumerConfigJson = agentConfigJson.getAsJsonObject("streams_subscribes");
if (dmaapConsumerConfigJson == null) {
dmaapConsumerConfig = new Properties();
} else {
}
}
- public Vector<RicConfig> getRicConfigs() {
- return this.ricConfig;
- }
-
- public Properties getDmaapPublisherConfig() {
- return dmaapPublisherConfig;
- }
-
- public Properties getDmaapConsumerConfig() {
- return dmaapConsumerConfig;
- }
-
private Vector<RicConfig> parseRics(JsonObject config) throws ServiceException {
Vector<RicConfig> result = new Vector<RicConfig>();
for (JsonElement ricElem : getAsJsonArray(config, "ric")) {
public Mono<ResponseEntity<Void>> deletePolicy( //
@RequestParam(name = "instance", required = true) String id) {
Policy policy = policies.get(id);
- if (policy != null && policy.ric().getState() == (Ric.RicState.IDLE)) {
+ if (policy != null && policy.ric().getState() == Ric.RicState.IDLE) {
policies.remove(policy);
return a1ClientFactory.createA1Client(policy.ric()) //
.flatMap(client -> client.deletePolicy(policy)) //
Ric ric = rics.get(ricName);
PolicyType type = policyTypes.get(typeName);
- if (ric != null && type != null && ric.getState() == (Ric.RicState.IDLE)) {
+ if (ric != null && type != null && ric.getState() == Ric.RicState.IDLE) {
Policy policy = ImmutablePolicy.builder() //
.id(instanceId) //
.json(jsonBody) //
ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
try (InputStream inputStream = createInputStream(filepath)) {
- JsonParser parser = new JsonParser();
- JsonObject rootObject = getJsonElement(parser, inputStream).getAsJsonObject();
+ JsonObject rootObject = getJsonElement(inputStream).getAsJsonObject();
if (rootObject == null) {
throw new JsonSyntaxException("Root is not a json object");
}
}
}
- JsonElement getJsonElement(JsonParser parser, InputStream inputStream) {
- return parser.parse(new InputStreamReader(inputStream));
+ JsonElement getJsonElement(InputStream inputStream) {
+ return JsonParser.parseReader(new InputStreamReader(inputStream));
}
InputStream createInputStream(@NotNull String filepath) throws IOException {
import reactor.core.publisher.Mono;
/**
- * Recovery handling of RIC, which means:
+ * Recovery handling of RIC.
+ * This means:
* - load all policy types
* - send all policy instances to the RIC
* --- if that fails remove all policy instances
logger.debug("Handling ric: {}", ric.getConfig().name());
synchronized (ric) {
- if (ric.getState() == (Ric.RicState.RECOVERING)) {
+ if (ric.getState() == Ric.RicState.RECOVERING) {
return; // Already running
}
ric.setState(Ric.RicState.RECOVERING);
@Test
public void testRecovery() throws Exception {
reset();
- Policy policy = addPolicy("policyId", "typeName", "service", "ric"); // This should be created in the RIC
Policy policy2 = addPolicy("policyId2", "typeName", "service", "ric");
getA1Client("ric").putPolicy(policy2); // put it in the RIC
policies.remove(policy2); // Remove it from the repo -> should be deleted in the RIC
+ Policy policy = addPolicy("policyId", "typeName", "service", "ric"); // This should be created in the RIC
supervision.checkAllRics(); // The created policy should be put in the RIC
Policies ricPolicies = getA1Client("ric").getPolicies();
assertThat(ricPolicies.size()).isEqualTo(1);
private static <T> List<T> parseList(String jsonString, Class<T> clazz) {
List<T> result = new ArrayList<>();
- JsonArray jsonArr = new JsonParser().parse(jsonString).getAsJsonArray();
+ JsonArray jsonArr = JsonParser.parseString(jsonString).getAsJsonArray();
for (JsonElement jsonElement : jsonArr) {
T o = gson.fromJson(jsonElement.toString(), clazz);
result.add(o);
}
private static List<String> parseSchemas(String jsonString) {
- JsonArray arrayOfSchema = new JsonParser().parse(jsonString).getAsJsonArray();
+ JsonArray arrayOfSchema = JsonParser.parseString(jsonString).getAsJsonArray();
List<String> result = new ArrayList<>();
for (JsonElement schemaObject : arrayOfSchema) {
result.add(schemaObject.toString());
}
/**
- * overrides the BeanFactory
+ * Overrides the BeanFactory.
*/
@TestConfiguration
static class TestBeanFactory {
}
private static String title(String jsonSchema) {
- JsonObject parsedSchema = (JsonObject) new JsonParser().parse(jsonSchema);
+ JsonObject parsedSchema = (JsonObject) JsonParser.parseString(jsonSchema);
String title = parsedSchema.get("title").getAsString();
return title;
}
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.oransc.policyagent.configuration.ImmutableRicConfig;
import org.oransc.policyagent.configuration.RicConfig;
import reactor.test.StepVerifier;
@ExtendWith(MockitoExtension.class)
-@RunWith(MockitoJUnitRunner.class)
public class StdA1ClientTest {
private static final String RIC_URL = "RicUrl";
private static final String POLICYTYPES_IDENTITIES_URL = "/policytypes";
--- /dev/null
+/*-
+ * ========================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 static org.junit.jupiter.api.Assertions.assertAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import com.google.gson.JsonIOException;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
+import org.junit.jupiter.api.Test;
+import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
+import org.springframework.http.MediaType;
+
+public class ApplicationConfigParserTest {
+
+ @Test
+ public void whenCorrectDmaapConfig() throws Exception {
+ JsonObject jsonRootObject = getJsonRootObject();
+
+ ApplicationConfigParser parserUnderTest = new ApplicationConfigParser();
+
+ parserUnderTest.parse(jsonRootObject);
+
+ Properties actualPublisherConfig = parserUnderTest.getDmaapPublisherConfig();
+ assertAll("publisherConfig",
+ () -> assertEquals("localhost:6845/events", actualPublisherConfig.get("ServiceName")),
+ () -> assertEquals("A1-POLICY-AGENT-WRITE", actualPublisherConfig.get("topic")),
+ () -> assertEquals("localhost:6845", actualPublisherConfig.get("host")),
+ () -> assertEquals(MediaType.APPLICATION_JSON.toString(), actualPublisherConfig.get("contenttype")),
+ () -> assertEquals("admin", actualPublisherConfig.get("userName")),
+ () -> assertEquals("admin", actualPublisherConfig.get("password")),
+ () -> assertEquals(ProtocolTypeConstants.HTTPNOAUTH.toString(), actualPublisherConfig.get("TransportType")),
+ () -> assertEquals(15000, actualPublisherConfig.get("timeout")),
+ () -> assertEquals(1000, actualPublisherConfig.get("limit")));
+
+ Properties actualConsumerConfig = parserUnderTest.getDmaapConsumerConfig();
+ assertAll("consumerConfig",
+ () -> assertEquals("localhost:6845/events", actualConsumerConfig.get("ServiceName")),
+ () -> assertEquals("A1-POLICY-AGENT-READ", actualConsumerConfig.get("topic")),
+ () -> assertEquals("localhost:6845", actualConsumerConfig.get("host")),
+ () -> assertEquals(MediaType.APPLICATION_JSON.toString(), actualConsumerConfig.get("contenttype")),
+ () -> assertEquals("admin", actualConsumerConfig.get("userName")),
+ () -> assertEquals("admin", actualConsumerConfig.get("password")),
+ () -> assertEquals("users", actualConsumerConfig.get("group")),
+ () -> assertEquals("policy-agent", actualConsumerConfig.get("id")),
+ () -> assertEquals(ProtocolTypeConstants.HTTPNOAUTH.toString(), actualConsumerConfig.get("TransportType")),
+ () -> assertEquals(15000, actualConsumerConfig.get("timeout")),
+ () -> assertEquals(1000, actualConsumerConfig.get("limit")));
+ }
+
+ private JsonObject getJsonRootObject() throws JsonIOException, JsonSyntaxException, IOException {
+ JsonObject rootObject = JsonParser.parseReader(new InputStreamReader(getCorrectJson())).getAsJsonObject();
+ return rootObject;
+ }
+
+ private static InputStream getCorrectJson() throws IOException {
+ URL url = ApplicationConfigParser.class.getClassLoader()
+ .getResource("test_application_configuration_with_dmaap_config.json");
+ String string = Resources.toString(url, Charsets.UTF_8);
+ return new ByteArrayInputStream((string.getBytes(StandardCharsets.UTF_8)));
+ }
+
+}
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
-import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
import reactor.test.StepVerifier;
@ExtendWith(MockitoExtension.class)
-@RunWith(MockitoJUnitRunner.class)
public class RefreshConfigTaskTest {
private RefreshConfigTask refreshTaskUnderTest;
}
private JsonObject getJsonRootObject() throws JsonIOException, JsonSyntaxException, IOException {
- JsonObject rootObject = (new JsonParser()).parse(new InputStreamReader(getCorrectJson())).getAsJsonObject();
+ JsonObject rootObject = JsonParser.parseReader(new InputStreamReader(getCorrectJson())).getAsJsonObject();
return rootObject;
}
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.oransc.policyagent.clients.A1Client;
import org.oransc.policyagent.clients.A1ClientFactory;
import reactor.core.publisher.Mono;
@ExtendWith(MockitoExtension.class)
-@RunWith(MockitoJUnitRunner.class)
public class RepositorySupervisionTest {
@Mock
A1Client a1ClientMock;
PolicyTypes types = new PolicyTypes();
Services services = new Services();
- RepositorySupervision supervisorUnderTest =
- new RepositorySupervision(rics, policies, a1ClientFactory, types, services);
-
Mono<List<String>> policyIds = Mono.just(Arrays.asList("policyId1", "policyId2"));
doReturn(policyIds).when(a1ClientMock).getPolicyTypeIdentities();
doReturn(Mono.just("OK")).when(a1ClientMock).putPolicy(any());
doReturn(Flux.empty()).when(a1ClientMock).deleteAllPolicies();
+ RepositorySupervision supervisorUnderTest =
+ new RepositorySupervision(rics, policies, a1ClientFactory, types, services);
+
supervisorUnderTest.checkAllRics();
await().untilAsserted(() -> RicState.IDLE.equals(ric1.getState()));
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.oransc.policyagent.clients.A1Client;
import org.oransc.policyagent.clients.A1ClientFactory;
import reactor.core.publisher.Mono;
@ExtendWith(MockitoExtension.class)
-@RunWith(MockitoJUnitRunner.class)
public class StartupServiceTest {
private static final String FIRST_RIC_NAME = "first";
private static final String FIRST_RIC_URL = "firstUrl";
private static final String POLICY_TYPE_1_NAME = "type1";
private static final String POLICY_TYPE_2_NAME = "type2";
- private static final String POLICY_ID_1 = "policy1";
- private static final String POLICY_ID_2 = "policy2";
ApplicationConfig appConfigMock;
RefreshConfigTask refreshTaskMock;
{
- "config": {
- "//description": "Application configuration",
- "ric": [
+ "config":{
+ "ric":[
{
- "name": "ric1",
- "baseUrl": "http://localhost:8080/",
- "managedElementIds": [
+ "name":"ric1",
+ "baseUrl":"http://localhost:8083/",
+ "managedElementIds":[
"kista_1",
"kista_2"
]
},
{
- "name": "ric2",
- "baseUrl": "http://localhost:8081/",
- "managedElementIds": [
+ "name":"ric2",
+ "baseUrl":"http://localhost:8085/",
+ "managedElementIds":[
"kista_3",
"kista_4"
]
}
- ]
- },
- "streams_publishes": {
- "dmaap_publisher": {
- "type": "message_router",
- "dmaap_info": {
- "topic_url": "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-WRITE"
+ ],
+ "streams_publishes":{
+ "dmaap_publisher":{
+ "type":"message_router",
+ "dmaap_info":{
+ "topic_url":"http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-WRITE"
+ }
+ }
+ },
+ "streams_subscribes":{
+ "dmaap_subscriber":{
+ "type":"message_router",
+ "dmaap_info":{
+ "topic_url":"http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-READ/users/policy-agent"
+ }
}
- }
- },
- "streams_subscribes": {
- "dmaap_subscriber": {
- "dmaap_info": {
- "topic_url": "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-READ/users/policy-agent"
- },
- "type": "message_router"
}
}
}
\ No newline at end of file