f8e24f95aefdaf181554d634ce2f7d9f94ea31b7
[so/adapters/so-cnf-adapter.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved.
6  * Modifications Copyright (C) 2021 Orange.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.so.adapters.cnf.service.aai;
23
24 import com.google.common.hash.Hashing;
25 import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
26 import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceGvk;
27 import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceResourceStatus;
28 import org.onap.so.adapters.cnf.model.statuscheck.K8sStatusMetadata;
29 import org.springframework.stereotype.Service;
30
31 import java.nio.charset.StandardCharsets;
32
33 @Service
34 class AaiIdGeneratorService {
35
36     String generateId(K8sRbInstanceResourceStatus resourceStatus, AaiRequest aaiRequest) {
37         K8sRbInstanceGvk gvk = resourceStatus.getGvk();
38         K8sStatusMetadata metadata = resourceStatus.getStatus().getK8sStatusMetadata();
39         String originalString = aaiRequest.getInstanceId() + resourceStatus.getName() +
40                 (metadata.getNamespace() != null ? metadata.getNamespace() : "") +
41                 gvk.getKind() + gvk.getGroup() + gvk.getVersion() +
42                 aaiRequest.getCloudOwner() + aaiRequest.getCloudRegion() + aaiRequest.getTenantId();
43
44         return Hashing.sha256()
45                 .hashString(originalString, StandardCharsets.UTF_8)
46                 .toString();
47     }
48
49 }