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;
49 private String artifactChecksum;
51 private Timestamp created;
53 public enum TemplateStatus {
54 PARENT, CHILD, PARENT_COMPLETE
57 public HeatTemplate () {
64 public void setId (int id) {
68 public String getTemplateName () {
72 public void setTemplateName (String templateName) {
73 this.templateName = templateName;
76 public String getTemplatePath () {
80 public void setTemplatePath (String templatePath) {
81 this.templatePath = templatePath;
84 public String getTemplateBody () {
88 public void setTemplateBody (String templateBody) {
89 this.templateBody = templateBody;
92 public int getTimeoutMinutes () {
93 return timeoutMinutes;
96 public void setTimeoutMinutes (int timeout) {
97 this.timeoutMinutes = timeout;
100 public Set <HeatTemplateParam> getParameters () {
104 public void setParameters (Set <HeatTemplateParam> parameters) {
105 this.parameters = parameters;
108 public String getDescription() {
112 public void setDescription(String description) {
113 this.description = description;
116 public String getHeatTemplate () {
117 if (templateBody != null && !templateBody.isEmpty ()) {
118 // The template body is in the DB table. Just return it.
124 try (BufferedReader reader = new BufferedReader (new FileReader (templatePath)))
127 StringBuilder stringBuilder = new StringBuilder ();
128 while ((line = reader.readLine ()) != null) {
129 stringBuilder.append (line);
131 body = stringBuilder.toString ();
132 } catch (Exception e) {
133 LOGGER.debug ("Error reading template file " + templatePath, e);
139 public void setFiles (Set <HeatNestedTemplate> files) {
143 public Set <HeatNestedTemplate> getFiles () {
147 public String getAsdcUuid() {
151 public void setAsdcUuid(String asdcUuidp) {
152 this.asdcUuid = asdcUuidp;
155 public String getAsdcResourceName() {
156 return asdcResourceName;
159 public void setAsdcResourceName(String asdcResourceName) {
160 this.asdcResourceName = asdcResourceName;
162 public String getAsdcLabel() {
163 return this.asdcLabel;
165 public void setAsdcLabel(String asdcLabel) {
166 this.asdcLabel = asdcLabel;
169 public String getArtifactChecksum() {
170 return artifactChecksum;
173 public void setArtifactChecksum(String artifactChecksum) {
174 this.artifactChecksum = artifactChecksum;
176 public Timestamp getCreated() {
180 public void setCreated(Timestamp created) {
181 this.created = created;
185 public String toString () {
186 String body = (templateBody != null) ? "(" + templateBody.length () + " chars)" : "(Not defined)";
187 StringBuilder sb = new StringBuilder ();
188 sb.append ("Template=")
189 .append (templateName)
190 .append (",version=")
193 .append (templatePath)
196 .append (",timeout=")
197 .append (timeoutMinutes)
198 .append (",asdcUuid=")
200 .append (",asdcResourceName=")
201 .append (asdcResourceName)
202 .append (",description=")
203 .append (description);
204 if (created != null) {
205 sb.append (",created=");
206 sb.append (DateFormat.getInstance().format(created));
210 if (parameters != null && !parameters.isEmpty ()) {
211 sb.append (",params=[");
212 for (HeatTemplateParam param : parameters) {
213 sb.append (param.getParamName ());
214 if (param.isRequired ()) {
215 sb.append ("(reqd)");
219 sb.replace (sb.length () - 1, sb.length (), "]");
221 return sb.toString ();