summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
73a8d2b)
Change-Id: Ifbbb999aec5ecbf382c799a3bb733ca272f93da7
Issue-ID: NONRTRIC-209
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
@Around("execution(* org.oransc.policyagent..*(..)))")
public void executimeTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
@Around("execution(* org.oransc.policyagent..*(..)))")
public void executimeTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
- MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
- String className = methodSignature.getDeclaringType().getSimpleName();
- String methodName = methodSignature.getName();
final StopWatch stopWatch = new StopWatch();
stopWatch.start();
proceedingJoinPoint.proceed();
stopWatch.stop();
final StopWatch stopWatch = new StopWatch();
stopWatch.start();
proceedingJoinPoint.proceed();
stopWatch.stop();
+ MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
+ String className = methodSignature.getDeclaringType().getSimpleName();
+ String methodName = methodSignature.getName();
logger.trace("Execution time of {}.{}: {} ms", className, methodName, stopWatch.getTotalTimeMillis());
}
logger.trace("Execution time of {}.{}: {} ms", className, methodName, stopWatch.getTotalTimeMillis());
}
private final A1ProtocolType protocolType;
/**
private final A1ProtocolType protocolType;
/**
+ * Constructor that creates the REST client to use.
+ *
* @param protocolType the southbound protocol of the controller. Supported
* protocols are SDNC_OSC_STD_V1_1 and SDNC_OSC_OSC_V1
* @param protocolType the southbound protocol of the controller. Supported
* protocols are SDNC_OSC_STD_V1_1 and SDNC_OSC_OSC_V1
- * @param ricConfig
- * @param controllerBaseUrl the base URL of the SDNC controller
- * @param username username to accesss the SDNC controller
- * @param password password to accesss the SDNC controller
+ * @param ricConfig the configuration of the Ric to communicate with
+ * @param controllerConfig the configuration of the SDNC controller to use
*/
public SdncOscA1Client(A1ProtocolType protocolType, RicConfig ricConfig, ControllerConfig controllerConfig) {
this(protocolType, ricConfig, controllerConfig,
*/
public SdncOscA1Client(A1ProtocolType protocolType, RicConfig ricConfig, ControllerConfig controllerConfig) {
this(protocolType, ricConfig, controllerConfig,
logger.debug("SdncOscA1Client for ric: {}, a1Controller: {}", ricConfig.name(), controllerConfig);
}
logger.debug("SdncOscA1Client for ric: {}, a1Controller: {}", ricConfig.name(), controllerConfig);
}
+ /**
+ * Constructor where the REST client to use is provided.
+ *
+ * @param protocolType the southbound protocol of the controller. Supported
+ * protocols are SDNC_OSC_STD_V1_1 and SDNC_OSC_OSC_V1
+ * @param ricConfig the configuration of the Ric to communicate with
+ * @param controllerConfig the configuration of the SDNC controller to use
+ * @param restClient the REST client to use
+ */
public SdncOscA1Client(A1ProtocolType protocolType, RicConfig ricConfig, ControllerConfig controllerConfig,
AsyncRestClient restClient) {
this.restClient = restClient;
public SdncOscA1Client(A1ProtocolType protocolType, RicConfig ricConfig, ControllerConfig controllerConfig,
AsyncRestClient restClient) {
this.restClient = restClient;
Properties dmaapConsumerConfig = new Properties();
JsonObject agentConfigJson = root.getAsJsonObject(CONFIG);
Properties dmaapConsumerConfig = new Properties();
JsonObject agentConfigJson = root.getAsJsonObject(CONFIG);
- List<RicConfig> ricConfigs = parseRics(agentConfigJson);
- Map<String, ControllerConfig> controllerConfigs = parseControllerConfigs(agentConfigJson);
JsonObject json = agentConfigJson.getAsJsonObject("streams_publishes");
if (json != null) {
JsonObject json = agentConfigJson.getAsJsonObject("streams_publishes");
if (json != null) {
dmaapConsumerConfig = parseDmaapConfig(json);
}
dmaapConsumerConfig = parseDmaapConfig(json);
}
+ List<RicConfig> ricConfigs = parseRics(agentConfigJson);
+ Map<String, ControllerConfig> controllerConfigs = parseControllerConfigs(agentConfigJson);
checkConfigurationConsistency(ricConfigs, controllerConfigs);
return ImmutableConfigParserResult.builder() //
checkConfigurationConsistency(ricConfigs, controllerConfigs);
return ImmutableConfigParserResult.builder() //
* The class fetches incoming requests from DMAAP. It uses the timeout parameter that lets the MessageRouter keep the
* connection with the Kafka open until requests are sent in.
*
* The class fetches incoming requests from DMAAP. It uses the timeout parameter that lets the MessageRouter keep the
* connection with the Kafka open until requests are sent in.
*
* If there is no DMaaP configuration in the application configuration, then this service will regularly check the
* configuration and start polling DMaaP if the configuration is added. If the DMaaP configuration is removed, then the
* service will stop polling and resume checking for configuration.
*
* If there is no DMaaP configuration in the application configuration, then this service will regularly check the
* configuration and start polling DMaaP if the configuration is added. If the DMaaP configuration is removed, then the
* service will stop polling and resume checking for configuration.
*
* Each received request is processed by {@link DmaapMessageHandler}.
*/
@Component
* Each received request is processed by {@link DmaapMessageHandler}.
*/
@Component
this.applicationConfig = applicationConfig;
}
this.applicationConfig = applicationConfig;
}
+ /**
+ * Starts the consumer. If there is a DMaaP configuration, it will start polling for messages. Otherwise it will
+ * check regularly for the configuration.
+ *
+ * @return the running thread, for test purposes.
+ */
- Thread thread = new Thread(() -> this.checkConfigLoop());
+ Thread thread = new Thread(this::checkConfigLoop);
thread.start();
return thread;
}
thread.start();
return thread;
}
* limitations under the License.
* ========================LICENSE_END===================================
*/
* limitations under the License.
* ========================LICENSE_END===================================
*/
package org.oransc.policyagent.dmaap;
import com.google.gson.Gson;
package org.oransc.policyagent.dmaap;
import com.google.gson.Gson;
package org.oransc.policyagent;
package org.oransc.policyagent;
+import static org.awaitility.Awaitility.await;
+
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.util.StringUtils;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
private int port;
private void keepServerAlive() throws InterruptedException, IOException {
private int port;
private void keepServerAlive() throws InterruptedException, IOException {
- logger.info("Keeping server alive!");
- Thread.sleep(1000);
+ waitForConfigurationToBeLoaded();
+ logger.info("Keeping server alive!");
synchronized (this) {
this.wait();
}
}
synchronized (this) {
this.wait();
}
}
+ private void waitForConfigurationToBeLoaded() throws IOException {
+ String json = getConfigJsonFromFile();
+ try {
+ int noOfRicsInConfigFile = StringUtils.countOccurrencesOf(json, "baseUrl");
+ await().until(() -> rics.size() == noOfRicsInConfigFile);
+ } catch (Exception e) {
+ logger.info("Loaded rics: {}, and no of rics in config file: {} never matched!", rics.size(),
+ StringUtils.countOccurrencesOf(json, "baseUrl"));
+ }
+ }
+
private static String title(String jsonSchema) {
JsonObject parsedSchema = (JsonObject) JsonParser.parseString(jsonSchema);
String title = parsedSchema.get("title").getAsString();
private static String title(String jsonSchema) {
JsonObject parsedSchema = (JsonObject) JsonParser.parseString(jsonSchema);
String title = parsedSchema.get("title").getAsString();
private void loadInstances() throws IOException {
PolicyType unnamedPolicyType = policyTypes.get("");
Ric ric = rics.get("ric1");
private void loadInstances() throws IOException {
PolicyType unnamedPolicyType = policyTypes.get("");
Ric ric = rics.get("ric1");
- File jsonFile = getFile("test_application_configuration.json");
- String json = new String(Files.readAllBytes(jsonFile.toPath()));
+ String json = getConfigJsonFromFile();
Policy policy = ImmutablePolicy.builder() //
.id("typelessPolicy") //
Policy policy = ImmutablePolicy.builder() //
.id("typelessPolicy") //
this.policies.put(policy);
}
this.policies.put(policy);
}
+ private String getConfigJsonFromFile() throws IOException {
+ File jsonFile = getFile("test_application_configuration.json");
+ String json = new String(Files.readAllBytes(jsonFile.toPath()));
+ return json;
+ }
+
- @SuppressWarnings("squid:S2699") // Tests should include assertions. This test is only for keeping the server
- // alive,
+ @SuppressWarnings("squid:S2699") // Tests should include assertions. This test is only for keeping the server alive,
// so it will only be confusing to add an assertion.
public void runMock() throws Exception {
keepServerAlive();
// so it will only be confusing to add an assertion.
public void runMock() throws Exception {
keepServerAlive();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
private void asynchUnlock(Lock lock) {
}
}
private void asynchUnlock(Lock lock) {
- Thread t = new Thread(() -> {
+ Thread thread = new Thread(() -> {
sleep();
lock.unlockBlocking();
});
sleep();
lock.unlockBlocking();
});
protected static final String NO_SERVICE_LOGIC_ACTIVE = "No service logic active for ";
private static final String NON_NULL_PARAM = "non-null";
private static final String NULL_PARAM = "null";
protected static final String NO_SERVICE_LOGIC_ACTIVE = "No service logic active for ";
private static final String NON_NULL_PARAM = "non-null";
private static final String NULL_PARAM = "null";
+ private static final String REST_CLIENT_RESPONSE_EXCEPTION_MSG = "Caught RestClientResponseException: {}";
private final Logger log = LoggerFactory.getLogger(NonrtRicApiProvider.class);
private final ExecutorService executor;
private final Logger log = LoggerFactory.getLogger(NonrtRicApiProvider.class);
private final ExecutorService executor;
@Override
public ListenableFuture<RpcResult<PutA1PolicyOutput>> putA1Policy(PutA1PolicyInput input) {
log.info("Start of putPolicy");
@Override
public ListenableFuture<RpcResult<PutA1PolicyOutput>> putA1Policy(PutA1PolicyInput input) {
log.info("Start of putPolicy");
- PutA1PolicyOutputBuilder responseBuilder = new PutA1PolicyOutputBuilder();
+ PutA1PolicyOutputBuilder putPolicyResponseBuilder = new PutA1PolicyOutputBuilder();
try {
final Uri uri = input.getNearRtRicUrl();
log.info("PUT Request input.GetA1Policy() : {} ", uri);
try {
final Uri uri = input.getNearRtRicUrl();
log.info("PUT Request input.GetA1Policy() : {} ", uri);
- ResponseEntity<String> response = restAdapter.put(uri.getValue(), input.getBody(), String.class);
- if (response.hasBody()) {
- log.info("Response PutA1Policy : {} ", response.getBody());
- responseBuilder.setBody(response.getBody());
+ ResponseEntity<String> putPolicyResponse = restAdapter.put(uri.getValue(), input.getBody(), String.class);
+ if (putPolicyResponse.hasBody()) {
+ log.info("Response PutA1Policy : {} ", putPolicyResponse.getBody());
+ putPolicyResponseBuilder.setBody(putPolicyResponse.getBody());
- responseBuilder.setHttpStatus(response.getStatusCodeValue());
+ putPolicyResponseBuilder.setHttpStatus(putPolicyResponse.getStatusCodeValue());
} catch (RestClientResponseException ex) {
} catch (RestClientResponseException ex) {
- log.error("Caught RestClientResponseException: {}", ex.getMessage());
+ log.error(REST_CLIENT_RESPONSE_EXCEPTION_MSG, ex.getMessage());
if (ex.getResponseBodyAsByteArray() != null) {
if (ex.getResponseBodyAsByteArray() != null) {
- responseBuilder.setBody(ex.getResponseBodyAsString());
+ putPolicyResponseBuilder.setBody(ex.getResponseBodyAsString());
- responseBuilder.setHttpStatus(ex.getRawStatusCode());
+ putPolicyResponseBuilder.setHttpStatus(ex.getRawStatusCode());
}
log.info("End of PutA1Policy");
RpcResult<PutA1PolicyOutput> rpcResult = RpcResultBuilder.<PutA1PolicyOutput>status(true)
}
log.info("End of PutA1Policy");
RpcResult<PutA1PolicyOutput> rpcResult = RpcResultBuilder.<PutA1PolicyOutput>status(true)
- .withResult(responseBuilder.build()).build();
+ .withResult(putPolicyResponseBuilder.build()).build();
return Futures.immediateFuture(rpcResult);
}
@Override
public ListenableFuture<RpcResult<DeleteA1PolicyOutput>> deleteA1Policy(DeleteA1PolicyInput input) {
log.info("Start of DeleteA1Policy");
return Futures.immediateFuture(rpcResult);
}
@Override
public ListenableFuture<RpcResult<DeleteA1PolicyOutput>> deleteA1Policy(DeleteA1PolicyInput input) {
log.info("Start of DeleteA1Policy");
- DeleteA1PolicyOutputBuilder responseBuilder = new DeleteA1PolicyOutputBuilder();
+ DeleteA1PolicyOutputBuilder deletePolicyResponseBuilder = new DeleteA1PolicyOutputBuilder();
try {
final Uri uri = input.getNearRtRicUrl();
try {
final Uri uri = input.getNearRtRicUrl();
- ResponseEntity<Object> response = restAdapter.delete(uri.getValue());
- if (response.hasBody()) {
- log.info("Response DeleteA1Policy : {} ", response.getBody());
- responseBuilder.setBody(response.getBody().toString());
+ ResponseEntity<Object> deletePolicyResponse = restAdapter.delete(uri.getValue());
+ if (deletePolicyResponse.hasBody()) {
+ log.info("Response DeleteA1Policy : {} ", deletePolicyResponse.getBody());
+ deletePolicyResponseBuilder.setBody(deletePolicyResponse.getBody().toString());
- responseBuilder.setHttpStatus(response.getStatusCodeValue());
+ deletePolicyResponseBuilder.setHttpStatus(deletePolicyResponse.getStatusCodeValue());
} catch (RestClientResponseException ex) {
} catch (RestClientResponseException ex) {
- log.error("Caught RestClientResponseException: {}", ex.getMessage());
+ log.error(REST_CLIENT_RESPONSE_EXCEPTION_MSG, ex.getMessage());
if (ex.getResponseBodyAsByteArray() != null) {
if (ex.getResponseBodyAsByteArray() != null) {
- responseBuilder.setBody(ex.getResponseBodyAsString());
+ deletePolicyResponseBuilder.setBody(ex.getResponseBodyAsString());
- responseBuilder.setHttpStatus(ex.getRawStatusCode());
+ deletePolicyResponseBuilder.setHttpStatus(ex.getRawStatusCode());
}
log.info("End of DeleteA1Policy");
RpcResult<DeleteA1PolicyOutput> rpcResult = RpcResultBuilder.<DeleteA1PolicyOutput>status(true)
}
log.info("End of DeleteA1Policy");
RpcResult<DeleteA1PolicyOutput> rpcResult = RpcResultBuilder.<DeleteA1PolicyOutput>status(true)
- .withResult(responseBuilder.build()).build();
+ .withResult(deletePolicyResponseBuilder.build()).build();
return Futures.immediateFuture(rpcResult);
}
private GetA1PolicyOutput getA1(GetA1PolicyInput input) {
log.info("Start of getA1");
return Futures.immediateFuture(rpcResult);
}
private GetA1PolicyOutput getA1(GetA1PolicyInput input) {
log.info("Start of getA1");
- GetA1PolicyOutputBuilder responseBuilder = new GetA1PolicyOutputBuilder();
+ GetA1PolicyOutputBuilder getPolicyResponseBuilder = new GetA1PolicyOutputBuilder();
try {
final Uri uri = input.getNearRtRicUrl();
try {
final Uri uri = input.getNearRtRicUrl();
- ResponseEntity<String> response = restAdapter.get(uri.getValue(), String.class);
- if (response.hasBody()) {
- log.info("Response getA1 : {} ", response.getBody());
- responseBuilder.setBody(response.getBody());
+ ResponseEntity<String> getPolicyResponse = restAdapter.get(uri.getValue(), String.class);
+ if (getPolicyResponse.hasBody()) {
+ log.info("Response getA1 : {} ", getPolicyResponse.getBody());
+ getPolicyResponseBuilder.setBody(getPolicyResponse.getBody());
- responseBuilder.setHttpStatus(response.getStatusCodeValue());
+ getPolicyResponseBuilder.setHttpStatus(getPolicyResponse.getStatusCodeValue());
} catch (RestClientResponseException ex) {
} catch (RestClientResponseException ex) {
- log.error("Caught RestClientResponseException: {}", ex.getMessage());
+ log.error(REST_CLIENT_RESPONSE_EXCEPTION_MSG, ex.getMessage());
if (ex.getResponseBodyAsByteArray() != null) {
if (ex.getResponseBodyAsByteArray() != null) {
- responseBuilder.setBody(ex.getResponseBodyAsString());
+ getPolicyResponseBuilder.setBody(ex.getResponseBodyAsString());
- responseBuilder.setHttpStatus(ex.getRawStatusCode());
+ getPolicyResponseBuilder.setHttpStatus(ex.getRawStatusCode());
}
log.info("End of getA1");
}
log.info("End of getA1");
- return responseBuilder.build();
+ return getPolicyResponseBuilder.build();
@Override
public ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> getA1PolicyStatus(GetA1PolicyStatusInput input) {
@Override
public ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> getA1PolicyStatus(GetA1PolicyStatusInput input) {
- GetA1PolicyInputBuilder getInputBuilder = new GetA1PolicyInputBuilder();
- getInputBuilder.setNearRtRicUrl(input.getNearRtRicUrl());
- GetA1PolicyOutput getOutput = getA1(getInputBuilder.build());
+ GetA1PolicyInputBuilder getPolicyStatusInputBuilder = new GetA1PolicyInputBuilder();
+ getPolicyStatusInputBuilder.setNearRtRicUrl(input.getNearRtRicUrl());
+ GetA1PolicyOutput getOutput = getA1(getPolicyStatusInputBuilder.build());
- GetA1PolicyStatusOutputBuilder outputBuilder = new GetA1PolicyStatusOutputBuilder();
- outputBuilder.setBody(getOutput.getBody());
- outputBuilder.setHttpStatus(getOutput.getHttpStatus());
+ GetA1PolicyStatusOutputBuilder getPolicyStatusoutputBuilder = new GetA1PolicyStatusOutputBuilder();
+ getPolicyStatusoutputBuilder.setBody(getOutput.getBody());
+ getPolicyStatusoutputBuilder.setHttpStatus(getOutput.getHttpStatus());
return Futures.immediateFuture(RpcResultBuilder.<GetA1PolicyStatusOutput>status(true) //
return Futures.immediateFuture(RpcResultBuilder.<GetA1PolicyStatusOutput>status(true) //
- .withResult(outputBuilder.build()) //
+ .withResult(getPolicyStatusoutputBuilder.build()) //
.build());
}
@Override
public ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> getA1PolicyType(GetA1PolicyTypeInput input) {
.build());
}
@Override
public ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> getA1PolicyType(GetA1PolicyTypeInput input) {
- GetA1PolicyInputBuilder getInputBuilder = new GetA1PolicyInputBuilder();
- getInputBuilder.setNearRtRicUrl(input.getNearRtRicUrl());
- GetA1PolicyOutput getOutput = getA1(getInputBuilder.build());
+ GetA1PolicyInputBuilder getPolicyTypeInputBuilder = new GetA1PolicyInputBuilder();
+ getPolicyTypeInputBuilder.setNearRtRicUrl(input.getNearRtRicUrl());
+ GetA1PolicyOutput getOutput = getA1(getPolicyTypeInputBuilder.build());
- GetA1PolicyTypeOutputBuilder outputBuilder = new GetA1PolicyTypeOutputBuilder();
- outputBuilder.setBody(getOutput.getBody());
- outputBuilder.setHttpStatus(getOutput.getHttpStatus());
+ GetA1PolicyTypeOutputBuilder getPolicyTypeOutputBuilder = new GetA1PolicyTypeOutputBuilder();
+ getPolicyTypeOutputBuilder.setBody(getOutput.getBody());
+ getPolicyTypeOutputBuilder.setHttpStatus(getOutput.getHttpStatus());
return Futures.immediateFuture(RpcResultBuilder.<GetA1PolicyTypeOutput>status(true) //
return Futures.immediateFuture(RpcResultBuilder.<GetA1PolicyTypeOutput>status(true) //
- .withResult(outputBuilder.build()) //
+ .withResult(getPolicyTypeOutputBuilder.build()) //