2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.job.command;
23 import static org.apache.commons.collections4.MapUtils.emptyIfNull;
25 import org.apache.commons.lang3.StringUtils;
26 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
27 import org.onap.vid.aai.model.ModelVer;
28 import org.onap.vid.model.Group;
29 import org.onap.vid.model.GroupProperties;
30 import org.onap.vid.model.ServiceModel;
31 import org.onap.vid.model.VfModule;
32 import org.onap.vid.mso.model.ModelInfo;
33 import org.onap.vid.services.AaiService;
34 import org.onap.vid.services.VidService;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
39 public class CommandUtils {
41 private static final EELFLoggerDelegate Logger = EELFLoggerDelegate.getLogger(CommandUtils.class);
43 private final VidService vidService;
44 private final AaiService aaiService;
47 public CommandUtils(VidService vidService, AaiService aaiService) {
48 this.vidService = vidService;
49 this.aaiService = aaiService;
52 public boolean isVfModuleBaseModule(String serviceModelUuid, ModelInfo vfModuleModelInfo) {
53 ServiceModel serviceModel = getServiceModel(serviceModelUuid);
55 return emptyIfNull(serviceModel.getVfModules())
57 .filter(toscaModelInfo -> modelsMatch(vfModuleModelInfo, toscaModelInfo))
58 .map(Group::getProperties)
59 .map(GroupProperties::getBaseModule)
60 .findAny().orElseGet(() -> {
61 Logger.debug(EELFLoggerDelegate.debugLogger,
62 "Could not find vfModule in model with uuid {}, assuming not base module ({})",
63 serviceModelUuid, vfModuleModelInfo);
68 private boolean modelsMatch(ModelInfo instanceModelInfo, VfModule toscaModelInfo) {
69 return StringUtils.equals(toscaModelInfo.getCustomizationUuid(), instanceModelInfo.getModelCustomizationId())
70 || StringUtils.equals(toscaModelInfo.getModelCustomizationName(), instanceModelInfo.getModelCustomizationName());
73 public ServiceModel getServiceModel(String serviceModelUuid) {
74 return vidService.getServiceModelOrThrow(serviceModelUuid);
77 public String getNewestModelUuid(String serviceModelInvariantId) {
78 ModelVer serviceModelLatestVersion = aaiService.getNewestModelVersionByInvariantId(serviceModelInvariantId);
79 return serviceModelLatestVersion.getModelVersionId();