import java.net.MalformedURLException;
import java.net.URL;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
import org.onap.so.client.aai.AAIProperties;
import org.onap.so.client.aai.AAIVersion;
import org.onap.so.spring.SpringContextHelper;
public class AaiPropertiesExt implements AAIProperties {
+ private static final String MSO = "MSO";
+
private final String endpoint;
private final String encryptedBasicAuth;
private final String encryptionKey;
public AaiPropertiesExt() {
final ApplicationContext context = SpringContextHelper.getAppContext();
- this.endpoint = context.getEnvironment().getProperty("aai.endpoint");
- this.encryptedBasicAuth = context.getEnvironment().getProperty("aai.auth");
- this.encryptionKey = context.getEnvironment().getProperty("mso.key");
+ final ConfigProperties configProperties = context.getBean(ConfigProperties.class);
+ this.endpoint = configProperties.getAaiEndpoint();
+ this.encryptedBasicAuth = configProperties.getAaiAuth();
+ this.encryptionKey = configProperties.getMsoKey();
}
@Override
@Override
public String getSystemName() {
- return "MSO";
+ return MSO;
}
@Override
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * SO
+ * ================================================================================
+ * Copyright (C) 2020 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.onap.so.adapters.vevnfm.configuration;
+
+import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class ConfigProperties {
+
+ @Value("${vevnfmadapter.vnf-filter-json}")
+ private String vevnfmadapterVnfFilterJson;
+
+ @Value("${vevnfmadapter.endpoint}")
+ private String vevnfmadapterEndpoint;
+
+ @Value("${mso.key}")
+ private String msoKey;
+
+ @Value("${aai.endpoint}")
+ private String aaiEndpoint;
+
+ @Value("${aai.auth}")
+ private String aaiAuth;
+
+ @Value("${vnfm.default-endpoint}")
+ private String vnfmDefaultEndpoint;
+
+ @Value("${vnfm.subscription}")
+ private String vnfmSubscription;
+
+ @Value("${vnfm.notification}")
+ private String vnfmNotification;
+
+ @Value("${notification.vnf-filter-type}")
+ private NotificationVnfFilterType notificationVnfFilterType;
+
+ @Value("${dmaap.endpoint}")
+ private String dmaapEndpoint;
+
+ @Value("${dmaap.topic}")
+ private String dmaapTopic;
+
+ @Value("${dmaap.closed-loop.control.name}")
+ private String dmaapClosedLoopControlName;
+
+ @Value("${dmaap.version}")
+ private String dmaapVersion;
+
+ @Value("${spring.security.usercredentials[0].username}")
+ private String springSecurityUsername;
+
+ @Value("${spring.security.usercredentials[0].openpass}")
+ private String springSecurityOpenpass;
+
+ public String getVevnfmadapterVnfFilterJson() {
+ return vevnfmadapterVnfFilterJson;
+ }
+
+ public String getVevnfmadapterEndpoint() {
+ return vevnfmadapterEndpoint;
+ }
+
+ public String getMsoKey() {
+ return msoKey;
+ }
+
+ public String getAaiEndpoint() {
+ return aaiEndpoint;
+ }
+
+ public String getAaiAuth() {
+ return aaiAuth;
+ }
+
+ public String getVnfmDefaultEndpoint() {
+ return vnfmDefaultEndpoint;
+ }
+
+ public String getVnfmSubscription() {
+ return vnfmSubscription;
+ }
+
+ public String getVnfmNotification() {
+ return vnfmNotification;
+ }
+
+ public NotificationVnfFilterType getNotificationVnfFilterType() {
+ return notificationVnfFilterType;
+ }
+
+ public String getDmaapEndpoint() {
+ return dmaapEndpoint;
+ }
+
+ public String getDmaapTopic() {
+ return dmaapTopic;
+ }
+
+ public String getDmaapClosedLoopControlName() {
+ return dmaapClosedLoopControlName;
+ }
+
+ public String getDmaapVersion() {
+ return dmaapVersion;
+ }
+
+ public String getSpringSecurityUsername() {
+ return springSecurityUsername;
+ }
+
+ public String getSpringSecurityOpenpass() {
+ return springSecurityOpenpass;
+ }
+}
public static final String TEST_PROFILE = "test";
- @Autowired
- private Environment environment;
-
- @Autowired
- private StartupService startupService;
+ private final Environment environment;
+ private final StartupService startupService;
+ private final SubscriptionScheduler subscriptionScheduler;
@Autowired
- private SubscriptionScheduler subscriptionScheduler;
+ public StartupConfiguration(final Environment environment, final StartupService startupService,
+ final SubscriptionScheduler subscriptionScheduler) {
+ this.environment = environment;
+ this.startupService = startupService;
+ this.subscriptionScheduler = subscriptionScheduler;
+ }
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReadyEvent() throws Exception {
package org.onap.so.adapters.vevnfm.constant;
/**
- * Which incoming Notification with particular VNF id is supported
+ * Select which incoming Notification with particular VNF id should be supported
*/
-public enum VnfNotificationFilterType {
+public enum NotificationVnfFilterType {
/**
* None
*/
package org.onap.so.adapters.vevnfm.controller;
-import org.onap.so.adapters.vevnfm.constant.VnfNotificationFilterType;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
+import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
import org.onap.so.adapters.vevnfm.service.DmaapService;
import org.onap.so.adapters.vevnfm.service.VnfAaiChecker;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
private static final Logger logger = LoggerFactory.getLogger(NotificationController.class);
- private final VnfNotificationFilterType vnfFilterType;
+ private final NotificationVnfFilterType notificationVnfFilterType;
private final VnfAaiChecker vnfAaiChecker;
private final DmaapService dmaapService;
@Autowired
- public NotificationController(
- @Value("${notification.vnf-filter-type}") final VnfNotificationFilterType vnfFilterType,
- final VnfAaiChecker vnfAaiChecker, final DmaapService dmaapService) {
- this.vnfFilterType = vnfFilterType;
+ public NotificationController(final ConfigProperties configProperties, final VnfAaiChecker vnfAaiChecker,
+ final DmaapService dmaapService) {
+ this.notificationVnfFilterType = configProperties.getNotificationVnfFilterType();
this.vnfAaiChecker = vnfAaiChecker;
this.dmaapService = dmaapService;
}
final String vnfInstanceId = notification.getVnfInstanceId();
- if (vnfAaiChecker.vnfCheck(vnfFilterType, vnfInstanceId)) {
+ if (vnfAaiChecker.vnfCheck(notificationVnfFilterType, vnfInstanceId)) {
logger.info("The info with the VNF id '{}' is sent to DMaaP", vnfInstanceId);
dmaapService.send(notification);
} else {
package org.onap.so.adapters.vevnfm.service;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
import org.onap.so.adapters.vevnfm.event.DmaapEvent;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification;
import org.onap.so.rest.service.HttpRestServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
private static final Logger logger = LoggerFactory.getLogger(DmaapService.class);
- @Value("${dmaap.endpoint}")
- private String endpoint;
-
- @Value("${dmaap.topic}")
- private String topic;
-
- @Value("${dmaap.closed-loop.control.name}")
- private String closedLoopControlName;
-
- @Value("${dmaap.version}")
- private String version;
+ private final String endpoint;
+ private final String topic;
+ private final String closedLoopControlName;
+ private final String version;
+ private final HttpRestServiceProvider restProvider;
@Autowired
- private HttpRestServiceProvider restProvider;
+ public DmaapService(final ConfigProperties configProperties, final HttpRestServiceProvider restProvider) {
+ this.endpoint = configProperties.getDmaapEndpoint();
+ this.topic = configProperties.getDmaapTopic();
+ this.closedLoopControlName = configProperties.getDmaapClosedLoopControlName();
+ this.version = configProperties.getDmaapVersion();
+ this.restProvider = restProvider;
+ }
public void send(final VnfLcmOperationOccurrenceNotification notification) {
try {
import java.util.List;
import org.onap.aai.domain.yang.EsrSystemInfo;
import org.onap.so.adapters.vevnfm.aai.AaiConnection;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.retry.annotation.Recover;
private static final Logger logger = LoggerFactory.getLogger(StartupService.class);
- @Value("${vnfm.default-endpoint}")
- private String vnfmDefaultEndpoint;
+ private final String vnfmDefaultEndpoint;
+ private final AaiConnection aaiConnection;
@Autowired
- private AaiConnection aaiConnection;
+ public StartupService(final ConfigProperties configProperties, final AaiConnection aaiConnection) {
+ this.vnfmDefaultEndpoint = configProperties.getVnfmDefaultEndpoint();
+ this.aaiConnection = aaiConnection;
+ }
@Retryable(value = {Exception.class}, maxAttempts = 5, backoff = @Backoff(delay = 5000, multiplier = 2))
public List<EsrSystemInfo> receiveVnfm() throws VeVnfmException {
import com.fasterxml.jackson.annotation.JsonProperty;
import org.onap.aai.domain.yang.EsrSystemInfo;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
import org.onap.so.rest.service.HttpRestServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
private static final Logger logger = LoggerFactory.getLogger(SubscribeSender.class);
- @Value("${vnfm.subscription}")
- private String vnfmSubscription;
+ private final String vnfmSubscription;
+ private final HttpRestServiceProvider restProvider;
@Autowired
- private HttpRestServiceProvider restProvider;
+ public SubscribeSender(final ConfigProperties configProperties, final HttpRestServiceProvider restProvider) {
+ this.vnfmSubscription = configProperties.getVnfmSubscription();
+ this.restProvider = restProvider;
+ }
public String send(final EsrSystemInfo info, final LccnSubscriptionRequest request) throws VeVnfmException {
final ResponseEntity<SubscribeToManoResponse> response =
import java.util.Collections;
import org.apache.logging.log4j.util.Strings;
import org.onap.aai.domain.yang.EsrSystemInfo;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
import org.onap.so.adapters.vevnfm.provider.AuthorizationHeadersProvider;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthenticationParamsBasic;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsFilter;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
private static final Gson gson = new Gson();
- @Value("${vevnfmadapter.vnf-filter-json}")
- private String vnfFilter;
-
- @Value("${vevnfmadapter.endpoint}")
- private String endpoint;
-
- @Value("${vnfm.notification}")
- private String notification;
-
- @Value("${spring.security.usercredentials[0].username}")
- private String username;
-
- @Value("${spring.security.usercredentials[0].openpass}")
- private String openpass;
+ private final String vnfFilter;
+ private final String endpoint;
+ private final String notification;
+ private final String username;
+ private final String openpass;
+ private final AuthorizationHeadersProvider headersProvider;
+ private final SubscribeSender sender;
@Autowired
- private AuthorizationHeadersProvider headersProvider;
-
- @Autowired
- private SubscribeSender sender;
+ public SubscriberService(final ConfigProperties configProperties,
+ final AuthorizationHeadersProvider headersProvider, final SubscribeSender sender) {
+ this.vnfFilter = configProperties.getVevnfmadapterVnfFilterJson();
+ this.endpoint = configProperties.getVevnfmadapterEndpoint();
+ this.notification = configProperties.getVnfmNotification();
+ this.username = configProperties.getSpringSecurityUsername();
+ this.openpass = configProperties.getSpringSecurityOpenpass();
+ this.headersProvider = headersProvider;
+ this.sender = sender;
+ }
private static String getAuthorization(final EsrSystemInfo info) {
if (info == null) {
private static final Logger logger = LoggerFactory.getLogger(SubscriptionScheduler.class);
- @Autowired
- private SubscriberService subscriberService;
-
+ private final SubscriberService subscriberService;
private List<EsrId> esrIds;
+ @Autowired
+ public SubscriptionScheduler(final SubscriberService subscriberService) {
+ this.subscriberService = subscriberService;
+ }
+
public void setInfos(final List<EsrSystemInfo> infos) {
esrIds = new LinkedList<>();
package org.onap.so.adapters.vevnfm.service;
import org.onap.so.adapters.vevnfm.aai.AaiConnection;
-import org.onap.so.adapters.vevnfm.constant.VnfNotificationFilterType;
+import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
this.aaiConnection = aaiConnection;
}
- public boolean vnfCheck(final VnfNotificationFilterType filterType, final String vnfId) {
+ public boolean vnfCheck(final NotificationVnfFilterType filterType, final String vnfId) {
switch (filterType) {
case ALL:
return true;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
private static final String MINIMAL_JSON_CONTENT = "{}";
private static final int ZERO = 0;
- @Value("${vnfm.notification}")
- private String notification;
+ @Autowired
+ private ConfigProperties configProperties;
@Autowired
private WebApplicationContext webApplicationContext;
@Autowired
private RestTemplate restTemplate;
+ private String notification;
private MockMvc mvc;
private MockRestServiceServer mockRestServer;
@Before
public void init() {
+ notification = configProperties.getVnfmNotification();
mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
mockRestServer = MockRestServiceServer.bindTo(restTemplate).build();
}
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.aai.domain.yang.EsrSystemInfo;
import org.onap.so.adapters.vevnfm.aai.AaiConnection;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
@RunWith(MockitoJUnitRunner.class)
public class StartupServiceTest {
private static final String URL = "rt";
+ private static final String ENDPOINT = "localhost";
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Mock
+ private ConfigProperties configProperties;
+
@Mock
private AaiConnection aaiConnection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.aai.domain.yang.EsrSystemInfo;
+import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration;
import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
GSON = builder.create();
}
- @Value("${vnfm.subscription}")
- private String vnfmSubscription;
+ @Autowired
+ private ConfigProperties configProperties;
@Autowired
private SubscribeSender sender;
@Autowired
private RestTemplate restTemplate;
+ private String vnfmSubscription;
private MockRestServiceServer mockRestServer;
@Before
public void init() {
+ vnfmSubscription = configProperties.getVnfmSubscription();
mockRestServer = MockRestServiceServer.bindTo(restTemplate).build();
}
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.so.adapters.vevnfm.aai.AaiConnection;
-import org.onap.so.adapters.vevnfm.constant.VnfNotificationFilterType;
+import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
@RunWith(MockitoJUnitRunner.class)
public class VnfAaiCheckerTest {
@Test
public void testAll() {
// when
- final boolean response = checker.vnfCheck(VnfNotificationFilterType.ALL, VNF_ID);
+ final boolean response = checker.vnfCheck(NotificationVnfFilterType.ALL, VNF_ID);
// then
assertTrue(response);
when(aaiConnection.checkGenericVnfId(eq(VNF_ID))).thenReturn(true);
// when
- final boolean response = checker.vnfCheck(VnfNotificationFilterType.AAI_CHECKED, VNF_ID);
+ final boolean response = checker.vnfCheck(NotificationVnfFilterType.AAI_CHECKED, VNF_ID);
// then
assertTrue(response);
when(aaiConnection.checkGenericVnfId(eq(VNF_ID))).thenReturn(false);
// when
- final boolean response = checker.vnfCheck(VnfNotificationFilterType.AAI_CHECKED, VNF_ID);
+ final boolean response = checker.vnfCheck(NotificationVnfFilterType.AAI_CHECKED, VNF_ID);
// then
assertFalse(response);
@Test
public void testNone() {
// when
- final boolean response = checker.vnfCheck(VnfNotificationFilterType.NONE, VNF_ID);
+ final boolean response = checker.vnfCheck(NotificationVnfFilterType.NONE, VNF_ID);
// then
assertFalse(response);