1 package org.openecomp.sdc.healing.healers;
4 import org.openecomp.core.model.dao.ServiceModelDao;
5 import org.openecomp.core.model.dao.ServiceModelDaoFactory;
6 import org.openecomp.core.model.dao.ServiceTemplateDaoFactory;
7 import org.openecomp.core.model.dao.ServiceTemplateDaoInter;
8 import org.openecomp.core.model.types.ServiceElement;
9 import org.openecomp.core.translator.datatypes.TranslatorOutput;
10 import org.openecomp.core.utilities.file.FileContentHandler;
11 import org.openecomp.sdc.common.utils.CommonUtil;
12 import org.openecomp.sdc.common.utils.SdcCommon;
13 import org.openecomp.sdc.healing.interfaces.Healer;
14 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
15 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
16 import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
17 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
18 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory;
19 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
20 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
21 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
22 import org.openecomp.sdc.versioning.dao.types.Version;
25 import java.util.Objects;
26 import java.util.Optional;
28 public class HeatToToscaTranslationHealer implements Healer {
30 private static final OrchestrationTemplateDao orchestrationTemplateDao =
31 OrchestrationTemplateDaoFactory.getInstance().createInterface();
32 private static final ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao =
33 ServiceModelDaoFactory.getInstance().createInterface();
34 public static final ServiceTemplateDaoInter
35 templateDao = ServiceTemplateDaoFactory.getInstance().createInterface();
36 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
38 public HeatToToscaTranslationHealer(){
43 public Object heal(Map<String, Object> healingParams) throws Exception {
44 mdcDataDebugMessage.debugEntryMessage(null, null);
45 String vspId = (String) healingParams.get(SdcCommon.VSP_ID);
46 Version version = (Version) healingParams.get(SdcCommon.VERSION);
47 String user = (String) healingParams.get(SdcCommon.USER);
48 UploadDataEntity uploadData =
49 orchestrationTemplateDao.getOrchestrationTemplate(vspId, version);
51 if (Objects.isNull(uploadData) || Objects.isNull(uploadData.getContentData())) {
52 return Optional.empty();
55 FileContentHandler fileContentHandler;
56 TranslatorOutput translatorOutput;
58 fileContentHandler = CommonUtil.loadUploadFileContent(uploadData
59 .getContentData().array());
61 HeatToToscaUtil.loadAndTranslateTemplateData(fileContentHandler);
63 return Optional.empty();
66 if(Objects.isNull(translatorOutput)){
67 return Optional.empty();
70 if (translatorOutput != null && translatorOutput.getToscaServiceModel() == null) {
71 return Optional.empty();
73 //templateDao.deleteAll(vspId, version);
74 serviceModelDao.deleteAll(vspId,version);
75 serviceModelDao.storeServiceModel(vspId, version,
76 translatorOutput.getToscaServiceModel());
77 mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
79 return translatorOutput;