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.vendorsoftwareproduct.dao.type.VspDetails;
24 import org.openecomp.sdc.vendorsoftwareproduct.factory.QuestionnnaireDataServiceFactory;
25 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData;
26 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
27 import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService;
28 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
29 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.Compute;
30 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.GuestOS;
31 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.NumOfVMs;
32 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.Hypervisor;
33 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.Recovery;
34 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.IpConfiguration;
35 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.Network;
36 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.NicQuestionnaire;
37 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.VspQuestionnaire;
38 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.Availability;
39 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.General;
40 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.StorageDataReplication;
41 import org.openecomp.sdc.versioning.dao.types.Version;
43 import java.util.List;
44 import java.util.Optional;
46 import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.*;
50 * @since November 23, 2016
53 public class TxtInformationArtifactGeneratorImpl implements InformationArtifactGenerator {
54 private QuestionnaireDataService questionnaireDataService = QuestionnnaireDataServiceFactory
55 .getInstance().createInterface();
56 private StringBuilder textArtifact;
58 public String generate(String vspId, Version version) {
59 InformationArtifactData informationArtifactData =
60 questionnaireDataService.generateQuestionnaireDataForInformationArtifact(vspId, version);
61 return createTxtArtifact(informationArtifactData);
64 private String createTxtArtifact(InformationArtifactData informationArtifactData) {
65 textArtifact = new StringBuilder();
66 addVspVlmEntries(informationArtifactData);
67 addAvailabilityEntries();
68 addDataEntries(informationArtifactData);
69 addEntryWithIndent(LIST_OF_VFCS, "", TAB);
70 addEntryWithIndent(FOR_EACH_VFC, "", TAB + TAB);
71 List<ComponentQuestionnaire> componentQuestionnaires =
72 informationArtifactData.getComponentQuestionnaires();
74 for (ComponentQuestionnaire componentQuestionnaire : componentQuestionnaires) {
75 addEntriesPerComponent(componentQuestionnaire);
79 List<NicQuestionnaire> nicQuestionnaires = informationArtifactData.getNicQuestionnaires();
80 for (NicQuestionnaire nicQuestionnaire : nicQuestionnaires) {
81 addEntriesPerNic(nicQuestionnaire);
84 for (ComponentQuestionnaire componentQuestionnaire : componentQuestionnaires) {
85 addRecoveryEntriesPerComponent(componentQuestionnaire);
87 return textArtifact.toString();
91 private void addDataEntries(InformationArtifactData informationArtifactData) {
92 addEntryWithIndent(STORAGE_BACKUP_DETAILS, "", TAB);
94 Optional<StorageDataReplication> storageDataReplication =
95 Optional.of(informationArtifactData).map(InformationArtifactData::getVspQuestionnaire)
96 .map(VspQuestionnaire::getGeneral).map(General::getStorageDataReplication);
97 storageDataReplication
98 .ifPresent(replication -> addEntryWithIndent(IS_DATA_REPLICATION,
99 String.valueOf(replication.isStorageReplicationAcrossRegion()), TAB + TAB));
102 storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_SIZE_TO_REP,
103 String.valueOf(rep.getStorageReplicationSize()), TAB + TAB));
105 storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_FREQUENCY,
106 String.valueOf(rep.getStorageReplicationFrequency()), TAB + TAB));
108 storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_SOURCE,
109 String.valueOf(rep.getStorageReplicationSource()), TAB + TAB));
111 storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_DEST,
112 String.valueOf(rep.getStorageReplicationDestination()), TAB + TAB));
115 private void addAvailabilityEntries() {
116 addEntryWithIndent(HIGH_AVAILABILITY, "", TAB);
118 Optional<Availability> availability =
119 Optional.of(new InformationArtifactData()).map(InformationArtifactData::getVspQuestionnaire)
120 .map(VspQuestionnaire::getGeneral).map(General::getAvailability);
122 .ifPresent(availabilityVal -> addEntryWithIndent(USING_AVAILABILITY_ZONES, String.valueOf(
123 availabilityVal.isUseAvailabilityZonesForHighAvailability()), TAB + TAB));
126 private void addVspVlmEntries(InformationArtifactData informationArtifactData) {
127 addEntryWithIndent(TITLE, "", "");
128 Optional<VspDetails> vspDetails = Optional.of(informationArtifactData).map
129 (InformationArtifactData::getVspDetails);
130 addEntryWithIndent(VSP_NAME, informationArtifactData.getVspDetails().getName(), TAB);
131 addEntryWithIndent(VSP_DESC, informationArtifactData.getVspDetails().getDescription(), TAB);
132 addEntryWithIndent(VSP_VERSION,
133 roundVersionAsNeeded(informationArtifactData.getVspDetails().getVersion()), TAB);
134 addEntryWithIndent(VSP_VENDOR, informationArtifactData.getVspDetails().getVendorName(), TAB);
135 addEntryWithIndent(VSP_CATEGORY, informationArtifactData.getVspDetails().getCategory(), TAB);
136 addEntryWithIndent(LICENSE_DETAILS, "", TAB);
137 addEntryWithIndent(LICENSE_MODEL_VERSION,
138 informationArtifactData.getVspDetails().getVlmVersion() == null
140 : informationArtifactData.getVspDetails().getVlmVersion().toString(),
142 addEntryWithIndent(LICENSE_AGREEMENT_NAME, informationArtifactData.getVspDetails()
143 .getLicenseAgreement(), TAB + TAB);
144 addEntryWithIndent(LIST_OF_FEATURE_GROUPS, "", TAB + TAB);
145 vspDetails.ifPresent(vspDets -> addListEntriesWithIndent(vspDets
146 .getFeatureGroups(), TAB + TAB + TAB));
149 static String roundVersionAsNeeded(Version version) {
150 if (version.isFinal()) {
151 return version.toString();
153 return String.valueOf(Math.ceil(Double.valueOf(version.toString())));
157 private void addRecoveryEntriesPerComponent(ComponentQuestionnaire componentQuestionnaire) {
158 addEntryWithIndent(RECOVERY_DETAILS, "", TAB + TAB + TAB);
159 Optional<Recovery> recovery = Optional.of(componentQuestionnaire).map(
160 ComponentQuestionnaire::getGeneral).map(
161 org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general
162 .General::getRecovery);
163 recovery.ifPresent(recoveryVal -> addEntryWithIndent(RECOVERY_DETAILS_POINT, String.valueOf(
164 recoveryVal.getPointObjective()), TAB + TAB + TAB + TAB));
166 recovery.ifPresent(recoveryVal -> addEntryWithIndent(RECOVERY_DETAILS_TIME, String.valueOf(
167 recoveryVal.getTimeObjective()), TAB + TAB + TAB + TAB));
170 private void addEntriesPerNic(NicQuestionnaire nicQuestionnaire) {
171 addEntryWithIndent(VNICS, "", TAB + TAB + TAB);
172 Optional<Network> networkOpt = Optional.of(nicQuestionnaire).map(
173 NicQuestionnaire::getNetwork);
175 networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_NAME, network
176 .getNetworkDescription(),
177 TAB + TAB + TAB + TAB));
178 networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_PURPOSE, network
179 .getNetworkDescription(), TAB + TAB + TAB + TAB));
180 networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_INT_EXT, network
181 .getNetworkDescription(), TAB + TAB + TAB + TAB));
182 networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_NETWORK, network.toString(),
183 TAB + TAB + TAB + TAB));
184 addEntryWithIndent(VNICS_PROTOCOLS, nicQuestionnaire.getProtocols() == null ? "" : nicQuestionnaire.getProtocols().toString(),
185 TAB + TAB + TAB + TAB);
187 Optional<IpConfiguration> ipconfigOpt = Optional.of(nicQuestionnaire).map
188 (NicQuestionnaire::getIpConfiguration);
189 ipconfigOpt.ifPresent(ipconfig -> addEntryWithIndent(VNICS_IPV4, String.valueOf(ipconfig
190 .isIpv4Required()), TAB + TAB + TAB + TAB));
191 ipconfigOpt.ifPresent(ipconfig -> addEntryWithIndent(VNICS_IPV6, String.valueOf(ipconfig
192 .isIpv6Required()), TAB + TAB + TAB + TAB));
195 private void addEntriesPerComponent(ComponentQuestionnaire componentQuestionnaire) {
196 addEntryWithIndent(VFC_NAME, "", TAB + TAB + TAB);
197 addEntryWithIndent(VFC_DESC, "", TAB + TAB + TAB);
198 addEntryWithIndent(VFC_IMAGES, "", TAB + TAB + TAB);
199 //todo component name +desc +img+vcpu
200 addEntryWithIndent(VFC_COMPUTE, "", TAB + TAB + TAB);
201 addEntryWithIndent(VFC_COMPUTE_VCPU, "", TAB + TAB + TAB + TAB);
202 addEntryWithIndent(VFC_COMPUTE_CPU_OVER_SUBSCRIPTION, "",
203 TAB + TAB + TAB + TAB);
204 addEntryWithIndent(VFC_COMPUTE_MEMORY, "", TAB + TAB + TAB + TAB);
205 addEntryWithIndent(VFC_COMPUTE_DISK, "", TAB + TAB + TAB + TAB);
207 addEntryWithIndent(HYPERVISOR_DETAILS, "", TAB + TAB + TAB);
209 Optional<Hypervisor> hypervisorOpt = Optional.of(componentQuestionnaire).map(
210 ComponentQuestionnaire::getGeneral).map(
211 org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general
212 .General::getHypervisor);
213 hypervisorOpt.ifPresent(hypervisor -> addEntryWithIndent(HYPERVISOR_DETAILS_NAME, hypervisor
214 .getHypervisor(), TAB
217 hypervisorOpt.ifPresent(hypervisor -> addEntryWithIndent(HYPERVISOR_DETAILS_DRIVERS, hypervisor
218 .getDrivers(), TAB + TAB + TAB + TAB));
220 addEntryWithIndent(GUEST_OS_DETAILS, "", TAB + TAB + TAB);
221 Optional<GuestOS> guestOSOptional = Optional.of(componentQuestionnaire).map
222 (ComponentQuestionnaire::getCompute).map(Compute::getGuestOS);
223 guestOSOptional.ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_NAME, guestOs.getName(),
224 TAB + TAB + TAB + TAB));
228 .ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_BIT_SIZE, String.valueOf(guestOs
229 .getBitSize()), TAB + TAB + TAB + TAB));
230 guestOSOptional.ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_TOOLS, guestOs.getTools
231 (), TAB + TAB + TAB + TAB));
233 addEntryWithIndent(VFC_INSTANCE_NUMBER, "",
236 Optional<NumOfVMs> numVmsOpt = Optional.of(componentQuestionnaire).map
237 (ComponentQuestionnaire::getCompute).map(Compute::getNumOfVMs);
238 numVmsOpt.ifPresent(numVms -> addEntryWithIndent(VFC_INSTANCE_NUMBER_MIN, String.valueOf
239 (numVms.getMinimum()), TAB + TAB + TAB + TAB));
241 numVmsOpt.ifPresent(numVms -> addEntryWithIndent(VFC_INSTANCE_NUMBER_MAX, String.valueOf
242 (numVms.getMaximum()), TAB + TAB + TAB + TAB));
245 private void addListEntriesWithIndent(List<String> fieldValues, String indent) {
247 if (fieldValues == null) {
250 for (String fieldValue : fieldValues) {
251 textArtifact.append(indent).append(counter++).append(".").append(TAB).append(fieldValue)
259 private void addEntryWithIndent(String fieldName, String fieldValue, String indent) {
260 textArtifact.append(indent).append(fieldName).append(SPACE).append(fieldValue).append(NL);