{
- "config": {
- "//description": "Application configuration",
- "exampleProperty": "test"
- }
+ "config": {
+ "//description": "Application configuration",
+ "ric": [
+ {
+ "name": "ric1",
+ "baseUrl": "http://localhost:8080/",
+ "managedElementIds": [
+ "kista_1",
+ "kista_2"
+ ]
+ }
+ ]
+ }
}
\ No newline at end of file
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.Optional;
import java.util.Properties;
import java.util.ServiceLoader;
+import java.util.Vector;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@NotEmpty
private String filepath;
+ private Vector<RicConfig> ricConfigs;
+
@Autowired
public ApplicationConfig() {
}
this.filepath = filepath;
}
- /**
- * Reads the cloud configuration.
- */
+ public Vector<RicConfig> getRicConfigs() {
+ return this.ricConfigs;
+ }
+
+ public Optional<RicConfig> getRicConfig(String managedElementId) {
+ for (RicConfig ricConfig : getRicConfigs()) {
+ if (ricConfig.managedElementIds().contains(managedElementId)) {
+ return Optional.of(ricConfig);
+
+ }
+ }
+ return Optional.empty();
+ }
+
public void initialize() {
loadConfigurationFromFile();
}
}
ApplicationConfigParser appParser = new ApplicationConfigParser();
appParser.parse(rootObject);
+ this.ricConfigs = appParser.getRicConfigs();
logger.info("Local configuration file loaded: {}", filepath);
} catch (JsonSyntaxException | ServiceException | IOException e) {
logger.trace("Local configuration file not loaded: {}", filepath, e);
@Configuration
@EnableScheduling
-public class ApplicationConfigLoader {
+class ApplicationConfigLoader {
private static final Logger logger = LoggerFactory.getLogger(ApplicationConfigLoader.class);
private static List<ScheduledFuture<?>> scheduledFutureList = new ArrayList<>();
package org.oransc.policyagent.configuration;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import java.util.Vector;
+
import org.oransc.policyagent.exceptions.ServiceException;
-public class ApplicationConfigParser {
+class ApplicationConfigParser {
private static final String CONFIG = "config";
+ private static Gson gson = new GsonBuilder() //
+ .serializeNulls() //
+ .create(); //
+
+ private Vector<RicConfig> ricConfig;
public ApplicationConfigParser() {
}
- String example;
-
public void parse(JsonObject root) throws ServiceException {
JsonObject config = root.getAsJsonObject(CONFIG);
- example = getAsString(config, "exampleProperty");
+ ricConfig = parseRics(config);
+ }
+
+ public Vector<RicConfig> getRicConfigs() {
+ return this.ricConfig;
+ }
+
+ private Vector<RicConfig> parseRics(JsonObject config) throws ServiceException {
+ Vector<RicConfig> result = new Vector<RicConfig>();
+ for (JsonElement ricElem : getAsJsonArray(config, "ric")) {
+ result.add(gson.fromJson(ricElem.getAsJsonObject(), ImmutableRicConfig.class));
+ }
+ return result;
}
private static JsonElement get(JsonObject obj, String memberName) throws ServiceException {
return get(obj, memberName).getAsJsonObject();
}
+ private JsonArray getAsJsonArray(JsonObject obj, String memberName) throws ServiceException {
+ return get(obj, memberName).getAsJsonArray();
+ }
+
}
--- /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 java.util.Vector;
+
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
+
+@Value.Immutable
+@Gson.TypeAdapters
+public interface RicConfig {
+ public String name();
+
+ public String baseUrl();
+
+ public Vector<String> managedElementIds();
+}
*/
package org.oransc.policyagent.controllers;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-import java.net.http.HttpHeaders;
+import java.util.Vector;
+import org.oransc.policyagent.configuration.ApplicationConfig;
+import org.oransc.policyagent.configuration.RicConfig;
+import org.springframework.beans.factory.annotation.Autowired;
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 {
+ private final ApplicationConfig appConfig;
+ private static Gson gson = new GsonBuilder() //
+ .serializeNulls() //
+ .create(); //
+
+ @Autowired
+ PolicyController(ApplicationConfig config) {
+ this.appConfig = config;
+ }
+
// http://localhost:8080/policy?type=type3&instance=xxx
@GetMapping("/policy")
public String getPolicy(@RequestParam(name = "type", required = false, defaultValue = "type1") String typeName,
}
@GetMapping("/status")
- @ApiOperation(value = "Returns status and statistics of DATAFILE service")
+ @ApiOperation(value = "Returns status and statistics of the service")
@ApiResponses(
value = { //
@ApiResponse(code = 200, message = "DATAFILE service is living"),
@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<ResponseEntity<String>> getStatus(@RequestHeader HttpHeaders headers) {
+ public Mono<ResponseEntity<String>> getStatus() {
Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>("hunky dory", HttpStatus.OK));
return response;
}
+ // http://localhost:8080/rics?managedElementId=kista_1
+ @GetMapping("/rics")
+ @ApiOperation(value = "Returns defined NearRT RIC:s")
+ public ResponseEntity<String> getRics(
+ @RequestParam(name = "managedElementId", required = false, defaultValue = "") String managedElementId) {
+ Vector<RicInfo> result = new Vector<RicInfo>();
+ Vector<RicConfig> config = getRicConfigs(managedElementId);
+
+ for (RicConfig ricConfig : config) {
+ RicInfo ric = ImmutableRicInfo.builder() //
+ .managedElementIds(ricConfig.managedElementIds()) //
+ .name(ricConfig.name()) //
+ .build();
+ result.add(ric);
+ }
+
+ return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);
+ }
+
+ private Vector<RicConfig> getRicConfigs(String managedElementId) {
+ if (managedElementId.equals("")) {
+ return this.appConfig.getRicConfigs();
+ }
+
+ Vector<RicConfig> result = new Vector<RicConfig>(1);
+ appConfig.getRicConfig(managedElementId).ifPresent((config) -> {
+ result.add(config);
+ });
+ return result;
+ }
+
}
--- /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.controllers;
+
+import java.util.Vector;
+
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
+
+@Value.Immutable
+@Gson.TypeAdapters
+public interface RicInfo {
+ public String name();
+
+ public Vector<String> managedElementIds();
+}
--- /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.repository;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.oransc.policyagent.configuration.RicConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class Policies {
+ private static final Logger logger = LoggerFactory.getLogger(Policies.class);
+
+ private Map<String, Policy> policies = new HashMap<String, Policy>();
+
+ @Autowired
+ public Policies() {
+ }
+
+ public synchronized void put(String id, Policy policy) {
+ policies.put(id, policy);
+ }
+
+}
--- /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.repository;
+
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
+import org.oransc.policyagent.configuration.RicConfig;
+
+@Value.Immutable
+@Gson.TypeAdapters
+public interface Policy {
+ public String id();
+
+ public String json();
+
+ public String ownerServiceName();
+
+ public RicConfig ric();
+
+ public PolicyType type();
+}
--- /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.repository;
+
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
+
+@Value.Immutable
+@Gson.TypeAdapters
+public interface PolicyType {
+ public String name();
+
+ public String jsonSchema();
+
+}
--- /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.repository;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.oransc.policyagent.exceptions.ServiceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class PolicyTypes {
+ private static final Logger logger = LoggerFactory.getLogger(PolicyTypes.class);
+
+ private Map<String, PolicyType> types = new HashMap<String, PolicyType>();
+
+ @Autowired
+ public PolicyTypes() {
+ }
+
+ public synchronized PolicyType getType(String name) throws ServiceException {
+ PolicyType t = types.get(name);
+ if (t == null) {
+ throw new ServiceException("Could not find type: " + name);
+ }
+ return t;
+ }
+
+ public synchronized void putType(String name, PolicyType type) {
+ types.put(name, type);
+ }
+
+}
assertThat(rsp).contains("type3");
}
+ @Test
+ public void getRics() throws Exception {
+ String cmd = "/rics";
+ String rsp = this.restTemplate.getForObject("http://localhost:" + port + cmd, String.class);
+ System.out.println("*** rsp " + rsp);
+ assertThat(rsp).contains("kista_1");
+ }
+
}