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.informationArtifact.impl;
23 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
24 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
25 import org.openecomp.sdc.vendorsoftwareproduct.factory.QuestionnnaireDataServiceFactory;
26 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData;
27 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
28 import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService;
29 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
30 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.Compute;
31 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.GuestOS;
32 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.NumOfVMs;
33 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.Hypervisor;
34 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.Recovery;
35 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.IpConfiguration;
36 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.Network;
37 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.NicQuestionnaire;
38 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.VspQuestionnaire;
39 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.Availability;
40 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.General;
41 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.StorageDataReplication;
42 import org.openecomp.sdc.versioning.dao.types.Version;
44 import java.util.List;
45 import java.util.Optional;
47 import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.*;
51 * @since November 23, 2016
54 public class TxtInformationArtifactGeneratorImpl implements InformationArtifactGenerator {
55 private QuestionnaireDataService questionnaireDataService = QuestionnnaireDataServiceFactory
56 .getInstance().createInterface();
57 private StringBuilder textArtifact;
58 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
61 public String generate(String vspId, Version version) {
62 InformationArtifactData informationArtifactData =
63 questionnaireDataService.generateQuestionnaireDataForInformationArtifact(vspId, version);
64 return createTxtArtifact(informationArtifactData);
67 private String createTxtArtifact(InformationArtifactData informationArtifactData) {
70 mdcDataDebugMessage.debugEntryMessage(null);
72 textArtifact = new StringBuilder(TxtInformationArtifactConstants.HEADER);
73 addVspVlmEntries(informationArtifactData);
74 addAvailabilityEntries();
75 addDataEntries(informationArtifactData);
76 addEntryWithIndent(LIST_OF_VFCS, "", TAB);
77 addEntryWithIndent(FOR_EACH_VFC, "", TAB + TAB);
78 List<ComponentQuestionnaire> componentQuestionnaires =
79 informationArtifactData.getComponentQuestionnaires();
81 for (ComponentQuestionnaire componentQuestionnaire : componentQuestionnaires) {
82 addEntriesPerComponent(componentQuestionnaire);
86 List<NicQuestionnaire> nicQuestionnaires = informationArtifactData.getNicQuestionnaires();
87 for (NicQuestionnaire nicQuestionnaire : nicQuestionnaires) {
88 addEntriesPerNic(nicQuestionnaire);
91 for (ComponentQuestionnaire componentQuestionnaire : componentQuestionnaires) {
92 addRecoveryEntriesPerComponent(componentQuestionnaire);
94 textArtifact.append(TxtInformationArtifactConstants.FOOTER);
96 mdcDataDebugMessage.debugExitMessage(null);
97 return textArtifact.toString();
101 private void addDataEntries(InformationArtifactData informationArtifactData) {
104 mdcDataDebugMessage.debugEntryMessage(null);
106 addEntryWithIndent(STORAGE_BACKUP_DETAILS, "", TAB);
108 Optional<StorageDataReplication> storageDataReplication =
109 Optional.of(informationArtifactData).map(InformationArtifactData::getVspQuestionnaire)
110 .map(VspQuestionnaire::getGeneral).map(General::getStorageDataReplication);
111 storageDataReplication
112 .ifPresent(replication -> addEntryWithIndent(IS_DATA_REPLICATION,
113 String.valueOf(replication.isStorageReplicationAcrossRegion()), TAB + TAB));
116 storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_SIZE_TO_REP,
117 String.valueOf(rep.getStorageReplicationSize()), TAB + TAB));
119 storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_FREQUENCY,
120 String.valueOf(rep.getStorageReplicationFrequency()), TAB + TAB));
122 storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_SOURCE,
123 String.valueOf(rep.getStorageReplicationSource()), TAB + TAB));
125 storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_DEST,
126 String.valueOf(rep.getStorageReplicationDestination()), TAB + TAB));
128 mdcDataDebugMessage.debugExitMessage(null);
131 private void addAvailabilityEntries() {
132 mdcDataDebugMessage.debugEntryMessage(null);
134 addEntryWithIndent(HIGH_AVAILABILITY, "", TAB);
136 Optional<Availability> availability =
137 Optional.of(new InformationArtifactData()).map(InformationArtifactData::getVspQuestionnaire)
138 .map(VspQuestionnaire::getGeneral).map(General::getAvailability);
140 .ifPresent(availabilityVal -> addEntryWithIndent(USING_AVAILABILITY_ZONES, String.valueOf(
141 availabilityVal.isUseAvailabilityZonesForHighAvailability()), TAB + TAB));
143 mdcDataDebugMessage.debugExitMessage(null);
146 private void addVspVlmEntries(InformationArtifactData informationArtifactData) {
147 mdcDataDebugMessage.debugEntryMessage(null);
149 addEntryWithIndent(TITLE, "", "");
150 Optional<VspDetails> vspDetails = Optional.of(informationArtifactData).map
151 (InformationArtifactData::getVspDetails);
152 addEntryWithIndent(VSP_NAME, informationArtifactData.getVspDetails().getName(), TAB);
153 addEntryWithIndent(VSP_DESC, informationArtifactData.getVspDetails().getDescription(), TAB);
154 addEntryWithIndent(VSP_VERSION,
155 roundVersionAsNeeded(informationArtifactData.getVspDetails().getVersion()), TAB);
156 addEntryWithIndent(VSP_VENDOR, informationArtifactData.getVspDetails().getVendorName(), TAB);
157 addEntryWithIndent(VSP_CATEGORY, informationArtifactData.getVspDetails().getCategory(), TAB);
158 addEntryWithIndent(LICENSE_DETAILS, "", TAB);
159 addEntryWithIndent(LICENSE_MODEL_VERSION,
160 informationArtifactData.getVspDetails().getVlmVersion() == null
162 : informationArtifactData.getVspDetails().getVlmVersion().toString(),
164 addEntryWithIndent(LICENSE_AGREEMENT_NAME, informationArtifactData.getVspDetails()
165 .getLicenseAgreement(), TAB + TAB);
166 addEntryWithIndent(LIST_OF_FEATURE_GROUPS, "", TAB + TAB);
167 vspDetails.ifPresent(vspDets -> addListEntriesWithIndent(vspDets
168 .getFeatureGroups(), TAB + TAB + TAB));
170 mdcDataDebugMessage.debugExitMessage(null);
173 static String roundVersionAsNeeded(Version version) {
174 if (version.isFinal()) {
175 return version.toString();
177 return String.valueOf(Math.ceil(Double.valueOf(version.toString())));
181 private void addRecoveryEntriesPerComponent(ComponentQuestionnaire componentQuestionnaire) {
183 mdcDataDebugMessage.debugEntryMessage(null);
185 addEntryWithIndent(RECOVERY_DETAILS, "", TAB + TAB + TAB);
186 Optional<Recovery> recovery = Optional.of(componentQuestionnaire).map(
187 ComponentQuestionnaire::getGeneral).map(
188 org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general
189 .General::getRecovery);
190 recovery.ifPresent(recoveryVal -> addEntryWithIndent(RECOVERY_DETAILS_POINT, String.valueOf(
191 recoveryVal.getPointObjective()), TAB + TAB + TAB + TAB));
193 recovery.ifPresent(recoveryVal -> addEntryWithIndent(RECOVERY_DETAILS_TIME, String.valueOf(
194 recoveryVal.getTimeObjective()), TAB + TAB + TAB + TAB));
196 mdcDataDebugMessage.debugExitMessage(null);
199 private void addEntriesPerNic(NicQuestionnaire nicQuestionnaire) {
202 mdcDataDebugMessage.debugEntryMessage(null);
204 addEntryWithIndent(VNICS, "", TAB + TAB + TAB);
205 Optional<Network> networkOpt = Optional.of(nicQuestionnaire).map(
206 NicQuestionnaire::getNetwork);
208 networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_NAME, network
209 .getNetworkDescription(),
210 TAB + TAB + TAB + TAB));
211 networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_PURPOSE, network
212 .getNetworkDescription(), TAB + TAB + TAB + TAB));
213 networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_INT_EXT, network
214 .getNetworkDescription(), TAB + TAB + TAB + TAB));
215 networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_NETWORK, network.toString(),
216 TAB + TAB + TAB + TAB));
217 addEntryWithIndent(VNICS_PROTOCOLS, nicQuestionnaire.getProtocols().toString(),
218 TAB + TAB + TAB + TAB);
220 Optional<IpConfiguration> ipconfigOpt = Optional.of(nicQuestionnaire).map
221 (NicQuestionnaire::getIpConfiguration);
222 ipconfigOpt.ifPresent(ipconfig -> addEntryWithIndent(VNICS_IPV4, String.valueOf(ipconfig
223 .isIpv4Required()), TAB + TAB + TAB + TAB));
224 ipconfigOpt.ifPresent(ipconfig -> addEntryWithIndent(VNICS_IPV6, String.valueOf(ipconfig
225 .isIpv6Required()), TAB + TAB + TAB + TAB));
227 mdcDataDebugMessage.debugExitMessage(null);
230 private void addEntriesPerComponent(ComponentQuestionnaire componentQuestionnaire) {
233 mdcDataDebugMessage.debugEntryMessage(null);
235 addEntryWithIndent(VFC_NAME, "", TAB + TAB + TAB);
236 addEntryWithIndent(VFC_DESC, "", TAB + TAB + TAB);
237 addEntryWithIndent(VFC_IMAGES, "", TAB + TAB + TAB);
238 //todo component name +desc +img+vcpu
239 addEntryWithIndent(VFC_COMPUTE, "", TAB + TAB + TAB);
240 addEntryWithIndent(VFC_COMPUTE_VCPU, "", TAB + TAB + TAB + TAB);
241 addEntryWithIndent(VFC_COMPUTE_CPU_OVER_SUBSCRIPTION, "",
242 TAB + TAB + TAB + TAB);
243 addEntryWithIndent(VFC_COMPUTE_MEMORY, "", TAB + TAB + TAB + TAB);
244 addEntryWithIndent(VFC_COMPUTE_DISK, "", TAB + TAB + TAB + TAB);
246 addEntryWithIndent(HYPERVISOR_DETAILS, "", TAB + TAB + TAB);
248 Optional<Hypervisor> hypervisorOpt = Optional.of(componentQuestionnaire).map(
249 ComponentQuestionnaire::getGeneral).map(
250 org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general
251 .General::getHypervisor);
252 hypervisorOpt.ifPresent(hypervisor -> addEntryWithIndent(HYPERVISOR_DETAILS_NAME, hypervisor
253 .getHypervisor(), TAB
256 hypervisorOpt.ifPresent(hypervisor -> addEntryWithIndent(HYPERVISOR_DETAILS_DRIVERS, hypervisor
257 .getDrivers(), TAB + TAB + TAB + TAB));
259 addEntryWithIndent(GUEST_OS_DETAILS, "", TAB + TAB + TAB);
260 Optional<GuestOS> guestOSOptional = Optional.of(componentQuestionnaire).map
261 (ComponentQuestionnaire::getCompute).map(Compute::getGuestOS);
262 guestOSOptional.ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_NAME, guestOs.getName(),
263 TAB + TAB + TAB + TAB));
267 .ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_BIT_SIZE, String.valueOf(guestOs
268 .getBitSize()), TAB + TAB + TAB + TAB));
269 guestOSOptional.ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_TOOLS, guestOs.getTools
270 (), TAB + TAB + TAB + TAB));
272 addEntryWithIndent(VFC_INSTANCE_NUMBER, "",
275 Optional<NumOfVMs> numVmsOpt = Optional.of(componentQuestionnaire).map
276 (ComponentQuestionnaire::getCompute).map(Compute::getNumOfVMs);
277 numVmsOpt.ifPresent(numVms -> addEntryWithIndent(VFC_INSTANCE_NUMBER_MIN, String.valueOf
278 (numVms.getMinimum()), TAB + TAB + TAB + TAB));
280 numVmsOpt.ifPresent(numVms -> addEntryWithIndent(VFC_INSTANCE_NUMBER_MAX, String.valueOf
281 (numVms.getMaximum()), TAB + TAB + TAB + TAB));
284 mdcDataDebugMessage.debugExitMessage(null);
287 private void addListEntriesWithIndent(List<String> fieldValues, String indent) {
289 if (fieldValues == null) {
292 for (String fieldValue : fieldValues) {
293 textArtifact.append(indent).append(counter++).append(".").append(TAB).append(fieldValue)
301 private void addEntryWithIndent(String fieldName, String fieldValue, String indent) {
302 textArtifact.append(indent).append(fieldName).append(SPACE).append(fieldValue).append(NL);