diff options
author | DR695H <dr695h@att.com> | 2017-02-07 14:21:32 -0500 |
---|---|---|
committer | DR695H <dr695h@att.com> | 2017-02-07 14:21:40 -0500 |
commit | ab9f3f111118a9ef5ca9cf302b690128023d6fce (patch) | |
tree | 8cf63d32159746ed4765677988ca21508642d02e /src/main | |
parent | ad79e6eed1a1497ddf3a6d252d77301f6122a0b8 (diff) |
Initial OpenECOMP VID ASDC Client commit
Change-Id: I7ce3f07829106a386240325a67ab533f85332d42
Signed-off-by: DR695H <dr695h@att.com>
Diffstat (limited to 'src/main')
22 files changed, 4113 insertions, 0 deletions
diff --git a/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java b/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java new file mode 100644 index 0000000..6a8ab91 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc; + +/** + * The Class AsdcCatalogException. + */ +public class AsdcCatalogException extends Exception { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 1L; + + /** + * Instantiates a new asdc catalog exception. + * + * @param msg the msg + */ + public AsdcCatalogException(String msg) { + super(msg); + } + + /** + * Instantiates a new asdc catalog exception. + * + * @param cause the cause + */ + public AsdcCatalogException(Throwable cause) { + super(cause); + } + + /** + * Instantiates a new asdc catalog exception. + * + * @param msg the msg + * @param t the t + */ + public AsdcCatalogException(String msg, Throwable t) { + super(msg, t); + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/AsdcClient.java b/src/main/java/org/openecomp/vid/asdc/AsdcClient.java new file mode 100644 index 0000000..ec5ba78 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/AsdcClient.java @@ -0,0 +1,128 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc; + +import java.util.Collection; +import java.util.Map; +import java.util.UUID; + +import org.openecomp.vid.asdc.beans.Artifact; +import org.openecomp.vid.asdc.beans.Resource; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.asdc.beans.tosca.ToscaCsar; + +/** + * The Interface AsdcClient. + */ +public interface AsdcClient { + + /** + * Gets the resource. + * + * @param uuid the uuid + * @return the resource + * @throws AsdcCatalogException the asdc catalog exception + */ + public Resource getResource(UUID uuid) throws AsdcCatalogException; + + /** + * Gets the resources. + * + * @return the resources + * @throws AsdcCatalogException the asdc catalog exception + */ + public Collection<Resource> getResources() throws AsdcCatalogException; + + /** + * Gets the resources. + * + * @param filter the filter + * @return the resources + * @throws AsdcCatalogException the asdc 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 asdc 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 asdc catalog exception + */ + public ToscaCsar getResourceToscaModel(UUID uuid) throws AsdcCatalogException; + + /** + * Gets the service. + * + * @param uuid the uuid + * @return the service + * @throws AsdcCatalogException the asdc catalog exception + */ + public Service getService(UUID uuid) throws AsdcCatalogException; + + /** + * Gets the services. + * + * @return the services + * @throws AsdcCatalogException the asdc 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; + + /** + * Gets the service tosca model. + * + * @param uuid the uuid + * @return the service tosca model + * @throws AsdcCatalogException the asdc catalog exception + */ + public ToscaCsar getServiceToscaModel(UUID uuid) throws AsdcCatalogException; + + //TODO: Collect TOSCA information from CSAR +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java b/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java new file mode 100644 index 0000000..b260abb --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java @@ -0,0 +1,277 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans; + +import java.util.UUID; + +/** + * The Class Artifact. + */ +public class Artifact { + +/* + * ASDC has widened this to a String type for 1610. + public enum Type { + HEAT, + HEAT_ENV, + HEAT_VOL, + HEAT_NET, + HEAT_NESTED, + HEAT_ARTIFACT, + YANG_XML, + VNF_CATALOG, + VF_LICENSE, + VENDOR_LICENSE, + ASSET_INVENTORY_PROFILE, + ASSET_QUERY_SPEC, + APPC_CONFIG, + VF_MODULES_METADATA, + DCAE_TOSCA, + DCAE_JSON, + DCAE_EMF, + DCAE_DOC, + DCAE_BLUEPRINT, + DCAE_EVENT, + DCAE_INVENTORY_TOSCA, + DCAE_INVENTORY_JSON, + DCAE_INVENTORY_EMF, + DCAE_INVENTORY_DOC, + DCAE_INVENTORY_BLUEPRINT, + DCAE_INVENTORY_EVENT, + OTHER, + AAI_SERVICE_MODEL //HEY! READ ME! YES, YOU! I AM A TEMPORARY FIX, PLEASE REMOVE ME BECAUSE I AM A FRAUD. I DON'T BELONG HERE. + //Warm Regards, + // *The* Artifact.Type.AAI_SERVICE_MODEL Constant + } + */ + + /** The artifact name. */ +private String artifactName; + + /** The artifact type. */ + private String artifactType; + + /** The artifact URL. */ + private String artifactURL; + + /** The artifact description. */ + private String artifactDescription; + + /** The artifact timeout. */ + private int artifactTimeout; + + /** The artifact checksum. */ + private String artifactChecksum; + + /** The artifact UUID. */ + private String artifactUUID; + + /** The artifact version. */ + private String artifactVersion; + + /** The generated from UUID. */ + private String generatedFromUUID; + + /** + * Gets the artifact name. + * + * @return the artifact name + */ + public String getArtifactName() { + return artifactName; + } + + /** + * Gets the artifact type. + * + * @return the artifact type + */ + public String getArtifactType() { + return artifactType; + } + + /** + * Gets the artifact URL. + * + * @return the artifact URL + */ + public String getArtifactURL() { + return artifactURL; + } + + /** + * Gets the artifact description. + * + * @return the artifact description + */ + public String getArtifactDescription() { + return artifactDescription; + } + + /** + * Gets the artifact timeout. + * + * @return the artifact timeout + */ + public int getArtifactTimeout() { + return artifactTimeout; + } + + /** + * Gets the artifact checksum. + * + * @return the artifact checksum + */ + public String getArtifactChecksum() { + return artifactChecksum; + } + + /** + * Gets the artifact UUID. + * + * @return the artifact UUID + */ + public String getArtifactUUID() { + return artifactUUID; + } + + /** + * Gets the artifact version. + * + * @return the artifact version + */ + public String getArtifactVersion() { + return artifactVersion; + } + + /** + * Gets the generated from UUID. + * + * @return the generated from UUID + */ + public String getGeneratedFromUUID() { + return generatedFromUUID; + } + + /** + * Sets the artifact name. + * + * @param artifactName the new artifact name + */ + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + /** + * Sets the artifact type. + * + * @param artifactType the new artifact type + */ + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + /** + * Sets the artifact URL. + * + * @param artifactURL the new artifact URL + */ + public void setArtifactURL(String artifactURL) { + this.artifactURL = artifactURL; + } + + /** + * Sets the artifact description. + * + * @param artifactDescription the new artifact description + */ + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + /** + * Sets the artifact timeout. + * + * @param artifactTimeout the new artifact timeout + */ + public void setArtifactTimeout(int artifactTimeout) { + this.artifactTimeout = artifactTimeout; + } + + /** + * Sets the artifact checksum. + * + * @param artifactChecksum the new artifact checksum + */ + public void setArtifactChecksum(String artifactChecksum) { + this.artifactChecksum = artifactChecksum; + } + + /** + * Sets the artifact UUID. + * + * @param artifactUUID the new artifact UUID + */ + public void setArtifactUUID(String artifactUUID) { + this.artifactUUID = artifactUUID; + } + + /** + * Sets the artifact version. + * + * @param artifactVersion the new artifact version + */ + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + /** + * Sets the generated from UUID. + * + * @param generatedFromUUID the new generated from UUID + */ + public void setGeneratedFromUUID(String generatedFromUUID) { + this.generatedFromUUID = generatedFromUUID; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final UUID uuid = UUID.fromString(getArtifactUUID()); + + 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 Artifact)) return false; + + final Artifact artifact = (Artifact) o; + + return (artifact.getArtifactUUID().equals(getArtifactUUID())); + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/Resource.java b/src/main/java/org/openecomp/vid/asdc/beans/Resource.java new file mode 100644 index 0000000..94804a5 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/Resource.java @@ -0,0 +1,407 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.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 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 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 uid. */ + 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 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 uid. + * + * @return the last updater user uid + */ + 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 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 uid. + * + * @param lastUpdaterUserId the new last updater user uid + */ + 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/src/main/java/org/openecomp/vid/asdc/beans/Service.java b/src/main/java/org/openecomp/vid/asdc/beans/Service.java new file mode 100644 index 0000000..da3d42d --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/Service.java @@ -0,0 +1,351 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans; + +import java.util.Collection; +import java.util.UUID; +/** + * The Class Service. + */ +public class Service { + + /** + * The Enum DistributionStatus. + */ + public enum DistributionStatus { + + /** The distribution not approved. */ + DISTRIBUTION_NOT_APPROVED, + + /** The distribution approved. */ + DISTRIBUTION_APPROVED, + + /** The distributed. */ + DISTRIBUTED, + + /** The distribution rejected. */ + DISTRIBUTION_REJECTED + } + + /** + * 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 version. */ + private String version; + + /** The tosca model URL. */ + private String toscaModelURL; + + /** The category. */ + private String category; + + /** The lifecycle state. */ + private Service.LifecycleState lifecycleState; + + /** The last updater user uid. */ + private String lastUpdaterUserId; + + /** The last updater full name. */ + private String lastUpdaterFullName; + + /** The distribution status. */ + private Service.DistributionStatus distributionStatus; + + /** 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 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 lifecycle state. + * + * @return the lifecycle state + */ + public Service.LifecycleState getLifecycleState() { + return lifecycleState; + } + + /** + * Gets the last updater user uid. + * + * @return the last updater user uid + */ + public String getLastUpdaterUserId() { + return lastUpdaterUserId; + } + + /** + * Gets the last updater full name. + * + * @return the last updater full name + */ + public String getLastUpdaterFullName() { + return lastUpdaterFullName; + } + + /** + * Gets the distribution status. + * + * @return the distribution status + */ + public Service.DistributionStatus getDistributionStatus() { + return distributionStatus; + } + + /** + * 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 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 lifecycle state. + * + * @param lifecycleState the new lifecycle state + */ + public void setLifecycleState(Service.LifecycleState lifecycleState) { + this.lifecycleState = lifecycleState; + } + + /** + * Sets the last updater user uid. + * + * @param lastUpdaterUserId the new last updater user uid + */ + 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 distribution status. + * + * @param distributionStatus the new distribution status + */ + public void setDistributionStatus(Service.DistributionStatus distributionStatus) { + this.distributionStatus = distributionStatus; + } + + /** + * 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#toString() + */ + @Override + public String toString() { + return uuid; + } + + /* (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 Service)) return false; + + final Service service = (Service) o; + + return (service.getUuid().equals(getUuid())); + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java b/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java new file mode 100644 index 0000000..2031e27 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java @@ -0,0 +1,175 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans; + +import java.util.Collection; +/** + * The Class SubResource. + */ +public class SubResource { + + /** The resource instance name. */ + private String resourceInstanceName; + + /** The resource name. */ + private String resourceName; + + /** The resource invariant UUID. */ + private String resourceInvariantUUID; + + /** The resource version. */ + private String resourceVersion; + + /** The resource type. */ + private String resourceType; + + /** The resource UUID. */ + private String resourceUUID; + + /** The artifacts. */ + private Collection<Artifact> artifacts; + + /** + * Gets the resource instance name. + * + * @return the resource instance name + */ + public String getResourceInstanceName() { + return resourceInstanceName; + } + + /** + * Gets the resource name. + * + * @return the resource name + */ + public String getResourceName() { + return resourceName; + } + + /** + * Gets the resource invariant UUID. + * + * @return the resource invariant UUID + */ + public String getResourceInvariantUUID() { + return resourceInvariantUUID; + } + + /** + * Gets the resource version. + * + * @return the resource version + */ + public String getResourceVersion() { + return resourceVersion; + } + + /** + * Gets the resoucre type. + * + * @return the resoucre type + */ + public String getResoucreType() { + return resourceType; + } + + /** + * Gets the resource UUID. + * + * @return the resource UUID + */ + public String getResourceUUID() { + return resourceUUID; + } + + /** + * Gets the artifacts. + * + * @return the artifacts + */ + public Collection<Artifact> getArtifacts() { + return artifacts; + } + + /** + * Sets the resource instance name. + * + * @param resourceInstanceName the new resource instance name + */ + public void setResourceInstanceName(String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + } + + /** + * Sets the resource name. + * + * @param resourceName the new resource name + */ + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + /** + * Sets the resource invariant UUID. + * + * @param resourceInvariantUUID the new resource invariant UUID + */ + public void setResourceInvariantUUID(String resourceInvariantUUID) { + this.resourceInvariantUUID = resourceInvariantUUID; + } + + /** + * Sets the resource version. + * + * @param resourceVersion the new resource version + */ + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + /** + * Sets the resoucre type. + * + * @param resourceType the new resoucre type + */ + public void setResoucreType(String resourceType) { + this.resourceType = resourceType; + } + + /** + * Sets the resource UUID. + * + * @param resourceUUID the new resource UUID + */ + public void setResourceUUID(String resourceUUID) { + this.resourceUUID = resourceUUID; + } + + /** + * Sets the artifacts. + * + * @param artifacts the new artifacts + */ + public void setArtifacts(Collection<Artifact> artifacts) { + this.artifacts = artifacts; + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java new file mode 100644 index 0000000..11e53ec --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java @@ -0,0 +1,140 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.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/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java new file mode 100644 index 0000000..25db4d4 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java @@ -0,0 +1,135 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +import java.util.Collection; +import java.util.Map; + +/** + * The Class Group. + */ +public class Group { + + /** The type. */ + private String type; + + /** The members. */ + private Collection<String> members; + + /** The metadata. */ + private ToscaMetadata metadata; + + /** The vf module type. */ + private String vf_module_type; + + /** The properties. */ + private Map<String, String> properties; + + /** + * Gets the metadata. + * + * @return the metadata + */ + public ToscaMetadata getMetadata() { + return metadata; + } + + /** + * Sets the metadata. + * + * @param metadata the new metadata + */ + public void setMetadata(ToscaMetadata metadata) { + this.metadata = metadata; + } + + /** + * Gets the members. + * + * @return the members + */ + public Collection<String> getMembers() { + return members; + } + + /** + * Sets the members. + * + * @param members the new members + */ + public void setMembers(Collection<String> members) { + this.members = members; + } + + /** + * Gets the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Sets the type. + * + * @param type the new type + */ + public void setType(String type) { + this.type = type; + } + + /** + * Gets the vf module type. + * + * @return the vf module type + */ + public String getvf_module_type() { + return vf_module_type; + } + + /** + * Sets the vf module type. + * + * @param vf_module_type the new vf module type + */ + public void setvf_module_type(String vf_module_type) { + this.vf_module_type = vf_module_type; + } + + /** + * Gets the properties. + * + * @return the properties + */ + public Map<String, String> getProperties() { + return properties; + } + + /** + * Sets the properties. + * + * @param properties the properties + */ + public void setProperties(Map<String, String> properties) { + this.properties = properties; + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java new file mode 100644 index 0000000..8fcd7e1 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +/** + * The Class Import. + */ +public class Import { + + /** The file. */ + private String file; + + /** + * Gets the file. + * + * @return the file + */ + public String getFile() { + return file; + } + + /** + * Sets the file. + * + * @param file the new file + */ + public void setFile(String file) { + this.file = file; + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java new file mode 100644 index 0000000..8612181 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java @@ -0,0 +1,125 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +// TODO: Auto-generated Javadoc +/** + * The Class Input. + */ +public class Input { + + /** The type. */ + private String type; + + /** The description. */ + private String description; + + /** The default. */ + private Object _default; + + /** The entry schema. */ + private Input entry_schema; + + /** + * Instantiates a new input. + */ + public Input() {} + + /** + * Gets the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Sets the type. + * + * @param type the new type + */ + public void setType(String type) { + this.type = type; + } + + /** + * Gets the description. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Sets the description. + * + * @param description the new description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Gets the default. + * + * @return the default + */ + public Object getDefault() { + return _default; + } + + /** + * Sets the default. + * + * @param _default the new default + */ + public void setDefault(Object _default) { + this._default = _default; + } + + /** + * Gets the entry schema. + * + * @return the entry schema + */ + public Input getentry_schema() { + return entry_schema; + } + + /** + * Sets the entry schema. + * + * @param entry_schema the new entry schema + */ + public void setentry_schema(Input entry_schema) { + this.entry_schema = entry_schema; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "type=" + type + ",description=" + description + ",default=" + _default; + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java new file mode 100644 index 0000000..89fac61 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +import java.util.Map; + +/** + * The Class NodeTemplate. + */ +public class NodeTemplate { + + /** The type. */ + private String type; + + /** The metadata. */ + private ToscaMetadata metadata; + + /** The properties. */ + private Map<String, Object> properties; //HEAT? + + /** The requirements. */ + private Object requirements; + + /** + * Gets the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Sets the type. + * + * @param type the new type + */ + public void setType(String type) { + this.type = type; + } + + /** + * Gets the metadata. + * + * @return the metadata + */ + public ToscaMetadata getMetadata() { + return metadata; + } + + /** + * Sets the metadata. + * + * @param metadata the new metadata + */ + public void setMetadata(ToscaMetadata metadata) { + this.metadata = metadata; + } + + /** + * Gets the properties. + * + * @return the properties + */ + public Map<String, Object> getProperties() { + return properties; + } + + /** + * Sets the properties. + * + * @param properties the properties + */ + public void setProperties(Map<String, Object> properties) { + this.properties = properties; + } + + /** + * Gets the requirements. + * + * @return the requirements + */ + public Object getRequirements() { + return requirements; + } + + /** + * Sets the requirements. + * + * @param requirements the new requirements + */ + public void setRequirements(Object requirements) { + this.requirements = requirements; + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java new file mode 100644 index 0000000..171d0fd --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +/** + * The Class Property. + */ +public class Property { + + /** The type. */ + private String type; + + /** The description. */ + private String description; + + /** The entry schema. */ + private Schema entry_schema; + + /** The default. */ + private String _default; + + /** The required. */ + private boolean required; + + /** + * Instantiates a new property. + */ + private Property() {} + + /** + * Gets the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Gets the description. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Gets the entry schema. + * + * @return the entry schema + */ + public Schema getEntry_schema() { + return entry_schema; + } + + /** + * Gets the default. + * + * @return the default + */ + public String get_default() { + return _default; + } + + /** + * 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 entry schema. + * + * @param entry_schema the new entry schema + */ + public void setEntry_schema(Schema entry_schema) { + this.entry_schema = entry_schema; + } + + /** + * Sets the default. + * + * @param _default the new default + */ + public void set_default(String _default) { + this._default = _default; + } + + /** + * Gets the default. + * + * @return the default + */ + public String getDefault() { + return _default; + } + + /** + * Checks if is required. + * + * @return true, if is required + */ + public boolean isRequired() { + return required; + } + + /** + * Sets the default. + * + * @param _default the new default + */ + public void setDefault(String _default) { + this._default = _default; + } + + /** + * Sets the required. + * + * @param required the new required + */ + public void setRequired(boolean required) { + this.required = required; + } + + +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java new file mode 100644 index 0000000..c6089a4 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.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. + */ + private 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/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java new file mode 100644 index 0000000..6eccfdf --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +/** + * The Class Schema. + */ +public class Schema { + + /** The type. */ + public String type; + + /** + * Instantiates a new schema. + */ + public Schema() {} + + /** + * Gets the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Sets the type. + * + * @param type the new type + */ + public void setType(String type) { + this.type = type; + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java new file mode 100644 index 0000000..2f2db43 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +import java.util.HashMap; +import java.util.Map; + +/** + * The Class SubstitutionMappings. + */ +public class SubstitutionMappings { + + /** The node type. */ + private String node_type; + + /** The capabilities. */ + private Map<String, Capability> capabilities; + + /** The requirements. */ + private Map<String, Requirement> requirements; + + /** + * Instantiates a new substitution mappings. + */ + public SubstitutionMappings() { + capabilities = new HashMap<String, Capability> (); + requirements = new HashMap<String, Requirement> (); + } + + /** + * Gets the node type. + * + * @return the node type + */ + public String getnode_type() { + return node_type; + } + + /** + * Sets the node type. + * + * @param node_type the new node type + */ + public void setnode_type(String node_type) { + this.node_type = node_type; + } + + /** + * Gets the capabilities. + * + * @return the capabilities + */ + public Map<String, Capability> getCapabilities() { + return capabilities; + } + + /** + * Sets the capabilities. + * + * @param capabilities the capabilities + */ + public void setCapabilities(Map<String, Capability> capabilities) { + this.capabilities = capabilities; + } + + /** + * Gets the requirements. + * + * @return the requirements + */ + public Map<String, Requirement> getRequirements() { + return requirements; + } + + /** + * Sets the requirements. + * + * @param requirements the requirements + */ + public void setRequirements(Map<String, Requirement> requirements) { + this.requirements = requirements; + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java new file mode 100644 index 0000000..efa2847 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +import java.util.HashMap; +import java.util.Map; + +/** + * The Class TopologyTemplate. + */ +public class TopologyTemplate { + + /** The substitution mappings. */ + private SubstitutionMappings substitution_mappings; + + /** The inputs. */ + private Map<String, Input> inputs; + + /** The node templates. */ + private Map<String, NodeTemplate> node_templates; + + /** The groups. */ + private Map<String, Group> groups; + + /** + * Instantiates a new topology template. + */ + public TopologyTemplate() { + substitution_mappings = new SubstitutionMappings(); + inputs = new HashMap<String, Input> (); + node_templates = new HashMap<String, NodeTemplate> (); + groups = new HashMap<String, Group> (); + } + + /** + * Gets the substitution mappings. + * + * @return the substitution mappings + */ + public SubstitutionMappings getsubstitution_mappings() { + return this.substitution_mappings; + } + + /** + * Sets the substitution mappings. + * + * @param substitution_mappings the new substitution mappings + */ + public void setsubstitution_mappings(SubstitutionMappings substitution_mappings) { + this.substitution_mappings = substitution_mappings; + } + + /** + * Gets the inputs. + * + * @return the inputs + */ + public Map<String, Input> getInputs() { + return inputs; + } + + /** + * Sets the inputs. + * + * @param inputs the inputs + */ + public void setInputs(Map<String, Input> inputs) { + this.inputs = inputs; + } + + /** + * Gets the node templates. + * + * @return the node templates + */ + public Map<String, NodeTemplate> getnode_templates() { + return node_templates; + } + + /** + * Setnode templates. + * + * @param node_templates the node templates + */ + public void setnode_templates(Map<String, NodeTemplate> node_templates) { + this.node_templates = node_templates; + } + + /** + * Gets the groups. + * + * @return the groups + */ + public Map<String, Group> getGroups() { + return groups; + } + + /** + * Sets the groups. + * + * @param groups the groups + */ + public void setGroups(Map<String, Group> groups) { + this.groups = groups; + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java new file mode 100644 index 0000000..a294b19 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +import java.util.Collection; +import java.util.LinkedList; + +/** + * The Class ToscaCsar. + */ +public class ToscaCsar { + + /** The parent. */ + private final ToscaModel parent; + + /** The children. */ + private final Collection<ToscaModel> children; + + /** + * The Class Builder. + */ + public static class Builder { + + /** The parent. */ + private final ToscaModel parent; + + /** The children. */ + private Collection<ToscaModel> children = new LinkedList<ToscaModel> (); + + /** + * Instantiates a new builder. + * + * @param parent the parent + */ + public Builder(ToscaModel parent) { + this.parent = parent; + } + + /** + * Adds the vnf. + * + * @param child the child + * @return the builder + */ + public Builder addVnf(ToscaModel child) { + children.add(child); + return this; + } + + /** + * Builds the. + * + * @return the tosca csar + */ + public ToscaCsar build() { + return new ToscaCsar(this); + } + } + + /** + * Instantiates a new tosca csar. + * + * @param builder the builder + */ + public ToscaCsar(Builder builder) { + this.parent = builder.parent; + this.children = builder.children; + } + + /** + * Gets the parent. + * + * @return the parent + */ + public ToscaModel getParent() { return parent; } + + /** + * Gets the children. + * + * @return the children + */ + public Collection<ToscaModel> getChildren() { return children; } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMeta.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMeta.java new file mode 100644 index 0000000..5e74750 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMeta.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; + +import org.openecomp.vid.asdc.AsdcCatalogException; + +/** + * The Class ToscaMeta. + */ +public class ToscaMeta { + + /** The metadata. */ + private final Map<String, String> metadata; + + /** + * Instantiates a new tosca meta. + * + * @param builder the builder + * @throws IOException Signals that an I/O exception has occurred. + * @throws AsdcCatalogException the asdc catalog exception + */ + private ToscaMeta(Builder builder) throws IOException, AsdcCatalogException { + metadata = new HashMap<String, String> (); + + read(builder.inputStream); + } + + /** + * The Class Builder. + */ + public static class Builder { + + /** The input stream. */ + private final InputStream inputStream; + + /** + * Instantiates a new builder. + * + * @param inputStream the input stream + */ + public Builder(InputStream inputStream) { + this.inputStream = inputStream; + } + + /** + * Builds the. + * + * @return the tosca meta + * @throws IOException Signals that an I/O exception has occurred. + * @throws AsdcCatalogException the asdc catalog exception + */ + public ToscaMeta build() throws IOException, AsdcCatalogException { + return new ToscaMeta(this); + } + } + + /** + * Gets the. + * + * @param property the property + * @return the string + */ + public String get(String property) { + return metadata.get(property); + } + + /** + * Read. + * + * @param inputStream the input stream + * @throws IOException Signals that an I/O exception has occurred. + * @throws AsdcCatalogException the asdc catalog exception + */ + private void read(InputStream inputStream) throws IOException, AsdcCatalogException { + + final BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); + + String line; + + try { + while ((line = br.readLine()) != null) { + final String[] entry = line.split(":"); + + if (entry.length != 2) throw new AsdcCatalogException("TOSCA.meta file cannot be parsed (more than 1 colon found on a single line"); + if (!entry[1].startsWith(" ")) throw new AsdcCatalogException("TOSCA.meta file cannot be parsed (: not immediately followed by ' ')"); + + metadata.put(entry[0], entry[1].substring(1)); + } + } catch (IOException e) { + metadata.clear(); + throw e; + } catch (AsdcCatalogException e) { + metadata.clear(); + throw e; + } + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java new file mode 100644 index 0000000..a48d676 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java @@ -0,0 +1,390 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +/** + * The Class ToscaMetadata. + */ +public class ToscaMetadata { + + /** The template name. */ + private String template_name; + + /** The invariant UUID. */ + private String invariantUUID; + + /** The uuid. */ + private String uuid; + + /** The version. */ + private String version; + + /** The name. */ + private String name; + + /** The description. */ + private String description; + + /** The category. */ + private String category; + + /** The subcategory. */ + private String subcategory; + + /** The type. */ + private String type; + + /** The resource vendor. */ + private String resourceVendor; + + /** The resource vendor release. */ + private String resourceVendorRelease; + + /** The service ecomp naming. */ + private boolean serviceEcompNaming; + + /** The service homing. */ + private boolean serviceHoming; + + /** The vf module model name. */ + //ToscaMetadata for VF Modules + private String vfModuleModelName; + + /** The vf module model invariant UUID. */ + private String vfModuleModelInvariantUUID; + + /** The vf module model UUID. */ + private String vfModuleModelUUID; + + /** The vf module model version. */ + private String vfModuleModelVersion; + + /** + * Instantiates a new tosca metadata. + */ + public ToscaMetadata() {} + + /** + * Gets the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Gets the invariant UUID. + * + * @return the invariant UUID + */ + public String getInvariantUUID() { + return invariantUUID; + } + + /** + * Gets the uuid. + * + * @return the uuid + */ + public String getUUID() { + return uuid; + } + + /** + * Gets the version. + * + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Gets the description. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Gets the category. + * + * @return the category + */ + public String getCategory() { + return category; + } + + /** + * Gets the subcategory. + * + * @return the subcategory + */ + public String getSubcategory() { + return subcategory; + } + + /** + * Gets the resource vendor. + * + * @return the resource vendor + */ + public String getResourceVendor() { + return resourceVendor; + } + + /** + * Gets the resource vendor release. + * + * @return the resource vendor release + */ + public String getResourceVendorRelease() { + return resourceVendorRelease; + } + + /** + * Checks if is service ecomp naming. + * + * @return true, if is service ecomp naming + */ + public boolean isServiceEcompNaming() { + return serviceEcompNaming; + } + + /** + * Checks if is service homing. + * + * @return true, if is service homing + */ + public boolean isServiceHoming() { + return serviceHoming; + } + + /** + * Sets the type. + * + * @param type the new type + */ + public void setType(String type) { + this.type = type; + } + + /** + * Sets the invariant UUID. + * + * @param invariantUUID the new invariant UUID + */ + public void setInvariantUUID(String invariantUUID) { + this.invariantUUID = invariantUUID; + } + + /** + * Sets the uuid. + * + * @param uuid the new uuid + */ + public void setUUID(String uuid) { + this.uuid = uuid; + } + + /** + * Sets the version. + * + * @param version the new version + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Sets the description. + * + * @param description the new description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Sets the category. + * + * @param category the new category + */ + public void setCategory(String category) { + this.category = category; + } + + /** + * Sets the service ecomp naming. + * + * @param serviceEcompNaming the new service ecomp naming + */ + public void setServiceEcompNaming(boolean serviceEcompNaming) { + this.serviceEcompNaming = serviceEcompNaming; + } + + /** + * Sets the service homing. + * + * @param serviceHoming the new service homing + */ + public void setServiceHoming(boolean serviceHoming) { + this.serviceHoming = serviceHoming; + } + + /** + * Gets the template name. + * + * @return the template name + */ + public String gettemplate_name() { + return template_name; + } + + /** + * Sets the template name. + * + * @param template_name the new template name + */ + public void settemplate_name(String template_name) { + this.template_name = template_name; + } + + /** + * Sets the subcategory. + * + * @param subcategory the new subcategory + */ + public void setSubcategory(String subcategory) { + this.subcategory = subcategory; + } + + /** + * Sets the resource vendor. + * + * @param resourceVendor the new resource vendor + */ + public void setResourceVendor(String resourceVendor) { + this.resourceVendor = resourceVendor; + } + + /** + * Sets the resource vendor release. + * + * @param resourceVendorRelease the new resource vendor release + */ + public void setResourceVendorRelease(String resourceVendorRelease) { + this.resourceVendorRelease = resourceVendorRelease; + } + + /** + * Gets the vf module model name. + * + * @return the vf module model name + */ + public String getVfModuleModelName() { + return vfModuleModelName; + } + + /** + * Sets the vf module model name. + * + * @param vfModuleModelName the new vf module model name + */ + public void setVfModuleModelName(String vfModuleModelName) { + this.vfModuleModelName = vfModuleModelName; + } + + /** + * Gets the vf module model invariant UUID. + * + * @return the vf module model invariant UUID + */ + public String getVfModuleModelInvariantUUID() { + return vfModuleModelInvariantUUID; + } + + /** + * Sets the vf module model invariant UUID. + * + * @param vfModuleModelInvariantUUID the new vf module model invariant UUID + */ + public void setVfModuleModelInvariantUUID(String vfModuleModelInvariantUUID) { + this.vfModuleModelInvariantUUID = vfModuleModelInvariantUUID; + } + + /** + * Gets the vf module model UUID. + * + * @return the vf module model UUID + */ + public String getVfModuleModelUUID() { + return vfModuleModelUUID; + } + + /** + * Sets the vf module model UUID. + * + * @param vfModuleModelUUID the new vf module model UUID + */ + public void setVfModuleModelUUID(String vfModuleModelUUID) { + this.vfModuleModelUUID = vfModuleModelUUID; + } + + /** + * Gets the vf module model version. + * + * @return the vf module model version + */ + public String getVfModuleModelVersion() { + return vfModuleModelVersion; + } + + /** + * Sets the vf module model version. + * + * @param vfModuleModelVersion the new vf module model version + */ + public void setVfModuleModelVersion(String vfModuleModelVersion) { + this.vfModuleModelVersion = vfModuleModelVersion; + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java b/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java new file mode 100644 index 0000000..f01f469 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java @@ -0,0 +1,166 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.beans.tosca; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.Map; + +/** + * The Class ToscaModel. + */ +public class ToscaModel { + + /** The tosca definitions version. */ + private String tosca_definitions_version; + + /** The description. */ + private String description; + + /** The metadata. */ + private ToscaMetadata metadata; + + /** The topology template. */ + private TopologyTemplate topology_template; + + /** The imports. */ + private Collection<Map<String, Map<String, String>>> imports; + + /** The node types. */ + private Map<String, Object> node_types; + + /** + * Instantiates a new tosca model. + */ + public ToscaModel() { + metadata = new ToscaMetadata(); + topology_template = new TopologyTemplate(); + imports = new LinkedList<Map<String, Map<String, String>>> (); + } + + /** + * Gets the metadata. + * + * @return the metadata + */ + public ToscaMetadata getMetadata() { + return metadata; + } + + /** + * Sets the metadata. + * + * @param metadata the new metadata + */ + public void setMetadata(ToscaMetadata metadata) { + this.metadata = metadata; + } + + /** + * Gets the tosca definitions version. + * + * @return the tosca definitions version + */ + public String gettosca_definitions_version() { + return tosca_definitions_version; + } + + /** + * Sets the tosca definitions version. + * + * @param tosca_definitions_version the new tosca definitions version + */ + public void settosca_definitions_version(String tosca_definitions_version) { + this.tosca_definitions_version = tosca_definitions_version; + } + + /** + * Gets the topology template. + * + * @return the topology template + */ + public TopologyTemplate gettopology_template() { + return topology_template; + } + + /** + * Sets the topology template. + * + * @param topology_template the new topology template + */ + public void settopology_template(TopologyTemplate topology_template) { + this.topology_template = topology_template; + } + + /** + * Gets the description. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Sets the description. + * + * @param description the new description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Gets the imports. + * + * @return the imports + */ + public Collection<Map<String, Map<String, String>>> getImports() { + return imports; + } + + /** + * Sets the imports. + * + * @param imports the imports + */ + public void setImports(Collection<Map<String, Map<String, String>>> imports) { + this.imports = imports; + } + + /** + * Gets the node types. + * + * @return the node types + */ + public Map<String, Object> getnode_types() { + return node_types; + } + + /** + * Setnode types. + * + * @param node_types the node types + */ + public void setnode_types(Map<String, Object> node_types) { + this.node_types = node_types; + } +} diff --git a/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java b/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java new file mode 100644 index 0000000..085eea8 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java @@ -0,0 +1,372 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.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.openecomp.vid.asdc.AsdcCatalogException; +import org.openecomp.vid.asdc.AsdcClient; +import org.openecomp.vid.asdc.beans.Artifact; +import org.openecomp.vid.asdc.beans.Resource; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.asdc.beans.tosca.ToscaCsar; +import org.openecomp.vid.asdc.beans.tosca.ToscaMeta; +import org.openecomp.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 asdc client + */ + public InMemoryAsdcClient build() { + return new InMemoryAsdcClient(this); + } + } + + /** + * Instantiates a new in memory asdc 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 asdc 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 ASDC response (bad data)", e); + } catch (JsonMappingException e) { + throw new AsdcCatalogException("Failed to map ASDC response to internal VID data structure(s)", e); + } catch (IOException e) { + throw new AsdcCatalogException("Failed to get a response from ASDC", e); + } + } + + /* (non-Javadoc) + * @see org.openecomp.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.openecomp.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.openecomp.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.openecomp.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.openecomp.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.openecompt.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.openecomp.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.openecomp.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.openecomp.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID) + */ + public ToscaCsar 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 getToscaModel(toscaModelStream); + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID) + */ + public ToscaCsar 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 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/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java b/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java new file mode 100644 index 0000000..49c24e9 --- /dev/null +++ b/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java @@ -0,0 +1,450 @@ +/*- + * ============LICENSE_START======================================================= + * VID ASDC Client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.asdc.rest; + +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.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; +import java.util.logging.Logger; +import java.util.zip.ZipFile; + +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 org.openecomp.vid.asdc.AsdcCatalogException; +import org.openecomp.vid.asdc.AsdcClient; +import org.openecomp.vid.asdc.beans.Artifact; +import org.openecomp.vid.asdc.beans.Resource; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.asdc.beans.tosca.ToscaCsar; +import org.openecomp.vid.asdc.beans.tosca.ToscaMeta; +import org.openecomp.vid.asdc.beans.tosca.ToscaModel; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.error.YAMLException; + +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; + +/** + * The Class RestfulAsdcClient. + */ +public class RestfulAsdcClient implements AsdcClient { + + /** The Constant LOGGER. */ + private static final Logger LOGGER = Logger.getLogger(RestfulAsdcClient.class.getName()); + + /** The client. */ + private final Client client; + + /** The uri. */ + private final URI uri; + + /** The common headers. */ + private final MultivaluedHashMap<String, Object> commonHeaders; + + /** The auth. */ + private final String auth; + + /** + * The Class Builder. + */ + public static class Builder { + + /** The client. */ + private final Client client; + + /** The uri. */ + private final URI uri; + + /** The auth. */ + private String auth = null; + + /** + * Instantiates a new builder. + * + * @param client the client + * @param uri the uri + */ + public Builder(Client client, URI uri) { + this.client = client; + this.client.register(JacksonJsonProvider.class); + this.uri = uri; + } + + /** + * Auth. + * + * @param auth the auth + * @return the builder + */ + public Builder auth(String auth) { + this.auth = auth; + return this; + } + + /** + * Builds the. + * + * @return the restful asdc client + */ + public RestfulAsdcClient build() { + return new RestfulAsdcClient(this); + } + } + + /** + * Instantiates a new restful asdc client. + * + * @param builder the builder + */ + private RestfulAsdcClient(Builder builder) { + client = builder.client; + uri = builder.uri; + auth = builder.auth; + + commonHeaders = new MultivaluedHashMap<String, Object> (); + commonHeaders.put("X-ECOMP-InstanceID", Collections.singletonList((Object) "VID")); + commonHeaders.put("Authorization", Collections.singletonList((Object) (auth))); + } + + /** + * Gets the client. + * + * @return the client + */ + private Client getClient() { return client; } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getResource(java.util.UUID) + */ + public Resource getResource(UUID uuid) throws AsdcCatalogException { + try { + return getClient() + .target(uri) + .path("asdc/v1/catalog/resources/" + uuid.toString() + "/metadata") + .request(MediaType.APPLICATION_JSON_TYPE) + .headers(commonHeaders) + .header("Content-Type", MediaType.APPLICATION_JSON) + .get(Resource.class); + } catch (ResponseProcessingException e) { + //Couldn't convert response to Java type + throw new AsdcCatalogException("ASDC response could not be processed", e); + } catch (ProcessingException e) { + //IO problems during request + throw new AsdcCatalogException("Failed to get a response from ASDC 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.openecomp.vid.asdc.AsdcClient#getResources() + */ + public Collection<Resource> getResources() throws AsdcCatalogException { + + try { + return getClient() + .target(uri) + .path("asdc/v1/catalog/resources") + .request(MediaType.APPLICATION_JSON_TYPE) + .headers(commonHeaders) + .header("Content-Type", MediaType.APPLICATION_JSON) + .get(new GenericType<Collection<Resource>> () {}); + } catch (ResponseProcessingException e) { + //Couldn't convert response to Java type + throw new AsdcCatalogException("ASDC response could not be processed", e); + } catch (ProcessingException e) { + //IO problems during request + throw new AsdcCatalogException("Failed to get a response from ASDC 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.openecomp.vid.asdc.AsdcClient#getResources(java.util.Map) + */ + public Collection<Resource> getResources(Map<String, String[]> filter) throws AsdcCatalogException { + WebTarget target = getClient() + .target(uri) + .path("asdc/v1/catalog/resources"); + + 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) + .get(new GenericType<Collection<Resource>> () {}); + } catch (ResponseProcessingException e) { + //Couldn't convert response to Java type + throw new AsdcCatalogException("ASDC response could not be processed", e); + } catch (ProcessingException e) { + //IO problems during request + throw new AsdcCatalogException("Failed to get a response from ASDC 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.openecomp.vid.asdc.AsdcClient#getResourceArtifact(java.util.UUID, java.util.UUID) + */ + public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException { + + try { + return getClient() + .target(uri) + .path("/asdc/v1/catalog/resources/" + resourceUuid + "/artifacts/" + artifactUuid) + .request(MediaType.APPLICATION_JSON_TYPE) + .headers(commonHeaders) + .header("Content-Type", MediaType.APPLICATION_JSON) + .get(Artifact.class); + } catch (ResponseProcessingException e) { + //Couldn't convert response to Java type + throw new AsdcCatalogException("ASDC response could not be processed", e); + } catch (ProcessingException e) { + //IO problems during request + throw new AsdcCatalogException("Failed to get a response from ASDC 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.openecomp.vid.asdc.AsdcClient#getService(java.util.UUID) + */ + public Service getService(UUID uuid) throws AsdcCatalogException { + try { + return getClient() + .target(uri) + .path("asdc/v1/catalog/services/" + uuid.toString() + "/metadata") + .request(MediaType.APPLICATION_JSON) + .headers(commonHeaders) + .get(Service.class); + } catch (ResponseProcessingException e) { + //Couldn't convert response to Java type + throw new AsdcCatalogException("ASDC response could not be processed", e); + } catch (ProcessingException e) { + //IO problems during request + throw new AsdcCatalogException("Failed to get a response from ASDC 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.openecomp.vid.asdc.AsdcClient#getServices() + */ + public Collection<Service> getServices() throws AsdcCatalogException { + try { + return getClient() + .target(uri) + .path("asdc/v1/catalog/services") + .request() + .accept(MediaType.APPLICATION_JSON_TYPE) + .headers(commonHeaders) + .header("Content-Type", MediaType.APPLICATION_JSON) + .get(new GenericType<Collection<Service>> () {}); + } catch (ResponseProcessingException e) { + //Couldn't convert response to Java type + throw new AsdcCatalogException("ASDC response could not be processed", e); + } catch (ProcessingException e) { + //IO problems during request + throw new AsdcCatalogException("Failed to get a response from ASDC 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.openecomp.vid.asdc.AsdcClient#getServices(java.util.Map) + */ + public Collection<Service> getServices(Map<String, String[]> filter) throws AsdcCatalogException { + WebTarget target = getClient() + .target(uri) + .path("asdc/v1/catalog/services"); + + + 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) + .get(new GenericType<Collection<Service>> () {}); + } catch (ResponseProcessingException e) { + //Couldn't convert response to Java type + throw new AsdcCatalogException("ASDC response could not be processed", e); + } catch (ProcessingException e) { + //IO problems during request + throw new AsdcCatalogException("Failed to get a response from ASDC 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.openecomp.vid.asdc.AsdcClient#getServiceArtifact(java.util.UUID, java.util.UUID) + */ + public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException { + try { + return getClient() + .target(uri) + .path("/asdc/v1/catalog/services/" + serviceUuid + "/artifacts/" + artifactUuid) + .request(MediaType.APPLICATION_JSON_TYPE) + .headers(commonHeaders) + .header("Content-Type", MediaType.APPLICATION_JSON) + .get(Artifact.class); + } catch (ResponseProcessingException e) { + //Couldn't convert response to Java type + throw new AsdcCatalogException("ASDC response could not be processed", e); + } catch (ProcessingException e) { + //IO problems during request + throw new AsdcCatalogException("Failed to get a response from ASDC 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.openecomp.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID) + */ + public ToscaCsar getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException { + try (final InputStream csarInputStream = (InputStream) getClient() + .target(uri) + .path("/asdc/v1/catalog/resources/" + resourceUuid + "/toscaModel") + .request(MediaType.APPLICATION_OCTET_STREAM_TYPE) + .headers(commonHeaders) + .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM) + .get(InputStream.class)) { + + return getToscaModel(csarInputStream); + } catch (IOException e) { + throw new AsdcCatalogException("Failed to retrieve resource TOSCA model from ASDC", e); + } + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID) + */ + public ToscaCsar getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException { + try { + final InputStream csarInputStream = (InputStream) getClient() + .target(uri) + .path("/asdc/v1/catalog/services/" + serviceUuid + "/toscaModel") + .request(MediaType.APPLICATION_OCTET_STREAM_TYPE) + .headers(commonHeaders) + .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM) + .get(InputStream.class); + + return getToscaModel(csarInputStream); + } catch (ResponseProcessingException e) { + //Couldn't convert response to Java type + throw new AsdcCatalogException("ASDC response could not be processed", e); + } catch (ProcessingException e) { + //IO problems during request + throw new AsdcCatalogException("Failed to get a response from ASDC 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); + } + } + + /** + * 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)); + + 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()) { + 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 (YAMLException e) { + throw new AsdcCatalogException("Caught exception while processing TOSCA YAML", e); + } + } catch (IOException e) { + throw new AsdcCatalogException("Caught IOException while processing CSAR", e); + } + } +} |