/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.clamp.acm.runtime.config;
-import java.util.Arrays;
import java.util.List;
import org.onap.policy.clamp.common.acm.rest.CoderHttpMesageConverter;
import org.springframework.context.annotation.Configuration;
converters.add(new CoderHttpMesageConverter<>("json"));
StringHttpMessageConverter converter = new StringHttpMessageConverter();
- converter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN));
+ converter.setSupportedMediaTypes(List.of(MediaType.TEXT_PLAIN));
converters.add(converter);
}
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.config;
+
+import io.micrometer.core.instrument.MeterRegistry;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MetricsConfiguration {
+
+ /**
+ * Load up the metrics registry.
+ */
+ @Bean
+ InitializingBean forcePrometheusPostProcessor(BeanPostProcessor meterRegistryPostProcessor,
+ MeterRegistry registry) {
+ return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, "");
+ }
+}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* Common superclass to provide REST endpoints for the participant simulator.
*/
// @formatter:off
-@RequestMapping(value = "/v2", produces = {MediaType.APPLICATION_JSON, AbstractRestController.APPLICATION_YAML})
+@RequestMapping(value = "/onap/policy/clamp/acm/v2",
+ produces = {MediaType.APPLICATION_JSON, AbstractRestController.APPLICATION_YAML})
@Api(value = "Automation Composition Commissioning API")
@SwaggerDefinition(
info = @Info(description =
server:
port: 6969
- servlet:
- context-path: /onap/policy/clamp/acm
error:
path: /error
management:
endpoints:
web:
+ base-path: /
exposure:
include: health, metrics, prometheus
}
@Test
- void testSwagger() throws Exception {
+ void testSwagger() {
super.testSwagger(COMMISSIONING_ENDPOINT);
}
@Test
- void testUnauthorizedCreate() throws Exception {
+ void testUnauthorizedCreate() {
assertUnauthorizedPost(COMMISSIONING_ENDPOINT, Entity.json(serviceTemplate));
}
@Test
- void testUnauthorizedQuery() throws Exception {
+ void testUnauthorizedQuery() {
assertUnauthorizedGet(COMMISSIONING_ENDPOINT);
}
@Test
- void testUnauthorizedQueryElements() throws Exception {
+ void testUnauthorizedQueryElements() {
assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/elements");
}
@Test
- void testUnauthorizedDelete() throws Exception {
+ void testUnauthorizedDelete() {
assertUnauthorizedDelete(COMMISSIONING_ENDPOINT);
}
@Test
- void testUnauthorizedQueryToscaServiceTemplate() throws Exception {
+ void testUnauthorizedQueryToscaServiceTemplate() {
assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/toscaservicetemplate");
}
@Test
- void testUnauthorizedQueryToscaServiceTemplateSchema() throws Exception {
+ void testUnauthorizedQueryToscaServiceTemplateSchema() {
assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/toscaServiceTemplateSchema");
}
@Test
- void testUnauthorizedQueryToscaServiceCommonOrInstanceProperties() throws Exception {
+ void testUnauthorizedQueryToscaServiceCommonOrInstanceProperties() {
assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/getCommonOrInstanceProperties");
}
}
@Test
- void testCreateBadRequest() throws Exception {
+ void testCreateBadRequest() {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
Response resp = invocationBuilder.post(Entity.json("NotToscaServiceTempalte"));
}
@Test
- void testCreate() throws Exception {
+ void testCreate() {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
AutomationCompositions automationCompositions) {
assertThat(response).isNotNull();
assertThat(response.getErrorDetails()).isNull();
- assertThat(response.getAffectedAutomationCompositions().size())
- .isEqualTo(automationCompositions.getAutomationCompositionList().size());
+ assertThat(response.getAffectedAutomationCompositions())
+ .hasSameSizeAs(automationCompositions.getAutomationCompositionList());
for (AutomationComposition automationComposition : automationCompositions.getAutomationCompositionList()) {
assertTrue(response.getAffectedAutomationCompositions().stream()
.anyMatch(ac -> ac.equals(automationComposition.getKey().asIdentifier())));
}
@Test
- void testSwagger() throws Exception {
+ void testSwagger() {
super.testSwagger(INSTANTIATION_ENDPOINT);
}
}
@Test
- void testQuery_Unauthorized() throws Exception {
+ void testQuery_Unauthorized() {
assertUnauthorizedGet(INSTANTIATION_ENDPOINT);
}
}
@Test
- void testDelete_Unauthorized() throws Exception {
+ void testDelete_Unauthorized() {
assertUnauthorizedDelete(INSTANTIATION_ENDPOINT);
}
}
@Test
- void testQuery_NoResultWithThisName() throws Exception {
+ void testQuery_NoResultWithThisName() {
Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT + "?name=noResultWithThisName");
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
}
@Test
- void testDelete_NoResultWithThisName() throws Exception {
+ void testDelete_NoResultWithThisName() {
Invocation.Builder invocationBuilder =
super.sendRequest(INSTANTIATION_ENDPOINT + "?name=noResultWithThisName&version=1.0.1");
Response resp = invocationBuilder.delete();
}
@Test
- void testCreateInstanceProperties() throws Exception {
+ void testCreateInstanceProperties() {
Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
}
@Test
- void testDeleteInstancePropertiesBadRequest() throws Exception {
+ void testDeleteInstancePropertiesBadRequest() {
Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
}
@Test
- void testCommand_NotFound1() throws Exception {
+ void testCommand_NotFound1() {
Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
Response resp = invocationBuilder.put(Entity.json(new InstantiationCommand()));
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
}
@Test
- void testGetHealth_Unauthorized() throws Exception {
+ void testGetHealth_Unauthorized() {
assertUnauthorizedActGet(HEALTH_ENDPOINT);
}
@Test
- void testGetMetrics_Unauthorized() throws Exception {
+ void testGetMetrics_Unauthorized() {
assertUnauthorizedActGet(METRICS_ENDPOINT);
}
@Test
- void testGetPrometheus_Unauthorized() throws Exception {
+ void testGetPrometheus_Unauthorized() {
assertUnauthorizedActGet(PROMETHEUS_ENDPOINT);
}
@Test
- void testGetHealth() throws Exception {
+ void testGetHealth() {
Invocation.Builder invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT);
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
}
@Test
- void testGetMetrics() throws Exception {
+ void testGetMetrics() {
Invocation.Builder invocationBuilder = super.sendActRequest(METRICS_ENDPOINT);
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
}
@Test
- void testGePrometheus() throws Exception {
+ void testGetPrometheus() {
Invocation.Builder invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT);
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
}
@Test
- void testQuery_Unauthorized_for_AcElementStats() throws Exception {
+ void testQuery_Unauthorized_for_AcElementStats() {
assertUnauthorizedGet(AC_ELEMENT_STATS_ENDPOINT);
}
@Test
- void testQuery_Unauthorized_for_AcParticipantStats() throws Exception {
+ void testQuery_Unauthorized_for_AcParticipantStats() {
assertUnauthorizedGet(PARTICIPANT_STATS_ENDPOINT);
}
@Test
- void testQuery_Unauthorized_for_ParticipantStatsPerAc() throws Exception {
+ void testQuery_Unauthorized_for_ParticipantStatsPerAc() {
assertUnauthorizedGet(PARTICIPANT_STATS_PER_AC_ENDPOINT);
}
@Test
- void testQuery_Unauthorized_for_AcElementStatsPerAc() throws Exception {
+ void testQuery_Unauthorized_for_AcElementStatsPerAc() {
assertUnauthorizedGet(AC_ELEMENT_STATS_PER_AC_ENDPOINT);
}
@Test
- void testSwagger_AcStats() throws Exception {
+ void testSwagger_AcStats() {
super.testSwagger(AC_ELEMENT_STATS_ENDPOINT);
super.testSwagger(PARTICIPANT_STATS_ENDPOINT);
super.testSwagger(AC_ELEMENT_STATS_PER_AC_ENDPOINT);
}
@Test
- void testAcElementStatisticsEndpoint() throws Exception {
+ void testAcElementStatisticsEndpoint() {
// Filter statistics only based on participant Id and UUID
Invocation.Builder invokeRequest1 = super.sendRequest(AC_ELEMENT_STATS_ENDPOINT + "?name="
+ acElementStatisticsList.getAcElementStatistics().get(0).getParticipantId().getName() + "&version="
}
@Test
- void testAcElementStats_BadRequest() throws Exception {
+ void testAcElementStats_BadRequest() {
Invocation.Builder invokeRequest1 = super.sendRequest(AC_ELEMENT_STATS_ENDPOINT + "?version=1.0.0");
Response response1 = invokeRequest1.buildGet().invoke();
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response1.getStatus());
}
@Test
- void testParticipantStatisticsEndpoint() throws Exception {
+ void testParticipantStatisticsEndpoint() {
// Filter statistics only based on participant Id
Invocation.Builder invokeRequest1 = super.sendRequest(PARTICIPANT_STATS_ENDPOINT + "?name="
}
@Test
- void testParticipantStats_BadRequest() throws Exception {
+ void testParticipantStats_BadRequest() {
Invocation.Builder invokeRequest1 = super.sendRequest(PARTICIPANT_STATS_ENDPOINT + "?version=0.0");
Response response1 = invokeRequest1.buildGet().invoke();
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response1.getStatus());
}
@Test
- void testParticipantStatsPerAcEndpoint() throws Exception {
+ void testParticipantStatsPerAcEndpoint() {
Invocation.Builder invokeRequest1 =
super.sendRequest(PARTICIPANT_STATS_PER_AC_ENDPOINT + "?name=dummyName&version=1.001");
Response response1 = invokeRequest1.buildGet().invoke();
}
@Test
- void testParticipantStatsPerAc_BadRequest() throws Exception {
+ void testParticipantStatsPerAc_BadRequest() {
Invocation.Builder invokeRequest1 = super.sendRequest(PARTICIPANT_STATS_PER_AC_ENDPOINT);
Response response1 = invokeRequest1.buildGet().invoke();
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response1.getStatus());
}
@Test
- void testAcElementStatisticsPerAcEndpoint() throws Exception {
+ void testAcElementStatisticsPerAcEndpoint() {
Invocation.Builder invokeRequest1 =
super.sendRequest(AC_ELEMENT_STATS_PER_AC_ENDPOINT + "?name=dummyName&version=1.001");
Response response1 = invokeRequest1.buildGet().invoke();
}
@Test
- void testAcElementStatsPerAc_BadRequest() throws Exception {
+ void testAcElementStatsPerAc_BadRequest() {
Invocation.Builder invokeRequest1 = super.sendRequest(AC_ELEMENT_STATS_PER_AC_ENDPOINT);
Response response1 = invokeRequest1.buildGet().invoke();
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response1.getStatus());
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
public class CommonRestController {
public static final String SELF = NetworkUtil.getHostname();
- public static final String CONTEXT_PATH = "onap/automationcomposition";
+ public static final String CONTEXT_PATH = "onap/policy/clamp/acm";
public static final String ENDPOINT_PREFIX = CONTEXT_PATH + "/v2/";
- public static final String ACTUATOR_ENDPOINT = CONTEXT_PATH + "/actuator/";
private static String httpPrefix;
* Verifies that an endpoint appears within the swagger response.
*
* @param endpoint the endpoint of interest
- * @throws Exception if an error occurs
*/
- protected void testSwagger(final String endpoint) throws Exception {
- final Invocation.Builder invocationBuilder = sendRequest("api-docs");
+ protected void testSwagger(final String endpoint) {
+ final Invocation.Builder invocationBuilder = sendActRequest("v2/api-docs");
final String resp = invocationBuilder.get(String.class);
assertThat(resp).contains(endpoint);
*
* @param endpoint the target endpoint
* @return a request builder
- * @throws Exception if an error occurs
*/
- protected Invocation.Builder sendRequest(final String endpoint) throws Exception {
+ protected Invocation.Builder sendRequest(final String endpoint) {
return sendFqeRequest(httpPrefix + ENDPOINT_PREFIX + endpoint, true);
}
*
* @param endpoint the target endpoint
* @return a request builder
- * @throws Exception if an error occurs
*/
- protected Invocation.Builder sendActRequest(final String endpoint) throws Exception {
- return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + endpoint, true);
+ protected Invocation.Builder sendActRequest(final String endpoint) {
+ return sendFqeRequest(httpPrefix + endpoint, true);
}
/**
*
* @param endpoint the target endpoint
* @return a request builder
- * @throws Exception if an error occurs
*/
- protected Invocation.Builder sendNoAuthRequest(final String endpoint) throws Exception {
+ protected Invocation.Builder sendNoAuthRequest(final String endpoint) {
return sendFqeRequest(httpPrefix + ENDPOINT_PREFIX + endpoint, false);
}
*
* @param endpoint the target endpoint
* @return a request builder
- * @throws Exception if an error occurs
*/
- protected Invocation.Builder sendNoAuthActRequest(final String endpoint) throws Exception {
- return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + endpoint, false);
+ protected Invocation.Builder sendNoAuthActRequest(final String endpoint) {
+ return sendFqeRequest(httpPrefix + endpoint, false);
}
/**
* @param fullyQualifiedEndpoint the fully qualified target endpoint
* @param includeAuth if authorization header should be included
* @return a request builder
- * @throws Exception if an error occurs
*/
- protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth)
- throws Exception {
+ protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) {
final Client client = ClientBuilder.newBuilder().build();
client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
*
* @param endPoint the endpoint
* @param entity the entity ofthe body
- * @throws Exception if an error occurs
*/
- protected void assertUnauthorizedPost(final String endPoint, final Entity<?> entity) throws Exception {
+ protected void assertUnauthorizedPost(final String endPoint, final Entity<?> entity) {
Response rawresp = sendNoAuthRequest(endPoint).post(entity);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
*
* @param endPoint the endpoint
* @param entity the entity ofthe body
- * @throws Exception if an error occurs
*/
- protected void assertUnauthorizedPut(final String endPoint, final Entity<?> entity) throws Exception {
+ protected void assertUnauthorizedPut(final String endPoint, final Entity<?> entity) {
Response rawresp = sendNoAuthRequest(endPoint).put(entity);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
* Assert that GET call is Unauthorized.
*
* @param endPoint the endpoint
- * @throws Exception if an error occurs
*/
- protected void assertUnauthorizedGet(final String endPoint) throws Exception {
+ protected void assertUnauthorizedGet(final String endPoint) {
Response rawresp = sendNoAuthRequest(endPoint).buildGet().invoke();
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
* Assert that GET call to actuator endpoint is Unauthorized.
*
* @param endPoint the endpoint
- * @throws Exception if an error occurs
*/
- protected void assertUnauthorizedActGet(final String endPoint) throws Exception {
+ protected void assertUnauthorizedActGet(final String endPoint) {
Response rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
* Assert that DELETE call is Unauthorized.
*
* @param endPoint the endpoint
- * @throws Exception if an error occurs
*/
- protected void assertUnauthorizedDelete(final String endPoint) throws Exception {
+ protected void assertUnauthorizedDelete(final String endPoint) {
Response rawresp = sendNoAuthRequest(endPoint).delete();
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
hibernate:
dialect: org.hibernate.dialect.HSQLDialect
-server:
- servlet:
- context-path: /onap/automationcomposition
-
runtime:
participantParameters:
updateParameters: