2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.so.adapters.cnf.service.aai;
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;
31 import java.nio.charset.StandardCharsets;
34 class AaiIdGeneratorService {
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();
44 return Hashing.sha256()
45 .hashString(originalString, StandardCharsets.UTF_8)