2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2023 Nordix Foundation. All rights reserved.
4 * Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
5 * ===============================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END========================================================================
20 package com.oransc.rappmanager.dme.service;
22 import com.fasterxml.jackson.databind.ObjectMapper;
23 import com.oransc.rappmanager.dme.data.ConsumerJob;
24 import com.oransc.rappmanager.dme.data.ProducerRegistrationInfo;
25 import com.oransc.rappmanager.dme.rest.DataProducerRegistrationApiClient;
26 import com.oransc.rappmanager.models.RappDeployer;
27 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
28 import com.oransc.rappmanager.models.rapp.Rapp;
29 import com.oransc.rappmanager.models.rappinstance.RappInstance;
30 import java.util.HashSet;
32 import lombok.RequiredArgsConstructor;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.stereotype.Service;
38 @RequiredArgsConstructor
39 public class DmeDeployer implements RappDeployer {
41 Logger logger = LoggerFactory.getLogger(DmeDeployer.class);
43 private final DataProducerRegistrationApiClient dataProducerRegistrationApiClient;
45 private final RappCsarConfigurationHandler rappCsarConfigurationHandler;
47 private final ObjectMapper objectMapper;
50 public boolean deployRappInstance(Rapp rapp, RappInstance rappInstance) {
51 logger.debug("DME instance deployment is handled as part of ACM injection for {}",
52 rappInstance.getRappInstanceId());
57 public boolean undeployRappInstance(Rapp rapp, RappInstance rappInstance) {
58 logger.debug("DME instance undeployment is handled as part of ACM injection for {}",
59 rappInstance.getRappInstanceId());
64 public boolean primeRapp(Rapp rapp) {
65 logger.debug("Priming DME functions for rApp {}", rapp.getRappId());
66 if (rapp.isDMEEnabled()) {
68 Set<String> requiredInfoTypes = new HashSet<>();
69 for (String producerResourceName : rapp.getRappResources().getDme().getInfoProducers()) {
70 String producerPayload =
71 rappCsarConfigurationHandler.getDmeInfoProducerPayload(rapp, producerResourceName);
72 ProducerRegistrationInfo producerRegistrationInfo =
73 objectMapper.readValue(producerPayload, ProducerRegistrationInfo.class);
74 requiredInfoTypes.addAll(producerRegistrationInfo.getSupportedInfoTypes());
76 for (String consumerResourceName : rapp.getRappResources().getDme().getInfoConsumers()) {
77 String consumerPayload =
78 rappCsarConfigurationHandler.getDmeInfoConsumerPayload(rapp, consumerResourceName);
79 ConsumerJob consumerJob = objectMapper.readValue(consumerPayload, ConsumerJob.class);
80 requiredInfoTypes.add(consumerJob.getInfoTypeId());
82 Set<String> allInfoTypes = new HashSet<>(rapp.getRappResources().getDme().getProducerInfoTypes());
83 allInfoTypes.addAll(rapp.getRappResources().getDme().getConsumerInfoTypes());
84 requiredInfoTypes.removeAll(allInfoTypes);
85 if (!requiredInfoTypes.isEmpty()) {
86 allInfoTypes.addAll(dataProducerRegistrationApiClient.getInfoTypdentifiers());
87 requiredInfoTypes.removeAll(allInfoTypes);
88 if (!requiredInfoTypes.isEmpty()) {
90 String.format("Invalid rapp package as the following info types cannot be found %s",
95 } catch (Exception e) {
96 logger.warn("Failed to prime DME", e);
97 rapp.setReason("Failed to prime DME");
105 public boolean deprimeRapp(Rapp rapp) {
106 logger.debug("Depriming DME functions for rApp {}", rapp.getRappId());