2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
19 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
20 import org.openecomp.sdc.heat.datatypes.HeatBoolean;
21 import org.openecomp.sdc.heat.services.HeatConstants;
22 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
23 import org.openecomp.sdc.tosca.services.DataModelUtil;
24 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
25 import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
26 import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
31 public class ResourceTranslationCinderVolumeImpl extends ResourceTranslationBase {
33 private static final String VOLUME_SIZE_PROPERTY_NAME = "size";
36 public void translate(TranslateTo translateTo) {
37 NodeTemplate nodeTemplate = new NodeTemplate();
38 nodeTemplate.setType(ToscaNodeType.CINDER_VOLUME);
39 nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
40 .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
41 translateTo.getResourceId(), translateTo.getResource().getProperties(),
42 nodeTemplate.getProperties(), translateTo.getHeatFileName(),
43 translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
44 nodeTemplate, translateTo.getContext()));
45 handleSizeProperty(nodeTemplate.getProperties());
46 String toscaReadOnlyPropName =
47 HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.READ_ONLY_PROPERTY_NAME);
48 Object readOnlyPropVal = nodeTemplate.getProperties().get(toscaReadOnlyPropName);
49 if (readOnlyPropVal != null && !(readOnlyPropVal instanceof Map)) {
50 nodeTemplate.getProperties().put(toscaReadOnlyPropName, HeatBoolean.eval(readOnlyPropVal));
52 DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
57 private void handleSizeProperty(Map<String, Object> nodeTemplateProperties) {
58 Object size = nodeTemplateProperties.get(VOLUME_SIZE_PROPERTY_NAME);
62 if (size instanceof Map) {
63 Map<String, Object> propMap = (Map) size;
64 Map.Entry<String, Object> entry = propMap.entrySet().iterator().next();
65 String val = "(" + entry.getKey() + " : " + entry.getValue() + ") * 1024";
66 nodeTemplateProperties.put(VOLUME_SIZE_PROPERTY_NAME, val);
68 nodeTemplateProperties.put(VOLUME_SIZE_PROPERTY_NAME, size + "*1024");