diff options
Diffstat (limited to 'vid-app-common/src/main/java/org/openecomp/vid/asdc')
26 files changed, 1400 insertions, 583 deletions
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java index aafb11cad..c80787205 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcClient.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcClient.java index c4a8b1c0c..314ea037d 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcClient.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcClient.java @@ -20,6 +20,8 @@ package org.openecomp.vid.asdc;
+import java.io.IOException;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;
@@ -27,7 +29,6 @@ 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.
@@ -77,7 +78,7 @@ public interface AsdcClient { * @return the resource tosca model
* @throws AsdcCatalogException the sdc catalog exception
*/
- public ToscaCsar getResourceToscaModel(UUID uuid) throws AsdcCatalogException;
+ public Path getResourceToscaModel(UUID uuid) throws AsdcCatalogException;
/**
* Gets the service.
@@ -122,7 +123,7 @@ public interface AsdcClient { * @return the service tosca model
* @throws AsdcCatalogException the asdc catalog exception
*/
- public ToscaCsar getServiceToscaModel(UUID uuid) throws AsdcCatalogException;
+ public Path getServiceToscaModel(UUID uuid) throws AsdcCatalogException;
//TODO: Collect TOSCA information from CSAR
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java index d24d1232a..4974d44a8 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Resource.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Resource.java index 3911c699a..000aae1a9 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Resource.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Resource.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Service.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Service.java index fa898e56a..2a83cbe3a 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Service.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Service.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java index 6d7fb41b1..cd3ec7fee 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java index 21a50d3bb..0d3f17ae4 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Constraint.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Constraint.java index b68b51a09..a91f38312 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Constraint.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Constraint.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.openecomp.vid.asdc.beans.tosca;
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java index 275db3c0d..4d31faab1 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java index 33f317579..d64a58066 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java index f98820716..e5eec0121 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,12 +14,14 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.openecomp.vid.asdc.beans.tosca;
+import org.openecomp.sdc.toscaparser.api.elements.constraints.*;
+
import java.util.List;
import java.util.ArrayList;
@@ -42,7 +44,7 @@ public class Input { private Input entry_schema;
/** The constraints */
- private List<Constraint> constraints;
+ private List<org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint> constraints;
/** The required field. If not set, the default is true */
private boolean required = true;
@@ -51,7 +53,7 @@ public class Input { * Instantiates a new input.
*/
public Input() {
- constraints = new ArrayList<Constraint>();
+ constraints = new ArrayList<org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint>();
}
/**
@@ -144,7 +146,7 @@ public class Input { *
* @param c the new constraints
*/
- public void setConstraints(List<Constraint> c) {
+ public void setConstraints(List<org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint> c) {
this.constraints = c;
}
/**
@@ -152,7 +154,7 @@ public class Input { *
* @return the constraints
*/
- public List<Constraint> getConstraints() {
+ public List<org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint> getConstraints() {
return constraints;
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java index 73eead93f..97740b3f5 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java index c8f048ced..16b921e2a 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java index fce41ec6e..acb250997 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java index bd3a2f0a5..f77c1b4b5 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java index 026f29bbe..f59f24674 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java index ce7ce5755..25b2c2c38 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java index cca4ae7c2..9e9e1d00b 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java index 41c7ca5ba..d42c1f150 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java @@ -61,9 +61,6 @@ public class ToscaMetadata { /** The resource vendor release. */
private String resourceVendorRelease;
- /** the resourceVendorModelNumber */
- private String resourceVendorModelNumber;
-
/** The service ecomp naming. */
private String serviceEcompNaming;
@@ -91,11 +88,6 @@ public class ToscaMetadata { /** The vf module model version. */
private String vfModuleModelVersion;
-
- /** serviceType */
- private String serviceType;
- /** serviceRole */
- private String serviceRole;
/**
* Instantiates a new tosca metadata.
@@ -466,26 +458,4 @@ public class ToscaMetadata { return vfModuleModelCustomizationUUID;
}
-
- /** serviceType */
- public String getServiceType() {
- return serviceType;
- }
- public void setServiceType(String serviceType) {
- this.serviceType= serviceType;
- }
- /** serviceRole */
- public String getServiceRole() {
- return serviceRole;
- }
- public void setServiceRole(String serviceRole) {
- this.serviceRole= serviceRole;
- }
- /** resourceVendorModelNumber */
- public String getResourceVendorModelNumber() {
- return resourceVendorModelNumber;
- }
- public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
- this.resourceVendorModelNumber= resourceVendorModelNumber;
- }
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java index c9e42f291..77fbe9135 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * 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. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/local/LocalAsdcClient.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/local/LocalAsdcClient.java new file mode 100644 index 000000000..8538f6ba6 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/local/LocalAsdcClient.java @@ -0,0 +1,388 @@ +package org.openecomp.vid.asdc.local; + +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.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 java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.*; +import java.util.zip.ZipFile; + +/** + * The Class LocalAsdcClient. + */ +public class LocalAsdcClient 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 org.openecomp.vid.asdc.local.LocalAsdcClient.Builder catalog(JSONObject catalog) { + this.catalog = catalog; + return this; + } + + /** + * Mapper. + * + * @param mapper the mapper + * @return the builder + */ + public org.openecomp.vid.asdc.local.LocalAsdcClient.Builder mapper(ObjectMapper mapper) { + this.mapper = mapper; + return this; + } + + /** + * Builds the. + * + * @return the in local sdc client + */ + public org.openecomp.vid.asdc.local.LocalAsdcClient build() { + return new org.openecomp.vid.asdc.local.LocalAsdcClient(this); + } + } + + /** + * Instantiates a new in local sdc client. + * + * @param builder the builder + */ + private LocalAsdcClient(org.openecomp.vid.asdc.local.LocalAsdcClient.Builder builder) { + catalog = builder.catalog; + mapper = builder.mapper; + } + + /** + * Gets the catalog. + * + * @return the catalog + */ + private JSONObject getCatalog() { + return catalog; + } + + /** + * Gets the mapper. + * + * @return the mapper + */ + private ObjectMapper getMapper() { + return mapper; + } + + /** + * Convert. + * + * @param <T> the generic type + * @param json the json + * @param clazz the clazz + * @return the t + * @throws AsdcCatalogException the sdc catalog exception + */ + private <T> T convert(JSONObject json, Class<T> clazz) throws AsdcCatalogException { + try { + return getMapper().readValue(json.toString(), clazz); + } catch (JsonParseException e) { + throw new AsdcCatalogException("Failed to parse SDC response (bad data)", e); + } catch (JsonMappingException e) { + throw new AsdcCatalogException("Failed to map SDC response to internal VID data structure(s)", e); + } catch (IOException e) { + throw new AsdcCatalogException("Failed to get a response from SDC", e); + } + } + + /* (non-Javadoc) + * @see org.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 (Map.Entry<String, String[]> entry : filter.entrySet()) { + for (int i = 0; i < entry.getValue().length; i++) { + if (!json.getString(entry.getKey()).equals(entry.getValue()[i])) { + filterMatch = false; + break; + } + } + } + + if (filterMatch) resources.add(convert(json, Resource.class)); + } + + return resources; + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getService(java.util.UUID) + */ + public Service getService(UUID uuid) throws AsdcCatalogException { + + JSONObject serviceJsonObject = null; + final JSONArray categoryJsonArray = getCatalog().getJSONArray("services"); + + for (int i = 0; i < categoryJsonArray.length() ; i++) { + JSONObject jsonServiceObject = categoryJsonArray.getJSONObject(i); + if (jsonServiceObject.get("uuid").equals(uuid.toString())) { + serviceJsonObject = jsonServiceObject; + break; + } + } + + if (serviceJsonObject != null) + return convert(serviceJsonObject, Service.class); + else return null; + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getServices() + */ + public Collection<Service> getServices() throws AsdcCatalogException { + final Collection<Service> services = new LinkedList<Service>(); + + JSONArray servicesArr = getCatalog().getJSONArray("services"); + + for (Object objService : servicesArr) { + JSONObject jsonServiceItem = (JSONObject) objService; + final Service service = convert(jsonServiceItem, Service.class); + services.add(service); + } + + return services; + } + + /* (non-Javadoc) + * @see org.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>(); + + JSONArray catalogServices = catalog.getJSONArray("services"); + + for (int i = 0; i < catalogServices.length(); i++) { + + JSONObject serviceJson = catalogServices.getJSONObject(i); + + boolean filterMatch = true; + + for (Map.Entry<String, String[]> entry : filter.entrySet()) { + for (int j = 0; j < entry.getValue().length; j++) { + if (!serviceJson.getString(entry.getKey()).equals(entry.getValue()[j])) { + filterMatch = false; + break; + } + } + } + if (filterMatch) services.add(convert(serviceJson, Service.class)); + } + return services; + } + + /* (non-Javadoc) + * @see org.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 Path getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException { + final String toscaModelURL = getCatalog().getJSONObject("resources") + .getJSONObject(resourceUuid.toString()) + .getString("toscaModelURL"); + + + final InputStream toscaModelStream = getClass().getClassLoader().getResourceAsStream(toscaModelURL); + + if (toscaModelStream == null) return null; + + return null;//getToscaModel(toscaModelStream); + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID) + */ + public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException { + + String toscaModelURL = null; + + final JSONArray categoryJsonArray = getCatalog().getJSONArray("services"); + + for (int i = 0; i < categoryJsonArray.length() ; i++) { + + JSONObject jsonServiceObject = categoryJsonArray.getJSONObject(i); + if (jsonServiceObject.get("uuid").equals(serviceUuid.toString())) { + toscaModelURL = jsonServiceObject.getString("toscaModelURL"); + } + } + + final InputStream toscaModelStream = getClass().getClassLoader().getResourceAsStream(toscaModelURL); + + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource(toscaModelURL).getFile()); + Path path = Paths.get(file.getPath()); + + if (toscaModelStream == null) return null; + + return path; + } + + /** + * 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 (Map.Entry<String, Map<String, String>> entry : imports.entrySet()) { + final InputStream toscaChildEntryYamlStream = csar.getInputStream(csar.getEntry("Definitions/" + entry.getValue().get("file"))); + final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class); + csarBuilder.addVnf(childModel); + } + } + + return csarBuilder.build(); + } catch (IOException e) { + throw new AsdcCatalogException("Caught IOException while processing CSAR", e); + } + } + +} diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java index c5134bfca..123cc5788 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java @@ -7,7 +7,7 @@ * 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
@@ -168,7 +168,6 @@ public class InMemoryAsdcClient implements AsdcClient { }
/* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getResources()
*/
public Collection<Resource> getResources() throws AsdcCatalogException {
final Collection<Resource> resources = new LinkedList<Resource> ();
@@ -299,7 +298,7 @@ public class InMemoryAsdcClient implements AsdcClient { /* (non-Javadoc)
* @see org.openecomp.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID)
*/
- public ToscaCsar getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException {
+ public Path getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException {
final String toscaModelURL = getCatalog().getJSONObject("resources")
.getJSONObject(resourceUuid.toString())
.getString("toscaModelURL");
@@ -309,13 +308,13 @@ public class InMemoryAsdcClient implements AsdcClient { if (toscaModelStream == null) return null;
- return getToscaModel(toscaModelStream);
+ return null;//getToscaModel(toscaModelStream);
}
/* (non-Javadoc)
* @see org.openecomp.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID)
*/
- public ToscaCsar getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException {
+ public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException {
final String toscaModelURL = getCatalog().getJSONObject("services")
.getJSONObject(serviceUuid.toString())
.getString("toscaModelURL");
@@ -324,7 +323,7 @@ public class InMemoryAsdcClient implements AsdcClient { if (toscaModelStream == null) return null;
- return getToscaModel(toscaModelStream);
+ return null;//getToscaModel(toscaModelStream);
}
/**
@@ -369,4 +368,5 @@ public class InMemoryAsdcClient implements AsdcClient { throw new AsdcCatalogException("Caught IOException while processing CSAR", e);
}
}
+
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParser.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParser.java new file mode 100644 index 000000000..eb1669846 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParser.java @@ -0,0 +1,15 @@ +package org.openecomp.vid.asdc.parser; + +import java.nio.file.Path; + +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.vid.asdc.AsdcCatalogException; +import org.openecomp.vid.asdc.beans.tosca.ToscaCsar; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.model.ServiceModel; + +public interface ToscaParser{ + ToscaCsar parse(Path path) throws AsdcCatalogException; + + ServiceModel makeServiceModel(String uuid,Path path,Service asdcServiceMetadata) throws Exception; +}
\ No newline at end of file diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl.java new file mode 100644 index 000000000..bea5da877 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl.java @@ -0,0 +1,225 @@ +package org.openecomp.vid.asdc.parser; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.Map.Entry; +import java.util.zip.ZipFile; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.vid.asdc.AsdcCatalogException; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.asdc.beans.tosca.NodeTemplate; +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.openecomp.vid.model.ModelConstants; +import org.openecomp.vid.model.Network; +import org.openecomp.vid.model.Node; +import org.openecomp.vid.model.ServiceModel; +import org.openecomp.vid.model.VNF; +import org.openecomp.vid.properties.VidProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.error.YAMLException; + +public class ToscaParserImpl implements ToscaParser { + /** The Constant LOG. */ + static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ToscaParserImpl.class); + + @Autowired + private final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + + + private static final String asdcModelNamespace = VidProperties.getAsdcModelNamespace(); + private static final String vnfTag = asdcModelNamespace + ModelConstants.VNF; + private static final String networkTag = asdcModelNamespace + ModelConstants.NETWORK; + private static final String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE; + + + @Override + public ToscaCsar parse(Path path) throws AsdcCatalogException { + return getToscaCsar(path); + } + + private ToscaCsar getToscaCsar(final Path csarFile) throws AsdcCatalogException { + 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()) { + LOG.debug("imports = " + imports.toString()); + for (Entry<String, Map<String, String>> entry : imports.entrySet()) { + if (entry.getValue() != null) { + String fname = entry.getValue().get("file"); + if ((fname != null) && (fname.startsWith("service") || fname.startsWith("resource"))) { + LOG.debug("fname = " + fname); + final InputStream toscaChildEntryYamlStream = csar + .getInputStream(csar.getEntry("Definitions/" + fname)); + + final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class); + csarBuilder.addVnf(childModel); + } + } + } + } + + return csarBuilder.build(); + } 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); + } + } + + public ServiceModel makeServiceModel(String uuid, final Path serviceCsar,Service service ) throws AsdcCatalogException, SdcToscaParserException { + + + final ServiceModel serviceModel = new ServiceModel(); + ToscaCsar toscaCsar = getToscaCsar(serviceCsar); + String methodName = "getServices"; + LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start"); + Boolean isNewFlow = false; + final Map<String, VNF> vnfs = new HashMap<String, VNF>(); + final Map<String, Network> networks = new HashMap<String, Network>(); + final ToscaModel asdcServiceToscaModel = toscaCsar.getParent(); + serviceModel.setService(ServiceModel.extractService(asdcServiceToscaModel, service)); + + + populateVnfsAndNetwork(methodName, isNewFlow, vnfs, networks, asdcServiceToscaModel, serviceModel); + + // If we see customization uuid under vnf or network, follow 1702 flow + if (isNewFlow) { + return (getCustomizedServices(asdcServiceToscaModel, serviceModel)); + } else { + VNF vnf = null; + for (ToscaModel vnfModel : toscaCsar.getChildren()) { + // using uuid to match should only be valid for 1610 models + final String vnfUuid = (vnfModel.getMetadata().getUUID()); + // find the VNF with that uuid, uuid is not the key anymore + vnf = findVNFAccordingToUUID(vnfs, vnfUuid); + if (vnf == null) { + LOG.warn("Couldn't find VNF object " + vnfUuid + ". Problem with Tosca model?"); + continue; + } + extractAndUpdateInputs(vnf, vnfModel); + ServiceModel.extractGroups(vnfModel, serviceModel); + } + + serviceModel.setVnfs(vnfs); + serviceModel.setNetworks(networks); + return serviceModel; + } + } + + private VNF findVNFAccordingToUUID(final Map<String, VNF> vnfs, final String vnfUuid) { + VNF vnf = null; + for (Entry<String, VNF> vnfComp : vnfs.entrySet()) { + if (((vnfComp.getValue().getUuid()).equalsIgnoreCase(vnfUuid))) { + // found the vnf + vnf = vnfComp.getValue(); + } + } + return vnf; + } + + private void extractAndUpdateInputs(VNF vnf, ToscaModel vnfModel) { + vnf.setInputs(vnfModel.gettopology_template().getInputs()); + } + + private static void populateVnfsAndNetwork(String methodName, Boolean isNewFlow, final Map<String, VNF> vnfs, + final Map<String, Network> networks, final ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) + throws AsdcCatalogException, SdcToscaParserException { + for (Entry<String, NodeTemplate> component : extractNodeTemplates(asdcServiceToscaModel)) { + final String modelCustomizationName = component.getKey(); + LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + + " model customization name: " + modelCustomizationName); + final NodeTemplate nodeTemplate = component.getValue(); + final String type = nodeTemplate.getType(); + + if (type.startsWith(vnfTag)) { + LOG.debug(EELFLoggerDelegate.debugLogger, + dateFormat.format(new Date()) + methodName + " found node template type: " + type); + final VNF vnf = new VNF(); + vnf.extractVnf(modelCustomizationName, nodeTemplate); +// populateNodeVersionIfMissing(nodeTemplate, vnf,service); + LOG.debug(EELFLoggerDelegate.debugLogger, + dateFormat.format(new Date()) + methodName + " VNF commands: " + vnf.getCommands()); + vnfs.put(modelCustomizationName, vnf); + isNewFlow = isNewFlow(vnf); + } + // Networks + if (type.startsWith(networkTag)) { + LOG.debug(EELFLoggerDelegate.debugLogger, + dateFormat.format(new Date()) + methodName + " found node template type: " + type); + final Network network = new Network(); + network.extractNetwork(modelCustomizationName, nodeTemplate); +// populateNodeVersionIfMissing(nodeTemplate, network, service); + isNewFlow = isNewFlow(network); + networks.put(modelCustomizationName, network); + + } + } + serviceModel.setVnfs(vnfs); + serviceModel.setNetworks(networks); + + } + + private static Set<Entry<String, NodeTemplate>> extractNodeTemplates(final ToscaModel asdcServiceToscaModel) { + return asdcServiceToscaModel.gettopology_template().getnode_templates().entrySet(); + } + + private static boolean isNewFlow(Node node) { + return (node.getCustomizationUuid() != null) && (node.getCustomizationUuid().length() > 0); + } + + private static boolean isNodeVersionMissing(Node Node) { + return Node.getVersion() == null; + } + + private static void populateNodeVersionIfMissing(final NodeTemplate nodeTemplate, final Node node, Service service) + throws AsdcCatalogException { + if (isNodeVersionMissing(node)) { + node.setVersion(service.getVersion()); + } + } + + private ServiceModel getCustomizedServices(ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) { + String methodName = "asdcServiceToscaModel"; + LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start"); + + // asdcServiceToscaModel should have vf modules and vol groups populated + // at this point but + // they are not associated with the VNFs + ServiceModel.extractGroups(asdcServiceToscaModel,serviceModel); + // Now put the vf modules and volume groups under the VNF they belong + // too + serviceModel.associateGroups(); + return (serviceModel); + } + + + private UUID extractUUIDFromNodeTemplate(final NodeTemplate nodeTemplate) { + return UUID.fromString(nodeTemplate.getMetadata().getUUID()); + } + + +}
\ No newline at end of file diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl2.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl2.java new file mode 100644 index 000000000..4819cae8f --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl2.java @@ -0,0 +1,226 @@ +package org.openecomp.vid.asdc.parser; + +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.tosca.parser.impl.FilterType; +import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.openecomp.sdc.toscaparser.api.Group; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.Property; +import org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint; +import org.openecomp.sdc.toscaparser.api.parameters.Input; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.model.*; + +import java.nio.file.Path; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ToscaParserImpl2 { + + + public class Constants { + public final static String uuid = "UUID"; + public final static String description = "description"; + public final static String ecompGeneratedNaming = "ecompGeneratedNaming"; + public final static String customizationUUID = "customizationUUID"; + public final static String vfModuleModelVersion = "vfModuleModelVersion"; + public final static String vfModuleModelCustomizationUUID = "vfModuleModelCustomizationUUID"; + public final static String volume_group = "volume_group"; + public final static String vfModuleModelInvariantUUID = "vfModuleModelInvariantUUID"; + public final static String vfModuleModelUUID = "vfModuleModelUUID"; + public final static String invariantUUID = "invariantUUID"; + public final static String version = "version"; + public final static String name = "name"; + public final static String category = "category"; + public final static String vfModuleModelName = "vfModuleModelName"; + public final static String getInput = "get_input"; + } + + public ToscaParserImpl2() { + + } + + public ServiceModel makeServiceModel(Path path, Service asdcServiceMetadata) throws Exception { + ServiceModel serviceModel = new ServiceModel(); + SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath()); + serviceModel.setService(extractServiceFromCsar(asdcServiceMetadata, sdcCsarHelper)); + serviceModel.setVolumeGroups(extractVolumeGroups(sdcCsarHelper)); + serviceModel.setVfModules(extractVfModuleFromCsar(sdcCsarHelper)); + serviceModel.setVnfs(extractVnfsFromCsar(sdcCsarHelper)); + serviceModel.setNetworks(extractNetworksFromCsar(sdcCsarHelper)); + return serviceModel; + } + + private org.openecomp.vid.model.Service extractServiceFromCsar(Service asdcServiceMetadata, ISdcCsarHelper csarHelper) throws SdcToscaParserException { + org.openecomp.vid.model.Service service = new org.openecomp.vid.model.Service(); + + service.setName(csarHelper.getServiceMetadata().getValue(Constants.name)); + service.setCategory(csarHelper.getServiceMetadata().getValue(Constants.category)); + service.setInvariantUuid(csarHelper.getServiceMetadata().getValue(Constants.invariantUUID)); + service.setUuid(csarHelper.getServiceMetadata().getValue(Constants.uuid)); + service.setVersion(asdcServiceMetadata.getVersion()); + service.setDescription(csarHelper.getServiceMetadata().getValue(Constants.description)); + service.setInputs(inputsListToInputsMap(csarHelper.getServiceInputs())); + service.setServiceEcompNaming(csarHelper.getServiceMetadata().getValue(Constants.ecompGeneratedNaming)); + return service; + } + + private Map<String, VNF> extractVnfsFromCsar(ISdcCsarHelper csarHelper) { + List<NodeTemplate> nodeTemplates = csarHelper.getServiceVfList(); + Map<String, VNF> vnfsMaps = new HashMap<String, VNF>(); + + for (NodeTemplate nodeTemplate : nodeTemplates) { + VNF vnf = new VNF(); + populateNodeFromNodeTemplate(nodeTemplate, csarHelper, vnf); + vnf.setModelCustomizationName(nodeTemplate.getName()); + vnfsMaps.put(nodeTemplate.getName(), vnf); + } + return vnfsMaps; + } + + private Map<String, Network> extractNetworksFromCsar(ISdcCsarHelper csarHelper) { + List<NodeTemplate> nodeTemplates = csarHelper.getServiceVlList(); + Map<String, Network> networksMap = new HashMap<String, Network>(); + + for (NodeTemplate nodeTemplate : nodeTemplates) { + Network newNetwork = new Network(); + populateNodeFromNodeTemplate(nodeTemplate, csarHelper, newNetwork); + newNetwork.setModelCustomizationName(nodeTemplate.getName()); + networksMap.put(nodeTemplate.getName(), newNetwork); + } + return networksMap; + } + + private Map<String, VfModule> extractVfModuleFromCsar(ISdcCsarHelper csarHelper) { + List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList(); + HashMap<String, VfModule> vfModuleHashMap = new HashMap<>(); + + for (NodeTemplate nodeTemplate : serviceVfList) { + List<Group> groups = csarHelper.getVfModulesByVf(nodeTemplate.getMetaData().getValue(Constants.customizationUUID)); + for (Group group : groups) { + vfModuleHashMap.put(group.getName(), populateVfModuleFromGroup(group)); + } + } + return vfModuleHashMap; + } + + + private Map<String, VolumeGroup> extractVolumeGroups(ISdcCsarHelper csarHelper) { + HashMap<String, VolumeGroup> volumeGroupHashMap = new HashMap<>(); + for (NodeTemplate nodeTemplate : csarHelper.getServiceVfList()) { + List<Group> groups = csarHelper.getVfModulesByVf(csarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); + for (Group group : groups) { + boolean isVolumeGroup = Boolean.valueOf(group.getPropertyValue(Constants.volume_group).toString()); + if (isVolumeGroup) { + volumeGroupHashMap.put(group.getName(), populateVolumeGroupFromGroup(group)); + } + } + } + return volumeGroupHashMap; + } + + private Map<String, org.openecomp.vid.asdc.beans.tosca.Input> inputsListToInputsMap(List<org.openecomp.sdc.toscaparser.api.parameters.Input> inputList) { + Map<String, org.openecomp.vid.asdc.beans.tosca.Input> inputs = new HashMap<>(); + for (org.openecomp.sdc.toscaparser.api.parameters.Input input : inputList) { + inputs.put(input.getName(), convertInput(input, new org.openecomp.vid.asdc.beans.tosca.Input())); + } + return inputs; + } + + private Node populateNodeFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode) { + newNode.setCustomizationUuid(csarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); + newNode.setDescription(nodeTemplate.getMetaData().getValue(Constants.description)); + newNode.setInvariantUuid(nodeTemplate.getMetaData().getValue(Constants.invariantUUID)); + newNode.setUuid(nodeTemplate.getMetaData().getValue(Constants.uuid)); + newNode.setName(nodeTemplate.getMetaData().getValue(Constants.name)); + newNode.setVersion(nodeTemplate.getMetaData().getValue(Constants.version)); + newNode.setInputs(extractInputsAndCommandsForNodeTemplate(nodeTemplate, csarHelper, newNode)); + Map<String, String> propertiesMap = setPropertiesOfVnf(nodeTemplate.getPropertiesObjects()); + newNode.setProperties(propertiesMap); + return newNode; + } + + private VfModule populateVfModuleFromGroup(Group group){ + VfModule vfModule = new VfModule(); + + vfModule.setVersion(group.getMetadata().getValue(Constants.vfModuleModelVersion)); + vfModule.setCustomizationUuid(group.getMetadata().getValue(Constants.vfModuleModelCustomizationUUID)); + vfModule.setModelCustomizationName(group.getMetadata().getValue(Constants.vfModuleModelName)); + vfModule.setName(group.getMetadata().getValue(Constants.vfModuleModelName)); + vfModule.setVolumeGroupAllowed(Boolean.valueOf((group.getPropertyValue(Constants.volume_group)).toString())); + vfModule.setDescription(group.getDescription()); + vfModule.setInvariantUuid(group.getMetadata().getValue(Constants.vfModuleModelInvariantUUID)); + vfModule.setUuid(group.getMetadata().getValue(Constants.vfModuleModelUUID)); + return vfModule; + } + + private VolumeGroup populateVolumeGroupFromGroup(Group group){ + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setDescription(group.getDescription()); + volumeGroup.setInvariantUuid(group.getMetadata().getValue(Constants.vfModuleModelInvariantUUID)); + volumeGroup.setName(group.getMetadata().getValue(Constants.vfModuleModelName)); + volumeGroup.setModelCustomizationName(group.getMetadata().getValue(Constants.vfModuleModelName)); + volumeGroup.setVersion(group.getMetadata().getValue(Constants.vfModuleModelVersion)); + volumeGroup.setUuid(group.getMetadata().getValue(Constants.vfModuleModelUUID)); + return volumeGroup; + } + + + private Map<String, org.openecomp.vid.asdc.beans.tosca.Input> extractInputsAndCommandsForNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode){ + Map<String, org.openecomp.vid.asdc.beans.tosca.Input> inputMap = new HashMap<>(); + Map<String, CommandProperty> commandPropertyMap = new HashMap<>(); + + List<Input> inputs = csarHelper.getServiceInputs(); + Map<String, String> properties = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.getInput); + for (Map.Entry<String, String> property : properties.entrySet()) { + String inputKey = property.getValue(); + String key = extractInputValue(inputKey); + for (Input input: inputs){ + if(input.getName().equals(key)){ + org.openecomp.vid.asdc.beans.tosca.Input localInput = new org.openecomp.vid.asdc.beans.tosca.Input(); + localInput = convertInput(input, localInput); + String name = property.getKey(); + commandPropertyMap.put(name, extractCommands(name, key)); + inputMap.put(name, localInput); + } + } + } + newNode.setCommands(commandPropertyMap); + return inputMap; + } + + private String extractInputValue(String inputKey) { + return inputKey.substring(inputKey.indexOf(":") + 1); + } + + private org.openecomp.vid.asdc.beans.tosca.Input convertInput(Input parserInput, org.openecomp.vid.asdc.beans.tosca.Input localInput){ + localInput.setDefault(parserInput.getDefault()); + localInput.setDescription(parserInput.getDescription()); + localInput.setRequired(parserInput.isRequired()); + localInput.setType(parserInput.getType()); + localInput.setConstraints(parserInput.getConstraints()); +// localInput.setentry_schema() + return localInput; + } + + private CommandProperty extractCommands(String displayName, String inputName){ + CommandProperty commandProperty = new CommandProperty(); + commandProperty.setDisplayName(displayName); + commandProperty.setCommand(Constants.getInput); + commandProperty.setInputName(inputName); + return commandProperty; + } + + private Map<String, String> setPropertiesOfVnf(List<Property> properties) { + Map<String, String> propertiesMap = new HashMap<String, String>(); + for (Property property : properties) { + propertiesMap.put(property.getName(), property.getValue().toString()); + } + return propertiesMap; + } + + +}
\ No newline at end of file diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java index 9f7c3a57d..5b783f5cd 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java @@ -20,10 +20,28 @@ package org.openecomp.vid.asdc.rest;
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+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.parser.ToscaParserImpl;
+import org.openecomp.vid.model.ModelConstants;
+import org.openecomp.vid.properties.VidProperties;
+
+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 java.io.IOException;
import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.File;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -35,441 +53,413 @@ import java.util.Collections; import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
-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.portalsdk.core.logging.logic.EELFLoggerDelegate;
-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.openecomp.vid.model.ModelConstants;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.error.YAMLException;
-
-import org.openecomp.vid.properties.VidProperties;
-import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
/**
* The Class RestfulAsdcClient.
*/
public class RestfulAsdcClient implements AsdcClient {
- /** The Constant LOG. */
- private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(RestfulAsdcClient.class);
-
- /** The Constant dateFormat. */
- final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
-
- /** 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 {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path(path + "/" + uuid.toString() + "/metadata")
- .request(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .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 {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path(path)
- .request(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .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 {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
- WebTarget target = getClient()
- .target(uri)
- .path(path);
-
- for (Entry<String, String[]> filterEntry : filter.entrySet()) {
- target = target.queryParam(filterEntry.getKey(), (Object []) filterEntry.getValue());
- }
-
- try {
- return target.request()
- .accept(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .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 {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path(path + "/" + resourceUuid + "/artifacts/" + artifactUuid)
- .request(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .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 {
-
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path( path + "/" + 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 {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path(path)
- .request()
- .accept(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .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 {
-
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- WebTarget target = getClient()
- .target(uri)
- .path(path);
-
-
- for (Entry<String, String[]> filterEntry : filter.entrySet()) {
- target = target.queryParam(filterEntry.getKey(), (Object []) filterEntry.getValue());
- }
-
- try {
- return target.request()
- .accept(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .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 {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path(path + "/" + serviceUuid + "/artifacts/" + artifactUuid)
- .request(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .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 {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
- try (final InputStream csarInputStream = (InputStream) getClient()
- .target(uri)
- .path(path + "/" + resourceUuid + "/toscaModel")
- .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)
- .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 {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- try {
- final InputStream csarInputStream = (InputStream) getClient()
- .target(uri)
- .path(path + "/" + 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);
- }
+ /**
+ * 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);
+ }
+ }
+
+ /**
+ * The Constant LOG.
+ */
+ static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(RestfulAsdcClient.class);
+
+ /**
+ * The Constant dateFormat.
+ */
+ final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
+
+ /**
+ * 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;
+
+ ToscaParserImpl p = new ToscaParserImpl();
+
+ /**
+ * 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)));
+ }
+
+ private Path createTmpFile(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);
+ }
+ return csarFile;
+ }
+
+ /**
+ * 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 {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
+ try {
+ return getClient()
+ .target(uri)
+ .path(path + "/" + uuid.toString() + "/metadata")
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .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#getResourceArtifact(java.util.UUID, java.util.UUID)
+ */
+ public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
+ try {
+ return getClient()
+ .target(uri)
+ .path(path + "/" + resourceUuid + "/artifacts/" + artifactUuid)
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .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#getResources()
+ */
+ public Collection<Resource> getResources() throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
+ try {
+ return getClient()
+ .target(uri)
+ .path(path)
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .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 {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
+ WebTarget target = getClient()
+ .target(uri)
+ .path(path);
+
+ for (Entry<String, String[]> filterEntry : filter.entrySet()) {
+ target = target.queryParam(filterEntry.getKey(), (Object[]) filterEntry.getValue());
+ }
+
+ try {
+ return target.request()
+ .accept(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .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#getResourceToscaModel(java.util.UUID)
+ */
+ public Path getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
+ try (final InputStream csarInputStream = (InputStream) getClient()
+ .target(uri)
+ .path(path + "/" + resourceUuid + "/toscaModel")
+ .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)
+ .get(InputStream.class)) {
+
+ return getToscaCsar(csarInputStream);
+ } catch (IOException e) {
+ throw new AsdcCatalogException("Failed to retrieve resource TOSCA model from ASDC", e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getService(java.util.UUID)
+ */
+ public Service getService(UUID uuid) throws AsdcCatalogException {
+
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
+ try {
+ return getClient()
+ .target(uri)
+ .path(path + "/" + 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#getServiceArtifact(java.util.UUID, java.util.UUID)
+ */
+ public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- try (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()) {
- LOG.debug("imports = " + imports.toString());
- for (Entry<String, Map<String, String>> entry : imports.entrySet()) {
- if ( entry.getValue() != null) {
- String fname = entry.getValue().get("file");
- if ( ( fname != null ) && (fname.startsWith("service") || fname.startsWith("resource")) ) {
- LOG.debug("fname = " + fname);
- final InputStream toscaChildEntryYamlStream = csar.getInputStream(csar.getEntry("Definitions/" + fname ));
- final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class);
- csarBuilder.addVnf(childModel);
- }
- }
- }
- }
-
- return csarBuilder.build();
- } 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);
- }
- }
+ try {
+ return getClient()
+ .target(uri)
+ .path(path + "/" + 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#getServices()
+ */
+ public Collection<Service> getServices() throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
+ try {
+ return getClient()
+ .target(uri)
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .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 {
+
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
+ WebTarget target = getClient()
+ .target(uri)
+ .path(path);
+
+
+ for (Entry<String, String[]> filterEntry : filter.entrySet()) {
+ target = target.queryParam(filterEntry.getKey(), (Object[]) filterEntry.getValue());
+ }
+
+ try {
+ return target.request()
+ .accept(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .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#getServiceToscaModel(java.util.UUID)
+ */
+ public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
+ try {
+ final InputStream csarInputStream = (InputStream) getClient()
+ .target(uri)
+ .path(path + "/" + serviceUuid + "/toscaModel")
+ .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)
+ .get(InputStream.class);
+
+
+ return getToscaCsar(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 Path getToscaCsar(InputStream csarInputStream) throws AsdcCatalogException {
+ return createTmpFile(csarInputStream);
+ }
}
|