From 04d12d50d1d6144008b49f4484e879a3e145885c Mon Sep 17 00:00:00 2001 From: "Claudio D. Gasparini" Date: Mon, 3 May 2021 16:36:20 +0200 Subject: [PATCH] OAM NF Adopter REST PM PM to VES Issue-ID: OAM-206 Signed-off-by: Claudio D. Gasparini Change-Id: If25ad51ca5ff346f5d9fd27d2f6514f5f9a55ecc --- ves-nf-oam-adopter/pom.xml | 1 + .../ves-nf-oam-adopter-artifacts/pom.xml | 5 + .../ves-nf-oam-adopter-parent/pom.xml | 10 +- .../ves-nf-oam-adopter-pm-manager/pom.xml | 108 ++++++++++++++++++ .../adopter/pm/rest/manager/AdaptersDeployer.java | 100 ++++++++++++++++ .../PerformanceManagementMapperConfigProvider.java | 85 ++++++++++++++ .../manager/PerformanceManagementRestAgent.java | 80 +++++++++++++ .../PerformanceManagementRestAgentFactory.java | 97 ++++++++++++++++ .../pm/rest/manager/api/HttpRestClient.java | 13 +++ .../api/PerformanceManagementAdaptersDeployer.java | 59 ++++++++++ .../PerformanceManagementRestManagerConfig.java | 57 +++++++++ .../exceptions/AlreadyPresentException.java | 28 +++++ .../rest/manager/exceptions/NotFoundException.java | 28 +++++ .../PerformanceManagementEmptyOutputException.java | 37 ++++++ .../exceptions/PerformanceManagementException.java | 41 +++++++ .../exceptions/TokenGenerationException.java | 38 ++++++ .../rest/manager/exceptions/ZoneIdException.java | 38 ++++++ .../manager/mapper/CommonEventHeaderHandler.java | 83 ++++++++++++++ .../manager/mapper/MeasurementFieldsHandler.java | 82 +++++++++++++ .../PerformanceManagementFile2VesMapper.java | 127 +++++++++++++++++++++ .../oam/adopter/pm/rest/manager/pojos/Adapter.java | 34 ++++++ .../pm/rest/manager/pojos/CsvConfiguration.java | 42 +++++++ .../manager/pojos/VesMappingConfiguration.java | 49 ++++++++ .../PerformanceManagementManagerProperties.java | 36 ++++++ 24 files changed, 1277 insertions(+), 1 deletion(-) create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/pom.xml create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/AdaptersDeployer.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementMapperConfigProvider.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementRestAgent.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementRestAgentFactory.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/api/HttpRestClient.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/api/PerformanceManagementAdaptersDeployer.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/configurations/PerformanceManagementRestManagerConfig.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/AlreadyPresentException.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/NotFoundException.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/PerformanceManagementEmptyOutputException.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/PerformanceManagementException.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/TokenGenerationException.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/ZoneIdException.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/CommonEventHeaderHandler.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/MeasurementFieldsHandler.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/PerformanceManagementFile2VesMapper.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/Adapter.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/CsvConfiguration.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/VesMappingConfiguration.java create mode 100644 ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/properties/PerformanceManagementManagerProperties.java diff --git a/ves-nf-oam-adopter/pom.xml b/ves-nf-oam-adopter/pom.xml index aa53ec3..c116ba1 100644 --- a/ves-nf-oam-adopter/pom.xml +++ b/ves-nf-oam-adopter/pom.xml @@ -50,5 +50,6 @@ ves-nf-oam-adopter-api ves-nf-oam-adopter-event-notifier ves-nf-oam-adopter-snmp-manager + ves-nf-oam-adopter-pm-manager \ No newline at end of file diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-artifacts/pom.xml b/ves-nf-oam-adopter/ves-nf-oam-adopter-artifacts/pom.xml index 63cb23f..eac13ad 100644 --- a/ves-nf-oam-adopter/ves-nf-oam-adopter-artifacts/pom.xml +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-artifacts/pom.xml @@ -66,6 +66,11 @@ ves-nf-oam-adopter-snmp-manager ${project.version} + + ${project.groupId} + ves-nf-oam-adopter-pm-manager + ${project.version} + \ No newline at end of file diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-parent/pom.xml b/ves-nf-oam-adopter/ves-nf-oam-adopter-parent/pom.xml index a694efe..aa697e4 100644 --- a/ves-nf-oam-adopter/ves-nf-oam-adopter-parent/pom.xml +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-parent/pom.xml @@ -44,7 +44,9 @@ ../ves-nf-oam-adopter-event-notifier/target/site/jacoco-ut/jacoco.xml, ../ves-nf-oam-adopter-event-notifier/target/site/jacoco-aggregate/jacoco.xml, ../ves-nf-oam-adopter-snmp-manager/target/site/jacoco-ut/jacoco.xml, - ../ves-nf-oam-adopter-snmp-manager/target/site/jacoco-aggregate/jacoco.xml + ../ves-nf-oam-adopter-snmp-manager/target/site/jacoco-aggregate/jacoco.xml, + ../ves-nf-oam-adopter-pm-manager/target/site/jacoco-ut/jacoco.xml, + ../ves-nf-oam-adopter-pm-manager/target/site/jacoco-aggregate/jacoco.xml 3.8.0.2131 @@ -52,6 +54,7 @@ 2.6 1.9.4 2.8.6 + 30.1-jre 5.0.3 2.2.600 1.18.20 @@ -134,6 +137,11 @@ commons-beanutils ${commons-beanutils.version} + + com.google.guava + guava + ${guava.version} + com.github.spotbugs spotbugs-annotations diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/pom.xml b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/pom.xml new file mode 100644 index 0000000..02b4f98 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/pom.xml @@ -0,0 +1,108 @@ + + + + 4.0.0 + + + org.o-ran-sc.oam + ves-nf-oam-adopter-parent + 1.0.0-SNAPSHOT + ../ves-nf-oam-adopter-parent/pom.xml + + + ves-nf-oam-adopter-pm-manager + + + + ${project.groupId} + ves-nf-oam-adopter-api + + + org.apache.httpcomponents.client5 + httpclient5 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.dataformat + jackson-dataformat-csv + + + commons-io + commons-io + + + org.apache.commons + commons-configuration2 + + + commons-beanutils + commons-beanutils + + + com.google.guava + guava + 30.1-jre + + + io.reactivex.rxjava3 + rxjava + + + org.projectlombok + lombok + + + org.slf4j + slf4j-api + + + com.google.code.gson + gson + + + com.github.spotbugs + spotbugs-annotations + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-test + test + + + \ No newline at end of file diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/AdaptersDeployer.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/AdaptersDeployer.java new file mode 100644 index 0000000..924373d --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/AdaptersDeployer.java @@ -0,0 +1,100 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager; + +import static org.eclipse.jdt.annotation.Checks.requireNonNull; + +import com.google.common.collect.ImmutableList; +import java.time.ZoneId; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.api.PerformanceManagementAdaptersDeployer; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.exceptions.AlreadyPresentException; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.exceptions.NotFoundException; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos.Adapter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public final class AdaptersDeployer implements PerformanceManagementAdaptersDeployer, AutoCloseable { + + private static final Logger LOG = LoggerFactory.getLogger(AdaptersDeployer.class); + + private final PerformanceManagementRestAgentFactory pmRestAgentFactory; + private final Map adapters = new ConcurrentHashMap<>(); + + @Autowired + public AdaptersDeployer(final PerformanceManagementRestAgentFactory pmRestAgentFactory) { + this.pmRestAgentFactory = pmRestAgentFactory; + } + + @Override + public synchronized void create(final String hostIpAddress, final String username, final String password) + throws AlreadyPresentException { + LOG.info("Create device PM adapter {}", hostIpAddress); + if (adapters.get(hostIpAddress) != null) { + throw new AlreadyPresentException(hostIpAddress); + } + final Adapter adapter = + Adapter.builder().username(username).password(password).hostIpAddress(hostIpAddress).build(); + final PerformanceManagementRestAgent pmRestAgent = + pmRestAgentFactory.createPerformanceManagementRestAgent(adapter).blockingGet(); + pmRestAgent.init(); + adapters.put(hostIpAddress, pmRestAgent); + } + + @Override + public synchronized void delete(final String host) throws NotFoundException { + LOG.info("Adapter PM adapter removed {}", requireNonNull(host)); + final PerformanceManagementRestAgent adapter = adapters.remove(host); + if (adapter == null) { + throw new NotFoundException(host); + } + adapter.close(); + } + + @Override + public List getAll() { + return ImmutableList.copyOf(adapters.keySet()); + } + + @Override + public ZoneId getTimeZone(final String host) { + LOG.debug("Read time zone for {}", host); + return Optional.ofNullable(adapters.get(host)).map( + PerformanceManagementRestAgent::getTimeZone).orElse(null); + } + + @Override + public synchronized void close() { + for (final String host : ImmutableList.copyOf(adapters.keySet())) { + try { + delete(host); + } catch (final Exception e) { + LOG.warn("Failed to delete device PM adapter {}", host); + } + } + adapters.clear(); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementMapperConfigProvider.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementMapperConfigProvider.java new file mode 100644 index 0000000..b7c24f8 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementMapperConfigProvider.java @@ -0,0 +1,85 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager; + +import static java.util.Objects.requireNonNull; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import java.io.IOException; +import java.io.StringWriter; +import java.net.URI; +import java.nio.file.Paths; +import javax.annotation.PostConstruct; +import org.apache.commons.configuration2.YAMLConfiguration; +import org.apache.commons.configuration2.builder.ConfigurationBuilderEvent; +import org.apache.commons.configuration2.builder.ReloadingFileBasedConfigurationBuilder; +import org.apache.commons.configuration2.builder.fluent.Parameters; +import org.apache.commons.configuration2.event.EventListener; +import org.apache.commons.configuration2.ex.ConfigurationException; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos.VesMappingConfiguration; +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.stereotype.Service; + +@Service +public class PerformanceManagementMapperConfigProvider { + + private static final Logger LOG = LoggerFactory.getLogger(PerformanceManagementMapperConfigProvider.class); + + private static final ObjectMapper YAML_READER = new ObjectMapper(new YAMLFactory()); + @Value("${pm-rest-manager.mapping-config-path:#{null}}") + private String mappingFilePath; + private ReloadingFileBasedConfigurationBuilder builder; + + @Autowired + public PerformanceManagementMapperConfigProvider() { + + } + + /** + * Initialize Service. + */ + @PostConstruct + public void init() throws IOException, ConfigurationException { + requireNonNull(mappingFilePath); + final URI filePath = Paths.get(mappingFilePath).toUri(); + builder = new ReloadingFileBasedConfigurationBuilder<>(YAMLConfiguration.class) + .configure(new Parameters().hierarchical().setURL(filePath.toURL())); + builder.addEventListener(ConfigurationBuilderEvent.CONFIGURATION_REQUEST, (EventListener) event -> { + builder.getReloadingController().checkForReloading(null); + LOG.debug("Reloading {}", filePath.toString()); + }); + //Test initial configuration + builder.getConfiguration(); + } + + /** + * Provide VES Mapping configuration. + */ + public VesMappingConfiguration getVesMappingConfiguration() throws ConfigurationException, IOException { + final YAMLConfiguration configuration = builder.getConfiguration(); + final StringWriter output = new StringWriter(); + configuration.write(output); + return YAML_READER.readValue(output.toString(), VesMappingConfiguration.class); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementRestAgent.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementRestAgent.java new file mode 100644 index 0000000..66693fc --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementRestAgent.java @@ -0,0 +1,80 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager; + +import java.time.Duration; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public final class PerformanceManagementRestAgent implements AutoCloseable { + + private static final DateTimeFormatter TIME_INPUT_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss"); + private final ScheduledExecutorService scheduler; + private final Runnable pmAgent; + private final LocalTime synchronizationTimeStart; + private final int synchronizationTimeFrequency; + private final ZoneId zoneId; + + + PerformanceManagementRestAgent(final Runnable pmAgent, final String synchronizationTimeStart, + final int synchronizationTimeFrequency, final ZoneId zoneId) { + this.scheduler = Executors.newSingleThreadScheduledExecutor(); + this.pmAgent = pmAgent; + this.synchronizationTimeStart = LocalTime.parse(synchronizationTimeStart, TIME_INPUT_FORMAT); + this.synchronizationTimeFrequency = synchronizationTimeFrequency; + this.zoneId = zoneId; + } + + /** + * Initialize service at fixed rate. + */ + public void init() { + final long initialDelay = initialDelay(); + scheduler.scheduleAtFixedRate(pmAgent, initialDelay, synchronizationTimeFrequency, TimeUnit.SECONDS); + } + + private long initialDelay() { + final ZonedDateTime now = ZonedDateTime.now(zoneId); + + ZonedDateTime nextRun = now + .withHour(synchronizationTimeStart.getHour()) + .withMinute(synchronizationTimeStart.getMinute()) + .withSecond(synchronizationTimeStart.getSecond()); + if (now.compareTo(nextRun) > 0) { + nextRun = nextRun.plusSeconds(synchronizationTimeFrequency); + } + final Duration duration = Duration.between(now, nextRun); + return duration.getSeconds(); + } + + public ZoneId getTimeZone() { + return zoneId; + } + + @Override + public void close() { + scheduler.shutdown(); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementRestAgentFactory.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementRestAgentFactory.java new file mode 100644 index 0000000..0ebaa6c --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/PerformanceManagementRestAgentFactory.java @@ -0,0 +1,97 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager; + +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.core.Single; +import io.reactivex.rxjava3.schedulers.Schedulers; +import org.o.ran.oam.nf.oam.adopter.api.VesEventNotifier; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.api.HttpRestClient; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.mapper.PerformanceManagementFile2VesMapper; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos.Adapter; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.properties.PerformanceManagementManagerProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PerformanceManagementRestAgentFactory { + private static final Logger LOG = LoggerFactory.getLogger(PerformanceManagementRestAgentFactory.class); + + private final VesEventNotifier eventListener; + private final PerformanceManagementManagerProperties properties; + private final PerformanceManagementFile2VesMapper pmFileMapper; + private final HttpRestClient httpRestClient; + + /** + * Default constructor. + */ + public PerformanceManagementRestAgentFactory(final VesEventNotifier eventListener, + final PerformanceManagementFile2VesMapper pmFileMapper, + final PerformanceManagementManagerProperties properties, final HttpRestClient httpRestClient) { + this.eventListener = eventListener; + this.pmFileMapper = pmFileMapper; + this.properties = properties; + this.httpRestClient = httpRestClient; + } + + /** + * Generates new PM Agent which will get pm files via rest at specific time each day and + * send it as CommonEventFormat302ONAP event via rest. + * @param adapter IP address fo the adapter, adapter login username, adapter login password + * @return PMRestAgent + */ + public final Single createPerformanceManagementRestAgent(final Adapter adapter) { + return httpRestClient.getTimeZone(adapter).map(timeZone -> { + final PerformanceManagementAgentRunnable pmAgentRunnable = + new PerformanceManagementAgentRunnable(httpRestClient, eventListener, pmFileMapper, adapter); + return new PerformanceManagementRestAgent(pmAgentRunnable, properties.getSynchronizationTimeStart(), + properties.getSynchronizationTimeFrequency(), timeZone); + }); + } + + private static class PerformanceManagementAgentRunnable implements Runnable { + final HttpRestClient httpClient; + private final VesEventNotifier pmEventListener; + private final PerformanceManagementFile2VesMapper pmFileMapper; + private final Adapter adapter; + + public PerformanceManagementAgentRunnable(final HttpRestClient httpClient, + final VesEventNotifier pmEventListener, + final PerformanceManagementFile2VesMapper pmFileMapper, final Adapter adapter) { + this.httpClient = httpClient; + this.pmEventListener = pmEventListener; + this.pmFileMapper = pmFileMapper; + this.adapter = adapter; + } + + @Override + public synchronized void run() { + final String hostIp = adapter.getHostIpAddress(); + httpClient.readFiles(adapter) + .flatMap(zip -> pmFileMapper.map(zip, hostIp)) + .flatMapCompletable(events -> Observable.fromIterable(events) + .concatMapCompletable(pmEventListener::notifyEvents)) + .doOnSubscribe(result -> LOG.info("PM VES notification forwarding for adapter {} started", hostIp)) + .doOnComplete(() -> LOG.info("PM VES notification forwarding for adapter {} finished", hostIp)) + .doOnError(error -> LOG.warn("PM VES notification forwarding for adapter {} failed", hostIp)) + .subscribeOn(Schedulers.single()) + .subscribe(); + } + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/api/HttpRestClient.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/api/HttpRestClient.java new file mode 100644 index 0000000..71a27ea --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/api/HttpRestClient.java @@ -0,0 +1,13 @@ +package org.o.ran.oam.nf.oam.adopter.pm.rest.manager.api; + +import io.reactivex.rxjava3.core.Single; +import java.time.ZoneId; +import java.util.zip.ZipInputStream; +import org.eclipse.jdt.annotation.NonNull; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos.Adapter; + +public interface HttpRestClient { + @NonNull Single readFiles(@NonNull Adapter adapter); + + @NonNull Single getTimeZone(@NonNull Adapter adapter); +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/api/PerformanceManagementAdaptersDeployer.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/api/PerformanceManagementAdaptersDeployer.java new file mode 100644 index 0000000..01be898 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/api/PerformanceManagementAdaptersDeployer.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.api; + +import java.time.ZoneId; +import java.util.List; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.exceptions.AlreadyPresentException; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.exceptions.NotFoundException; + +public interface PerformanceManagementAdaptersDeployer { + + /** + * Creates PM Adapter. + * + * @param hostIpAddress adapter ip address + * @param username mechid username + * @param password mechid password + * @throws AlreadyPresentException if already present + */ + void create(@NonNull String hostIpAddress, @NonNull String username, @NonNull String password) + throws AlreadyPresentException; + + /** + * Removes PM Adapter by host ip address. + * + * @param host ip address + * @throws NotFoundException if not present + */ + void delete(@NonNull String host) throws NotFoundException; + + /** + * Returns list of Adapters host Ip. + */ + @NonNull List getAll(); + + /** + * Returns time zone of specific device. + */ + @Nullable ZoneId getTimeZone(@NonNull String host); +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/configurations/PerformanceManagementRestManagerConfig.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/configurations/PerformanceManagementRestManagerConfig.java new file mode 100644 index 0000000..0a88e80 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/configurations/PerformanceManagementRestManagerConfig.java @@ -0,0 +1,57 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.configurations; + +import org.o.ran.oam.nf.oam.adopter.api.VesEventNotifier; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.PerformanceManagementRestAgentFactory; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.api.HttpRestClient; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.mapper.PerformanceManagementFile2VesMapper; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.properties.PerformanceManagementManagerProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties +public class PerformanceManagementRestManagerConfig { + private final PerformanceManagementManagerProperties pmManagerProperties; + private final VesEventNotifier eventListener; + private final PerformanceManagementFile2VesMapper pmFileMapper; + + /** + * Default constructor. + */ + @Autowired + public PerformanceManagementRestManagerConfig(final VesEventNotifier eventListener, + final PerformanceManagementFile2VesMapper pmFileMapper, + final PerformanceManagementManagerProperties pmManagerProperties) { + this.eventListener = eventListener; + this.pmFileMapper = pmFileMapper; + this.pmManagerProperties = pmManagerProperties; + } + + @Bean + PerformanceManagementRestAgentFactory getPerformanceManagementRestManagerFactoryService( + final HttpRestClient httpRestClient) { + return new PerformanceManagementRestAgentFactory(eventListener, pmFileMapper, pmManagerProperties, + httpRestClient); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/AlreadyPresentException.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/AlreadyPresentException.java new file mode 100644 index 0000000..9199daa --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/AlreadyPresentException.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.exceptions; + +public class AlreadyPresentException extends PerformanceManagementException { + private static final long serialVersionUID = -1852996415384288431L; + + public AlreadyPresentException(final String adapter) { + super("Adapter " + adapter + " already present."); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/NotFoundException.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/NotFoundException.java new file mode 100644 index 0000000..4179fb9 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/NotFoundException.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.exceptions; + +public class NotFoundException extends PerformanceManagementException { + private static final long serialVersionUID = -1852996415384288431L; + + public NotFoundException(final String adapter) { + super("Adapter " + adapter + " is not present."); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/PerformanceManagementEmptyOutputException.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/PerformanceManagementEmptyOutputException.java new file mode 100644 index 0000000..492e13c --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/PerformanceManagementEmptyOutputException.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.exceptions; + +/** + * Object already exists exception. + */ +public class PerformanceManagementEmptyOutputException extends PerformanceManagementException { + + private static final long serialVersionUID = 1L; + + /** + * Create object already exists exception. + * + * @param message exception message + */ + public PerformanceManagementEmptyOutputException(final String message) { + super(message); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/PerformanceManagementException.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/PerformanceManagementException.java new file mode 100644 index 0000000..f39dac8 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/PerformanceManagementException.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.exceptions; + +/** + * Object already exists exception. + */ +public class PerformanceManagementException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** + * Create object already exists exception. + * + * @param message exception message + */ + public PerformanceManagementException(final String message) { + super(message); + } + + public PerformanceManagementException(final String message, final Throwable cause) { + super(message, cause); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/TokenGenerationException.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/TokenGenerationException.java new file mode 100644 index 0000000..6441e98 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/TokenGenerationException.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.exceptions; + +/** + * Object already exists exception. + */ +public class TokenGenerationException extends PerformanceManagementException { + + private static final long serialVersionUID = 1L; + + /** + * Create object already exists exception. + * + * @param message exception message + */ + public TokenGenerationException(final String message) { + super(message); + } + +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/ZoneIdException.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/ZoneIdException.java new file mode 100644 index 0000000..4552533 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/exceptions/ZoneIdException.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.exceptions; + +/** + * Object already exists exception. + */ +public class ZoneIdException extends PerformanceManagementException { + + private static final long serialVersionUID = 1L; + + /** + * Create object already exists exception. + * + * @param message exception message + */ + public ZoneIdException(final String message, final Throwable cause) { + super(message, cause); + } + +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/CommonEventHeaderHandler.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/CommonEventHeaderHandler.java new file mode 100644 index 0000000..7049285 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/CommonEventHeaderHandler.java @@ -0,0 +1,83 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.mapper; + +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.o.ran.oam.nf.oam.adopter.api.CommonEventHeader; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos.CsvConfiguration; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos.VesMappingConfiguration; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +final class CommonEventHeaderHandler { + private static final String PM_NOTIFICATIONS = "PM_Notification"; + + static CommonEventHeader toCommonEventHeader(final VesMappingConfiguration config, final String hostIp, + final CsvConfiguration csv, final Map record, final int sequence) { + final CommonEventHeader header = new CommonEventHeader(); + setMandatoryFields(config, hostIp, csv, header, record, sequence); + setOptionalFields(config, header); + return header; + } + + private static void setOptionalFields(final VesMappingConfiguration config, final CommonEventHeader header) { + header.setNfVendorName(Optional.ofNullable(config.getNfVendorName()).orElse(null)); + header.setReportingEntityId(config.getReportingEntityId()); + header.setNfNamingCode(null); //NOP + header.setNfcNamingCode(null); //NOP + header.setTimeZoneOffset(null); //NOP + } + + private static void setMandatoryFields(final VesMappingConfiguration config, final String hostIp, + final CsvConfiguration csv, final CommonEventHeader header, final Map record, + final int sequence) { + header.setDomain(CommonEventHeader.Domain.MEASUREMENT); + header.setEventName(CommonEventHeader.Domain.FAULT.name() + + "_" + config.getReportingEntityName() + + "_" + Optional.ofNullable(config.getEventName()).orElse(PM_NOTIFICATIONS)); + header.setStartEpochMicrosec(System.currentTimeMillis()); + header.setLastEpochMicrosec(System.currentTimeMillis()); + header.setPriority(CommonEventHeader.Priority.fromValue(config.getPriority())); + header.setReportingEntityName(config.getReportingEntityName()); + header.setSequence((long) sequence); + final String sourceNameField = csv.getSourceName(); + final String sourceNameRecordValue = Optional.ofNullable(sourceNameField).map(record::get).orElse(hostIp); + final Optional optRegex = Optional.ofNullable(csv.getSourceNameRegex()); + header.setSourceName(optRegex.map(regex -> sourceNameRecordValue.replaceAll(regex, "")) + .orElse(sourceNameRecordValue)); + header.setVersion(CommonEventHeader.Version._4_0); + header.setVesEventListenerVersion(Optional.ofNullable(config.getVesEventListenerVersion()) + .map(CommonEventHeader.VesEventListenerVersion::fromValue) + .orElse(CommonEventHeader.VesEventListenerVersion._7_1)); + + final List eventId = csv.getEventId(); + final String keyIdConcat = eventId.stream() + .filter(record::containsKey) + .map(record::get) + .collect(Collectors.joining()); + header.setEventId(UUID.nameUUIDFromBytes(keyIdConcat.getBytes(StandardCharsets.UTF_8)).toString()); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/MeasurementFieldsHandler.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/MeasurementFieldsHandler.java new file mode 100644 index 0000000..166af50 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/MeasurementFieldsHandler.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.mapper; + +import java.util.Collections; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.o.ran.oam.nf.oam.adopter.api.MeasurementFields; +import org.o.ran.oam.nf.oam.adopter.api.NamedHashMap; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos.CsvConfiguration; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos.VesMappingConfiguration; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +final class MeasurementFieldsHandler { + private static void setOptionalsFields(final MeasurementFields measurementFields, final Map records, + final VesMappingConfiguration config) { + final CsvConfiguration csv = config.getCsv(); + measurementFields.setAdditionalFields(csv.getAdditionalFields() + .stream().filter(records::containsKey) + .collect(Collectors.toMap(Function.identity(), records::get))); + + final NamedHashMap namedHashMap = new NamedHashMap(); + namedHashMap.setName(csv.getAdditionalMeasurementsName()); + namedHashMap.setHashMap(csv.getAdditionalMeasurements().stream() + .filter(records::containsKey) + .collect(Collectors.toMap(Function.identity(), records::get))); + measurementFields.setAdditionalMeasurements(Collections.singletonList(namedHashMap)); + measurementFields.setAdditionalObjects(null); + measurementFields.setCodecUsageArray(null); + measurementFields.setConfiguredEntities(null); + measurementFields.setCpuUsageArray(null); + measurementFields.setDiskUsageArray(null); + measurementFields.setFeatureUsageArray(null); + measurementFields.setFilesystemUsageArray(null); + measurementFields.setHugePagesArray(null); + measurementFields.setIpmi(null); + measurementFields.setLatencyDistribution(null); + measurementFields.setLoadArray(null); + measurementFields.setMachineCheckExceptionArray(null); + measurementFields.setMeanRequestLatency(null); + measurementFields.setMemoryUsageArray(null); + measurementFields.setNfcScalingMetric(null); + measurementFields.setNicPerformanceArray(null); + measurementFields.setNumberOfMediaPortsInUse(null); + measurementFields.setProcessStatsArray(null); + measurementFields.setRequestRate(null); + } + + static MeasurementFields toMeasurementFields(final VesMappingConfiguration config, + final Map records) { + final MeasurementFields measurementFields = new MeasurementFields(); + setMandatoryFields(measurementFields, config); + setOptionalsFields(measurementFields, records, config); + return measurementFields; + } + + private static void setMandatoryFields(final MeasurementFields measurementFields, + final VesMappingConfiguration config) { + measurementFields.setMeasurementFieldsVersion(MeasurementFields.MeasurementFieldsVersion._4_0); + measurementFields.setMeasurementInterval(config.getMeasurementInterval()); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/PerformanceManagementFile2VesMapper.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/PerformanceManagementFile2VesMapper.java new file mode 100644 index 0000000..6036a93 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/mapper/PerformanceManagementFile2VesMapper.java @@ -0,0 +1,127 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.mapper; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.dataformat.csv.CsvMapper; +import com.fasterxml.jackson.dataformat.csv.CsvSchema; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import io.reactivex.rxjava3.core.Single; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import org.o.ran.oam.nf.oam.adopter.api.CommonEventFormat302ONAP; +import org.o.ran.oam.nf.oam.adopter.api.Event; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.PerformanceManagementMapperConfigProvider; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos.CsvConfiguration; +import org.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos.VesMappingConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class PerformanceManagementFile2VesMapper { + private static final Logger LOG = LoggerFactory.getLogger(PerformanceManagementFile2VesMapper.class); + + private static final String CSV_EXTENSION = ".csv"; + private final PerformanceManagementMapperConfigProvider pmConfigProvider; + + @Autowired + public PerformanceManagementFile2VesMapper(final PerformanceManagementMapperConfigProvider pmConfigProvider) { + this.pmConfigProvider = pmConfigProvider; + } + + /** + * Translate CSV in ZipInputStream format to list of CommonEventFormat302ONAP events. + * + * @param zipInputStream csv + * @param hostIp source Ip Address + * @return CommonEventFormat302ONAP events + */ + @SuppressFBWarnings("REC_CATCH_EXCEPTION") + public Single> map(final ZipInputStream zipInputStream, final String hostIp) { + LOG.info("Converting ZIP files to VES Message started"); + final List listOfNotifications = new ArrayList<>(); + final CsvSchema schema = CsvSchema.emptySchema().withHeader(); + final CsvMapper mapper = new CsvMapper(); + mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false); + try { + ZipEntry entry; + final VesMappingConfiguration mappingConfiguration = pmConfigProvider.getVesMappingConfiguration(); + while ((entry = zipInputStream.getNextEntry()) != null) { + final String entryName = entry.getName(); + if (!entryName.endsWith(CSV_EXTENSION)) { + return Single.error(new Exception("Wrong file type :" + entryName)); + } + + final Iterator> iterator = + mapper.readerFor(Map.class).with(schema).readValues(zipInputStream); + final List> mappedEvents = toEvent(mappingConfiguration, hostIp, iterator); + + mappedEvents.forEach(mapped -> { + final CommonEventFormat302ONAP eventFormat = new CommonEventFormat302ONAP(); + eventFormat.setEventList(mapped); + listOfNotifications.add(eventFormat); + }); + } + } catch (final Exception e) { + return Single.error(new Exception("Failed to process file", e)); + } finally { + try { + zipInputStream.closeEntry(); + } catch (final IOException e) { + LOG.warn("Failed to close zip stream", e); + } + } + LOG.info("Converting ZIP files to VES Message finished"); + return Single.just(listOfNotifications); + } + + private static List> toEvent(final VesMappingConfiguration mappingConfiguration, final String hostIp, + final Iterator> iterator) { + final List> globalList = new ArrayList<>(); + final int batchSize = mappingConfiguration.getBatchSize(); + int sequence = 0; + List events = new ArrayList<>(); + final CsvConfiguration csv = mappingConfiguration.getCsv(); + while (iterator.hasNext()) { + final Event event = new Event(); + final Map record = iterator.next(); + event.setCommonEventHeader( + CommonEventHeaderHandler.toCommonEventHeader(mappingConfiguration, hostIp, csv, record, sequence)); + event.setMeasurementFields(MeasurementFieldsHandler.toMeasurementFields(mappingConfiguration, record)); + events.add(event); + sequence++; + if (sequence % batchSize == 0) { + globalList.add(events); + events = new ArrayList<>(); + } + } + if (!events.isEmpty()) { + globalList.add(events); + } + return globalList; + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/Adapter.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/Adapter.java new file mode 100644 index 0000000..555634b --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/Adapter.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos; + +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; + +@EqualsAndHashCode +@Getter +@Builder +public final class Adapter { + private @NonNull final String hostIpAddress; + private @NonNull final String username; + private @NonNull final String password; +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/CsvConfiguration.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/CsvConfiguration.java new file mode 100644 index 0000000..cdb7617 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/CsvConfiguration.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class CsvConfiguration { + @JsonProperty("additional-fields") + private List additionalFields; + @JsonProperty("additional-measurements-name") + private String additionalMeasurementsName; + @JsonProperty("additional-measurements") + private List additionalMeasurements; + @JsonProperty("event-id") + private List eventId; + @JsonProperty("source-name") + private String sourceName; + @JsonProperty("source-name-regex") + private String sourceNameRegex; +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/VesMappingConfiguration.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/VesMappingConfiguration.java new file mode 100644 index 0000000..3d4ea11 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/pojos/VesMappingConfiguration.java @@ -0,0 +1,49 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.pojos; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class VesMappingConfiguration { + @JsonProperty("reporting-entity-name") + private String reportingEntityName; + @JsonProperty("reporting-entity-id") + private String reportingEntityId; + @JsonProperty("nf-vendor-name") + private String nfVendorName; + @JsonProperty("event-source-type") + private String eventSourceType; + @JsonProperty("event-name") + private String eventName; + @JsonProperty("measurement-interval") + private Long measurementInterval; + @JsonProperty("csv") + private CsvConfiguration csv; + @JsonProperty("batch-size") + private int batchSize; + @JsonProperty("priority") + private String priority; + @JsonProperty("ves-event-listener-version") + private String vesEventListenerVersion; +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/properties/PerformanceManagementManagerProperties.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/properties/PerformanceManagementManagerProperties.java new file mode 100644 index 0000000..2a3af54 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-pm-manager/src/main/java/org/o/ran/oam/nf/oam/adopter/pm/rest/manager/properties/PerformanceManagementManagerProperties.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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.o.ran.oam.nf.oam.adopter.pm.rest.manager.properties; + +import javax.validation.constraints.NotEmpty; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "pm-rest-manager") +@Data +@NoArgsConstructor +public class PerformanceManagementManagerProperties { + @NotEmpty + private String synchronizationTimeStart; + private int synchronizationTimeFrequency; +} -- 2.16.6