X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fclients%2FStdA1Client.java;fp=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fclients%2FStdA1Client.java;h=0000000000000000000000000000000000000000;hb=be2000ec2d21151b42cb559ef881695eb32e35e9;hp=73adecee44e3abc80efc69f0b02c65e9faf14046;hpb=d898170a0bb639b85a7f8770ddab2a3ccd181cfb;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/StdA1Client.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/StdA1Client.java deleted file mode 100644 index 73adecee..00000000 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/StdA1Client.java +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * ========================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.clients; - -import java.util.List; - -import org.oransc.policyagent.configuration.RicConfig; -import org.oransc.policyagent.repository.Policy; -import org.springframework.web.util.UriComponentsBuilder; - -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -public class StdA1Client implements A1Client { - private static final String URL_PREFIX = "/A1-P/v1"; - - private static final String POLICY_TYPES_URI = "/policytypes"; - private static final String POLICY_TYPE_ID = "policyTypeId"; - - private static final String POLICIES_URI = "/policies"; - - private static final UriComponentsBuilder POLICY_TYPE_SCHEMA_URI = - UriComponentsBuilder.fromPath("/policytypes/{policy-type-name}"); - - private static final UriComponentsBuilder POLICY_URI = - UriComponentsBuilder.fromPath("/policies/{policy-id}").queryParam(POLICY_TYPE_ID, "{policy-type-name}"); - - private static final UriComponentsBuilder POLICY_DELETE_URI = - UriComponentsBuilder.fromPath("/policies/{policy-id}"); - - private static final UriComponentsBuilder POLICY_STATUS_URI = - UriComponentsBuilder.fromPath("/policies/{policy-id}/status"); - - private final AsyncRestClient restClient; - - public StdA1Client(RicConfig ricConfig) { - String baseUrl = ricConfig.baseUrl() + URL_PREFIX; - this.restClient = new AsyncRestClient(baseUrl); - } - - public StdA1Client(AsyncRestClient restClient) { - this.restClient = restClient; - } - - @Override - public Mono> getPolicyIdentities() { - return getPolicyIds() // - .collectList(); - } - - @Override - public Mono putPolicy(Policy policy) { - String uri = POLICY_URI.buildAndExpand(policy.id(), policy.type().name()).toUriString(); - return restClient.put(uri, policy.json()) // - .flatMap(JsonHelper::validateJson); - } - - @Override - public Mono> getPolicyTypeIdentities() { - return restClient.get(POLICY_TYPES_URI) // - .flatMapMany(JsonHelper::parseJsonArrayOfString) // - .collectList(); - } - - @Override - public Mono getPolicyTypeSchema(String policyTypeId) { - String uri = POLICY_TYPE_SCHEMA_URI.buildAndExpand(policyTypeId).toUriString(); - return restClient.get(uri) // - .flatMap(JsonHelper::extractPolicySchema); - } - - @Override - public Mono deletePolicy(Policy policy) { - return deletePolicyById(policy.id()); - } - - @Override - public Flux deleteAllPolicies() { - return getPolicyIds() // - .flatMap(this::deletePolicyById); // - } - - @Override - public Mono getProtocolVersion() { - return getPolicyTypeIdentities() // - .flatMap(x -> Mono.just(A1ProtocolType.STD_V1)); - } - - @Override - public Mono getPolicyStatus(Policy policy) { - String uri = POLICY_STATUS_URI.buildAndExpand(policy.id()).toUriString(); - return restClient.get(uri); - } - - private Flux getPolicyIds() { - return restClient.get(POLICIES_URI) // - .flatMapMany(JsonHelper::parseJsonArrayOfString); - } - - private Mono deletePolicyById(String policyId) { - String uri = POLICY_DELETE_URI.buildAndExpand(policyId).toUriString(); - return restClient.delete(uri); - } -}