2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.mso.openstack.utils;
25 import org.openecomp.mso.logger.MsoLogger;
27 public class MsoHeatEnvironmentEntry {
29 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
30 private Set<MsoHeatEnvironmentParameter> parameters;
31 private String rawEntry;
32 private boolean valid = true;
33 private String errorString;
34 private String resourceRegistryEntryRaw;
36 private MsoHeatEnvironmentEntry(String rawEntry) {
37 this.rawEntry = rawEntry;
40 private MsoHeatEnvironmentEntry(Set<MsoHeatEnvironmentParameter> parameters, String rawEntry, boolean valid,
41 String errorString, String resourceRegistryEntryRaw) {
42 this.parameters = parameters;
43 this.rawEntry = rawEntry;
45 this.errorString = errorString;
46 this.resourceRegistryEntryRaw = resourceRegistryEntryRaw;
49 public boolean isValid() {
52 public String getErrorString() {
53 return this.errorString;
56 public boolean containsParameter(String paramName) {
57 if (this.parameters == null || this.parameters.size() < 1) {
60 if (this.parameters.contains(new MsoHeatEnvironmentParameter(paramName))) {
67 public String toString() {
68 return "MsoHeatEnvironmentEntry{" + "parameters=" + parameters +
69 ", resourceRegistryEntryRaw='" + resourceRegistryEntryRaw + '\'' +
73 public String getRawEntry() {
77 private static String getResourceRegistryRawEntry(String rawEntry) {
78 int indexOf = rawEntry.indexOf("resource_registry:");
82 return rawEntry.substring(indexOf);
85 public static MsoHeatEnvironmentEntry create(String rawEntry) {
86 if (rawEntry == null || rawEntry.isEmpty()) {
87 return new MsoHeatEnvironmentEntry(rawEntry);
90 Set<MsoHeatEnvironmentParameter> parameters = new MsoYamlEditorWithEnvt(rawEntry.getBytes())
91 .getParameterListFromEnvt();
92 return new MsoHeatEnvironmentEntry(parameters, rawEntry, true, null,
93 getResourceRegistryRawEntry(rawEntry));
94 } catch (Exception e) {
95 LOGGER.debug(String.format("An exception occurred during processing the following raw entry: %s", rawEntry),
97 return new MsoHeatEnvironmentEntry(null, rawEntry, false, e.getMessage(), null);