From: John Keeney Date: Fri, 20 Mar 2020 08:46:52 +0000 (+0000) Subject: Merge "Renamed things to fit with namechange of RicSynchronizationTask" X-Git-Tag: 2.0.0~109 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=96805287db06a91e569c184cc34ba4e69e4d22b2;hp=-c;p=nonrtric.git Merge "Renamed things to fit with namechange of RicSynchronizationTask" --- 96805287db06a91e569c184cc34ba4e69e4d22b2 diff --combined policy-agent/docs/api.yaml index 1696dad9,bd1ba686..3dd78621 --- a/policy-agent/docs/api.yaml +++ b/policy-agent/docs/api.yaml @@@ -484,46 -484,6 +484,46 @@@ paths schema: type: string deprecated: false + /policy_ids: + get: + tags: + - A1 Policy Management + summary: 'Query policies, only IDs returned' + operationId: getPolicyIdsUsingGET + produces: + - '*/*' + parameters: + - name: ric + in: query + description: ric + required: false + type: string + - name: service + in: query + description: service + required: false + type: string + - name: type + in: query + description: type + required: false + type: string + responses: + '200': + description: Policy ids + schema: + type: array + items: + type: string + '401': + description: Unauthorized + '403': + description: Forbidden + '404': + description: RIC or type not found + schema: + type: string + deprecated: false /policy_schema: get: tags: @@@ -910,7 -870,7 +910,7 @@@ definitions properties: callbackUrl: type: string - description: callback for notifying of RIC recovery + description: callback for notifying of RIC synchronization keepAliveIntervalSeconds: type: integer format: int64 @@@ -924,7 -884,7 +924,7 @@@ properties: callbackUrl: type: string - description: callback for notifying of RIC recovery + description: callback for notifying of RIC synchronization keepAliveIntervalSeconds: type: integer format: int64 @@@ -937,4 -897,3 +937,3 @@@ format: int64 description: time since last invocation by the service title: ServiceStatus - diff --combined policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java index 22dba54a,0efec60a..0be4b31b --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java @@@ -66,8 -66,10 +66,8 @@@ public class A1ClientFactory } A1Client createClient(Ric ric, A1ProtocolType version) { - if (version == A1ProtocolType.STD_V1) { + if (version == A1ProtocolType.STD_V1_1) { return new StdA1ClientVersion1(ric.getConfig()); - } else if (version == A1ProtocolType.STD_V1_1) { - return new StdA1ClientVersion2(ric.getConfig()); } else if (version == A1ProtocolType.OSC_V1) { return new OscA1Client(ric.getConfig()); } else if (version == A1ProtocolType.SDNC_OSC) { @@@ -89,12 -91,13 +89,12 @@@ private Mono getProtocolVersion(Ric ric) { if (ric.getProtocolVersion() == A1ProtocolType.UNKNOWN) { - return fetchVersion(createClient(ric, A1ProtocolType.STD_V1)) // - .onErrorResume(notUsed -> fetchVersion(createClient(ric, A1ProtocolType.STD_V1_1))) // + return fetchVersion(createClient(ric, A1ProtocolType.STD_V1_1)) // .onErrorResume(notUsed -> fetchVersion(createClient(ric, A1ProtocolType.OSC_V1))) // .onErrorResume(notUsed -> fetchVersion(createClient(ric, A1ProtocolType.SDNC_OSC))) // .onErrorResume(notUsed -> fetchVersion(createClient(ric, A1ProtocolType.SDNC_ONAP))) // .doOnNext(ric::setProtocolVersion) - .doOnNext(version -> logger.debug("Recover ric: {}, protocol version:{}", ric.name(), version)) // + .doOnNext(version -> logger.debug("Established protocol version:{} for Ric: {}", version, ric.name())) // .doOnError(notUsed -> logger.warn("Could not get protocol version from RIC: {}", ric.name())); // } else { return Mono.just(ric.getProtocolVersion()); diff --combined policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java index 2520b0a9,0ef1679c..0f3b391f --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java @@@ -182,7 -182,7 +182,7 @@@ public class PolicyController policy = policies.getPolicy(id); keepServiceAlive(policy.ownerServiceName()); if (policy.ric().getState() != Ric.RicState.IDLE) { - return Mono.just(new ResponseEntity<>("Busy, recovering", HttpStatus.LOCKED)); + return Mono.just(new ResponseEntity<>("Busy, synchronizing", HttpStatus.LOCKED)); } Ric ric = policy.ric(); return ric.getLock().lock(LockType.SHARED) // // @@@ -242,7 -242,7 +242,7 @@@ } return ric == null || type == null ? Mono.just(new ResponseEntity<>(HttpStatus.NOT_FOUND)) - : Mono.just(new ResponseEntity<>(HttpStatus.LOCKED)); // Recovering + : Mono.just(new ResponseEntity<>(HttpStatus.LOCKED)); // Synchronizing } @SuppressWarnings({"unchecked"}) @@@ -293,30 -293,27 +293,30 @@@ return new ResponseEntity<>("RIC not found", HttpStatus.NOT_FOUND); } synchronized (policies) { - Collection result = null; - - if (type != null) { - result = policies.getForType(type); - result = filter(result, null, ric, service); - } else if (service != null) { - result = policies.getForService(service); - result = filter(result, type, ric, null); - } else if (ric != null) { - result = filter(policies.getForRic(ric), type, null, service); - } else { - result = policies.getAll(); - } + String filteredPolicies = policiesToJson(filter(type, ric, service)); + return new ResponseEntity<>(filteredPolicies, HttpStatus.OK); + } + } - String policiesJson; - try { - policiesJson = policiesToJson(result); - } catch (ServiceException e) { - return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } - return new ResponseEntity<>(policiesJson, HttpStatus.OK); + @GetMapping("/policy_ids") + @ApiOperation(value = "Query policies, only IDs returned") + @ApiResponses( + value = {@ApiResponse(code = 200, message = "Policy ids", response = String.class, responseContainer = "List"), + @ApiResponse(code = 404, message = "RIC or type not found", response = String.class)}) + public ResponseEntity getPolicyIds( // + @RequestParam(name = "type", required = false) String type, // + @RequestParam(name = "ric", required = false) String ric, // + @RequestParam(name = "service", required = false) String service) // + { + if ((type != null && this.policyTypes.get(type) == null)) { + return new ResponseEntity<>("Policy type not found", HttpStatus.NOT_FOUND); + } + if ((ric != null && this.rics.get(ric) == null)) { + return new ResponseEntity<>("RIC not found", HttpStatus.NOT_FOUND); + } + synchronized (policies) { + String policyIdsJson = toPolicyIdsJson(filter(type, ric, service)); + return new ResponseEntity<>(policyIdsJson, HttpStatus.OK); } } @@@ -366,21 -363,7 +366,21 @@@ return filtered; } - private String policiesToJson(Collection policies) throws ServiceException { + private Collection filter(String type, String ric, String service) { + synchronized (policies) { + if (type != null) { + return filter(policies.getForType(type), null, ric, service); + } else if (service != null) { + return filter(policies.getForService(service), type, ric, null); + } else if (ric != null) { + return filter(policies.getForRic(ric), type, null, service); + } else { + return policies.getAll(); + } + } + } + + private String policiesToJson(Collection policies) { List v = new ArrayList<>(policies.size()); for (Policy p : policies) { PolicyInfo policyInfo = new PolicyInfo(); @@@ -391,7 -374,7 +391,7 @@@ policyInfo.service = p.ownerServiceName(); policyInfo.lastModified = p.lastModified(); if (!policyInfo.validate()) { - throw new ServiceException("BUG, all fields must be set"); + throw new NullPointerException("BUG, all fields must be set"); } v.add(policyInfo); } @@@ -425,14 -408,6 +425,14 @@@ return gson.toJson(v); } + private String toPolicyIdsJson(Collection policies) { + List v = new ArrayList<>(policies.size()); + for (Policy p : policies) { + v.add(p.id()); + } + return gson.toJson(v); + } + private String getTimeStampUtc() { return java.time.Instant.now().toString(); } diff --combined policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java index 4bc95128,2308fcf1..71bd9a5e --- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@@ -22,7 -22,6 +22,7 @@@ package org.oransc.policyagent import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; @@@ -87,7 -86,6 +87,7 @@@ import org.springframework.web.reactive import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import reactor.util.annotation.Nullable; @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @@@ -214,7 -212,7 +214,7 @@@ public class ApplicationTest } @Test - public void testRecovery() throws Exception { + public void testSynchronization() throws Exception { addRic("ric").setState(Ric.RicState.UNDEFINED); String ricName = "ric"; Policy policy2 = addPolicy("policyId2", "typeName", "service", ricName); @@@ -498,37 -496,10 +498,37 @@@ testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND); } + @Test + public void testGetPolicyIdsFilter() throws Exception { + addPolicy("id1", "type1", "service1", "ric1"); + addPolicy("id2", "type1", "service2", "ric1"); + addPolicy("id3", "type2", "service1", "ric1"); + + String url = "/policy_ids?type=type1"; + String rsp = restClient().get(url).block(); + logger.info(rsp); + assertThat(rsp).contains("id1"); + assertThat(rsp).contains("id2"); + assertThat(rsp.contains("id3")).isFalse(); + + url = "/policy_ids?type=type1&service=service1&ric=ric1"; + rsp = restClient().get(url).block(); + assertThat(rsp).isEqualTo("[\"id1\"]"); + + // Test get policy ids for non existing type + url = "/policy_ids?type=type1XXX"; + testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND); + + // Test get policy ids for non existing RIC + url = "/policy_ids?ric=XXX"; + testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND); + } + @Test public void testPutAndGetService() throws Exception { // PUT - putService("name", 0); + putService("name", 0, HttpStatus.CREATED); + putService("name", 0, HttpStatus.OK); // GET one service String url = "/services?name=name"; @@@ -569,7 -540,7 +569,7 @@@ @Test public void testServiceSupervision() throws Exception { - putService("service1", 1); + putService("service1", 1, HttpStatus.CREATED); addPolicyType("type1", "ric1"); String url = putPolicyUrl("service1", "ric1", "type1", "instance1"); @@@ -622,16 -593,13 +622,16 @@@ } private void putService(String name) { - putService(name, 0); + putService(name, 0, null); } - private void putService(String name, long keepAliveIntervalSeconds) { + private void putService(String name, long keepAliveIntervalSeconds, @Nullable HttpStatus expectedStatus) { String url = "/service"; String body = createServiceJson(name, keepAliveIntervalSeconds); - restClient().put(url, body).block(); + ResponseEntity resp = restClient().putForEntity(url, body).block(); + if (expectedStatus != null) { + assertEquals(expectedStatus, resp.getStatusCode(), ""); + } } private String baseUrl() {