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;
20 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
21 import org.openecomp.sdc.heat.datatypes.HeatBoolean;
22 import org.openecomp.sdc.heat.services.HeatConstants;
23 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
24 import org.openecomp.sdc.tosca.services.DataModelUtil;
25 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
26 import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
27 import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
30 public class ResourceTranslationCinderVolumeImpl extends ResourceTranslationBase {
32 private static final String VOLUME_SIZE_PROPERTY_NAME = "size";
35 public void translate(final TranslateTo translateTo) {
36 final NodeTemplate nodeTemplate = new NodeTemplate();
37 nodeTemplate.setType(ToscaNodeType.CINDER_VOLUME);
38 nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
39 .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
40 translateTo.getResourceId(), translateTo.getResource().getProperties(),
41 nodeTemplate.getProperties(), translateTo.getHeatFileName(),
42 translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
43 nodeTemplate, translateTo.getContext()));
44 handleSizeProperty(nodeTemplate.getProperties());
45 final String toscaReadOnlyPropName =
46 HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.READ_ONLY_PROPERTY_NAME);
47 final Object readOnlyPropVal = nodeTemplate.getProperties().get(toscaReadOnlyPropName);
48 if (readOnlyPropVal != null && !(readOnlyPropVal instanceof Map)) {
49 nodeTemplate.getProperties().put(toscaReadOnlyPropName, HeatBoolean.eval(readOnlyPropVal));
51 DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
56 private void handleSizeProperty(final Map<String, Object> nodeTemplateProperties) {
57 final Object size = nodeTemplateProperties.get(VOLUME_SIZE_PROPERTY_NAME);
61 nodeTemplateProperties.put(VOLUME_SIZE_PROPERTY_NAME, size);