Change-Id: I9699ee13321f136b4460d5c85d49ab13378f52b4
Issue-ID: AAI-2121
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
============LICENSE_START=======================================================
org.onap.aai
================================================================================
============LICENSE_START=======================================================
org.onap.aai
================================================================================
-Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
-Copyright © 2017-2018 European Software Marketing Ltd.
+Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
+Copyright © 2017-2019 European Software Marketing Ltd.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
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.
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=========================================================
\ No newline at end of file
+============LICENSE_END=========================================================
* Constructs using csarHelper
*
* @param csarHelper
* Constructs using csarHelper
*
* @param csarHelper
*/
public ArtifactGeneratorToscaParser(ISdcCsarHelper csarHelper) {
this.csarHelper = csarHelper;
*/
public ArtifactGeneratorToscaParser(ISdcCsarHelper csarHelper) {
this.csarHelper = csarHelper;
* Get or create the artifact description.
*
* @param model
* Get or create the artifact description.
*
* @param model
* @return the artifact model's description
*/
public static String getArtifactDescription(Model model) {
* @return the artifact model's description
*/
public static String getArtifactDescription(Model model) {
* Initialises the group filtering and TOSCA mapping configuration.
*
* @param configLocation
* Initialises the group filtering and TOSCA mapping configuration.
*
* @param configLocation
- * the pathname to the JSON config file
+ * the pathname to the JSON config file
* @throws FileNotFoundException
* @throws FileNotFoundException
- * if the file cannot be opened for reading
+ * if the file cannot be opened for reading
*/
public static void initToscaMappingsConfiguration(String configLocation) throws FileNotFoundException {
log.debug("Getting TOSCA Mappings Configuration");
*/
public static void initToscaMappingsConfiguration(String configLocation) throws FileNotFoundException {
log.debug("Getting TOSCA Mappings Configuration");
* duplicate keys then the TOSCA Property value takes precedence.
*
* @param stringProps
* duplicate keys then the TOSCA Property value takes precedence.
*
* @param stringProps
- * initial Map of String property values (e.g. from the TOSCA YAML metadata section)
+ * initial Map of String property values (e.g. from the TOSCA YAML metadata section)
- * Map of TOSCA Property Type Object values to merge in (or overwrite)
+ * Map of TOSCA Property Type Object values to merge in (or overwrite)
* @return a Map of the property values converted to String
*/
public Map<String, String> mergeProperties(Map<String, String> stringProps, Map<String, Property> toscaProps) {
* @return a Map of the property values converted to String
*/
public Map<String, String> mergeProperties(Map<String, String> stringProps, Map<String, Property> toscaProps) {
String metaDataType = Optional.ofNullable(metadata).map(m -> m.getValue("type")).orElse(nodeTypeName);
Resource model = Model.getModelFor(nodeTypeName, metaDataType);
String metaDataType = Optional.ofNullable(metadata).map(m -> m.getValue("type")).orElse(nodeTypeName);
Resource model = Model.getModelFor(nodeTypeName, metaDataType);
- if (metadata != null && hasAllottedResource(metadata.getAllProperties())) {
- if (model.getWidgetType() == Type.VSERVER) {
- model = new Resource(Type.ALLOTTED_RESOURCE, false);
- Map<String, Object> props = new HashMap<>();
- props.put("providingService", true);
- model.setProperties(props);
- }
+ if (metadata != null && hasAllottedResource(metadata.getAllProperties())
+ && model.getWidgetType() == Type.VSERVER) {
+ model = new Resource(Type.ALLOTTED_RESOURCE, false);
+ Map<String, Object> props = new HashMap<>();
+ props.put("providingService", true);
+ model.setProperties(props);
}
foundProvidingService |= processModel(resourceModel, metadata, model, resourceNodeTemplate.getProperties());
}
foundProvidingService |= processModel(resourceModel, metadata, model, resourceNodeTemplate.getProperties());
* Create an Instance Group Model and populate it with the supplied data.
*
* @param resourceModel
* Create an Instance Group Model and populate it with the supplied data.
*
* @param resourceModel
- * the Resource node template Model
+ * the Resource node template Model
- * the Resources and Widgets belonging to the Group
+ * the Resources and Widgets belonging to the Group
- * the metadata of the Group
+ * the metadata of the Group
- * the properties of the Group
+ * the properties of the Group
* @return the Instance Group and Member resource models
*/
private List<Resource> processInstanceGroup(Model resourceModel, ArrayList<NodeTemplate> memberNodes,
* @return the Instance Group and Member resource models
*/
private List<Resource> processInstanceGroup(Model resourceModel, ArrayList<NodeTemplate> memberNodes,
* Create a Map of property name against String property value from the input Map
*
* @param inputMap
* Create a Map of property name against String property value from the input Map
*
* @param inputMap
* @return Map of property name against String property value
*/
private Map<String, String> populateStringProperties(Map<String, Property> inputMap) {
* @return Map of property name against String property value
*/
private Map<String, String> populateStringProperties(Map<String, Property> inputMap) {
* is ProvidingService then return true, otherwise return false.
*
* @param resourceModel
* is ProvidingService then return true, otherwise return false.
*
* @param resourceModel
- * for populating the Resource IDs
+ * for populating the Resource IDs
- * any Model (will be ignored if not a Resource)
+ * any Model (will be ignored if not a Resource)
* @return whether or not a ProvidingService was processed
*/
private boolean processModel(Model resourceModel, Metadata metaData, Resource resourceNode,
* @return whether or not a ProvidingService was processed
*/
private boolean processModel(Model resourceModel, Metadata metaData, Resource resourceNode,
*
* @param serviceVersion
* @param csarHelper
*
* @param serviceVersion
* @param csarHelper
- * interface to the TOSCA parser
+ * interface to the TOSCA parser
* @return the generated Artifacts (containing XML models)
*/
private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper) {
* @return the generated Artifacts (containing XML models)
*/
private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper) {
if (model != null) {
Metadata metadata = nodeTemplate.getMetaData();
if (model != null) {
Metadata metadata = nodeTemplate.getMetaData();
- if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())) {
- if (model.getWidgetType() == Type.VF) {
- model = new Resource(Type.ALLOTTED_RESOURCE, true);
- }
+ if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())
+ && model.getWidgetType() == Type.VF) {
+ model = new Resource(Type.ALLOTTED_RESOURCE, true);
private void generateResourceModel(ISdcCsarHelper csarHelper, List<Resource> resources,
ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) {
Resource resourceModel = getModelFor(parser, nodeTemplate);
private void generateResourceModel(ISdcCsarHelper csarHelper, List<Resource> resources,
ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) {
Resource resourceModel = getModelFor(parser, nodeTemplate);
+ if (resourceModel == null) {
+ log.info(ApplicationMsgs.DISTRIBUTION_EVENT, "Could not generate resource model");
+ return;
+ }
+
Map<String, String> serviceMetadata = nodeTemplate.getMetaData().getAllProperties();
resourceModel.populateModelIdentificationInformation(serviceMetadata);
Map<String, String> serviceMetadata = nodeTemplate.getMetaData().getAllProperties();
resourceModel.populateModelIdentificationInformation(serviceMetadata);
* Method to generate the artifact name for an AAI model.
*
* @param model
* Method to generate the artifact name for an AAI model.
*
* @param model
* @return Model artifact name
*/
private String getArtifactName(Model model) {
* @return Model artifact name
*/
private String getArtifactName(Model model) {
* Create Resource artifact model from the AAI xml model string.
*
* @param resourceModel
* Create Resource artifact model from the AAI xml model string.
*
* @param resourceModel
- * Model of the resource artifact
+ * Model of the resource artifact
* @param aaiResourceModel
* @param aaiResourceModel
* @return Generated {@link Artifact} model for the resource
*/
private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
* @return Generated {@link Artifact} model for the resource
*/
private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
* Create Service artifact model from the AAI XML model.
*
* @param serviceModel
* Create Service artifact model from the AAI XML model.
*
* @param serviceModel
- * Model of the service artifact
+ * Model of the service artifact
* @return Generated {@link Artifact} model for the service
*/
private Artifact getServiceArtifact(Service serviceModel, String aaiServiceModel) {
* @return Generated {@link Artifact} model for the service
*/
private Artifact getServiceArtifact(Service serviceModel, String aaiServiceModel) {
public boolean getDeleteFlag() {
return deleteFlag;
}
public boolean getDeleteFlag() {
return deleteFlag;
}
public String getWidgetInvariantId() {
return Widget.getWidget(getWidgetType()).getWidgetId();
}
public String getWidgetInvariantId() {
return Widget.getWidget(getWidgetType()).getWidgetId();
}
public String getWidgetId() {
return Widget.getWidget(getWidgetType()).getId();
}
public String getWidgetId() {
return Widget.getWidget(getWidgetType()).getId();
}
* Adds a Widget.
*
* @param widget
* Adds a Widget.
*
* @param widget
* @return the boolean
*/
@Override
* @return the boolean
*/
@Override
/**
* Call the extractor with the specified arguments and assert that an exception is thrown.
*
/**
* Call the extractor with the specified arguments and assert that an exception is thrown.
*
- * @param archive the compressed archive in the form of a byte array, expected to contain one or more YAML files
- * @param name the name of the archive
- * @param version the version of the archive
- * @param expectedErrorMessage the text of the InvalidArchiveException thrown by the extractor
+ * @param archive
+ * the compressed archive in the form of a byte array, expected to contain one or more YAML files
+ * @param name
+ * the name of the archive
+ * @param version
+ * the version of the archive
+ * @param expectedErrorMessage
+ * the text of the InvalidArchiveException thrown by the extractor
*/
private void invalidArgumentsTest(byte[] archive, String name, String version, String expectedErrorMessage) {
try {
*/
private void invalidArgumentsTest(byte[] archive, String name, String version, String expectedErrorMessage) {
try {
* Check that each message can be logged and that (by implication of successful logging) there is a corresponding
* resource (message format).
*
* Check that each message can be logged and that (by implication of successful logging) there is a corresponding
* resource (message format).
*
- * @throws IOException if the log files cannot be read
+ * @throws IOException
+ * if the log files cannot be read
*/
@Test
public void logAllMessages() throws IOException {
Logger logger = LogHelper.INSTANCE;
LogReader errorReader = new LogReader(LogHelper.getLogDirectory(), "error");
LogReader debugReader = new LogReader(LogHelper.getLogDirectory(), "debug");
*/
@Test
public void logAllMessages() throws IOException {
Logger logger = LogHelper.INSTANCE;
LogReader errorReader = new LogReader(LogHelper.getLogDirectory(), "error");
LogReader debugReader = new LogReader(LogHelper.getLogDirectory(), "debug");
- String[] args = { "1", "2", "3", "4" };
+ String[] args = {"1", "2", "3", "4"};
for (ApplicationMsgs msg : Arrays.asList(ApplicationMsgs.values())) {
if (msg.name().endsWith("ERROR")) {
logger.error(msg, args);
for (ApplicationMsgs msg : Arrays.asList(ApplicationMsgs.values())) {
if (msg.name().endsWith("ERROR")) {
logger.error(msg, args);
* Check that each message can be logged and that (by implication of successful logging) there is a corresponding
* resource (message format).
*
* Check that each message can be logged and that (by implication of successful logging) there is a corresponding
* resource (message format).
*
- * @throws IOException if the log file cannot be read
+ * @throws IOException
+ * if the log file cannot be read
*/
@Test
public void logDebugMessages() throws IOException {
*/
@Test
public void logDebugMessages() throws IOException {
/**
* Check logAudit with HTTP headers.
*
/**
* Check logAudit with HTTP headers.
*
- * @throws IOException if the log file cannot be read
+ * @throws IOException
+ * if the log file cannot be read
*/
@Test
public void logAuditMessage() throws IOException {
*/
@Test
public void logAuditMessage() throws IOException {
/**
* Check logAudit with no HTTP headers.
*
/**
* Check logAudit with no HTTP headers.
*
- * @throws IOException if the log file cannot be read
+ * @throws IOException
+ * if the log file cannot be read
*/
@Test
public void logAuditMessageWithoutHeaders() throws IOException {
*/
@Test
public void logAuditMessageWithoutHeaders() throws IOException {
/**
* Check logMetrics.
*
/**
* Check logMetrics.
*
- * @throws IOException if the log file cannot be read
+ * @throws IOException
+ * if the log file cannot be read
*/
@Test
public void logMetricsMessage() throws IOException {
*/
@Test
public void logMetricsMessage() throws IOException {
/**
* Call a logger method which is expected to throw an UnsupportedOperationException.
*
/**
* Call a logger method which is expected to throw an UnsupportedOperationException.
*
- * @param logMethod the logger method to invoke
- * @param dummyMsg any Application Message enumeration value
+ * @param logMethod
+ * the logger method to invoke
+ * @param dummyMsg
+ * any Application Message enumeration value
*/
private void callUnsupportedOperationMethod(TriConsumer<Enum<?>, LogFields, String[]> logMethod,
ApplicationMsgs dummyMsg) {
try {
*/
private void callUnsupportedOperationMethod(TriConsumer<Enum<?>, LogFields, String[]> logMethod,
ApplicationMsgs dummyMsg) {
try {
- logMethod.accept(dummyMsg, new LogFields(), new String[] { "" });
+ logMethod.accept(dummyMsg, new LogFields(), new String[] {""});
org.junit.Assert.fail("method should have thrown execption"); // NOSONAR as code not reached
} catch (UnsupportedOperationException e) {
// Expected to reach here
org.junit.Assert.fail("method should have thrown execption"); // NOSONAR as code not reached
} catch (UnsupportedOperationException e) {
// Expected to reach here
/**
* Assert that a log message was logged to the expected log file at the expected severity.
*
/**
* Assert that a log message was logged to the expected log file at the expected severity.
*
- * @param msg the Application Message enumeration value
- * @param reader the log reader for the message
- * @param severity log level
- * @throws IOException if the log file cannot be read
+ * @param msg
+ * the Application Message enumeration value
+ * @param reader
+ * the log reader for the message
+ * @param severity
+ * log level
+ * @throws IOException
+ * if the log file cannot be read
*/
private void validateLoggedMessage(ApplicationMsgs msg, LogReader reader, String severity) throws IOException {
String str = reader.getNewLines();
*/
private void validateLoggedMessage(ApplicationMsgs msg, LogReader reader, String severity) throws IOException {
String str = reader.getNewLines();
* from the Artifact Generator properties.
*
* @throws IOException
* from the Artifact Generator properties.
*
* @throws IOException
- * if the Artifact Generator properties file is not loaded
+ * if the Artifact Generator properties file is not loaded
*/
@Before
public void setup() throws IOException {
*/
@Before
public void setup() throws IOException {
String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
if (configLocation == null) {
throw new IllegalArgumentException(
String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
if (configLocation == null) {
throw new IllegalArgumentException(
- String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND, ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE));
+ String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND,
+ ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE));
ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
utils.loadWidgetToUuidMappings();
ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
utils.loadWidgetToUuidMappings();
* Assert that the TOSCA type String is mapped to the expected Widget Type.
*
* @param toscaType
* Assert that the TOSCA type String is mapped to the expected Widget Type.
*
* @param toscaType
- * the TOSCA type or prefix
+ * the TOSCA type or prefix
- * the type of Widget expected from the mappings
+ * the type of Widget expected from the mappings
*/
private void assertMapping(String toscaType, Type widgetType) {
assertThat(Model.getModelFor(toscaType).getWidgetType(), is(widgetType));
*/
private void assertMapping(String toscaType, Type widgetType) {
assertThat(Model.getModelFor(toscaType).getWidgetType(), is(widgetType));
* Assert that the TOSCA metadata type is mapped to the expected Widget Type.
*
* @param toscaType
* Assert that the TOSCA metadata type is mapped to the expected Widget Type.
*
* @param toscaType
- * the name (or name prefix) of the TOSCA type
+ * the name (or name prefix) of the TOSCA type
- * the type specified in the TOSCA metadata
+ * the type specified in the TOSCA metadata
- * the type of Widget expected from the mappings
+ * the type of Widget expected from the mappings
*/
private void assertMapping(String toscaType, String metadataType, Type widgetType) {
assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType));
*/
private void assertMapping(String toscaType, String metadataType, Type widgetType) {
assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType));