*/
@SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
public class OscA1Client implements A1Client {
+ static final int CONCURRENCY_RIC = 1; // How may paralell requests that is sent to one NearRT RIC
public static class UriBuilder implements A1UriBuilder {
private final RicConfig ricConfig;
uri = new UriBuilder(ricConfig);
}
+ public static Mono<String> extractCreateSchema(String policyTypeResponse, String policyTypeId) {
+ try {
+ JSONObject obj = new JSONObject(policyTypeResponse);
+ JSONObject schemaObj = obj.getJSONObject("create_schema");
+ schemaObj.put(TITLE, policyTypeId);
+ return Mono.just(schemaObj.toString());
+ } catch (Exception e) {
+ String exceptionString = e.toString();
+ logger.error("Unexpected response for policy type: {}, exception: {}", policyTypeResponse, exceptionString);
+ return Mono.error(e);
+ }
+ }
+
@Override
public Mono<List<String>> getPolicyTypeIdentities() {
return getPolicyTypeIds() //
public Mono<String> getPolicyTypeSchema(String policyTypeId) {
String schemaUri = uri.createGetSchemaUri(policyTypeId);
return restClient.get(schemaUri) //
- .flatMap(response -> getCreateSchema(response, policyTypeId));
+ .flatMap(response -> extractCreateSchema(response, policyTypeId));
}
@Override
@Override
public Flux<String> deleteAllPolicies() {
return getPolicyTypeIds() //
- .flatMap(this::deletePoliciesForType);
+ .flatMap(this::deletePoliciesForType, CONCURRENCY_RIC);
}
@Override
.flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
}
- private Mono<String> getCreateSchema(String policyTypeResponse, String policyTypeId) {
- try {
- JSONObject obj = new JSONObject(policyTypeResponse);
- JSONObject schemaObj = obj.getJSONObject("create_schema");
- schemaObj.put(TITLE, policyTypeId);
- return Mono.just(schemaObj.toString());
- } catch (Exception e) {
- String exceptionString = e.toString();
- logger.error("Unexpected response for policy type: {}, exception: {}", policyTypeResponse, exceptionString);
- return Mono.error(e);
- }
- }
-
private Mono<String> deletePolicyById(String typeId, String policyId) {
String policyUri = uri.createDeleteUri(typeId, policyId);
return restClient.delete(policyUri);
private Flux<String> deletePoliciesForType(String typeId) {
return getPolicyIdentitiesByType(typeId) //
- .flatMap(policyId -> deletePolicyById(typeId, policyId));
+ .flatMap(policyId -> deletePolicyById(typeId, policyId), CONCURRENCY_RIC);
}
}