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.mso.db.catalog.beans;
24 import java.io.BufferedReader;
25 import java.io.FileReader;
26 import java.sql.Timestamp;
27 import java.text.DateFormat;
28 import java.util.Date;
31 import org.openecomp.mso.db.catalog.utils.MavenLikeVersioning;
32 import org.openecomp.mso.logger.MsoLogger;
34 public class HeatTemplate extends MavenLikeVersioning {
36 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
39 private String templateName;
40 private String templatePath = null;
41 private String templateBody = null;
42 private int timeoutMinutes;
43 private Set <HeatTemplateParam> parameters;
44 private Set <HeatNestedTemplate> files;
45 private String description;
46 private String asdcUuid;
47 private String asdcResourceName;
48 private String asdcLabel;
50 private Timestamp created;
52 public enum TemplateStatus {
53 PARENT, CHILD, PARENT_COMPLETE
56 public HeatTemplate () {
63 public void setId (int id) {
67 public String getTemplateName () {
71 public void setTemplateName (String templateName) {
72 this.templateName = templateName;
75 public String getTemplatePath () {
79 public void setTemplatePath (String templatePath) {
80 this.templatePath = templatePath;
83 public String getTemplateBody () {
87 public void setTemplateBody (String templateBody) {
88 this.templateBody = templateBody;
91 public int getTimeoutMinutes () {
92 return timeoutMinutes;
95 public void setTimeoutMinutes (int timeout) {
96 this.timeoutMinutes = timeout;
99 public Set <HeatTemplateParam> getParameters () {
103 public void setParameters (Set <HeatTemplateParam> parameters) {
104 this.parameters = parameters;
107 public String getDescription() {
111 public void setDescription(String description) {
112 this.description = description;
115 public String getHeatTemplate () {
116 if (templateBody != null && !templateBody.isEmpty ()) {
117 // The template body is in the DB table. Just return it.
123 try (BufferedReader reader = new BufferedReader (new FileReader (templatePath)))
126 StringBuilder stringBuilder = new StringBuilder ();
127 while ((line = reader.readLine ()) != null) {
128 stringBuilder.append (line);
130 body = stringBuilder.toString ();
131 } catch (Exception e) {
132 LOGGER.debug ("Error reading template file " + templatePath, e);
138 public void setFiles (Set <HeatNestedTemplate> files) {
142 public Set <HeatNestedTemplate> getFiles () {
146 public String getAsdcUuid() {
150 public void setAsdcUuid(String asdcUuidp) {
151 this.asdcUuid = asdcUuidp;
154 public String getAsdcResourceName() {
155 return asdcResourceName;
158 public void setAsdcResourceName(String asdcResourceName) {
159 this.asdcResourceName = asdcResourceName;
161 public String getAsdcLabel() {
162 return this.asdcLabel;
164 public void setAsdcLabel(String asdcLabel) {
165 this.asdcLabel = asdcLabel;
168 public Timestamp getCreated() {
172 public void setCreated(Timestamp created) {
173 this.created = created;
177 public String toString () {
178 String body = (templateBody != null) ? "(" + templateBody.length () + " chars)" : "(Not defined)";
179 StringBuilder sb = new StringBuilder ();
180 sb.append ("Template=")
181 .append (templateName)
182 .append (",version=")
185 .append (templatePath)
188 .append (",timeout=")
189 .append (timeoutMinutes)
190 .append (",asdcUuid=")
192 .append (",asdcResourceName=")
193 .append (asdcResourceName)
194 .append (",description=")
195 .append (description);
196 if (created != null) {
197 sb.append (",created=");
198 sb.append (DateFormat.getInstance().format(created));
202 if (parameters != null && !parameters.isEmpty ()) {
203 sb.append (",params=[");
204 for (HeatTemplateParam param : parameters) {
205 sb.append (param.getParamName ());
206 if (param.isRequired ()) {
207 sb.append ("(reqd)");
211 sb.replace (sb.length () - 1, sb.length (), "]");
213 return sb.toString ();