2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.oransc.participant.dme.restclient;
23 import com.fasterxml.jackson.core.JsonProcessingException;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import com.oransc.participant.dme.data.ConsumerJob;
26 import com.oransc.participant.dme.data.ProducerInfoTypeInfo;
27 import com.oransc.participant.dme.data.ProducerRegistrationInfo;
28 import com.oransc.participant.dme.rest.DataConsumerApiClient;
29 import com.oransc.participant.dme.rest.DataProducerRegistrationApiClient;
32 import lombok.RequiredArgsConstructor;
33 import org.oransc.participant.dme.exception.DmeException;
34 import org.springframework.http.ResponseEntity;
35 import org.springframework.stereotype.Component;
38 @RequiredArgsConstructor
39 public class AcDmeClient {
41 private final DataProducerRegistrationApiClient dataProducerRegistrationApiClient;
42 private final DataConsumerApiClient dataConsumerApiClient;
43 private final ObjectMapper objectMapper;
45 public boolean isDmeHealthy() {
46 return dataProducerRegistrationApiClient.getInfoTypdentifiersWithHttpInfo().getStatusCode().is2xxSuccessful();
49 public void createInfoType(Map<String, String> infoTypeMap) throws DmeException, JsonProcessingException {
50 for (Map.Entry<String, String> entry : infoTypeMap.entrySet()) {
51 String infoTypeName = entry.getKey();
52 ProducerInfoTypeInfo infoTypeInfo = objectMapper.readValue(entry.getValue(), ProducerInfoTypeInfo.class);
53 ResponseEntity<Object> objectResponseEntity =
54 dataProducerRegistrationApiClient.putInfoTypeWithHttpInfo(infoTypeName, infoTypeInfo);
55 if (!objectResponseEntity.getStatusCode().is2xxSuccessful()) {
56 throw new DmeException(objectResponseEntity.getStatusCode().value(), "Error in creating info types");
61 public void createDataProducer(Map<String, String> dataProducerMap) throws DmeException, JsonProcessingException {
62 for (Map.Entry<String, String> entry : dataProducerMap.entrySet()) {
63 String infoProducerName = entry.getKey();
64 ProducerRegistrationInfo producerRegistrationInfo =
65 objectMapper.readValue(entry.getValue(), ProducerRegistrationInfo.class);
66 ResponseEntity<Object> objectResponseEntity =
67 dataProducerRegistrationApiClient.putInfoProducerWithHttpInfo(infoProducerName,
68 producerRegistrationInfo);
69 if (!objectResponseEntity.getStatusCode().is2xxSuccessful()) {
70 throw new DmeException(objectResponseEntity.getStatusCode().value(), "Error in creating data producer");
75 public void createDataConsumer(Map<String, String> dataConsumerMap) throws DmeException, JsonProcessingException {
76 for (Map.Entry<String, String> entry : dataConsumerMap.entrySet()) {
77 String infoProducerName = entry.getKey();
78 ConsumerJob consumerJob = objectMapper.readValue(entry.getValue(), ConsumerJob.class);
79 ResponseEntity<Object> objectResponseEntity =
80 dataConsumerApiClient.putIndividualInfoJobWithHttpInfo(infoProducerName, consumerJob);
81 if (!objectResponseEntity.getStatusCode().is2xxSuccessful()) {
82 throw new DmeException(objectResponseEntity.getStatusCode().value(), "Error in creating data consumer");
87 public void deleteDataProducer(Set<String> dataProducerList) throws DmeException {
88 for (String dataProducer : dataProducerList) {
89 ResponseEntity<Object> objectResponseEntity =
90 dataProducerRegistrationApiClient.deleteInfoProducerWithHttpInfo(dataProducer);
91 if (!objectResponseEntity.getStatusCode().is2xxSuccessful()) {
92 throw new DmeException(objectResponseEntity.getStatusCode().value(), "Error in deleting data producer");
97 public void deleteDataConsumer(Set<String> dataConsumerList) throws DmeException {
98 for (String dataConsumer : dataConsumerList) {
99 ResponseEntity<Object> objectResponseEntity =
100 dataConsumerApiClient.deleteIndividualInfoJobWithHttpInfo(dataConsumer);
101 if (!objectResponseEntity.getStatusCode().is2xxSuccessful()) {
102 throw new DmeException(objectResponseEntity.getStatusCode().value(), "Error in deleting data consumer");