1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
/*-
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.be.model;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.utils.MapUtil;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class Resource extends Component {
private List<String> derivedFrom;
private List<String> derivedList;
private List<PropertyDefinition> attributes;
private Map<String, InterfaceInstanceDataDefinition> instInterfaces;
private List<String> defaultCapabilities;
public Resource() {
super(new ResourceMetadataDefinition());
this.getComponentMetadataDefinition().getMetadataDataDefinition()
.setComponentType(ComponentTypeEnum.RESOURCE);
}
public Resource(ComponentMetadataDefinition componentMetadataDefinition) {
super(componentMetadataDefinition);
if (this.getComponentMetadataDefinition().getMetadataDataDefinition() == null) {
this.getComponentMetadataDefinition().componentMetadataDataDefinition = new ResourceMetadataDataDefinition();
}
this.getComponentMetadataDefinition().getMetadataDataDefinition().setComponentType(ComponentTypeEnum.RESOURCE);
}
/**
* Please note that more than one "derivedFrom" resource is not currently
* supported by the app. The first list element is always addressed.
*
* @return
*/
public List<String> getDerivedFrom() {
return derivedFrom;
}
public void setDerivedFrom(List<String> derivedFrom) {
this.derivedFrom = derivedFrom;
}
/**
* The derivedList is a chain of derivedFrom. e.g. if resource C is derived
* from resource B that is derived from resource A - then A, B is the
* "DerivedList" of resource C
*
* @return
*/
public List<String> getDerivedList() {
return derivedList;
}
public void setDerivedList(List<String> derivedList) {
this.derivedList = derivedList;
}
public List<PropertyDefinition> getProperties() {
return properties;
}
public void setProperties(List<PropertyDefinition> properties) {
this.properties = properties;
}
public List<PropertyDefinition> getAttributes() {
return attributes;
}
public void setAttributes(List<PropertyDefinition> attributes) {
this.attributes = attributes;
}
public Map<String, InterfaceInstanceDataDefinition> getInstInterfaces() {
return instInterfaces;
}
public void setInstInterfaces(
Map<String, InterfaceInstanceDataDefinition> instInterfaces) {
this.instInterfaces = instInterfaces;
}
public Boolean isAbstract() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition()
.getMetadataDataDefinition())
.isAbstract();
}
public void setAbstract(Boolean isAbstract) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.setAbstract(isAbstract);
}
public List<String> getDefaultCapabilities() {
return defaultCapabilities;
}
public void setDefaultCapabilities(List<String> defaultCapabilities) {
this.defaultCapabilities = defaultCapabilities;
}
public String getCost() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.getCost();
}
public void setCost(String cost) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setCost(cost);
;
}
public String getLicenseType() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.getLicenseType();
}
public void setLicenseType(String licenseType) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.setLicenseType(licenseType);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + super.hashCode();
result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
result = prime * result + ((defaultCapabilities == null) ? 0 : defaultCapabilities.hashCode());
result = prime * result + ((derivedFrom == null) ? 0 : derivedFrom.hashCode());
result = prime * result + ((properties == null) ? 0 : properties.hashCode());
result = prime * result + ((derivedList == null) ? 0 : derivedList.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Resource other = (Resource) obj;
if (attributes == null) {
if (other.attributes != null)
return false;
} else if (!attributes.equals(other.attributes))
return false;
if (defaultCapabilities == null) {
if (other.defaultCapabilities != null)
return false;
} else if (!defaultCapabilities.equals(other.defaultCapabilities))
return false;
if (derivedFrom == null) {
if (other.derivedFrom != null)
return false;
} else if (!derivedFrom.equals(other.derivedFrom))
return false;
if (derivedList == null) {
if (other.derivedList != null)
return false;
} else if (!derivedList.equals(other.derivedList))
return false;
if (properties == null) {
if (other.properties != null)
return false;
} else if (!properties.equals(other.properties))
return false;
return super.equals(obj);
}
@Override
public String toString() {
return "Resource [derivedFrom=" + derivedFrom + ", properties=" + properties + ", attributes=" + attributes
+ ", defaultCapabilities=" + defaultCapabilities + ", additionalInformation=" + additionalInformation
+ "Metadata [" + getComponentMetadataDefinition().getMetadataDataDefinition().toString() + "]";
}
public String getToscaResourceName() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.getToscaResourceName();
}
public void setToscaResourceName(String toscaResourceName) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.setToscaResourceName(toscaResourceName);
}
public ResourceTypeEnum getResourceType() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.getResourceType();
}
public void setResourceType(ResourceTypeEnum resourceType) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.setResourceType(resourceType);
}
public void setVendorName(String vendorName) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.setVendorName(vendorName);
}
public void setVendorRelease(String vendorRelease) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.setVendorRelease(vendorRelease);
}
public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).
setResourceVendorModelNumber(resourceVendorModelNumber);
}
public String getVendorName() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.getVendorName();
}
public String getVendorRelease() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.getVendorRelease();
}
public String getResourceVendorModelNumber() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
.getResourceVendorModelNumber();
}
@Override
public String fetchGenericTypeToscaNameFromConfig() {
String result = super.fetchGenericTypeToscaNameFromConfig();
if (null == result)
result = ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes().get(ResourceTypeEnum.VFC.getValue());
return result;
}
@Override
public String assetType() {
return this.getResourceType().name();
}
@Override
public boolean shouldGenerateInputs() {
//TODO add complex VFC condition when supported
return !(this.getResourceType().isAtomicType());
}
@Override
public boolean deriveFromGeneric() {
return this.shouldGenerateInputs() || (derivedFrom != null && derivedFrom.contains(fetchGenericTypeToscaNameFromConfig()));
}
public Map<String, List<RequirementCapabilityRelDef>> groupRelationsByInstanceName(Resource resource) {
Map<String, List<RequirementCapabilityRelDef>> relationsByInstanceId = MapUtil.groupListBy(resource.getComponentInstancesRelations(), RequirementCapabilityRelDef::getFromNode);
return MapUtil.convertMapKeys(relationsByInstanceId, (instId) -> getInstanceNameFromInstanceId(resource, instId));
}
private String getInstanceNameFromInstanceId(Resource resource, String instId) {
Optional<ComponentInstance> componentInstanceById = resource.getComponentInstanceById(instId);
return componentInstanceById.isPresent() ? componentInstanceById.get().getName() : null;
}
}
|