diff options
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/asdc')
16 files changed, 462 insertions, 1991 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java index 970ec954f..4e0254cde 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java @@ -20,66 +20,16 @@ package org.onap.vid.asdc; -import java.io.IOException; +import org.onap.vid.asdc.beans.Service; + import java.nio.file.Path; -import java.util.Collection; -import java.util.Map; import java.util.UUID; -import org.onap.vid.asdc.beans.Artifact; -import org.onap.vid.asdc.beans.Resource; -import org.onap.vid.asdc.beans.Service; - /** * The Interface AsdcClient. */ public interface AsdcClient { - - /** - * Gets the resource. - * - * @param uuid the uuid - * @return the resource - * @throws AsdcCatalogException the sdc catalog exception - */ - public Resource getResource(UUID uuid) throws AsdcCatalogException; - - /** - * Gets the resources. - * - * @return the resources - * @throws AsdcCatalogException the sdc catalog exception - */ - public Collection<Resource> getResources() throws AsdcCatalogException; - - /** - * Gets the resources. - * - * @param filter the filter - * @return the resources - * @throws AsdcCatalogException the sdc catalog exception - */ - public Collection<Resource> getResources(Map<String, String[]> filter) throws AsdcCatalogException; - - /** - * Gets the resource artifact. - * - * @param resourceUuid the resource uuid - * @param artifactUuid the artifact uuid - * @return the resource artifact - * @throws AsdcCatalogException the sdc catalog exception - */ - public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException; - - /** - * Gets the resource tosca model. - * - * @param uuid the uuid - * @return the resource tosca model - * @throws AsdcCatalogException the sdc catalog exception - */ - public Path getResourceToscaModel(UUID uuid) throws AsdcCatalogException; - + /** * Gets the service. * @@ -87,35 +37,8 @@ public interface AsdcClient { * @return the service * @throws AsdcCatalogException the sdc catalog exception */ - public Service getService(UUID uuid) throws AsdcCatalogException; - - /** - * Gets the services. - * - * @return the services - * @throws AsdcCatalogException the sdc catalog exception - */ - public Collection<Service> getServices() throws AsdcCatalogException; - - /** - * Gets the services. - * - * @param filter the filter - * @return the services - * @throws AsdcCatalogException the asdc catalog exception - */ - public Collection<Service> getServices(Map<String, String[]> filter) throws AsdcCatalogException; - - /** - * Gets the service artifact. - * - * @param serviceUuid the service uuid - * @param artifactUuid the artifact uuid - * @return the service artifact - * @throws AsdcCatalogException the asdc catalog exception - */ - public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException; - + Service getService(UUID uuid) throws AsdcCatalogException; + /** * Gets the service tosca model. * @@ -123,7 +46,5 @@ public interface AsdcClient { * @return the service tosca model * @throws AsdcCatalogException the asdc catalog exception */ - public Path getServiceToscaModel(UUID uuid) throws AsdcCatalogException; - - //TODO: Collect TOSCA information from CSAR + Path getServiceToscaModel(UUID uuid) throws AsdcCatalogException; } diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Resource.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Resource.java deleted file mode 100644 index 6b5aa5320..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Resource.java +++ /dev/null @@ -1,429 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.asdc.beans; - -import java.util.Collection; -import java.util.UUID; - -/** - * The Class Resource. - */ -public class Resource { - - /** - * The Enum Type. - */ - public enum Type { - - /** The vf. */ - VF, - - /** The vfc. */ - VFC, - - /** The cp. */ - CP, - - /** The vl. */ - VL, - - /** The vfcmt. */ - VFCMT - } - - /** - * The Enum LifecycleState. - */ - public enum LifecycleState { - - /** The not certified checkout. */ - NOT_CERTIFIED_CHECKOUT, - - /** The not certified checkin. */ - NOT_CERTIFIED_CHECKIN, - - /** The ready for certification. */ - READY_FOR_CERTIFICATION, - - /** The certification in progress. */ - CERTIFICATION_IN_PROGRESS, - - /** The certified. */ - CERTIFIED - } - - /** The uuid. */ - private String uuid; - - /** The invariant UUID. */ - private String invariantUUID; - - /** The name. */ - private String name; - - /** The description. */ - private String description; - - /** The version. */ - private String version; - - /** The tosca model URL. */ - private String toscaModelURL; - - /** The category. */ - private String category; - - /** The sub category. */ - private String subCategory; - - /** The resource type. */ - private Resource.Type resourceType; - - /** The lifecycle state. */ - private Resource.LifecycleState lifecycleState; - - /** The last updater user ID. */ - private String lastUpdaterUserId; - - /** The last updater full name. */ - private String lastUpdaterFullName; - - /** The tosca model. */ - private String toscaModel; - - /** The tosca resource name. */ - private String toscaResourceName; - - /** The artifacts. */ - private Collection<Artifact> artifacts; - - /** The resources. */ - private Collection<SubResource> resources; - - /** - * Gets the uuid. - * - * @return the uuid - */ - public String getUuid() { - return uuid; - } - - /** - * Gets the invariant UUID. - * - * @return the invariant UUID - */ - public String getInvariantUUID() { - return invariantUUID; - } - - /** - * Gets the name. - * - * @return the name - */ - public String getName() { - return name; - } - - /** - * Gets the description. - * - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * Gets the version. - * - * @return the version - */ - public String getVersion() { - return version; - } - - /** - * Gets the tosca model URL. - * - * @return the tosca model URL - */ - public String getToscaModelURL() { - return toscaModelURL; - } - - /** - * Gets the category. - * - * @return the category - */ - public String getCategory() { - return category; - } - - /** - * Gets the sub category. - * - * @return the sub category - */ - public String getSubCategory() { - return subCategory; - } - - /** - * Gets the resource type. - * - * @return the resource type - */ - public Resource.Type getResourceType() { - return resourceType; - } - - /** - * Gets the lifecycle state. - * - * @return the lifecycle state - */ - public Resource.LifecycleState getLifecycleState() { - return lifecycleState; - } - - /** - * Gets the last updater user ID. - * - * @return the last updater user ID - */ - public String getLastUpdaterUserId() { - return lastUpdaterUserId; - } - - /** - * Gets the last updater full name. - * - * @return the last updater full name - */ - public String getLastUpdaterFullName() { - return lastUpdaterFullName; - } - - /** - * Gets the tosca model. - * - * @return the tosca model - */ - public String getToscaModel() { - return toscaModel; - } - - /** - * Gets the tosca resource name. - * - * @return the tosca resource name - */ - public String getToscaResourceName() { - return toscaResourceName; - } - - /** - * Gets the artifacts. - * - * @return the artifacts - */ - public Collection<Artifact> getArtifacts() { - return artifacts; - } - - /** - * Gets the resources. - * - * @return the resources - */ - public Collection<SubResource> getResources() { - return resources; - } - - /** - * Sets the uuid. - * - * @param uuid the new uuid - */ - public void setUuid(String uuid) { - this.uuid = uuid; - } - - /** - * Sets the invariant UUID. - * - * @param invariantUUID the new invariant UUID - */ - public void setInvariantUUID(String invariantUUID) { - this.invariantUUID = invariantUUID; - } - - /** - * Sets the name. - * - * @param name the new name - */ - public void setName(String name) { - this.name = name; - } - /** - * Sets the description. - * - * @param name the new description - */ - public void setDescription(String description) { - this.description = description; - } - /** - * Sets the version. - * - * @param version the new version - */ - public void setVersion(String version) { - this.version = version; - } - - /** - * Sets the tosca model URL. - * - * @param toscaModelURL the new tosca model URL - */ - public void setToscaModelURL(String toscaModelURL) { - this.toscaModelURL = toscaModelURL; - } - - /** - * Sets the category. - * - * @param category the new category - */ - public void setCategory(String category) { - this.category = category; - } - - /** - * Sets the sub category. - * - * @param subCategory the new sub category - */ - public void setSubCategory(String subCategory) { - this.subCategory = subCategory; - } - - /** - * Sets the resource type. - * - * @param resourceType the new resource type - */ - public void setResourceType(Resource.Type resourceType) { - this.resourceType = resourceType; - } - - /** - * Sets the lifecycle state. - * - * @param lifecycleState the new lifecycle state - */ - public void setLifecycleState(Resource.LifecycleState lifecycleState) { - this.lifecycleState = lifecycleState; - } - - /** - * Sets the last updater user ID. - * - * @param lastUpdaterUserId the new last updater user ID - */ - public void setLastUpdaterUserId(String lastUpdaterUserId) { - this.lastUpdaterUserId = lastUpdaterUserId; - } - - /** - * Sets the last updater full name. - * - * @param lastUpdaterFullName the new last updater full name - */ - public void setLastUpdaterFullName(String lastUpdaterFullName) { - this.lastUpdaterFullName = lastUpdaterFullName; - } - - /** - * Sets the tosca model. - * - * @param toscaModel the new tosca model - */ - public void setToscaModel(String toscaModel) { - this.toscaModel = toscaModel; - } - - /** - * Sets the tosca resource name. - * - * @param toscaResourceName the new tosca resource name - */ - public void setToscaResourceName(String toscaResourceName) { - this.toscaResourceName = toscaResourceName; - } - - /** - * Sets the artifacts. - * - * @param artifacts the new artifacts - */ - public void setArtifacts(Collection<Artifact> artifacts) { - this.artifacts = artifacts; - } - - /** - * Sets the resources. - * - * @param resources the new resources - */ - public void setResources(Collection<SubResource> resources) { - this.resources = resources; - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final UUID uuid = UUID.fromString(getUuid()); - - return uuid.hashCode(); - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object o) { - if (o == this) return true; - if (!(o instanceof Resource)) return false; - - final Resource resource = (Resource) o; - - return (resource.getUuid().equals(getUuid())); - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/SecureService.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/SecureService.java deleted file mode 100644 index b81a43893..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/SecureService.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.onap.vid.asdc.beans; - -/** - * Created by Oren on 6/27/17. - */ -public class SecureService extends Service{ - - public boolean isPermmited = true; -} diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Service.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Service.java index 5f59b89e8..cb16f1443 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Service.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Service.java @@ -97,7 +97,7 @@ public class Service { private String lastUpdaterFullName; /** The distribution status. */ - private Service.DistributionStatus distributionStatus; + private String distributionStatus; /** The artifacts. */ private Collection<Artifact> artifacts; @@ -191,7 +191,7 @@ public class Service { * * @return the distribution status */ - public Service.DistributionStatus getDistributionStatus() { + public String getDistributionStatus() { return distributionStatus; } @@ -299,7 +299,7 @@ public class Service { * * @param distributionStatus the new distribution status */ - public void setDistributionStatus(Service.DistributionStatus distributionStatus) { + public void setDistributionStatus(String distributionStatus) { this.distributionStatus = distributionStatus; } @@ -334,9 +334,7 @@ public class Service { */ @Override public int hashCode() { - final UUID uuid = UUID.fromString(getUuid()); - - return uuid.hashCode(); + return UUID.fromString(getUuid()).hashCode(); } /* (non-Javadoc) @@ -351,4 +349,20 @@ public class Service { return (service.getUuid().equals(getUuid())); } + + public Service(String uuid, String invariantUUID, String category, String version, String name, String distributionStatus, String toscaModelURL, LifecycleState lifecycleState, Collection<Artifact> artifacts, Collection<SubResource> resources) { + this.uuid = uuid; + this.invariantUUID = invariantUUID; + this.name = name; + this.version = version; + this.toscaModelURL = toscaModelURL; + this.category = category; + this.lifecycleState = lifecycleState; + this.distributionStatus = distributionStatus; + this.artifacts = artifacts; + this.resources = resources; + } + + public Service() { + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Capability.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Capability.java deleted file mode 100644 index 7aa13435d..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Capability.java +++ /dev/null @@ -1,140 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.asdc.beans.tosca; - -import java.util.Collection; -import java.util.Map; - -/** - * The Class Capability. - */ -public class Capability { - - /** The type. */ - private String type; //FIXME: Make an enumeration? - - /** The description. */ - private String description; - - /** The occurrences. */ - private Collection<String> occurrences; //FIXME: Make an enumeration? - - /** The properties. */ - private Map<String, Property> properties; - - /** The valid source types. */ - private Collection<String> valid_source_types; //FIXME: Make an enumeration? - - /** - * Instantiates a new capability. - */ - public Capability() {} - - /** - * Gets the type. - * - * @return the type - */ - public String getType() { - return type; - } - - /** - * Gets the description. - * - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * Gets the occurrences. - * - * @return the occurrences - */ - public Collection<String> getOccurrences() { - return occurrences; - } - - /** - * Gets the properties. - * - * @return the properties - */ - public Map<String, Property> getProperties() { - return properties; - } - - /** - * Gets the valid source types. - * - * @return the valid source types - */ - public Collection<String> getValid_source_types() { - return valid_source_types; - } - - /** - * Sets the type. - * - * @param type the new type - */ - public void setType(String type) { - this.type = type; - } - - /** - * Sets the description. - * - * @param description the new description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Sets the occurrences. - * - * @param occurrences the new occurrences - */ - public void setOccurrences(Collection<String> occurrences) { - this.occurrences = occurrences; - } - - /** - * Sets the properties. - * - * @param properties the properties - */ - public void setProperties(Map<String, Property> properties) { - this.properties = properties; - } - - /** - * Sets the valid source types. - * - * @param valid_source_types the new valid source types - */ - public void setValid_source_types(Collection<String> valid_source_types) { - this.valid_source_types = valid_source_types; - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Constraint.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Constraint.java deleted file mode 100644 index 118776cab..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Constraint.java +++ /dev/null @@ -1,199 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.asdc.beans.tosca; -import java.util.List; -import java.util.ArrayList; - -/** - * The Class Constraint. - */ - -public class Constraint { - private List<Object> valid_values; - private Object equal; - private Object greater_than; - private Object greater_or_equal; - private Object less_than; - private Object less_or_equal; - private List<Object> in_range; - private Object length; - private Object min_length; - private Object max_length; - - /** - * Instantiates a new Constraint. - */ - public Constraint() { - valid_values = new ArrayList<Object>(); - in_range = new ArrayList<Object>(); - } - - /** - * Gets the valid_values. - * - * @return the valid_values - */ - public List<Object> getvalid_values() { - return valid_values; - } - /** - * Gets equal. - * - * @return equal - */ - public Object getEqual() { - return equal; - } - /** - * Gets greater_than. - * - * @return greater_than - */ - public Object getGreater_than() { - return greater_than; - } - /** - * Gets greater_or_equal. - * - * @return greater_or_equal - */ - public Object getGreater_or_equal() { - return greater_or_equal; - } - /** - * Gets less_than. - * - * @return less_than - */ - public Object getLess_than() { - return less_than; - } - /** - * Gets less_or_equal. - * - * @return less_or_equal - */ - public Object getLess_or_equal() { - return less_or_equal; - } - /** - * Gets in_range. - * - * @return in_range - */ - public List<Object> getIn_range() { - return in_range; - } - /** - * Gets length. - * - * @return length - */ - public Object getLength() { - return length; - } - /** - * Gets min_length. - * - * @return min_length - */ - public Object getMin_length() { - return min_length; - } - /** - * Gets max_length. - * - * @return max_length - */ - public Object getMax_length() { - return max_length; - } - /** - * Sets the valid_values. - * - * @param op the new valid_values - */ - public void setvalid_values(List<Object> vlist) { - this.valid_values = vlist; - } - /** - * Sets equal. - * - * @param e the new equal - */ - public void setEqual(Object e) { - this.equal = e; - } - /** - * Sets greater_than. - * - * @param e the new greater_than - */ - public void setGreater_than(Object e) { - this.greater_than = e; - } - /** - * Sets less_than. - * - * @param e the new less_than - */ - public void setLess_than(Object e) { - this.less_than = e; - } - /** - * Sets in_range. - * - * @param e the new in_range - */ - public void setIn_range(List<Object> e) { - this.in_range = e; - } - /** - * Sets length. - * - * @param e the length - */ - public void setLength(Object e) { - this.length = e; - } - /** - * Sets min_length. - * - * @param e the min_length - */ - public void setMin_length(Object e) { - this.min_length = e; - } - /** - * Sets max_length. - * - * @param e the max_length - */ - public void setMax_length(Object e) { - this.max_length = e; - } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "valid_values=" + valid_values; - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Input.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Input.java index 6b2f39eca..590284928 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Input.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Input.java @@ -20,7 +20,7 @@ package org.onap.vid.asdc.beans.tosca; -import org.onap.sdc.toscaparser.api.elements.constraints.*; +import org.onap.sdc.toscaparser.api.Property; import java.util.List; import java.util.ArrayList; @@ -31,6 +31,13 @@ import java.util.ArrayList; */ public class Input { + public Input(org.onap.sdc.toscaparser.api.parameters.Input input, List<Property> properties){ + this.type = input.getType(); + this.description = input.getDescription(); + this._default = input.getDefault(); + this.inputProperties = new InputProperties(properties); + } + /** The type. */ private String type; @@ -42,6 +49,8 @@ public class Input { /** The entry schema. */ private Input entry_schema; + + private InputProperties inputProperties; /** The constraints */ private List<org.onap.sdc.toscaparser.api.elements.constraints.Constraint> constraints; @@ -142,11 +151,18 @@ public class Input { /** * Sets the entry schema. * - * @param the entry schema */ public void setentry_schema(Input s) { this.entry_schema = s; } + + public InputProperties getInputProperties() { + return inputProperties; + } + + public void setInputProperties(InputProperties inputProperties) { + this.inputProperties = inputProperties; + } /** * Sets the constraints. * diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/InputProperties.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/InputProperties.java new file mode 100644 index 000000000..bc2513ea9 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/InputProperties.java @@ -0,0 +1,63 @@ +package org.onap.vid.asdc.beans.tosca; + +import org.onap.sdc.toscaparser.api.Property; + +import java.util.List; + +public class InputProperties { + private String sourceType; + private String vfModuleLabel; + private String paramName; + + public InputProperties(){ + + } + + public InputProperties(List<Property> properties) { + for(Property property: properties) { + if (property.getName().equals("source_type")) { + this.sourceType = (String)property.getValue(); + continue; + } else if (property.getName().equals("param_name")) { + this.paramName = (String)property.getValue(); + continue; + } else if (property.getName().equals("vf_module_label")) { + this.vfModuleLabel = getPropertyValueAsString(property); + continue; + } + } + } + + public String getSourceType() { + return sourceType; + } + + public void setSourceType(String sourceType) { + this.sourceType = sourceType; + } + + public String getVfModuleLabel() { + return vfModuleLabel; + } + + public void setVfModuleLabel(String vfModuleLabel) { + this.vfModuleLabel = vfModuleLabel; + } + + public String getParamName() { + return paramName; + } + + public void setParamName(String paramName) { + this.paramName = paramName; + } + + private String getPropertyValueAsString(Property property) { + return property.getValue().toString().substring(1, property.getValue().toString().length()-1); + } + + + + + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Property.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Property.java index 4bebe8b8a..74b00bdf7 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Property.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Property.java @@ -73,15 +73,6 @@ public class Property { } /** - * Gets the default. - * - * @return the default - */ - public String get_default() { - return _default; - } - - /** * Sets the type. * * @param type the new type @@ -109,15 +100,6 @@ public class Property { } /** - * Sets the default. - * - * @param _default the new default - */ - public void set_default(String _default) { - this._default = _default; - } - - /** * Gets the default. * * @return the default @@ -125,7 +107,7 @@ public class Property { public String getDefault() { return _default; } - + /** * Checks if is required. * diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Requirement.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Requirement.java deleted file mode 100644 index 202e88f1e..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Requirement.java +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.asdc.beans.tosca; - -import java.util.Collection; - -/** - * The Class Requirement. - */ -public class Requirement { - - /** The occurrences. */ - private Collection<String> occurrences; - - /** The capability. */ - private String capability; - - /** The node. */ - private String node; - - /** The relationship. */ - private String relationship; - - /** - * Instantiates a new requirement. - */ - Requirement() {} - - /** - * Gets the occurrences. - * - * @return the occurrences - */ - public Collection<String> getOccurrences() { - return occurrences; - } - - /** - * Gets the capability. - * - * @return the capability - */ - public String getCapability() { - return capability; - } - - /** - * Gets the node. - * - * @return the node - */ - public String getNode() { - return node; - } - - /** - * Gets the relationship. - * - * @return the relationship - */ - public String getRelationship() { - return relationship; - } - - /** - * Sets the occurrences. - * - * @param occurrences the new occurrences - */ - public void setOccurrences(Collection<String> occurrences) { - this.occurrences = occurrences; - } - - /** - * Sets the capability. - * - * @param capability the new capability - */ - public void setCapability(String capability) { - this.capability = capability; - } - - /** - * Sets the node. - * - * @param node the new node - */ - public void setNode(String node) { - this.node = node; - } - - /** - * Sets the relationship. - * - * @param relationship the new relationship - */ - public void setRelationship(String relationship) { - this.relationship = relationship; - } - - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java index 7671b7305..108d9c06a 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java @@ -7,23 +7,22 @@ import org.json.JSONArray; import org.json.JSONObject; import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.asdc.AsdcClient; -import org.onap.vid.asdc.beans.Artifact; -import org.onap.vid.asdc.beans.Resource; import org.onap.vid.asdc.beans.Service; import org.onap.vid.asdc.beans.tosca.ToscaCsar; import org.onap.vid.asdc.beans.tosca.ToscaMeta; import org.onap.vid.asdc.beans.tosca.ToscaModel; +import org.onap.vid.exceptions.GenericUncheckedException; import org.yaml.snakeyaml.Yaml; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; -import java.util.Collection; -import java.util.LinkedList; import java.util.Map; import java.util.UUID; import java.util.zip.ZipFile; @@ -34,6 +33,7 @@ import java.util.zip.ZipFile; public class LocalAsdcClient implements AsdcClient { + public static final String SERVICES = "services"; /** * The catalog. */ @@ -94,62 +94,12 @@ public class LocalAsdcClient implements AsdcClient { } /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResource(java.util.UUID) - */ - public Resource getResource(UUID uuid) throws AsdcCatalogException { - final JSONObject resource = getCatalog().getJSONObject("resources") - .getJSONObject(uuid.toString()); - return convert(resource, Resource.class); - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResources() - */ - public Collection<Resource> getResources() throws AsdcCatalogException { - final Collection<Resource> resources = new LinkedList<Resource>(); - - for (String key : getCatalog().getJSONObject("resources").keySet()) { - final JSONObject json = getCatalog().getJSONObject("resources").getJSONObject(key); - final Resource resource = convert(json, Resource.class); - resources.add(resource); - } - - return resources; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResources(java.util.Map) - */ - public Collection<Resource> getResources(Map<String, String[]> filter) throws AsdcCatalogException { - final Collection<Resource> resources = new LinkedList<Resource>(); - - for (String key : getCatalog().getJSONObject("resources").keySet()) { - final JSONObject json = getCatalog().getJSONObject("resources").getJSONObject(key); - - boolean filterMatch = true; - - for (Map.Entry<String, String[]> entry : filter.entrySet()) { - for (int i = 0; i < entry.getValue().length; i++) { - if (!json.getString(entry.getKey()).equals(entry.getValue()[i])) { - filterMatch = false; - break; - } - } - } - - if (filterMatch) resources.add(convert(json, Resource.class)); - } - - return resources; - } - - /* (non-Javadoc) * @see org.onap.vid.asdc.AsdcClient#getService(java.util.UUID) */ public Service getService(UUID uuid) throws AsdcCatalogException { JSONObject serviceJsonObject = null; - final JSONArray categoryJsonArray = getCatalog().getJSONArray("services"); + final JSONArray categoryJsonArray = getCatalog().getJSONArray(SERVICES); for (int i = 0; i < categoryJsonArray.length(); i++) { JSONObject jsonServiceObject = categoryJsonArray.getJSONObject(i); @@ -165,132 +115,34 @@ public class LocalAsdcClient implements AsdcClient { } /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getServices() - */ - public Collection<Service> getServices() throws AsdcCatalogException { - final Collection<Service> services = new LinkedList<Service>(); - - JSONArray servicesArr = getCatalog().getJSONArray("services"); - - for (Object objService : servicesArr) { - JSONObject jsonServiceItem = (JSONObject) objService; - final Service service = convert(jsonServiceItem, Service.class); - services.add(service); - } - - return services; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getServices(java.util.Map) - */ - public Collection<Service> getServices(Map<String, String[]> filter) throws AsdcCatalogException { - final Collection<Service> services = new LinkedList<Service>(); - - JSONArray catalogServices = catalog.getJSONArray("services"); - - for (int i = 0; i < catalogServices.length(); i++) { - - JSONObject serviceJson = catalogServices.getJSONObject(i); - - boolean filterMatch = true; - - for (Map.Entry<String, String[]> entry : filter.entrySet()) { - for (int j = 0; j < entry.getValue().length; j++) { - if (!serviceJson.getString(entry.getKey()).equals(entry.getValue()[j])) { - filterMatch = false; - break; - } - } - } - if (filterMatch) services.add(convert(serviceJson, Service.class)); - } - return services; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResourceArtifact(java.util.UUID, java.util.UUID) - */ - public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException { - final JSONArray artifacts = getCatalog().getJSONObject("resources") - .getJSONObject(resourceUuid.toString()) - .getJSONArray("artifacts"); - - for (int i = 0; i < artifacts.length(); i++) { - final JSONObject artifact = artifacts.getJSONObject(i); - - if (artifact.getString("artifactUUID").equals(artifactUuid.toString())) { - return convert(artifact, Artifact.class); - } - } - - return null; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getServiceArtifact(java.util.UUID, java.util.UUID) - */ - public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException { - final JSONArray artifacts = getCatalog().getJSONObject("services") - .getJSONObject(serviceUuid.toString()) - .getJSONArray("artifacts"); - - for (int i = 0; i < artifacts.length(); i++) { - final JSONObject artifact = artifacts.getJSONObject(i); - - if (artifact.getString("artifactUUID").equals(artifactUuid.toString())) { - return convert(artifact, Artifact.class); - } - } - - return null; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID) - */ - public Path getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException { - final String toscaModelURL = getCatalog().getJSONObject("resources") - .getJSONObject(resourceUuid.toString()) - .getString("toscaModelURL"); - - - final InputStream toscaModelStream = getClass().getClassLoader().getResourceAsStream(toscaModelURL); - - if (toscaModelStream == null) return null; - - return null;//getToscaModel(toscaModelStream); - } - - /* (non-Javadoc) * @see org.onap.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID) */ public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException { String toscaModelURL = null; - final JSONArray categoryJsonArray = getCatalog().getJSONArray("services"); + final JSONArray categoryJsonArray = getCatalog().getJSONArray(SERVICES); for (int i = 0; i < categoryJsonArray.length(); i++) { JSONObject jsonServiceObject = categoryJsonArray.getJSONObject(i); if (jsonServiceObject.get("uuid").equals(serviceUuid.toString())) { toscaModelURL = jsonServiceObject.getString("toscaModelURL"); - break; } } if (toscaModelURL == null) { return null; } - final InputStream toscaModelStream = getClass().getClassLoader().getResourceAsStream(toscaModelURL); - ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource(toscaModelURL).getFile()); - Path path = Paths.get(file.getPath()); - - if (toscaModelStream == null) return null; - return path; + try { + //using URLDecoder.decode to convert special characters from %XX to real character + //see https://stackoverflow.com/questions/32251251/java-classloader-getresource-with-special-characters-in-path + return Paths.get(URLDecoder.decode(file.getPath(), "UTF-8")); + } catch (UnsupportedEncodingException e) { + throw new GenericUncheckedException(e); + } } /** @@ -346,7 +198,7 @@ public class LocalAsdcClient implements AsdcClient { */ private JSONObject catalog = new JSONObject() .put("resources", new JSONObject()) - .put("services", new JSONObject()); + .put(SERVICES, new JSONObject()); /** * The mapper. diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/memory/InMemoryAsdcClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/memory/InMemoryAsdcClient.java deleted file mode 100644 index 780e82a6f..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/memory/InMemoryAsdcClient.java +++ /dev/null @@ -1,372 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.asdc.memory; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.Collection; -import java.util.LinkedList; -import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; -import java.util.zip.ZipFile; - -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.json.JSONArray; -import org.json.JSONObject; -import org.yaml.snakeyaml.Yaml; - -import org.onap.vid.asdc.AsdcCatalogException; -import org.onap.vid.asdc.AsdcClient; -import org.onap.vid.asdc.beans.Artifact; -import org.onap.vid.asdc.beans.Resource; -import org.onap.vid.asdc.beans.Service; -import org.onap.vid.asdc.beans.tosca.ToscaCsar; -import org.onap.vid.asdc.beans.tosca.ToscaMeta; -import org.onap.vid.asdc.beans.tosca.ToscaModel; - -/** - * The Class InMemoryAsdcClient. - */ -public class InMemoryAsdcClient implements AsdcClient { - - /** The catalog. */ - private final JSONObject catalog; - - /** The mapper. */ - private final ObjectMapper mapper; - - /** - * The Class Builder. - */ - public static class Builder { - - /** The catalog. */ - private JSONObject catalog = new JSONObject() - .put("resources", new JSONObject()) - .put("services", new JSONObject()); - - /** The mapper. */ - private ObjectMapper mapper = new ObjectMapper(); - - /** - * Instantiates a new builder. - */ - public Builder() {} - - /** - * Catalog. - * - * @param catalog the catalog - * @return the builder - */ - public Builder catalog(JSONObject catalog) { - this.catalog = catalog; - return this; - } - - /** - * Mapper. - * - * @param mapper the mapper - * @return the builder - */ - public Builder mapper(ObjectMapper mapper) { - this.mapper = mapper; - return this; - } - - /** - * Builds the. - * - * @return the in memory sdc client - */ - public InMemoryAsdcClient build() { - return new InMemoryAsdcClient(this); - } - } - - /** - * Instantiates a new in memory sdc client. - * - * @param builder the builder - */ - private InMemoryAsdcClient(Builder builder) { - catalog = builder.catalog; - mapper = builder.mapper; - } - - /** - * Gets the catalog. - * - * @return the catalog - */ - private JSONObject getCatalog() { - return catalog; - } - - /** - * Gets the mapper. - * - * @return the mapper - */ - private ObjectMapper getMapper() { - return mapper; - } - - /** - * Convert. - * - * @param <T> the generic type - * @param json the json - * @param clazz the clazz - * @return the t - * @throws AsdcCatalogException the sdc catalog exception - */ - private <T> T convert(JSONObject json, Class<T> clazz) throws AsdcCatalogException { - try { - return getMapper().readValue(json.toString(), clazz); - } catch (JsonParseException e) { - throw new AsdcCatalogException("Failed to parse SDC response (bad data)", e); - } catch (JsonMappingException e) { - throw new AsdcCatalogException("Failed to map SDC response to internal VID data structure(s)", e); - } catch (IOException e) { - throw new AsdcCatalogException("Failed to get a response from SDC", e); - } - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResource(java.util.UUID) - */ - public Resource getResource(UUID uuid) throws AsdcCatalogException { - final JSONObject resource = getCatalog().getJSONObject("resources") - .getJSONObject(uuid.toString()); - return convert(resource, Resource.class); - } - - /* (non-Javadoc) - */ - public Collection<Resource> getResources() throws AsdcCatalogException { - final Collection<Resource> resources = new LinkedList<Resource> (); - - for (String key : getCatalog().getJSONObject("resources").keySet()) { - final JSONObject json = getCatalog().getJSONObject("resources").getJSONObject(key); - final Resource resource = convert(json, Resource.class); - resources.add(resource); - } - - return resources; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResources(java.util.Map) - */ - public Collection<Resource> getResources(Map<String, String[]> filter) throws AsdcCatalogException { - final Collection<Resource> resources = new LinkedList<Resource> (); - - for (String key : getCatalog().getJSONObject("resources").keySet()) { - final JSONObject json = getCatalog().getJSONObject("resources").getJSONObject(key); - - boolean filterMatch = true; - - for (Entry<String, String[]> entry : filter.entrySet()) { - for (int i = 0; i < entry.getValue().length; i++) { - if (!json.getString(entry.getKey()).equals(entry.getValue()[i])) { - filterMatch = false; - break; - } - } - } - - if (filterMatch) resources.add(convert(json, Resource.class)); - } - - return resources; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getService(java.util.UUID) - */ - public Service getService(UUID uuid) throws AsdcCatalogException { - final JSONObject service = getCatalog().getJSONObject("services") - .getJSONObject(uuid.toString()); - return convert(service, Service.class); - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getServices() - */ - public Collection<Service> getServices() throws AsdcCatalogException { - final Collection<Service> services = new LinkedList<Service> (); - - for (String key : getCatalog().getJSONObject("services").keySet()) { - final JSONObject json = getCatalog().getJSONObject("services").getJSONObject(key); - final Service service = convert(json, Service.class); - services.add(service); - } - - return services; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getServices(java.util.Map) - */ - public Collection<Service> getServices(Map<String, String[]> filter) throws AsdcCatalogException { - final Collection<Service> services = new LinkedList<Service> (); - - for (String key : getCatalog().getJSONObject("services").keySet()) { - final JSONObject json = getCatalog().getJSONObject("services").getJSONObject(key); - - boolean filterMatch = true; - - for (Entry<String, String[]> entry : filter.entrySet()) { - for (int i = 0; i < entry.getValue().length; i++) { - if (!json.getString(entry.getKey()).equals(entry.getValue()[i])) { - filterMatch = false; - break; - } - } - } - - if (filterMatch) services.add(convert(json, Service.class)); - } - - return services; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResourceArtifact(java.util.UUID, java.util.UUID) - */ - public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException { - final JSONArray artifacts = getCatalog().getJSONObject("resources") - .getJSONObject(resourceUuid.toString()) - .getJSONArray("artifacts"); - - for (int i = 0; i < artifacts.length(); i++) { - final JSONObject artifact = artifacts.getJSONObject(i); - - if (artifact.getString("artifactUUID").equals(artifactUuid.toString())) { - return convert(artifact, Artifact.class); - } - } - - return null; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getServiceArtifact(java.util.UUID, java.util.UUID) - */ - public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException { - final JSONArray artifacts = getCatalog().getJSONObject("services") - .getJSONObject(serviceUuid.toString()) - .getJSONArray("artifacts"); - - for (int i = 0; i < artifacts.length(); i++) { - final JSONObject artifact = artifacts.getJSONObject(i); - - if (artifact.getString("artifactUUID").equals(artifactUuid.toString())) { - return convert(artifact, Artifact.class); - } - } - - return null; - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID) - */ - public Path getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException { - final String toscaModelURL = getCatalog().getJSONObject("resources") - .getJSONObject(resourceUuid.toString()) - .getString("toscaModelURL"); - - - final InputStream toscaModelStream = getClass().getClassLoader().getResourceAsStream(toscaModelURL); - - if (toscaModelStream == null) return null; - - return null;//getToscaModel(toscaModelStream); - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID) - */ - public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException { - final String toscaModelURL = getCatalog().getJSONObject("services") - .getJSONObject(serviceUuid.toString()) - .getString("toscaModelURL"); - - final InputStream toscaModelStream = getClass().getClassLoader().getResourceAsStream(toscaModelURL); - - if (toscaModelStream == null) return null; - - return null;//getToscaModel(toscaModelStream); - } - - /** - * Gets the tosca model. - * - * @param csarInputStream the csar input stream - * @return the tosca model - * @throws AsdcCatalogException the asdc catalog exception - */ - private ToscaCsar getToscaModel(InputStream csarInputStream) throws AsdcCatalogException { - final Path csarFile; - - try { - csarFile = Files.createTempFile("csar", ".zip"); - Files.copy(csarInputStream, csarFile, StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - throw new AsdcCatalogException("Caught IOException while creating CSAR", e); - } - - try (final ZipFile csar = new ZipFile(csarFile.toFile())) { - - final InputStream toscaMetaStream = csar.getInputStream(csar.getEntry("TOSCA-Metadata/TOSCA.meta")); - final ToscaMeta toscaMeta = new ToscaMeta.Builder(toscaMetaStream).build(); - final String entryDefinitions = toscaMeta.get("Entry-Definitions"); - final InputStream toscaParentEntryYamlStream = csar.getInputStream(csar.getEntry(entryDefinitions)); - - final Yaml yaml = new Yaml(); - final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class); - - final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel); - - for (Map<String, Map<String, String>> imports : parentModel.getImports()) { - for (Entry<String, Map<String, String>> entry : imports.entrySet()) { - final InputStream toscaChildEntryYamlStream = csar.getInputStream(csar.getEntry("Definitions/" + entry.getValue().get("file"))); - final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class); - csarBuilder.addVnf(childModel); - } - } - - return csarBuilder.build(); - } catch (IOException e) { - throw new AsdcCatalogException("Caught IOException while processing CSAR", e); - } - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParser.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParser.java index 6da1738a9..8af1f7b02 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParser.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParser.java @@ -1,15 +1,14 @@ package org.onap.vid.asdc.parser; -import java.nio.file.Path; - -import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.vid.asdc.AsdcCatalogException; -import org.onap.vid.asdc.beans.tosca.ToscaCsar; import org.onap.vid.asdc.beans.Service; +import org.onap.vid.asdc.beans.tosca.ToscaCsar; import org.onap.vid.model.ServiceModel; +import java.nio.file.Path; + public interface ToscaParser{ ToscaCsar parse(Path path) throws AsdcCatalogException; - ServiceModel makeServiceModel(String uuid,Path path,Service asdcServiceMetadata) throws Exception; + ServiceModel makeServiceModel(String uuid,Path path,Service asdcServiceMetadata) throws AsdcCatalogException; }
\ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java index 37f4b0ab0..27445c0f3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java @@ -1,49 +1,34 @@ package org.onap.vid.asdc.parser; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.Map.Entry; -import java.util.zip.ZipFile; - import org.apache.commons.lang3.mutable.MutableBoolean; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.asdc.beans.Service; import org.onap.vid.asdc.beans.tosca.NodeTemplate; import org.onap.vid.asdc.beans.tosca.ToscaCsar; import org.onap.vid.asdc.beans.tosca.ToscaMeta; import org.onap.vid.asdc.beans.tosca.ToscaModel; -import org.onap.vid.model.ModelConstants; -import org.onap.vid.model.Network; -import org.onap.vid.model.Node; -import org.onap.vid.model.ServiceModel; -import org.onap.vid.model.VNF; +import org.onap.vid.model.*; import org.onap.vid.properties.VidProperties; -import org.springframework.beans.factory.annotation.Autowired; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.error.YAMLException; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.zip.ZipFile; + public class ToscaParserImpl implements ToscaParser { /** The Constant LOG. */ static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ToscaParserImpl.class); - @Autowired - private final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - - private static final String asdcModelNamespace = VidProperties.getAsdcModelNamespace(); - private static final String vnfTag = asdcModelNamespace + ModelConstants.VNF; - private static final String networkTag = asdcModelNamespace + ModelConstants.NETWORK; - private static final String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE; + private static final String ASDC_MODEL_NAMESPACE = VidProperties.getAsdcModelNamespace(); + private static final String VNF_TAG = ASDC_MODEL_NAMESPACE + ModelConstants.VNF; + private static final String NETWORK_TAG = ASDC_MODEL_NAMESPACE + ModelConstants.NETWORK; @Override @@ -60,29 +45,7 @@ public class ToscaParserImpl implements ToscaParser { final InputStream toscaParentEntryYamlStream = csar.getInputStream(csar.getEntry(entryDefinitions)); try { - final Yaml yaml = new Yaml(); - final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class); - - final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel); - - for (Map<String, Map<String, String>> imports : parentModel.getImports()) { - LOG.debug("imports = " + imports.toString()); - for (Entry<String, Map<String, String>> entry : imports.entrySet()) { - if (entry.getValue() != null) { - String fname = entry.getValue().get("file"); - if ((fname != null) && (fname.startsWith("service") || fname.startsWith("resource"))) { - LOG.debug("fname = " + fname); - final InputStream toscaChildEntryYamlStream = csar - .getInputStream(csar.getEntry("Definitions/" + fname)); - - final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class); - csarBuilder.addVnf(childModel); - } - } - } - } - - return csarBuilder.build(); + return createToscaCsar(csar, toscaParentEntryYamlStream); } catch (YAMLException e) { throw new AsdcCatalogException("Caught exception while processing TOSCA YAML", e); } @@ -91,22 +54,49 @@ public class ToscaParserImpl implements ToscaParser { } } - public ServiceModel makeServiceModel(String uuid, final Path serviceCsar,Service service ) throws AsdcCatalogException, SdcToscaParserException { + private ToscaCsar createToscaCsar(ZipFile csar, InputStream toscaParentEntryYamlStream) throws IOException { + final Yaml yaml = new Yaml(); + final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class); + + final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel); + + for (Map<String, Map<String, String>> imports : parentModel.getImports()) { + LOG.debug("imports = " + imports.toString()); + for (Entry<String, Map<String, String>> entry : imports.entrySet()) { + if (entry.getValue() != null) { + String fname = entry.getValue().get("file"); + if ((fname != null) && (fname.startsWith("service") || fname.startsWith("resource"))) { + LOG.debug("fname = " + fname); + final InputStream toscaChildEntryYamlStream = csar + .getInputStream(csar.getEntry("Definitions/" + fname)); + + final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class); + csarBuilder.addVnf(childModel); + } + } + } + } + + return csarBuilder.build(); + } + + public ServiceModel makeServiceModel(String uuid, final Path serviceCsar,Service service ) throws AsdcCatalogException { final ServiceModel serviceModel = new ServiceModel(); ToscaCsar toscaCsar = getToscaCsar(serviceCsar); String methodName = "getServices"; - LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start"); MutableBoolean isNewFlow = new MutableBoolean(false); - final Map<String, VNF> vnfs = new HashMap<String, VNF>(); - final Map<String, Network> networks = new HashMap<String, Network>(); + final Map<String, VNF> vnfs = new HashMap<>(); + final Map<String, Network> networks = new HashMap<>(); final ToscaModel asdcServiceToscaModel = toscaCsar.getParent(); serviceModel.setService(ServiceModel.extractService(asdcServiceToscaModel, service)); + populateVnfsAndNetwork(methodName, isNewFlow, vnfs, networks, asdcServiceToscaModel, serviceModel); + // If we see customization uuid under vnf or network, follow 1702 flow if (isNewFlow.getValue()) { return (getCustomizedServices(asdcServiceToscaModel, serviceModel)); @@ -147,33 +137,30 @@ public class ToscaParserImpl implements ToscaParser { } private static void populateVnfsAndNetwork(String methodName, MutableBoolean isNewFlow, final Map<String, VNF> vnfs, - final Map<String, Network> networks, final ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) - throws AsdcCatalogException, SdcToscaParserException { + final Map<String, Network> networks, final ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) { for (Entry<String, NodeTemplate> component : extractNodeTemplates(asdcServiceToscaModel)) { final String modelCustomizationName = component.getKey(); - LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " model customization name: " + modelCustomizationName); final NodeTemplate nodeTemplate = component.getValue(); final String type = nodeTemplate.getType(); - if (type.startsWith(vnfTag)) { + if (type.startsWith(VNF_TAG)) { LOG.debug(EELFLoggerDelegate.debugLogger, - dateFormat.format(new Date()) + methodName + " found node template type: " + type); + methodName + " found node template type: " + type); final VNF vnf = new VNF(); vnf.extractVnf(modelCustomizationName, nodeTemplate); -// populateNodeVersionIfMissing(nodeTemplate, vnf,service); LOG.debug(EELFLoggerDelegate.debugLogger, - dateFormat.format(new Date()) + methodName + " VNF commands: " + vnf.getCommands()); + methodName + " VNF commands: " + vnf.getCommands()); vnfs.put(modelCustomizationName, vnf); isNewFlow.setValue(isNewFlow(vnf)); } // Networks - if (type.startsWith(networkTag)) { + if (type.startsWith(NETWORK_TAG)) { LOG.debug(EELFLoggerDelegate.debugLogger, - dateFormat.format(new Date()) + methodName + " found node template type: " + type); + methodName + " found node template type: " + type); final Network network = new Network(); network.extractNetwork(modelCustomizationName, nodeTemplate); -// populateNodeVersionIfMissing(nodeTemplate, network, service); isNewFlow.setValue(isNewFlow(network)); networks.put(modelCustomizationName, network); @@ -192,20 +179,8 @@ public class ToscaParserImpl implements ToscaParser { return (node.getCustomizationUuid() != null) && (node.getCustomizationUuid().length() > 0); } - private static boolean isNodeVersionMissing(Node Node) { - return Node.getVersion() == null; - } - - private static void populateNodeVersionIfMissing(final NodeTemplate nodeTemplate, final Node node, Service service) - throws AsdcCatalogException { - if (isNodeVersionMissing(node)) { - node.setVersion(service.getVersion()); - } - } - private ServiceModel getCustomizedServices(ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) { String methodName = "asdcServiceToscaModel"; - LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start"); // asdcServiceToscaModel should have vf modules and vol groups populated // at this point but @@ -217,10 +192,4 @@ public class ToscaParserImpl implements ToscaParser { return (serviceModel); } - - private UUID extractUUIDFromNodeTemplate(final NodeTemplate nodeTemplate) { - return UUID.fromString(nodeTemplate.getMetadata().getUUID()); - } - - }
\ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java index e75bb3063..17fb29b59 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java @@ -7,6 +7,7 @@ import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.tosca.parser.impl.FilterType; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; import org.onap.sdc.tosca.parser.impl.SdcTypes; +import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.*; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.sdc.toscaparser.api.parameters.Input; @@ -16,98 +17,208 @@ import java.util.*; import java.util.stream.Collectors; import static java.util.stream.Collectors.toMap; +import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.VF_MODULE_LABEL; public class ToscaParserImpl2 { public class Constants { - public final static String uuid = "UUID"; - public final static String description = "description"; - public final static String serviceType = "serviceType"; - public final static String serviceRole = "serviceRole"; - public final static String ecompGeneratedNaming = "ecompGeneratedNaming"; - - public final static String customizationUUID = "customizationUUID"; - public final static String vfModuleModelVersion = "vfModuleModelVersion"; - public final static String vfModuleModelCustomizationUUID = "vfModuleModelCustomizationUUID"; - public final static String volume_group = "volume_group"; - public final static String vfModuleModelInvariantUUID = "vfModuleModelInvariantUUID"; - public final static String vfModuleModelUUID = "vfModuleModelUUID"; - public final static String invariantUUID = "invariantUUID"; - public final static String version = "version"; - public final static String name = "name"; - public final static String category = "category"; - public final static String vfModuleModelName = "vfModuleModelName"; - public final static String getInput = "get_input"; - - public final static String instantiationType = "instantiationType"; - //Instantiation Types - public final static String both = "Both"; - public final static String macro = "Macro"; - public final static String aLaCarte = "A-La-Carte"; - public final static String clientConfig = "ClientConfig"; - - - } - - public ToscaParserImpl2() { - + public final static String UUID = "UUID"; + public final static String DESCRIPTION = "description"; + public final static String SERVICE_TYPE = "serviceType"; + public final static String SERVICE_ROLE = "serviceRole"; + public final static String ECOMP_GENERATED_NAMING = "ecompGeneratedNaming"; + + public final static String CUSTOMIZATION_UUID = "customizationUUID"; + public final static String VF_MODULE_MODEL_VERSION = "vfModuleModelVersion"; + public final static String VF_MODULE_MODEL_CUSTOMIZATION_UUID = "vfModuleModelCustomizationUUID"; + public final static String VOLUME_GROUP = "volume_group"; + public final static String VF_MODULE_MODEL_INVARIANT_UUID = "vfModuleModelInvariantUUID"; + public final static String VF_MODULE_MODEL_UUID = "vfModuleModelUUID"; + public final static String INVARIANT_UUID = "invariantUUID"; + public final static String VERSION = "version"; + public final static String NAME = "name"; + public final static String CATEGORY = "category"; + public final static String VF_MODULE_MODEL_NAME = "vfModuleModelName"; + public final static String GET_INPUT = "get_input"; + public final static String TYPE = "type"; + + public final static String INSTANTIATION_TYPE = "instantiationType"; + //instantiation type + public final static String BOTH = "Both"; + public final static String MACRO = "Macro"; + public final static String A_LA_CARTE = "A-La-Carte"; + public final static String CLIENT_CONFIG = "ClientConfig"; + + //group properties + public final static String MIN_VF_MODULE_INSTANCES = "min_vf_module_instances"; + public final static String MAX_VF_MODULE_INSTANCES = "max_vf_module_instances"; + public final static String INITIAL_COUNT = "initial_count"; + public final static String VF_MODULE_LABEL = "vf_module_label"; + + //collection resource properties + public final static String SUBCATEGORY = "subcategory"; + public final static String RESOURCE_VENDOR = "resourceVendor"; + public final static String RESOURCE_VENDOR_RELEASE = "resourceVendorRelease"; + public final static String RESOURCE_VENDOR_MODEL_NUMBER = "resourceVendorModelNumber"; + public final static String ORG_OPENECOMP_GROUPS_NETWORK_COLLECTION = "org.openecomp.groups.NetworkCollection"; + public final static String NETWORK_COLLECTION_FUNCTION = "network_collection_function"; + public final static String NETWORK_COLLECTION_DESCRIPTION = "network_collection_description"; + + //vfc instance group properties + public final static String VFC_INSTANCE_GROUP_TYPE = "org.openecomp.groups.VfcInstanceGroup"; + public final static String VFC_PARENT_PORT_ROLE = "vfc_parent_port_role"; + public final static String SUBINTERFACE_ROLE = "subinterface_role"; + public final static String VFC_INSTANCE_GROUP_FUNCTION = "vfc_instance_group_function"; } + + public ToscaParserImpl2() {} - public ServiceModel makeServiceModel(Path path, Service asdcServiceMetadata) throws Exception { + public ServiceModel makeServiceModel(Path path, Service asdcServiceMetadata) throws SdcToscaParserException { ServiceModel serviceModel = new ServiceModel(); SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(),false); - serviceModel.setService(extractServiceFromCsar(asdcServiceMetadata, sdcCsarHelper)); + serviceModel.setService(extractServiceFromCsar(asdcServiceMetadata, sdcCsarHelper)); serviceModel.setVolumeGroups(extractVolumeGroups(sdcCsarHelper)); serviceModel.setVfModules(extractVfModuleFromCsar(sdcCsarHelper)); - serviceModel.setVnfs(extractVnfsFromCsar(serviceModel,sdcCsarHelper)); + serviceModel.setVnfs(extractVnfsFromCsar(sdcCsarHelper)); serviceModel.setConfigurations(extractPortMirroringConfigFromCsar(sdcCsarHelper)); serviceModel.setServiceProxies(extractServiceProxyFromCsar(sdcCsarHelper)); serviceModel.setNetworks(extractNetworksFromCsar(sdcCsarHelper)); serviceModel.setPnfs(extractPnfsFromCsar(sdcCsarHelper)); + serviceModel.setCollectionResource(extractCRFromCsar(sdcCsarHelper)); return serviceModel; } + + private org.onap.vid.model.Service extractServiceFromCsar(Service asdcServiceMetadata, ISdcCsarHelper csarHelper) throws SdcToscaParserException { org.onap.vid.model.Service service = new org.onap.vid.model.Service(); - service.setName(csarHelper.getServiceMetadata().getValue(Constants.name)); - service.setCategory(csarHelper.getServiceMetadata().getValue(Constants.category)); - service.setInvariantUuid(csarHelper.getServiceMetadata().getValue(Constants.invariantUUID)); - service.setUuid(csarHelper.getServiceMetadata().getValue(Constants.uuid)); + service.setName(csarHelper.getServiceMetadata().getValue(Constants.NAME)); + service.setCategory(csarHelper.getServiceMetadata().getValue(Constants.CATEGORY)); + service.setInvariantUuid(csarHelper.getServiceMetadata().getValue(Constants.INVARIANT_UUID)); + service.setUuid(csarHelper.getServiceMetadata().getValue(Constants.UUID)); service.setVersion(asdcServiceMetadata.getVersion()); - service.setDescription(csarHelper.getServiceMetadata().getValue(Constants.description)); - service.setInputs(inputsListToInputsMap(csarHelper.getServiceInputs())); - service.setServiceEcompNaming(csarHelper.getServiceMetadata().getValue(Constants.ecompGeneratedNaming)); - service.setServiceType(csarHelper.getServiceMetadata().getValue(Constants.serviceType)); - service.setServiceRole(csarHelper.getServiceMetadata().getValue(Constants.serviceRole)); + service.setDescription(csarHelper.getServiceMetadata().getValue(Constants.DESCRIPTION)); + service.setInputs(inputsListToInputsMap(csarHelper.getInputsWithAnnotations())); + service.setServiceEcompNaming(csarHelper.getServiceMetadata().getValue(Constants.ECOMP_GENERATED_NAMING)); + service.setServiceType(csarHelper.getServiceMetadata().getValue(Constants.SERVICE_TYPE)); + service.setServiceRole(csarHelper.getServiceMetadata().getValue(Constants.SERVICE_ROLE)); service.setInstantiationType(validateInstantiationType(csarHelper)); return service; } - - private Map<String, VNF> extractVnfsFromCsar(ServiceModel serviceModel,ISdcCsarHelper csarHelper) { + private Map<String,CR> extractCRFromCsar(ISdcCsarHelper sdcCsarHelper) { + List<NodeTemplate> nodeTemplates = sdcCsarHelper.getServiceNodeTemplates(); + Map<String, CR> collectionResourceMap = new HashMap<>(); + + for(NodeTemplate nodeTemplate: nodeTemplates){ + if(nodeTemplate.getMetaData().getValue(Constants.TYPE).equals(SdcTypes.CR.getValue())) { + CR cr = new CR(); + populateCrFromNodeTemplate(nodeTemplate, sdcCsarHelper, cr); + collectionResourceMap.put(nodeTemplate.getName(), cr); + } + } + + return collectionResourceMap; + } + + private void populateCrFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper sdcCsarHelper, CR cr) { + populateNodeFromNodeTemplate(nodeTemplate, sdcCsarHelper, cr); + cr.setCustomizationUUID(nodeTemplate.getMetaData().getValue(Constants.CUSTOMIZATION_UUID)); + cr.setCategory(nodeTemplate.getMetaData().getValue(Constants.CATEGORY)); + cr.setSubcategory(nodeTemplate.getMetaData().getValue(Constants.SUBCATEGORY)); + cr.setResourceVendor(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR)); + cr.setResourceVendorRelease(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR_RELEASE)); + cr.setResourceVendorModelNumber(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR_MODEL_NUMBER)); + cr.setNetworksCollection(getNetworksCollectionMapFromGroupsList(sdcCsarHelper, nodeTemplate)); + } + + private Map<String, NetworkCollection> getNetworksCollectionMapFromGroupsList(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + List<Group> groups = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, Constants.ORG_OPENECOMP_GROUPS_NETWORK_COLLECTION); + Map<String, NetworkCollection> networksCollectionMap = new HashMap<String, NetworkCollection>(); + for(Group group: groups){ + networksCollectionMap.put(group.getName(), populateCollectionNetworkFromGroup(group, nodeTemplate)); + } + return networksCollectionMap; + } + + private NetworkCollection populateCollectionNetworkFromGroup(Group group, NodeTemplate nodeTemplate) { + NetworkCollection networkCollection = new NetworkCollection(); + networkCollection.setUuid(group.getMetadata().getValue(Constants.UUID)); + networkCollection.setInvariantUuid(group.getMetadata().getValue(Constants.INVARIANT_UUID)); + networkCollection.setVersion(group.getMetadata().getValue(Constants.VERSION)); + networkCollection.setName(group.getMetadata().getValue(Constants.NAME)); + extractPropertiesOfCollectionNetworkFromCsar(group, nodeTemplate, networkCollection); + + return networkCollection; + } + + private void extractPropertiesOfCollectionNetworkFromCsar(Group group, NodeTemplate nodeTemplate, NetworkCollection networkCollection) { + LinkedHashMap<String, Property> properties = group.getProperties(); + Map<String, Property> nodeTemplateProperties = nodeTemplate.getProperties(); + + String networkCollectionFunction = (String)((Map)(properties.get(Constants.NETWORK_COLLECTION_FUNCTION).getValue())).get(Constants.GET_INPUT); + String networkCollectionDescription = (String)((Map)(properties.get(Constants.NETWORK_COLLECTION_DESCRIPTION).getValue())).get(Constants.GET_INPUT); + + networkCollection.getNetworkCollectionProperties().setNetworkCollectionDescription((String)nodeTemplateProperties.get(networkCollectionDescription).getValue()); + networkCollection.getNetworkCollectionProperties().setNetworkCollectionFunction((String)nodeTemplateProperties.get(networkCollectionFunction).getValue()); + } + + + private Map<String, VNF> extractVnfsFromCsar(ISdcCsarHelper csarHelper) { List<NodeTemplate> nodeTemplates = csarHelper.getServiceVfList(); Map<String, VNF> vnfsMaps = new HashMap<String, VNF>(); for (NodeTemplate nodeTemplate : nodeTemplates) { VNF vnf = new VNF(); populateNodeFromNodeTemplate(nodeTemplate, csarHelper, vnf); - vnf.setModelCustomizationName(nodeTemplate.getName()); - Map<String, VfModule> vfModuleHashMap = getVfModulesFromVF(csarHelper, vnf.getCustomizationUuid()); - vnf.setVfModules(vfModuleHashMap); - - Map<String, VolumeGroup> volumeGroupMap = getVolumeGroupsFromVF(csarHelper, vnf.getCustomizationUuid()); - vnf.setVolumeGroups(volumeGroupMap); + vnf.setVfModules(getVfModulesFromVF(csarHelper, vnf.getCustomizationUuid())); + vnf.setVolumeGroups(getVolumeGroupsFromVF(csarHelper, vnf.getCustomizationUuid())); + vnf.setVfcInstanceGroups(getVfcInstanceGroup(csarHelper, nodeTemplate)); vnfsMaps.put(nodeTemplate.getName(), vnf); } return vnfsMaps; } + private Map<String,VfcInstanceGroup> getVfcInstanceGroup(ISdcCsarHelper csarHelper, NodeTemplate nodeTemplate) { + List<Group> vfcList = csarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, Constants.VFC_INSTANCE_GROUP_TYPE); + return vfcList.stream() + .collect(toMap(Group::getName, group -> populateVfcInstanceGroupFromGroup(group, csarHelper, nodeTemplate))); + } + + private VfcInstanceGroup populateVfcInstanceGroupFromGroup(Group group, ISdcCsarHelper csarHelper, NodeTemplate nodeTemplate) { + VfcInstanceGroup vfcInstanceGroup = new VfcInstanceGroup(); + vfcInstanceGroup.setUuid(group.getMetadata().getValue(Constants.UUID)); + vfcInstanceGroup.setInvariantUuid(group.getMetadata().getValue(Constants.INVARIANT_UUID)); + vfcInstanceGroup.setVersion(group.getMetadata().getValue(Constants.VERSION)); + vfcInstanceGroup.setName(group.getMetadata().getValue(Constants.NAME)); + vfcInstanceGroup.setVfcInstanceGroupProperties(getVfcPropertiesFromGroup(nodeTemplate, group)); + + return vfcInstanceGroup; + + } + + private VfcInstanceGroupProperties getVfcPropertiesFromGroup(NodeTemplate nodeTemplate, Group group) { + VfcInstanceGroupProperties vfcInstanceGroupProperties = new VfcInstanceGroupProperties(); + vfcInstanceGroupProperties.setVfcParentPortRole((String) group.getProperties().get(Constants.VFC_PARENT_PORT_ROLE).getValue()); + vfcInstanceGroupProperties.setSubinterfaceRole((String) group.getProperties().get(Constants.SUBINTERFACE_ROLE).getValue()); + + String networkCollectionFunction = (String)((Map)(group.getProperties().get(Constants.NETWORK_COLLECTION_FUNCTION).getValue())).get(Constants.GET_INPUT); + String vfcInstanceGroupFunction = (String)((Map)(group.getProperties().get(Constants.VFC_INSTANCE_GROUP_FUNCTION).getValue())).get(Constants.GET_INPUT); + + if(nodeTemplate.getProperties().get(networkCollectionFunction) != null) + vfcInstanceGroupProperties.setNetworkCollectionFunction((String) nodeTemplate.getProperties().get(networkCollectionFunction).getValue()); + if(nodeTemplate.getProperties().get(vfcInstanceGroupFunction) != null) + vfcInstanceGroupProperties.setVfcInstanceGroupFunction((String) nodeTemplate.getProperties().get(vfcInstanceGroupFunction).getValue()); + + return vfcInstanceGroupProperties; + } + private Map<String, PortMirroringConfig> extractPortMirroringConfigFromCsar(ISdcCsarHelper csarHelper) { List<NodeTemplate> nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION); Map<String, PortMirroringConfig> configMaps = new HashMap<>(); @@ -175,18 +286,18 @@ public class ToscaParserImpl2 { Map<String, VfModule> getVfModulesFromVF(ISdcCsarHelper csarHelper, String vfUuid) { List<Group> vfModulesByVf = csarHelper.getVfModulesByVf(vfUuid); return vfModulesByVf.stream() - .collect(toMap(Group::getName, this::populateVfModuleFromGroup)); + .collect(toMap(Group::getName, group -> populateVfModuleFromGroup(group, csarHelper))); } Map<String, VolumeGroup> getVolumeGroupsFromVF(ISdcCsarHelper csarHelper, String vfCustomizationUuid) { List<Group> vfModulesByVf = csarHelper.getVfModulesByVf(vfCustomizationUuid); return vfModulesByVf.stream() .filter((group -> isVolumeGroup(group))) - .collect(toMap(Group::getName, this::populateVolumeGroupFromGroup)); + .collect(toMap(Group::getName, group -> populateVolumeGroupFromGroup(group, csarHelper))); } private static Boolean isVolumeGroup(Group group) { - return Boolean.valueOf(group.getPropertyValue(Constants.volume_group).toString()); + return Boolean.valueOf(group.getPropertyValue(Constants.VOLUME_GROUP).toString()); } private Map<String, Network> extractNetworksFromCsar(ISdcCsarHelper csarHelper) { @@ -220,7 +331,7 @@ public class ToscaParserImpl2 { for (NodeTemplate nodeTemplate : serviceVfList) { Map<String, VfModule> nodeTemplateVfModule = - getVfModulesFromVF(csarHelper, nodeTemplate.getMetaData().getValue(Constants.customizationUUID)); + getVfModulesFromVF(csarHelper, nodeTemplate.getMetaData().getValue(Constants.CUSTOMIZATION_UUID)); vfModuleHashMap.putAll(nodeTemplateVfModule); } return vfModuleHashMap; @@ -239,60 +350,109 @@ public class ToscaParserImpl2 { private Map<String, org.onap.vid.asdc.beans.tosca.Input> inputsListToInputsMap(List<org.onap.sdc.toscaparser.api.parameters.Input> inputList) { Map<String, org.onap.vid.asdc.beans.tosca.Input> inputs = new HashMap<>(); for (org.onap.sdc.toscaparser.api.parameters.Input input : inputList) { - inputs.put(input.getName(), convertInput(input, new org.onap.vid.asdc.beans.tosca.Input(), null)); + //Set only inputs without annotation to the service level + if(input.getAnnotations() == null) + inputs.put(input.getName(), convertInput(input, new org.onap.vid.asdc.beans.tosca.Input(), null)); } return inputs; } private Node populateNodeFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode) { newNode.setCustomizationUuid(csarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); - newNode.setDescription(nodeTemplate.getMetaData().getValue(Constants.description)); - newNode.setInvariantUuid(nodeTemplate.getMetaData().getValue(Constants.invariantUUID)); - newNode.setUuid(nodeTemplate.getMetaData().getValue(Constants.uuid)); - newNode.setName(nodeTemplate.getMetaData().getValue(Constants.name)); - newNode.setVersion(nodeTemplate.getMetaData().getValue(Constants.version)); + newNode.setDescription(nodeTemplate.getMetaData().getValue(Constants.DESCRIPTION)); + newNode.setInvariantUuid(nodeTemplate.getMetaData().getValue(Constants.INVARIANT_UUID)); + newNode.setUuid(nodeTemplate.getMetaData().getValue(Constants.UUID)); + newNode.setName(nodeTemplate.getMetaData().getValue(Constants.NAME)); + newNode.setVersion(nodeTemplate.getMetaData().getValue(Constants.VERSION)); newNode.setInputs(extractInputsAndCommandsForNodeTemplate(nodeTemplate, csarHelper, newNode)); - newNode.setType(nodeTemplate.getMetaData().getValue("type")); + newNode.setType(nodeTemplate.getMetaData().getValue(Constants.TYPE)); Map<String, String> propertiesMap = setPropertiesOfVnf(nodeTemplate.getPropertiesObjects()); newNode.setProperties(propertiesMap); return newNode; } - private VfModule populateVfModuleFromGroup(Group group){ + private VfModule populateVfModuleFromGroup(Group group, ISdcCsarHelper csarHelper){ VfModule vfModule = new VfModule(); - - vfModule.setVersion(group.getMetadata().getValue(Constants.vfModuleModelVersion)); - vfModule.setCustomizationUuid(group.getMetadata().getValue(Constants.vfModuleModelCustomizationUUID)); - vfModule.setModelCustomizationName(group.getMetadata().getValue(Constants.vfModuleModelName)); - vfModule.setName(group.getMetadata().getValue(Constants.vfModuleModelName)); + extractBasicPropertiesForGroup(vfModule, group, csarHelper); vfModule.setVolumeGroupAllowed(isVolumeGroup(group)); - vfModule.setDescription(group.getDescription()); - vfModule.setInvariantUuid(group.getMetadata().getValue(Constants.vfModuleModelInvariantUUID)); - vfModule.setUuid(group.getMetadata().getValue(Constants.vfModuleModelUUID)); - vfModule.setProperties(group.getProperties()); return vfModule; } - private VolumeGroup populateVolumeGroupFromGroup(Group group){ + private VolumeGroup populateVolumeGroupFromGroup(Group group, ISdcCsarHelper csarHelper){ VolumeGroup volumeGroup = new VolumeGroup(); - volumeGroup.setDescription(group.getDescription()); - volumeGroup.setInvariantUuid(group.getMetadata().getValue(Constants.vfModuleModelInvariantUUID)); - volumeGroup.setName(group.getMetadata().getValue(Constants.vfModuleModelName)); - volumeGroup.setModelCustomizationName(group.getMetadata().getValue(Constants.vfModuleModelName)); - volumeGroup.setVersion(group.getMetadata().getValue(Constants.vfModuleModelVersion)); - volumeGroup.setUuid(group.getMetadata().getValue(Constants.vfModuleModelUUID)); - volumeGroup.setCustomizationUuid(group.getMetadata().getValue(Constants.vfModuleModelCustomizationUUID)); - + extractBasicPropertiesForGroup(volumeGroup, group, csarHelper); return volumeGroup; } + private void extractBasicPropertiesForGroup(org.onap.vid.model.Group newGroup, Group group, ISdcCsarHelper csarHelper) { + newGroup.setDescription(group.getDescription()); + newGroup.setVersion(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_VERSION)); + newGroup.setCustomizationUuid(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_CUSTOMIZATION_UUID)); + newGroup.setModelCustomizationName(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_NAME)); + newGroup.setName(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_NAME)); + newGroup.setUuid(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_UUID)); + newGroup.setInvariantUuid(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_INVARIANT_UUID)); + newGroup.setProperties(extractVfModuleProperties(group, csarHelper)); + newGroup.setInputs(extractVfInputsFromCsarByAnnotation(csarHelper, newGroup)); + } + + + private Map<String,org.onap.vid.asdc.beans.tosca.Input> extractVfInputsFromCsarByAnnotation(ISdcCsarHelper csarHelper, org.onap.vid.model.Group group) { + Map<String, org.onap.vid.asdc.beans.tosca.Input> inputMap = new HashMap<>(); + if(group.getProperties().getVfModuleLabel() != null){ + List<Input> inputsList = csarHelper.getInputsWithAnnotations(); + for(Input input: inputsList){ + if(input.getAnnotations() != null){ + List<Property> annotationProperties = input.getAnnotations().get("source").getProperties(); + if(isInputMatchesToGroup(annotationProperties, group)){ + inputMap.put(input.getName(), new org.onap.vid.asdc.beans.tosca.Input(input ,annotationProperties)); + } + } + } + } + return inputMap; + } + + + private boolean isInputMatchesToGroup(List<Property> annotationProperties, org.onap.vid.model.Group group){ + for(Property property: annotationProperties){ + if(property.getName().equals(VF_MODULE_LABEL)){ + return getPropertyValueAsString(property).equals(group.getProperties().getVfModuleLabel()); + } + } + return false; + } + + public String getPropertyValueAsString(Property property) { + return removeSquareBrackets(property.getValue().toString()); + } + + private String removeSquareBrackets(String stringWithSquareBrackets){ + return stringWithSquareBrackets.substring(1, stringWithSquareBrackets.length()-1); + } + + private GroupProperties extractVfModuleProperties(Group group, ISdcCsarHelper csarHelper){ + GroupProperties vfModuleProperties = new GroupProperties(); + if(csarHelper.getGroupPropertyAsObject(group, Constants.MIN_VF_MODULE_INSTANCES) != null) + vfModuleProperties.setMinCountInstances((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.MIN_VF_MODULE_INSTANCES)); + if(csarHelper.getGroupPropertyAsObject(group, Constants.MAX_VF_MODULE_INSTANCES) != null) + vfModuleProperties.setMaxCountInstances((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.MAX_VF_MODULE_INSTANCES)); + if(csarHelper.getGroupPropertyAsObject(group, Constants.INITIAL_COUNT) != null) + vfModuleProperties.setInitialCount((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.INITIAL_COUNT)); + if(csarHelper.getGroupPropertyAsObject(group, VF_MODULE_LABEL) != null) + vfModuleProperties.setVfModuleLabel((String) csarHelper.getGroupPropertyAsObject(group, VF_MODULE_LABEL)); + return vfModuleProperties; + } + + + private Map<String, org.onap.vid.asdc.beans.tosca.Input> extractInputsAndCommandsForNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode){ Map<String, org.onap.vid.asdc.beans.tosca.Input> inputMap = new HashMap<>(); Map<String, CommandProperty> commandPropertyMap = new HashMap<>(); List<Input> inputs = csarHelper.getServiceInputs(); - Map<String, String> properties = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.getInput); + Map<String, String> properties = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.GET_INPUT); for (Map.Entry<String, String> property : properties.entrySet()) { String inputKey = property.getValue(); String key = extractInputValue(inputKey); @@ -337,7 +497,7 @@ public class ToscaParserImpl2 { private CommandProperty extractCommands(String displayName, String inputName){ CommandProperty commandProperty = new CommandProperty(); commandProperty.setDisplayName(displayName); - commandProperty.setCommand(Constants.getInput); + commandProperty.setCommand(Constants.GET_INPUT); commandProperty.setInputName(inputName); return commandProperty; } @@ -345,19 +505,23 @@ public class ToscaParserImpl2 { private Map<String, String> setPropertiesOfVnf(List<Property> properties) { Map<String, String> propertiesMap = new HashMap<String, String>(); for (Property property : properties) { + //special handling to necessary sub-property "ecomp_generated_naming" + if(property.getName().equals("nf_naming")){ + propertiesMap.put(removeSquareBrackets(((LinkedHashMap)(property.getValue())).keySet().toString()) ,((LinkedHashMap)(property.getValue())).get("ecomp_generated_naming").toString()); + } propertiesMap.put(property.getName(), property.getValue().toString()); } return propertiesMap; } private String validateInstantiationType(ISdcCsarHelper csarHelper){ - String instantiationType = csarHelper.getServiceMetadata().getValue(Constants.instantiationType); - String validatedInstantiationType = Constants.clientConfig; + String instantiationType = csarHelper.getServiceMetadata().getValue(Constants.INSTANTIATION_TYPE); + String validatedInstantiationType = Constants.CLIENT_CONFIG; if(instantiationType != null && !instantiationType.isEmpty()){ - if(instantiationType.equalsIgnoreCase(Constants.macro) || instantiationType.equalsIgnoreCase(Constants.both)) - validatedInstantiationType = Constants.macro; - else if(instantiationType.equalsIgnoreCase(Constants.aLaCarte)) - validatedInstantiationType = Constants.aLaCarte; + if(instantiationType.equalsIgnoreCase(Constants.MACRO) || instantiationType.equalsIgnoreCase(Constants.BOTH)) + validatedInstantiationType = Constants.MACRO; + else if(instantiationType.equalsIgnoreCase(Constants.A_LA_CARTE)) + validatedInstantiationType = Constants.A_LA_CARTE; } return validatedInstantiationType; } diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/rest/RestfulAsdcClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/rest/RestfulAsdcClient.java index 7ac0fa398..5dd0f4cce 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/rest/RestfulAsdcClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/rest/RestfulAsdcClient.java @@ -20,43 +20,35 @@ package org.onap.vid.asdc.rest; +import com.att.eelf.configuration.EELFLogger; import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.asdc.AsdcClient; -import org.onap.vid.asdc.beans.Artifact; -import org.onap.vid.asdc.beans.Resource; import org.onap.vid.asdc.beans.Service; -import org.onap.vid.asdc.parser.ToscaParserImpl; import org.onap.vid.model.ModelConstants; import org.onap.vid.properties.VidProperties; +import org.onap.vid.utils.Logging; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.http.HttpMethod; -import javax.ws.rs.NotFoundException; import javax.ws.rs.ProcessingException; import javax.ws.rs.WebApplicationException; import javax.ws.rs.client.Client; import javax.ws.rs.client.ResponseProcessingException; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.Response; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Collection; import java.util.Collections; -import java.util.Map; -import java.util.Map.Entry; import java.util.UUID; -import static org.onap.vid.utils.Logging.getHttpServletRequest; -import static org.onap.vid.utils.Logging.requestIdHeaderKey; +import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY; /** * The Class RestfulAsdcClient. */ @@ -122,10 +114,7 @@ public class RestfulAsdcClient implements AsdcClient { */ static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(RestfulAsdcClient.class); - /** - * The Constant dateFormat. - */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + final private static EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("asdc"); /** * The client. @@ -147,8 +136,6 @@ public class RestfulAsdcClient implements AsdcClient { */ private final String auth; - ToscaParserImpl p = new ToscaParserImpl(); - /** * Instantiates a new restful asdc client. * @@ -160,8 +147,8 @@ public class RestfulAsdcClient implements AsdcClient { auth = builder.auth; commonHeaders = new MultivaluedHashMap<String, Object>(); - commonHeaders.put("Authorization", Collections.singletonList((Object) (auth))); commonHeaders.put("X-ECOMP-InstanceID", Collections.singletonList((Object) (SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME)))); + commonHeaders.put("Authorization", Collections.singletonList((Object) (auth))); } private Path createTmpFile(InputStream csarInputStream) throws AsdcCatalogException { @@ -185,252 +172,32 @@ public class RestfulAsdcClient implements AsdcClient { } /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResource(java.util.UUID) - */ - public Resource getResource(UUID uuid) throws AsdcCatalogException { - - String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH); - try { - return getClient() - .target(uri) - .path(path + "/" + uuid.toString() + "/metadata") - .request(MediaType.APPLICATION_JSON_TYPE) - .headers(commonHeaders) - .header("Content-Type", MediaType.APPLICATION_JSON) - .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey)) - .get(Resource.class); - } catch (ResponseProcessingException e) { - //Couldn't convert response to Java type - throw new AsdcCatalogException("SDC response could not be processed", e); - } catch (ProcessingException e) { - //IO problems during request - throw new AsdcCatalogException("Failed to get a response from SDC service", e); - } catch (WebApplicationException e) { - //Web service returned data, but the response status wasn't a good one (i.e. non 2xx) - throw new AsdcCatalogException(e); - } - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResourceArtifact(java.util.UUID, java.util.UUID) - */ - public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException { - String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH); - try { - return getClient() - .target(uri) - .path(path + "/" + resourceUuid + "/artifacts/" + artifactUuid) - .request(MediaType.APPLICATION_JSON_TYPE) - .headers(commonHeaders) - .header("Content-Type", MediaType.APPLICATION_JSON) - .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey)) - .get(Artifact.class); - } catch (ResponseProcessingException e) { - //Couldn't convert response to Java type - throw new AsdcCatalogException("SDC response could not be processed", e); - } catch (ProcessingException e) { - //IO problems during request - throw new AsdcCatalogException("Failed to get a response from SDC service", e); - } catch (WebApplicationException e) { - //Web service returned data, but the response status wasn't a good one (i.e. non 2xx) - throw new AsdcCatalogException(e); - } - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResources() - */ - public Collection<Resource> getResources() throws AsdcCatalogException { - String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH); - try { - return getClient() - .target(uri) - .path(path) - .request(MediaType.APPLICATION_JSON_TYPE) - .headers(commonHeaders) - .header("Content-Type", MediaType.APPLICATION_JSON) - .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey)) - .get(new GenericType<Collection<Resource>>() { - }); - } catch (ResponseProcessingException e) { - //Couldn't convert response to Java type - throw new AsdcCatalogException("SDC response could not be processed", e); - } catch (ProcessingException e) { - //IO problems during request - throw new AsdcCatalogException("Failed to get a response from SDC service", e); - } catch (WebApplicationException e) { - //Web service returned data, but the response status wasn't a good one (i.e. non 2xx) - throw new AsdcCatalogException(e); - } - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResources(java.util.Map) - */ - public Collection<Resource> getResources(Map<String, String[]> filter) throws AsdcCatalogException { - String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH); - WebTarget target = getClient() - .target(uri) - .path(path); - - for (Entry<String, String[]> filterEntry : filter.entrySet()) { - target = target.queryParam(filterEntry.getKey(), (Object[]) filterEntry.getValue()); - } - - try { - return target.request() - .accept(MediaType.APPLICATION_JSON_TYPE) - .headers(commonHeaders) - .header("Content-Type", MediaType.APPLICATION_JSON) - .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey)) - .get(new GenericType<Collection<Resource>>() { - }); - } catch (ResponseProcessingException e) { - //Couldn't convert response to Java type - throw new AsdcCatalogException("SDC response could not be processed", e); - } catch (ProcessingException e) { - //IO problems during request - throw new AsdcCatalogException("Failed to get a response from SDC service", e); - } catch (NotFoundException e) { - throw e; - } catch (WebApplicationException e) { - //Web service returned data, but the response status wasn't a good one (i.e. non 2xx) - throw new AsdcCatalogException(e); - } - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID) - */ - public Path getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException { - String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH); - try (final InputStream csarInputStream = (InputStream) getClient() - .target(uri) - .path(path + "/" + resourceUuid + "/toscaModel") - .request(MediaType.APPLICATION_OCTET_STREAM_TYPE) - .headers(commonHeaders) - .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM) - .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey)) - .get(InputStream.class)) { - - return getToscaCsar(csarInputStream); - } catch (IOException e) { - throw new AsdcCatalogException("Failed to retrieve resource TOSCA model from SDC", e); - } - } - - /* (non-Javadoc) * @see org.onap.vid.asdc.AsdcClient#getService(java.util.UUID) */ public Service getService(UUID uuid) throws AsdcCatalogException { - String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH); + String path = VidProperties.getPropertyWithDefault( + ModelConstants.ASDC_SVC_API_PATH, + ModelConstants.DEFAULT_ASDC_SVC_API_PATH); + + String url = uri+path + "/" + uuid.toString() + "/metadata"; + Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); try { - return getClient() + Response response = getClient() .target(uri) .path(path + "/" + uuid.toString() + "/metadata") .request(MediaType.APPLICATION_JSON) .headers(commonHeaders) - .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey)) - .get(Service.class); - } catch (ResponseProcessingException e) { - //Couldn't convert response to Java type - throw new AsdcCatalogException("SDC response could not be processed", e); - } catch (ProcessingException e) { - //IO problems during request - throw new AsdcCatalogException("Failed to get a response from SDC service", e); - } catch (WebApplicationException e) { - //Web service returned data, but the response status wasn't a good one (i.e. non 2xx) - throw new AsdcCatalogException(e); - } - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getServiceArtifact(java.util.UUID, java.util.UUID) - */ - public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException { - String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH); - - try { - return getClient() - .target(uri) - .path(path + "/" + serviceUuid + "/artifacts/" + artifactUuid) - .request(MediaType.APPLICATION_JSON_TYPE) - .headers(commonHeaders) - .header("Content-Type", MediaType.APPLICATION_JSON) - .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey)) - .get(Artifact.class); - } catch (ResponseProcessingException e) { - //Couldn't convert response to Java type - throw new AsdcCatalogException("SDC response could not be processed", e); - } catch (ProcessingException e) { - //IO problems during request - throw new AsdcCatalogException("Failed to get a response from SDC service", e); - } catch (WebApplicationException e) { - //Web service returned data, but the response status wasn't a good one (i.e. non 2xx) - throw new AsdcCatalogException(e); - } - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getServices() - */ - public Collection<Service> getServices() throws AsdcCatalogException { - String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH); - try { - return getClient() - .target(uri) - .path(path) - .request() - .accept(MediaType.APPLICATION_JSON_TYPE) - .headers(commonHeaders) - .header("Content-Type", MediaType.APPLICATION_JSON) - .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey)) - .get(new GenericType<Collection<Service>>() { - }); - } catch (ResponseProcessingException e) { - //Couldn't convert response to Java type - throw new AsdcCatalogException("SDC response could not be processed", e); - } catch (ProcessingException e) { - //IO problems during request - throw new AsdcCatalogException("Failed to get a response from SDC service", e); - } catch (WebApplicationException e) { - //Web service returned data, but the response status wasn't a good one (i.e. non 2xx) - throw new AsdcCatalogException(e); - } - } - - /* (non-Javadoc) - * @see org.onap.vid.asdc.AsdcClient#getServices(java.util.Map) - */ - public Collection<Service> getServices(Map<String, String[]> filter) throws AsdcCatalogException { - - String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH); - WebTarget target = getClient() - .target(uri) - .path(path); - - - for (Entry<String, String[]> filterEntry : filter.entrySet()) { - target = target.queryParam(filterEntry.getKey(), (Object[]) filterEntry.getValue()); - } - - try { - return target.request() - .accept(MediaType.APPLICATION_JSON_TYPE) - .headers(commonHeaders) - .header("Content-Type", MediaType.APPLICATION_JSON) - .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey)) - .get(new GenericType<Collection<Service>>() { - }); + .header(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId()) + .get(); + Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, response); + return response.readEntity(Service.class); } catch (ResponseProcessingException e) { //Couldn't convert response to Java type throw new AsdcCatalogException("SDC response could not be processed", e); } catch (ProcessingException e) { //IO problems during request throw new AsdcCatalogException("Failed to get a response from SDC service", e); - } catch (NotFoundException e) { - throw e; } catch (WebApplicationException e) { //Web service returned data, but the response status wasn't a good one (i.e. non 2xx) throw new AsdcCatalogException(e); @@ -442,41 +209,34 @@ public class RestfulAsdcClient implements AsdcClient { * @see org.onap.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID) */ public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException { - String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH); + String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, + ModelConstants.DEFAULT_ASDC_SVC_API_PATH); + + String url = uri+path + "/" + serviceUuid + "/toscaModel"; + Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); try { - final InputStream csarInputStream = (InputStream) getClient() + final InputStream csarInputStream = getClient() .target(uri) .path(path + "/" + serviceUuid + "/toscaModel") .request(MediaType.APPLICATION_OCTET_STREAM_TYPE) .headers(commonHeaders) .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM) - .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey)) + .header(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId()) .get(InputStream.class); - - - return getToscaCsar(csarInputStream); + Path toscaFilePath = createTmpFile(csarInputStream); + outgoingRequestsLogger.debug("Received {} {} . Tosca file was saved at: {}", HttpMethod.GET.name(), url, toscaFilePath.toAbsolutePath()); + return toscaFilePath; } catch (ResponseProcessingException e) { //Couldn't convert response to Java type throw new AsdcCatalogException("SDC response could not be processed", e); } catch (ProcessingException e) { //IO problems during request - throw new AsdcCatalogException("Failed to get a response from SDC service", e); + throw new AsdcCatalogException("Failed to get a response from SDC service. Cause: "+e.getMessage(), e); } catch (WebApplicationException e) { //Web service returned data, but the response status wasn't a good one (i.e. non 2xx) throw new AsdcCatalogException(e); } } - - /** - * Gets the tosca model. - * - * @param csarInputStream the csar input stream - * @return the tosca model - * @throws AsdcCatalogException the asdc catalog exception - */ - private Path getToscaCsar(InputStream csarInputStream) throws AsdcCatalogException { - return createTmpFile(csarInputStream); - } } |