X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fclients%2FA1ClientFactory.java;h=6598c27672fa12e1b300e1fa3e9a5e6fad5acc48;hb=063e00d7a9f1f56c8b0714602fcaecb3c4eac951;hp=cd53f838d60d092b23de80425c7f16581f03dae2;hpb=ff56d2600d074ac0a4473c81b8193004a316c2f8;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java index cd53f838..6598c276 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java @@ -21,16 +21,42 @@ package org.oransc.policyagent.clients; import org.oransc.policyagent.clients.A1Client.A1ProtocolType; -import org.oransc.policyagent.exceptions.ServiceException; +import org.oransc.policyagent.configuration.ApplicationConfig; import org.oransc.policyagent.repository.Ric; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; +/** + * Factory for A1 clients that supports four different protocol versions of the A1 api. + */ public class A1ClientFactory { private static final Logger logger = LoggerFactory.getLogger(A1ClientFactory.class); + private final ApplicationConfig appConfig; + + @Autowired + public A1ClientFactory(ApplicationConfig appConfig) { + this.appConfig = appConfig; + } + + /** + * Creates an A1 client with the correct A1 protocol for the provided Ric. + * + *

+ * It detects the protocol version by trial and error, since there is no getVersion method specified in the A1 + * api yet. + * + *

+ * As a side effect it also sets the protocol version in the provided Ric. This means that after the first + * successful creation it won't have to try which protocol to use, but can create the client directly. + * + * @param ric The Ric to get a client for. + * @return a client with the correct protocol, or a ServiceException if none of the protocols are supported by the + * Ric. + */ public Mono createA1Client(Ric ric) { return getProtocolVersion(ric) // .flatMap(version -> createA1Client(ric, version)); @@ -40,18 +66,20 @@ public class A1ClientFactory { if (version == A1ProtocolType.STD_V1) { return Mono.just(createStdA1ClientImpl(ric)); } else if (version == A1ProtocolType.OSC_V1) { - return Mono.just(new OscA1Client(ric.getConfig())); - } else if (version == A1ProtocolType.CONTROLLER) { - return Mono.just(createControllerA1Client(ric)); + return Mono.just(createOscA1Client(ric)); + } else if (version == A1ProtocolType.SDNC_OSC) { + return Mono.just(createSdncOscA1Client(ric)); + } else { // A1ProtocolType.SDNR_ONAP + return Mono.just(createSdnrOnapA1Client(ric)); } - return Mono.error(new ServiceException("Not supported protocoltype: " + version)); } private Mono getProtocolVersion(Ric ric) { if (ric.getProtocolVersion() == A1ProtocolType.UNKNOWN) { - return fetchVersion(ric, createControllerA1Client(ric)) // - .onErrorResume(err -> fetchVersion(ric, new OscA1Client(ric.getConfig()))) - .onErrorResume(err -> fetchVersion(ric, createStdA1ClientImpl(ric))) + return fetchVersion(createSdnrOnapA1Client(ric)) // + .onErrorResume(err -> fetchVersion(createSdncOscA1Client(ric))) // + .onErrorResume(err -> fetchVersion(createOscA1Client(ric))) // + .onErrorResume(err -> fetchVersion(createStdA1ClientImpl(ric))) // .doOnNext(version -> ric.setProtocolVersion(version)) .doOnNext(version -> logger.debug("Recover ric: {}, protocol version:{}", ric.name(), version)) // .doOnError(t -> logger.warn("Could not get protocol version from RIC: {}", ric.name())); // @@ -60,17 +88,26 @@ public class A1ClientFactory { } } + protected A1Client createOscA1Client(Ric ric) { + return new OscA1Client(ric.getConfig()); + } + protected A1Client createStdA1ClientImpl(Ric ric) { return new StdA1Client(ric.getConfig()); } - protected A1Client createControllerA1Client(Ric ric) { - return new ControllerA1Client(ric.getConfig()); + protected A1Client createSdncOscA1Client(Ric ric) { + return new SdncOscA1Client(ric.getConfig(), appConfig.getA1ControllerBaseUrl(), + appConfig.getA1ControllerUsername(), appConfig.getA1ControllerPassword()); + } + + protected A1Client createSdnrOnapA1Client(Ric ric) { + return new SdnrOnapA1Client(ric.getConfig(), appConfig.getA1ControllerBaseUrl(), + appConfig.getA1ControllerUsername(), appConfig.getA1ControllerPassword()); } - private Mono fetchVersion(Ric ric, A1Client a1Client) { + private Mono fetchVersion(A1Client a1Client) { return Mono.just(a1Client) // .flatMap(client -> a1Client.getProtocolVersion()); } - }