2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.sdc.vendorsoftwareproduct.util;
23 import org.openecomp.core.enrichment.types.ComponentArtifactType;
24 import org.openecomp.core.enrichment.types.ComponentCeilometerInfo;
25 import org.openecomp.core.enrichment.types.ComponentMibInfo;
26 import org.openecomp.core.enrichment.types.MibInfo;
27 import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
28 import org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory;
29 import org.openecomp.core.utilities.json.JsonUtil;
30 import org.openecomp.sdc.datatypes.error.ErrorMessage;
31 import org.openecomp.sdc.enrichment.impl.tosca.ComponentInfo;
32 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDaoFactory;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentArtifactEntity;
35 import org.openecomp.sdc.versioning.dao.types.Version;
38 import java.util.List;
42 * The type Compilation util.
44 public class CompilationUtil {
46 private static final ApplicationConfig applicationConfig =
47 ApplicationConfigFactory.getInstance().createInterface();
48 private static final ComponentArtifactDao componentArtifactDao =
49 ComponentArtifactDaoFactory.getInstance().createInterface();
52 * Add monitoring info.
54 * @param componentInfo the component info
55 * @param compileErrors the compile errors
57 public static void addMonitoringInfo(ComponentInfo componentInfo,
58 Map<String, List<ErrorMessage>> compileErrors) {
60 String ceilometerJson =
61 applicationConfig.getConfigurationData("vsp.monitoring", "component.ceilometer").getValue();
62 ComponentCeilometerInfo ceilometerInfo =
63 JsonUtil.json2Object(ceilometerJson, ComponentCeilometerInfo.class);
64 componentInfo.setCeilometerInfo(ceilometerInfo);
70 * @param vspId the vsp id
71 * @param version the version
72 * @param componentEntity the component entity
73 * @param componentInfo the component info
74 * @param compileErrors the compile errors
76 public static void addMibInfo(String vspId, Version version, org.openecomp.sdc
77 .vendorsoftwareproduct.dao.type.ComponentEntity componentEntity,
78 ComponentInfo componentInfo,
79 Map<String, List<ErrorMessage>> compileErrors) {
81 String componentId = componentEntity.getId();
83 ComponentArtifactEntity entity = new ComponentArtifactEntity();
84 entity.setVspId(vspId);
85 entity.setVersion(version);
86 entity.setComponentId(componentId);
88 ComponentMibInfo componentMibInfo = new ComponentMibInfo();
90 extractAndInsertMibContentToComponentInfo(componentId, ComponentArtifactType.SNMP_POLL, entity,
91 componentMibInfo, compileErrors);
92 extractAndInsertMibContentToComponentInfo(componentId, ComponentArtifactType.SNMP_TRAP, entity,
93 componentMibInfo, compileErrors);
94 componentInfo.setMibInfo(componentMibInfo);
97 private static void extractAndInsertMibContentToComponentInfo(String componentId,
98 ComponentArtifactType type,
99 ComponentArtifactEntity componentArtifactEntity,
100 ComponentMibInfo componentMibInfo,
101 Map<String, List<ErrorMessage>> compileErrors) {
103 componentArtifactEntity.setType(type);
104 ComponentArtifactEntity artifact =
105 componentArtifactDao.getArtifactByType(componentArtifactEntity);
107 if (artifact == null) {
110 path = componentId + File.separator + type.name();
111 MibInfo mibInfo = new MibInfo();
112 mibInfo.setName(path);
113 mibInfo.setContent(artifact.getArtifact().array());
116 componentMibInfo.setSnmpPoll(mibInfo);
119 componentMibInfo.setSnmpTrap(mibInfo);